Skip to content

Commit 5a23637

Browse files
committed
Add a separate option for identity inline caches on context-specific objects
1 parent 02f5685 commit 5a23637

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
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/options.yml

Lines changed: 3 additions & 1 deletion
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
@@ -184,7 +185,8 @@ INTERNAL: # Options for debugging the TruffleRuby implementation
184185

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

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public class OptionsCatalog {
118118
public static final OptionKey<Integer> POW_CACHE_KEY = new OptionKey<>(DEFAULT_CACHE_KEY.getDefaultValue());
119119
public static final OptionKey<Integer> RUBY_LIBRARY_CACHE_KEY = new OptionKey<>(DEFAULT_CACHE_KEY.getDefaultValue());
120120
public static final OptionKey<Integer> THREAD_CACHE_KEY = new OptionKey<>(1);
121+
public static final OptionKey<Integer> CONTEXT_SPECIFIC_IDENTITY_CACHE_KEY = new OptionKey<>(1);
121122
public static final OptionKey<Integer> IDENTITY_CACHE_KEY = new OptionKey<>(1);
122123
public static final OptionKey<Integer> CLASS_CACHE_KEY = new OptionKey<>(3);
123124
public static final OptionKey<Integer> ARRAY_DUP_CACHE_KEY = new OptionKey<>(3);
@@ -836,9 +837,16 @@ public class OptionsCatalog {
836837
.stability(OptionStability.EXPERIMENTAL)
837838
.build();
838839

840+
public static final OptionDescriptor CONTEXT_SPECIFIC_IDENTITY_CACHE = OptionDescriptor
841+
.newBuilder(CONTEXT_SPECIFIC_IDENTITY_CACHE_KEY, "ruby.context-identity-cache")
842+
.help("Cache size for inline caches comparing by identity for context-specific objects")
843+
.category(OptionCategory.INTERNAL)
844+
.stability(OptionStability.EXPERIMENTAL)
845+
.build();
846+
839847
public static final OptionDescriptor IDENTITY_CACHE = OptionDescriptor
840848
.newBuilder(IDENTITY_CACHE_KEY, "ruby.identity-cache")
841-
.help("Cache size for inline caches comparing against an object identity")
849+
.help("Cache size for inline caches comparing by identity for context-independent objects")
842850
.category(OptionCategory.INTERNAL)
843851
.stability(OptionStability.EXPERIMENTAL)
844852
.build();
@@ -1251,6 +1259,8 @@ public static OptionDescriptor fromName(String name) {
12511259
return RUBY_LIBRARY_CACHE;
12521260
case "ruby.thread-cache":
12531261
return THREAD_CACHE;
1262+
case "ruby.context-identity-cache":
1263+
return CONTEXT_SPECIFIC_IDENTITY_CACHE;
12541264
case "ruby.identity-cache":
12551265
return IDENTITY_CACHE;
12561266
case "ruby.class-cache":
@@ -1418,6 +1428,7 @@ public static OptionDescriptor[] allDescriptors() {
14181428
POW_CACHE,
14191429
RUBY_LIBRARY_CACHE,
14201430
THREAD_CACHE,
1431+
CONTEXT_SPECIFIC_IDENTITY_CACHE,
14211432
IDENTITY_CACHE,
14221433
CLASS_CACHE,
14231434
ARRAY_DUP_CACHE,

0 commit comments

Comments
 (0)