Skip to content

Commit 0e34d95

Browse files
committed
[GR-36894] Update import and migrate GraalPy to DynamicObject nodes.
PullRequest: graalpython/4122
2 parents 2a2ef65 + 9c66ad8 commit 0e34d95

24 files changed

+211
-212
lines changed

ci/graal/common.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Jsonnet files should not include this file directly but use ci/common.jsonnet instead."
55
],
66

7-
"mx_version": "7.67.0",
7+
"mx_version": "7.68.2",
88

99
"COMMENT.jdks": "When adding or removing JDKs keep in sync with JDKs in ci/common.jsonnet",
1010
"jdks": {
@@ -49,12 +49,12 @@
4949
"graalvm-ee-25-ea": {"name": "graalvm-jdk", "version": "25.0.0", "ea": "36", "platformspecific": true },
5050

5151
"oraclejdk-latest": {"name": "jpg-jdk", "version": "25", "build_id": "jdk-25.0.1+8", "platformspecific": true, "extrabundles": ["static-libs"]},
52-
"labsjdk-ce-latest": {"name": "labsjdk", "version": "ce-25.0.1+8-jvmci-25.1-b08", "platformspecific": true },
53-
"labsjdk-ce-latestDebug": {"name": "labsjdk", "version": "ce-25.0.1+8-jvmci-25.1-b08-debug", "platformspecific": true },
54-
"labsjdk-ce-latest-llvm": {"name": "labsjdk", "version": "ce-25.0.1+8-jvmci-25.1-b08-sulong", "platformspecific": true },
55-
"labsjdk-ee-latest": {"name": "labsjdk", "version": "ee-25.0.1+8-jvmci-25.1-b08", "platformspecific": true },
56-
"labsjdk-ee-latestDebug": {"name": "labsjdk", "version": "ee-25.0.1+8-jvmci-25.1-b08-debug", "platformspecific": true },
57-
"labsjdk-ee-latest-llvm": {"name": "labsjdk", "version": "ee-25.0.1+8-jvmci-25.1-b08-sulong", "platformspecific": true }
52+
"labsjdk-ce-latest": {"name": "labsjdk", "version": "ce-25.0.1+8-jvmci-25.1-b10", "platformspecific": true },
53+
"labsjdk-ce-latestDebug": {"name": "labsjdk", "version": "ce-25.0.1+8-jvmci-25.1-b10-debug", "platformspecific": true },
54+
"labsjdk-ce-latest-llvm": {"name": "labsjdk", "version": "ce-25.0.1+8-jvmci-25.1-b10-sulong", "platformspecific": true },
55+
"labsjdk-ee-latest": {"name": "labsjdk", "version": "ee-25.0.1+8-jvmci-25.1-b10", "platformspecific": true },
56+
"labsjdk-ee-latestDebug": {"name": "labsjdk", "version": "ee-25.0.1+8-jvmci-25.1-b10-debug", "platformspecific": true },
57+
"labsjdk-ee-latest-llvm": {"name": "labsjdk", "version": "ee-25.0.1+8-jvmci-25.1-b10-sulong", "platformspecific": true }
5858
},
5959

6060
"eclipse": {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ protected Object getLanguageView(PythonContext context, Object value) {
837837
}
838838

839839
@ExportLibrary(value = InteropLibrary.class, delegateTo = "delegate")
840-
static class ForeignLanguageView implements TruffleObject {
840+
static final class ForeignLanguageView implements TruffleObject {
841841
final Object delegate;
842842

843843
ForeignLanguageView(Object delegate) {
@@ -853,13 +853,14 @@ String toDisplayString(boolean allowSideEffects,
853853

854854
@ExportMessage
855855
@SuppressWarnings("static-method")
856-
boolean hasLanguage() {
856+
boolean hasLanguageId() {
857857
return true;
858858
}
859859

860860
@ExportMessage
861-
Class<? extends TruffleLanguage<?>> getLanguage() {
862-
return PythonLanguage.class;
861+
@SuppressWarnings("static-method")
862+
String getLanguageId() {
863+
return PythonLanguage.ID;
863864
}
864865
}
865866

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextNamespaceBuiltins.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@
6363
import com.oracle.truffle.api.dsl.Cached;
6464
import com.oracle.truffle.api.dsl.Cached.Shared;
6565
import com.oracle.truffle.api.dsl.Specialization;
66-
import com.oracle.truffle.api.library.CachedLibrary;
6766
import com.oracle.truffle.api.nodes.Node;
68-
import com.oracle.truffle.api.object.DynamicObjectLibrary;
67+
import com.oracle.truffle.api.object.DynamicObject;
6968

7069
public final class PythonCextNamespaceBuiltins {
7170

@@ -78,20 +77,20 @@ static Object impDict(PDict dict,
7877
@Shared("itNext") @Cached HashingStorageIteratorNext itNext,
7978
@Shared("itKey") @Cached HashingStorageIteratorKey itKey,
8079
@Shared("itVal") @Cached HashingStorageIteratorValue itValue,
81-
@Shared("dylib") @CachedLibrary(limit = "1") DynamicObjectLibrary dyLib) {
80+
@Shared @Cached DynamicObject.PutNode putNode) {
8281
HashingStorage storage = dict.getDictStorage();
83-
return impl(inliningTarget, storage, getIterator, itNext, itKey, itValue, dyLib);
82+
return impl(inliningTarget, storage, getIterator, itNext, itKey, itValue, putNode);
8483
}
8584

8685
private static Object impl(Node inliningTarget, HashingStorage storage, HashingStorageGetIterator getIterator, HashingStorageIteratorNext itNext,
8786
HashingStorageIteratorKey itKey, HashingStorageIteratorValue itValue,
88-
DynamicObjectLibrary dyLib) {
87+
DynamicObject.PutNode putNode) {
8988
PSimpleNamespace ns = PFactory.createSimpleNamespace(PythonLanguage.get(inliningTarget));
9089
HashingStorageNodes.HashingStorageIterator it = getIterator.execute(inliningTarget, storage);
9190
while (itNext.execute(inliningTarget, storage, it)) {
9291
Object key = itKey.execute(inliningTarget, storage, it);
9392
Object value = itValue.execute(inliningTarget, storage, it);
94-
dyLib.put(ns, assertNoJavaString(key), value);
93+
putNode.execute(ns, assertNoJavaString(key), value);
9594
}
9695
return ns;
9796
}
@@ -104,9 +103,9 @@ static Object impGeneric(Object dict,
104103
@Shared("itNext") @Cached HashingStorageIteratorNext itNext,
105104
@Shared("itKey") @Cached HashingStorageIteratorKey itKey,
106105
@Shared("itVal") @Cached HashingStorageIteratorValue itValue,
107-
@Shared("dylib") @CachedLibrary(limit = "1") DynamicObjectLibrary dyLib) {
106+
@Shared @Cached DynamicObject.PutNode putNode) {
108107
HashingStorage hs = initNode.execute(null, dict, PKeyword.EMPTY_KEYWORDS);
109-
return impl(inliningTarget, hs, getIterator, itNext, itKey, itValue, dyLib);
108+
return impl(inliningTarget, hs, getIterator, itNext, itKey, itValue, putNode);
110109
}
111110
}
112111

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextStructSeqBuiltins.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
import com.oracle.truffle.api.interop.InteropLibrary;
9191
import com.oracle.truffle.api.library.CachedLibrary;
9292
import com.oracle.truffle.api.nodes.Node;
93-
import com.oracle.truffle.api.object.DynamicObjectLibrary;
93+
import com.oracle.truffle.api.object.DynamicObject;
9494
import com.oracle.truffle.api.strings.TruffleString;
9595

9696
public final class PythonCextStructSeqBuiltins {
@@ -139,16 +139,17 @@ abstract static class GraalPyPrivate_StructSequence_NewType extends CApiQuaterna
139139
Object doGeneric(TruffleString typeName, TruffleString typeDoc, Object fields, int nInSequence,
140140
@Cached GraalPyPrivate_StructSequence_InitType2 initNode,
141141
@Cached ReadAttributeFromModuleNode readTypeBuiltinNode,
142-
@CachedLibrary(limit = "1") DynamicObjectLibrary dylib,
142+
@Cached DynamicObject.GetShapeFlagsNode getShapeFlagsNode,
143+
@Cached DynamicObject.SetShapeFlagsNode setShapeFlagsNode,
143144
@Cached CallNode callTypeNewNode,
144145
@Bind PythonLanguage language) {
145146
Object typeBuiltin = readTypeBuiltinNode.execute(getCore().getBuiltins(), BuiltinNames.T_TYPE);
146147
PTuple bases = PFactory.createTuple(language, new Object[]{PythonBuiltinClassType.PTuple});
147148
PDict namespace = PFactory.createDict(language, new PKeyword[]{new PKeyword(SpecialAttributeNames.T___DOC__, typeDoc)});
148149
Object cls = callTypeNewNode.executeWithoutFrame(typeBuiltin, typeName, bases, namespace);
149150
initNode.execute(cls, fields, nInSequence);
150-
if (cls instanceof PythonClass) {
151-
((PythonClass) cls).makeStaticBase(dylib);
151+
if (cls instanceof PythonClass pythonClass) {
152+
pythonClass.makeStaticBase(getShapeFlagsNode, setShapeFlagsNode);
152153
}
153154
return cls;
154155
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTypeBuiltins.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@
126126
import com.oracle.truffle.api.nodes.Node;
127127
import com.oracle.truffle.api.nodes.RootNode;
128128
import com.oracle.truffle.api.object.DynamicObject;
129-
import com.oracle.truffle.api.object.DynamicObjectLibrary;
130129
import com.oracle.truffle.api.object.Shape;
131130
import com.oracle.truffle.api.strings.TruffleString;
132131
import com.oracle.truffle.api.utilities.CyclicAssumption;
@@ -143,7 +142,8 @@ Object doGeneric(Object type, Object name,
143142
@Cached PythonCextBuiltins.PromoteBorrowedValue promoteBorrowedValue,
144143
@Cached CStructAccess.ReadObjectNode getNativeDict,
145144
@Cached GetDictIfExistsNode getDictIfExistsNode,
146-
@CachedLibrary(limit = "3") DynamicObjectLibrary dylib,
145+
@Cached DynamicObject.GetNode getNode,
146+
@Cached DynamicObject.PutNode putNode,
147147
@Cached PyDictGetItem getItem,
148148
@Cached PyDictSetItem setItem) {
149149
TruffleString key = castToTruffleStringNode.castKnownString(inliningTarget, name);
@@ -165,15 +165,15 @@ Object doGeneric(Object type, Object name,
165165
}
166166
Object value;
167167
if (dict == null) {
168-
value = dylib.getOrDefault((DynamicObject) cls, key, null);
168+
value = getNode.execute((PythonManagedClass) cls, key, null);
169169
} else {
170170
value = getItem.execute(null, inliningTarget, dict, key);
171171
}
172172
if (value != null && value != PNone.NO_VALUE) {
173173
Object promoted = promoteBorrowedValue.execute(inliningTarget, value);
174174
if (promoted != null) {
175175
if (dict == null) {
176-
dylib.put((DynamicObject) cls, key, promoted);
176+
putNode.execute((PythonManagedClass) cls, key, promoted);
177177
} else {
178178
setItem.execute(null, inliningTarget, dict, key, promoted);
179179
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@
158158
import com.oracle.graal.python.util.PythonUtils;
159159
import com.oracle.truffle.api.CompilerDirectives;
160160
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
161-
import com.oracle.truffle.api.TruffleLanguage;
162161
import com.oracle.truffle.api.dsl.Bind;
163162
import com.oracle.truffle.api.dsl.Cached;
164163
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -234,6 +233,18 @@ public void setIndexedSlots(Object[] indexedSlots) {
234233
this.indexedSlots = indexedSlots;
235234
}
236235

236+
@ExportMessage
237+
@SuppressWarnings("static-method")
238+
public final boolean hasLanguageId() {
239+
return true;
240+
}
241+
242+
@ExportMessage
243+
@SuppressWarnings("static-method")
244+
public final String getLanguageId() {
245+
return PythonLanguage.ID;
246+
}
247+
237248
@ExportMessage
238249
public void writeMember(String key, Object value,
239250
@Bind Node inliningTarget,
@@ -1457,16 +1468,6 @@ boolean isArrayElementReadable(long index) {
14571468
}
14581469
}
14591470

1460-
@ExportMessage
1461-
public boolean hasLanguage() {
1462-
return true;
1463-
}
1464-
1465-
@ExportMessage
1466-
public Class<? extends TruffleLanguage<?>> getLanguage() {
1467-
return PythonLanguage.class;
1468-
}
1469-
14701471
@GenerateUncached
14711472
@GenerateInline
14721473
@GenerateCached(false)

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

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,14 @@
6868
import com.oracle.truffle.api.dsl.GenerateInline;
6969
import com.oracle.truffle.api.dsl.GenerateUncached;
7070
import com.oracle.truffle.api.dsl.ImportStatic;
71-
import com.oracle.truffle.api.dsl.NeverDefault;
7271
import com.oracle.truffle.api.dsl.Specialization;
7372
import com.oracle.truffle.api.frame.Frame;
74-
import com.oracle.truffle.api.library.CachedLibrary;
7573
import com.oracle.truffle.api.nodes.ExplodeLoop;
7674
import com.oracle.truffle.api.nodes.ExplodeLoop.LoopExplosionKind;
7775
import com.oracle.truffle.api.nodes.Node;
7876
import com.oracle.truffle.api.object.DynamicObject;
79-
import com.oracle.truffle.api.object.DynamicObjectLibrary;
8077
import com.oracle.truffle.api.object.Shape;
78+
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
8179
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
8280
import com.oracle.truffle.api.strings.TruffleString;
8381

@@ -277,8 +275,8 @@ private static boolean hasNext(Iterator<Object> keys) {
277275
}
278276
}
279277

280-
void setStringKey(TruffleString key, Object value, DynamicObjectLibrary dylib) {
281-
dylib.put(store, key, assertNoJavaString(value));
278+
void setStringKey(TruffleString key, Object value, DynamicObject.PutNode putNode) {
279+
putNode.execute(store, key, assertNoJavaString(value));
282280
}
283281

284282
boolean shouldTransitionOnPut() {
@@ -298,8 +296,8 @@ abstract static class ClearNode extends Node {
298296

299297
@Specialization(guards = "!isPythonObject(receiver.getStore())")
300298
static HashingStorage clearPlain(DynamicObjectStorage receiver,
301-
@CachedLibrary(limit = "3") DynamicObjectLibrary dylib) {
302-
dylib.resetShape(receiver.getStore(), PythonLanguage.get(dylib).getEmptyShape());
299+
@Cached DynamicObject.ResetShapeNode resetShapeNode) {
300+
resetShapeNode.execute(receiver.getStore(), PythonLanguage.get(resetShapeNode).getEmptyShape());
303301
return receiver;
304302
}
305303

@@ -327,39 +325,12 @@ static HashingStorage clearObjectBacked(Node inliningTarget, DynamicObjectStorag
327325
abstract static class Copy extends Node {
328326
abstract DynamicObjectStorage execute(Node node, DynamicObjectStorage receiver);
329327

330-
@NeverDefault
331-
static DynamicObjectLibrary[] createAccess(int length) {
332-
DynamicObjectLibrary[] result = new DynamicObjectLibrary[length];
333-
for (int i = 0; i < length; i++) {
334-
result[i] = DynamicObjectLibrary.getFactory().createDispatched(1);
335-
}
336-
return result;
337-
}
338-
339-
@ExplodeLoop
340-
@Specialization(limit = "1", guards = {"cachedLength < EXPLODE_LOOP_SIZE_LIMIT", "keys.length == cachedLength"})
328+
@Specialization
341329
public static DynamicObjectStorage copy(DynamicObjectStorage receiver,
342-
@SuppressWarnings("unused") @Bind("receiver.store") DynamicObject store,
343-
@SuppressWarnings("unused") @CachedLibrary("store") DynamicObjectLibrary dylib,
344-
@Bind("dylib.getKeyArray(store)") Object[] keys,
345-
@Cached(value = "keys.length") int cachedLength,
346-
@Cached("createAccess(cachedLength)") DynamicObjectLibrary[] readLib,
347-
@Cached("createAccess(cachedLength)") DynamicObjectLibrary[] writeLib) {
348-
DynamicObject copy = new Store(PythonLanguage.get(dylib).getEmptyShape());
349-
for (int i = 0; i < cachedLength; i++) {
350-
writeLib[i].put(copy, keys[i], readLib[i].getOrDefault(receiver.store, keys[i], PNone.NO_VALUE));
351-
}
352-
return new DynamicObjectStorage(copy);
353-
}
354-
355-
@Specialization(replaces = "copy")
356-
public static DynamicObjectStorage copyGeneric(DynamicObjectStorage receiver,
357-
@CachedLibrary(limit = "3") DynamicObjectLibrary dylib) {
358-
DynamicObject copy = new Store(PythonLanguage.get(dylib).getEmptyShape());
359-
Object[] keys = dylib.getKeyArray(receiver.store);
360-
for (Object key : keys) {
361-
dylib.put(copy, key, dylib.getOrDefault(receiver.store, key, PNone.NO_VALUE));
362-
}
330+
@Bind Node inliningTarget,
331+
@Cached DynamicObject.CopyPropertiesNode copyPropertiesNode) {
332+
DynamicObject copy = new Store(PythonLanguage.get(inliningTarget).getEmptyShape());
333+
copyPropertiesNode.execute(receiver.store, copy);
363334
return new DynamicObjectStorage(copy);
364335
}
365336
}
@@ -369,9 +340,10 @@ public static DynamicObjectStorage copyGeneric(DynamicObjectStorage receiver,
369340
@GenerateCached(false)
370341
public abstract static class DynamicObjectStorageSetStringKey extends SpecializedSetStringKey {
371342
@Specialization
372-
static void doIt(HashingStorage self, TruffleString key, Object value,
373-
@CachedLibrary(limit = "3") DynamicObjectLibrary dylib) {
374-
((DynamicObjectStorage) self).setStringKey(key, value, dylib);
343+
static void doIt(Node inliningTarget, HashingStorage self, TruffleString key, Object value,
344+
@Cached DynamicObject.PutNode putNode,
345+
@Cached InlinedBranchProfile invalidateMro) {
346+
((DynamicObjectStorage) self).setStringKey(key, value, putNode);
375347
}
376348
}
377349
}

0 commit comments

Comments
 (0)