Skip to content

Commit 9fe7929

Browse files
committed
PropagateSharingNode supports DSL inlining
1 parent e1fe7ac commit 9fe7929

File tree

8 files changed

+43
-38
lines changed

8 files changed

+43
-38
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,10 +2235,11 @@ protected RubyArray stealStorageNoOp(RubyArray array, RubyArray other) {
22352235
}
22362236

22372237
@Specialization(guards = "array != other")
2238-
protected RubyArray stealStorage(RubyArray array, RubyArray other,
2238+
protected static RubyArray stealStorage(RubyArray array, RubyArray other,
22392239
@CachedLibrary(limit = "2") ArrayStoreLibrary stores,
2240-
@Cached PropagateSharingNode propagateSharingNode) {
2241-
propagateSharingNode.executePropagate(array, other);
2240+
@Cached PropagateSharingNode propagateSharingNode,
2241+
@Bind("this") Node node) {
2242+
propagateSharingNode.execute(node, array, other);
22422243

22432244
final int size = other.size;
22442245
final Object store = other.getStore();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ protected RubyHash initialize(RubyHash hash, NotProvided defaultValue, RubyProc
385385
@Shared @Cached PropagateSharingNode propagateSharingNode) {
386386
assert HashStoreLibrary.verify(hash);
387387
hash.defaultValue = nil;
388-
propagateSharingNode.executePropagate(hash, block);
388+
propagateSharingNode.execute(this, hash, block);
389389
hash.defaultBlock = block;
390390
return hash;
391391
}
@@ -394,7 +394,7 @@ protected RubyHash initialize(RubyHash hash, NotProvided defaultValue, RubyProc
394394
protected RubyHash initialize(RubyHash hash, Object defaultValue, Nil block,
395395
@Shared @Cached PropagateSharingNode propagateSharingNode) {
396396
assert HashStoreLibrary.verify(hash);
397-
propagateSharingNode.executePropagate(hash, defaultValue);
397+
propagateSharingNode.execute(this, hash, defaultValue);
398398
hash.defaultValue = defaultValue;
399399
hash.defaultBlock = nil;
400400
return hash;
@@ -480,7 +480,7 @@ public abstract static class SetDefaultProcNode extends PrimitiveArrayArgumentsN
480480
@Specialization
481481
protected RubyProc setDefaultProc(RubyHash hash, RubyProc defaultProc,
482482
@Cached PropagateSharingNode propagateSharingNode) {
483-
propagateSharingNode.executePropagate(hash, defaultProc);
483+
propagateSharingNode.execute(this, hash, defaultProc);
484484
hash.defaultValue = nil;
485485
hash.defaultBlock = defaultProc;
486486
return defaultProc;
@@ -500,7 +500,7 @@ public abstract static class SetDefaultValueNode extends CoreMethodArrayArgument
500500
@Specialization
501501
protected Object setDefault(RubyHash hash, Object defaultValue,
502502
@Cached PropagateSharingNode propagateSharingNode) {
503-
propagateSharingNode.executePropagate(hash, defaultValue);
503+
propagateSharingNode.execute(this, hash, defaultValue);
504504

505505
hash.defaultValue = defaultValue;
506506
hash.defaultBlock = nil;

src/main/java/org/truffleruby/core/hash/library/BucketsHashStore.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ protected boolean set(RubyHash hash, Object key, Object value, boolean byIdentit
248248

249249
final Object key2 = freezeHashKeyIfNeeded.executeFreezeIfNeeded(key, byIdentity);
250250

251-
propagateSharingKey.executePropagate(hash, key2);
252-
propagateSharingValue.executePropagate(hash, value);
251+
propagateSharingKey.execute(node, hash, key2);
252+
propagateSharingValue.execute(node, hash, value);
253253

254254
final Entry[] entries = this.entries;
255255
final HashLookupResult result = lookup.execute(hash, entries, key2);
@@ -380,12 +380,13 @@ protected Object eachEntrySafe(RubyHash hash, EachEntryCallback callback, Object
380380
@TruffleBoundary
381381
@ExportMessage
382382
protected void replace(RubyHash hash, RubyHash dest,
383-
@Cached @Exclusive PropagateSharingNode propagateSharing) {
383+
@Cached @Exclusive PropagateSharingNode propagateSharing,
384+
@Bind("$node") Node node) {
384385
if (hash == dest) {
385386
return;
386387
}
387388

388-
propagateSharing.executePropagate(dest, hash);
389+
propagateSharing.execute(node, dest, hash);
389390
assert verify(hash);
390391

391392
final Entry[] entries = ((BucketsHashStore) hash.store).entries;

src/main/java/org/truffleruby/core/hash/library/EmptyHashStore.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111

1212
import com.oracle.truffle.api.CompilerDirectives;
1313
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
14+
import com.oracle.truffle.api.dsl.Bind;
1415
import com.oracle.truffle.api.dsl.Cached;
1516
import com.oracle.truffle.api.dsl.GenerateUncached;
1617
import com.oracle.truffle.api.frame.Frame;
1718
import com.oracle.truffle.api.frame.VirtualFrame;
1819
import com.oracle.truffle.api.library.CachedLibrary;
1920
import com.oracle.truffle.api.library.ExportLibrary;
2021
import com.oracle.truffle.api.library.ExportMessage;
22+
import com.oracle.truffle.api.nodes.Node;
2123
import org.truffleruby.collections.PEBiFunction;
2224
import org.truffleruby.core.array.RubyArray;
2325
import org.truffleruby.core.hash.HashLiteralNode;
@@ -76,11 +78,12 @@ protected Object eachEntrySafe(RubyHash hash, EachEntryCallback callback, Object
7678

7779
@ExportMessage
7880
protected void replace(RubyHash hash, RubyHash dest,
79-
@Cached PropagateSharingNode propagateSharing) {
81+
@Cached PropagateSharingNode propagateSharing,
82+
@Bind("$node") Node node) {
8083
if (hash == dest) {
8184
return;
8285
}
83-
propagateSharing.executePropagate(dest, hash);
86+
propagateSharing.execute(node, dest, hash);
8487
dest.store = EmptyHashStore.NULL_HASH_STORE;
8588
dest.size = 0;
8689
dest.defaultBlock = hash.defaultBlock;

src/main/java/org/truffleruby/core/hash/library/PackedHashStoreLibrary.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,12 @@ protected static boolean setFirst(Object[] store, RubyHash hash, Object key, Obj
176176
@Cached @Shared FreezeHashKeyIfNeededNode freezeHashKeyIfNeeded,
177177
@Cached @Shared HashingNodes.ToHash hashNode,
178178
@Cached @Shared PropagateSharingNode propagateSharingKey,
179-
@Cached @Shared PropagateSharingNode propagateSharingValue) {
179+
@Cached @Shared PropagateSharingNode propagateSharingValue,
180+
@Bind("this") Node node) {
180181

181182
final Object key2 = freezeHashKeyIfNeeded.executeFreezeIfNeeded(key, byIdentity);
182-
propagateSharingKey.executePropagate(hash, key2);
183-
propagateSharingValue.executePropagate(hash, value);
183+
propagateSharingKey.execute(node, hash, key2);
184+
propagateSharingValue.execute(node, hash, value);
184185
setHashedKeyValue(store, 0, hashNode.execute(key2, byIdentity), key2, value);
185186
hash.size = 1;
186187
assert verify(store, hash);
@@ -202,8 +203,8 @@ protected static boolean set(Object[] store, RubyHash hash, Object key, Object v
202203
final int size = hash.size;
203204
final Object key2 = freezeHashKeyIfNeeded.executeFreezeIfNeeded(key, byIdentity);
204205
final int hashed = hashNode.execute(key2, byIdentity);
205-
propagateSharingKey.executePropagate(hash, key2);
206-
propagateSharingValue.executePropagate(hash, value);
206+
propagateSharingKey.execute(node, hash, key2);
207+
propagateSharingValue.execute(node, hash, value);
207208

208209
// written very carefully to allow PE
209210
for (int n = 0; n < MAX_ENTRIES; n++) {
@@ -307,12 +308,13 @@ protected static Object eachEntrySafe(Object[] store, RubyHash hash, EachEntryCa
307308

308309
@ExportMessage
309310
protected static void replace(Object[] store, RubyHash hash, RubyHash dest,
310-
@Cached @Exclusive PropagateSharingNode propagateSharing) {
311+
@Cached @Exclusive PropagateSharingNode propagateSharing,
312+
@Bind("$node") Node node) {
311313
if (hash == dest) {
312314
return;
313315
}
314316

315-
propagateSharing.executePropagate(dest, hash);
317+
propagateSharing.execute(node, dest, hash);
316318

317319
Object storeCopy = copyStore(store);
318320
int size = hash.size;

src/main/java/org/truffleruby/core/queue/QueueNodes.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,12 @@ protected RubyQueue allocate(RubyClass rubyClass) {
5252
@CoreMethod(names = { "push", "<<", "enq" }, required = 1)
5353
public abstract static class PushNode extends CoreMethodArrayArgumentsNode {
5454

55-
@Child private PropagateSharingNode propagateSharingNode = PropagateSharingNode.create();
56-
5755
@Specialization
58-
protected RubyQueue push(RubyQueue self, final Object value) {
56+
protected RubyQueue push(RubyQueue self, final Object value,
57+
@Cached PropagateSharingNode propagateSharingNode) {
5958
final UnsizedQueue queue = self.queue;
6059

61-
propagateSharingNode.executePropagate(self, value);
60+
propagateSharingNode.execute(this, self, value);
6261

6362
if (queue.add(value)) {
6463
return self;

src/main/java/org/truffleruby/core/queue/SizedQueueNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ protected static RubySizedQueue pushBlocking(
131131
@Cached @Shared PropagateSharingNode propagateSharingNode) {
132132
final SizedQueue queue = self.queue;
133133

134-
propagateSharingNode.executePropagate(self, value);
134+
propagateSharingNode.execute(node, self, value);
135135
doPushBlocking(node, value, queue);
136136

137137
return self;
@@ -155,7 +155,7 @@ protected static RubySizedQueue pushNonBlock(
155155
@Cached InlinedBranchProfile errorProfile) {
156156
final SizedQueue queue = self.queue;
157157

158-
propagateSharingNode.executePropagate(self, value);
158+
propagateSharingNode.execute(node, self, value);
159159

160160
switch (queue.offer(value)) {
161161
case SUCCESS:

src/main/java/org/truffleruby/language/objects/shared/PropagateSharingNode.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
*/
1010
package org.truffleruby.language.objects.shared;
1111

12-
import com.oracle.truffle.api.dsl.NeverDefault;
12+
import com.oracle.truffle.api.dsl.GenerateCached;
13+
import com.oracle.truffle.api.dsl.GenerateInline;
14+
import com.oracle.truffle.api.nodes.Node;
1315
import org.truffleruby.language.RubyBaseNode;
1416
import org.truffleruby.language.RubyDynamicObject;
1517

@@ -19,25 +21,22 @@
1921
import com.oracle.truffle.api.dsl.Specialization;
2022

2123
@GenerateUncached
24+
@GenerateCached(false)
25+
@GenerateInline
2226
public abstract class PropagateSharingNode extends RubyBaseNode {
2327

24-
@NeverDefault
25-
public static PropagateSharingNode create() {
26-
return PropagateSharingNodeGen.create();
27-
}
28-
29-
public abstract void executePropagate(RubyDynamicObject source, Object value);
28+
public abstract void execute(Node node, RubyDynamicObject source, Object value);
3029

31-
@Specialization(guards = "!isSharedNode.executeIsShared(this, source)", limit = "1")
32-
protected void propagateNotShared(RubyDynamicObject source, Object value,
30+
@Specialization(guards = "!isSharedNode.executeIsShared(node, source)", limit = "1")
31+
protected static void propagateNotShared(Node node, RubyDynamicObject source, Object value,
3332
@Cached @Shared IsSharedNode isSharedNode) {
3433
// do nothing
3534
}
3635

37-
@Specialization(guards = "isSharedNode.executeIsShared(this, source)", limit = "1")
38-
protected void propagateShared(RubyDynamicObject source, Object value,
36+
@Specialization(guards = "isSharedNode.executeIsShared(node, source)", limit = "1")
37+
protected static void propagateShared(Node node, RubyDynamicObject source, Object value,
3938
@Cached @Shared IsSharedNode isSharedNode,
4039
@Cached WriteBarrierNode writeBarrierNode) {
41-
writeBarrierNode.execute(this, value);
40+
writeBarrierNode.execute(node, value);
4241
}
4342
}

0 commit comments

Comments
 (0)