Skip to content

Commit 9581a2f

Browse files
committed
Add --basic-ops-log-rewrite to debug why inlined operations are rewritten
1 parent c7dd93c commit 9581a2f

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

src/main/java/org/truffleruby/core/inlined/InlinedOperationNode.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
package org.truffleruby.core.inlined;
1111

1212
import com.oracle.truffle.api.Assumption;
13+
import com.oracle.truffle.api.CompilerDirectives;
1314
import com.oracle.truffle.api.frame.VirtualFrame;
1415

1516
import org.truffleruby.RubyLanguage;
17+
import org.truffleruby.core.array.ArrayUtils;
1618
import org.truffleruby.language.dispatch.RubyCallNodeParameters;
19+
import org.truffleruby.language.methods.TranslateExceptionNode;
1720

1821
public abstract class InlinedOperationNode extends InlinedReplaceableNode {
1922

@@ -30,6 +33,12 @@ protected Object rewriteAndCall(VirtualFrame frame, Object receiver, Object... a
3033

3134
protected Object rewriteAndCallWithBlock(VirtualFrame frame, Object receiver, Object block,
3235
Object... arguments) {
36+
CompilerDirectives.transferToInterpreterAndInvalidate();
37+
if (getContext().getOptions().BASICOPS_LOG_REWRITE) {
38+
RubyLanguage.LOGGER.info(
39+
"Rewrite " + this + " with arguments" + TranslateExceptionNode
40+
.argumentsToString(new StringBuilder(), ArrayUtils.unshift(arguments, receiver)));
41+
}
3342
return rewriteToCallNode().executeWithArgumentsEvaluated(frame, receiver, block, arguments);
3443
}
3544

src/main/java/org/truffleruby/language/methods/TranslateExceptionNode.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,15 @@ private RubyException translateUnsupportedSpecialization(RubyContext context,
190190
builder.append("TruffleRuby doesn't have a case for the ");
191191
builder.append(exception.getNode().getClass().getName());
192192
builder.append(" node with values of type");
193+
argumentsToString(builder, exception.getSuppliedValues());
194+
builder.append('\n');
195+
appendJavaStackTrace(exception, builder);
196+
String message = builder.toString().trim();
197+
return context.getCoreExceptions().typeError(message, this, exception);
198+
}
193199

194-
for (Object value : exception.getSuppliedValues()) {
200+
public static StringBuilder argumentsToString(StringBuilder builder, Object[] arguments) {
201+
for (Object value : arguments) {
195202
builder.append(" ");
196203

197204
if (value == null) {
@@ -232,11 +239,7 @@ private RubyException translateUnsupportedSpecialization(RubyContext context,
232239
builder.append(value.toString());
233240
}
234241
}
235-
236-
builder.append('\n');
237-
appendJavaStackTrace(exception, builder);
238-
String message = builder.toString().trim();
239-
return context.getCoreExceptions().typeError(message, this, exception);
242+
return builder;
240243
}
241244

242245
@TruffleBoundary

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ public class Options {
161161
public final boolean ROPE_PRINT_INTERN_STATS;
162162
/** --cexts-to-native-stats=false */
163163
public final boolean CEXTS_TO_NATIVE_STATS;
164+
/** --basic-ops-log-rewrite=false */
165+
public final boolean BASICOPS_LOG_REWRITE;
164166
/** --array-small=3 */
165167
public final int ARRAY_SMALL;
166168
/** --cexts-marking-cache=100 */
@@ -270,6 +272,7 @@ public Options(Env env, OptionValues options, LanguageOptions languageOptions) {
270272
LOG_PENDING_INTERRUPTS = options.get(OptionsCatalog.LOG_PENDING_INTERRUPTS_KEY);
271273
ROPE_PRINT_INTERN_STATS = options.get(OptionsCatalog.ROPE_PRINT_INTERN_STATS_KEY);
272274
CEXTS_TO_NATIVE_STATS = options.get(OptionsCatalog.CEXTS_TO_NATIVE_STATS_KEY);
275+
BASICOPS_LOG_REWRITE = options.get(OptionsCatalog.BASICOPS_LOG_REWRITE_KEY);
273276
ARRAY_SMALL = options.get(OptionsCatalog.ARRAY_SMALL_KEY);
274277
CEXTS_MARKING_CACHE = options.get(OptionsCatalog.CEXTS_MARKING_CACHE_KEY);
275278
GLOBAL_VARIABLE_MAX_INVALIDATIONS = options.get(OptionsCatalog.GLOBAL_VARIABLE_MAX_INVALIDATIONS_KEY);
@@ -431,6 +434,8 @@ public Object fromDescriptor(OptionDescriptor descriptor) {
431434
return ROPE_PRINT_INTERN_STATS;
432435
case "ruby.cexts-to-native-stats":
433436
return CEXTS_TO_NATIVE_STATS;
437+
case "ruby.basic-ops-log-rewrite":
438+
return BASICOPS_LOG_REWRITE;
434439
case "ruby.array-small":
435440
return ARRAY_SMALL;
436441
case "ruby.cexts-marking-cache":

src/options.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ INTERNAL: # Options for debugging the TruffleRuby implementation
180180

181181
# Options to help debugging the implementation performance
182182
BASICOPS_INLINE: [basic-ops-inline, boolean, true, Inline basic operations (like Fixnum operators) in the AST without a call]
183+
BASICOPS_LOG_REWRITE: [basic-ops-log-rewrite, boolean, false, Log the receiver and arguments when basic operations like Fixnum operators cannot be handled inline]
183184
PROFILE_ARGUMENTS: [profile-arguments, boolean, true, Profile the value and class of the receiver and arguments]
184185

185186
# Inline cache sizes

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public class OptionsCatalog {
105105
public static final OptionKey<Boolean> LAZY_TRANSLATION_CORE_KEY = new OptionKey<>(LAZY_CALLTARGETS_KEY.getDefaultValue());
106106
public static final OptionKey<Boolean> CHAOS_DATA_KEY = new OptionKey<>(false);
107107
public static final OptionKey<Boolean> BASICOPS_INLINE_KEY = new OptionKey<>(true);
108+
public static final OptionKey<Boolean> BASICOPS_LOG_REWRITE_KEY = new OptionKey<>(false);
108109
public static final OptionKey<Boolean> PROFILE_ARGUMENTS_KEY = new OptionKey<>(true);
109110
public static final OptionKey<Integer> DEFAULT_CACHE_KEY = new OptionKey<>(8);
110111
public static final OptionKey<Integer> METHOD_LOOKUP_CACHE_KEY = new OptionKey<>(DEFAULT_CACHE_KEY.getDefaultValue());
@@ -756,6 +757,13 @@ public class OptionsCatalog {
756757
.stability(OptionStability.EXPERIMENTAL)
757758
.build();
758759

760+
public static final OptionDescriptor BASICOPS_LOG_REWRITE = OptionDescriptor
761+
.newBuilder(BASICOPS_LOG_REWRITE_KEY, "ruby.basic-ops-log-rewrite")
762+
.help("Log the receiver and arguments when basic operations like Fixnum operators cannot be handled inline")
763+
.category(OptionCategory.INTERNAL)
764+
.stability(OptionStability.EXPERIMENTAL)
765+
.build();
766+
759767
public static final OptionDescriptor PROFILE_ARGUMENTS = OptionDescriptor
760768
.newBuilder(PROFILE_ARGUMENTS_KEY, "ruby.profile-arguments")
761769
.help("Profile the value and class of the receiver and arguments")
@@ -1313,6 +1321,8 @@ public static OptionDescriptor fromName(String name) {
13131321
return CHAOS_DATA;
13141322
case "ruby.basic-ops-inline":
13151323
return BASICOPS_INLINE;
1324+
case "ruby.basic-ops-log-rewrite":
1325+
return BASICOPS_LOG_REWRITE;
13161326
case "ruby.profile-arguments":
13171327
return PROFILE_ARGUMENTS;
13181328
case "ruby.default-cache":
@@ -1515,6 +1525,7 @@ public static OptionDescriptor[] allDescriptors() {
15151525
LAZY_TRANSLATION_CORE,
15161526
CHAOS_DATA,
15171527
BASICOPS_INLINE,
1528+
BASICOPS_LOG_REWRITE,
15181529
PROFILE_ARGUMENTS,
15191530
DEFAULT_CACHE,
15201531
METHOD_LOOKUP_CACHE,

0 commit comments

Comments
 (0)