Skip to content

Commit f8f5c0d

Browse files
committed
pass current language around to all places that need shapes to avoid runtime invoke
1 parent f4fefe7 commit f8f5c0d

Some content is hidden

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

51 files changed

+294
-260
lines changed

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@
4646
import com.oracle.graal.python.builtins.objects.dict.PDict;
4747
import com.oracle.graal.python.builtins.objects.function.PArguments;
4848
import com.oracle.graal.python.builtins.objects.object.PythonObject;
49+
import com.oracle.graal.python.builtins.objects.type.PythonManagedClass;
4950
import com.oracle.graal.python.nodes.BuiltinNames;
51+
import com.oracle.graal.python.nodes.HiddenAttributes;
5052
import com.oracle.graal.python.nodes.NodeFactory;
5153
import com.oracle.graal.python.nodes.call.InvokeNode;
5254
import com.oracle.graal.python.nodes.control.TopLevelExceptionHandler;
@@ -306,13 +308,14 @@ private RootNode parseWithArguments(ParsingRequest request) {
306308
final String[] argumentNames = request.getArgumentNames().toArray(new String[request.getArgumentNames().size()]);
307309
final Source source = request.getSource();
308310
CompilerDirectives.transferToInterpreter();
309-
final RootNode executableNode = new RootNode(this) {
311+
final PythonLanguage lang = this;
312+
final RootNode executableNode = new RootNode(lang) {
310313
@Node.Child private RootNode rootNode;
311314

312315
protected Object[] preparePArguments(VirtualFrame frame) {
313316
int argumentsLength = frame.getArguments().length;
314317
Object[] arguments = PArguments.create(argumentsLength);
315-
PArguments.setGlobals(arguments, new PDict());
318+
PArguments.setGlobals(arguments, new PDict(lang));
316319
PythonUtils.arraycopy(frame.getArguments(), 0, arguments, PArguments.USER_ARGUMENTS_OFFSET, argumentsLength);
317320
return arguments;
318321
}
@@ -651,17 +654,24 @@ public RootCallTarget getOrComputeBuiltinCallTarget(Builtin builtin, Class<? ext
651654
return builtinCallTargetCache.computeIfAbsent(key, (k) -> supplier.apply(builtin));
652655
}
653656

654-
public static Shape getEmptyShape() {
655-
return getCurrent().emptyShape;
657+
public Shape getEmptyShape() {
658+
return emptyShape;
656659
}
657660

658-
public static Shape getBuiltinTypeInstanceShape(PythonBuiltinClassType type) {
659-
Shape[] builtinTypeInstanceShapes = getCurrent().builtinTypeInstanceShapes;
661+
public Shape getShapeForClass(PythonManagedClass klass) {
662+
if (singleContextAssumption.isValid()) {
663+
return Shape.newBuilder(getEmptyShape()).addConstantProperty(HiddenAttributes.CLASS, klass, 0).build();
664+
} else {
665+
return getEmptyShape();
666+
}
667+
}
668+
669+
public Shape getBuiltinTypeInstanceShape(PythonBuiltinClassType type) {
660670
int ordinal = type.ordinal();
661671
Shape shape = builtinTypeInstanceShapes[ordinal];
662672
if (shape == null) {
663673
CompilerDirectives.transferToInterpreterAndInvalidate();
664-
shape = PythonObject.freshShape(type);
674+
shape = Shape.newBuilder(getEmptyShape()).addConstantProperty(HiddenAttributes.CLASS, type, 0).build();
665675
builtinTypeInstanceShapes[ordinal] = shape;
666676
}
667677
return shape;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,9 +597,9 @@ private PythonBuiltinClass initializeBuiltinClass(PythonBuiltinClassType type) {
597597
if (builtinTypes[index] == null) {
598598
if (type.getBase() == null) {
599599
// object case
600-
builtinTypes[index] = new PythonBuiltinClass(type, null);
600+
builtinTypes[index] = new PythonBuiltinClass(getLanguage(), type, null);
601601
} else {
602-
builtinTypes[index] = new PythonBuiltinClass(type, initializeBuiltinClass(type.getBase()));
602+
builtinTypes[index] = new PythonBuiltinClass(getLanguage(), type, initializeBuiltinClass(type.getBase()));
603603
}
604604
}
605605
return builtinTypes[index];

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,11 @@ public String toString() {
269269
return name;
270270
}
271271

272-
public final Shape getInstanceShape() {
272+
public final Shape getInstanceShape(PythonLanguage lang) {
273273
if (name == null) {
274274
CompilerDirectives.shouldNotReachHere("incorrect use of Python builtin type marker");
275275
}
276-
return PythonLanguage.getBuiltinTypeInstanceShape(this);
276+
return lang.getBuiltinTypeInstanceShape(this);
277277
}
278278

279279
@CompilationFinal(dimensions = 1) public static final PythonBuiltinClassType[] VALUES = Arrays.copyOf(values(), values().length - 1);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,9 @@ abstract static class CharmapBuildNode extends PythonBuiltinNode {
531531
// This is replaced in the core _codecs.py with the full functionality
532532
@Specialization
533533
Object lookup(String chars,
534+
@CachedLanguage PythonLanguage lang,
534535
@CachedLibrary(limit = "3") HashingStorageLibrary lib) {
535-
HashingStorage store = PDict.createNewStorage(false, chars.length());
536+
HashingStorage store = PDict.createNewStorage(lang, false, chars.length());
536537
PDict dict = factory().createDict(store);
537538
int pos = 0;
538539
int num = 0;

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ public static final class MethDirectRoot extends PRootNode {
123123
private final String name;
124124
private final Object callable;
125125

126-
@CompilationFinal private ConditionProfile customLocalsProfile;
127-
128126
private MethDirectRoot(PythonLanguage lang, String name, Object callable) {
129127
super(lang);
130128
this.name = name;
@@ -134,7 +132,7 @@ private MethDirectRoot(PythonLanguage lang, String name, Object callable) {
134132

135133
@Override
136134
public Object execute(VirtualFrame frame) {
137-
CalleeContext.enter(frame, ensureCustomLocalsProfile());
135+
calleeContext.enter(frame);
138136
try {
139137
return ensureInvokeNode().execute(frame, name, callable, PArguments.getVariableArguments(frame), 0);
140138
} finally {
@@ -168,14 +166,6 @@ public boolean isPythonInternal() {
168166
return true;
169167
}
170168

171-
private ConditionProfile ensureCustomLocalsProfile() {
172-
if (customLocalsProfile == null) {
173-
CompilerDirectives.transferToInterpreterAndInvalidate();
174-
customLocalsProfile = ConditionProfile.createBinaryProfile();
175-
}
176-
return customLocalsProfile;
177-
}
178-
179169
private ExternalFunctionInvokeNode ensureInvokeNode() {
180170
if (invokeNode == null) {
181171
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -377,8 +367,6 @@ abstract static class MethodDescriptorRoot extends PRootNode {
377367
@Child private ExternalFunctionInvokeNode externalInvokeNode;
378368
@Child ReadIndexedArgumentNode readSelfNode = ReadIndexedArgumentNode.create(0);
379369

380-
private final ConditionProfile customLocalsProfile = ConditionProfile.createCountingProfile();
381-
382370
private final String name;
383371
private final Object callable;
384372

@@ -400,7 +388,7 @@ abstract static class MethodDescriptorRoot extends PRootNode {
400388

401389
@Override
402390
public Object execute(VirtualFrame frame) {
403-
CalleeContext.enter(frame, customLocalsProfile);
391+
calleeContext.enter(frame);
404392
try {
405393
if (externalInvokeNode != null) {
406394
Object[] cArguments = prepareCArguments(frame);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ private PCode readCode() {
650650

651651
private PDict readDict(int depth, HashingStorageLibrary lib) {
652652
int len = readInt();
653-
HashingStorage store = PDict.createNewStorage(false, len);
653+
HashingStorage store = PDict.createNewStorage(PythonLanguage.getCurrent(), false, len);
654654
PDict dict = factory().createDict(store);
655655
for (int i = 0; i < len; i++) {
656656
Object key = readObject(depth + 1, lib);

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
8787
import com.oracle.graal.python.builtins.objects.complex.PComplex;
8888
import com.oracle.graal.python.builtins.objects.floats.PFloat;
89-
import com.oracle.graal.python.builtins.objects.function.PFunction;
9089
import com.oracle.graal.python.builtins.objects.function.PKeyword;
9190
import com.oracle.graal.python.builtins.objects.function.Signature;
9291
import com.oracle.graal.python.builtins.objects.getsetdescriptor.DescriptorDeleteMarker;
@@ -106,21 +105,14 @@
106105
import com.oracle.graal.python.nodes.PRaiseNode;
107106
import com.oracle.graal.python.nodes.PRootNode;
108107
import com.oracle.graal.python.nodes.SpecialMethodNames;
109-
import com.oracle.graal.python.nodes.argument.CreateArgumentsNode;
110-
import com.oracle.graal.python.nodes.argument.ReadArgumentNode;
111-
import com.oracle.graal.python.nodes.argument.ReadVarArgsNode;
112108
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
113109
import com.oracle.graal.python.nodes.call.CallNode;
114-
import com.oracle.graal.python.nodes.call.CallTargetInvokeNode;
115-
import com.oracle.graal.python.nodes.call.FunctionInvokeNode;
116110
import com.oracle.graal.python.nodes.call.special.CallBinaryMethodNode;
117111
import com.oracle.graal.python.nodes.call.special.CallTernaryMethodNode;
118112
import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode;
119113
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode.LookupAndCallUnaryDynamicNode;
120114
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
121115
import com.oracle.graal.python.nodes.frame.GetCurrentFrameRef;
122-
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
123-
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
124116
import com.oracle.graal.python.nodes.object.GetClassNode;
125117
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
126118
import com.oracle.graal.python.nodes.truffle.PythonTypes;
@@ -140,7 +132,6 @@
140132
import com.oracle.truffle.api.CompilerDirectives;
141133
import com.oracle.truffle.api.RootCallTarget;
142134
import com.oracle.truffle.api.Truffle;
143-
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
144135
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
145136
import com.oracle.truffle.api.TruffleLogger;
146137
import com.oracle.truffle.api.dsl.Cached;

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
import com.oracle.truffle.api.dsl.Cached.Exclusive;
155155
import com.oracle.truffle.api.dsl.Cached.Shared;
156156
import com.oracle.truffle.api.dsl.CachedContext;
157+
import com.oracle.truffle.api.dsl.CachedLanguage;
157158
import com.oracle.truffle.api.dsl.GenerateUncached;
158159
import com.oracle.truffle.api.dsl.ImportStatic;
159160
import com.oracle.truffle.api.dsl.Specialization;
@@ -185,9 +186,9 @@ public DynamicObjectNativeWrapper(Object delegate) {
185186
super(delegate);
186187
}
187188

188-
public DynamicObjectStorage createNativeMemberStore() {
189+
public DynamicObjectStorage createNativeMemberStore(PythonLanguage lang) {
189190
if (nativeMemberStore == null) {
190-
nativeMemberStore = new DynamicObjectStorage();
191+
nativeMemberStore = new DynamicObjectStorage(lang);
191192
}
192193
return nativeMemberStore;
193194
}
@@ -1165,8 +1166,9 @@ static Object doTpSubclasses(PythonClass object, @SuppressWarnings("unused") Pyt
11651166

11661167
@Specialization(guards = "eq(MD_DEF, key)", limit = "1")
11671168
static Object doMdDef(@SuppressWarnings("unused") PythonObject object, DynamicObjectNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key, Object value,
1168-
@CachedLibrary("nativeWrapper.createNativeMemberStore()") HashingStorageLibrary lib) {
1169-
lib.setItem(nativeWrapper.createNativeMemberStore(), MD_DEF.getMemberName(), value);
1169+
@CachedLanguage PythonLanguage lang,
1170+
@CachedLibrary("nativeWrapper.createNativeMemberStore(lang)") HashingStorageLibrary lib) {
1171+
lib.setItem(nativeWrapper.createNativeMemberStore(lang), MD_DEF.getMemberName(), value);
11701172
return value;
11711173
}
11721174

@@ -1235,13 +1237,14 @@ static int doFLineno(PFrame object, @SuppressWarnings("unused") PythonNativeWrap
12351237

12361238
@Specialization(guards = "isGenericCase(object, key)", limit = "1")
12371239
static Object doGeneric(@SuppressWarnings("unused") Object object, DynamicObjectNativeWrapper nativeWrapper, String key, Object value,
1238-
@CachedLibrary("nativeWrapper.createNativeMemberStore()") HashingStorageLibrary lib) throws UnknownIdentifierException {
1240+
@CachedLanguage PythonLanguage lang,
1241+
@CachedLibrary("nativeWrapper.createNativeMemberStore(lang)") HashingStorageLibrary lib) throws UnknownIdentifierException {
12391242
// This is the preliminary generic case: There are native members we know that they
12401243
// exist but we do currently not represent them. So, store them into a dynamic object
12411244
// such that native code at least reads the value that was written before.
12421245
if (nativeWrapper.isMemberModifiable(key)) {
12431246
logGeneric(key);
1244-
lib.setItem(nativeWrapper.createNativeMemberStore(), key, value);
1247+
lib.setItem(nativeWrapper.createNativeMemberStore(lang), key, value);
12451248
return value;
12461249
}
12471250
throw UnknownIdentifierException.create(key);

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
import com.oracle.truffle.api.library.ExportLibrary;
8686
import com.oracle.truffle.api.library.ExportMessage;
8787
import com.oracle.truffle.api.library.ExportMessage.Ignore;
88-
import com.oracle.truffle.api.object.Shape;
8988
import com.oracle.truffle.api.profiles.ConditionProfile;
9089
import com.oracle.truffle.api.profiles.ValueProfile;
9190
import com.oracle.truffle.api.utilities.TriState;
@@ -104,12 +103,6 @@ public int compareTo(Object o) {
104103
return 0;
105104
}
106105

107-
@SuppressWarnings("static-method")
108-
public Shape getInstanceShape() {
109-
CompilerDirectives.transferToInterpreter();
110-
throw new UnsupportedOperationException("native class does not have a shape");
111-
}
112-
113106
public void lookupChanged() {
114107
// TODO invalidate cached native MRO
115108
CompilerDirectives.transferToInterpreter();

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ private static final class CApiReferenceCleanerRootNode extends PRootNode {
311311
@Child private InteropLibrary pointerObjectLib;
312312
@Child private PCallCapiFunction callBulkSubref;
313313

314-
private final ConditionProfile customLocalsProfile = ConditionProfile.createBinaryProfile();
315314
private final CApiContext cApiContext;
316315

317316
protected CApiReferenceCleanerRootNode(PythonContext context) {
@@ -323,7 +322,7 @@ protected CApiReferenceCleanerRootNode(PythonContext context) {
323322

324323
@Override
325324
public Object execute(VirtualFrame frame) {
326-
CalleeContext.enter(frame, customLocalsProfile);
325+
calleeContext.enter(frame);
327326
try {
328327
NativeObjectReference[] nativeObjectReferences = (NativeObjectReference[]) PArguments.getArgument(frame, 0);
329328
int cleaned = 0;

0 commit comments

Comments
 (0)