Skip to content

Commit 7d585f0

Browse files
committed
simplify PythonObject constructor
1 parent 38611b8 commit 7d585f0

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,7 @@ Object doObjectCachedInstanceShape(PythonManagedClass self, Object[] varargs, PK
14901490
if (varargs.length > 0 || kwargs.length > 0) {
14911491
// TODO: tfel: this should throw an error only if init isn't overridden
14921492
}
1493-
return factory().createPythonObject(self, cachedInstanceShape);
1493+
return factory().createPythonObject(cachedInstanceShape);
14941494
}
14951495

14961496
@Specialization(guards = "!self.needsNativeAllocation()", replaces = "doObjectCachedInstanceShape")

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@
125125
import com.oracle.graal.python.builtins.objects.type.PythonClass;
126126
import com.oracle.graal.python.builtins.objects.type.PythonManagedClass;
127127
import com.oracle.graal.python.builtins.objects.type.TypeNodes;
128-
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetInstanceShape;
129128
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetTypeFlagsNode;
130129
import com.oracle.graal.python.nodes.PGuards;
131130
import com.oracle.graal.python.nodes.PNodeWithContext;
@@ -221,7 +220,7 @@ public void initialize(PythonCore core) {
221220
PythonClass errorHandlerClass = core.factory().createPythonClass(PythonBuiltinClassType.PythonClass, "CErrorHandler",
222221
new PythonAbstractClass[]{core.lookupType(PythonBuiltinClassType.PythonObject)});
223222
builtinConstants.put("CErrorHandler", errorHandlerClass);
224-
builtinConstants.put(ERROR_HANDLER, core.factory().createPythonObject(errorHandlerClass, GetInstanceShape.doSlowPath(errorHandlerClass)));
223+
builtinConstants.put(ERROR_HANDLER, core.factory().createPythonObject(errorHandlerClass));
225224
builtinConstants.put(NATIVE_NULL, new PythonNativeNull());
226225
}
227226

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import com.oracle.graal.python.builtins.objects.object.PythonObject;
5353
import com.oracle.graal.python.builtins.objects.str.PString;
5454
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
55-
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetInstanceShape;
5655
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
5756
import com.oracle.graal.python.runtime.PythonCore;
5857
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -160,7 +159,7 @@ public void initialize(PythonCore core) {
160159
super.initialize(core);
161160
builtinConstants.put("version", getUnicodeVersion());
162161
PythonBuiltinClass objectType = core.lookupType(PythonBuiltinClassType.PythonObject);
163-
PythonObject ucd_3_2_0 = core.factory().createPythonObject(objectType, GetInstanceShape.doSlowPath(objectType));
162+
PythonObject ucd_3_2_0 = core.factory().createPythonObject(objectType);
164163
ucd_3_2_0.setAttribute("unidata_version", "3.2.0");
165164
builtinConstants.put("ucd_3_2_0", ucd_3_2_0); // TODO this is a fake object, just satisfy
166165
// pip installer import

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import com.oracle.graal.python.builtins.objects.type.PythonManagedClass;
3939
import com.oracle.graal.python.builtins.objects.type.TypeNodes;
4040
import com.oracle.truffle.api.CompilerAsserts;
41-
import com.oracle.truffle.api.CompilerDirectives;
4241
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
4342
import com.oracle.truffle.api.object.DynamicObject;
4443
import com.oracle.truffle.api.object.DynamicObjectFactory;
@@ -56,11 +55,7 @@ public PythonObject(LazyPythonClass pythonClass) {
5655
assert getLazyPythonClass() == pythonClass;
5756
}
5857

59-
public PythonObject(LazyPythonClass pythonClass, Shape instanceShape) {
60-
if (pythonClass == null) {
61-
assert false;
62-
CompilerDirectives.transferToInterpreter();
63-
}
58+
public PythonObject(Shape instanceShape) {
6459
storage = instanceShape.newInstance();
6560
}
6661

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/PythonManagedClass.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ public abstract class PythonManagedClass extends PythonObject implements PythonA
6464

6565
@TruffleBoundary
6666
public PythonManagedClass(LazyPythonClass typeClass, String name, PythonAbstractClass... baseClasses) {
67-
super(typeClass, PythonObject.freshShape(typeClass) /*
68-
* do not inherit layout from the
69-
* TypeClass
70-
*/);
67+
super(PythonObject.freshShape(typeClass) /* do not inherit layout from the */);
7168
this.className = name;
7269

7370
this.methodResolutionOrder = new MroSequenceStorage(name, 0);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectFactory.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,20 @@ public final <T> T trace(T allocatedObject) {
177177
* Python objects
178178
*/
179179

180-
public PythonObject createPythonObject(LazyPythonClass cls, Shape instanceShape) {
181-
return trace(new PythonObject(cls, instanceShape));
180+
/**
181+
* Creates a PythonObject for the given class. This is potentially slightly slower than if the
182+
* shape had been cached, due to the additional shape lookup.
183+
*/
184+
public PythonObject createPythonObject(LazyPythonClass cls) {
185+
return trace(new PythonObject(cls));
186+
}
187+
188+
/**
189+
* Creates a Python object with the given shape. Python object shapes store the class in the
190+
* ObjectType.
191+
*/
192+
public PythonObject createPythonObject(Shape instanceShape) {
193+
return trace(new PythonObject(instanceShape));
182194
}
183195

184196
public PythonNativeObject createNativeObjectWrapper(TruffleObject obj) {

0 commit comments

Comments
 (0)