Skip to content

Commit 6919d54

Browse files
committed
PIC for builtin class types when we're in multi-context case
1 parent 87b17da commit 6919d54

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
4343
import com.oracle.truffle.api.object.DynamicObject;
4444
import com.oracle.truffle.api.object.DynamicObjectFactory;
45+
import com.oracle.truffle.api.object.ObjectType;
4546
import com.oracle.truffle.api.object.Shape;
4647
import com.oracle.truffle.api.object.dsl.Layout;
4748
import com.oracle.truffle.api.object.dsl.Nullable;
@@ -158,6 +159,8 @@ protected static interface PythonObjectLayout {
158159

159160
LazyPythonClass getLazyPythonClass(DynamicObjectFactory factory);
160161

162+
LazyPythonClass getLazyPythonClass(ObjectType objectType);
163+
161164
LazyPythonClass getLazyPythonClass(DynamicObject object);
162165

163166
void setLazyPythonClass(DynamicObject object, LazyPythonClass value);
@@ -166,4 +169,8 @@ protected static interface PythonObjectLayout {
166169
public static Shape freshShape(LazyPythonClass klass) {
167170
return PythonObjectLayoutImpl.INSTANCE.createPythonObjectShape(klass).getShape();
168171
}
172+
173+
public static LazyPythonClass getLazyPythonClass(ObjectType type) {
174+
return PythonObjectLayoutImpl.INSTANCE.getLazyPythonClass(type);
175+
}
169176
}

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,27 @@ protected static LazyPythonClass getIt(@SuppressWarnings("unused") PythonNativeV
158158

159159
// if object is constant here, storage will also be constant, so the shape
160160
// lookup is the only thing we need.
161-
@Specialization(guards = "object.getStorage().getShape() == cachedShape", assumptions = {"singleContextAssumption"}, limit = "1")
162-
protected static LazyPythonClass getPythonClassCached(@SuppressWarnings("unused") PythonObject object,
161+
@Specialization(guards = "object.getStorage().getShape() == cachedShape", assumptions = {"singleContextAssumption"}, limit = "4")
162+
protected static LazyPythonClass getPythonClassCachedSingle(@SuppressWarnings("unused") PythonObject object,
163163
@SuppressWarnings("unused") @Cached("object.getStorage().getShape()") Shape cachedShape,
164164
@SuppressWarnings("unused") @Cached("singleContextAssumption()") Assumption singleContextAssumption,
165165
@Cached("object.getLazyPythonClass()") LazyPythonClass klass) {
166166
return klass;
167167
}
168168

169-
@Specialization(replaces = "getPythonClassCached")
169+
protected static boolean isBuiltinType(Shape shape) {
170+
return PythonObject.getLazyPythonClass(shape.getObjectType()) instanceof PythonBuiltinClassType;
171+
}
172+
173+
// we can at least cache builtin types in the multi-context case
174+
@Specialization(guards = {"object.getStorage().getShape() == cachedShape", "isBuiltinType(cachedShape)"}, limit = "4")
175+
protected static LazyPythonClass getPythonClassCached(@SuppressWarnings("unused") PythonObject object,
176+
@SuppressWarnings("unused") @Cached("object.getStorage().getShape()") Shape cachedShape,
177+
@Cached("object.getLazyPythonClass()") LazyPythonClass klass) {
178+
return klass;
179+
}
180+
181+
@Specialization(replaces = {"getPythonClassCached", "getPythonClassCachedSingle"})
170182
protected static LazyPythonClass getPythonClassGeneric(PythonObject object) {
171183
return object.getLazyPythonClass();
172184
}

0 commit comments

Comments
 (0)