Skip to content

Commit f8cf9cc

Browse files
committed
Convert IsSharedNode to DSL inlinable
1 parent 971f0d3 commit f8cf9cc

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ protected RubyArray clear(RubyArray array,
480480
@Cached IsSharedNode isSharedNode,
481481
@Cached ConditionProfile sharedProfile) {
482482
setStoreAndSize(array,
483-
ArrayStoreLibrary.initialStorage(sharedProfile.profile(isSharedNode.executeIsShared(array))),
483+
ArrayStoreLibrary.initialStorage(sharedProfile.profile(isSharedNode.executeIsShared(this, array))),
484484
0);
485485
return array;
486486
}
@@ -1142,7 +1142,8 @@ protected RubyArray initializeNoArgs(RubyArray array, NotProvided size, NotProvi
11421142
@Cached @Shared IsSharedNode isSharedNode,
11431143
@Cached @Shared ConditionProfile sharedProfile) {
11441144
setStoreAndSize(array,
1145-
ArrayStoreLibrary.initialStorage(sharedProfile.profile(isSharedNode.executeIsShared(array))), 0);
1145+
ArrayStoreLibrary.initialStorage(sharedProfile.profile(isSharedNode.executeIsShared(this, array))),
1146+
0);
11461147
return array;
11471148
}
11481149

@@ -1158,7 +1159,8 @@ protected RubyArray initializeOnlyBlock(
11581159
}
11591160

11601161
setStoreAndSize(array,
1161-
ArrayStoreLibrary.initialStorage(sharedProfile.profile(isSharedNode.executeIsShared(array))), 0);
1162+
ArrayStoreLibrary.initialStorage(sharedProfile.profile(isSharedNode.executeIsShared(this, array))),
1163+
0);
11621164
return array;
11631165
}
11641166

@@ -1190,7 +1192,7 @@ protected RubyArray initializeWithSizeNoValue(RubyArray array, int size, NotProv
11901192
@Cached @Shared ConditionProfile sharedProfile,
11911193
@CachedLibrary(limit = "2") @Exclusive ArrayStoreLibrary stores) {
11921194
final Object store;
1193-
if (sharedProfile.profile(isSharedNode.executeIsShared(array))) {
1195+
if (sharedProfile.profile(isSharedNode.executeIsShared(this, array))) {
11941196
store = new SharedArrayStorage(new Object[size]);
11951197
} else {
11961198
store = new Object[size];
@@ -1253,7 +1255,7 @@ protected Object initializeBlock(RubyArray array, int size, Object unusedFilling
12531255
} finally {
12541256
profileAndReportLoopCount(loopProfile, n);
12551257
Object store = arrayBuilder.finish(state, n);
1256-
if (sharedProfile.profile(isSharedNode.executeIsShared(array))) {
1258+
if (sharedProfile.profile(isSharedNode.executeIsShared(this, array))) {
12571259
store = stores.makeShared(store, n);
12581260
}
12591261
setStoreAndSize(array, store, n);
@@ -1836,7 +1838,7 @@ protected RubyArray replace(RubyArray array, RubyArray other,
18361838
@CachedLibrary(limit = "2") ArrayStoreLibrary stores) {
18371839
final int size = other.size;
18381840
Object store = cowNode.execute(other, 0, size);
1839-
if (sharedProfile.profile(isSharedNode.executeIsShared(array))) {
1841+
if (sharedProfile.profile(isSharedNode.executeIsShared(this, array))) {
18401842
store = stores.makeShared(store, size);
18411843
}
18421844
setStoreAndSize(array, store, size);
@@ -2297,9 +2299,7 @@ public abstract static class StoreToNativeNode extends PrimitiveArrayArgumentsNo
22972299
protected RubyArray storeToNative(RubyArray array,
22982300
@Bind("array.getStore()") Object store,
22992301
@CachedLibrary("store") ArrayStoreLibrary stores,
2300-
@Cached IntValueProfile arraySizeProfile,
2301-
@Cached IsSharedNode isSharedNode,
2302-
@Cached ConditionProfile sharedProfile) {
2302+
@Cached IntValueProfile arraySizeProfile) {
23032303
final int size = arraySizeProfile.profile(array.size);
23042304
Pointer pointer = Pointer.mallocAutoRelease(getLanguage(), getContext(), size * Pointer.SIZE);
23052305
Object newStore = new NativeArrayStorage(pointer, size);

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

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

12+
import com.oracle.truffle.api.dsl.GenerateInline;
13+
import com.oracle.truffle.api.nodes.Node;
1214
import org.truffleruby.language.RubyBaseNode;
1315
import org.truffleruby.language.RubyDynamicObject;
1416
import org.truffleruby.language.objects.ShapeCachingGuards;
@@ -21,30 +23,32 @@
2123

2224
@ImportStatic(ShapeCachingGuards.class)
2325
@GenerateUncached
26+
@GenerateInline(inlineByDefault = true)
2427
public abstract class IsSharedNode extends RubyBaseNode {
2528

2629
protected static final int CACHE_LIMIT = 8;
2730

28-
public abstract boolean executeIsShared(RubyDynamicObject object);
31+
public abstract boolean executeIsShared(Node node, RubyDynamicObject object);
2932

3033
@Specialization(
3134
guards = "object.getShape() == cachedShape",
3235
assumptions = "cachedShape.getValidAssumption()",
3336
limit = "CACHE_LIMIT")
34-
protected boolean isShareCached(RubyDynamicObject object,
37+
protected static boolean isShareCached(RubyDynamicObject object,
3538
@Cached("object.getShape()") Shape cachedShape,
3639
@Cached("cachedShape.isShared()") boolean shared) {
3740
return shared;
3841
}
3942

4043
@Specialization(guards = "updateShape(object)")
41-
protected boolean updateShapeAndIsShared(RubyDynamicObject object) {
42-
return executeIsShared(object);
44+
protected static boolean updateShapeAndIsShared(Node node, RubyDynamicObject object,
45+
@Cached(inline = false) IsSharedNode isSharedNode) {
46+
return isSharedNode.executeIsShared(node, object);
4347
}
4448

4549
@Specialization(replaces = { "isShareCached", "updateShapeAndIsShared" })
46-
protected boolean isSharedUncached(RubyDynamicObject object) {
47-
return getLanguage().options.SHARED_OBJECTS_ENABLED && SharedObjects.isShared(object);
50+
protected static boolean isSharedUncached(Node node, RubyDynamicObject object) {
51+
return getLanguage(node).options.SHARED_OBJECTS_ENABLED && SharedObjects.isShared(object);
4852
}
4953

5054
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ public static PropagateSharingNode create() {
2828

2929
public abstract void executePropagate(RubyDynamicObject source, Object value);
3030

31-
@Specialization(guards = "!isSharedNode.executeIsShared(source)", limit = "1")
31+
@Specialization(guards = "!isSharedNode.executeIsShared(this, source)", limit = "1")
3232
protected void propagateNotShared(RubyDynamicObject source, Object value,
3333
@Cached @Shared IsSharedNode isSharedNode) {
3434
// do nothing
3535
}
3636

37-
@Specialization(guards = "isSharedNode.executeIsShared(source)", limit = "1")
37+
@Specialization(guards = "isSharedNode.executeIsShared(this, source)", limit = "1")
3838
protected void propagateShared(RubyDynamicObject source, Object value,
3939
@Cached @Shared IsSharedNode isSharedNode,
4040
@Cached WriteBarrierNode writeBarrierNode) {

0 commit comments

Comments
 (0)