Skip to content

Commit 72dfb19

Browse files
committed
Remove the ObjectHashMap.putUncachedWithJavaEq hack, because tp_richcompare slots for builtins are now initialized before the rest of the runtime
1 parent 7ae1294 commit 72dfb19

File tree

8 files changed

+18
-60
lines changed

8 files changed

+18
-60
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ErrnoModuleBuiltins.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import com.oracle.graal.python.builtins.objects.common.EconomicMapStorage;
5252
import com.oracle.graal.python.builtins.objects.dict.PDict;
5353
import com.oracle.graal.python.builtins.objects.exception.OSErrorEnum;
54-
import com.oracle.graal.python.lib.PyObjectHashNode;
5554
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5655
import com.oracle.graal.python.runtime.object.PFactory;
5756
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -82,6 +81,6 @@ public void initialize(Python3Core core) {
8281

8382
private void addConstant(int number, TruffleString name, EconomicMapStorage storage) {
8483
addBuiltinConstant(name, number);
85-
storage.putUncachedWithJavaEq(number, PyObjectHashNode.hash(number), name);
84+
storage.putUncached(number, name);
8685
}
8786
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2874,8 +2874,8 @@ abstract static class SysconfNode extends PythonUnaryBuiltinNode {
28742874
public static final EconomicMapStorage SYSCONF_NAMES = EconomicMapStorage.create();
28752875
static {
28762876
// TODO populate from constants
2877-
SYSCONF_NAMES.putUncachedWithJavaEq(T_SC_CLK_TCK, SC_CLK_TCK);
2878-
SYSCONF_NAMES.putUncachedWithJavaEq(T_SC_NPROCESSORS_ONLN, SC_NPROCESSORS_ONLN);
2877+
SYSCONF_NAMES.putUncached(T_SC_CLK_TCK, SC_CLK_TCK);
2878+
SYSCONF_NAMES.putUncached(T_SC_NPROCESSORS_ONLN, SC_NPROCESSORS_ONLN);
28792879
}
28802880

28812881
@Specialization

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ public void postInitialize0(Python3Core core) {
686686
private static PFrozenSet createStdLibModulesSet(PythonLanguage language) {
687687
EconomicMapStorage storage = EconomicMapStorage.create(STDLIB_MODULE_NAMES.length);
688688
for (String s : STDLIB_MODULE_NAMES) {
689-
storage.putUncachedWithJavaEq(s, PNone.NONE);
689+
storage.putUncached(s, PNone.NONE);
690690
}
691691
return PFactory.createFrozenSet(language, storage);
692692
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/hashlib/HashlibModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
157157
public void initialize(Python3Core core) {
158158
EconomicMapStorage algos = EconomicMapStorage.create(DIGEST_ALGORITHMS.length);
159159
for (var digest : DIGEST_ALGORITHMS) {
160-
algos.putUncachedWithJavaEq(digest, PNone.NONE);
160+
algos.putUncached(digest, PNone.NONE);
161161
}
162162
PythonLanguage language = core.getLanguage();
163163
addBuiltinConstant("openssl_md_meth_names", PFactory.createFrozenSet(language, algos));

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/EconomicMapStorage.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,23 +155,20 @@ public void putUncached(TruffleString key, Object value) {
155155
PutUnsafeNode.putUncached(this.map, key, PyObjectHashNode.hash(key, HashCodeNode.getUncached()), value);
156156
}
157157

158-
private void putUncached(Object key, Object value) {
159-
PutNode.getUncached().put(null, null, this.map, key, PyObjectHashNode.executeUncached(key), value);
160-
}
161-
162-
// Solves boot-order problem, do not use in normal code or during startup when __eq__ of
163-
// builtins may not be properly set-up
164-
public void putUncachedWithJavaEq(Object key, long keyHash, Object value) {
165-
PutUnsafeNode.putUncachedWithJavaEq(this.map, key, keyHash, value);
158+
@TruffleBoundary
159+
public void putUncached(Object key, Object value) {
160+
PutNode.getUncached().execute(null, null, this.map, key, PyObjectHashNode.executeUncached(key), value);
166161
}
167162

168-
public void putUncachedWithJavaEq(TruffleString key, Object value) {
169-
putUncachedWithJavaEq(key, PyObjectHashNode.hash(key, HashCodeNode.getUncached()), value);
163+
@TruffleBoundary
164+
public void putUncached(int key, Object value) {
165+
PutUnsafeNode.putUncached(this.map, key, PyObjectHashNode.hash(key), value);
170166
}
171167

172-
public void putUncachedWithJavaEq(String key, Object value) {
168+
@TruffleBoundary
169+
public void putUncached(String key, Object value) {
173170
TruffleString ts = toTruffleStringUncached(key);
174-
putUncachedWithJavaEq(ts, value);
171+
putUncached(ts, value);
175172
}
176173

177174
private static void putAllUncached(LinkedHashMap<String, Object> map, EconomicMapStorage result) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/ObjectHashMap.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,12 @@
4444

4545
import java.util.Arrays;
4646

47-
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
48-
import com.oracle.graal.python.builtins.objects.cext.PythonNativeClass;
4947
import com.oracle.graal.python.builtins.objects.common.ObjectHashMapFactory.IsSideEffectingKeyNodeGen;
5048
import com.oracle.graal.python.builtins.objects.common.ObjectHashMapFactory.PutNodeGen;
5149
import com.oracle.graal.python.builtins.objects.str.PString;
52-
import com.oracle.graal.python.builtins.objects.type.PythonManagedClass;
5350
import com.oracle.graal.python.lib.PyObjectRichCompareBool;
5451
import com.oracle.graal.python.nodes.PGuards;
5552
import com.oracle.graal.python.util.PythonUtils;
56-
import com.oracle.truffle.api.CompilerAsserts;
5753
import com.oracle.truffle.api.CompilerDirectives;
5854
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5955
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
@@ -621,14 +617,6 @@ public static void putUncached(ObjectHashMap map, Object key, long keyHash, Obje
621617

622618
abstract void execute(Frame frame, Node inliningTarget, ObjectHashMap map, Object key, long keyHash, Object value);
623619

624-
static void putUncachedWithJavaEq(ObjectHashMap map, Object key, long keyHash, Object value) {
625-
assert isJavaEqualsAllowed(key) : key;
626-
doPutWithRestart(null, null, map, key, keyHash, value,
627-
InlinedBranchProfile.getUncached(), InlinedCountingConditionProfile.getUncached(), InlinedCountingConditionProfile.getUncached(),
628-
InlinedCountingConditionProfile.getUncached(), InlinedCountingConditionProfile.getUncached(), InlinedBranchProfile.getUncached(), InlinedBranchProfile.getUncached(),
629-
null);
630-
}
631-
632620
// "public" for testing...
633621
@Specialization
634622
public static void doPutWithRestart(Frame frame, Node inliningTarget, ObjectHashMap map, Object key, long keyHash, Object value,
@@ -908,10 +896,6 @@ private boolean keysEqual(int[] originalIndices, Frame frame, Node inliningTarge
908896
if (originalKey == key) {
909897
return true;
910898
}
911-
if (CompilerDirectives.inInterpreter() && eqNode == null) {
912-
// this is hack, see putUncachedWithJavaEq
913-
return javaEquals(originalKey, key);
914-
}
915899
boolean result = eqNode.executeEq(frame, inliningTarget, originalKey, key);
916900
if (getKey(index) != originalKey || indices != originalIndices) {
917901
// Either someone overridden the slot we are just examining, or rehasing reallocated the
@@ -930,18 +914,6 @@ private boolean keysEqual(int[] originalIndices, Frame frame, Node inliningTarge
930914
return result;
931915
}
932916

933-
private static boolean javaEquals(Object a, Object b) {
934-
CompilerAsserts.neverPartOfCompilation();
935-
assert isJavaEqualsAllowed(a) : a;
936-
assert isJavaEqualsAllowed(b) : b;
937-
return a.equals(b);
938-
}
939-
940-
private static boolean isJavaEqualsAllowed(Object o) {
941-
return o instanceof PythonManagedClass || o instanceof PythonBuiltinClassType || //
942-
o instanceof PythonNativeClass || o instanceof Number || o instanceof TruffleString;
943-
}
944-
945917
/**
946918
* Called when we need space for new entry. It determines the new size from the number of slots
947919
* occupied by real values (i.e., does not count dummy entries), so the new size may be actually

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionGroupBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private static void createExceptionGroupType(Python3Core core) {
133133
Object typeBuiltin = builtins.getAttribute(T_TYPE);
134134
PTuple bases = PFactory.createTuple(language, new Object[]{PythonBuiltinClassType.PBaseExceptionGroup, PythonBuiltinClassType.Exception});
135135
EconomicMapStorage dictStorage = EconomicMapStorage.create(1);
136-
dictStorage.putUncachedWithJavaEq(T___MODULE__, T_BUILTINS);
136+
dictStorage.putUncached(T___MODULE__, T_BUILTINS);
137137
PDict dict = PFactory.createDict(language, dictStorage);
138138
Object exceptionGroupType = CallNode.executeUncached(typeBuiltin, T_EXCEPTION_GROUP, bases, dict);
139139
builtins.setAttribute(T_EXCEPTION_GROUP, exceptionGroupType);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -815,19 +815,9 @@ protected static void unsafeAddSubclass(Object base, Object subclass) {
815815
long hash = ObjectBuiltins.HashNode.hash(subclass);
816816
PDict dict = executeUncached(base);
817817
HashingStorage storage = dict.getDictStorage();
818-
// Booting order problem: special method slot for object.__eq__ is not initialized yet
819-
// In the unlikely event of hash collision __eq__ would fail
820-
if (HashingStorageLen.executeUncached(storage) == 0) {
821-
// This should not call __eq__
822-
HashingStorageSetItemWithHash setItem = HashingStorageSetItemWithHashNodeGen.getUncached();
823-
storage = setItem.execute(null, null, storage, subclass, hash, subclass);
824-
dict.setDictStorage(storage);
825-
} else {
826-
// the storage must be EconomicMap, because keys should not be Strings so there is
827-
// no other option left
828-
EconomicMapStorage mapStorage = (EconomicMapStorage) storage;
829-
mapStorage.putUncachedWithJavaEq(subclass, hash, subclass);
830-
}
818+
HashingStorageSetItemWithHash setItem = HashingStorageSetItemWithHashNodeGen.getUncached();
819+
storage = setItem.execute(null, null, storage, subclass, hash, subclass);
820+
dict.setDictStorage(storage);
831821
}
832822

833823
protected static void unsafeRemoveSubclass(Object base, Object subclass) {

0 commit comments

Comments
 (0)