Skip to content

Commit 2daa744

Browse files
committed
Add debug logging for pending interrupts
1 parent 8eef09d commit 2daa744

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

src/main/java/org/truffleruby/core/thread/ThreadNodes.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ protected Object handleInterrupt(RubyThread self, RubySymbol timing, RubyProc bl
286286
try {
287287
if (newInterruptMode == InterruptMode.IMMEDIATE) {
288288
beforeProfile.enter();
289-
runPendingSafepointActions(self);
289+
runPendingSafepointActions(self, "before");
290290
}
291291

292292
return yield(block);
@@ -295,15 +295,19 @@ protected Object handleInterrupt(RubyThread self, RubySymbol timing, RubyProc bl
295295

296296
if (oldInterruptMode != InterruptMode.NEVER) {
297297
afterProfile.enter();
298-
runPendingSafepointActions(self);
298+
runPendingSafepointActions(self, "after");
299299
}
300300
}
301301
}
302302

303303
@TruffleBoundary
304-
private void runPendingSafepointActions(RubyThread thread) {
304+
private void runPendingSafepointActions(RubyThread thread, String when) {
305305
SafepointAction action;
306306
while ((action = thread.pendingSafepointActions.poll()) != null) {
307+
if (getContext().getOptions().LOG_PENDING_INTERRUPTS) {
308+
RubyLanguage.LOGGER
309+
.info("Running pending interrupt " + action + " " + when + " Thread.handle_interrupt");
310+
}
307311
action.accept(thread, this);
308312
}
309313
}

src/main/java/org/truffleruby/options/Options.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ public class Options {
145145
public final String[] ARGV_GLOBAL_FLAGS;
146146
/** --building-core-cexts=false */
147147
public final boolean BUILDING_CORE_CEXTS;
148+
/** --log-pending-interrupts=false */
149+
public final boolean LOG_PENDING_INTERRUPTS;
148150
/** --rope-print-intern-stats=false */
149151
public final boolean ROPE_PRINT_INTERN_STATS;
150152
/** --preinit=true */
@@ -258,6 +260,7 @@ public Options(Env env, OptionValues options, LanguageOptions languageOptions) {
258260
ARGV_GLOBAL_VALUES = options.get(OptionsCatalog.ARGV_GLOBAL_VALUES_KEY);
259261
ARGV_GLOBAL_FLAGS = options.get(OptionsCatalog.ARGV_GLOBAL_FLAGS_KEY);
260262
BUILDING_CORE_CEXTS = options.get(OptionsCatalog.BUILDING_CORE_CEXTS_KEY);
263+
LOG_PENDING_INTERRUPTS = options.get(OptionsCatalog.LOG_PENDING_INTERRUPTS_KEY);
261264
ROPE_PRINT_INTERN_STATS = options.get(OptionsCatalog.ROPE_PRINT_INTERN_STATS_KEY);
262265
PREINITIALIZATION = options.get(OptionsCatalog.PREINITIALIZATION_KEY);
263266
ARRAY_UNINITIALIZED_SIZE = options.get(OptionsCatalog.ARRAY_UNINITIALIZED_SIZE_KEY);
@@ -409,6 +412,8 @@ public Object fromDescriptor(OptionDescriptor descriptor) {
409412
return ARGV_GLOBAL_FLAGS;
410413
case "ruby.building-core-cexts":
411414
return BUILDING_CORE_CEXTS;
415+
case "ruby.log-pending-interrupts":
416+
return LOG_PENDING_INTERRUPTS;
412417
case "ruby.rope-print-intern-stats":
413418
return ROPE_PRINT_INTERN_STATS;
414419
case "ruby.preinit":

src/options.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ INTERNAL: # Options for debugging the TruffleRuby implementation
145145
# Low-level logging of implementation details
146146
LAZY_TRANSLATION_LOG: [lazy-translation-log, boolean, false, Log lazy translations from the parser AST to the Truffle AST]
147147
LOG_DYNAMIC_CONSTANT_LOOKUP: [constant-dynamic-lookup-log, boolean, false, Log source code positions where dynamic constant lookup is performed]
148+
LOG_PENDING_INTERRUPTS: [log-pending-interrupts, boolean, false, Log when executing pending interrupts]
148149
ROPE_PRINT_INTERN_STATS: [rope-print-intern-stats, boolean, false, Print interned rope stats at application exit]
149150

150151
# Options to debug the implementation

src/shared/java/org/truffleruby/shared/options/OptionsCatalog.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public class OptionsCatalog {
8989
public static final OptionKey<Boolean> BUILDING_CORE_CEXTS_KEY = new OptionKey<>(false);
9090
public static final OptionKey<Boolean> LAZY_TRANSLATION_LOG_KEY = new OptionKey<>(false);
9191
public static final OptionKey<Boolean> LOG_DYNAMIC_CONSTANT_LOOKUP_KEY = new OptionKey<>(false);
92+
public static final OptionKey<Boolean> LOG_PENDING_INTERRUPTS_KEY = new OptionKey<>(false);
9293
public static final OptionKey<Boolean> ROPE_PRINT_INTERN_STATS_KEY = new OptionKey<>(false);
9394
public static final OptionKey<Boolean> PREINITIALIZATION_KEY = new OptionKey<>(true);
9495
public static final OptionKey<Boolean> LAZY_BUILTINS_KEY = new OptionKey<>(DEFAULT_LAZY_KEY.getDefaultValue());
@@ -631,6 +632,13 @@ public class OptionsCatalog {
631632
.stability(OptionStability.EXPERIMENTAL)
632633
.build();
633634

635+
public static final OptionDescriptor LOG_PENDING_INTERRUPTS = OptionDescriptor
636+
.newBuilder(LOG_PENDING_INTERRUPTS_KEY, "ruby.log-pending-interrupts")
637+
.help("Log when executing pending interrupts")
638+
.category(OptionCategory.INTERNAL)
639+
.stability(OptionStability.EXPERIMENTAL)
640+
.build();
641+
634642
public static final OptionDescriptor ROPE_PRINT_INTERN_STATS = OptionDescriptor
635643
.newBuilder(ROPE_PRINT_INTERN_STATS_KEY, "ruby.rope-print-intern-stats")
636644
.help("Print interned rope stats at application exit")
@@ -1177,6 +1185,8 @@ public static OptionDescriptor fromName(String name) {
11771185
return LAZY_TRANSLATION_LOG;
11781186
case "ruby.constant-dynamic-lookup-log":
11791187
return LOG_DYNAMIC_CONSTANT_LOOKUP;
1188+
case "ruby.log-pending-interrupts":
1189+
return LOG_PENDING_INTERRUPTS;
11801190
case "ruby.rope-print-intern-stats":
11811191
return ROPE_PRINT_INTERN_STATS;
11821192
case "ruby.preinit":
@@ -1369,6 +1379,7 @@ public static OptionDescriptor[] allDescriptors() {
13691379
BUILDING_CORE_CEXTS,
13701380
LAZY_TRANSLATION_LOG,
13711381
LOG_DYNAMIC_CONSTANT_LOOKUP,
1382+
LOG_PENDING_INTERRUPTS,
13721383
ROPE_PRINT_INTERN_STATS,
13731384
PREINITIALIZATION,
13741385
LAZY_BUILTINS,

0 commit comments

Comments
 (0)