Skip to content

Commit 231f8ca

Browse files
committed
Adjust true/nil/undef values based on the changes in special_consts.h
1 parent d1f09a9 commit 231f8ca

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,20 @@ public final class ValueWrapperManager {
4242

4343
static final long UNSET_HANDLE = -2L;
4444

45-
/* These constants are taken from ruby.h, and are based on us not tagging doubles. */
45+
/* These constants are taken from lib/cext/include/ruby/internal/special_consts.h with USE_FLONUM=false */
4646

47-
public static final int FALSE_HANDLE = 0b000;
48-
public static final int TRUE_HANDLE = 0b010;
49-
public static final int NIL_HANDLE = 0b100;
50-
public static final int UNDEF_HANDLE = 0b110;
47+
public static final int FALSE_HANDLE = 0b0000;
48+
public static final int TRUE_HANDLE = 0b0110;
49+
public static final int NIL_HANDLE = 0b0010;
50+
public static final int UNDEF_HANDLE = 0b1010;
51+
public static final long IMMEDIATE_MASK = 0b0011;
5152

5253
public static final long LONG_TAG = 1;
5354
public static final long OBJECT_TAG = 0;
5455

5556
public static final long MIN_FIXNUM_VALUE = -(1L << 62);
5657
public static final long MAX_FIXNUM_VALUE = (1L << 62) - 1;
5758

58-
public static final long TAG_MASK = 0b111;
59-
public static final long TAG_BITS = 3;
60-
6159
public final ValueWrapper trueWrapper = new ValueWrapper(true, TRUE_HANDLE, null);
6260
public final ValueWrapper falseWrapper = new ValueWrapper(false, FALSE_HANDLE, null);
6361
public final ValueWrapper undefWrapper = new ValueWrapper(NotProvided.INSTANCE, UNDEF_HANDLE, null);
@@ -177,9 +175,10 @@ public long totalHandleAllocations() {
177175
return counter.get();
178176
}
179177

178+
private static final long ADDRESS_ALIGN_BITS = 3;
180179
private static final int BLOCK_BITS = 15;
181-
private static final int BLOCK_SIZE = 1 << (BLOCK_BITS - TAG_BITS);
182-
private static final int BLOCK_BYTE_SIZE = BLOCK_SIZE << TAG_BITS;
180+
private static final int BLOCK_SIZE = 1 << (BLOCK_BITS - ADDRESS_ALIGN_BITS);
181+
private static final int BLOCK_BYTE_SIZE = BLOCK_SIZE << ADDRESS_ALIGN_BITS;
183182
private static final long BLOCK_MASK = -1L << BLOCK_BITS;
184183
private static final long OFFSET_MASK = ~BLOCK_MASK;
185184
public static final long ALLOCATION_BASE = 0x0badL << 48;
@@ -245,7 +244,7 @@ public int getIndex() {
245244
}
246245

247246
public ValueWrapper getWrapper(long handle) {
248-
int offset = (int) (handle & OFFSET_MASK) >> TAG_BITS;
247+
int offset = (int) (handle & OFFSET_MASK) >> ADDRESS_ALIGN_BITS;
249248
return wrappers[offset].get();
250249
}
251250

@@ -371,7 +370,7 @@ public static boolean isTaggedLong(long handle) {
371370
}
372371

373372
public static boolean isTaggedObject(long handle) {
374-
return handle != FALSE_HANDLE && (handle & TAG_MASK) == OBJECT_TAG;
373+
return handle != FALSE_HANDLE && (handle & IMMEDIATE_MASK) == OBJECT_TAG;
375374
}
376375

377376
public static boolean isMallocAligned(long handle) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static boolean isFloatID(BigInteger id) {
108108
}
109109

110110
public static boolean isBasicObjectID(long id) {
111-
return id != 0 && (id & ValueWrapperManager.TAG_MASK) == 0;
111+
return id != FALSE && (id & ValueWrapperManager.IMMEDIATE_MASK) == 0;
112112
}
113113

114114
@TruffleBoundary // BigInteger

test/truffle/compiler/pe/core/objectid_pe.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
# GNU General Public License version 2, or
77
# GNU Lesser General Public License version 2.1.
88

9-
example "nil.object_id", 4
9+
example "nil.object_id", 2
1010

11-
example "true.object_id", 2
11+
example "true.object_id", 6
1212

1313
example "false.object_id", 0
1414

test/truffle/compiler/pe/pe.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ def report(status, code, message = nil)
144144
if value == example.expected_value
145145
report 'OK', example.code
146146
else
147-
report 'INCORRECT', example.code, "was: #{$value.inspect} and not: #{example.expected_value.inspect}"
147+
report 'INCORRECT', example.code, "was: #{value.inspect} and not: #{example.expected_value.inspect}"
148148
failed += 1
149149
end
150150
end
151151
else
152152
if constant
153-
report 'QUERY', example.code, "wasn't supposed to be constant but it was (#{$value.inspect})"
153+
report 'QUERY', example.code, "wasn't supposed to be constant but it was (#{value.inspect})"
154154
failed += 1
155155
else
156156
report 'OK (counter)', example.code

0 commit comments

Comments
 (0)