Skip to content

Commit 9938e94

Browse files
committed
[GR-26641] Fix two invalid usage of identity profiles in multi-context mode
PullRequest: graalpython/1402
2 parents 5d18662 + 01fe6c5 commit 9938e94

File tree

4 files changed

+42
-21
lines changed

4 files changed

+42
-21
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/advance/LeakTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ private MBeanServer doFullGC() {
185185
// do this a few times to dump a small heap if we can
186186
MBeanServer server = null;
187187
for (int i = 0; i < 10; i++) {
188+
try {
189+
Thread.sleep(1000);
190+
} catch (InterruptedException e1) {
191+
// do nothing
192+
}
188193
System.gc();
189194
Runtime.getRuntime().freeMemory();
190195
server = ManagementFactory.getPlatformMBeanServer();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,28 +2104,39 @@ public TriState isIdenticalOrUndefined(Object other,
21042104
* {@code tp_iter} for every user class.
21052105
*/
21062106
@ExportMessage
2107-
public Object getIteratorWithState(ThreadState state,
2108-
@Cached("createIdentityProfile()") ValueProfile iterMethodProfile,
2109-
@CachedLibrary("this") PythonObjectLibrary plib,
2110-
@CachedLibrary(limit = "2") PythonObjectLibrary methodLib,
2111-
@Cached IteratorNodes.IsIteratorObjectNode isIteratorObjectNode,
2112-
@Cached PythonObjectFactory factory,
2113-
@Shared("raise") @Cached PRaiseNode raise) {
2114-
Object v = plib.getDelegatedValue(this);
2115-
Object iterMethod = iterMethodProfile.profile(plib.lookupAttributeOnType(this, __ITER__));
2116-
if (iterMethod != PNone.NONE) {
2117-
if (iterMethod != PNone.NO_VALUE) {
2118-
Object iterObj = methodLib.callUnboundMethodIgnoreGetExceptionWithState(iterMethod, state, v);
2119-
if (iterObj != PNone.NO_VALUE && isIteratorObjectNode.execute(iterObj)) {
2120-
return iterObj;
2121-
}
2107+
public static class GetIteratorWithState {
2108+
public static final ValueProfile createIterMethodProfile() {
2109+
if (singleContextAssumption().isValid()) {
2110+
return ValueProfile.createIdentityProfile();
21222111
} else {
2123-
Object getItemAttrObj = plib.lookupAttributeOnType(this, __GETITEM__);
2124-
if (getItemAttrObj != PNone.NO_VALUE) {
2125-
return factory.createSequenceIterator(v);
2112+
return ValueProfile.createClassProfile();
2113+
}
2114+
}
2115+
2116+
@Specialization
2117+
public static Object getIteratorWithState(PythonAbstractObject self, ThreadState state,
2118+
@Cached("createIterMethodProfile()") ValueProfile iterMethodProfile,
2119+
@CachedLibrary("self") PythonObjectLibrary plib,
2120+
@CachedLibrary(limit = "2") PythonObjectLibrary methodLib,
2121+
@Cached IteratorNodes.IsIteratorObjectNode isIteratorObjectNode,
2122+
@Cached PythonObjectFactory factory,
2123+
@Shared("raise") @Cached PRaiseNode raise) {
2124+
Object v = plib.getDelegatedValue(self);
2125+
Object iterMethod = iterMethodProfile.profile(plib.lookupAttributeOnType(self, __ITER__));
2126+
if (iterMethod != PNone.NONE) {
2127+
if (iterMethod != PNone.NO_VALUE) {
2128+
Object iterObj = methodLib.callUnboundMethodIgnoreGetExceptionWithState(iterMethod, state, v);
2129+
if (iterObj != PNone.NO_VALUE && isIteratorObjectNode.execute(iterObj)) {
2130+
return iterObj;
2131+
}
2132+
} else {
2133+
Object getItemAttrObj = plib.lookupAttributeOnType(self, __GETITEM__);
2134+
if (getItemAttrObj != PNone.NO_VALUE) {
2135+
return factory.createSequenceIterator(v);
2136+
}
21262137
}
21272138
}
2139+
throw raise.raise(PythonErrorType.TypeError, ErrorMessages.OBJ_NOT_ITERABLE, self);
21282140
}
2129-
throw raise.raise(PythonErrorType.TypeError, ErrorMessages.OBJ_NOT_ITERABLE, this);
21302141
}
21312142
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/WrapTpNew.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
*/
4141
package com.oracle.graal.python.nodes.function.builtins;
4242

43+
import com.oracle.graal.python.PythonLanguage;
4344
import com.oracle.graal.python.builtins.Builtin;
4445
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4546
import com.oracle.graal.python.builtins.objects.function.PArguments;
@@ -130,7 +131,11 @@ public Object execute(VirtualFrame frame) {
130131
if (newMethod instanceof PBuiltinFunction) {
131132
if (builtinProfile == null) {
132133
CompilerDirectives.transferToInterpreterAndInvalidate();
133-
builtinProfile = ValueProfile.createIdentityProfile();
134+
if (lookupLanguageReference(PythonLanguage.class).get().singleContextAssumption.isValid()) {
135+
builtinProfile = ValueProfile.createIdentityProfile();
136+
} else {
137+
builtinProfile = ValueProfile.getUncached();
138+
}
134139
}
135140
NodeFactory<? extends PythonBuiltinBaseNode> factory = ((PBuiltinFunction) builtinProfile.profile(newMethod)).getBuiltinNodeFactory();
136141
if (factory != null) {

mx.graalpython/mx_graalpython.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2014,7 +2014,7 @@ def run_leak_launcher(input_args, out=None):
20142014

20152015
vm_args, graalpython_args = mx.extract_VM_args(args, useDoubleDash=True, defaultAllVMArgs=False)
20162016
vm_args += mx.get_runtime_jvm_args(dists)
2017-
jdk = mx.get_jdk(tag=None)
2017+
jdk = get_jdk()
20182018
vm_args.append("com.oracle.graal.python.test.advance.LeakTest")
20192019
retval = mx.run_java(vm_args + graalpython_args, jdk=jdk, env=env, nonZeroIsFatal=False, out=out)
20202020
if retval == 0:

0 commit comments

Comments
 (0)