Skip to content

Commit e4e30a0

Browse files
committed
ShareInternalFieldsNode supports DSL inlining
1 parent 427c581 commit e4e30a0

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

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

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

12+
import com.oracle.truffle.api.CompilerAsserts;
13+
import com.oracle.truffle.api.dsl.GenerateCached;
14+
import com.oracle.truffle.api.dsl.GenerateInline;
1215
import com.oracle.truffle.api.nodes.Node;
1316
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
1417
import org.truffleruby.collections.BoundaryIterable;
@@ -31,40 +34,40 @@
3134
/** Share the plain Java fields which may contain objets for subclasses of RubyDynamicObject.
3235
* {@link RubyDynamicObject#metaClass} is handled by {@link ShareObjectNode}. */
3336
@ImportStatic({ ShapeCachingGuards.class, ArrayGuards.class })
37+
@GenerateCached(false)
38+
@GenerateInline
3439
public abstract class ShareInternalFieldsNode extends RubyBaseNode {
3540

3641
protected static final int CACHE_LIMIT = 8;
3742

38-
protected final int depth;
39-
40-
public ShareInternalFieldsNode(int depth) {
41-
this.depth = depth;
43+
public final void execute(Node node, RubyDynamicObject object, int depth) {
44+
CompilerAsserts.partialEvaluationConstant(depth);
45+
executeInternal(node, object, depth);
4246
}
4347

44-
public abstract void executeShare(RubyDynamicObject object);
48+
protected abstract void executeInternal(Node node, RubyDynamicObject object, int depth);
4549

4650
@Specialization(limit = "CACHE_LIMIT")
47-
protected void shareArray(RubyArray array,
51+
protected static void shareArray(RubyArray array, int depth,
4852
@Bind("array.getStore()") Object store,
4953
@CachedLibrary("store") ArrayStoreLibrary stores) {
5054
array.setStore(stores.makeShared(store, array.size));
5155
}
5256

5357
@Specialization
54-
protected void shareCachedQueue(RubyQueue object,
58+
protected static void shareCachedQueue(Node node, RubyQueue object, int depth,
5559
@Cached InlinedConditionProfile profileEmpty,
56-
@Cached WriteBarrierNode writeBarrierNode,
57-
@Bind("this") Node node) {
60+
@Cached WriteBarrierNode writeBarrierNode) {
5861
final UnsizedQueue queue = object.queue;
59-
if (!profileEmpty.profile(this, queue.isEmpty())) {
62+
if (!profileEmpty.profile(node, queue.isEmpty())) {
6063
for (Object e : BoundaryIterable.wrap(queue.getContents())) {
6164
writeBarrierNode.execute(node, e, depth);
6265
}
6366
}
6467
}
6568

6669
@Specialization
67-
protected void shareCachedBasicObject(RubyBasicObject object) {
70+
protected static void shareCachedBasicObject(RubyBasicObject object, int depth) {
6871
/* No extra Java fields for RubyBasicObject */
6972
}
7073

@@ -73,7 +76,7 @@ protected void shareCachedBasicObject(RubyBasicObject object) {
7376
"shareArray",
7477
"shareCachedQueue",
7578
"shareCachedBasicObject" })
76-
protected void shareUncached(RubyDynamicObject object) {
79+
protected static void shareUncached(RubyDynamicObject object, int depth) {
7780
SharedObjects.shareInternalFields(object);
7881
}
7982

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected void shareCached(RubyDynamicObject object,
5454
@Cached("createSharedShape(cachedShape)") Shape sharedShape,
5555
@CachedLibrary(limit = "1") DynamicObjectLibrary objectLibrary,
5656
@Cached("new()") RunTwiceBranchProfile shareMetaClassProfile,
57-
@Cached("createShareInternalFieldsNode()") ShareInternalFieldsNode shareInternalFieldsNode,
57+
@Cached ShareInternalFieldsNode shareInternalFieldsNode,
5858
@Cached(value = "getObjectProperties(sharedShape)", dimensions = 1) PropertyGetter[] propertyGetters,
5959
@Cached("createWriteBarrierNodes(propertyGetters)") WriteBarrierNode[] writeBarrierNodes) {
6060
// Mark the object as shared first to avoid recursion
@@ -71,7 +71,7 @@ protected void shareCached(RubyDynamicObject object,
7171
assert SharedObjects
7272
.isShared(object.getLogicalClass()) : "the logical class should have been shared by the metaclass";
7373

74-
shareInternalFieldsNode.executeShare(object);
74+
shareInternalFieldsNode.execute(this, object, depth);
7575

7676
for (int i = 0; i < propertyGetters.length; i++) {
7777
final PropertyGetter propertyGetter = propertyGetters[i];
@@ -110,10 +110,6 @@ protected static PropertyGetter[] getObjectProperties(Shape shape) {
110110
return objectProperties.toArray(KernelNodes.CopyInstanceVariablesNode.EMPTY_PROPERTY_GETTER_ARRAY);
111111
}
112112

113-
protected ShareInternalFieldsNode createShareInternalFieldsNode() {
114-
return ShareInternalFieldsNodeGen.create(depth);
115-
}
116-
117113
protected WriteBarrierNode[] createWriteBarrierNodes(PropertyGetter[] propertyGetters) {
118114
WriteBarrierNode[] nodes = propertyGetters.length == 0
119115
? WriteBarrierNode.EMPTY_ARRAY

0 commit comments

Comments
 (0)