@@ -814,6 +814,9 @@ public final List<KeyAndHash> execute(Frame frame, Node inliningTarget, HashingS
814
814
Object subclassValue = pref .getObject ();
815
815
if (subclassValue == null ) {
816
816
Object key = HashingStorageIteratorKey .executeUncached (storage , it );
817
+ // CPython uses the object pointer as the key, but we cannot so we do not
818
+ // really know how the hash is arrived at and need to make sure to remove
819
+ // the same hash that was stored.
817
820
long hash = HashingStorageIteratorKeyHash .executeUncached (storage , it );
818
821
acc .add (new KeyAndHash (key , hash ));
819
822
}
@@ -833,6 +836,10 @@ static void clearEmptyReferences(EconomicMapStorage storage) {
833
836
protected static void addSubclass (PythonAbstractClass base , PythonManagedClass subclass ) {
834
837
CompilerAsserts .neverPartOfCompilation ();
835
838
PDict dict = executeUncached (base );
839
+ // CPython uses the object pointer as the key, but we cannot since identity hashes are
840
+ // not unique. So we need to use the actual weakref as the key here, but not all
841
+ // classes are hashable. So we use the identity hash code for the map storage hash.
842
+ long hash = System .identityHashCode (subclass );
836
843
HashingStorage storage = dict .getDictStorage ();
837
844
Object weakref = PFactory .createReferenceType (PythonLanguage .get (null ), subclass );
838
845
if (!(storage instanceof EconomicMapStorage )) {
@@ -842,7 +849,7 @@ protected static void addSubclass(PythonAbstractClass base, PythonManagedClass s
842
849
} else {
843
850
clearEmptyReferences ((EconomicMapStorage ) storage );
844
851
}
845
- ((EconomicMapStorage ) storage ).putUncached (weakref , weakref );
852
+ ((EconomicMapStorage ) storage ).putUncached (weakref , hash , weakref );
846
853
}
847
854
848
855
static final class RemoveSubclassValue extends HashingStorageForEachCallback <PythonManagedClass > {
0 commit comments