Skip to content

Commit 773ddc6

Browse files
committed
[GR-45042] Address truffle sharing warning
PullRequest: truffleruby/3764
2 parents ae5d5c7 + 1b6f294 commit 773ddc6

12 files changed

+129
-125
lines changed

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
import com.oracle.truffle.api.RootCallTarget;
122122
import com.oracle.truffle.api.Truffle;
123123
import com.oracle.truffle.api.dsl.Cached;
124+
import com.oracle.truffle.api.dsl.Cached.Shared;
124125
import com.oracle.truffle.api.dsl.CreateCast;
125126
import com.oracle.truffle.api.dsl.Fallback;
126127
import com.oracle.truffle.api.dsl.NodeChild;
@@ -956,8 +957,7 @@ protected RubyString rbStrUnlockTmp(RubyString string,
956957
}
957958

958959
@Specialization
959-
protected ImmutableRubyString rbStrUnlockTmpImmutable(ImmutableRubyString string,
960-
@Cached BranchProfile errorProfile) {
960+
protected ImmutableRubyString rbStrUnlockTmpImmutable(ImmutableRubyString string) {
961961
throw new RaiseException(getContext(),
962962
coreExceptions().runtimeError("temporal unlocking immutable string", this));
963963
}
@@ -1937,7 +1937,7 @@ public abstract static class RBSprintfFormatNode extends CoreMethodArrayArgument
19371937
"equalNode.execute(libFormat, format, cachedFormat, cachedEncoding)" },
19381938
limit = "2")
19391939
protected Object typesCached(VirtualFrame frame, Object format,
1940-
@Cached RubyStringLibrary libFormat,
1940+
@Cached @Shared RubyStringLibrary libFormat,
19411941
@Cached("asTruffleStringUncached(format)") TruffleString cachedFormat,
19421942
@Cached("libFormat.getEncoding(format)") RubyEncoding cachedEncoding,
19431943
@Cached("compileArgTypes(cachedFormat, cachedEncoding, byteArrayNode)") RubyArray cachedTypes,
@@ -1947,7 +1947,7 @@ protected Object typesCached(VirtualFrame frame, Object format,
19471947

19481948
@Specialization(guards = "libFormat.isRubyString(format)", limit = "1")
19491949
protected RubyArray typesUncached(VirtualFrame frame, Object format,
1950-
@Cached RubyStringLibrary libFormat) {
1950+
@Cached @Shared RubyStringLibrary libFormat) {
19511951
return compileArgTypes(libFormat.getTString(format), libFormat.getEncoding(format), byteArrayNode);
19521952
}
19531953

@@ -1978,11 +1978,8 @@ public abstract static class RBSprintfNode extends CoreMethodArrayArgumentsNode
19781978
"equalNode.execute(libFormat, format, cachedFormat, cachedEncoding)" },
19791979
limit = "2")
19801980
protected RubyString formatCached(Object format, Object stringReader, RubyArray argArray,
1981-
@Cached TranslateInteropExceptionNode translateInteropExceptionNode,
1982-
@Cached ArrayToObjectArrayNode arrayToObjectArrayNode,
1983-
@Cached WrapNode wrapNode,
1984-
@Cached UnwrapNode unwrapNode,
1985-
@Cached RubyStringLibrary libFormat,
1981+
@Cached @Shared ArrayToObjectArrayNode arrayToObjectArrayNode,
1982+
@Cached @Shared RubyStringLibrary libFormat,
19861983
@Cached("asTruffleStringUncached(format)") TruffleString cachedFormat,
19871984
@Cached("libFormat.getEncoding(format)") RubyEncoding cachedEncoding,
19881985
@Cached("cachedFormat.byteLength(cachedEncoding.tencoding)") int cachedFormatLength,
@@ -2004,12 +2001,9 @@ protected RubyString formatCached(Object format, Object stringReader, RubyArray
20042001
guards = "libFormat.isRubyString(format)",
20052002
replaces = "formatCached", limit = "1")
20062003
protected RubyString formatUncached(Object format, Object stringReader, RubyArray argArray,
2007-
@Cached TranslateInteropExceptionNode translateInteropExceptionNode,
2008-
@Cached WrapNode wrapNode,
2009-
@Cached UnwrapNode unwrapNode,
20102004
@Cached IndirectCallNode formatNode,
2011-
@Cached ArrayToObjectArrayNode arrayToObjectArrayNode,
2012-
@Cached RubyStringLibrary libFormat) {
2005+
@Cached @Shared ArrayToObjectArrayNode arrayToObjectArrayNode,
2006+
@Cached @Shared RubyStringLibrary libFormat) {
20132007
var tstring = libFormat.getTString(format);
20142008
var encoding = libFormat.getEncoding(format);
20152009
final Object[] arguments = arrayToObjectArrayNode.executeToObjectArray(argArray);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.truffleruby.language.RubyBaseNode;
1414

1515
import com.oracle.truffle.api.dsl.Cached;
16+
import com.oracle.truffle.api.dsl.Cached.Shared;
1617
import com.oracle.truffle.api.dsl.GenerateUncached;
1718
import com.oracle.truffle.api.dsl.ReportPolymorphism;
1819
import com.oracle.truffle.api.dsl.Specialization;
@@ -26,15 +27,15 @@ public abstract class SymbolToIDNode extends RubyBaseNode {
2627

2728
@Specialization(guards = "symbol == cachedSymbol", limit = "2")
2829
protected Object getIDCached(RubySymbol symbol,
29-
@Cached WrapNode wrapNode,
30+
@Cached @Shared WrapNode wrapNode,
3031
@Cached("symbol") RubySymbol cachedSymbol,
3132
@Cached("getID(cachedSymbol, wrapNode)") Object cachedID) {
3233
return cachedID;
3334
}
3435

3536
@Specialization(replaces = "getIDCached")
3637
protected Object getIDUncached(RubySymbol symbol,
37-
@Cached WrapNode wrapNode,
38+
@Cached @Shared WrapNode wrapNode,
3839
@Cached ConditionProfile staticSymbolProfile) {
3940
if (staticSymbolProfile.profile(symbol.getId() != RubySymbol.UNASSIGNED_ID)) {
4041
return symbol.getId();

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
2727
import com.oracle.truffle.api.dsl.Cached;
28+
import com.oracle.truffle.api.dsl.Cached.Shared;
29+
import com.oracle.truffle.api.dsl.Cached.Exclusive;
2830
import com.oracle.truffle.api.dsl.Fallback;
2931
import com.oracle.truffle.api.dsl.GenerateUncached;
3032
import com.oracle.truffle.api.dsl.ImportStatic;
@@ -152,14 +154,14 @@ protected ValueWrapper wrappedValueWrapper(ValueWrapper value) {
152154

153155
@Specialization
154156
protected ValueWrapper longToWrapper(long value,
155-
@Cached NativeToWrapperNode nativeToWrapperNode) {
157+
@Cached @Shared NativeToWrapperNode nativeToWrapperNode) {
156158
return nativeToWrapperNode.execute(value);
157159
}
158160

159161
@Specialization(guards = { "!isWrapper(value)", "values.isPointer(value)" }, limit = "getCacheLimit()")
160162
protected ValueWrapper genericToWrapper(Object value,
161163
@CachedLibrary("value") InteropLibrary values,
162-
@Cached NativeToWrapperNode nativeToWrapperNode,
164+
@Cached @Shared NativeToWrapperNode nativeToWrapperNode,
163165
@Cached BranchProfile unsupportedProfile) {
164166
long handle;
165167
try {
@@ -189,7 +191,7 @@ protected Object[] unwrapCArrayExplode(Object cArray,
189191
@CachedLibrary("cArray") InteropLibrary interop,
190192
@Bind("getArraySize(cArray, interop)") int size,
191193
@Cached("size") int cachedSize,
192-
@Cached UnwrapNode unwrapNode) {
194+
@Cached @Shared UnwrapNode unwrapNode) {
193195
final Object[] store = new Object[cachedSize];
194196
for (int i = 0; i < cachedSize; i++) {
195197
final Object cValue = readArrayElement(cArray, interop, i);
@@ -202,7 +204,7 @@ protected Object[] unwrapCArrayExplode(Object cArray,
202204
protected Object[] unwrapCArray(Object cArray,
203205
@CachedLibrary("cArray") InteropLibrary interop,
204206
@Bind("getArraySize(cArray, interop)") int size,
205-
@Cached UnwrapNode unwrapNode,
207+
@Cached @Shared UnwrapNode unwrapNode,
206208
@Cached LoopConditionProfile loopProfile) {
207209
final Object[] store = new Object[size];
208210
int i = 0;
@@ -249,14 +251,14 @@ protected long unwrapValueTaggedLong(ValueWrapper value) {
249251

250252
@Specialization
251253
protected Object longToWrapper(long value,
252-
@Cached UnwrapNativeNode unwrapNode) {
254+
@Cached @Exclusive UnwrapNativeNode unwrapNode) {
253255
return unwrapNode.execute(value);
254256
}
255257

256258
@Specialization(guards = { "!isWrapper(value)", "values.isPointer(value)" }, limit = "getCacheLimit()")
257259
protected Object unwrapGeneric(Object value,
258260
@CachedLibrary("value") InteropLibrary values,
259-
@Cached UnwrapNativeNode unwrapNativeNode,
261+
@Cached @Exclusive UnwrapNativeNode unwrapNativeNode,
260262
@Cached BranchProfile unsupportedProfile) {
261263
long handle;
262264
try {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.truffleruby.language.control.RaiseException;
2525

2626
import com.oracle.truffle.api.dsl.Cached;
27+
import com.oracle.truffle.api.dsl.Cached.Exclusive;
28+
import com.oracle.truffle.api.dsl.Cached.Shared;
2729
import com.oracle.truffle.api.dsl.GenerateUncached;
2830
import com.oracle.truffle.api.dsl.Specialization;
2931
import com.oracle.truffle.api.library.CachedLibrary;
@@ -44,7 +46,7 @@ public static WrapNode create() {
4446

4547
@Specialization
4648
protected ValueWrapper wrapLong(long value,
47-
@Cached BranchProfile smallFixnumProfile) {
49+
@Cached @Exclusive BranchProfile smallFixnumProfile) {
4850
if (value >= ValueWrapperManager.MIN_FIXNUM_VALUE && value <= ValueWrapperManager.MAX_FIXNUM_VALUE) {
4951
smallFixnumProfile.enter();
5052
long val = (value << 1) | LONG_TAG;
@@ -85,7 +87,7 @@ protected ValueWrapper wrapNil(Nil value) {
8587

8688
@Specialization(guards = "!isNil(value)")
8789
protected ValueWrapper wrapImmutable(ImmutableRubyObject value,
88-
@Cached BranchProfile noHandleProfile) {
90+
@Cached @Shared BranchProfile noHandleProfile) {
8991
ValueWrapper wrapper = value.getValueWrapper();
9092
if (wrapper == null) {
9193
noHandleProfile.enter();
@@ -106,7 +108,7 @@ protected ValueWrapper wrapImmutable(ImmutableRubyObject value,
106108
@Specialization(limit = "getDynamicObjectCacheLimit()")
107109
protected ValueWrapper wrapValue(RubyDynamicObject value,
108110
@CachedLibrary("value") DynamicObjectLibrary objectLibrary,
109-
@Cached BranchProfile noHandleProfile) {
111+
@Cached @Shared BranchProfile noHandleProfile) {
110112
ValueWrapper wrapper = (ValueWrapper) objectLibrary.getOrDefault(value, Layouts.VALUE_WRAPPER_IDENTIFIER, null);
111113
if (wrapper == null) {
112114
noHandleProfile.enter();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@SuppressPackageWarnings({ "truffle-sharing", "truffle-inlining" })
1+
@SuppressPackageWarnings({ "truffle-inlining" })
22
package org.truffleruby.cext;
33

44
import com.oracle.truffle.api.dsl.SuppressPackageWarnings;

src/main/java/org/truffleruby/core/array/ArrayEnsureCapacityNode.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import com.oracle.truffle.api.dsl.Bind;
1717
import com.oracle.truffle.api.dsl.Cached;
18+
import com.oracle.truffle.api.dsl.Cached.Shared;
1819
import com.oracle.truffle.api.dsl.ImportStatic;
1920
import com.oracle.truffle.api.dsl.Specialization;
2021
import com.oracle.truffle.api.library.CachedLibrary;
@@ -28,7 +29,7 @@ public abstract class ArrayEnsureCapacityNode extends RubyBaseNode {
2829
protected Object ensureCapacityAndMakeMutable(RubyArray array, int requiredCapacity,
2930
@Bind("array.getStore()") Object store,
3031
@CachedLibrary("store") ArrayStoreLibrary stores,
31-
@Cached CountingConditionProfile extendProfile) {
32+
@Cached @Shared CountingConditionProfile extendProfile) {
3233
final int currentCapacity = stores.capacity(store);
3334
final int capacity;
3435
if (extendProfile.profile(currentCapacity < requiredCapacity)) {
@@ -47,7 +48,7 @@ protected Object ensureCapacityAndMakeMutable(RubyArray array, int requiredCapac
4748
protected Object ensureCapacity(RubyArray array, int requiredCapacity,
4849
@Bind("array.getStore()") Object store,
4950
@CachedLibrary("store") ArrayStoreLibrary stores,
50-
@Cached CountingConditionProfile extendProfile) {
51+
@Cached @Shared CountingConditionProfile extendProfile) {
5152
final int length = stores.capacity(store);
5253
if (extendProfile.profile(length < requiredCapacity)) {
5354
final int capacity = ArrayUtils.capacity(getLanguage(), length, requiredCapacity);

0 commit comments

Comments
 (0)