Skip to content

Commit 2c0afc7

Browse files
committed
Convert UnwrapNode to DSL inlinable
1 parent fcdc8ef commit 2c0afc7

File tree

7 files changed

+37
-25
lines changed

7 files changed

+37
-25
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ protected Object callWithCExtLockAndFrame(
252252
MutexOperations.lockInternal(getContext(), lock, this);
253253
}
254254
try {
255-
return unwrapNode.execute(
255+
return unwrapNode.execute(this,
256256
InteropNodes.execute(receiver, args, receivers, translateInteropExceptionNode));
257257
} finally {
258258
runMarksNode.execute(extensionStack);
@@ -262,7 +262,7 @@ protected Object callWithCExtLockAndFrame(
262262
}
263263
} else {
264264
try {
265-
return unwrapNode.execute(
265+
return unwrapNode.execute(this,
266266
InteropNodes.execute(receiver, args, receivers, translateInteropExceptionNode));
267267
} finally {
268268
runMarksNode.execute(extensionStack);
@@ -1761,7 +1761,7 @@ public abstract static class UnwrapValueNode extends PrimitiveArrayArgumentsNode
17611761
protected Object unwrap(Object value,
17621762
@Cached InlinedBranchProfile exceptionProfile,
17631763
@Cached UnwrapNode unwrapNode) {
1764-
Object object = unwrapNode.execute(value);
1764+
Object object = unwrapNode.execute(this, value);
17651765
if (object == null) {
17661766
exceptionProfile.enter(this);
17671767
throw new RaiseException(getContext(), coreExceptions().runtimeError(exceptionMessage(value), this));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected RubySymbol unwrapStaticSymbol(long value,
4848
@Specialization(guards = "!isStaticSymbol(value)")
4949
protected RubySymbol unwrapDynamicSymbol(Object value,
5050
@Cached UnwrapNode unwrapNode) {
51-
return (RubySymbol) unwrapNode.execute(value);
51+
return (RubySymbol) unwrapNode.execute(this, value);
5252
}
5353

5454
public static boolean isStaticSymbol(Object value) {

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
import com.oracle.truffle.api.CompilerDirectives;
1717
import com.oracle.truffle.api.TruffleSafepoint;
1818
import com.oracle.truffle.api.dsl.Bind;
19+
import com.oracle.truffle.api.dsl.GenerateCached;
20+
import com.oracle.truffle.api.dsl.GenerateInline;
1921
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
2022
import com.oracle.truffle.api.nodes.ExplodeLoop;
23+
import com.oracle.truffle.api.nodes.Node;
2124
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
2225
import com.oracle.truffle.api.profiles.LoopConditionProfile;
2326
import org.truffleruby.language.NotProvided;
@@ -36,6 +39,8 @@
3639
import com.oracle.truffle.api.library.CachedLibrary;
3740

3841
@GenerateUncached
42+
@GenerateInline
43+
@GenerateCached(false)
3944
@ImportStatic(ValueWrapperManager.class)
4045
public abstract class UnwrapNode extends RubyBaseNode {
4146

@@ -194,7 +199,7 @@ protected Object[] unwrapCArrayExplode(Object cArray,
194199
final Object[] store = new Object[cachedSize];
195200
for (int i = 0; i < cachedSize; i++) {
196201
final Object cValue = readArrayElement(cArray, interop, i);
197-
store[i] = unwrapNode.execute(cValue);
202+
store[i] = unwrapNode.execute(this, cValue);
198203
}
199204
return store;
200205
}
@@ -210,7 +215,7 @@ protected Object[] unwrapCArray(Object cArray,
210215
try {
211216
for (; loopProfile.inject(i < size); i++) {
212217
final Object cValue = readArrayElement(cArray, interop, i);
213-
store[i] = unwrapNode.execute(cValue);
218+
store[i] = unwrapNode.execute(this, cValue);
214219
TruffleSafepoint.poll(this);
215220
}
216221
} finally {
@@ -236,35 +241,35 @@ private static Object readArrayElement(Object cArray, InteropLibrary interop, in
236241
}
237242
}
238243

239-
public abstract Object execute(Object value);
244+
public abstract Object execute(Node node, Object value);
240245

241246
@Specialization(guards = "!isTaggedLong(value.getHandle())")
242-
protected Object unwrapValueObject(ValueWrapper value) {
247+
protected static Object unwrapValueObject(ValueWrapper value) {
243248
return value.getObject();
244249
}
245250

246251
@Specialization(guards = "isTaggedLong(value.getHandle())")
247-
protected long unwrapValueTaggedLong(ValueWrapper value) {
252+
protected static long unwrapValueTaggedLong(ValueWrapper value) {
248253
return ValueWrapperManager.untagTaggedLong(value.getHandle());
249254
}
250255

251256
@Specialization
252-
protected Object longToWrapper(long value,
257+
protected static Object longToWrapper(long value,
253258
@Cached @Shared UnwrapNativeNode unwrapNativeNode) {
254259
return unwrapNativeNode.execute(value);
255260
}
256261

257262
@Specialization(guards = { "!isWrapper(value)", "!isImplicitLong(value)" })
258-
protected Object unwrapGeneric(Object value,
263+
protected static Object unwrapGeneric(Node node, Object value,
259264
@CachedLibrary(limit = "getCacheLimit()") InteropLibrary values,
260265
@Cached @Shared UnwrapNativeNode unwrapNativeNode,
261266
@Cached InlinedBranchProfile unsupportedProfile) {
262267
long handle;
263268
try {
264269
handle = values.asPointer(value);
265270
} catch (UnsupportedMessageException e) {
266-
unsupportedProfile.enter(this);
267-
throw new RaiseException(getContext(), coreExceptions().argumentError(e.getMessage(), this, e));
271+
unsupportedProfile.enter(node);
272+
throw new RaiseException(getContext(node), coreExceptions(node).argumentError(e.getMessage(), node, e));
268273
}
269274
return unwrapNativeNode.execute(handle);
270275
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import java.util.concurrent.ConcurrentHashMap;
1616
import java.util.concurrent.atomic.AtomicLong;
1717

18+
import com.oracle.truffle.api.dsl.Bind;
19+
import com.oracle.truffle.api.nodes.Node;
1820
import org.truffleruby.RubyContext;
1921
import org.truffleruby.RubyLanguage;
2022
import org.truffleruby.annotations.SuppressFBWarnings;
@@ -396,8 +398,9 @@ protected boolean isExecutable() {
396398

397399
@ExportMessage
398400
protected Object execute(Object[] arguments,
399-
@Cached UnwrapNode unwrapNode) {
400-
return unwrapNode.execute(arguments[0]);
401+
@Cached UnwrapNode unwrapNode,
402+
@Bind("$node") Node node) {
403+
return unwrapNode.execute(node, arguments[0]);
401404
}
402405
}
403406

@@ -429,8 +432,9 @@ protected boolean isExecutable() {
429432
@ExportMessage
430433
public Object execute(Object[] arguments,
431434
@Cached UnwrapNode unwrapNode,
432-
@Cached SymbolToIDNode symbolTOIDNode) {
433-
return symbolTOIDNode.execute(unwrapNode.execute(arguments[0]));
435+
@Cached SymbolToIDNode symbolTOIDNode,
436+
@Bind("$node") Node node) {
437+
return symbolTOIDNode.execute(unwrapNode.execute(node, arguments[0]));
434438
}
435439
}
436440

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ protected static String toString(NativeArrayStorage storage) {
9393

9494
@ExportMessage
9595
protected Object read(int index,
96-
@Shared @Cached UnwrapNode unwrapNode) {
97-
return unwrapNode.execute(readElement(index));
96+
@Shared @Cached UnwrapNode unwrapNode,
97+
@Bind("$node") Node node) {
98+
return unwrapNode.execute(node, readElement(index));
9899
}
99100

100101
@ExportMessage
@@ -140,10 +141,11 @@ protected NativeArrayStorage expand(int newCapacity,
140141

141142
@ExportMessage
142143
protected Object[] boxedCopyOfRange(int start, int length,
143-
@Shared @Cached UnwrapNode unwrapNode) {
144+
@Shared @Cached UnwrapNode unwrapNode,
145+
@Bind("$node") Node node) {
144146
Object[] newStore = new Object[length];
145147
for (int i = 0; i < length; i++) {
146-
newStore[i] = unwrapNode.execute(readElement(start + i));
148+
newStore[i] = unwrapNode.execute(node, readElement(start + i));
147149
}
148150
return newStore;
149151
}
@@ -205,11 +207,12 @@ protected static void fill(NativeArrayStorage store, int start, int length, Obje
205207

206208
@ExportMessage
207209
protected Object[] toJavaArrayCopy(int size,
208-
@Shared @Cached UnwrapNode unwrapNode) {
210+
@Shared @Cached UnwrapNode unwrapNode,
211+
@Bind("$node") Node node) {
209212
Object[] newStore = new Object[size];
210213
assert size >= length;
211214
for (int i = 0; i < length; i++) {
212-
newStore[i] = unwrapNode.execute(readElement(i));
215+
newStore[i] = unwrapNode.execute(node, readElement(i));
213216
}
214217
return newStore;
215218
}

src/main/java/org/truffleruby/core/format/read/array/ReadCStringNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected Object read(Object pointer,
3737
@Cached UnwrapNode unwrapNode,
3838
@Cached TranslateInteropExceptionNode translateInteropExceptionNode,
3939
@CachedLibrary("stringReader") InteropLibrary stringReaders) {
40-
Object string = unwrapNode.execute(InteropNodes.execute(
40+
Object string = unwrapNode.execute(this, InteropNodes.execute(
4141
stringReader,
4242
new Object[]{ pointer },
4343
stringReaders,

src/main/java/org/truffleruby/core/format/read/array/ReadCValueNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ public abstract class ReadCValueNode extends FormatNode {
2222
@Specialization
2323
protected Object read(Object source,
2424
@Cached UnwrapNode unwrapNode) {
25-
return unwrapNode.execute(source);
25+
return unwrapNode.execute(this, source);
2626
}
2727
}

0 commit comments

Comments
 (0)