Skip to content

Commit 0caf91e

Browse files
committed
Add option --lazy-calltargets to control whether to create any CallTarget Supplier
1 parent f89c33a commit 0caf91e

File tree

4 files changed

+46
-14
lines changed

4 files changed

+46
-14
lines changed

src/main/java/org/truffleruby/builtins/CoreMethodNodeManager.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,14 @@ private static void addMethod(
267267
final RubyRootNode rootNode = (RubyRootNode) callTarget.getRootNode();
268268
alwaysInlinedNodeFactory = ((ReRaiseInlinedExceptionNode) rootNode.getBody()).nodeFactory;
269269
} else {
270-
callTarget = null;
271-
callTargetSupplier = new CachedSupplier<>(() -> callTargetFactory.apply(sharedMethodInfo));
270+
if (context.getLanguageSlow().options.LAZY_CALLTARGETS) {
271+
callTarget = null;
272+
callTargetSupplier = new CachedSupplier<>(() -> callTargetFactory.apply(sharedMethodInfo));
273+
} else {
274+
callTarget = callTargetFactory.apply(sharedMethodInfo);
275+
callTargetSupplier = null;
276+
}
277+
272278
alwaysInlinedNodeFactory = null;
273279
}
274280

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,23 @@ public class LanguageOptions {
2626
public final boolean FROZEN_STRING_LITERALS;
2727
/** --lazy-default=true */
2828
public final boolean DEFAULT_LAZY;
29+
/** --lazy-calltargets=DEFAULT_LAZY */
30+
public final boolean LAZY_CALLTARGETS;
2931
/** --core-as-internal=false */
3032
public final boolean CORE_AS_INTERNAL;
3133
/** --stdlib-as-internal=false */
3234
public final boolean STDLIB_AS_INTERNAL;
33-
/** --lazy-translation-user=DEFAULT_LAZY */
35+
/** --lazy-translation-user=LAZY_CALLTARGETS */
3436
public final boolean LAZY_TRANSLATION_USER;
3537
/** --backtraces-omit-unused=true */
3638
public final boolean BACKTRACES_OMIT_UNUSED;
3739
/** --lazy-translation-log=false */
3840
public final boolean LAZY_TRANSLATION_LOG;
3941
/** --constant-dynamic-lookup-log=false */
4042
public final boolean LOG_DYNAMIC_CONSTANT_LOOKUP;
41-
/** --lazy-builtins=DEFAULT_LAZY */
43+
/** --lazy-builtins=LAZY_CALLTARGETS */
4244
public final boolean LAZY_BUILTINS;
43-
/** --lazy-translation-core=DEFAULT_LAZY */
45+
/** --lazy-translation-core=LAZY_CALLTARGETS */
4446
public final boolean LAZY_TRANSLATION_CORE;
4547
/** --basic-ops-inline=true */
4648
public final boolean BASICOPS_INLINE;
@@ -108,14 +110,15 @@ public class LanguageOptions {
108110
public LanguageOptions(Env env, OptionValues options) {
109111
FROZEN_STRING_LITERALS = options.get(OptionsCatalog.FROZEN_STRING_LITERALS_KEY);
110112
DEFAULT_LAZY = options.get(OptionsCatalog.DEFAULT_LAZY_KEY);
113+
LAZY_CALLTARGETS = options.hasBeenSet(OptionsCatalog.LAZY_CALLTARGETS_KEY) ? options.get(OptionsCatalog.LAZY_CALLTARGETS_KEY) : DEFAULT_LAZY;
111114
CORE_AS_INTERNAL = options.get(OptionsCatalog.CORE_AS_INTERNAL_KEY);
112115
STDLIB_AS_INTERNAL = options.get(OptionsCatalog.STDLIB_AS_INTERNAL_KEY);
113-
LAZY_TRANSLATION_USER = options.hasBeenSet(OptionsCatalog.LAZY_TRANSLATION_USER_KEY) ? options.get(OptionsCatalog.LAZY_TRANSLATION_USER_KEY) : DEFAULT_LAZY;
116+
LAZY_TRANSLATION_USER = options.hasBeenSet(OptionsCatalog.LAZY_TRANSLATION_USER_KEY) ? options.get(OptionsCatalog.LAZY_TRANSLATION_USER_KEY) : LAZY_CALLTARGETS;
114117
BACKTRACES_OMIT_UNUSED = options.get(OptionsCatalog.BACKTRACES_OMIT_UNUSED_KEY);
115118
LAZY_TRANSLATION_LOG = options.get(OptionsCatalog.LAZY_TRANSLATION_LOG_KEY);
116119
LOG_DYNAMIC_CONSTANT_LOOKUP = options.get(OptionsCatalog.LOG_DYNAMIC_CONSTANT_LOOKUP_KEY);
117-
LAZY_BUILTINS = options.hasBeenSet(OptionsCatalog.LAZY_BUILTINS_KEY) ? options.get(OptionsCatalog.LAZY_BUILTINS_KEY) : DEFAULT_LAZY;
118-
LAZY_TRANSLATION_CORE = options.hasBeenSet(OptionsCatalog.LAZY_TRANSLATION_CORE_KEY) ? options.get(OptionsCatalog.LAZY_TRANSLATION_CORE_KEY) : DEFAULT_LAZY;
120+
LAZY_BUILTINS = options.hasBeenSet(OptionsCatalog.LAZY_BUILTINS_KEY) ? options.get(OptionsCatalog.LAZY_BUILTINS_KEY) : LAZY_CALLTARGETS;
121+
LAZY_TRANSLATION_CORE = options.hasBeenSet(OptionsCatalog.LAZY_TRANSLATION_CORE_KEY) ? options.get(OptionsCatalog.LAZY_TRANSLATION_CORE_KEY) : LAZY_CALLTARGETS;
119122
BASICOPS_INLINE = options.get(OptionsCatalog.BASICOPS_INLINE_KEY);
120123
PROFILE_ARGUMENTS = options.get(OptionsCatalog.PROFILE_ARGUMENTS_KEY);
121124
DEFAULT_CACHE = options.get(OptionsCatalog.DEFAULT_CACHE_KEY);
@@ -155,6 +158,8 @@ public Object fromDescriptor(OptionDescriptor descriptor) {
155158
return FROZEN_STRING_LITERALS;
156159
case "ruby.lazy-default":
157160
return DEFAULT_LAZY;
161+
case "ruby.lazy-calltargets":
162+
return LAZY_CALLTARGETS;
158163
case "ruby.core-as-internal":
159164
return CORE_AS_INTERNAL;
160165
case "ruby.stdlib-as-internal":
@@ -241,6 +246,7 @@ public Object fromDescriptor(OptionDescriptor descriptor) {
241246
public static boolean areOptionsCompatible(OptionValues one, OptionValues two) {
242247
return one.get(OptionsCatalog.FROZEN_STRING_LITERALS_KEY).equals(two.get(OptionsCatalog.FROZEN_STRING_LITERALS_KEY)) &&
243248
one.get(OptionsCatalog.DEFAULT_LAZY_KEY).equals(two.get(OptionsCatalog.DEFAULT_LAZY_KEY)) &&
249+
one.get(OptionsCatalog.LAZY_CALLTARGETS_KEY).equals(two.get(OptionsCatalog.LAZY_CALLTARGETS_KEY)) &&
244250
one.get(OptionsCatalog.CORE_AS_INTERNAL_KEY).equals(two.get(OptionsCatalog.CORE_AS_INTERNAL_KEY)) &&
245251
one.get(OptionsCatalog.STDLIB_AS_INTERNAL_KEY).equals(two.get(OptionsCatalog.STDLIB_AS_INTERNAL_KEY)) &&
246252
one.get(OptionsCatalog.LAZY_TRANSLATION_USER_KEY).equals(two.get(OptionsCatalog.LAZY_TRANSLATION_USER_KEY)) &&
@@ -300,6 +306,13 @@ public static boolean areOptionsCompatibleOrLog(TruffleLogger logger, LanguageOp
300306
return false;
301307
}
302308

309+
oldValue = oldOptions.LAZY_CALLTARGETS;
310+
newValue = newOptions.LAZY_CALLTARGETS;
311+
if (!newValue.equals(oldValue)) {
312+
logger.fine("not reusing pre-initialized context: --lazy-calltargets differs, was: " + oldValue + " and is now: " + newValue);
313+
return false;
314+
}
315+
303316
oldValue = oldOptions.CORE_AS_INTERNAL;
304317
newValue = newOptions.CORE_AS_INTERNAL;
305318
if (!newValue.equals(oldValue)) {

src/options.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ LANGUAGE_OPTIONS:
88
- LOG_DYNAMIC_CONSTANT_LOOKUP
99
- PROFILE_ARGUMENTS
1010
- DEFAULT_LAZY
11+
- LAZY_CALLTARGETS
1112
- BASICOPS_INLINE
1213
- LAZY_BUILTINS
1314
- SHARED_OBJECTS_ENABLED
@@ -65,6 +66,7 @@ EXPERT:
6566
FROZEN_STRING_LITERALS: [frozen-string-literals, boolean, false, Use frozen string literals]
6667
RUBYGEMS: [rubygems, boolean, true, Use RubyGems]
6768
DEFAULT_LAZY: [lazy-default, boolean, true, Enable default lazy options]
69+
LAZY_CALLTARGETS: [lazy-calltargets, boolean, DEFAULT_LAZY, Create CallTargets lazily when possible]
6870
LAZY_RUBYGEMS: [lazy-rubygems, boolean, ['RUBYGEMS && ', DEFAULT_LAZY], Load RubyGems lazily on first failing require]
6971
PATCHING: [patching, boolean, true, Use patching]
7072
DID_YOU_MEAN: [did-you-mean, boolean, true, Use did_you_mean]
@@ -87,7 +89,7 @@ EXPERT:
8789
# Options helpful in for debugging, potentially also for user code
8890
CORE_AS_INTERNAL: [core-as-internal, boolean, false, 'Mark core library sources as internal']
8991
STDLIB_AS_INTERNAL: [stdlib-as-internal, boolean, false, 'Mark stdlib sources as internal']
90-
LAZY_TRANSLATION_USER: [lazy-translation-user, boolean, DEFAULT_LAZY, 'Lazily translation of stdlib, gem and user source files']
92+
LAZY_TRANSLATION_USER: [lazy-translation-user, boolean, LAZY_CALLTARGETS, 'Lazily translation of stdlib, gem and user source files']
9193

9294
# Options to tweak backtraces
9395
EXCEPTIONS_STORE_JAVA: [exceptions-store-java, boolean, false, Store the Java exception with the Ruby backtrace]
@@ -150,8 +152,8 @@ INTERNAL: # Options for debugging the TruffleRuby implementation
150152

151153
# Options to debug the implementation
152154
PREINITIALIZATION: [preinit, boolean, true, Use the pre-initialized context when available]
153-
LAZY_BUILTINS: [lazy-builtins, boolean, DEFAULT_LAZY, Load builtin classes (core methods & primitives) lazily on first use]
154-
LAZY_TRANSLATION_CORE: [lazy-translation-core, boolean, DEFAULT_LAZY, Lazily translation of core source files]
155+
LAZY_BUILTINS: [lazy-builtins, boolean, LAZY_CALLTARGETS, Load builtin classes (core methods & primitives) lazily on first use]
156+
LAZY_TRANSLATION_CORE: [lazy-translation-core, boolean, LAZY_CALLTARGETS, Lazily translation of core source files]
155157

156158
# Options to help debugging the implementation performance
157159
BASICOPS_INLINE: [basic-ops-inline, boolean, true, Inline basic operations (like Fixnum operators) in the AST without a call]

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class OptionsCatalog {
3434
public static final OptionKey<Boolean> FROZEN_STRING_LITERALS_KEY = new OptionKey<>(false);
3535
public static final OptionKey<Boolean> RUBYGEMS_KEY = new OptionKey<>(true);
3636
public static final OptionKey<Boolean> DEFAULT_LAZY_KEY = new OptionKey<>(true);
37+
public static final OptionKey<Boolean> LAZY_CALLTARGETS_KEY = new OptionKey<>(DEFAULT_LAZY_KEY.getDefaultValue());
3738
public static final OptionKey<Boolean> LAZY_RUBYGEMS_KEY = new OptionKey<>(DEFAULT_LAZY_KEY.getDefaultValue());
3839
public static final OptionKey<Boolean> PATCHING_KEY = new OptionKey<>(true);
3940
public static final OptionKey<Boolean> DID_YOU_MEAN_KEY = new OptionKey<>(true);
@@ -50,7 +51,7 @@ public class OptionsCatalog {
5051
public static final OptionKey<Boolean> COVERAGE_GLOBAL_KEY = new OptionKey<>(false);
5152
public static final OptionKey<Boolean> CORE_AS_INTERNAL_KEY = new OptionKey<>(false);
5253
public static final OptionKey<Boolean> STDLIB_AS_INTERNAL_KEY = new OptionKey<>(false);
53-
public static final OptionKey<Boolean> LAZY_TRANSLATION_USER_KEY = new OptionKey<>(DEFAULT_LAZY_KEY.getDefaultValue());
54+
public static final OptionKey<Boolean> LAZY_TRANSLATION_USER_KEY = new OptionKey<>(LAZY_CALLTARGETS_KEY.getDefaultValue());
5455
public static final OptionKey<Boolean> EXCEPTIONS_STORE_JAVA_KEY = new OptionKey<>(false);
5556
public static final OptionKey<Boolean> EXCEPTIONS_PRINT_JAVA_KEY = new OptionKey<>(false);
5657
public static final OptionKey<Boolean> EXCEPTIONS_PRINT_UNCAUGHT_JAVA_KEY = new OptionKey<>(false);
@@ -92,8 +93,8 @@ public class OptionsCatalog {
9293
public static final OptionKey<Boolean> LOG_PENDING_INTERRUPTS_KEY = new OptionKey<>(false);
9394
public static final OptionKey<Boolean> ROPE_PRINT_INTERN_STATS_KEY = new OptionKey<>(false);
9495
public static final OptionKey<Boolean> PREINITIALIZATION_KEY = new OptionKey<>(true);
95-
public static final OptionKey<Boolean> LAZY_BUILTINS_KEY = new OptionKey<>(DEFAULT_LAZY_KEY.getDefaultValue());
96-
public static final OptionKey<Boolean> LAZY_TRANSLATION_CORE_KEY = new OptionKey<>(DEFAULT_LAZY_KEY.getDefaultValue());
96+
public static final OptionKey<Boolean> LAZY_BUILTINS_KEY = new OptionKey<>(LAZY_CALLTARGETS_KEY.getDefaultValue());
97+
public static final OptionKey<Boolean> LAZY_TRANSLATION_CORE_KEY = new OptionKey<>(LAZY_CALLTARGETS_KEY.getDefaultValue());
9798
public static final OptionKey<Boolean> BASICOPS_INLINE_KEY = new OptionKey<>(true);
9899
public static final OptionKey<Boolean> PROFILE_ARGUMENTS_KEY = new OptionKey<>(true);
99100
public static final OptionKey<Integer> DEFAULT_CACHE_KEY = new OptionKey<>(8);
@@ -247,6 +248,13 @@ public class OptionsCatalog {
247248
.stability(OptionStability.EXPERIMENTAL)
248249
.build();
249250

251+
public static final OptionDescriptor LAZY_CALLTARGETS = OptionDescriptor
252+
.newBuilder(LAZY_CALLTARGETS_KEY, "ruby.lazy-calltargets")
253+
.help("Create CallTargets lazily when possible")
254+
.category(OptionCategory.EXPERT)
255+
.stability(OptionStability.EXPERIMENTAL)
256+
.build();
257+
250258
public static final OptionDescriptor LAZY_RUBYGEMS = OptionDescriptor
251259
.newBuilder(LAZY_RUBYGEMS_KEY, "ruby.lazy-rubygems")
252260
.help("Load RubyGems lazily on first failing require")
@@ -1075,6 +1083,8 @@ public static OptionDescriptor fromName(String name) {
10751083
return RUBYGEMS;
10761084
case "ruby.lazy-default":
10771085
return DEFAULT_LAZY;
1086+
case "ruby.lazy-calltargets":
1087+
return LAZY_CALLTARGETS;
10781088
case "ruby.lazy-rubygems":
10791089
return LAZY_RUBYGEMS;
10801090
case "ruby.patching":
@@ -1324,6 +1334,7 @@ public static OptionDescriptor[] allDescriptors() {
13241334
FROZEN_STRING_LITERALS,
13251335
RUBYGEMS,
13261336
DEFAULT_LAZY,
1337+
LAZY_CALLTARGETS,
13271338
LAZY_RUBYGEMS,
13281339
PATCHING,
13291340
DID_YOU_MEAN,

0 commit comments

Comments
 (0)