Skip to content

Commit 5580e29

Browse files
committed
[GR-16336] Check fast specs pass with empty inline caches
PullRequest: truffleruby/2720
2 parents 830305d + f0045a1 commit 5580e29

File tree

9 files changed

+83
-61
lines changed

9 files changed

+83
-61
lines changed

spec/truffle/pre_initialization_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
guard -> { TruffleRuby.native? } do
1313
describe "The pre-initialized context" do
14-
it "can be used to run specs, as otherwise this spec run will not have tested pre-initialization" do
15-
Truffle::Boot.was_preinitialized?.should == true
14+
guard -> { ENV["TRUFFLERUBY_CHECK_PREINITIALIZED_SPEC"] != "false" } do
15+
it "can be used to run specs, as otherwise this spec run will not have tested pre-initialization" do
16+
Truffle::Boot.was_preinitialized?.should == true
17+
end
1618
end
1719

1820
it "is not used if --engine.UsePreInitializedContext=false is passed" do

src/main/java/org/truffleruby/RubyContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ private void dispose() {
524524
RubyLanguage.LOGGER.info("total ropes interned: " + language.ropeCache.totalRopes());
525525
}
526526

527-
if (options.CEXTS_TONATIVE_STATS) {
527+
if (options.CEXTS_TO_NATIVE_STATS) {
528528
RubyLanguage.LOGGER.info(
529529
"Total VALUE object to native conversions: " + getValueWrapperManager().totalHandleAllocations());
530530
}

src/main/java/org/truffleruby/cext/ValueWrapperManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ protected long allocateHandleOnKnownThread(ValueWrapper wrapper,
318318
@Cached GetHandleBlockHolderNode getBlockHolderNode) {
319319
HandleThreadData threadData = getBlockHolderNode.execute(wrapper);
320320
HandleBlock block = threadData.holder.handleBlock;
321-
if (context.getOptions().CEXTS_TONATIVE_STATS) {
321+
if (context.getOptions().CEXTS_TO_NATIVE_STATS) {
322322
context.getValueWrapperManager().recordHandleAllocation();
323323
}
324324

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

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
1515
import com.oracle.truffle.api.dsl.CachedContext;
1616
import com.oracle.truffle.api.frame.MaterializedFrame;
17+
import com.oracle.truffle.api.nodes.EncapsulatingNodeReference;
1718
import com.oracle.truffle.api.nodes.Node;
1819
import com.oracle.truffle.api.nodes.NodeUtil;
1920
import com.oracle.truffle.api.profiles.BranchProfile;
@@ -115,27 +116,40 @@ protected Object alwaysInlinedUncached(
115116
self,
116117
block,
117118
args,
118-
contextRef);
119+
contextRef,
120+
isAdoptable());
119121
}
120122

121123
@TruffleBoundary // getUncachedAlwaysInlinedMethodNode(method) and arity are not PE constants
122124
private Object alwaysInlinedBoundary(
123125
MaterializedFrame frame, Object callerData, InternalMethod method, Object self, Object block, Object[] args,
124-
ContextReference<RubyContext> contextRef) {
125-
return alwaysInlined(
126-
frame,
127-
callerData,
128-
method,
129-
self,
130-
block,
131-
args,
132-
method.getCallTarget(),
133-
method,
134-
getUncachedAlwaysInlinedMethodNode(method),
135-
method.getSharedMethodInfo().getArity(),
136-
BranchProfile.getUncached(),
137-
BranchProfile.getUncached(),
138-
contextRef);
126+
ContextReference<RubyContext> contextRef, boolean cachedToUncached) {
127+
EncapsulatingNodeReference encapsulating = null;
128+
Node prev = null;
129+
if (cachedToUncached) {
130+
encapsulating = EncapsulatingNodeReference.getCurrent();
131+
prev = encapsulating.set(this);
132+
}
133+
try {
134+
return alwaysInlined(
135+
frame,
136+
callerData,
137+
method,
138+
self,
139+
block,
140+
args,
141+
method.getCallTarget(),
142+
method,
143+
getUncachedAlwaysInlinedMethodNode(method),
144+
method.getSharedMethodInfo().getArity(),
145+
BranchProfile.getUncached(),
146+
BranchProfile.getUncached(),
147+
contextRef);
148+
} finally {
149+
if (cachedToUncached) {
150+
encapsulating.set(prev);
151+
}
152+
}
139153
}
140154

141155
protected AlwaysInlinedMethodNode createAlwaysInlinedMethodNode(InternalMethod method) {

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ public class LanguageOptions {
9696
public final int RUBY_LIBRARY_CACHE;
9797
/** --thread-cache=!singleContext ? 0 : 1 */
9898
public final int THREAD_CACHE;
99-
/** --context-identity-cache=!singleContext ? 0 : 1 */
100-
public final int CONTEXT_SPECIFIC_IDENTITY_CACHE;
10199
/** --identity-cache=1 */
102100
public final int IDENTITY_CACHE;
101+
/** --context-identity-cache=!singleContext ? 0 : IDENTITY_CACHE */
102+
public final int CONTEXT_SPECIFIC_IDENTITY_CACHE;
103103
/** --class-cache=3 */
104104
public final int CLASS_CACHE;
105105
/** --array-dup-cache=3 */
@@ -161,8 +161,8 @@ public LanguageOptions(Env env, OptionValues options, boolean singleContext) {
161161
POW_CACHE = options.hasBeenSet(OptionsCatalog.POW_CACHE_KEY) ? options.get(OptionsCatalog.POW_CACHE_KEY) : DEFAULT_CACHE;
162162
RUBY_LIBRARY_CACHE = options.hasBeenSet(OptionsCatalog.RUBY_LIBRARY_CACHE_KEY) ? options.get(OptionsCatalog.RUBY_LIBRARY_CACHE_KEY) : DEFAULT_CACHE;
163163
THREAD_CACHE = !singleContext ? 0 : (options.get(OptionsCatalog.THREAD_CACHE_KEY));
164-
CONTEXT_SPECIFIC_IDENTITY_CACHE = !singleContext ? 0 : (options.get(OptionsCatalog.CONTEXT_SPECIFIC_IDENTITY_CACHE_KEY));
165164
IDENTITY_CACHE = options.get(OptionsCatalog.IDENTITY_CACHE_KEY);
165+
CONTEXT_SPECIFIC_IDENTITY_CACHE = !singleContext ? 0 : (options.hasBeenSet(OptionsCatalog.CONTEXT_SPECIFIC_IDENTITY_CACHE_KEY) ? options.get(OptionsCatalog.CONTEXT_SPECIFIC_IDENTITY_CACHE_KEY) : IDENTITY_CACHE);
166166
CLASS_CACHE = options.get(OptionsCatalog.CLASS_CACHE_KEY);
167167
ARRAY_DUP_CACHE = options.get(OptionsCatalog.ARRAY_DUP_CACHE_KEY);
168168
ARRAY_STRATEGY_CACHE = options.get(OptionsCatalog.ARRAY_STRATEGY_CACHE_KEY);
@@ -252,10 +252,10 @@ public Object fromDescriptor(OptionDescriptor descriptor) {
252252
return RUBY_LIBRARY_CACHE;
253253
case "ruby.thread-cache":
254254
return THREAD_CACHE;
255-
case "ruby.context-identity-cache":
256-
return CONTEXT_SPECIFIC_IDENTITY_CACHE;
257255
case "ruby.identity-cache":
258256
return IDENTITY_CACHE;
257+
case "ruby.context-identity-cache":
258+
return CONTEXT_SPECIFIC_IDENTITY_CACHE;
259259
case "ruby.class-cache":
260260
return CLASS_CACHE;
261261
case "ruby.array-dup-cache":
@@ -321,8 +321,8 @@ public static boolean areOptionsCompatible(OptionValues one, OptionValues two) {
321321
one.get(OptionsCatalog.POW_CACHE_KEY).equals(two.get(OptionsCatalog.POW_CACHE_KEY)) &&
322322
one.get(OptionsCatalog.RUBY_LIBRARY_CACHE_KEY).equals(two.get(OptionsCatalog.RUBY_LIBRARY_CACHE_KEY)) &&
323323
one.get(OptionsCatalog.THREAD_CACHE_KEY).equals(two.get(OptionsCatalog.THREAD_CACHE_KEY)) &&
324-
one.get(OptionsCatalog.CONTEXT_SPECIFIC_IDENTITY_CACHE_KEY).equals(two.get(OptionsCatalog.CONTEXT_SPECIFIC_IDENTITY_CACHE_KEY)) &&
325324
one.get(OptionsCatalog.IDENTITY_CACHE_KEY).equals(two.get(OptionsCatalog.IDENTITY_CACHE_KEY)) &&
325+
one.get(OptionsCatalog.CONTEXT_SPECIFIC_IDENTITY_CACHE_KEY).equals(two.get(OptionsCatalog.CONTEXT_SPECIFIC_IDENTITY_CACHE_KEY)) &&
326326
one.get(OptionsCatalog.CLASS_CACHE_KEY).equals(two.get(OptionsCatalog.CLASS_CACHE_KEY)) &&
327327
one.get(OptionsCatalog.ARRAY_DUP_CACHE_KEY).equals(two.get(OptionsCatalog.ARRAY_DUP_CACHE_KEY)) &&
328328
one.get(OptionsCatalog.ARRAY_STRATEGY_CACHE_KEY).equals(two.get(OptionsCatalog.ARRAY_STRATEGY_CACHE_KEY)) &&
@@ -599,17 +599,17 @@ public static boolean areOptionsCompatibleOrLog(TruffleLogger logger, LanguageOp
599599
return false;
600600
}
601601

602-
oldValue = oldOptions.CONTEXT_SPECIFIC_IDENTITY_CACHE;
603-
newValue = newOptions.CONTEXT_SPECIFIC_IDENTITY_CACHE;
602+
oldValue = oldOptions.IDENTITY_CACHE;
603+
newValue = newOptions.IDENTITY_CACHE;
604604
if (!newValue.equals(oldValue)) {
605-
logger.fine("not reusing pre-initialized context: --context-identity-cache differs, was: " + oldValue + " and is now: " + newValue);
605+
logger.fine("not reusing pre-initialized context: --identity-cache differs, was: " + oldValue + " and is now: " + newValue);
606606
return false;
607607
}
608608

609-
oldValue = oldOptions.IDENTITY_CACHE;
610-
newValue = newOptions.IDENTITY_CACHE;
609+
oldValue = oldOptions.CONTEXT_SPECIFIC_IDENTITY_CACHE;
610+
newValue = newOptions.CONTEXT_SPECIFIC_IDENTITY_CACHE;
611611
if (!newValue.equals(oldValue)) {
612-
logger.fine("not reusing pre-initialized context: --identity-cache differs, was: " + oldValue + " and is now: " + newValue);
612+
logger.fine("not reusing pre-initialized context: --context-identity-cache differs, was: " + oldValue + " and is now: " + newValue);
613613
return false;
614614
}
615615

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ public class Options {
153153
public final boolean LOG_PENDING_INTERRUPTS;
154154
/** --rope-print-intern-stats=false */
155155
public final boolean ROPE_PRINT_INTERN_STATS;
156+
/** --cexts-to-native-stats=false */
157+
public final boolean CEXTS_TO_NATIVE_STATS;
156158
/** --array-small=3 */
157159
public final int ARRAY_SMALL;
158160
/** --cexts-marking-cache=100 */
159161
public final int CEXTS_MARKING_CACHE;
160-
/** --cexts-tonative-stats=false */
161-
public final boolean CEXTS_TONATIVE_STATS;
162162
/** --global-variable-max-invalidations=1 */
163163
public final int GLOBAL_VARIABLE_MAX_INVALIDATIONS;
164164
/** --clone-default=true */
@@ -258,9 +258,9 @@ public Options(Env env, OptionValues options, LanguageOptions languageOptions) {
258258
BUILDING_CORE_CEXTS = options.get(OptionsCatalog.BUILDING_CORE_CEXTS_KEY);
259259
LOG_PENDING_INTERRUPTS = options.get(OptionsCatalog.LOG_PENDING_INTERRUPTS_KEY);
260260
ROPE_PRINT_INTERN_STATS = options.get(OptionsCatalog.ROPE_PRINT_INTERN_STATS_KEY);
261+
CEXTS_TO_NATIVE_STATS = options.get(OptionsCatalog.CEXTS_TO_NATIVE_STATS_KEY);
261262
ARRAY_SMALL = options.get(OptionsCatalog.ARRAY_SMALL_KEY);
262263
CEXTS_MARKING_CACHE = options.get(OptionsCatalog.CEXTS_MARKING_CACHE_KEY);
263-
CEXTS_TONATIVE_STATS = options.get(OptionsCatalog.CEXTS_TONATIVE_STATS_KEY);
264264
GLOBAL_VARIABLE_MAX_INVALIDATIONS = options.get(OptionsCatalog.GLOBAL_VARIABLE_MAX_INVALIDATIONS_KEY);
265265
CLONE_DEFAULT = options.get(OptionsCatalog.CLONE_DEFAULT_KEY);
266266
INLINE_DEFAULT = options.get(OptionsCatalog.INLINE_DEFAULT_KEY);
@@ -411,12 +411,12 @@ public Object fromDescriptor(OptionDescriptor descriptor) {
411411
return LOG_PENDING_INTERRUPTS;
412412
case "ruby.rope-print-intern-stats":
413413
return ROPE_PRINT_INTERN_STATS;
414+
case "ruby.cexts-to-native-stats":
415+
return CEXTS_TO_NATIVE_STATS;
414416
case "ruby.array-small":
415417
return ARRAY_SMALL;
416418
case "ruby.cexts-marking-cache":
417419
return CEXTS_MARKING_CACHE;
418-
case "ruby.cexts-tonative-stats":
419-
return CEXTS_TONATIVE_STATS;
420420
case "ruby.global-variable-max-invalidations":
421421
return GLOBAL_VARIABLE_MAX_INVALIDATIONS;
422422
case "ruby.clone-default":

src/options.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ INTERNAL: # Options for debugging the TruffleRuby implementation
166166
LOG_DYNAMIC_CONSTANT_LOOKUP: [constant-dynamic-lookup-log, boolean, false, Log source code positions where dynamic constant lookup is performed]
167167
LOG_PENDING_INTERRUPTS: [log-pending-interrupts, boolean, false, Log when executing pending interrupts]
168168
ROPE_PRINT_INTERN_STATS: [rope-print-intern-stats, boolean, false, Print interned rope stats at application exit]
169+
CEXTS_TO_NATIVE_STATS: [cexts-to-native-stats, boolean, false, Track the number of conversions of VALUEs to native and print the stats at application exit]
169170

170171
# Options to debug the implementation
171172
LAZY_BUILTINS: [lazy-builtins, boolean, LAZY_CALLTARGETS, Load builtin classes (core methods & primitives) lazily on first use]
@@ -198,10 +199,10 @@ INTERNAL: # Options for debugging the TruffleRuby implementation
198199
POW_CACHE: [integer-pow-cache, integer, DEFAULT_CACHE, Cache size for Integer#** with a constant exponent]
199200
RUBY_LIBRARY_CACHE: [ruby-library-cache, integer, DEFAULT_CACHE, Ruby Library cache size]
200201

201-
# Inline caches with a non-default size
202+
# Inline caches with a non-default size. When adding a new option here, update test/truffle/integration/limit-zero.sh
202203
THREAD_CACHE: [thread-cache, integer, ['!singleContext ? 0 : ', 1], Cache size of operations that depend on a particular thread]
203-
CONTEXT_SPECIFIC_IDENTITY_CACHE: [context-identity-cache, integer, ['!singleContext ? 0 : ', 1], Cache size for inline caches comparing by identity for context-specific objects]
204204
IDENTITY_CACHE: [identity-cache, integer, 1, Cache size for inline caches comparing by identity for context-independent objects]
205+
CONTEXT_SPECIFIC_IDENTITY_CACHE: [context-identity-cache, integer, ['!singleContext ? 0 : ', IDENTITY_CACHE], Cache size for inline caches comparing by identity for context-specific objects]
205206
CLASS_CACHE: [class-cache, integer, 3, .class and .metaclass cache size]
206207
ARRAY_DUP_CACHE: [array-dup-cache, integer, 3, Cache size for copying small arrays]
207208
ARRAY_STRATEGY_CACHE: [array-strategy-cache, integer, 4, Cache size for array strategies]
@@ -213,7 +214,6 @@ INTERNAL: # Options for debugging the TruffleRuby implementation
213214
PACK_UNROLL_LIMIT: [pack-unroll, integer, 4, 'If a pack or unpack expression has a loop less than this many iterations, unroll it']
214215
PACK_RECOVER_LOOP_MIN: [pack-recover, integer, 32, 'If a pack or unpack expression is longer than this, attempt to recover loops']
215216
CEXTS_MARKING_CACHE: [cexts-marking-cache, integer, 100, 'Number of objects converted to native handles before the marking service is run']
216-
CEXTS_TONATIVE_STATS: [cexts-tonative-stats, boolean, false, Track the number of conversions of VALUEs to native and print the stats at application exit]
217217
GLOBAL_VARIABLE_MAX_INVALIDATIONS: [global-variable-max-invalidations, integer, 1, Maximum number of times a global variable can be changed to be considered constant]
218218

219219
# Splitting and cloning, useful for debugging cloning

0 commit comments

Comments
 (0)