Skip to content

Commit 97cf7b1

Browse files
horakivoeregon
authored andcommitted
[GR-17457] Fix order of @cached and @Shared/@exclusive
PullRequest: truffleruby/3971
2 parents ade4b8e + aa4853d commit 97cf7b1

26 files changed

+256
-248
lines changed

src/main/.checkstyle_checks.xml

+8
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,14 @@
269269
<property name="format" value="@CreateCast"/>
270270
<property name="message" value="Do not use @CreateCast. Use DSL inlining nodes instead."/>
271271
</module>
272+
<module name="RegexpSinglelineJava">
273+
<property name="format" value="@Shared @Cached"/>
274+
<property name="message" value="Wrong order of annotations. The correct order is @Cached @Shared."/>
275+
</module>
276+
<module name="RegexpSinglelineJava">
277+
<property name="format" value="@Exclusive @Cached"/>
278+
<property name="message" value="Wrong order of annotations. The correct order is @Cached @Exclusive."/>
279+
</module>
272280
<module name="IllegalType">
273281
<!-- Use PrintStream instead of PrintWriter, PrintWriter does not consistently flush, even when writing \n.-->
274282
<property name="illegalClassNames" value="PrintWriter"/>

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ void nothingToMark(ExtensionCallStack stack) {
9494

9595
@Specialization(guards = "stack.hasSingleMarkObject()")
9696
void markSingleObject(ExtensionCallStack stack,
97-
@Shared @Cached DispatchNode callNode) {
97+
@Cached @Shared DispatchNode callNode) {
9898
ValueWrapper value = stack.getSingleMarkObject();
9999
callNode.call(getContext().getCoreLibrary().truffleCExtModule, "run_marker", value.getObject());
100100
}
101101

102102
@TruffleBoundary
103103
@Specialization(guards = { "stack.hasMarkObjects()", "!stack.hasSingleMarkObject()" })
104104
void marksToRun(ExtensionCallStack stack,
105-
@Shared @Cached DispatchNode callNode) {
105+
@Cached @Shared DispatchNode callNode) {
106106
// Run the markers...
107107
var valuesForMarking = stack.getMarkOnExitObjects();
108108
// Push a new stack frame because we should

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,13 @@ public abstract static class MinNode extends PrimitiveArrayArgumentsNode {
550550

551551
@Specialization
552552
int min(int a, int b,
553-
@Shared @Cached InlinedConditionProfile profile) {
553+
@Cached @Shared InlinedConditionProfile profile) {
554554
return profile.profile(this, a < b) ? a : b;
555555
}
556556

557557
@Specialization
558558
long min(long a, long b,
559-
@Shared @Cached InlinedConditionProfile profile) {
559+
@Cached @Shared InlinedConditionProfile profile) {
560560
return profile.profile(this, a < b) ? a : b;
561561
}
562562

@@ -567,13 +567,13 @@ public abstract static class MaxNode extends PrimitiveArrayArgumentsNode {
567567

568568
@Specialization
569569
int max(int a, int b,
570-
@Shared @Cached InlinedConditionProfile profile) {
570+
@Cached @Shared InlinedConditionProfile profile) {
571571
return profile.profile(this, a > b) ? a : b;
572572
}
573573

574574
@Specialization
575575
long max(long a, long b,
576-
@Shared @Cached InlinedConditionProfile profile) {
576+
@Cached @Shared InlinedConditionProfile profile) {
577577
return profile.profile(this, a > b) ? a : b;
578578
}
579579

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ public abstract static class LogNode extends CoreMethodArrayArgumentsNode {
236236

237237
@Specialization(guards = { "strings.isRubyString(message)", "level == cachedLevel" }, limit = "3")
238238
Object logCached(RubySymbol level, Object message,
239-
@Shared @Cached RubyStringLibrary strings,
240-
@Shared @Cached ToJavaStringNode toJavaStringNode,
239+
@Cached @Shared RubyStringLibrary strings,
240+
@Cached @Shared ToJavaStringNode toJavaStringNode,
241241
@Cached("level") RubySymbol cachedLevel,
242242
@Cached("getLevel(cachedLevel)") Level javaLevel) {
243243
log(javaLevel, toJavaStringNode.execute(this, message));
@@ -246,8 +246,8 @@ Object logCached(RubySymbol level, Object message,
246246

247247
@Specialization(guards = "strings.isRubyString(message)", replaces = "logCached")
248248
Object log(RubySymbol level, Object message,
249-
@Shared @Cached RubyStringLibrary strings,
250-
@Shared @Cached ToJavaStringNode toJavaStringNode) {
249+
@Cached @Shared RubyStringLibrary strings,
250+
@Cached @Shared ToJavaStringNode toJavaStringNode) {
251251
log(getLevel(level), toJavaStringNode.execute(this, message));
252252
return nil;
253253
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ public abstract static class VMWatchSignalNode extends PrimitiveArrayArgumentsNo
278278
@Specialization(guards = { "libSignalString.isRubyString(signalString)", "libAction.isRubyString(action)" },
279279
limit = "1")
280280
boolean watchSignalString(Object signalString, boolean isRubyDefaultHandler, Object action,
281-
@Shared @Cached RubyStringLibrary libSignalString,
282-
@Exclusive @Cached RubyStringLibrary libAction) {
281+
@Cached @Shared RubyStringLibrary libSignalString,
282+
@Cached @Exclusive RubyStringLibrary libAction) {
283283
final String actionString = RubyGuards.getJavaString(action);
284284
final String signalName = RubyGuards.getJavaString(signalString);
285285

@@ -298,7 +298,7 @@ boolean watchSignalString(Object signalString, boolean isRubyDefaultHandler, Obj
298298
@TruffleBoundary
299299
@Specialization(guards = "libSignalString.isRubyString(signalString)")
300300
boolean watchSignalProc(Object signalString, boolean isRubyDefaultHandler, RubyProc proc,
301-
@Shared @Cached RubyStringLibrary libSignalString) {
301+
@Cached @Shared RubyStringLibrary libSignalString) {
302302
final RubyContext context = getContext();
303303

304304
if (getLanguage().getCurrentThread() != context.getThreadManager().getRootThread()) {

src/main/java/org/truffleruby/core/array/library/NativeArrayStorage.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static String toString(NativeArrayStorage storage) {
9393

9494
@ExportMessage
9595
protected Object read(int index,
96-
@Shared @Cached UnwrapNode unwrapNode,
96+
@Cached @Shared UnwrapNode unwrapNode,
9797
@Bind("$node") Node node) {
9898
return unwrapNode.execute(node, readElement(index));
9999
}
@@ -141,7 +141,7 @@ protected NativeArrayStorage expand(int newCapacity,
141141

142142
@ExportMessage
143143
protected Object[] boxedCopyOfRange(int start, int length,
144-
@Shared @Cached UnwrapNode unwrapNode,
144+
@Cached @Shared UnwrapNode unwrapNode,
145145
@Bind("$node") Node node) {
146146
Object[] newStore = new Object[length];
147147
for (int i = 0; i < length; i++) {
@@ -208,7 +208,7 @@ static void fill(NativeArrayStorage store, int start, int length, Object value,
208208

209209
@ExportMessage
210210
protected Object[] toJavaArrayCopy(int size,
211-
@Shared @Cached UnwrapNode unwrapNode,
211+
@Cached @Shared UnwrapNode unwrapNode,
212212
@Bind("$node") Node node) {
213213
Object[] newStore = new Object[size];
214214
assert size >= length;

src/main/java/org/truffleruby/core/array/library/SharedArrayStorage.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected Object read(int index,
7676

7777
@ExportMessage
7878
protected void write(int index, Object value,
79-
@Shared @Cached WriteBarrierNode writeBarrierNode,
79+
@Cached @Shared WriteBarrierNode writeBarrierNode,
8080
@CachedLibrary("this.storage") ArrayStoreLibrary stores,
8181
@Bind("$node") Node node) {
8282
writeBarrierNode.execute(node, value);
@@ -85,7 +85,7 @@ protected void write(int index, Object value,
8585

8686
@ExportMessage
8787
protected void fill(int start, int length, Object value,
88-
@Shared @Cached WriteBarrierNode writeBarrierNode,
88+
@Cached @Shared WriteBarrierNode writeBarrierNode,
8989
@CachedLibrary("this.storage") ArrayStoreLibrary stores,
9090
@Bind("$node") Node node) {
9191
writeBarrierNode.execute(node, value);

src/main/java/org/truffleruby/core/hash/HashNodes.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ RubyHash initialize(RubyHash hash, NotProvided defaultValue, Nil block) {
382382

383383
@Specialization
384384
RubyHash initialize(RubyHash hash, NotProvided defaultValue, RubyProc block,
385-
@Shared @Cached PropagateSharingNode propagateSharingNode) {
385+
@Cached @Shared PropagateSharingNode propagateSharingNode) {
386386
assert HashStoreLibrary.verify(hash);
387387
hash.defaultValue = nil;
388388
propagateSharingNode.execute(this, hash, block);
@@ -392,7 +392,7 @@ RubyHash initialize(RubyHash hash, NotProvided defaultValue, RubyProc block,
392392

393393
@Specialization(guards = "wasProvided(defaultValue)")
394394
RubyHash initialize(RubyHash hash, Object defaultValue, Nil block,
395-
@Shared @Cached PropagateSharingNode propagateSharingNode) {
395+
@Cached @Shared PropagateSharingNode propagateSharingNode) {
396396
assert HashStoreLibrary.verify(hash);
397397
propagateSharingNode.execute(this, hash, defaultValue);
398398
hash.defaultValue = defaultValue;

src/main/java/org/truffleruby/core/hash/HashingNodes.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ static int hashBignum(Node node, RubyBignum value) {
100100

101101
@Specialization
102102
static int hashString(Node node, RubyString value,
103-
@Shared @Cached StringHelperNodes.HashStringNode stringHashNode) {
103+
@Cached @Shared StringHelperNodes.HashStringNode stringHashNode) {
104104
return (int) stringHashNode.execute(node, value);
105105
}
106106

107107
@Specialization
108108
static int hashImmutableString(Node node, ImmutableRubyString value,
109-
@Shared @Cached StringHelperNodes.HashStringNode stringHashNode) {
109+
@Cached @Shared StringHelperNodes.HashStringNode stringHashNode) {
110110
return (int) stringHashNode.execute(node, value);
111111
}
112112

src/main/java/org/truffleruby/core/hash/RubyHash.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public void writeHashEntry(Object key, Object value,
186186
@ExportMessage
187187
public void removeHashEntry(Object key,
188188
@Cached @Exclusive DispatchNode delete,
189-
@Shared @Cached IsFrozenNode isFrozenNode,
189+
@Cached @Shared IsFrozenNode isFrozenNode,
190190
@CachedLibrary("this") InteropLibrary interop,
191191
@Cached @Shared ForeignToRubyNode toRuby,
192192
@Bind("$node") Node node)

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ RubyProc lambdaFromProcBlock(RubyProc block) {
11731173

11741174
@Specialization(guards = { "!isLiteralBlock(block)", "block.isProc()" })
11751175
RubyProc lambdaFromExistingProc(RubyProc block,
1176-
@Cached("new()") WarnNode warnNode) {
1176+
@Cached WarnNode warnNode) {
11771177
if (warnNode.shouldWarnForDeprecation()) {
11781178
warnNode.warningMessage(
11791179
getContext().getCallStack().getTopMostUserSourceSection(),
@@ -1885,7 +1885,7 @@ boolean setCategory(RubySymbol category, boolean newValue) {
18851885
public abstract static class WarnGivenBlockNotUsedNode extends PrimitiveNode {
18861886
@Specialization
18871887
Object warn(
1888-
@Cached("new()") WarnNode warnNode) {
1888+
@Cached WarnNode warnNode) {
18891889
if (warnNode.shouldWarn()) {
18901890
warnNode.warningMessage(
18911891
getContext().getCallStack().getTopMostUserSourceSection(),
@@ -1901,7 +1901,7 @@ Object warn(
19011901
public abstract static class WarnBlockSupersedesDefaultValueArgumentNode extends PrimitiveNode {
19021902
@Specialization
19031903
Object warn(
1904-
@Cached("new()") WarnNode warnNode) {
1904+
@Cached WarnNode warnNode) {
19051905
if (warnNode.shouldWarn()) {
19061906
warnNode.warningMessage(
19071907
getContext().getCallStack().getTopMostUserSourceSection(),

src/main/java/org/truffleruby/core/mutex/ConditionVariableNodes.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public abstract static class WaitNode extends PrimitiveArrayArgumentsNode {
6161

6262
@Specialization
6363
RubyConditionVariable noTimeout(RubyConditionVariable condVar, RubyMutex mutex, Nil timeout,
64-
@Shared @Cached InlinedBranchProfile errorProfile) {
64+
@Cached @Shared InlinedBranchProfile errorProfile) {
6565
final RubyThread thread = getLanguage().getCurrentThread();
6666
final ReentrantLock mutexLock = mutex.lock;
6767

@@ -72,7 +72,7 @@ RubyConditionVariable noTimeout(RubyConditionVariable condVar, RubyMutex mutex,
7272

7373
@Specialization
7474
RubyConditionVariable withTimeout(RubyConditionVariable condVar, RubyMutex mutex, long timeout,
75-
@Shared @Cached InlinedBranchProfile errorProfile) {
75+
@Cached @Shared InlinedBranchProfile errorProfile) {
7676
final RubyThread thread = getLanguage().getCurrentThread();
7777
final ReentrantLock mutexLock = mutex.lock;
7878

src/main/java/org/truffleruby/core/numeric/FloatNodes.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -409,13 +409,13 @@ Object compareSecondNaN(Object a, double b) {
409409

410410
@Specialization(guards = { "!isNaN(a)", "!isNaN(b)" })
411411
int compareDoubleDouble(double a, double b,
412-
@Shared @Cached InlinedConditionProfile equalProfile) {
412+
@Cached @Shared InlinedConditionProfile equalProfile) {
413413
return compareDoubles(a, b, equalProfile, this);
414414
}
415415

416416
@Specialization(guards = "!isNaN(a)")
417417
int compareDoubleLong(double a, long b,
418-
@Shared @Cached InlinedConditionProfile equalProfile) {
418+
@Cached @Shared InlinedConditionProfile equalProfile) {
419419
return compareDoubles(a, b, equalProfile, this);
420420
}
421421

0 commit comments

Comments
 (0)