Skip to content

Commit 7acc918

Browse files
committed
[GR-45141] Get rid of clinit cycle CExtContext<>CApiContext, remove unused logger
PullRequest: graalpython/2724
2 parents 28be1bb + e81f45e commit 7acc918

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/DynamicObjectNativeWrapper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@
228228
@ExportLibrary(InteropLibrary.class)
229229
@ExportLibrary(value = NativeTypeLibrary.class, useForAOT = false)
230230
public abstract class DynamicObjectNativeWrapper extends PythonNativeWrapper {
231-
private static final TruffleLogger LOGGER = CApiContext.getLogger(DynamicObjectNativeWrapper.class);
232231
static final String J_GP_OBJECT = "gp_object";
233232
static final TruffleString T_GP_OBJECT = tsLiteral(J_GP_OBJECT);
234233
static final TruffleString T_VALUE = tsLiteral("value");

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtContext.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,15 @@
9393

9494
public abstract class CExtContext {
9595

96-
private static final TruffleLogger LOGGER = CApiContext.getLogger(CExtContext.class);
96+
// Due to the cycle CExtContext -> CApiContext < CExtContext this needs to be done lazily
97+
private static TruffleLogger LOGGER;
98+
99+
private static TruffleLogger getLogger() {
100+
if (LOGGER == null) {
101+
LOGGER = CApiContext.getLogger(CExtContext.class);
102+
}
103+
return LOGGER;
104+
}
97105

98106
public static final CExtContext LAZY_CONTEXT = new CExtContext(null, null) {
99107
@Override
@@ -325,12 +333,10 @@ public static Object loadCExtModule(Node location, PythonContext context, Module
325333
if (loaded) {
326334
String name = spec.name.toJavaStringUncached();
327335
if (!isForcedLLVM(name) && (nativeModuleOption.equals("all") || moduleMatches(name, nativeModuleOption.split(",")))) {
328-
if (cApiContext.supportsNativeBackend) {
329-
GraalHPyContext.loadJNIBackend();
330-
LOGGER.config("loading module " + spec.path + " as native");
331-
boolean panama = PythonOptions.UsePanama.getValue(PythonContext.get(null).getEnv().getOptions());
332-
library = GraalHPyContext.evalNFI(context, (panama ? "with panama " : "") + "load \"" + spec.path + "\"", "load " + spec.name);
333-
}
336+
GraalHPyContext.loadJNIBackend();
337+
getLogger().config("loading module " + spec.path + " as native");
338+
boolean panama = PythonOptions.UsePanama.getValue(PythonContext.get(null).getEnv().getOptions());
339+
library = GraalHPyContext.evalNFI(context, (panama ? "with panama " : "") + "load \"" + spec.path + "\"", "load " + spec.name);
334340
}
335341
} else {
336342
cApiContext.supportsNativeBackend = false;
@@ -342,12 +348,12 @@ public static Object loadCExtModule(Node location, PythonContext context, Module
342348
try {
343349
if (InteropLibrary.getUncached(library).getLanguage(library).toString().startsWith("class com.oracle.truffle.nfi")) {
344350
if (cApiContext.supportsNativeBackend) {
345-
LOGGER.config("loading module " + spec.path + " as native (no bitcode found)");
351+
getLogger().config("loading module " + spec.path + " as native (no bitcode found)");
346352
} else {
347353
throw PRaiseNode.raiseUncached(null, SystemError, ErrorMessages.CANNOT_MULTICONTEXT);
348354
}
349355
} else {
350-
LOGGER.config("loading module " + spec.path + " as llvm bitcode");
356+
getLogger().config("loading module " + spec.path + " as llvm bitcode");
351357
}
352358
} catch (UnsupportedMessageException e) {
353359
throw CompilerDirectives.shouldNotReachHere(e);

0 commit comments

Comments
 (0)