Skip to content

Commit 6402e5a

Browse files
committed
Initialize GraalHPyContext#slowPathFactory eagerly from the context
1 parent 588209f commit 6402e5a

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ private void loadFile(String s, String prefix) {
942942
GenericInvokeNode.getUncached().execute(callTarget, PArguments.withGlobals(mod));
943943
}
944944

945-
public PythonObjectFactory factory() {
945+
public PythonObjectSlowPathFactory factory() {
946946
return objectFactory;
947947
}
948948

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import java.util.concurrent.atomic.AtomicReference;
6767
import java.util.logging.Level;
6868

69+
import com.oracle.graal.python.runtime.object.PythonObjectSlowPathFactory;
6970
import org.graalvm.nativeimage.ImageInfo;
7071

7172
import com.oracle.graal.python.PythonLanguage;
@@ -771,10 +772,11 @@ public static GraalHPyNativeSymbol getGetterFunctionName(LLVMType llvmType) {
771772
@CompilationFinal private RootCallTarget referenceCleanerCallTarget;
772773
private Thread hpyReferenceCleanerThread;
773774

774-
private PythonObjectFactory slowPathFactory;
775+
private final PythonObjectSlowPathFactory slowPathFactory;
775776

776777
public GraalHPyContext(PythonContext context, Object hpyLibrary) {
777778
super(context, hpyLibrary, GraalHPyConversionNodeSupplier.HANDLE);
779+
this.slowPathFactory = context.getCore().factory();
778780
this.hpyContextMembers = createMembers(context, getName());
779781
this.useNativeFastPaths = context.getLanguage().getEngineOption(PythonOptions.HPyEnableJNIFastPaths);
780782
}
@@ -1296,17 +1298,6 @@ void increment() {
12961298
}
12971299
}
12981300

1299-
/**
1300-
* Returns a Python object factory that should only be used on the slow path. The factory object
1301-
* is initialized lazily.
1302-
*/
1303-
private PythonObjectFactory factory() {
1304-
if (slowPathFactory == null) {
1305-
slowPathFactory = getContext().getCore().factory();
1306-
}
1307-
return slowPathFactory;
1308-
}
1309-
13101301
@SuppressWarnings("static-method")
13111302
public final long ctxFloatFromDouble(double value) {
13121303
Counter.UpcallFloatFromDouble.increment();
@@ -1376,7 +1367,7 @@ public final long ctxNew(long typeHandle, long dataOutVar) {
13761367
long basicSize = clazz.basicSize;
13771368
if (basicSize == -1) {
13781369
// create the managed Python object
1379-
pythonObject = factory().createPythonObject(clazz, clazz.getInstanceShape());
1370+
pythonObject = slowPathFactory.createPythonObject(clazz, clazz.getInstanceShape());
13801371
} else {
13811372
/*
13821373
* Since this is a JNI upcall method, we know that (1) we are not running in some
@@ -1386,7 +1377,7 @@ public final long ctxNew(long typeHandle, long dataOutVar) {
13861377
long dataPtr = unsafe.allocateMemory(basicSize);
13871378
unsafe.setMemory(dataPtr, basicSize, (byte) 0);
13881379
unsafe.putLong(dataOutVar, dataPtr);
1389-
pythonObject = factory().createPythonHPyObject(clazz, dataPtr);
1380+
pythonObject = slowPathFactory.createPythonHPyObject(clazz, dataPtr);
13901381
Object destroyFunc = clazz.hpyDestroyFunc;
13911382
createHandleReference(pythonObject, dataPtr, destroyFunc != PNone.NO_VALUE ? destroyFunc : null);
13921383
}
@@ -1396,7 +1387,7 @@ public final long ctxNew(long typeHandle, long dataOutVar) {
13961387
return HPyRaiseNodeGen.getUncached().raiseIntWithoutFrame(this, 0, PythonBuiltinClassType.TypeError, "HPy_New arg 1 must be a type");
13971388
}
13981389
// TODO(fa): this should actually call __new__
1399-
pythonObject = factory().createPythonObject(type);
1390+
pythonObject = slowPathFactory.createPythonObject(type);
14001391
}
14011392
return GraalHPyBoxing.boxHandle(createHandle(pythonObject).getId(this, ConditionProfile.getUncached()));
14021393
}
@@ -1415,9 +1406,9 @@ public final long ctxTypeGenericNew(long typeHandle) {
14151406
// allocate native space
14161407
long dataPtr = unsafe.allocateMemory(basicSize);
14171408
unsafe.setMemory(dataPtr, basicSize, (byte) 0);
1418-
pythonObject = factory().createPythonHPyObject(clazz, dataPtr);
1409+
pythonObject = slowPathFactory.createPythonHPyObject(clazz, dataPtr);
14191410
} else {
1420-
pythonObject = factory().createPythonObject(clazz);
1411+
pythonObject = slowPathFactory.createPythonObject(clazz);
14211412
}
14221413
return GraalHPyBoxing.boxHandle(createHandle(pythonObject).getId(this, ConditionProfile.getUncached()));
14231414
}

0 commit comments

Comments
 (0)