Skip to content

Commit 517f020

Browse files
committed
More tidy up.
1 parent 9c8be9e commit 517f020

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,27 @@ public static abstract class UnwrapNativeNode extends RubyBaseNode {
3232
public abstract Object execute(long handle);
3333

3434
@Specialization(guards = "handle == FALSE_HANDLE")
35-
public Object unwrapFalse(long handle) {
35+
public boolean unwrapFalse(long handle) {
3636
return false;
3737
}
3838

3939
@Specialization(guards = "handle == TRUE_HANDLE")
40-
public Object unwrapTrue(long handle) {
40+
public boolean unwrapTrue(long handle) {
4141
return true;
4242
}
4343

4444
@Specialization(guards = "handle == UNDEF_HANDLE")
45-
public Object unwrapUndef(long handle) {
45+
public NotProvided unwrapUndef(long handle) {
4646
return NotProvided.INSTANCE;
4747
}
4848

4949
@Specialization(guards = "handle == NIL_HANDLE")
50-
public Object unwrapNil(long handle) {
50+
public DynamicObject unwrapNil(long handle) {
5151
return nil();
5252
}
5353

5454
@Specialization(guards = "isTaggedLong(handle)")
55-
public Object unwrapTaggedLong(long handle) {
55+
public long unwrapTaggedLong(long handle) {
5656
return handle >> 1;
5757
}
5858

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,18 @@ public class ValueWrapperManager {
2626
* These constants are taken from ruby.h, and are based on us not tagging doubles.
2727
*/
2828

29-
public static final int FALSE_HANDLE = 0x0;
30-
public static final int TRUE_HANDLE = 0x2;
31-
public static final int NIL_HANDLE = 0x04;
32-
public static final int UNDEF_HANDLE = 0x6;
29+
public static final int FALSE_HANDLE = 0b000;
30+
public static final int TRUE_HANDLE = 0b010;
31+
public static final int NIL_HANDLE = 0b100;
32+
public static final int UNDEF_HANDLE = 0b110;
3333

3434
public static final long LONG_TAG = 1;
3535
public static final long OBJECT_TAG = 0;
3636

3737
public static final long MIN_FIXNUM_VALUE = -(1L << 62);
3838
public static final long MAX_FIXNUM_VALUE = (1L << 62) - 1;
3939

40-
public static final int TAG_BITS = 3;
41-
public static final long TAG_MASK = 0x7;
40+
public static final long TAG_MASK = 0b111;
4241

4342
private final LongHashMap<WeakReference<DynamicObject>> handleMap = new LongHashMap<>(1024);
4443

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,17 @@
2121
import com.oracle.truffle.api.dsl.Specialization;
2222
import com.oracle.truffle.api.interop.TruffleObject;
2323
import com.oracle.truffle.api.object.DynamicObject;
24+
import com.oracle.truffle.api.profiles.BranchProfile;
2425

2526
public abstract class WrapNode extends RubyBaseNode {
2627

2728
public abstract TruffleObject execute(Object value);
2829

2930
@Specialization
30-
public DynamicObject wrapInt(int value) {
31-
return wrapLong(value);
32-
}
33-
34-
@Specialization
35-
public DynamicObject wrapLong(long value) {
31+
public DynamicObject wrapLong(long value,
32+
@Cached("create()") BranchProfile smallFixnumProfile) {
3633
if (value >= ValueWrapperManager.MIN_FIXNUM_VALUE && value <= ValueWrapperManager.MAX_FIXNUM_VALUE) {
34+
smallFixnumProfile.enter();
3735
long val = (value << 1) | LONG_TAG;
3836
return Layouts.VALUE_WRAPPER.createValueWrapper(value, val);
3937
} else {
@@ -69,9 +67,11 @@ public DynamicObject wrapNil(DynamicObject value) {
6967
@Specialization(guards = { "isRubyBasicObject(value)", "!isNil(value)" })
7068
public DynamicObject wrapValue(DynamicObject value,
7169
@Cached("createReader()") ReadObjectFieldNode readWrapperNode,
72-
@Cached("createWriter()") WriteObjectFieldNode writeWrapperNode) {
70+
@Cached("createWriter()") WriteObjectFieldNode writeWrapperNode,
71+
@Cached("create()") BranchProfile noHandleProfile) {
7372
DynamicObject wrapper = (DynamicObject) readWrapperNode.execute(value);
7473
if (wrapper == null) {
74+
noHandleProfile.enter();
7575
synchronized (value) {
7676
wrapper = (DynamicObject) readWrapperNode.execute(value);
7777
if (wrapper == null) {

0 commit comments

Comments
 (0)