66
66
import java .util .concurrent .atomic .AtomicReference ;
67
67
import java .util .logging .Level ;
68
68
69
+ import com .oracle .graal .python .runtime .object .PythonObjectSlowPathFactory ;
69
70
import org .graalvm .nativeimage .ImageInfo ;
70
71
71
72
import com .oracle .graal .python .PythonLanguage ;
@@ -771,10 +772,11 @@ public static GraalHPyNativeSymbol getGetterFunctionName(LLVMType llvmType) {
771
772
@ CompilationFinal private RootCallTarget referenceCleanerCallTarget ;
772
773
private Thread hpyReferenceCleanerThread ;
773
774
774
- private PythonObjectFactory slowPathFactory ;
775
+ private final PythonObjectSlowPathFactory slowPathFactory ;
775
776
776
777
public GraalHPyContext (PythonContext context , Object hpyLibrary ) {
777
778
super (context , hpyLibrary , GraalHPyConversionNodeSupplier .HANDLE );
779
+ this .slowPathFactory = context .getCore ().factory ();
778
780
this .hpyContextMembers = createMembers (context , getName ());
779
781
this .useNativeFastPaths = context .getLanguage ().getEngineOption (PythonOptions .HPyEnableJNIFastPaths );
780
782
}
@@ -1296,17 +1298,6 @@ void increment() {
1296
1298
}
1297
1299
}
1298
1300
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
-
1310
1301
@ SuppressWarnings ("static-method" )
1311
1302
public final long ctxFloatFromDouble (double value ) {
1312
1303
Counter .UpcallFloatFromDouble .increment ();
@@ -1376,7 +1367,7 @@ public final long ctxNew(long typeHandle, long dataOutVar) {
1376
1367
long basicSize = clazz .basicSize ;
1377
1368
if (basicSize == -1 ) {
1378
1369
// create the managed Python object
1379
- pythonObject = factory () .createPythonObject (clazz , clazz .getInstanceShape ());
1370
+ pythonObject = slowPathFactory .createPythonObject (clazz , clazz .getInstanceShape ());
1380
1371
} else {
1381
1372
/*
1382
1373
* 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) {
1386
1377
long dataPtr = unsafe .allocateMemory (basicSize );
1387
1378
unsafe .setMemory (dataPtr , basicSize , (byte ) 0 );
1388
1379
unsafe .putLong (dataOutVar , dataPtr );
1389
- pythonObject = factory () .createPythonHPyObject (clazz , dataPtr );
1380
+ pythonObject = slowPathFactory .createPythonHPyObject (clazz , dataPtr );
1390
1381
Object destroyFunc = clazz .hpyDestroyFunc ;
1391
1382
createHandleReference (pythonObject , dataPtr , destroyFunc != PNone .NO_VALUE ? destroyFunc : null );
1392
1383
}
@@ -1396,7 +1387,7 @@ public final long ctxNew(long typeHandle, long dataOutVar) {
1396
1387
return HPyRaiseNodeGen .getUncached ().raiseIntWithoutFrame (this , 0 , PythonBuiltinClassType .TypeError , "HPy_New arg 1 must be a type" );
1397
1388
}
1398
1389
// TODO(fa): this should actually call __new__
1399
- pythonObject = factory () .createPythonObject (type );
1390
+ pythonObject = slowPathFactory .createPythonObject (type );
1400
1391
}
1401
1392
return GraalHPyBoxing .boxHandle (createHandle (pythonObject ).getId (this , ConditionProfile .getUncached ()));
1402
1393
}
@@ -1415,9 +1406,9 @@ public final long ctxTypeGenericNew(long typeHandle) {
1415
1406
// allocate native space
1416
1407
long dataPtr = unsafe .allocateMemory (basicSize );
1417
1408
unsafe .setMemory (dataPtr , basicSize , (byte ) 0 );
1418
- pythonObject = factory () .createPythonHPyObject (clazz , dataPtr );
1409
+ pythonObject = slowPathFactory .createPythonHPyObject (clazz , dataPtr );
1419
1410
} else {
1420
- pythonObject = factory () .createPythonObject (clazz );
1411
+ pythonObject = slowPathFactory .createPythonObject (clazz );
1421
1412
}
1422
1413
return GraalHPyBoxing .boxHandle (createHandle (pythonObject ).getId (this , ConditionProfile .getUncached ()));
1423
1414
}
0 commit comments