Skip to content

Commit d3c89a5

Browse files
committed
Don't leak this in PBytecodeRootNode constructor
1 parent aee0431 commit d3c89a5

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ private CallTarget parseForBytecodeInterpreter(ParsingRequest request) {
496496
if (internal && !source.isInternal()) {
497497
source = Source.newBuilder(source).internal(true).build();
498498
}
499-
PBytecodeRootNode rootNode = new PBytecodeRootNode(this, code, source, null);
499+
PBytecodeRootNode rootNode = PBytecodeRootNode.create(this, code, source);
500500
return PythonUtils.getOrCreateCallTarget(rootNode);
501501
}
502502
for (int optimize = 0; optimize < MIME_TYPE_EVAL.length; optimize++) {
@@ -533,7 +533,7 @@ public RootCallTarget parseForBytecodeInterpreter(PythonContext context, Source
533533
}
534534
CompilationUnit cu = compiler.compile(mod, EnumSet.noneOf(Compiler.Flags.class), optimize);
535535
CodeUnit co = cu.assemble();
536-
RootNode rootNode = new PBytecodeRootNode(this, co, source, errorCb);
536+
RootNode rootNode = PBytecodeRootNode.create(this, co, source, errorCb);
537537
GilNode gil = GilNode.getUncached();
538538
boolean wasAcquired = gil.acquire(context, rootNode);
539539
if (topLevel) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private RootCallTarget deserializeForBytecodeInterpreter(PythonLanguage language
152152
code.outputCanQuicken, code.variableShouldUnbox,
153153
code.generalizeInputsMap, code.generalizeVarsMap);
154154
}
155-
RootNode rootNode = new PBytecodeRootNode(language, code, null, null);
155+
RootNode rootNode = PBytecodeRootNode.create(language, code, null);
156156
if (code.isGeneratorOrCoroutine()) {
157157
rootNode = new PBytecodeGeneratorFunctionRootNode(language, rootNode.getFrameDescriptor(), (PBytecodeRootNode) rootNode, code.name);
158158
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ private static Object convertConstantToPythonSpace(RootNode rootNode, Object o)
614614
PythonObjectFactory factory = PythonObjectFactory.getUncached();
615615
if (o instanceof CodeUnit) {
616616
CodeUnit code = ((CodeUnit) o);
617-
PBytecodeRootNode bytecodeRootNode = new PBytecodeRootNode(PythonLanguage.get(rootNode), code, getSourceSection(rootNode).getSource(), null);
617+
PBytecodeRootNode bytecodeRootNode = PBytecodeRootNode.create(PythonLanguage.get(rootNode), code, getSourceSection(rootNode).getSource());
618618
return factory.createCode(bytecodeRootNode.getCallTarget(), bytecodeRootNode.getSignature(), code);
619619
} else if (o instanceof BigInteger) {
620620
return factory.createInt((BigInteger) o);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ int makeFunction(VirtualFrame frame, Object globals, int initialStackTop, int fl
144144

145145
public static MakeFunctionNode create(PythonLanguage language, CodeUnit code, Source source) {
146146
RootCallTarget callTarget;
147-
PBytecodeRootNode bytecodeRootNode = new PBytecodeRootNode(language, code, source, null);
147+
PBytecodeRootNode bytecodeRootNode = PBytecodeRootNode.create(language, code, source);
148148
if (code.isGeneratorOrCoroutine()) {
149149
// TODO what should the frameDescriptor be? does it matter?
150150
callTarget = new PBytecodeGeneratorFunctionRootNode(language, bytecodeRootNode.getFrameDescriptor(), bytecodeRootNode, code.name).getCallTarget();

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,10 @@ public final class PBytecodeRootNode extends PRootNode implements BytecodeOSRNod
493493
@CompilationFinal private boolean usingCachedNodes;
494494
@CompilationFinal(dimensions = 1) private int[] conditionProfiles;
495495

496-
private static FrameDescriptor makeFrameDescriptor(CodeUnit co) {
496+
private static FrameDescriptor makeFrameDescriptor(CodeUnit co, FrameInfo info) {
497497
int capacity = co.varnames.length + co.cellvars.length + co.freevars.length + co.stacksize + 1;
498498
FrameDescriptor.Builder newBuilder = FrameDescriptor.newBuilder(capacity);
499-
newBuilder.info(new FrameInfo());
499+
newBuilder.info(info);
500500
// locals
501501
for (int i = 0; i < co.varnames.length; i++) {
502502
TruffleString varname = co.varnames[i];
@@ -544,14 +544,22 @@ private static Signature makeSignature(CodeUnit co) {
544544
}
545545

546546
@TruffleBoundary
547-
public PBytecodeRootNode(TruffleLanguage<?> language, CodeUnit co, Source source, RaisePythonExceptionErrorCallback parserErrorCallback) {
548-
this(language, makeFrameDescriptor(co), makeSignature(co), co, source, parserErrorCallback);
547+
public static PBytecodeRootNode create(TruffleLanguage<?> language, CodeUnit co, Source source) {
548+
return create(language, co, source, null);
549549
}
550550

551551
@TruffleBoundary
552-
public PBytecodeRootNode(TruffleLanguage<?> language, FrameDescriptor fd, Signature sign, CodeUnit co, Source source, RaisePythonExceptionErrorCallback parserErrorCallback) {
552+
public static PBytecodeRootNode create(TruffleLanguage<?> language, CodeUnit co, Source source, RaisePythonExceptionErrorCallback parserErrorCallback) {
553+
FrameInfo frameInfo = new FrameInfo();
554+
FrameDescriptor fd = makeFrameDescriptor(co, frameInfo);
555+
PBytecodeRootNode rootNode = new PBytecodeRootNode(language, fd, makeSignature(co), co, source, parserErrorCallback);
556+
frameInfo.rootNode = rootNode;
557+
return rootNode;
558+
}
559+
560+
@TruffleBoundary
561+
private PBytecodeRootNode(TruffleLanguage<?> language, FrameDescriptor fd, Signature sign, CodeUnit co, Source source, RaisePythonExceptionErrorCallback parserErrorCallback) {
553562
super(language, fd);
554-
((FrameInfo) fd.getInfo()).rootNode = this;
555563
this.celloffset = co.varnames.length;
556564
this.freeoffset = celloffset + co.cellvars.length;
557565
this.stackoffset = freeoffset + co.freevars.length;

0 commit comments

Comments
 (0)