Skip to content

Commit 06a62d3

Browse files
committed
Add comments about instrumentation
1 parent 208ab38 commit 06a62d3

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,10 @@ public final class PBytecodeRootNode extends PRootNode implements BytecodeOSRNod
508508
*/
509509
@CompilationFinal(dimensions = 1) private byte[] variableTypes;
510510

511+
/*
512+
* When instrumentation is in use, InstrumentationSupport#bciToHelper node is used instead of
513+
* this array. Use getChildNodes() to get the right array.
514+
*/
511515
@Children private final Node[] adoptedNodes;
512516
@Child private CalleeContext calleeContext = CalleeContext.create();
513517
@Child private PythonObjectFactory factory = PythonObjectFactory.create();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentationRoot.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
import com.oracle.truffle.api.instrumentation.StandardTags;
4646
import com.oracle.truffle.api.instrumentation.Tag;
4747

48+
/**
49+
* Takes care of lazily materializing the instrumentation nodes when requested. Also its wrapper is
50+
* notified of entering and exiting the function.
51+
*
52+
* @see InstrumentationSupport
53+
*/
4854
@GenerateWrapper
4955
public abstract class InstrumentationRoot extends InstrumentedBytecodeNode {
5056
public static InstrumentationRoot create() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentationRootImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
import com.oracle.truffle.api.instrumentation.Tag;
4949
import com.oracle.truffle.api.source.SourceSection;
5050

51+
/**
52+
* @see InstrumentationRoot
53+
* @see InstrumentationSupport
54+
*/
5155
class InstrumentationRootImpl extends InstrumentationRoot {
5256

5357
@Child private volatile InstrumentationSupport instrumentationSupport;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentationSupport.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,24 @@
5252
import com.oracle.truffle.api.instrumentation.ProbeNode;
5353
import com.oracle.truffle.api.nodes.Node;
5454

55+
/**
56+
* The bytecode interpreter has no AST nodes therefore Truffle AST instrumentation doesn't directly
57+
* work. We work around that by lazily creating a fake non-executable AST with a list of statement
58+
* nodes. We keep track of line changes in the bytecode loop and notify the probe nodes manually. We
59+
* also insert bytecode helper nodes into the statement nodes so that asking the location of a call
60+
* node obtained from a frame works.
61+
*
62+
* @see InstrumentationRoot
63+
*/
5564
public final class InstrumentationSupport extends Node {
5665
final CodeUnit code;
5766
@Children InstrumentedBytecodeStatement[] lineToNode;
67+
/*
68+
* When instrumentation is active, this array is used instead of PBytecodeRootNode#adoptedNodes
69+
* to hold helper nodes. The actual helper nodes are adopted by the statement nodes in
70+
* lineToNode, so this must not be annotated as @Children. When materializing, we cannot reuse
71+
* existing nodes from adoptedNodes due to possible race conditions.
72+
*/
5873
@CompilationFinal(dimensions = 1) public Node[] bciToHelperNode;
5974

6075
public InstrumentationSupport(PBytecodeRootNode rootNode) {

0 commit comments

Comments
 (0)