Skip to content

Commit fef26dc

Browse files
committed
split specializations for setting the class of an object into single and multicontext
1 parent 58e370e commit fef26dc

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ LazyPythonClass setClass(@SuppressWarnings("unused") Object self, @SuppressWarni
144144

145145
@Specialization
146146
PNone setClass(VirtualFrame frame, PythonObject self, PythonAbstractClass value,
147-
@CachedLibrary("self") PythonObjectLibrary lib,
147+
@CachedLibrary(limit = "2") PythonObjectLibrary lib,
148148
@Cached("create()") BranchProfile errorValueBranch,
149149
@Cached("create()") BranchProfile errorSelfBranch,
150150
@Cached("create()") BranchProfile errorSlotsBranch,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/PythonObject.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
4444
import com.oracle.truffle.api.dsl.Cached;
4545
import com.oracle.truffle.api.dsl.Cached.Exclusive;
46-
import com.oracle.truffle.api.dsl.CachedLanguage;
4746
import com.oracle.truffle.api.dsl.GenerateUncached;
4847
import com.oracle.truffle.api.dsl.Specialization;
4948
import com.oracle.truffle.api.library.ExportLibrary;
@@ -88,18 +87,27 @@ public final PythonAbstractClass getPythonClass() {
8887
}
8988

9089
@ExportMessage
91-
public final void setLazyPythonClass(PythonAbstractClass cls,
92-
@SuppressWarnings("unused") @CachedLanguage PythonLanguage language,
93-
@Cached("language.singleContextAssumption") Assumption storingClassesInShapes) {
94-
storedPythonClass = cls;
95-
if (storingClassesInShapes.isValid()) {
96-
PythonObjectLayoutImpl.INSTANCE.setLazyPythonClass(storage, cls);
97-
} else {
98-
if (PythonObjectLayoutImpl.INSTANCE.getLazyPythonClass(storage) != null) {
90+
@GenerateUncached
91+
public abstract static class SetLazyPythonClass {
92+
public static Assumption getSingleContextAssumption() {
93+
return PythonLanguage.getCurrent().singleContextAssumption;
94+
}
95+
96+
@Specialization(assumptions = "storingClassesInShapes")
97+
public static void setSingle(PythonObject self, PythonAbstractClass cls,
98+
@SuppressWarnings("unused") @Cached(value = "getSingleContextAssumption()", allowUncached = true) Assumption storingClassesInShapes) {
99+
self.storedPythonClass = cls;
100+
PythonObjectLayoutImpl.INSTANCE.setLazyPythonClass(self.storage, cls);
101+
}
102+
103+
@Specialization
104+
public static void setMultiContext(PythonObject self, PythonAbstractClass cls) {
105+
self.storedPythonClass = cls;
106+
if (PythonObjectLayoutImpl.INSTANCE.getLazyPythonClass(self.storage) != null) {
99107
// for the builtin class enums, we now should change the shape
100108
// to the generic one that just doesn't store the class
101-
Shape shape = storage.getShape();
102-
storage.setShapeAndGrow(shape, shape.changeType(emptyShape.getObjectType()));
109+
Shape shape = self.storage.getShape();
110+
self.storage.setShapeAndGrow(shape, shape.changeType(emptyShape.getObjectType()));
103111
}
104112
}
105113
}
@@ -240,7 +248,7 @@ public static Shape freshShape() {
240248
return emptyShape;
241249
}
242250

243-
public static LazyPythonClass getLazyPythonClass(ObjectType type) {
251+
public static LazyPythonClass getLazyClassFromObjectType(ObjectType type) {
244252
return PythonObjectLayoutImpl.INSTANCE.getLazyPythonClass(type);
245253
}
246254
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetLazyClassNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ protected static LazyPythonClass getPythonClassCachedSingle(@SuppressWarnings("u
167167
}
168168

169169
protected static boolean isBuiltinType(Shape shape) {
170-
return PythonObject.getLazyPythonClass(shape.getObjectType()) instanceof PythonBuiltinClassType;
170+
return PythonObject.getLazyClassFromObjectType(shape.getObjectType()) instanceof PythonBuiltinClassType;
171171
}
172172

173173
// we can at least cache builtin types in the multi-context case

0 commit comments

Comments
 (0)