Skip to content

Commit 63b1617

Browse files
committed
Save space in instrumention statement array
1 parent 06a62d3 commit 63b1617

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

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

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,19 @@
6363
*/
6464
public final class InstrumentationSupport extends Node {
6565
final CodeUnit code;
66-
@Children InstrumentedBytecodeStatement[] lineToNode;
66+
@Children InstrumentedBytecodeStatement[] statements;
6767
/*
6868
* When instrumentation is active, this array is used instead of PBytecodeRootNode#adoptedNodes
6969
* 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.
7272
*/
7373
@CompilationFinal(dimensions = 1) public Node[] bciToHelperNode;
7474

7575
public InstrumentationSupport(PBytecodeRootNode rootNode) {
7676
assert rootNode.getSource() != null && rootNode.getSource().hasCharacters();
7777
code = rootNode.getCodeUnit();
78-
lineToNode = new InstrumentedBytecodeStatement[code.endLine + 1];
78+
statements = new InstrumentedBytecodeStatement[code.endLine - code.startLine + 1];
7979
bciToHelperNode = new Node[code.code.length];
8080
boolean[] loadedBreakpoint = new boolean[1];
8181
code.iterateBytecode((bci, op, oparg, followingArgs) -> {
@@ -90,22 +90,35 @@ public InstrumentationSupport(PBytecodeRootNode rootNode) {
9090
}
9191
int line = code.bciToLine(bci);
9292
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();
9596
statement.setSourceSection(rootNode.getSource().createSection(line));
96-
lineToNode[line] = statement;
97+
setStatement(line, statement);
9798
}
98-
lineToNode[line].coversBci(bci, op.length());
99+
statement.coversBci(bci, op.length());
99100
if (setBreakpoint) {
100-
lineToNode[line].setContainsBreakpoint();
101+
statement.setContainsBreakpoint();
101102
}
102103
}
103104
});
104105
}
105106

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+
106119
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);
109122
if (node instanceof InstrumentableNode.WrapperNode) {
110123
return (InstrumentableNode.WrapperNode) node;
111124
}
@@ -167,7 +180,7 @@ public void notifyException(VirtualFrame frame, int line, Throwable exception) {
167180

168181
public void insertHelperNode(Node node, int bci) {
169182
int line = code.bciToLine(bci);
170-
lineToNode[line].insertHelperNode(node, bci);
183+
getStatement(line).insertHelperNode(node, bci);
171184
bciToHelperNode[bci] = node;
172185
}
173186
}

0 commit comments

Comments
 (0)