Skip to content

Commit 016af72

Browse files
committed
Fix memory leaks
1 parent 2742c41 commit 016af72

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SREModuleBuiltins.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
import com.oracle.graal.python.nodes.PNodeWithContext;
7979
import com.oracle.graal.python.nodes.PRaiseNode;
8080
import com.oracle.graal.python.nodes.attributes.GetAttributeNode;
81+
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
8182
import com.oracle.graal.python.nodes.call.CallNode;
8283
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
8384
import com.oracle.graal.python.nodes.function.builtins.PythonSenaryBuiltinNode;
@@ -595,15 +596,15 @@ abstract static class CreateMatchFromTRegexResultNode extends PNodeWithContext {
595596

596597
@Specialization
597598
static Object createMatch(VirtualFrame frame, Node inliningTarget, Object pattern, int pos, int endPos, Object regexResult, Object input,
598-
@Cached("lookupMatchConstructor()") Object matchConstructor,
599+
@Cached GetMatchConstructorNode getConstructor,
599600
@Cached InlinedConditionProfile matchProfile,
600601
@CachedLibrary(limit = "1") InteropLibrary libResult,
601602
@Cached PyObjectLookupAttr lookupIndexGroupNode,
602603
@Cached(inline = false) CallNode constructResultNode) {
603604
try {
604605
if (matchProfile.profile(inliningTarget, (boolean) libResult.readMember(regexResult, "isMatch"))) {
605606
Object indexGroup = lookupIndexGroupNode.execute(frame, inliningTarget, pattern, T__PATTERN__INDEXGROUP);
606-
return constructResultNode.execute(frame, matchConstructor, pattern, pos, endPos, regexResult, input, indexGroup);
607+
return constructResultNode.execute(frame, getConstructor.execute(inliningTarget), pattern, pos, endPos, regexResult, input, indexGroup);
607608
} else {
608609
return PNone.NONE;
609610
}
@@ -612,11 +613,31 @@ static Object createMatch(VirtualFrame frame, Node inliningTarget, Object patter
612613
}
613614
}
614615

615-
@TruffleBoundary
616-
@NeverDefault
617-
protected Object lookupMatchConstructor() {
618-
PythonModule module = getContext().lookupBuiltinModule(BuiltinNames.T__SRE);
619-
return PyObjectLookupAttr.executeUncached(module, T_MATCH_CONSTRUCTOR);
616+
@GenerateInline
617+
@GenerateCached(false)
618+
abstract static class GetMatchConstructorNode extends PNodeWithContext {
619+
public abstract Object execute(Node inliningTarget);
620+
621+
@Specialization(guards = "isSingleContext()")
622+
static Object doSingleContext(
623+
@Cached("lookupMatchConstructor()") Object constructor) {
624+
return constructor;
625+
}
626+
627+
@Specialization(replaces = "doSingleContext")
628+
static Object doRead(
629+
@Bind PythonContext context,
630+
@Cached ReadAttributeFromObjectNode read) {
631+
PythonModule module = context.lookupBuiltinModule(BuiltinNames.T__SRE);
632+
return read.execute(module, T_MATCH_CONSTRUCTOR);
633+
}
634+
635+
@TruffleBoundary
636+
@NeverDefault
637+
protected static Object lookupMatchConstructor() {
638+
PythonModule module = PythonContext.get(null).lookupBuiltinModule(BuiltinNames.T__SRE);
639+
return PyObjectLookupAttr.executeUncached(module, T_MATCH_CONSTRUCTOR);
640+
}
620641
}
621642
}
622643

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/CallDispatchers.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ static Object callBuiltinFunctionCached(VirtualFrame frame, Node inliningTarget,
188188

189189
@Specialization(guards = "sameCallTarget(callee.getCallTarget(), callNode)", limit = "getCallSiteInlineCacheMaxDepth()")
190190
static Object callBuiltinFunctionCachedCt(VirtualFrame frame, Node inliningTarget, @SuppressWarnings("unused") PBuiltinFunction callee, Object[] arguments,
191-
@SuppressWarnings("unused") @Cached("callee") PBuiltinFunction cachedCallee,
192191
@Cached("createDirectCallNodeFor(callee)") DirectCallNode callNode,
193192
@Cached SimpleDirectInvokeNode invoke) {
194193
return invoke.execute(frame, inliningTarget, callNode, arguments);
@@ -254,7 +253,7 @@ public abstract static class FunctionInvokeNode extends PNodeWithContext {
254253
// We only have a single context and this function never changed its code
255254
@Specialization(guards = {"isSingleContext()", "callee == cachedCallee"}, limit = "getCallSiteInlineCacheMaxDepth()", assumptions = "cachedCallee.getCodeStableAssumption()")
256255
static Object callFunctionCached(VirtualFrame frame, Node inliningTarget, @SuppressWarnings("unused") PFunction callee, Object[] arguments,
257-
@SuppressWarnings("unused") @Cached("callee") PFunction cachedCallee,
256+
@SuppressWarnings("unused") @Cached(value = "callee", weak = true) PFunction cachedCallee,
258257
@Cached("createDirectCallNodeFor(callee)") DirectCallNode callNode,
259258
@Cached FunctionDirectInvokeNode invoke) {
260259
return invoke.execute(frame, inliningTarget, callNode, cachedCallee, arguments);

0 commit comments

Comments
 (0)