Skip to content

Commit 693ae31

Browse files
committed
Convert UnwrapNativeNode to DSL inlinable
1 parent 2c0afc7 commit 693ae31

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

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

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,59 +45,65 @@
4545
public abstract class UnwrapNode extends RubyBaseNode {
4646

4747
@GenerateUncached
48+
@GenerateInline
49+
@GenerateCached(false)
4850
@ImportStatic(ValueWrapperManager.class)
4951
public abstract static class UnwrapNativeNode extends RubyBaseNode {
5052

51-
public abstract Object execute(long handle);
53+
public static Object executeUncached(long handle) {
54+
return UnwrapNodeGen.UnwrapNativeNodeGen.getUncached().execute(null, handle);
55+
}
56+
57+
public abstract Object execute(Node node, long handle);
5258

5359
@Specialization(guards = "handle == FALSE_HANDLE")
54-
protected boolean unwrapFalse(long handle) {
60+
protected static boolean unwrapFalse(long handle) {
5561
return false;
5662
}
5763

5864
@Specialization(guards = "handle == TRUE_HANDLE")
59-
protected boolean unwrapTrue(long handle) {
65+
protected static boolean unwrapTrue(long handle) {
6066
return true;
6167
}
6268

6369
@Specialization(guards = "handle == UNDEF_HANDLE")
64-
protected NotProvided unwrapUndef(long handle) {
70+
protected static NotProvided unwrapUndef(long handle) {
6571
return NotProvided.INSTANCE;
6672
}
6773

6874
@Specialization(guards = "handle == NIL_HANDLE")
69-
protected Object unwrapNil(long handle) {
75+
protected static Object unwrapNil(long handle) {
7076
return nil;
7177
}
7278

7379
@Specialization(guards = "isTaggedLong(handle)")
74-
protected long unwrapTaggedLong(long handle) {
80+
protected static long unwrapTaggedLong(long handle) {
7581
return ValueWrapperManager.untagTaggedLong(handle);
7682
}
7783

7884
@Specialization(guards = "isTaggedObject(handle)")
79-
protected Object unwrapTaggedObject(long handle,
85+
protected static Object unwrapTaggedObject(Node node, long handle,
8086
@Cached InlinedBranchProfile noHandleProfile) {
81-
final ValueWrapper wrapper = getContext()
87+
final ValueWrapper wrapper = getContext(node)
8288
.getValueWrapperManager()
83-
.getWrapperFromHandleMap(handle, getLanguage());
89+
.getWrapperFromHandleMap(handle, getLanguage(node));
8490
if (wrapper == null) {
85-
noHandleProfile.enter(this);
91+
noHandleProfile.enter(node);
8692
raiseError(handle);
8793
}
8894
return wrapper.getObject();
8995
}
9096

9197
@Fallback
92-
protected ValueWrapper unWrapUnexpectedHandle(long handle) {
98+
protected static ValueWrapper unWrapUnexpectedHandle(long handle) {
9399
// Avoid throwing a specialization exception when given an uninitialized or corrupt
94100
// handle.
95101
CompilerDirectives.transferToInterpreterAndInvalidate();
96102
throw CompilerDirectives.shouldNotReachHere("corrupt handle 0x" + Long.toHexString(handle));
97103
}
98104

99105
@TruffleBoundary
100-
private void raiseError(long handle) {
106+
private static void raiseError(long handle) {
101107
throw CompilerDirectives.shouldNotReachHere("dead handle 0x" + Long.toHexString(handle));
102108
}
103109
}
@@ -254,9 +260,9 @@ protected static long unwrapValueTaggedLong(ValueWrapper value) {
254260
}
255261

256262
@Specialization
257-
protected static Object longToWrapper(long value,
263+
protected static Object longToWrapper(Node node, long value,
258264
@Cached @Shared UnwrapNativeNode unwrapNativeNode) {
259-
return unwrapNativeNode.execute(value);
265+
return unwrapNativeNode.execute(node, value);
260266
}
261267

262268
@Specialization(guards = { "!isWrapper(value)", "!isImplicitLong(value)" })
@@ -271,7 +277,7 @@ protected static Object unwrapGeneric(Node node, Object value,
271277
unsupportedProfile.enter(node);
272278
throw new RaiseException(getContext(node), coreExceptions(node).argumentError(e.getMessage(), node, e));
273279
}
274-
return unwrapNativeNode.execute(handle);
280+
return unwrapNativeNode.execute(node, handle);
275281
}
276282

277283
protected int getCacheLimit() {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.oracle.truffle.api.profiles.LoopConditionProfile;
2323
import org.truffleruby.RubyContext;
2424
import org.truffleruby.cext.UnwrapNode;
25-
import org.truffleruby.cext.UnwrapNodeGen.UnwrapNativeNodeGen;
2625
import org.truffleruby.cext.ValueWrapper;
2726
import org.truffleruby.cext.WrapNode;
2827
import org.truffleruby.core.array.ArrayGuards;
@@ -298,7 +297,7 @@ public long getAddress() {
298297
@Override
299298
public void getAdjacentObjects(Set<Object> reachable) {
300299
for (int i = 0; i < length; i++) {
301-
final Object value = UnwrapNativeNodeGen.getUncached().execute(readElement(i));
300+
final Object value = UnwrapNode.UnwrapNativeNode.executeUncached(readElement(i));
302301
if (ObjectGraph.isRubyObject(value)) {
303302
reachable.add(value);
304303
}
@@ -308,7 +307,7 @@ public void getAdjacentObjects(Set<Object> reachable) {
308307
@TruffleBoundary
309308
public void preserveMembers() {
310309
for (int i = 0; i < length; i++) {
311-
final Object value = UnwrapNativeNodeGen.getUncached().execute(readElement(i));
310+
final Object value = UnwrapNode.UnwrapNativeNode.executeUncached(readElement(i));
312311
markedObjects[i] = value;
313312
}
314313
}

0 commit comments

Comments
 (0)