Skip to content

Commit 4209739

Browse files
author
Stefan Anzinger
committed
[GR-25036] [GR-21296] Migrate to DynamicObjectLibrary
PullRequest: graalpython/1131
2 parents 7388d1b + ccca3e7 commit 4209739

File tree

102 files changed

+679
-980
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+679
-980
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "b74ff16e12b2f48cf1f9793b0cd73b60b340562e" }
1+
{ "overlay": "8379af29266754c95a650478d1fbdb19ebaa978e" }

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import com.oracle.truffle.api.library.CachedLibrary;
5151
import com.oracle.truffle.api.library.ExportLibrary;
5252
import com.oracle.truffle.api.library.ExportMessage;
53-
import com.oracle.truffle.api.object.DynamicObject;
5453
import com.oracle.truffle.api.object.Shape;
5554

5655
@ExportLibrary(InteropLibrary.class)
@@ -274,11 +273,6 @@ public final Shape getInstanceShape() {
274273
return instanceShape;
275274
}
276275

277-
public final DynamicObject newInstance() {
278-
CompilerAsserts.partialEvaluationConstant(instanceShape);
279-
return instanceShape.newInstance();
280-
}
281-
282276
public static final PythonBuiltinClassType[] VALUES = Arrays.copyOf(values(), values().length - 1);
283277
public static final PythonBuiltinClassType[] EXCEPTIONS;
284278

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
import com.oracle.truffle.api.dsl.NodeFactory;
6464
import com.oracle.truffle.api.dsl.Specialization;
6565
import com.oracle.truffle.api.instrumentation.SourceSectionFilter;
66-
import com.oracle.truffle.api.object.DynamicObject;
66+
import com.oracle.truffle.api.object.Shape;
6767
import com.oracle.truffle.api.source.SourceSection;
6868
import com.oracle.truffle.tools.profiler.CPUSampler;
6969
import com.oracle.truffle.tools.profiler.CPUSampler.Payload;
@@ -93,7 +93,7 @@ Profiler doit(Object cls, @SuppressWarnings("unused") Object[] args, @SuppressWa
9393
if (instrumentInfo != null) {
9494
CPUSampler sampler = env.lookup(instrumentInfo, CPUSampler.class);
9595
if (sampler != null) {
96-
return factory().trace(new Profiler(cls, factory().makeStorage(cls), sampler));
96+
return factory().trace(new Profiler(cls, factory().getShape(cls), sampler));
9797
}
9898
}
9999
throw raise(PythonBuiltinClassType.NotImplementedError, "coverage tracker not available");
@@ -109,8 +109,8 @@ class Profiler extends PythonBuiltinObject {
109109
double time;
110110
final CPUSampler sampler;
111111

112-
public Profiler(Object cls, DynamicObject storage, CPUSampler sampler) {
113-
super(cls, storage);
112+
public Profiler(Object cls, Shape instanceShape, CPUSampler sampler) {
113+
super(cls, instanceShape);
114114
this.sampler = sampler;
115115
this.sampler.setFilter(SourceSectionFilter.newBuilder().includeInternal(true).build());
116116
this.sampler.setMode(CPUSampler.Mode.ROOTS);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,7 @@ public abstract static class PExternalFunctionWrapper extends PythonBuiltinObjec
15971597
private final Supplier<ConvertArgsToSulongNode> convertArgsNodeSupplier;
15981598

15991599
public PExternalFunctionWrapper(Supplier<ConvertArgsToSulongNode> convertArgsNodeSupplier) {
1600-
super(PythonBuiltinClassType.PythonObject, PythonBuiltinClassType.PythonObject.newInstance());
1600+
super(PythonBuiltinClassType.PythonObject, PythonBuiltinClassType.PythonObject.getInstanceShape());
16011601
this.convertArgsNodeSupplier = convertArgsNodeSupplier;
16021602
}
16031603

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
import com.oracle.graal.python.runtime.PythonOptions;
139139
import com.oracle.graal.python.runtime.exception.PException;
140140
import com.oracle.graal.python.util.OverflowException;
141+
import com.oracle.truffle.api.Assumption;
141142
import com.oracle.truffle.api.CompilerDirectives;
142143
import com.oracle.truffle.api.TruffleLanguage;
143144
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -162,17 +163,33 @@
162163
import com.oracle.truffle.api.library.ExportMessage.Ignore;
163164
import com.oracle.truffle.api.nodes.ExplodeLoop;
164165
import com.oracle.truffle.api.nodes.Node;
166+
import com.oracle.truffle.api.object.DynamicObject;
167+
import com.oracle.truffle.api.object.Shape;
165168
import com.oracle.truffle.api.profiles.BranchProfile;
166169
import com.oracle.truffle.api.profiles.ConditionProfile;
167170
import com.oracle.truffle.api.utilities.TriState;
168171

169172
@ImportStatic(SpecialMethodNames.class)
170173
@ExportLibrary(InteropLibrary.class)
171174
@ExportLibrary(PythonObjectLibrary.class)
172-
public abstract class PythonAbstractObject implements TruffleObject, Comparable<Object> {
175+
public abstract class PythonAbstractObject extends DynamicObject implements TruffleObject, Comparable<Object> {
173176
private static final String PRIVATE_PREFIX = "__";
174177
private DynamicObjectNativeWrapper nativeWrapper;
175178

179+
public static final Assumption singleContextAssumption() {
180+
return PythonLanguage.getCurrent().singleContextAssumption;
181+
}
182+
183+
protected static final Shape ABSTRACT_SHAPE = Shape.newBuilder().build();
184+
185+
protected PythonAbstractObject(Shape shape) {
186+
super(shape);
187+
}
188+
189+
protected PythonAbstractObject() {
190+
super(ABSTRACT_SHAPE);
191+
}
192+
176193
public final DynamicObjectNativeWrapper getNativeWrapper() {
177194
return nativeWrapper;
178195
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/PArray.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@
3232
import com.oracle.truffle.api.dsl.Cached;
3333
import com.oracle.truffle.api.library.ExportLibrary;
3434
import com.oracle.truffle.api.library.ExportMessage;
35-
import com.oracle.truffle.api.object.DynamicObject;
35+
import com.oracle.truffle.api.object.Shape;
3636

3737
@ExportLibrary(PythonObjectLibrary.class)
3838
public class PArray extends PMutableSequence {
3939

4040
private SequenceStorage store;
4141

42-
public PArray(Object clazz, DynamicObject storage) {
43-
super(clazz, storage);
42+
public PArray(Object clazz, Shape instanceShape) {
43+
super(clazz, instanceShape);
4444
}
4545

46-
public PArray(Object clazz, DynamicObject storage, SequenceStorage store) {
47-
super(clazz, storage);
46+
public PArray(Object clazz, Shape instanceShape, SequenceStorage store) {
47+
super(clazz, instanceShape);
4848
this.store = store;
4949
}
5050

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/PByteArray.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@
3939
import com.oracle.truffle.api.library.ExportLibrary;
4040
import com.oracle.truffle.api.library.ExportMessage;
4141
import com.oracle.truffle.api.library.ExportMessage.Ignore;
42-
import com.oracle.truffle.api.object.DynamicObject;
42+
import com.oracle.truffle.api.object.Shape;
4343

4444
@ExportLibrary(PythonObjectLibrary.class)
4545
public final class PByteArray extends PMutableSequence implements PIBytesLike {
4646

4747
private SequenceStorage store;
4848

49-
public PByteArray(Object cls, DynamicObject storage, byte[] bytes) {
50-
super(cls, storage);
49+
public PByteArray(Object cls, Shape instanceShape, byte[] bytes) {
50+
super(cls, instanceShape);
5151
store = new ByteSequenceStorage(bytes);
5252
}
5353

54-
public PByteArray(Object cls, DynamicObject storage, SequenceStorage store) {
55-
super(cls, storage);
54+
public PByteArray(Object cls, Shape instanceShape, SequenceStorage store) {
55+
super(cls, instanceShape);
5656
this.store = store;
5757
}
5858

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/PBytes.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,20 @@
4646
import com.oracle.truffle.api.library.ExportLibrary;
4747
import com.oracle.truffle.api.library.ExportMessage;
4848
import com.oracle.truffle.api.library.ExportMessage.Ignore;
49-
import com.oracle.truffle.api.object.DynamicObject;
49+
import com.oracle.truffle.api.object.Shape;
5050

5151
@ExportLibrary(PythonObjectLibrary.class)
5252
public final class PBytes extends PImmutableSequence implements PIBytesLike {
5353

5454
private SequenceStorage store;
5555

56-
public PBytes(Object cls, DynamicObject storage, byte[] bytes) {
57-
super(cls, storage);
56+
public PBytes(Object cls, Shape instanceShape, byte[] bytes) {
57+
super(cls, instanceShape);
5858
store = new ByteSequenceStorage(bytes);
5959
}
6060

61-
public PBytes(Object cls, DynamicObject storage, SequenceStorage store) {
62-
super(cls, storage);
61+
public PBytes(Object cls, Shape instanceShape, SequenceStorage store) {
62+
super(cls, instanceShape);
6363
setSequenceStorage(store);
6464
}
6565

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,6 @@
165165
import com.oracle.truffle.api.library.ExportLibrary;
166166
import com.oracle.truffle.api.library.ExportMessage;
167167
import com.oracle.truffle.api.nodes.Node;
168-
import com.oracle.truffle.api.object.Layout;
169-
import com.oracle.truffle.api.object.ObjectType;
170-
import com.oracle.truffle.api.object.Shape;
171168
import com.oracle.truffle.api.profiles.BranchProfile;
172169
import com.oracle.truffle.api.profiles.ConditionProfile;
173170
import com.oracle.truffle.api.profiles.ValueProfile;
@@ -178,9 +175,6 @@
178175
@ExportLibrary(NativeTypeLibrary.class)
179176
public abstract class DynamicObjectNativeWrapper extends PythonNativeWrapper {
180177
static final String GP_OBJECT = "gp_object";
181-
private static final Layout OBJECT_LAYOUT = Layout.newLayout().build();
182-
private static final Shape SHAPE = OBJECT_LAYOUT.createShape(new ObjectType());
183-
184178
private DynamicObjectStorage nativeMemberStore;
185179

186180
public DynamicObjectNativeWrapper() {
@@ -192,7 +186,7 @@ public DynamicObjectNativeWrapper(Object delegate) {
192186

193187
public DynamicObjectStorage createNativeMemberStore() {
194188
if (nativeMemberStore == null) {
195-
nativeMemberStore = new DynamicObjectStorage(SHAPE.newInstance());
189+
nativeMemberStore = new DynamicObjectStorage();
196190
}
197191
return nativeMemberStore;
198192
}

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import static com.oracle.graal.python.builtins.objects.cext.NativeCAPISymbols.FUN_GET_OB_TYPE;
4444
import static com.oracle.graal.python.builtins.objects.cext.NativeCAPISymbols.FUN_PY_OBJECT_GENERIC_GET_DICT;
4545

46-
import java.lang.ref.WeakReference;
4746
import java.util.Objects;
4847

4948
import com.oracle.graal.python.PythonLanguage;
@@ -227,9 +226,9 @@ public static Assumption getSingleContextAssumption() {
227226
return PythonLanguage.getCurrent().singleContextAssumption;
228227
}
229228

230-
@Specialization(guards = "object == cachedObject.get()", limit = "1", assumptions = "getSingleContextAssumption()")
229+
@Specialization(guards = "object == cachedObject", limit = "1", assumptions = "getSingleContextAssumption()")
231230
static Object getNativeClassCachedIdentity(PythonAbstractNativeObject object,
232-
@Exclusive @Cached("weak(object)") WeakReference<PythonAbstractNativeObject> cachedObject,
231+
@Exclusive @Cached(value = "object", weak = true) PythonAbstractNativeObject cachedObject,
233232
@Exclusive @Cached("getNativeClassUncached(object)") Object cachedClass) {
234233
// TODO: (tfel) is this really something we can do? It's so rare for this class to
235234
// change that it shouldn't be worth the effort, but in native code, anything can
@@ -240,7 +239,7 @@ static Object getNativeClassCachedIdentity(PythonAbstractNativeObject object,
240239

241240
@Specialization(guards = "isSame(lib, cachedObject, object)", assumptions = "getSingleContextAssumption()")
242241
static Object getNativeClassCached(PythonAbstractNativeObject object,
243-
@Exclusive @Cached("weak(object)") WeakReference<PythonAbstractNativeObject> cachedObject,
242+
@Exclusive @Cached(value = "object", weak = true) PythonAbstractNativeObject cachedObject,
244243
@Exclusive @Cached("getNativeClassUncached(object)") Object cachedClass,
245244
@CachedLibrary(limit = "3") @SuppressWarnings("unused") InteropLibrary lib) {
246245
// TODO same as for 'getNativeClassCachedIdentity'
@@ -267,16 +266,8 @@ static Object getNativeClass(PythonAbstractNativeObject object,
267266
return classProfile.profile(toJavaNode.execute(callGetObTypeNode.call(FUN_GET_OB_TYPE, object.getPtr())));
268267
}
269268

270-
static WeakReference<PythonAbstractNativeObject> weak(PythonAbstractNativeObject object) {
271-
return new WeakReference<>(object);
272-
}
273-
274-
static boolean isSame(InteropLibrary lib, WeakReference<PythonAbstractNativeObject> cachedObjectRef, PythonAbstractNativeObject object) {
275-
PythonAbstractNativeObject cachedObject = cachedObjectRef.get();
276-
if (cachedObject != null) {
277-
return lib.isIdentical(cachedObject.object, object.object, lib);
278-
}
279-
return false;
269+
static boolean isSame(InteropLibrary lib, PythonAbstractNativeObject cachedObject, PythonAbstractNativeObject object) {
270+
return lib.isIdentical(cachedObject.object, object.object, lib);
280271
}
281272

282273
public static Object getNativeClassUncached(PythonAbstractNativeObject object) {

0 commit comments

Comments
 (0)