Skip to content

Commit be0dedb

Browse files
eregonhorakivo
authored andcommitted
Less static and no need to guard isPointer, let it fail if it does not hold
1 parent fc92cac commit be0dedb

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

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

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.oracle.truffle.api.dsl.Bind;
1919
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
2020
import com.oracle.truffle.api.nodes.ExplodeLoop;
21-
import com.oracle.truffle.api.nodes.Node;
2221
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
2322
import com.oracle.truffle.api.profiles.LoopConditionProfile;
2423
import org.truffleruby.language.NotProvided;
@@ -28,7 +27,6 @@
2827
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
2928
import com.oracle.truffle.api.dsl.Cached;
3029
import com.oracle.truffle.api.dsl.Cached.Shared;
31-
import com.oracle.truffle.api.dsl.Cached.Exclusive;
3230
import com.oracle.truffle.api.dsl.Fallback;
3331
import com.oracle.truffle.api.dsl.GenerateUncached;
3432
import com.oracle.truffle.api.dsl.ImportStatic;
@@ -159,18 +157,17 @@ protected ValueWrapper longToWrapper(long value,
159157
return nativeToWrapperNode.execute(value);
160158
}
161159

162-
@Specialization(guards = { "!isWrapper(value)", "values.isPointer(value)" }, limit = "getCacheLimit()")
163-
protected static ValueWrapper genericToWrapper(Object value,
164-
@CachedLibrary("value") InteropLibrary values,
160+
@Fallback
161+
protected ValueWrapper genericToWrapper(Object value,
162+
@CachedLibrary(limit = "getCacheLimit()") InteropLibrary values,
165163
@Cached @Shared NativeToWrapperNode nativeToWrapperNode,
166-
@Cached InlinedBranchProfile unsupportedProfile,
167-
@Bind("this") Node node) {
164+
@Cached InlinedBranchProfile unsupportedProfile) {
168165
long handle;
169166
try {
170167
handle = values.asPointer(value);
171168
} catch (UnsupportedMessageException e) {
172-
unsupportedProfile.enter(node);
173-
throw new RaiseException(getContext(node), coreExceptions(node).argumentError(e.getMessage(), node, e));
169+
unsupportedProfile.enter(this);
170+
throw new RaiseException(getContext(), coreExceptions().argumentError(e.getMessage(), this, e));
174171
}
175172
return nativeToWrapperNode.execute(handle);
176173
}
@@ -253,22 +250,21 @@ protected long unwrapValueTaggedLong(ValueWrapper value) {
253250

254251
@Specialization
255252
protected Object longToWrapper(long value,
256-
@Cached @Exclusive UnwrapNativeNode unwrapNode) {
257-
return unwrapNode.execute(value);
253+
@Cached @Shared UnwrapNativeNode unwrapNativeNode) {
254+
return unwrapNativeNode.execute(value);
258255
}
259256

260-
@Specialization(guards = { "!isWrapper(value)", "values.isPointer(value)" }, limit = "getCacheLimit()")
261-
protected static Object unwrapGeneric(Object value,
262-
@CachedLibrary("value") InteropLibrary values,
263-
@Cached @Exclusive UnwrapNativeNode unwrapNativeNode,
264-
@Cached InlinedBranchProfile unsupportedProfile,
265-
@Bind("this") Node node) {
257+
@Specialization(guards = { "!isWrapper(value)", "!isImplicitLong(value)" })
258+
protected Object unwrapGeneric(Object value,
259+
@CachedLibrary(limit = "getCacheLimit()") InteropLibrary values,
260+
@Cached @Shared UnwrapNativeNode unwrapNativeNode,
261+
@Cached InlinedBranchProfile unsupportedProfile) {
266262
long handle;
267263
try {
268264
handle = values.asPointer(value);
269265
} catch (UnsupportedMessageException e) {
270-
unsupportedProfile.enter(node);
271-
throw new RaiseException(getContext(node), coreExceptions(node).argumentError(e.getMessage(), node, e));
266+
unsupportedProfile.enter(this);
267+
throw new RaiseException(getContext(), coreExceptions().argumentError(e.getMessage(), this, e));
272268
}
273269
return unwrapNativeNode.execute(handle);
274270
}

0 commit comments

Comments
 (0)