Skip to content

Commit 7afe792

Browse files
committed
Remove usages of @CachedContext or @CachedLanguage
1 parent 9531bae commit 7afe792

File tree

62 files changed

+429
-727
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+429
-727
lines changed

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,13 @@
1111

1212
import static org.truffleruby.core.symbol.CoreSymbols.idToIndex;
1313

14-
import com.oracle.truffle.api.dsl.CachedLanguage;
15-
import org.truffleruby.RubyContext;
16-
import org.truffleruby.RubyLanguage;
1714
import org.truffleruby.core.string.StringUtils;
1815
import org.truffleruby.core.symbol.CoreSymbols;
1916
import org.truffleruby.core.symbol.RubySymbol;
2017
import org.truffleruby.language.RubyBaseNode;
2118
import org.truffleruby.language.control.RaiseException;
2219

2320
import com.oracle.truffle.api.dsl.Cached;
24-
import com.oracle.truffle.api.dsl.CachedContext;
2521
import com.oracle.truffle.api.dsl.GenerateUncached;
2622
import com.oracle.truffle.api.dsl.ReportPolymorphism;
2723
import com.oracle.truffle.api.dsl.Specialization;
@@ -39,16 +35,14 @@ public static IDToSymbolNode create() {
3935

4036
@Specialization(guards = "isStaticSymbol(value)")
4137
protected Object unwrapStaticSymbol(long value,
42-
@CachedLanguage RubyLanguage language,
43-
@CachedContext(RubyLanguage.class) RubyContext context,
4438
@Cached BranchProfile errorProfile) {
4539
final int index = idToIndex(value);
46-
final RubySymbol symbol = language.coreSymbols.STATIC_SYMBOLS[index];
40+
final RubySymbol symbol = getLanguage().coreSymbols.STATIC_SYMBOLS[index];
4741
if (symbol == null) {
4842
errorProfile.enter();
4943
throw new RaiseException(
50-
context,
51-
context.getCoreExceptions().runtimeError(
44+
getContext(),
45+
coreExceptions().runtimeError(
5246
StringUtils.format("invalid static ID2SYM id: %d", value),
5347
this));
5448
}

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
1919
import com.oracle.truffle.api.nodes.ExplodeLoop;
2020
import com.oracle.truffle.api.profiles.LoopConditionProfile;
21-
import org.truffleruby.RubyContext;
2221
import org.truffleruby.RubyLanguage;
2322
import org.truffleruby.cext.UnwrapNodeGen.NativeToWrapperNodeGen;
2423
import org.truffleruby.cext.UnwrapNodeGen.ToWrapperNodeGen;
@@ -29,8 +28,6 @@
2928

3029
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
3130
import com.oracle.truffle.api.dsl.Cached;
32-
import com.oracle.truffle.api.dsl.CachedContext;
33-
import com.oracle.truffle.api.dsl.CachedLanguage;
3431
import com.oracle.truffle.api.dsl.Fallback;
3532
import com.oracle.truffle.api.dsl.GenerateUncached;
3633
import com.oracle.truffle.api.dsl.ImportStatic;
@@ -77,10 +74,10 @@ protected long unwrapTaggedLong(long handle) {
7774

7875
@Specialization(guards = "isTaggedObject(handle)")
7976
protected Object unwrapTaggedObject(long handle,
80-
@CachedContext(RubyLanguage.class) RubyContext context,
81-
@CachedLanguage RubyLanguage language,
8277
@Cached BranchProfile noHandleProfile) {
83-
final ValueWrapper wrapper = context.getValueWrapperManager().getWrapperFromHandleMap(handle, language);
78+
final ValueWrapper wrapper = getContext()
79+
.getValueWrapperManager()
80+
.getWrapperFromHandleMap(handle, getLanguage());
8481
if (wrapper == null) {
8582
noHandleProfile.enter();
8683
raiseError(handle);
@@ -138,10 +135,8 @@ protected ValueWrapper unwrapTaggedLong(long handle) {
138135
}
139136

140137
@Specialization(guards = "isTaggedObject(handle)")
141-
protected ValueWrapper unwrapTaggedObject(long handle,
142-
@CachedContext(RubyLanguage.class) RubyContext context,
143-
@CachedLanguage RubyLanguage language) {
144-
return context.getValueWrapperManager().getWrapperFromHandleMap(handle, language);
138+
protected ValueWrapper unwrapTaggedObject(long handle) {
139+
return getContext().getValueWrapperManager().getWrapperFromHandleMap(handle, getLanguage());
145140
}
146141

147142
@Fallback
@@ -279,15 +274,14 @@ protected Object longToWrapper(long value,
279274
@Specialization(guards = { "!isWrapper(value)", "values.isPointer(value)" }, limit = "getCacheLimit()")
280275
protected Object unwrapGeneric(Object value,
281276
@CachedLibrary("value") InteropLibrary values,
282-
@CachedContext(RubyLanguage.class) RubyContext context,
283277
@Cached UnwrapNativeNode unwrapNativeNode,
284278
@Cached BranchProfile unsupportedProfile) {
285279
long handle;
286280
try {
287281
handle = values.asPointer(value);
288282
} catch (UnsupportedMessageException e) {
289283
unsupportedProfile.enter();
290-
throw new RaiseException(context, context.getCoreExceptions().argumentError(e.getMessage(), this, e));
284+
throw new RaiseException(getContext(), coreExceptions().argumentError(e.getMessage(), this, e));
291285
}
292286
return unwrapNativeNode.execute(handle);
293287
}

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626

2727
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
2828
import com.oracle.truffle.api.dsl.Cached;
29-
import com.oracle.truffle.api.dsl.CachedContext;
30-
import com.oracle.truffle.api.dsl.CachedLanguage;
3129
import com.oracle.truffle.api.dsl.GenerateUncached;
3230
import com.oracle.truffle.api.dsl.Specialization;
3331
import com.oracle.truffle.api.interop.InteropLibrary;
@@ -334,16 +332,14 @@ public abstract static class GetHandleBlockHolderNode extends RubyBaseNode {
334332

335333
@Specialization(guards = "cachedThread == currentJavaThread(wrapper)", limit = "getCacheLimit()")
336334
protected HandleThreadData getHolderOnKnownThread(ValueWrapper wrapper,
337-
@CachedContext(RubyLanguage.class) RubyContext context,
338335
@Cached("currentJavaThread(wrapper)") Thread cachedThread,
339-
@Cached("getBlockHolder(wrapper, context)") HandleThreadData threadData) {
336+
@Cached("getBlockHolder(wrapper)") HandleThreadData threadData) {
340337
return threadData;
341338
}
342339

343340
@Specialization(replaces = "getHolderOnKnownThread")
344-
protected HandleThreadData getBlockHolder(ValueWrapper wrapper,
345-
@CachedContext(RubyLanguage.class) RubyContext context) {
346-
return context.getValueWrapperManager().getBlockHolder();
341+
protected HandleThreadData getBlockHolder(ValueWrapper wrapper) {
342+
return getContext().getValueWrapperManager().getBlockHolder();
347343
}
348344

349345
protected static Thread currentJavaThread(ValueWrapper wrapper) {
@@ -366,18 +362,14 @@ public abstract static class AllocateHandleNode extends RubyBaseNode {
366362

367363
@Specialization(guards = "!isSharedObject(wrapper)")
368364
protected long allocateHandleOnKnownThread(ValueWrapper wrapper,
369-
@CachedContext(RubyLanguage.class) RubyContext context,
370-
@CachedLanguage RubyLanguage language,
371365
@Cached GetHandleBlockHolderNode getBlockHolderNode) {
372-
return allocateHandle(wrapper, context, language, getBlockHolderNode.execute(wrapper), false);
366+
return allocateHandle(wrapper, getContext(), getLanguage(), getBlockHolderNode.execute(wrapper), false);
373367
}
374368

375369
@Specialization(guards = "isSharedObject(wrapper)")
376370
protected long allocateSharedHandleOnKnownThread(ValueWrapper wrapper,
377-
@CachedContext(RubyLanguage.class) RubyContext context,
378-
@CachedLanguage RubyLanguage language,
379371
@Cached GetHandleBlockHolderNode getBlockHolderNode) {
380-
return allocateHandle(wrapper, context, language, getBlockHolderNode.execute(wrapper), true);
372+
return allocateHandle(wrapper, getContext(), getLanguage(), getBlockHolderNode.execute(wrapper), true);
381373
}
382374

383375
protected static long allocateHandle(ValueWrapper wrapper, RubyContext context, RubyLanguage language,

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

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import com.oracle.truffle.api.memory.MemoryFence;
1616
import org.jcodings.specific.UTF8Encoding;
1717
import org.truffleruby.Layouts;
18-
import org.truffleruby.RubyContext;
19-
import org.truffleruby.RubyLanguage;
2018
import org.truffleruby.core.encoding.Encodings;
2119
import org.truffleruby.core.rope.RopeOperations;
2220
import org.truffleruby.language.ImmutableRubyObject;
@@ -28,7 +26,6 @@
2826
import org.truffleruby.language.control.RaiseException;
2927

3028
import com.oracle.truffle.api.dsl.Cached;
31-
import com.oracle.truffle.api.dsl.CachedContext;
3229
import com.oracle.truffle.api.dsl.GenerateUncached;
3330
import com.oracle.truffle.api.dsl.ImportStatic;
3431
import com.oracle.truffle.api.dsl.Specialization;
@@ -48,41 +45,38 @@ public static WrapNode create() {
4845

4946
@Specialization
5047
protected ValueWrapper wrapLong(long value,
51-
@Cached BranchProfile smallFixnumProfile,
52-
@CachedContext(RubyLanguage.class) RubyContext context) {
48+
@Cached BranchProfile smallFixnumProfile) {
5349
if (value >= ValueWrapperManager.MIN_FIXNUM_VALUE && value <= ValueWrapperManager.MAX_FIXNUM_VALUE) {
5450
smallFixnumProfile.enter();
5551
long val = (value << 1) | LONG_TAG;
5652
return new ValueWrapper(null, val, null);
5753
} else {
58-
return context.getValueWrapperManager().longWrapper(value);
54+
return getContext().getValueWrapperManager().longWrapper(value);
5955
}
6056
}
6157

6258
@Specialization
63-
protected ValueWrapper wrapDouble(double value,
64-
@CachedContext(RubyLanguage.class) RubyContext context) {
65-
return context.getValueWrapperManager().doubleWrapper(value);
59+
protected ValueWrapper wrapDouble(double value) {
60+
return getContext().getValueWrapperManager().doubleWrapper(value);
6661
}
6762

6863
@Specialization
69-
protected ValueWrapper wrapBoolean(boolean value,
70-
@CachedContext(RubyLanguage.class) RubyContext context) {
71-
return value ? context.getValueWrapperManager().trueWrapper : context.getValueWrapperManager().falseWrapper;
64+
protected ValueWrapper wrapBoolean(boolean value) {
65+
return value
66+
? getContext().getValueWrapperManager().trueWrapper
67+
: getContext().getValueWrapperManager().falseWrapper;
7268
}
7369

7470
@Specialization
75-
protected ValueWrapper wrapUndef(NotProvided value,
76-
@CachedContext(RubyLanguage.class) RubyContext context) {
77-
return context.getValueWrapperManager().undefWrapper;
71+
protected ValueWrapper wrapUndef(NotProvided value) {
72+
return getContext().getValueWrapperManager().undefWrapper;
7873
}
7974

8075
@Specialization
81-
protected ValueWrapper wrapWrappedValue(ValueWrapper value,
82-
@CachedContext(RubyLanguage.class) RubyContext context) {
76+
protected ValueWrapper wrapWrappedValue(ValueWrapper value) {
8377
throw new RaiseException(
84-
context,
85-
context.getCoreExceptions().argumentError(
78+
getContext(),
79+
coreExceptions().argumentError(
8680
RopeOperations.encodeAscii("Wrapping wrapped object", UTF8Encoding.INSTANCE),
8781
Encodings.UTF_8,
8882
this));
@@ -135,10 +129,9 @@ protected ValueWrapper wrapValue(RubyDynamicObject value,
135129
}
136130

137131
@Specialization(guards = "isForeignObject(value)")
138-
protected ValueWrapper wrapNonRubyObject(Object value,
139-
@CachedContext(RubyLanguage.class) RubyContext context) {
132+
protected ValueWrapper wrapNonRubyObject(Object value) {
140133
throw new RaiseException(
141-
context,
142-
context.getCoreExceptions().argumentError("Attempt to wrap something that isn't an Ruby object", this));
134+
getContext(),
135+
coreExceptions().argumentError("Attempt to wrap something that isn't an Ruby object", this));
143136
}
144137
}

src/main/java/org/truffleruby/core/MainNodes.java

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

1212
import com.oracle.truffle.api.RootCallTarget;
13-
import com.oracle.truffle.api.dsl.CachedContext;
1413
import com.oracle.truffle.api.dsl.GenerateUncached;
15-
import org.truffleruby.RubyContext;
16-
import org.truffleruby.RubyLanguage;
1714
import org.truffleruby.builtins.CoreMethod;
1815
import org.truffleruby.builtins.CoreModule;
1916
import org.truffleruby.core.inlined.AlwaysInlinedMethodNode;
@@ -38,9 +35,8 @@ public abstract class MainNodes {
3835
public abstract static class PublicNode extends AlwaysInlinedMethodNode {
3936
@Specialization
4037
protected Object forward(Frame callerFrame, Object self, Object[] args, Object block, RootCallTarget target,
41-
@Cached ModuleNodes.PublicNode publicNode,
42-
@CachedContext(RubyLanguage.class) RubyContext context) {
43-
return publicNode.execute(callerFrame, context.getCoreLibrary().objectClass, args, block, target);
38+
@Cached ModuleNodes.PublicNode publicNode) {
39+
return publicNode.execute(callerFrame, coreLibrary().objectClass, args, block, target);
4440
}
4541
}
4642

@@ -49,9 +45,8 @@ protected Object forward(Frame callerFrame, Object self, Object[] args, Object b
4945
public abstract static class PrivateNode extends AlwaysInlinedMethodNode {
5046
@Specialization
5147
protected Object forward(Frame callerFrame, Object self, Object[] args, Object block, RootCallTarget target,
52-
@Cached ModuleNodes.PrivateNode privateNode,
53-
@CachedContext(RubyLanguage.class) RubyContext context) {
54-
return privateNode.execute(callerFrame, context.getCoreLibrary().objectClass, args, block, target);
48+
@Cached ModuleNodes.PrivateNode privateNode) {
49+
return privateNode.execute(callerFrame, coreLibrary().objectClass, args, block, target);
5550
}
5651
}
5752

@@ -60,18 +55,17 @@ protected Object forward(Frame callerFrame, Object self, Object[] args, Object b
6055
public abstract static class MainUsingNode extends UsingNode {
6156
@Specialization
6257
protected Object mainUsing(Frame callerFrame, Object self, Object[] args, Object block, RootCallTarget target,
63-
@CachedContext(RubyLanguage.class) RubyContext context,
6458
@Cached BranchProfile errorProfile) {
6559
needCallerFrame(callerFrame, target);
6660
final Object refinementModule = args[0];
6761
final InternalMethod callerMethod = RubyArguments.getMethod(callerFrame);
6862
if (!isCalledFromTopLevel(callerMethod)) {
6963
errorProfile.enter();
7064
throw new RaiseException(
71-
context,
72-
context.getCoreExceptions().runtimeError("main.using is permitted only at toplevel", this));
65+
getContext(),
66+
coreExceptions().runtimeError("main.using is permitted only at toplevel", this));
7367
}
74-
using(context, callerFrame, refinementModule, errorProfile);
68+
using(callerFrame, refinementModule, errorProfile);
7569
return nil;
7670
}
7771

src/main/java/org/truffleruby/core/MarkingServiceNodes.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@
1111

1212
import java.util.ArrayList;
1313

14-
import org.truffleruby.RubyContext;
1514
import org.truffleruby.RubyLanguage;
1615
import org.truffleruby.core.MarkingService.MarkerThreadLocalData;
1716
import org.truffleruby.language.RubyBaseNode;
1817

1918
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
2019
import com.oracle.truffle.api.dsl.Cached;
21-
import com.oracle.truffle.api.dsl.CachedContext;
2220
import com.oracle.truffle.api.dsl.GenerateUncached;
2321
import com.oracle.truffle.api.dsl.Specialization;
2422

@@ -57,16 +55,14 @@ public final MarkerThreadLocalData execute() {
5755

5856
@Specialization(guards = "thread == currentJavaThread(dynamicParameter)", limit = "getCacheLimit()")
5957
protected MarkerThreadLocalData getDataOnKnownThread(Object dynamicParameter,
60-
@CachedContext(RubyLanguage.class) RubyContext context,
6158
@Cached("currentJavaThread(dynamicParameter)") Thread thread,
62-
@Cached("getData(dynamicParameter, context)") MarkerThreadLocalData data) {
59+
@Cached("getData(dynamicParameter)") MarkerThreadLocalData data) {
6360
return data;
6461
}
6562

6663
@Specialization(replaces = "getDataOnKnownThread")
67-
protected MarkerThreadLocalData getData(Object dynamicParameter,
68-
@CachedContext(RubyLanguage.class) RubyContext context) {
69-
return context.getMarkingService().getThreadLocalData();
64+
protected MarkerThreadLocalData getData(Object dynamicParameter) {
65+
return getContext().getMarkingService().getThreadLocalData();
7066
}
7167

7268
protected static Thread currentJavaThread(Object dynamicParameter) {

src/main/java/org/truffleruby/core/basicobject/BasicObjectNodes.java

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

1212
import com.oracle.truffle.api.RootCallTarget;
13-
import com.oracle.truffle.api.dsl.CachedLanguage;
1413
import com.oracle.truffle.api.dsl.Fallback;
1514
import com.oracle.truffle.api.object.Shape;
1615
import org.truffleruby.Layouts;
17-
import org.truffleruby.RubyContext;
1816
import org.truffleruby.RubyLanguage;
1917
import org.truffleruby.builtins.CoreMethod;
2018
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
@@ -71,7 +69,6 @@
7169
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
7270
import com.oracle.truffle.api.Truffle;
7371
import com.oracle.truffle.api.dsl.Cached;
74-
import com.oracle.truffle.api.dsl.CachedContext;
7572
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
7673
import com.oracle.truffle.api.dsl.GenerateUncached;
7774
import com.oracle.truffle.api.dsl.NodeChild;
@@ -224,12 +221,11 @@ protected RubyBignum objectID(double value) {
224221
}
225222

226223
@Specialization(guards = "!isNil(object)")
227-
protected long objectIDImmutable(ImmutableRubyObject object,
228-
@CachedLanguage RubyLanguage language) {
224+
protected long objectIDImmutable(ImmutableRubyObject object) {
229225
final long id = object.getObjectId();
230226

231227
if (id == 0) {
232-
final long newId = language.getNextObjectID();
228+
final long newId = getLanguage().getNextObjectID();
233229
object.setObjectId(newId);
234230
return newId;
235231
}
@@ -239,8 +235,7 @@ protected long objectIDImmutable(ImmutableRubyObject object,
239235

240236
@Specialization(limit = "getCacheLimit()")
241237
protected long objectID(RubyDynamicObject object,
242-
@CachedLibrary("object") DynamicObjectLibrary objectLibrary,
243-
@CachedContext(RubyLanguage.class) RubyContext context) {
238+
@CachedLibrary("object") DynamicObjectLibrary objectLibrary) {
244239
// Using the context here has the desirable effect that it checks the context is entered on this thread,
245240
// which is necessary to safely mutate DynamicObjects.
246241
final long id = ObjectSpaceManager.readObjectID(object, objectLibrary);
@@ -252,13 +247,13 @@ protected long objectID(RubyDynamicObject object,
252247
if (existingID != 0L) {
253248
return existingID;
254249
} else {
255-
final long newId = context.getObjectSpaceManager().getNextObjectID();
250+
final long newId = getContext().getObjectSpaceManager().getNextObjectID();
256251
objectLibrary.putLong(object, Layouts.OBJECT_ID_IDENTIFIER, newId);
257252
return newId;
258253
}
259254
}
260255
} else {
261-
final long newId = context.getObjectSpaceManager().getNextObjectID();
256+
final long newId = getContext().getObjectSpaceManager().getNextObjectID();
262257
objectLibrary.putLong(object, Layouts.OBJECT_ID_IDENTIFIER, newId);
263258
return newId;
264259
}

0 commit comments

Comments
 (0)