Skip to content

Commit 8da1df4

Browse files
committed
Profile both branches for wrapping a long
1 parent a3c879c commit 8da1df4

File tree

3 files changed

+14
-22
lines changed

3 files changed

+14
-22
lines changed

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,6 @@ public static HandleBlockHolder getBlockHolder(RubyContext context, RubyLanguage
6868
return language.getCurrentFiber().handleData;
6969
}
7070

71-
/* We keep a map of long wrappers that have been generated because various C extensions assume that any given fixnum
72-
* will translate to a given VALUE. */
73-
public ValueWrapper longWrapper(long value) {
74-
return new ValueWrapper(value, UNSET_HANDLE, null);
75-
}
76-
77-
public ValueWrapper doubleWrapper(double value) {
78-
return new ValueWrapper(value, UNSET_HANDLE, null);
79-
}
80-
8171
@TruffleBoundary
8272
public synchronized HandleBlock addToBlockMap(RubyContext context, RubyLanguage language) {
8373
HandleBlock block = new HandleBlock(context, language, this);

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import static org.truffleruby.cext.ValueWrapperManager.UNSET_HANDLE;
1414

1515
import com.oracle.truffle.api.dsl.Bind;
16+
import com.oracle.truffle.api.dsl.ImportStatic;
1617
import com.oracle.truffle.api.dsl.NeverDefault;
1718
import com.oracle.truffle.api.nodes.Node;
1819
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
@@ -27,15 +28,16 @@
2728
import org.truffleruby.language.control.RaiseException;
2829

2930
import com.oracle.truffle.api.dsl.Cached;
30-
import com.oracle.truffle.api.dsl.Cached.Exclusive;
3131
import com.oracle.truffle.api.dsl.Cached.Shared;
3232
import com.oracle.truffle.api.dsl.GenerateUncached;
3333
import com.oracle.truffle.api.dsl.Specialization;
3434
import com.oracle.truffle.api.library.CachedLibrary;
3535
import com.oracle.truffle.api.object.DynamicObjectLibrary;
36+
import org.truffleruby.language.objects.ObjectIDOperations;
3637

3738
import java.lang.invoke.VarHandle;
3839

40+
@ImportStatic(ObjectIDOperations.class)
3941
@GenerateUncached
4042
public abstract class WrapNode extends RubyBaseNode {
4143

@@ -46,21 +48,20 @@ public static WrapNode create() {
4648

4749
public abstract ValueWrapper execute(Object value);
4850

49-
@Specialization
50-
ValueWrapper wrapLong(long value,
51-
@Cached @Exclusive InlinedBranchProfile smallFixnumProfile) {
52-
if (value >= ValueWrapperManager.MIN_FIXNUM_VALUE && value <= ValueWrapperManager.MAX_FIXNUM_VALUE) {
53-
smallFixnumProfile.enter(this);
54-
long val = (value << 1) | LONG_TAG;
55-
return new ValueWrapper(null, val, null);
56-
} else {
57-
return getContext().getValueWrapperManager().longWrapper(value);
58-
}
51+
@Specialization(guards = "isSmallFixnum(value)")
52+
ValueWrapper wrapFixnum(long value) {
53+
long val = (value << 1) | LONG_TAG;
54+
return new ValueWrapper(null, val, null);
55+
}
56+
57+
@Specialization(guards = "!isSmallFixnum(value)")
58+
ValueWrapper wrapNonFixnum(long value) {
59+
return new ValueWrapper(value, UNSET_HANDLE, null);
5960
}
6061

6162
@Specialization
6263
ValueWrapper wrapDouble(double value) {
63-
return getContext().getValueWrapperManager().doubleWrapper(value);
64+
return new ValueWrapper(value, UNSET_HANDLE, null);
6465
}
6566

6667
@Specialization

src/main/java/org/truffleruby/language/objects/ObjectIDOperations.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public abstract class ObjectIDOperations {
5454

5555
// primitive => ID
5656

57+
/** Whether the long fits as a tagged pointer (fixnum) in C */
5758
public static boolean isSmallFixnum(long fixnum) {
5859
// TODO: optimize
5960
return MIN_FIXNUM_VALUE <= fixnum && fixnum <= MAX_FIXNUM_VALUE;

0 commit comments

Comments
 (0)