|
145 | 145 | import com.oracle.truffle.api.dsl.Cached.Exclusive;
|
146 | 146 | import com.oracle.truffle.api.dsl.Cached.Shared;
|
147 | 147 | import com.oracle.truffle.api.dsl.CachedContext;
|
| 148 | +import com.oracle.truffle.api.dsl.Fallback; |
148 | 149 | import com.oracle.truffle.api.dsl.GenerateUncached;
|
149 | 150 | import com.oracle.truffle.api.dsl.ImportStatic;
|
150 | 151 | import com.oracle.truffle.api.dsl.Specialization;
|
|
164 | 165 | import com.oracle.truffle.api.profiles.ConditionProfile;
|
165 | 166 | import com.oracle.truffle.api.profiles.ValueProfile;
|
166 | 167 | import com.oracle.truffle.llvm.spi.NativeTypeLibrary;
|
| 168 | +import com.oracle.truffle.llvm.spi.ReferenceLibrary; |
167 | 169 |
|
168 | 170 | @ExportLibrary(InteropLibrary.class)
|
169 | 171 | @ExportLibrary(NativeTypeLibrary.class)
|
@@ -1281,6 +1283,7 @@ public boolean isMemberModifiable(String member) {
|
1281 | 1283 | }
|
1282 | 1284 | }
|
1283 | 1285 |
|
| 1286 | + @ExportLibrary(ReferenceLibrary.class) |
1284 | 1287 | public static final class PrimitiveNativeWrapper extends DynamicObjectNativeWrapper {
|
1285 | 1288 |
|
1286 | 1289 | public static final byte PRIMITIVE_STATE_BOOL = 1 << 0;
|
@@ -1400,6 +1403,24 @@ public static PrimitiveNativeWrapper createDouble(double val) {
|
1400 | 1403 | protected boolean isMemberReadable(String member) {
|
1401 | 1404 | return member.equals(DynamicObjectNativeWrapper.GP_OBJECT) || NativeMemberNames.isValid(member);
|
1402 | 1405 | }
|
| 1406 | + |
| 1407 | + @ExportMessage |
| 1408 | + static class IsSame { |
| 1409 | + |
| 1410 | + @Specialization |
| 1411 | + static boolean doPrimitiveWrapper(PrimitiveNativeWrapper receiver, PrimitiveNativeWrapper other) { |
| 1412 | + // This basically emulates singletons for boxed values. However, we need to do so to |
| 1413 | + // preserve the invariant that storing an object into a list and getting it out (in |
| 1414 | + // the same critical region) returns the same object. |
| 1415 | + return other.state == receiver.state && other.value == receiver.value && (other.dvalue == receiver.dvalue || Double.isNaN(receiver.dvalue) && Double.isNaN(other.dvalue)); |
| 1416 | + } |
| 1417 | + |
| 1418 | + @Fallback |
| 1419 | + @SuppressWarnings("unused") |
| 1420 | + static boolean doGeneric(PrimitiveNativeWrapper receiver, Object other) { |
| 1421 | + return false; |
| 1422 | + } |
| 1423 | + } |
1403 | 1424 | }
|
1404 | 1425 |
|
1405 | 1426 | @ExportMessage
|
|
0 commit comments