diff --git a/ci/graal/common.json b/ci/graal/common.json index fdef930cc0..509db451ef 100644 --- a/ci/graal/common.json +++ b/ci/graal/common.json @@ -4,7 +4,7 @@ "Jsonnet files should not include this file directly but use ci/common.jsonnet instead." ], - "mx_version": "7.67.0", + "mx_version": "7.67.2", "COMMENT.jdks": "When adding or removing JDKs keep in sync with JDKs in ci/common.jsonnet", "jdks": { @@ -49,12 +49,12 @@ "graalvm-ee-25-ea": {"name": "graalvm-jdk", "version": "25.0.0", "ea": "36", "platformspecific": true }, "oraclejdk-latest": {"name": "jpg-jdk", "version": "25", "build_id": "jdk-25.0.1+8", "platformspecific": true, "extrabundles": ["static-libs"]}, - "labsjdk-ce-latest": {"name": "labsjdk", "version": "ce-25.0.1+8-jvmci-25.1-b08", "platformspecific": true }, - "labsjdk-ce-latestDebug": {"name": "labsjdk", "version": "ce-25.0.1+8-jvmci-25.1-b08-debug", "platformspecific": true }, - "labsjdk-ce-latest-llvm": {"name": "labsjdk", "version": "ce-25.0.1+8-jvmci-25.1-b08-sulong", "platformspecific": true }, - "labsjdk-ee-latest": {"name": "labsjdk", "version": "ee-25.0.1+8-jvmci-25.1-b08", "platformspecific": true }, - "labsjdk-ee-latestDebug": {"name": "labsjdk", "version": "ee-25.0.1+8-jvmci-25.1-b08-debug", "platformspecific": true }, - "labsjdk-ee-latest-llvm": {"name": "labsjdk", "version": "ee-25.0.1+8-jvmci-25.1-b08-sulong", "platformspecific": true } + "labsjdk-ce-latest": {"name": "labsjdk", "version": "ce-25.0.1+8-jvmci-25.1-b09", "platformspecific": true }, + "labsjdk-ce-latestDebug": {"name": "labsjdk", "version": "ce-25.0.1+8-jvmci-25.1-b09-debug", "platformspecific": true }, + "labsjdk-ce-latest-llvm": {"name": "labsjdk", "version": "ce-25.0.1+8-jvmci-25.1-b09-sulong", "platformspecific": true }, + "labsjdk-ee-latest": {"name": "labsjdk", "version": "ee-25.0.1+8-jvmci-25.1-b09", "platformspecific": true }, + "labsjdk-ee-latestDebug": {"name": "labsjdk", "version": "ee-25.0.1+8-jvmci-25.1-b09-debug", "platformspecific": true }, + "labsjdk-ee-latest-llvm": {"name": "labsjdk", "version": "ee-25.0.1+8-jvmci-25.1-b09-sulong", "platformspecific": true } }, "eclipse": { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextNamespaceBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextNamespaceBuiltins.java index ce8af02ca8..35116713cc 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextNamespaceBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextNamespaceBuiltins.java @@ -63,9 +63,8 @@ import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Cached.Shared; import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.library.CachedLibrary; import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.object.DynamicObjectLibrary; +import com.oracle.truffle.api.object.DynamicObject; public final class PythonCextNamespaceBuiltins { @@ -78,20 +77,20 @@ static Object impDict(PDict dict, @Shared("itNext") @Cached HashingStorageIteratorNext itNext, @Shared("itKey") @Cached HashingStorageIteratorKey itKey, @Shared("itVal") @Cached HashingStorageIteratorValue itValue, - @Shared("dylib") @CachedLibrary(limit = "1") DynamicObjectLibrary dyLib) { + @Shared @Cached DynamicObject.PutNode putNode) { HashingStorage storage = dict.getDictStorage(); - return impl(inliningTarget, storage, getIterator, itNext, itKey, itValue, dyLib); + return impl(inliningTarget, storage, getIterator, itNext, itKey, itValue, putNode); } private static Object impl(Node inliningTarget, HashingStorage storage, HashingStorageGetIterator getIterator, HashingStorageIteratorNext itNext, HashingStorageIteratorKey itKey, HashingStorageIteratorValue itValue, - DynamicObjectLibrary dyLib) { + DynamicObject.PutNode putNode) { PSimpleNamespace ns = PFactory.createSimpleNamespace(PythonLanguage.get(inliningTarget)); HashingStorageNodes.HashingStorageIterator it = getIterator.execute(inliningTarget, storage); while (itNext.execute(inliningTarget, storage, it)) { Object key = itKey.execute(inliningTarget, storage, it); Object value = itValue.execute(inliningTarget, storage, it); - dyLib.put(ns, assertNoJavaString(key), value); + putNode.execute(ns, assertNoJavaString(key), value); } return ns; } @@ -104,9 +103,9 @@ static Object impGeneric(Object dict, @Shared("itNext") @Cached HashingStorageIteratorNext itNext, @Shared("itKey") @Cached HashingStorageIteratorKey itKey, @Shared("itVal") @Cached HashingStorageIteratorValue itValue, - @Shared("dylib") @CachedLibrary(limit = "1") DynamicObjectLibrary dyLib) { + @Shared @Cached DynamicObject.PutNode putNode) { HashingStorage hs = initNode.execute(null, dict, PKeyword.EMPTY_KEYWORDS); - return impl(inliningTarget, hs, getIterator, itNext, itKey, itValue, dyLib); + return impl(inliningTarget, hs, getIterator, itNext, itKey, itValue, putNode); } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextStructSeqBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextStructSeqBuiltins.java index 7ba9b40844..4fb4a32a03 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextStructSeqBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextStructSeqBuiltins.java @@ -90,7 +90,7 @@ import com.oracle.truffle.api.interop.InteropLibrary; import com.oracle.truffle.api.library.CachedLibrary; import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.object.DynamicObjectLibrary; +import com.oracle.truffle.api.object.DynamicObject; import com.oracle.truffle.api.strings.TruffleString; public final class PythonCextStructSeqBuiltins { @@ -139,7 +139,8 @@ abstract static class GraalPyPrivate_StructSequence_NewType extends CApiQuaterna Object doGeneric(TruffleString typeName, TruffleString typeDoc, Object fields, int nInSequence, @Cached GraalPyPrivate_StructSequence_InitType2 initNode, @Cached ReadAttributeFromModuleNode readTypeBuiltinNode, - @CachedLibrary(limit = "1") DynamicObjectLibrary dylib, + @Cached DynamicObject.GetShapeFlagsNode getShapeFlagsNode, + @Cached DynamicObject.SetShapeFlagsNode setShapeFlagsNode, @Cached CallNode callTypeNewNode, @Bind PythonLanguage language) { Object typeBuiltin = readTypeBuiltinNode.execute(getCore().getBuiltins(), BuiltinNames.T_TYPE); @@ -147,8 +148,8 @@ Object doGeneric(TruffleString typeName, TruffleString typeDoc, Object fields, i PDict namespace = PFactory.createDict(language, new PKeyword[]{new PKeyword(SpecialAttributeNames.T___DOC__, typeDoc)}); Object cls = callTypeNewNode.executeWithoutFrame(typeBuiltin, typeName, bases, namespace); initNode.execute(cls, fields, nInSequence); - if (cls instanceof PythonClass) { - ((PythonClass) cls).makeStaticBase(dylib); + if (cls instanceof PythonClass pythonClass) { + pythonClass.makeStaticBase(getShapeFlagsNode, setShapeFlagsNode); } return cls; } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTypeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTypeBuiltins.java index 8b31d6dfde..0396efc05f 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTypeBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTypeBuiltins.java @@ -126,7 +126,6 @@ import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.RootNode; import com.oracle.truffle.api.object.DynamicObject; -import com.oracle.truffle.api.object.DynamicObjectLibrary; import com.oracle.truffle.api.object.Shape; import com.oracle.truffle.api.strings.TruffleString; import com.oracle.truffle.api.utilities.CyclicAssumption; @@ -143,7 +142,8 @@ Object doGeneric(Object type, Object name, @Cached PythonCextBuiltins.PromoteBorrowedValue promoteBorrowedValue, @Cached CStructAccess.ReadObjectNode getNativeDict, @Cached GetDictIfExistsNode getDictIfExistsNode, - @CachedLibrary(limit = "3") DynamicObjectLibrary dylib, + @Cached DynamicObject.GetNode getNode, + @Cached DynamicObject.PutNode putNode, @Cached PyDictGetItem getItem, @Cached PyDictSetItem setItem) { TruffleString key = castToTruffleStringNode.castKnownString(inliningTarget, name); @@ -165,7 +165,7 @@ Object doGeneric(Object type, Object name, } Object value; if (dict == null) { - value = dylib.getOrDefault((DynamicObject) cls, key, null); + value = getNode.execute((PythonManagedClass) cls, key, null); } else { value = getItem.execute(null, inliningTarget, dict, key); } @@ -173,7 +173,7 @@ Object doGeneric(Object type, Object name, Object promoted = promoteBorrowedValue.execute(inliningTarget, value); if (promoted != null) { if (dict == null) { - dylib.put((DynamicObject) cls, key, promoted); + putNode.execute((PythonManagedClass) cls, key, promoted); } else { setItem.execute(null, inliningTarget, dict, key, promoted); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/DynamicObjectStorage.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/DynamicObjectStorage.java index 998c212781..6abc2d9436 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/DynamicObjectStorage.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/DynamicObjectStorage.java @@ -69,15 +69,12 @@ import com.oracle.truffle.api.dsl.GenerateInline; import com.oracle.truffle.api.dsl.GenerateUncached; import com.oracle.truffle.api.dsl.ImportStatic; -import com.oracle.truffle.api.dsl.NeverDefault; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.frame.Frame; -import com.oracle.truffle.api.library.CachedLibrary; import com.oracle.truffle.api.nodes.ExplodeLoop; import com.oracle.truffle.api.nodes.ExplodeLoop.LoopExplosionKind; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.object.DynamicObject; -import com.oracle.truffle.api.object.DynamicObjectLibrary; import com.oracle.truffle.api.object.Shape; import com.oracle.truffle.api.profiles.InlinedBranchProfile; import com.oracle.truffle.api.profiles.InlinedConditionProfile; @@ -296,8 +293,8 @@ private static void invalidateAttributeInMROFinalAssumptions(MroSequenceStorage } } - void setStringKey(TruffleString key, Object value, DynamicObjectLibrary dylib, Node inliningTarget, InlinedBranchProfile invalidateMroProfile) { - dylib.put(store, key, assertNoJavaString(value)); + void setStringKey(TruffleString key, Object value, DynamicObject.PutNode putNode, Node inliningTarget, InlinedBranchProfile invalidateMroProfile) { + putNode.execute(store, key, assertNoJavaString(value)); invalidateAttributeInMROFinalAssumption(key, inliningTarget, invalidateMroProfile); } @@ -322,8 +319,8 @@ abstract static class ClearNode extends Node { @Specialization(guards = "!isPythonObject(receiver.getStore())") static HashingStorage clearPlain(DynamicObjectStorage receiver, - @CachedLibrary(limit = "3") DynamicObjectLibrary dylib) { - dylib.resetShape(receiver.getStore(), PythonLanguage.get(dylib).getEmptyShape()); + @Cached DynamicObject.ResetShapeNode resetShapeNode) { + resetShapeNode.execute(receiver.getStore(), PythonLanguage.get(resetShapeNode).getEmptyShape()); return receiver; } @@ -351,39 +348,12 @@ static HashingStorage clearObjectBacked(Node inliningTarget, DynamicObjectStorag abstract static class Copy extends Node { abstract DynamicObjectStorage execute(Node node, DynamicObjectStorage receiver); - @NeverDefault - static DynamicObjectLibrary[] createAccess(int length) { - DynamicObjectLibrary[] result = new DynamicObjectLibrary[length]; - for (int i = 0; i < length; i++) { - result[i] = DynamicObjectLibrary.getFactory().createDispatched(1); - } - return result; - } - - @ExplodeLoop - @Specialization(limit = "1", guards = {"cachedLength < EXPLODE_LOOP_SIZE_LIMIT", "keys.length == cachedLength"}) + @Specialization public static DynamicObjectStorage copy(DynamicObjectStorage receiver, - @SuppressWarnings("unused") @Bind("receiver.store") DynamicObject store, - @SuppressWarnings("unused") @CachedLibrary("store") DynamicObjectLibrary dylib, - @Bind("dylib.getKeyArray(store)") Object[] keys, - @Cached(value = "keys.length") int cachedLength, - @Cached("createAccess(cachedLength)") DynamicObjectLibrary[] readLib, - @Cached("createAccess(cachedLength)") DynamicObjectLibrary[] writeLib) { - DynamicObject copy = new Store(PythonLanguage.get(dylib).getEmptyShape()); - for (int i = 0; i < cachedLength; i++) { - writeLib[i].put(copy, keys[i], readLib[i].getOrDefault(receiver.store, keys[i], PNone.NO_VALUE)); - } - return new DynamicObjectStorage(copy); - } - - @Specialization(replaces = "copy") - public static DynamicObjectStorage copyGeneric(DynamicObjectStorage receiver, - @CachedLibrary(limit = "3") DynamicObjectLibrary dylib) { - DynamicObject copy = new Store(PythonLanguage.get(dylib).getEmptyShape()); - Object[] keys = dylib.getKeyArray(receiver.store); - for (Object key : keys) { - dylib.put(copy, key, dylib.getOrDefault(receiver.store, key, PNone.NO_VALUE)); - } + @Bind Node inliningTarget, + @Cached DynamicObject.CopyPropertiesNode copyPropertiesNode) { + DynamicObject copy = new Store(PythonLanguage.get(inliningTarget).getEmptyShape()); + copyPropertiesNode.execute(receiver.store, copy); return new DynamicObjectStorage(copy); } } @@ -394,9 +364,9 @@ public static DynamicObjectStorage copyGeneric(DynamicObjectStorage receiver, public abstract static class DynamicObjectStorageSetStringKey extends SpecializedSetStringKey { @Specialization static void doIt(Node inliningTarget, HashingStorage self, TruffleString key, Object value, - @CachedLibrary(limit = "3") DynamicObjectLibrary dylib, + @Cached DynamicObject.PutNode putNode, @Cached InlinedBranchProfile invalidateMro) { - ((DynamicObjectStorage) self).setStringKey(key, value, dylib, inliningTarget, invalidateMro); + ((DynamicObjectStorage) self).setStringKey(key, value, putNode, inliningTarget, invalidateMro); } } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingStorageNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingStorageNodes.java index dcff73276e..b0043eb9e3 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingStorageNodes.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingStorageNodes.java @@ -96,7 +96,6 @@ import com.oracle.truffle.api.nodes.LoopNode; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.object.DynamicObject; -import com.oracle.truffle.api.object.DynamicObjectLibrary; import com.oracle.truffle.api.profiles.InlinedBranchProfile; import com.oracle.truffle.api.profiles.InlinedConditionProfile; import com.oracle.truffle.api.profiles.InlinedLoopConditionProfile; @@ -231,15 +230,17 @@ abstract static class SpecializedSetStringKey extends Node { public abstract void execute(Node inliningTarget, HashingStorage self, TruffleString key, Object value); } - static EconomicMapStorage dynamicObjectStorageToEconomicMap(Node inliningTarget, DynamicObjectStorage s, DynamicObjectLibrary dylib, PyObjectHashNode hashNode, ObjectHashMap.PutNode putNode) { + static EconomicMapStorage dynamicObjectStorageToEconomicMap(Node inliningTarget, DynamicObjectStorage s, + DynamicObject.GetKeyArrayNode getKeyArrayNode, DynamicObject.GetNode getNode, + PyObjectHashNode hashNode, ObjectHashMap.PutNode putNode) { // TODO: shouldn't we invalidate all MRO assumptions in this case? DynamicObject store = s.store; - EconomicMapStorage result = EconomicMapStorage.create(dylib.getShape(store).getPropertyCount()); + Object[] keys = getKeyArrayNode.execute(store); + EconomicMapStorage result = EconomicMapStorage.create(keys.length); ObjectHashMap resultMap = result.map; - Object[] keys = dylib.getKeyArray(store); for (Object k : keys) { if (k instanceof TruffleString) { - Object v = dylib.getOrDefault(store, k, PNone.NO_VALUE); + Object v = getNode.execute(store, k, PNone.NO_VALUE); if (v != PNone.NO_VALUE) { putNode.put(null, inliningTarget, resultMap, k, hashNode.execute(null, inliningTarget, k), v); } @@ -282,8 +283,8 @@ static HashingStorage empty(Frame frame, Node inliningTarget, @SuppressWarnings( @Specialization(guards = "!self.shouldTransitionOnPut()") static HashingStorage domStringKey(Node inliningTarget, DynamicObjectStorage self, TruffleString key, long keyHash, Object value, @Cached InlinedBranchProfile invalidateMroProfile, - @Shared @CachedLibrary(limit = "3") DynamicObjectLibrary dylib) { - self.setStringKey(key, value, dylib, inliningTarget, invalidateMroProfile); + @Cached DynamicObject.PutNode putNode) { + self.setStringKey(key, value, putNode, inliningTarget, invalidateMroProfile); return self; } @@ -292,7 +293,6 @@ static HashingStorage domStringKey(Node inliningTarget, DynamicObjectStorage sel static HashingStorage dom(Frame frame, Node inliningTarget, DynamicObjectStorage self, Object key, long keyHash, Object value, @Cached InlinedConditionProfile shouldTransitionProfile, @Exclusive @Cached PyUnicodeCheckExactNode isBuiltinString, - @Shared @CachedLibrary(limit = "3") DynamicObjectLibrary dylib, @Cached DOMStorageSetItemWithHash domNode) { boolean transition = true; if (shouldTransitionProfile.profile(inliningTarget, !self.shouldTransitionOnPut())) { @@ -300,7 +300,7 @@ static HashingStorage dom(Frame frame, Node inliningTarget, DynamicObjectStorage transition = false; } } - return domNode.execute(frame, inliningTarget, self, key, keyHash, value, transition, dylib); + return domNode.execute(frame, inliningTarget, self, key, keyHash, value, transition); } @Specialization @@ -327,25 +327,26 @@ static HashingStorage foreign(Node inliningTarget, ForeignHashingStorage self, O @ImportStatic(PGuards.class) abstract static class DOMStorageSetItemWithHash extends Node { public abstract HashingStorage execute(Frame frame, Node inliningTarget, DynamicObjectStorage self, Object key, long keyHash, Object value, - boolean transition, DynamicObjectLibrary dylib); + boolean transition); @Specialization(guards = {"!transition", "isBuiltinString.execute(inliningTarget, key)"}, limit = "1") - static HashingStorage domStringKey(Node inliningTarget, DynamicObjectStorage self, Object key, @SuppressWarnings("unused") long keyHash, Object value, - @SuppressWarnings("unused") boolean transition, DynamicObjectLibrary dylib, + static HashingStorage domStringKey(Node inliningTarget, DynamicObjectStorage self, Object key, long keyHash, Object value, boolean transition, @SuppressWarnings("unused") @Cached PyUnicodeCheckExactNode isBuiltinString, @Cached CastBuiltinStringToTruffleStringNode castStr, - @Cached InlinedBranchProfile invalidateMroProfile) { - self.setStringKey(castStr.execute(inliningTarget, key), value, dylib, inliningTarget, invalidateMroProfile); + @Cached InlinedBranchProfile invalidateMroProfile, + @Cached DynamicObject.PutNode putNode) { + self.setStringKey(castStr.execute(inliningTarget, key), value, putNode, inliningTarget, invalidateMroProfile); return self; } @Fallback - static HashingStorage domTransition(Frame frame, Node inliningTarget, DynamicObjectStorage self, Object key, @SuppressWarnings("unused") long keyHash, Object value, - @SuppressWarnings("unused") boolean transition, DynamicObjectLibrary dylib, + static HashingStorage domTransition(Frame frame, Node inliningTarget, DynamicObjectStorage self, Object key, long keyHash, Object value, boolean transition, @Cached PyObjectHashNode hashNode, @Cached ObjectHashMap.PutNode putUnsafeNode, - @Cached PutNode putNode) { - EconomicMapStorage result = dynamicObjectStorageToEconomicMap(inliningTarget, self, dylib, hashNode, putUnsafeNode); + @Cached PutNode putNode, + @Cached DynamicObject.GetKeyArrayNode getKeyArrayNode, + @Cached DynamicObject.GetNode getNode) { + EconomicMapStorage result = dynamicObjectStorageToEconomicMap(inliningTarget, self, getKeyArrayNode, getNode, hashNode, putUnsafeNode); putNode.execute(frame, inliningTarget, result.map, key, keyHash, value); return result; } @@ -407,8 +408,8 @@ static HashingStorage empty(Frame frame, Node inliningTarget, @SuppressWarnings( @Specialization(guards = "!self.shouldTransitionOnPut()") static HashingStorage domStringKey(Node inliningTarget, DynamicObjectStorage self, TruffleString key, Object value, @Cached InlinedBranchProfile invalidateMroProfile, - @Shared @CachedLibrary(limit = "3") DynamicObjectLibrary dylib) { - self.setStringKey(key, value, dylib, inliningTarget, invalidateMroProfile); + @Cached DynamicObject.PutNode putNode) { + self.setStringKey(key, value, putNode, inliningTarget, invalidateMroProfile); return self; } @@ -417,7 +418,6 @@ static HashingStorage domStringKey(Node inliningTarget, DynamicObjectStorage sel static HashingStorage dom(Frame frame, Node inliningTarget, DynamicObjectStorage self, Object key, Object value, @Cached InlinedConditionProfile shouldTransitionProfile, @Exclusive @Cached PyUnicodeCheckExactNode isBuiltinString, - @Shared @CachedLibrary(limit = "3") DynamicObjectLibrary dylib, @Cached DOMStorageSetItem domNode) { boolean transition = true; if (shouldTransitionProfile.profile(inliningTarget, !self.shouldTransitionOnPut())) { @@ -425,7 +425,7 @@ static HashingStorage dom(Frame frame, Node inliningTarget, DynamicObjectStorage transition = false; } } - return domNode.execute(frame, inliningTarget, self, key, value, transition, dylib); + return domNode.execute(frame, inliningTarget, self, key, value, transition); } @Specialization @@ -453,25 +453,26 @@ static HashingStorage foreign(Node inliningTarget, ForeignHashingStorage self, O @ImportStatic(PGuards.class) abstract static class DOMStorageSetItem extends Node { public abstract HashingStorage execute(Frame frame, Node inliningTarget, DynamicObjectStorage self, Object key, Object value, - boolean transition, DynamicObjectLibrary dylib); + boolean transition); @Specialization(guards = {"!transition", "isBuiltinString.execute(inliningTarget, key)"}, limit = "1") - static HashingStorage domStringKey(Node inliningTarget, DynamicObjectStorage self, Object key, Object value, - @SuppressWarnings("unused") boolean transition, DynamicObjectLibrary dylib, + static HashingStorage domStringKey(Node inliningTarget, DynamicObjectStorage self, Object key, Object value, boolean transition, @SuppressWarnings("unused") @Cached PyUnicodeCheckExactNode isBuiltinString, + @Cached DynamicObject.PutNode putNode, @Cached CastBuiltinStringToTruffleStringNode castStr, @Cached InlinedBranchProfile invalidateMroProfile) { - self.setStringKey(castStr.execute(inliningTarget, key), value, dylib, inliningTarget, invalidateMroProfile); + self.setStringKey(castStr.execute(inliningTarget, key), value, putNode, inliningTarget, invalidateMroProfile); return self; } @Fallback - static HashingStorage domTransition(Frame frame, Node inliningTarget, DynamicObjectStorage self, Object key, Object value, - @SuppressWarnings("unused") boolean transition, DynamicObjectLibrary dylib, + static HashingStorage domTransition(Frame frame, Node inliningTarget, DynamicObjectStorage self, Object key, Object value, boolean transition, @Cached PyObjectHashNode hashNode, @Cached ObjectHashMap.PutNode putUnsafeNode, - @Cached PutNode putNode) { - EconomicMapStorage result = dynamicObjectStorageToEconomicMap(inliningTarget, self, dylib, hashNode, putUnsafeNode); + @Cached PutNode putNode, + @Cached DynamicObject.GetKeyArrayNode getKeyArrayNode, + @Cached DynamicObject.GetNode getNode) { + EconomicMapStorage result = dynamicObjectStorageToEconomicMap(inliningTarget, self, getKeyArrayNode, getNode, hashNode, putUnsafeNode); putNode.execute(frame, inliningTarget, result.map, key, hashNode.execute(frame, inliningTarget, key), value); return result; } @@ -543,7 +544,8 @@ static Object domStringKey(Frame frame, Node inliningTarget, DynamicObjectStorag @Cached CastBuiltinStringToTruffleStringNode castStr, @Exclusive @Cached PyObjectHashNode hashNode, @Exclusive @Cached InlinedBranchProfile invalidateMroProfile, - @CachedLibrary(limit = "3") DynamicObjectLibrary dylib) { + @Cached DynamicObject.GetNode getNode, + @Cached DynamicObject.PutNode putNode) { if (!isBuiltinString.execute(inliningTarget, keyObj)) { // Just for the potential side effects hashNode.execute(frame, inliningTarget, keyObj); @@ -552,16 +554,16 @@ static Object domStringKey(Frame frame, Node inliningTarget, DynamicObjectStorag TruffleString key = castStr.execute(inliningTarget, keyObj); DynamicObject store = self.store; if (needsValue) { - Object val = dylib.getOrDefault(store, key, PNone.NO_VALUE); + Object val = getNode.execute(store, key, PNone.NO_VALUE); if (val == PNone.NO_VALUE) { return null; } else { - dylib.put(store, key, PNone.NO_VALUE); + putNode.execute(store, key, PNone.NO_VALUE); self.invalidateAttributeInMROFinalAssumption(key, inliningTarget, invalidateMroProfile); return val; } } else { - if (dylib.putIfPresent(store, key, PNone.NO_VALUE)) { + if (putNode.executeIfPresent(store, key, PNone.NO_VALUE)) { self.invalidateAttributeInMROFinalAssumption(key, inliningTarget, invalidateMroProfile); return true; } else { @@ -804,8 +806,8 @@ static HashingStorageIterator economicMap(@SuppressWarnings("unused") EconomicMa @Specialization static HashingStorageIterator dom(DynamicObjectStorage self, - @CachedLibrary(limit = "3") DynamicObjectLibrary dylib) { - return new HashingStorageIterator(dylib.getKeyArray(self.store), false); + @Cached DynamicObject.GetKeyArrayNode getKeyArrayNode) { + return new HashingStorageIterator(getKeyArrayNode.execute(self.store), false); } @Specialization @@ -854,8 +856,8 @@ static HashingStorageIterator economicMap(@SuppressWarnings("unused") EconomicMa @Specialization static HashingStorageIterator dom(DynamicObjectStorage self, - @CachedLibrary(limit = "3") DynamicObjectLibrary dylib) { - HashingStorageIterator it = new HashingStorageIterator(dylib.getKeyArray(self.store), true); + @Cached DynamicObject.GetKeyArrayNode getKeyArrayNode) { + HashingStorageIterator it = new HashingStorageIterator(getKeyArrayNode.execute(self.store), true); it.index = it.domKeys.length; return it; } @@ -936,11 +938,11 @@ static boolean economicMapReverse(EconomicMapStorage self, HashingStorageIterato @Specialization(guards = "!it.isReverse") static boolean dom(DynamicObjectStorage self, HashingStorageIterator it, - @Shared @CachedLibrary(limit = "3") DynamicObjectLibrary dylib) { + @Shared @Cached DynamicObject.GetNode getNode) { it.index++; while (it.index < it.domKeys.length) { if (it.domKeys[it.index] instanceof TruffleString) { - Object val = dylib.getOrDefault(self.store, it.domKeys[it.index], PNone.NO_VALUE); + Object val = getNode.execute(self.store, it.domKeys[it.index], PNone.NO_VALUE); if (val != PNone.NO_VALUE) { it.currentValue = val; return true; @@ -954,11 +956,11 @@ static boolean dom(DynamicObjectStorage self, HashingStorageIterator it, @Specialization(guards = "it.isReverse") static boolean domReverse(DynamicObjectStorage self, HashingStorageIterator it, - @Shared @CachedLibrary(limit = "3") DynamicObjectLibrary dylib) { + @Shared @Cached DynamicObject.GetNode getNode) { it.index--; while (it.index >= 0) { if (it.domKeys[it.index] instanceof TruffleString) { - Object val = dylib.getOrDefault(self.store, it.domKeys[it.index], PNone.NO_VALUE); + Object val = getNode.execute(self.store, it.domKeys[it.index], PNone.NO_VALUE); if (val != PNone.NO_VALUE) { it.currentValue = val; return true; diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/ModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/ModuleBuiltins.java index ab2402c78a..f84fc13fd2 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/ModuleBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/ModuleBuiltins.java @@ -278,6 +278,8 @@ static Object getattribute(VirtualFrame frame, PythonModule self, TruffleString @Bind Node inliningTarget, @Cached IsBuiltinObjectProfile isAttrError, @Cached ReadAttributeFromModuleNode readGetattr, + @Cached ReadAttributeFromModuleNode readName, + @Cached ReadAttributeFromModuleNode readSpec, @Cached ReadAttributeFromObjectNode readInitializing, @Cached InlinedConditionProfile customGetAttr, @Cached CallNode callNode, @@ -291,13 +293,13 @@ static Object getattribute(VirtualFrame frame, PythonModule self, TruffleString } else { TruffleString moduleName; try { - moduleName = castNameToStringNode.execute(inliningTarget, readGetattr.execute(self, T___NAME__)); + moduleName = castNameToStringNode.execute(inliningTarget, readName.execute(self, T___NAME__)); } catch (CannotCastException ce) { // we just don't have the module name moduleName = null; } if (moduleName != null) { - Object moduleSpec = readGetattr.execute(self, T___SPEC__); + Object moduleSpec = readSpec.execute(self, T___SPEC__); if (moduleSpec != PNone.NO_VALUE) { Object isInitializing = readInitializing.execute(moduleSpec, T__INITIALIZING); if (isInitializing != PNone.NO_VALUE && castToBooleanNode.execute(frame, isInitializing)) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java index 55cdf0eb26..3840a52b06 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java @@ -164,9 +164,8 @@ import com.oracle.truffle.api.dsl.NodeFactory; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.library.CachedLibrary; import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.object.DynamicObjectLibrary; +import com.oracle.truffle.api.object.DynamicObject; import com.oracle.truffle.api.profiles.InlinedBranchProfile; import com.oracle.truffle.api.profiles.InlinedConditionProfile; import com.oracle.truffle.api.strings.TruffleString; @@ -225,10 +224,10 @@ abstract static class SetClassNode extends Node { @Specialization static void doPythonObject(PythonObject self, Object newClass, - @CachedLibrary(limit = "3") DynamicObjectLibrary dylib) { + @Cached DynamicObject.SetDynamicTypeNode setDynamicTypeNode) { // Clear the dynamic type when setting the class, so further class changes do not // create new shapes - dylib.setDynamicType(self, PNone.NO_VALUE); + setDynamicTypeNode.execute(self, PNone.NO_VALUE); self.setPythonClass(newClass); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/PythonObject.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/PythonObject.java index 30a2d88dd3..86718564dc 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/PythonObject.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/PythonObject.java @@ -43,7 +43,7 @@ import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.NeverDefault; import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.object.DynamicObjectLibrary; +import com.oracle.truffle.api.object.DynamicObject; import com.oracle.truffle.api.object.Shape; import com.oracle.truffle.api.strings.TruffleString; @@ -94,20 +94,20 @@ public void setPythonClass(Object pythonClass) { @TruffleBoundary public final Object getAttribute(TruffleString key) { - return DynamicObjectLibrary.getUncached().getOrDefault(this, key, PNone.NO_VALUE); + return DynamicObject.GetNode.getUncached().execute(this, key, PNone.NO_VALUE); } @TruffleBoundary public void setAttribute(TruffleString name, Object value) { CompilerAsserts.neverPartOfCompilation(); - DynamicObjectLibrary.getUncached().put(this, name, assertNoJavaString(value)); + DynamicObject.PutNode.getUncached().execute(this, name, assertNoJavaString(value)); } @TruffleBoundary public List getAttributeNames() { ArrayList keyList = new ArrayList<>(); for (Object o : getShape().getKeyList()) { - if (o instanceof TruffleString && DynamicObjectLibrary.getUncached().getOrDefault(this, o, PNone.NO_VALUE) != PNone.NO_VALUE) { + if (o instanceof TruffleString && DynamicObject.GetNode.getUncached().execute(this, o, PNone.NO_VALUE) != PNone.NO_VALUE) { keyList.add((TruffleString) o); } } @@ -144,4 +144,12 @@ public String toString() { public static int getCallSiteInlineCacheMaxDepth() { return PythonOptions.getCallSiteInlineCacheMaxDepth(); } + + public final void addShapeFlag(int flag, DynamicObject.GetShapeFlagsNode getShapeFlagsNode, DynamicObject.SetShapeFlagsNode setShapeFlagsNode) { + int oldFlags = getShapeFlagsNode.execute(this); + int newFlags = oldFlags | flag; + if (newFlags != oldFlags) { + setShapeFlagsNode.execute(this, newFlags); + } + } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/MroShape.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/MroShape.java index f91f9f73e4..be6ae769c6 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/MroShape.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/MroShape.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -57,7 +57,8 @@ import com.oracle.graal.python.runtime.sequence.storage.MroSequenceStorage; import com.oracle.truffle.api.CompilerAsserts; import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.object.DynamicObjectLibrary; +import com.oracle.truffle.api.object.DynamicObject; +import com.oracle.truffle.api.object.DynamicObject.GetNode; import com.oracle.truffle.api.object.Property; import com.oracle.truffle.api.object.Shape; import com.oracle.truffle.api.strings.TruffleString; @@ -102,7 +103,7 @@ public static MroShape create(MroSequenceStorage mro, PythonLanguage lang) { // effecting __eq__ and/or __hash__ return null; } - if ((DynamicObjectLibrary.getUncached().getShapeFlags(managedClass) & HAS_NO_VALUE_PROPERTIES) != 0) { + if ((DynamicObject.GetShapeFlagsNode.getUncached().execute(managedClass) & HAS_NO_VALUE_PROPERTIES) != 0) { return null; } assert hasNoNoValueProperties(managedClass); @@ -168,9 +169,8 @@ public Object getFromMro(MroSequenceStorage mro, TruffleString key) { } private static boolean hasNoNoValueProperties(PythonManagedClass klass) { - DynamicObjectLibrary lib = DynamicObjectLibrary.getFactory().getUncached(klass); for (Object key : klass.getShape().getKeyList()) { - if (key instanceof TruffleString && lib.getOrDefault(klass, key, null) == PNone.NO_VALUE) { + if (key instanceof TruffleString && GetNode.getUncached().execute(klass, key, null) == PNone.NO_VALUE) { // The MROShape machinery makes the assumption that shapes are enough to determine // MRO lookup results, in the presence of properties with NO_VALUE shape is not // enough, such shapes should be marked with the HAS_NO_VALUE_PROPERTIES flag @@ -219,7 +219,7 @@ public static boolean validate(Object obj, PythonLanguage language) { klsShapeProps.add(property.getKey()); } } - klsShapeProps.removeIf(x -> DynamicObjectLibrary.getUncached().getOrDefault(kls, x, null) == PNone.NO_VALUE); + klsShapeProps.removeIf(x -> DynamicObject.GetNode.getUncached().execute(kls, x, null) == PNone.NO_VALUE); Set currMroShapeProps = new HashSet<>(); for (Property property : currMroShape.shape.getPropertyList()) { if (!property.isHidden()) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonClass.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonClass.java index dc28331aa6..a755a155d8 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonClass.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonClass.java @@ -50,7 +50,7 @@ import com.oracle.truffle.api.library.ExportLibrary; import com.oracle.truffle.api.library.ExportMessage; import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.object.DynamicObjectLibrary; +import com.oracle.truffle.api.object.DynamicObject; import com.oracle.truffle.api.object.Shape; import com.oracle.truffle.api.profiles.InlinedBranchProfile; import com.oracle.truffle.api.source.SourceSection; @@ -217,8 +217,8 @@ public void setDictHiddenProp(Node inliningTarget, HiddenAttr.WriteNode writeNod } } - public void makeStaticBase(DynamicObjectLibrary dylib) { - dylib.setShapeFlags(this, dylib.getShapeFlags(this) | IS_STATIC_BASE); + public void makeStaticBase(DynamicObject.GetShapeFlagsNode getShapeFlagsNode, DynamicObject.SetShapeFlagsNode setShapeFlagsNode) { + addShapeFlag(IS_STATIC_BASE, getShapeFlagsNode, setShapeFlagsNode); } public boolean isStaticBase() { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java index 6993e7b675..e1c1a6e142 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java @@ -234,7 +234,7 @@ import com.oracle.truffle.api.interop.InteropLibrary; import com.oracle.truffle.api.interop.UnsupportedMessageException; import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.object.DynamicObjectLibrary; +import com.oracle.truffle.api.object.DynamicObject; import com.oracle.truffle.api.profiles.InlinedBranchProfile; import com.oracle.truffle.api.strings.TruffleString; @@ -1752,7 +1752,7 @@ public static void addOperatorsToBuiltin(Python3Core core, PythonBuiltinClassTyp TpSlotMeta slotMeta = slotDefGroup.getKey(); TpSlot slotValue = slotMeta.getter.get(slots); if (slotMeta == TpSlotMeta.TP_HASH && slotValue == TpSlotHashFun.HASH_NOT_IMPLEMENTED) { - DynamicObjectLibrary.getUncached().put(pythonBuiltinClass, T___HASH__, PNone.NONE); + DynamicObject.PutNode.getUncached().execute(pythonBuiltinClass, T___HASH__, PNone.NONE); continue; } if (!(slotValue instanceof TpSlotBuiltin builtinSlot)) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/HiddenAttr.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/HiddenAttr.java index f08f87e8d7..75aeb5f238 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/HiddenAttr.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/HiddenAttr.java @@ -53,6 +53,7 @@ import com.oracle.graal.python.builtins.objects.object.PythonObject; import com.oracle.graal.python.nodes.HiddenAttrFactory.ReadNodeGen; import com.oracle.graal.python.nodes.HiddenAttrFactory.WriteNodeGen; +import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Cached.Shared; import com.oracle.truffle.api.dsl.GenerateCached; import com.oracle.truffle.api.dsl.GenerateInline; @@ -60,9 +61,8 @@ import com.oracle.truffle.api.dsl.ImportStatic; import com.oracle.truffle.api.dsl.NeverDefault; import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.library.CachedLibrary; import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.object.DynamicObjectLibrary; +import com.oracle.truffle.api.object.DynamicObject; import com.oracle.truffle.api.object.HiddenKey; public final class HiddenAttr { @@ -135,8 +135,8 @@ public static Object executeUncached(PythonAbstractObject self, HiddenAttr attr, @Specialization static Object doGeneric(PythonAbstractObject self, HiddenAttr attr, Object defaultValue, - @CachedLibrary(limit = "3") DynamicObjectLibrary dylib) { - return dylib.getOrDefault(self, attr.key, defaultValue); + @Cached DynamicObject.GetNode getNode) { + return getNode.execute(self, attr.key, defaultValue); } @NeverDefault @@ -167,15 +167,17 @@ public static void executeUncached(PythonAbstractObject self, HiddenAttr attr, O @Specialization(guards = "attr == DICT") static void doPythonObjectDict(PythonObject self, HiddenAttr attr, Object value, - @Shared @CachedLibrary(limit = "3") DynamicObjectLibrary dylib) { - dylib.setShapeFlags(self, dylib.getShapeFlags(self) | HAS_MATERIALIZED_DICT); - dylib.put(self, DICT.key, value); + @Cached DynamicObject.GetShapeFlagsNode getShapeFlagsNode, + @Cached DynamicObject.SetShapeFlagsNode setShapeFlagsNode, + @Shared @Cached DynamicObject.PutNode putNode) { + self.addShapeFlag(HAS_MATERIALIZED_DICT, getShapeFlagsNode, setShapeFlagsNode); + putNode.execute(self, DICT.key, value); } @Specialization(guards = "attr != DICT || !isPythonObject(self)") static void doGeneric(PythonAbstractObject self, HiddenAttr attr, Object value, - @Shared @CachedLibrary(limit = "3") DynamicObjectLibrary dylib) { - dylib.put(self, attr.key, value); + @Shared @Cached DynamicObject.PutNode putNode) { + putNode.execute(self, attr.key, value); } protected static boolean isPythonObject(Object object) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/ReadAttributeFromPythonObjectNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/ReadAttributeFromPythonObjectNode.java index 3181604833..c3814700a6 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/ReadAttributeFromPythonObjectNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/ReadAttributeFromPythonObjectNode.java @@ -45,7 +45,6 @@ import com.oracle.graal.python.builtins.objects.object.PythonObject; import com.oracle.graal.python.builtins.objects.type.PythonManagedClass; import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.truffle.api.Assumption; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.GenerateInline; import com.oracle.truffle.api.dsl.GenerateUncached; @@ -53,9 +52,7 @@ import com.oracle.truffle.api.dsl.NeverDefault; import com.oracle.truffle.api.dsl.NonIdempotent; import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.library.CachedLibrary; import com.oracle.truffle.api.object.DynamicObject; -import com.oracle.truffle.api.object.DynamicObjectLibrary; import com.oracle.truffle.api.object.Location; import com.oracle.truffle.api.object.Property; import com.oracle.truffle.api.object.Shape; @@ -92,7 +89,7 @@ public final Object execute(PythonObject object, TruffleString key) { public abstract Object execute(DynamicObject object, TruffleString key, Object defaultValue); protected static Object getAttribute(DynamicObject object, TruffleString key, Object defaultValue) { - return DynamicObjectLibrary.getUncached().getOrDefault(object, key, defaultValue); + return DynamicObject.GetNode.getUncached().execute(object, key, defaultValue); } @Idempotent @@ -131,7 +128,6 @@ protected static Object readFinalAttr(DynamicObject dynamicObject, TruffleString @Cached(value = "dynamicObject", weak = true) DynamicObject cachedObject, @Cached("dynamicObject.getShape()") Shape cachedShape, @Cached("getLocationOrNull(cachedShape.getProperty(cachedKey))") Location loc, - @Cached("dynamicObject.getShape().getPropertyAssumption(key)") Assumption propertyAssumption, @Cached(value = "getAttribute(dynamicObject, key, defaultValue)", weak = true) Object value) { return value; } @@ -153,14 +149,13 @@ protected static Object readFinalPrimitiveAttr(DynamicObject dynamicObject, Truf @Cached(value = "dynamicObject", weak = true) DynamicObject cachedObject, @Cached("dynamicObject.getShape()") Shape cachedShape, @Cached("getLocationOrNull(cachedShape.getProperty(cachedKey))") Location loc, - @Cached("dynamicObject.getShape().getPropertyAssumption(key)") Assumption propertyAssumption, @Cached(value = "getAttribute(dynamicObject, key, defaultValue)") Object value) { return value; } - @Specialization(limit = "getAttributeAccessInlineCacheMaxDepth()", replaces = {"readFinalAttr", "readFinalPrimitiveAttr"}) + @Specialization(replaces = {"readFinalAttr", "readFinalPrimitiveAttr"}) protected static Object readDirect(DynamicObject dynamicObject, TruffleString key, Object defaultValue, - @CachedLibrary("dynamicObject") DynamicObjectLibrary dylib) { - return dylib.getOrDefault(dynamicObject, key, defaultValue); + @Cached DynamicObject.GetNode getNode) { + return getNode.execute(dynamicObject, key, defaultValue); } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/WriteAttributeToObjectNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/WriteAttributeToObjectNode.java index e225ad0792..437568d469 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/WriteAttributeToObjectNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/WriteAttributeToObjectNode.java @@ -74,9 +74,8 @@ import com.oracle.truffle.api.dsl.GenerateInline; import com.oracle.truffle.api.dsl.GenerateUncached; import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.library.CachedLibrary; import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.object.DynamicObjectLibrary; +import com.oracle.truffle.api.object.DynamicObject; import com.oracle.truffle.api.profiles.InlinedBranchProfile; import com.oracle.truffle.api.profiles.InlinedConditionProfile; import com.oracle.truffle.api.strings.TruffleString; @@ -100,9 +99,7 @@ static boolean writeToDynamicStorageNoTypeGuard(Object obj, GetDictIfExistsNode } // Specialization for cases that have no special handling and can just delegate to - // WriteAttributeToDynamicObjectNode. Note that the fast-path for String keys and the inline - // cache in WriteAttributeToDynamicObjectNode perform better in some configurations than if we - // cast the key here and used DynamicObjectLibrary directly + // WriteAttributeToPythonObjectNode. @Specialization(guards = {"isAttrWritable(object)", "writeToDynamicStorageNoTypeGuard(object, getDict)"}) static boolean writeToDynamicStorageNoType(PythonObject object, TruffleString key, Object value, @SuppressWarnings("unused") @Shared("getDict") @Cached GetDictIfExistsNode getDict, @@ -118,13 +115,13 @@ boolean writeToDynamicStorageBuiltinType(PythonBuiltinClass klass, TruffleString @Bind Node inliningTarget, @SuppressWarnings("unused") @Shared("getDict") @Cached GetDictIfExistsNode getDict, @Shared("callAttrUpdate") @Cached InlinedBranchProfile callAttrUpdate, - @Shared("dylib") @CachedLibrary(limit = "getAttributeAccessInlineCacheMaxDepth()") DynamicObjectLibrary dylib, + @Shared @Cached DynamicObject.PutNode putNode, @Shared("cpLen") @Cached TruffleString.CodePointLengthNode codePointLengthNode, @Shared("cpAtIndex") @Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode) { if (PythonContext.get(this).isInitialized()) { throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_R_OF_IMMUTABLE_TYPE_N, key, klass); } else { - return writeToDynamicStorageManagedClass(klass, key, value, inliningTarget, callAttrUpdate, dylib, codePointLengthNode, codePointAtIndexNode); + return writeToDynamicStorageManagedClass(klass, key, value, inliningTarget, callAttrUpdate, putNode, codePointLengthNode, codePointAtIndexNode); } } @@ -134,21 +131,24 @@ static boolean writeToDynamicStoragePythonClass(PythonClass klass, TruffleString @SuppressWarnings("unused") @Shared("getDict") @Cached GetDictIfExistsNode getDict, @Exclusive @Cached InlinedBranchProfile callAttrUpdate, @Exclusive @Cached InlinedBranchProfile updateFlags, - @Shared("dylib") @CachedLibrary(limit = "getAttributeAccessInlineCacheMaxDepth()") DynamicObjectLibrary dylib, + @Shared @Cached DynamicObject.PutNode putNode, + @Cached DynamicObject.GetShapeFlagsNode getShapeFlagsNode, + @Cached DynamicObject.SetShapeFlagsNode setShapeFlagsNode, @Shared("cpLen") @Cached TruffleString.CodePointLengthNode codePointLengthNode, @Shared("cpAtIndex") @Cached TruffleString.CodePointAtIndexNode codePointAtIndexNode) { if (value == PNone.NO_VALUE) { updateFlags.enter(inliningTarget); - dylib.setShapeFlags(klass, dylib.getShapeFlags(klass) | HAS_NO_VALUE_PROPERTIES); + klass.addShapeFlag(HAS_NO_VALUE_PROPERTIES, getShapeFlagsNode, setShapeFlagsNode); } - return writeToDynamicStorageManagedClass(klass, key, value, inliningTarget, callAttrUpdate, dylib, codePointLengthNode, codePointAtIndexNode); + return writeToDynamicStorageManagedClass(klass, key, value, inliningTarget, callAttrUpdate, putNode, codePointLengthNode, codePointAtIndexNode); } private static boolean writeToDynamicStorageManagedClass(PythonManagedClass klass, TruffleString key, Object value, Node inliningTarget, - InlinedBranchProfile callAttrUpdate, DynamicObjectLibrary dylib, TruffleString.CodePointLengthNode codePointLengthNode, TruffleString.CodePointAtIndexNode codePointAtIndexNode) { + InlinedBranchProfile callAttrUpdate, DynamicObject.PutNode putNode, TruffleString.CodePointLengthNode codePointLengthNode, + TruffleString.CodePointAtIndexNode codePointAtIndexNode) { CompilerAsserts.partialEvaluationConstant(klass.getClass()); try { - dylib.put(klass, key, value); + putNode.execute(klass, key, value); return true; } finally { if (!klass.canSkipOnAttributeUpdate(key, value, codePointLengthNode, codePointAtIndexNode)) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/WriteAttributeToPythonObjectNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/WriteAttributeToPythonObjectNode.java index 36873d39dc..1982b5896c 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/WriteAttributeToPythonObjectNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/WriteAttributeToPythonObjectNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -43,20 +43,19 @@ import com.oracle.graal.python.builtins.objects.object.PythonObject; import com.oracle.graal.python.nodes.PNodeWithContext; import com.oracle.graal.python.runtime.PythonOptions; +import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.GenerateInline; import com.oracle.truffle.api.dsl.GenerateUncached; import com.oracle.truffle.api.dsl.ImportStatic; import com.oracle.truffle.api.dsl.NeverDefault; import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.library.CachedLibrary; import com.oracle.truffle.api.object.DynamicObject; -import com.oracle.truffle.api.object.DynamicObjectLibrary; import com.oracle.truffle.api.strings.TruffleString; /** * Writes attribute directly to the underlying {@link DynamicObject} regardless of whether the * object has dict, also bypasses any other additional logic in {@link WriteAttributeToObjectNode}. - * This node does not provide any functionality on top of {@link DynamicObjectLibrary}, its purpose + * This node does not provide any functionality on top of {@link DynamicObject.PutNode}, its purpose * is to provide an abstraction in preparation for the transition from {@link DynamicObject} to * {@link com.oracle.graal.python.builtins.objects.common.ObjectHashMap}. */ @@ -80,9 +79,9 @@ public static WriteAttributeToPythonObjectNode getUncached() { return WriteAttributeToPythonObjectNodeGen.getUncached(); } - @Specialization(limit = "getAttributeAccessInlineCacheMaxDepth()") + @Specialization static void write(PythonObject dynamicObject, TruffleString key, Object value, - @CachedLibrary("dynamicObject") DynamicObjectLibrary dylib) { - dylib.put(dynamicObject, key, value); + @Cached DynamicObject.PutNode putNode) { + putNode.execute(dynamicObject, key, value); } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java index fda7cbd365..8260302ac6 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java @@ -282,12 +282,11 @@ import com.oracle.truffle.api.frame.FrameDescriptor; import com.oracle.truffle.api.frame.MaterializedFrame; import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.library.CachedLibrary; import com.oracle.truffle.api.nodes.EncapsulatingNodeReference; import com.oracle.truffle.api.nodes.ExplodeLoop; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.UnexpectedResultException; -import com.oracle.truffle.api.object.DynamicObjectLibrary; +import com.oracle.truffle.api.object.DynamicObject; import com.oracle.truffle.api.profiles.InlinedBranchProfile; import com.oracle.truffle.api.profiles.InlinedConditionProfile; import com.oracle.truffle.api.source.Source; @@ -1363,8 +1362,8 @@ public static Object functionSingleContext(VirtualFrame frame, @Bind PBytecodeDSLRootNode rootNode, @Cached(value = "createFunctionRootNode(rootNode, codeUnit)", adopt = false) PBytecodeDSLRootNode functionRootNode, @Cached("createCode(rootNode, codeUnit, functionRootNode)") PCode cachedCode, - @Shared @CachedLibrary(limit = "1") DynamicObjectLibrary dylib) { - return createFunction(frame, name, qualifiedName, codeUnit.getDocstring(), cachedCode, defaults, kwDefaultsObject, closure, annotations, rootNode, dylib); + @Shared @Cached DynamicObject.PutNode putNode) { + return createFunction(frame, name, qualifiedName, codeUnit.getDocstring(), cachedCode, defaults, kwDefaultsObject, closure, annotations, rootNode, putNode); } @Specialization(replaces = "functionSingleContext", guards = "!codeUnit.isGeneratorOrCoroutine()") @@ -1378,9 +1377,9 @@ public static Object functionMultiContext(VirtualFrame frame, Object annotations, @Bind PBytecodeDSLRootNode rootNode, @Cached(value = "createFunctionRootNode(rootNode, codeUnit)", adopt = false) PBytecodeDSLRootNode functionRootNode, - @Shared @CachedLibrary(limit = "1") DynamicObjectLibrary dylib) { + @Shared @Cached DynamicObject.PutNode putNode) { PCode code = createCode(rootNode, codeUnit, functionRootNode); - return createFunction(frame, name, qualifiedName, codeUnit.getDocstring(), code, defaults, kwDefaultsObject, closure, annotations, rootNode, dylib); + return createFunction(frame, name, qualifiedName, codeUnit.getDocstring(), code, defaults, kwDefaultsObject, closure, annotations, rootNode, putNode); } @Specialization(guards = {"isSingleContext(rootNode)", "codeUnit.isGeneratorOrCoroutine()"}) @@ -1395,8 +1394,8 @@ public static Object generatorOrCoroutineSingleContext(VirtualFrame frame, @Bind PBytecodeDSLRootNode rootNode, @Cached(value = "createFunctionRootNode(rootNode, codeUnit)", adopt = false) PBytecodeDSLRootNode functionRootNode, @Cached("createCode(rootNode, codeUnit, functionRootNode)") PCode cachedCode, - @Shared @CachedLibrary(limit = "1") DynamicObjectLibrary dylib) { - return createFunction(frame, name, qualifiedName, codeUnit.getDocstring(), cachedCode, defaults, kwDefaultsObject, closure, annotations, rootNode, dylib); + @Shared @Cached DynamicObject.PutNode putNode) { + return createFunction(frame, name, qualifiedName, codeUnit.getDocstring(), cachedCode, defaults, kwDefaultsObject, closure, annotations, rootNode, putNode); } @Specialization(replaces = "generatorOrCoroutineSingleContext", guards = "codeUnit.isGeneratorOrCoroutine()") @@ -1410,9 +1409,9 @@ public static Object generatorOrCoroutineMultiContext(VirtualFrame frame, Object annotations, @Bind PBytecodeDSLRootNode rootNode, @Cached(value = "createFunctionRootNode(rootNode, codeUnit)", adopt = false) PBytecodeDSLRootNode functionRootNode, - @Shared @CachedLibrary(limit = "1") DynamicObjectLibrary dylib) { + @Shared @Cached DynamicObject.PutNode putNode) { PCode code = createCode(rootNode, codeUnit, functionRootNode); - return createFunction(frame, name, qualifiedName, codeUnit.getDocstring(), code, defaults, kwDefaultsObject, closure, annotations, rootNode, dylib); + return createFunction(frame, name, qualifiedName, codeUnit.getDocstring(), code, defaults, kwDefaultsObject, closure, annotations, rootNode, putNode); } @Idempotent @@ -1439,7 +1438,7 @@ protected static PFunction createFunction(VirtualFrame frame, PCode code, Object[] defaults, Object[] kwDefaultsObject, Object closure, Object annotations, PBytecodeDSLRootNode node, - DynamicObjectLibrary dylib) { + DynamicObject.PutNode putNode) { PKeyword[] kwDefaults = new PKeyword[kwDefaultsObject.length]; // Note: kwDefaultsObject should be a result of operation MakeKeywords, which produces // PKeyword[] @@ -1447,10 +1446,10 @@ protected static PFunction createFunction(VirtualFrame frame, PFunction function = PFactory.createFunction(PythonLanguage.get(node), name, qualifiedName, code, PArguments.getGlobals(frame), defaults, kwDefaults, (PCell[]) closure); if (annotations != null) { - dylib.put(function, T___ANNOTATIONS__, annotations); + putNode.execute(function, T___ANNOTATIONS__, annotations); } if (doc != null) { - dylib.put(function, T___DOC__, doc); + putNode.execute(function, T___DOC__, doc); } return function; diff --git a/mx.graalpython/suite.py b/mx.graalpython/suite.py index 7cae6ba25b..9767f05826 100644 --- a/mx.graalpython/suite.py +++ b/mx.graalpython/suite.py @@ -53,7 +53,7 @@ }, { "name": "tools", - "version": "50d52936fef1a2737caee257b456c246f4cba242", + "version": "da130d21d8b8d151a23db7f8d2607536f1b69423", "subdir": True, "urls": [ {"url": "https://github.com/oracle/graal", "kind": "git"}, @@ -61,7 +61,7 @@ }, { "name": "regex", - "version": "50d52936fef1a2737caee257b456c246f4cba242", + "version": "da130d21d8b8d151a23db7f8d2607536f1b69423", "subdir": True, "urls": [ {"url": "https://github.com/oracle/graal", "kind": "git"},