Skip to content

Commit f5860f0

Browse files
committed
cache AllocationReporter in PythonContext
1 parent 5737b34 commit f5860f0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
import com.oracle.truffle.api.TruffleLanguage;
108108
import com.oracle.truffle.api.TruffleLanguage.Env;
109109
import com.oracle.truffle.api.TruffleLogger;
110+
import com.oracle.truffle.api.instrumentation.AllocationReporter;
110111
import com.oracle.truffle.api.interop.ExceptionType;
111112
import com.oracle.truffle.api.interop.InteropLibrary;
112113
import com.oracle.truffle.api.interop.UnsupportedMessageException;
@@ -314,6 +315,7 @@ private static final class AtExitHook {
314315
private final ThreadLocal<ArrayDeque<String>> currentImport = new ThreadLocal<>();
315316

316317
@CompilationFinal(dimensions = 1) private Object[] optionValues;
318+
private AllocationReporter allocationReporter;
317319

318320
/*
319321
* These maps are used to ensure that each "deserialization" of code in the parser gets a
@@ -341,6 +343,13 @@ public PythonContext(PythonLanguage language, TruffleLanguage.Env env, Python3Co
341343
this.err = env.err();
342344
}
343345

346+
public AllocationReporter getAllocationReporter() {
347+
if (allocationReporter == null) {
348+
return allocationReporter = env.lookup(AllocationReporter.class);
349+
}
350+
return allocationReporter;
351+
}
352+
344353
public ThreadGroup getThreadGroup() {
345354
return threadGroup;
346355
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ static PythonLanguage getLanguage(boolean marker, double marker2,
220220
}
221221

222222
protected static AllocationReporter getAllocationReporter(ContextReference<PythonContext> contextRef) {
223-
return contextRef.get().getEnv().lookup(AllocationReporter.class);
223+
return contextRef.get().getAllocationReporter();
224224
}
225225

226226
public final PythonLanguage getLanguage() {

0 commit comments

Comments
 (0)