63
63
*/
64
64
public final class InstrumentationSupport extends Node {
65
65
final CodeUnit code ;
66
- @ Children InstrumentedBytecodeStatement [] lineToNode ;
66
+ @ Children InstrumentedBytecodeStatement [] statements ;
67
67
/*
68
68
* When instrumentation is active, this array is used instead of PBytecodeRootNode#adoptedNodes
69
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.
70
+ * statements array , so this must not be annotated as @Children. When materializing, we cannot
71
+ * reuse existing nodes from adoptedNodes due to possible race conditions.
72
72
*/
73
73
@ CompilationFinal (dimensions = 1 ) public Node [] bciToHelperNode ;
74
74
75
75
public InstrumentationSupport (PBytecodeRootNode rootNode ) {
76
76
assert rootNode .getSource () != null && rootNode .getSource ().hasCharacters ();
77
77
code = rootNode .getCodeUnit ();
78
- lineToNode = new InstrumentedBytecodeStatement [code .endLine + 1 ];
78
+ statements = new InstrumentedBytecodeStatement [code .endLine - code . startLine + 1 ];
79
79
bciToHelperNode = new Node [code .code .length ];
80
80
boolean [] loadedBreakpoint = new boolean [1 ];
81
81
code .iterateBytecode ((bci , op , oparg , followingArgs ) -> {
@@ -90,22 +90,35 @@ public InstrumentationSupport(PBytecodeRootNode rootNode) {
90
90
}
91
91
int line = code .bciToLine (bci );
92
92
if (line >= 0 ) {
93
- if (lineToNode [line ] == null ) {
94
- InstrumentedBytecodeStatement statement = InstrumentedBytecodeStatement .create ();
93
+ InstrumentedBytecodeStatement statement = getStatement (line );
94
+ if (statement == null ) {
95
+ statement = InstrumentedBytecodeStatement .create ();
95
96
statement .setSourceSection (rootNode .getSource ().createSection (line ));
96
- lineToNode [ line ] = statement ;
97
+ setStatement ( line , statement ) ;
97
98
}
98
- lineToNode [ line ] .coversBci (bci , op .length ());
99
+ statement .coversBci (bci , op .length ());
99
100
if (setBreakpoint ) {
100
- lineToNode [ line ] .setContainsBreakpoint ();
101
+ statement .setContainsBreakpoint ();
101
102
}
102
103
}
103
104
});
104
105
}
105
106
107
+ private InstrumentedBytecodeStatement getStatement (int line ) {
108
+ return statements [getStatementIndex (line )];
109
+ }
110
+
111
+ private void setStatement (int line , InstrumentedBytecodeStatement statement ) {
112
+ statements [getStatementIndex (line )] = statement ;
113
+ }
114
+
115
+ private int getStatementIndex (int line ) {
116
+ return line - code .startLine ;
117
+ }
118
+
106
119
private InstrumentableNode .WrapperNode getWrapperAtLine (int line ) {
107
- if (line >= 0 && line < lineToNode . length ) {
108
- InstrumentableNode node = lineToNode [ line ] ;
120
+ if (line >= 0 ) {
121
+ InstrumentableNode node = getStatement ( line ) ;
109
122
if (node instanceof InstrumentableNode .WrapperNode ) {
110
123
return (InstrumentableNode .WrapperNode ) node ;
111
124
}
@@ -167,7 +180,7 @@ public void notifyException(VirtualFrame frame, int line, Throwable exception) {
167
180
168
181
public void insertHelperNode (Node node , int bci ) {
169
182
int line = code .bciToLine (bci );
170
- lineToNode [ line ] .insertHelperNode (node , bci );
183
+ getStatement ( line ) .insertHelperNode (node , bci );
171
184
bciToHelperNode [bci ] = node ;
172
185
}
173
186
}
0 commit comments