|
15 | 15 | import org.truffleruby.RubyContext;
|
16 | 16 | import org.truffleruby.collections.LongHashMap;
|
17 | 17 | import org.truffleruby.extra.ffi.Pointer;
|
18 |
| -import org.truffleruby.language.NotProvided; |
19 |
| -import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; |
20 | 18 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
21 | 19 | import com.oracle.truffle.api.object.DynamicObject;
|
22 | 20 |
|
23 | 21 | public class ValueWrapperManager {
|
24 | 22 |
|
25 | 23 | static final int UNSET_HANDLE = -1;
|
26 |
| - public static final int FALSE_HANDLE = 0; |
27 |
| - public static final int TRUE_HANDLE = 1; |
28 |
| - public static final int UNDEF_HANDLE = 2; |
29 |
| - public static final int NIL_HANDLE = 3; |
30 | 24 |
|
31 |
| - public static final int LONG_TAG = 4; |
32 |
| - public static final int OBJECT_TAG = 7; |
| 25 | + /* |
| 26 | + * These constants are taken from ruby.h, and are based on us not tagging doubles. |
| 27 | + */ |
| 28 | + |
| 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; |
| 33 | + |
| 34 | + public static final long LONG_TAG = 1; |
| 35 | + public static final long OBJECT_TAG = 0; |
| 36 | + |
| 37 | + public static final long MIN_FIXNUM_VALUE = -(1L << 62); |
| 38 | + public static final long MAX_FIXNUM_VALUE = (1L << 62) - 1; |
| 39 | + |
| 40 | + public static final int TAG_BITS = 3; |
| 41 | + public static final long TAG_MASK = 0x7; |
33 | 42 |
|
34 | 43 | private final LongHashMap<WeakReference<DynamicObject>> handleMap = new LongHashMap<>(1024);
|
35 | 44 |
|
@@ -79,7 +88,7 @@ public synchronized void removeFromHandleMap(long handle) {
|
79 | 88 | public synchronized long createNativeHandle(DynamicObject wrapper) {
|
80 | 89 | Pointer handlePointer = Pointer.malloc(1);
|
81 | 90 | long handleAddress = handlePointer.getAddress();
|
82 |
| - if ((handleAddress & 0x7) != 0) { |
| 91 | + if ((handleAddress & TAG_MASK) != 0) { |
83 | 92 | throw new RuntimeException("unaligned malloc for native handle");
|
84 | 93 | }
|
85 | 94 | Layouts.VALUE_WRAPPER.setHandle(wrapper, handleAddress);
|
|
0 commit comments