Skip to content

Commit 95c9c26

Browse files
committed
Add option to eagerly materialize instrumentation nodes
1 parent fd83074 commit 95c9c26

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
import java.math.BigInteger;
5252
import java.util.Arrays;
53+
import java.util.Collections;
5354
import java.util.Set;
5455
import java.util.concurrent.locks.Lock;
5556

@@ -208,7 +209,6 @@
208209
import com.oracle.truffle.api.HostCompilerDirectives.BytecodeInterpreterSwitch;
209210
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
210211
import com.oracle.truffle.api.Truffle;
211-
import com.oracle.truffle.api.TruffleLanguage;
212212
import com.oracle.truffle.api.TruffleSafepoint;
213213
import com.oracle.truffle.api.exception.AbstractTruffleException;
214214
import com.oracle.truffle.api.frame.Frame;
@@ -219,6 +219,7 @@
219219
import com.oracle.truffle.api.frame.VirtualFrame;
220220
import com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode;
221221
import com.oracle.truffle.api.instrumentation.ProbeNode;
222+
import com.oracle.truffle.api.instrumentation.StandardTags;
222223
import com.oracle.truffle.api.instrumentation.Tag;
223224
import com.oracle.truffle.api.nodes.BytecodeOSRNode;
224225
import com.oracle.truffle.api.nodes.ControlFlowException;
@@ -575,21 +576,26 @@ private static Signature makeSignature(CodeUnit co) {
575576
}
576577

577578
@TruffleBoundary
578-
public static PBytecodeRootNode create(TruffleLanguage<?> language, CodeUnit co, Source source) {
579+
public static PBytecodeRootNode create(PythonLanguage language, CodeUnit co, Source source) {
579580
return create(language, co, source, null);
580581
}
581582

582583
@TruffleBoundary
583-
public static PBytecodeRootNode create(TruffleLanguage<?> language, CodeUnit co, Source source, RaisePythonExceptionErrorCallback parserErrorCallback) {
584+
public static PBytecodeRootNode create(PythonLanguage language, CodeUnit co, Source source, RaisePythonExceptionErrorCallback parserErrorCallback) {
584585
FrameInfo frameInfo = new FrameInfo();
585586
FrameDescriptor fd = makeFrameDescriptor(co, frameInfo);
586587
PBytecodeRootNode rootNode = new PBytecodeRootNode(language, fd, makeSignature(co), co, source, parserErrorCallback);
588+
PythonContext context = PythonContext.get(rootNode);
589+
if (context != null && context.getOption(PythonOptions.EagerlyMaterializeInstrumentationNodes)) {
590+
rootNode.adoptChildren();
591+
rootNode.instrumentationRoot.materializeInstrumentableNodes(Collections.singleton(StandardTags.StatementTag.class));
592+
}
587593
frameInfo.rootNode = rootNode;
588594
return rootNode;
589595
}
590596

591597
@TruffleBoundary
592-
private PBytecodeRootNode(TruffleLanguage<?> language, FrameDescriptor fd, Signature sign, CodeUnit co, Source source, RaisePythonExceptionErrorCallback parserErrorCallback) {
598+
private PBytecodeRootNode(PythonLanguage language, FrameDescriptor fd, Signature sign, CodeUnit co, Source source, RaisePythonExceptionErrorCallback parserErrorCallback) {
593599
super(language, fd);
594600
this.celloffset = co.varnames.length;
595601
this.freeoffset = celloffset + co.cellvars.length;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ private PythonOptions() {
310310
@Option(category = OptionCategory.EXPERT, help = "Enables using bytecode interpreter instead of legacy AST interpreter.") //
311311
public static final OptionKey<Boolean> EnableBytecodeInterpreter = new OptionKey<>(true);
312312

313+
@Option(category = OptionCategory.EXPERT, help = "Makes bytecode instrumentation node materialization eager instead of lazy.") //
314+
public static final OptionKey<Boolean> EagerlyMaterializeInstrumentationNodes = new OptionKey<>(false);
315+
313316
public static final OptionDescriptors DESCRIPTORS = new PythonOptionsOptionDescriptors();
314317

315318
@CompilationFinal(dimensions = 1) private static final OptionKey<?>[] ENGINE_OPTION_KEYS;

0 commit comments

Comments
 (0)