Skip to content

Commit 1c3ecb1

Browse files
committed
[GR-29439] Add a separate option for identity inline caches on context-specific objects
PullRequest: truffleruby/2444
2 parents d798a78 + d0f50b2 commit 1c3ecb1

File tree

6 files changed

+105
-77
lines changed

6 files changed

+105
-77
lines changed

src/main/java/org/truffleruby/language/objects/MetaClassNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ protected RubyClass metaClassRegexp(RubyRegexp value,
105105

106106
@Specialization(
107107
guards = { "object == cachedObject", "metaClass.isSingleton" },
108-
limit = "getIdentityCacheLimit()")
108+
limit = "getIdentityCacheContextLimit()")
109109
protected RubyClass singletonClassCached(RubyDynamicObject object,
110110
@Cached("object") RubyDynamicObject cachedObject,
111111
@Cached("object.getMetaClass()") RubyClass metaClass) {
@@ -129,7 +129,7 @@ protected int getCacheLimit() {
129129
return RubyLanguage.getCurrentLanguage().options.CLASS_CACHE;
130130
}
131131

132-
protected int getIdentityCacheLimit() {
133-
return RubyLanguage.getCurrentLanguage().options.IDENTITY_CACHE;
132+
protected int getIdentityCacheContextLimit() {
133+
return RubyLanguage.getCurrentLanguage().options.CONTEXT_SPECIFIC_IDENTITY_CACHE;
134134
}
135135
}

src/main/java/org/truffleruby/language/objects/SingletonClassNode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected RubyClass singletonClassImmutableObject(ImmutableRubyObject value,
8888
@Specialization(
8989
// no need to guard on the context, the rubyClass is context-specific
9090
guards = { "rubyClass == cachedClass", "cachedSingletonClass != null" },
91-
limit = "getIdentityCacheLimit()")
91+
limit = "getIdentityCacheContextLimit()")
9292
protected RubyClass singletonClassClassCached(RubyClass rubyClass,
9393
@Cached("rubyClass") RubyClass cachedClass,
9494
@CachedContext(RubyLanguage.class) RubyContext context,
@@ -105,7 +105,7 @@ protected RubyClass singletonClassClassUncached(RubyClass rubyClass,
105105
@Specialization(
106106
// no need to guard on the context, the RubyDynamicObject is context-specific
107107
guards = { "object == cachedObject", "!isRubyClass(cachedObject)" },
108-
limit = "getIdentityCacheLimit()")
108+
limit = "getIdentityCacheContextLimit()")
109109
protected RubyClass singletonClassInstanceCached(RubyDynamicObject object,
110110
@Cached("object") RubyDynamicObject cachedObject,
111111
@CachedContext(RubyLanguage.class) RubyContext context,
@@ -158,8 +158,8 @@ protected int getCacheLimit() {
158158
return RubyLanguage.getCurrentLanguage().options.CLASS_CACHE;
159159
}
160160

161-
protected int getIdentityCacheLimit() {
162-
return RubyLanguage.getCurrentLanguage().options.IDENTITY_CACHE;
161+
protected int getIdentityCacheContextLimit() {
162+
return RubyLanguage.getCurrentLanguage().options.CONTEXT_SPECIFIC_IDENTITY_CACHE;
163163
}
164164

165165
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ public class LanguageOptions {
9090
public final int RUBY_LIBRARY_CACHE;
9191
/** --thread-cache=1 */
9292
public final int THREAD_CACHE;
93+
/** --context-identity-cache=1 */
94+
public final int CONTEXT_SPECIFIC_IDENTITY_CACHE;
9395
/** --identity-cache=1 */
9496
public final int IDENTITY_CACHE;
9597
/** --class-cache=3 */
@@ -142,6 +144,7 @@ public LanguageOptions(Env env, OptionValues options) {
142144
POW_CACHE = options.hasBeenSet(OptionsCatalog.POW_CACHE_KEY) ? options.get(OptionsCatalog.POW_CACHE_KEY) : DEFAULT_CACHE;
143145
RUBY_LIBRARY_CACHE = options.hasBeenSet(OptionsCatalog.RUBY_LIBRARY_CACHE_KEY) ? options.get(OptionsCatalog.RUBY_LIBRARY_CACHE_KEY) : DEFAULT_CACHE;
144146
THREAD_CACHE = options.get(OptionsCatalog.THREAD_CACHE_KEY);
147+
CONTEXT_SPECIFIC_IDENTITY_CACHE = options.get(OptionsCatalog.CONTEXT_SPECIFIC_IDENTITY_CACHE_KEY);
145148
IDENTITY_CACHE = options.get(OptionsCatalog.IDENTITY_CACHE_KEY);
146149
CLASS_CACHE = options.get(OptionsCatalog.CLASS_CACHE_KEY);
147150
ARRAY_DUP_CACHE = options.get(OptionsCatalog.ARRAY_DUP_CACHE_KEY);
@@ -222,6 +225,8 @@ public Object fromDescriptor(OptionDescriptor descriptor) {
222225
return RUBY_LIBRARY_CACHE;
223226
case "ruby.thread-cache":
224227
return THREAD_CACHE;
228+
case "ruby.context-identity-cache":
229+
return CONTEXT_SPECIFIC_IDENTITY_CACHE;
225230
case "ruby.identity-cache":
226231
return IDENTITY_CACHE;
227232
case "ruby.class-cache":
@@ -278,6 +283,7 @@ public static boolean areOptionsCompatible(OptionValues one, OptionValues two) {
278283
one.get(OptionsCatalog.POW_CACHE_KEY).equals(two.get(OptionsCatalog.POW_CACHE_KEY)) &&
279284
one.get(OptionsCatalog.RUBY_LIBRARY_CACHE_KEY).equals(two.get(OptionsCatalog.RUBY_LIBRARY_CACHE_KEY)) &&
280285
one.get(OptionsCatalog.THREAD_CACHE_KEY).equals(two.get(OptionsCatalog.THREAD_CACHE_KEY)) &&
286+
one.get(OptionsCatalog.CONTEXT_SPECIFIC_IDENTITY_CACHE_KEY).equals(two.get(OptionsCatalog.CONTEXT_SPECIFIC_IDENTITY_CACHE_KEY)) &&
281287
one.get(OptionsCatalog.IDENTITY_CACHE_KEY).equals(two.get(OptionsCatalog.IDENTITY_CACHE_KEY)) &&
282288
one.get(OptionsCatalog.CLASS_CACHE_KEY).equals(two.get(OptionsCatalog.CLASS_CACHE_KEY)) &&
283289
one.get(OptionsCatalog.ARRAY_DUP_CACHE_KEY).equals(two.get(OptionsCatalog.ARRAY_DUP_CACHE_KEY)) &&
@@ -530,6 +536,13 @@ public static boolean areOptionsCompatibleOrLog(TruffleLogger logger, LanguageOp
530536
return false;
531537
}
532538

539+
oldValue = oldOptions.CONTEXT_SPECIFIC_IDENTITY_CACHE;
540+
newValue = newOptions.CONTEXT_SPECIFIC_IDENTITY_CACHE;
541+
if (!newValue.equals(oldValue)) {
542+
logger.fine("not reusing pre-initialized context: --context-identity-cache differs, was: " + oldValue + " and is now: " + newValue);
543+
return false;
544+
}
545+
533546
oldValue = oldOptions.IDENTITY_CACHE;
534547
newValue = newOptions.IDENTITY_CACHE;
535548
if (!newValue.equals(oldValue)) {

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,10 @@ public class Options {
4747
public final String CORE_LOAD_PATH;
4848
/** --rubygems=true */
4949
public final boolean RUBYGEMS;
50-
/** --lazy-rubygems=RUBYGEMS && DEFAULT_LAZY */
51-
public final boolean LAZY_RUBYGEMS;
52-
/** --patching=true */
53-
public final boolean PATCHING;
5450
/** --did-you-mean=true */
5551
public final boolean DID_YOU_MEAN;
56-
/** --hashing-deterministic=false */
57-
public final boolean HASHING_DETERMINISTIC;
58-
/** --pattern-matching=false */
59-
public final boolean PATTERN_MATCHING;
52+
/** --lazy-rubygems=RUBYGEMS && DEFAULT_LAZY */
53+
public final boolean LAZY_RUBYGEMS;
6054
/** --embedded=true */
6155
public final boolean EMBEDDED;
6256
/** --platform-native=env.isNativeAccessAllowed() && true */
@@ -75,6 +69,12 @@ public class Options {
7569
public final boolean TRACE_CALLS;
7670
/** --coverage-global=false */
7771
public final boolean COVERAGE_GLOBAL;
72+
/** --pattern-matching=false */
73+
public final boolean PATTERN_MATCHING;
74+
/** --patching=true */
75+
public final boolean PATCHING;
76+
/** --hashing-deterministic=false */
77+
public final boolean HASHING_DETERMINISTIC;
7878
/** --exceptions-store-java=false */
7979
public final boolean EXCEPTIONS_STORE_JAVA;
8080
/** --exceptions-print-java=false */
@@ -213,11 +213,8 @@ public Options(Env env, OptionValues options, LanguageOptions languageOptions) {
213213
LAUNCHER = options.get(OptionsCatalog.LAUNCHER_KEY);
214214
CORE_LOAD_PATH = options.get(OptionsCatalog.CORE_LOAD_PATH_KEY);
215215
RUBYGEMS = options.get(OptionsCatalog.RUBYGEMS_KEY);
216-
LAZY_RUBYGEMS = RUBYGEMS && (options.hasBeenSet(OptionsCatalog.LAZY_RUBYGEMS_KEY) ? options.get(OptionsCatalog.LAZY_RUBYGEMS_KEY) : languageOptions.DEFAULT_LAZY);
217-
PATCHING = options.get(OptionsCatalog.PATCHING_KEY);
218216
DID_YOU_MEAN = options.get(OptionsCatalog.DID_YOU_MEAN_KEY);
219-
HASHING_DETERMINISTIC = options.get(OptionsCatalog.HASHING_DETERMINISTIC_KEY);
220-
PATTERN_MATCHING = options.get(OptionsCatalog.PATTERN_MATCHING_KEY);
217+
LAZY_RUBYGEMS = RUBYGEMS && (options.hasBeenSet(OptionsCatalog.LAZY_RUBYGEMS_KEY) ? options.get(OptionsCatalog.LAZY_RUBYGEMS_KEY) : languageOptions.DEFAULT_LAZY);
221218
EMBEDDED = options.get(OptionsCatalog.EMBEDDED_KEY);
222219
NATIVE_PLATFORM = env.isNativeAccessAllowed() && (options.get(OptionsCatalog.NATIVE_PLATFORM_KEY));
223220
NATIVE_INTERRUPT = options.hasBeenSet(OptionsCatalog.NATIVE_INTERRUPT_KEY) ? options.get(OptionsCatalog.NATIVE_INTERRUPT_KEY) : NATIVE_PLATFORM;
@@ -227,6 +224,9 @@ public Options(Env env, OptionValues options, LanguageOptions languageOptions) {
227224
HOST_INTEROP = env.isHostLookupAllowed() && (options.get(OptionsCatalog.HOST_INTEROP_KEY));
228225
TRACE_CALLS = options.get(OptionsCatalog.TRACE_CALLS_KEY);
229226
COVERAGE_GLOBAL = options.get(OptionsCatalog.COVERAGE_GLOBAL_KEY);
227+
PATTERN_MATCHING = options.get(OptionsCatalog.PATTERN_MATCHING_KEY);
228+
PATCHING = options.get(OptionsCatalog.PATCHING_KEY);
229+
HASHING_DETERMINISTIC = options.get(OptionsCatalog.HASHING_DETERMINISTIC_KEY);
230230
EXCEPTIONS_STORE_JAVA = options.get(OptionsCatalog.EXCEPTIONS_STORE_JAVA_KEY);
231231
EXCEPTIONS_PRINT_JAVA = options.get(OptionsCatalog.EXCEPTIONS_PRINT_JAVA_KEY);
232232
EXCEPTIONS_PRINT_UNCAUGHT_JAVA = options.get(OptionsCatalog.EXCEPTIONS_PRINT_UNCAUGHT_JAVA_KEY);
@@ -317,16 +317,10 @@ public Object fromDescriptor(OptionDescriptor descriptor) {
317317
return CORE_LOAD_PATH;
318318
case "ruby.rubygems":
319319
return RUBYGEMS;
320-
case "ruby.lazy-rubygems":
321-
return LAZY_RUBYGEMS;
322-
case "ruby.patching":
323-
return PATCHING;
324320
case "ruby.did-you-mean":
325321
return DID_YOU_MEAN;
326-
case "ruby.hashing-deterministic":
327-
return HASHING_DETERMINISTIC;
328-
case "ruby.pattern-matching":
329-
return PATTERN_MATCHING;
322+
case "ruby.lazy-rubygems":
323+
return LAZY_RUBYGEMS;
330324
case "ruby.embedded":
331325
return EMBEDDED;
332326
case "ruby.platform-native":
@@ -345,6 +339,12 @@ public Object fromDescriptor(OptionDescriptor descriptor) {
345339
return TRACE_CALLS;
346340
case "ruby.coverage-global":
347341
return COVERAGE_GLOBAL;
342+
case "ruby.pattern-matching":
343+
return PATTERN_MATCHING;
344+
case "ruby.patching":
345+
return PATCHING;
346+
case "ruby.hashing-deterministic":
347+
return HASHING_DETERMINISTIC;
348348
case "ruby.exceptions-store-java":
349349
return EXCEPTIONS_STORE_JAVA;
350350
case "ruby.exceptions-print-java":

src/options.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ LANGUAGE_OPTIONS:
3838
- POW_CACHE
3939
- RUBY_LIBRARY_CACHE
4040
- THREAD_CACHE
41+
- CONTEXT_SPECIFIC_IDENTITY_CACHE
4142
- IDENTITY_CACHE
4243
- CLASS_CACHE
4344
- ARRAY_DUP_CACHE
@@ -65,13 +66,12 @@ EXPERT:
6566
# CRuby features (--enable/disable-FEATURE), also exposed as options so they can be used outside the Ruby launcher
6667
FROZEN_STRING_LITERALS: [frozen-string-literals, boolean, false, Use frozen string literals]
6768
RUBYGEMS: [rubygems, boolean, true, Use RubyGems]
69+
DID_YOU_MEAN: [did-you-mean, boolean, true, Use did_you_mean]
70+
71+
# Control lazy behavior
6872
DEFAULT_LAZY: [lazy-default, boolean, true, Enable default lazy options]
6973
LAZY_CALLTARGETS: [lazy-calltargets, boolean, DEFAULT_LAZY, Create CallTargets lazily when possible]
7074
LAZY_RUBYGEMS: [lazy-rubygems, boolean, ['RUBYGEMS && ', DEFAULT_LAZY], Load RubyGems lazily on first failing require]
71-
PATCHING: [patching, boolean, true, Use patching]
72-
DID_YOU_MEAN: [did-you-mean, boolean, true, Use did_you_mean]
73-
HASHING_DETERMINISTIC: [hashing-deterministic, boolean, false, Produce deterministic hash values]
74-
PATTERN_MATCHING: [pattern-matching, boolean, false, Enable pattern matching syntax]
7575

7676
# Embedding options
7777
EMBEDDED: [embedded, boolean, true, 'Set default options for an embedded use of TruffleRuby, rather than top-level use']
@@ -85,11 +85,14 @@ EXPERT:
8585
# Ruby-level features
8686
TRACE_CALLS: [trace-calls, boolean, true, 'Support tracing (set_trace_func, TracePoint) of method calls']
8787
COVERAGE_GLOBAL: [coverage-global, boolean, false, Run coverage for all code and print results on exit]
88+
PATTERN_MATCHING: [pattern-matching, boolean, false, Enable pattern matching syntax]
8889

8990
# Options helpful in for debugging, potentially also for user code
9091
CORE_AS_INTERNAL: [core-as-internal, boolean, false, 'Mark core library sources as internal']
9192
STDLIB_AS_INTERNAL: [stdlib-as-internal, boolean, false, 'Mark stdlib sources as internal']
9293
LAZY_TRANSLATION_USER: [lazy-translation-user, boolean, LAZY_CALLTARGETS, 'Lazily translation of stdlib, gem and user source files']
94+
PATCHING: [patching, boolean, true, Use patching]
95+
HASHING_DETERMINISTIC: [hashing-deterministic, boolean, false, Produce deterministic hash values]
9396

9497
# Options to tweak backtraces
9598
EXCEPTIONS_STORE_JAVA: [exceptions-store-java, boolean, false, Store the Java exception with the Ruby backtrace]
@@ -185,7 +188,8 @@ INTERNAL: # Options for debugging the TruffleRuby implementation
185188

186189
# Inline caches with a non-default size
187190
THREAD_CACHE: [thread-cache, integer, 1, Cache size of operations that depend on a particular thread]
188-
IDENTITY_CACHE: [identity-cache, integer, 1, Cache size for inline caches comparing against an object identity]
191+
CONTEXT_SPECIFIC_IDENTITY_CACHE: [context-identity-cache, integer, 1, Cache size for inline caches comparing by identity for context-specific objects]
192+
IDENTITY_CACHE: [identity-cache, integer, 1, Cache size for inline caches comparing by identity for context-independent objects]
189193
CLASS_CACHE: [class-cache, integer, 3, .class and .metaclass cache size]
190194
ARRAY_DUP_CACHE: [array-dup-cache, integer, 3, Cache size for copying small arrays]
191195
ARRAY_STRATEGY_CACHE: [array-strategy-cache, integer, 4, Cache size for array strategies]

0 commit comments

Comments
 (0)