Skip to content

Commit 93f50a7

Browse files
committed
add identity message to DynamicObjectNativeWrapper
1 parent 1adbac7 commit 93f50a7

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/DynamicObjectNativeWrapper.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
import com.oracle.truffle.api.profiles.BranchProfile;
173173
import com.oracle.truffle.api.profiles.ConditionProfile;
174174
import com.oracle.truffle.api.profiles.ValueProfile;
175+
import com.oracle.truffle.api.utilities.TriState;
175176
import com.oracle.truffle.llvm.spi.NativeTypeLibrary;
176177
import com.oracle.truffle.llvm.spi.ReferenceLibrary;
177178

@@ -1703,6 +1704,31 @@ protected static boolean isObType(String key) {
17031704
}
17041705
}
17051706

1707+
@ExportMessage
1708+
@TruffleBoundary
1709+
int identityHashCode() {
1710+
int val = Byte.hashCode(state) ^ Long.hashCode(value);
1711+
if (Double.isNaN(dvalue)) {
1712+
return val;
1713+
} else {
1714+
return val ^ Double.hashCode(dvalue);
1715+
}
1716+
}
1717+
1718+
@ExportMessage
1719+
TriState isIdenticalOrUndefined(Object obj) {
1720+
if (obj instanceof PrimitiveNativeWrapper) {
1721+
// This basically emulates singletons for boxed values. However, we need to do so to
1722+
// preserve the invariant that storing an object into a list and getting it out (in
1723+
// the same critical region) returns the same object.
1724+
PrimitiveNativeWrapper other = (PrimitiveNativeWrapper) obj;
1725+
return TriState.valueOf(other.state == state && other.value == value &&
1726+
(other.dvalue == dvalue || Double.isNaN(dvalue) && Double.isNaN(other.dvalue)));
1727+
} else {
1728+
return TriState.UNDEFINED;
1729+
}
1730+
}
1731+
17061732
@ExportMessage
17071733
static class IsSame {
17081734

0 commit comments

Comments
 (0)