Skip to content

Commit 0564462

Browse files
committed
Use PythonObjectSlowPathFactory as Python3Core.factory and share it everywhere
1 parent a48aebd commit 0564462

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.regex.Matcher;
4545
import java.util.regex.Pattern;
4646

47+
import com.oracle.graal.python.runtime.object.PythonObjectSlowPathFactory;
4748
import org.graalvm.nativeimage.ImageInfo;
4849

4950
import com.oracle.graal.python.PythonLanguage;
@@ -606,7 +607,7 @@ private static PythonBuiltins[] initializeBuiltins(boolean nativeAccessAllowed)
606607
*/
607608
private volatile boolean initialized;
608609

609-
private final PythonObjectFactory objectFactory = PythonObjectFactory.getUncached();
610+
private PythonObjectSlowPathFactory objectFactory;
610611

611612
public Python3Core(PythonParser parser, boolean isNativeSupportAllowed) {
612613
this.parser = parser;
@@ -643,6 +644,7 @@ public boolean isInitialized() {
643644
*/
644645
public void initialize(PythonContext context) {
645646
singletonContext = context;
647+
objectFactory = new PythonObjectSlowPathFactory(context.getAllocationReporter());
646648
initializeJavaCore();
647649
initializePython3Core(context.getCoreHomeOrFail());
648650
assert SpecialMethodSlot.checkSlotOverrides(this);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstModuleBuiltins.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
5454
import com.oracle.graal.python.builtins.objects.type.PythonClass;
5555
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
56+
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
5657
import com.oracle.graal.python.runtime.object.PythonObjectSlowPathFactory;
5758
import com.oracle.truffle.api.dsl.NodeFactory;
5859

@@ -80,7 +81,7 @@ public void postInitialize(Python3Core core) {
8081
* writable class fields.
8182
*/
8283
PythonLanguage language = core.getLanguage();
83-
PythonObjectSlowPathFactory factory = new PythonObjectSlowPathFactory(core.getContext().getAllocationReporter());
84+
PythonObjectFactory factory = core.factory();
8485
PythonClass mod_type = makeType(language, factory, astModule, "mod", astType);
8586
PythonClass Module_type = makeType(language, factory, astModule, "Module", mod_type);
8687
PythonClass Interactive_type = makeType(language, factory, astModule, "Interactive", mod_type);
@@ -196,7 +197,7 @@ public void postInitialize(Python3Core core) {
196197
PythonClass TypeIgnore_type = makeType(language, factory, astModule, "TypeIgnore", type_ignore_type);
197198
}
198199

199-
private static PythonClass makeType(PythonLanguage language, PythonObjectSlowPathFactory factory, PythonModule astModule, String name, PythonAbstractClass base) {
200+
private static PythonClass makeType(PythonLanguage language, PythonObjectFactory factory, PythonModule astModule, String name, PythonAbstractClass base) {
200201
PythonClass newType = factory.createPythonClassAndFixupSlots(language, PythonBuiltinClassType.PythonClass, name, new PythonAbstractClass[]{base});
201202
astModule.setAttribute(name, newType);
202203
return newType;

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@
197197
import com.oracle.graal.python.runtime.exception.PException;
198198
import com.oracle.graal.python.runtime.exception.PythonThreadKillException;
199199
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
200-
import com.oracle.graal.python.runtime.object.PythonObjectSlowPathFactory;
201200
import com.oracle.graal.python.runtime.sequence.PSequence;
202201
import com.oracle.graal.python.runtime.sequence.storage.DoubleSequenceStorage;
203202
import com.oracle.graal.python.runtime.sequence.storage.IntSequenceStorage;
@@ -772,7 +771,7 @@ public static GraalHPyNativeSymbol getGetterFunctionName(LLVMType llvmType) {
772771
@CompilationFinal private RootCallTarget referenceCleanerCallTarget;
773772
private Thread hpyReferenceCleanerThread;
774773

775-
private PythonObjectSlowPathFactory slowPathFactory;
774+
private PythonObjectFactory slowPathFactory;
776775

777776
public GraalHPyContext(PythonContext context, Object hpyLibrary) {
778777
super(context, hpyLibrary, GraalHPyConversionNodeSupplier.HANDLE);
@@ -1301,9 +1300,9 @@ void increment() {
13011300
* Returns a Python object factory that should only be used on the slow path. The factory object
13021301
* is initialized lazily.
13031302
*/
1304-
private PythonObjectSlowPathFactory factory() {
1303+
private PythonObjectFactory factory() {
13051304
if (slowPathFactory == null) {
1306-
slowPathFactory = new PythonObjectSlowPathFactory(getContext().getAllocationReporter());
1305+
slowPathFactory = getContext().getCore().factory();
13071306
}
13081307
return slowPathFactory;
13091308
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
* directly stores a reference to the {@link AllocationReporter} instead of doing a context lookup
5555
* and getting it from the context. This class is meant to be used on slow path where the context is
5656
* explicitly available.
57+
*
58+
* Objects of this class should not be created directly, but retrieved from
59+
* {@link com.oracle.graal.python.builtins.Python3Core}.
5760
*/
5861
public final class PythonObjectSlowPathFactory extends PythonObjectFactory {
5962

0 commit comments

Comments
 (0)