Skip to content

Commit 9c8be9e

Browse files
committed
Unify tag values in value wrappers and object id code.
1 parent 68adeab commit 9c8be9e

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/main/java/org/truffleruby/core/objectspace/ObjectSpaceManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import com.oracle.truffle.api.utilities.CyclicAssumption;
4545

4646
import org.truffleruby.RubyContext;
47-
import org.truffleruby.language.objects.ObjectIDOperations;
47+
import org.truffleruby.cext.ValueWrapperManager;
4848

4949
import java.lang.management.GarbageCollectorMXBean;
5050
import java.lang.management.ManagementFactory;
@@ -63,7 +63,7 @@ public class ObjectSpaceManager {
6363
private int tracingAssumptionActivations = 0;
6464
private boolean tracingPaused = false;
6565

66-
private final AtomicLong nextObjectID = new AtomicLong(ObjectIDOperations.FIRST_OBJECT_ID);
66+
private final AtomicLong nextObjectID = new AtomicLong(ValueWrapperManager.TAG_MASK + 1);
6767

6868
public ObjectSpaceManager(RubyContext context) {
6969
this.context = context;
@@ -110,9 +110,9 @@ public boolean isTracing() {
110110
}
111111

112112
public long getNextObjectID() {
113-
final long id = nextObjectID.getAndAdd(2);
113+
final long id = nextObjectID.getAndAdd(ValueWrapperManager.TAG_MASK + 1);
114114

115-
if (id < 0) {
115+
if (id == 0) {
116116
CompilerDirectives.transferToInterpreterAndInvalidate();
117117
throw new RuntimeException("Object IDs exhausted");
118118
}

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@
1414
import com.oracle.truffle.api.object.Property;
1515
import org.truffleruby.Layouts;
1616
import org.truffleruby.RubyContext;
17+
import org.truffleruby.cext.ValueWrapperManager;
1718
import org.truffleruby.core.numeric.BignumOperations;
1819
import org.truffleruby.language.objects.shared.SharedObjects;
1920

21+
import static org.truffleruby.cext.ValueWrapperManager.FALSE_HANDLE;
22+
import static org.truffleruby.cext.ValueWrapperManager.MAX_FIXNUM_VALUE;
23+
import static org.truffleruby.cext.ValueWrapperManager.MIN_FIXNUM_VALUE;
24+
import static org.truffleruby.cext.ValueWrapperManager.NIL_HANDLE;
25+
import static org.truffleruby.cext.ValueWrapperManager.TRUE_HANDLE;
26+
2027
import java.math.BigInteger;
2128

2229
/**
@@ -41,22 +48,18 @@
4148
*/
4249
public abstract class ObjectIDOperations {
4350

44-
public static final long FALSE = 0;
45-
public static final long TRUE = 2;
46-
public static final long NIL = 4;
47-
public static final long FIRST_OBJECT_ID = 6;
51+
public static final long FALSE = FALSE_HANDLE;
52+
public static final long TRUE = TRUE_HANDLE;
53+
public static final long NIL = NIL_HANDLE;
4854

4955
private static final BigInteger LARGE_FIXNUM_FLAG = BigInteger.ONE.shiftLeft(64);
5056
private static final BigInteger FLOAT_FLAG = BigInteger.ONE.shiftLeft(65);
5157

52-
private static final long SMALL_FIXNUM_MIN = -(1L << 62);
53-
private static final long SMALL_FIXNUM_MAX = (1L << 62) - 1;
54-
5558
// primitive => ID
5659

5760
public static boolean isSmallFixnum(long fixnum) {
5861
// TODO: optimize
59-
return SMALL_FIXNUM_MIN <= fixnum && fixnum <= SMALL_FIXNUM_MAX;
62+
return MIN_FIXNUM_VALUE <= fixnum && fixnum <= MAX_FIXNUM_VALUE;
6063
}
6164

6265
public static long smallFixnumToIDOverflow(long fixnum) throws ArithmeticException {
@@ -99,7 +102,7 @@ public static boolean isFloatID(BigInteger id) {
99102
}
100103

101104
public static boolean isBasicObjectID(long id) {
102-
return id >= FIRST_OBJECT_ID && id % 2 == 0;
105+
return id != 0 && (id & ValueWrapperManager.TAG_MASK) == 0;
103106
}
104107

105108
private static BigInteger unsignedBigInteger(long value) {

0 commit comments

Comments
 (0)