Skip to content

Commit f4d085a

Browse files
otethalsteve-s
authored andcommitted
Resolve Truffle DSL warnings, optimize AST footprint, tune hosted inlining heuristics
Among other things: * remove deprecated IsBuiltinClassProfile * unify GetClassNode and InlinedGetClassNode into GetClassNode * unify InlinedIsSameTypeNode and IsSameTypeNode to IsSameTypeNode
1 parent d4c5774 commit f4d085a

File tree

716 files changed

+14060
-15561
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

716 files changed

+14060
-15561
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/nodes/util/CastToJavaUnsignedLongNodeTests.java

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@
5656
import com.oracle.graal.python.runtime.exception.PException;
5757
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
5858
import com.oracle.graal.python.test.PythonTests;
59-
import com.oracle.truffle.api.frame.VirtualFrame;
60-
import com.oracle.truffle.api.nodes.RootNode;
6159

6260
public class CastToJavaUnsignedLongNodeTests {
6361
private static PythonObjectFactory factory = PythonObjectFactory.getUncached();
@@ -145,35 +143,14 @@ private static void expect(PythonBuiltinClassType errorType, Runnable test) {
145143
}
146144

147145
private static long castInt(int arg) {
148-
return (Long) new RootNode(null) {
149-
@Child private CastToJavaUnsignedLongNode castNode = CastToJavaUnsignedLongNode.create();
150-
151-
@Override
152-
public Object execute(VirtualFrame frame) {
153-
return castNode.execute(arg);
154-
}
155-
}.getCallTarget().call();
146+
return CastToJavaUnsignedLongNode.executeUncached(arg);
156147
}
157148

158149
private static long castLong(long arg) {
159-
return (Long) new RootNode(null) {
160-
@Child private CastToJavaUnsignedLongNode castNode = CastToJavaUnsignedLongNode.create();
161-
162-
@Override
163-
public Object execute(VirtualFrame frame) {
164-
return castNode.execute(arg);
165-
}
166-
}.getCallTarget().call();
150+
return CastToJavaUnsignedLongNode.executeUncached(arg);
167151
}
168152

169153
private static long castObject(Object arg) {
170-
return (Long) new RootNode(null) {
171-
@Child private CastToJavaUnsignedLongNode castNode = CastToJavaUnsignedLongNode.create();
172-
173-
@Override
174-
public Object execute(VirtualFrame frame) {
175-
return castNode.execute(arg);
176-
}
177-
}.getCallTarget().call();
154+
return CastToJavaUnsignedLongNode.executeUncached(arg);
178155
}
179156
}

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/nodes/util/NarrowBigIntegerNodeTests.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -63,8 +63,6 @@ public void tearDown() {
6363
PythonTests.closeContext();
6464
}
6565

66-
private static NarrowBigIntegerNode narrow = NarrowBigIntegerNodeGen.getUncached();
67-
6866
@Test
6967
public void smallInts() {
7068
expectInt(-2);
@@ -108,19 +106,19 @@ public void longPIntBoundary() {
108106
}
109107

110108
private static void expectInt(int expected) {
111-
Object actual = narrow.execute(BigInteger.valueOf(expected));
109+
Object actual = NarrowBigIntegerNode.executeUncached(BigInteger.valueOf(expected));
112110
Assert.assertTrue(actual instanceof Integer);
113111
Assert.assertEquals(expected, (int) actual);
114112
}
115113

116114
private static void expectLong(long expected) {
117-
Object actual = narrow.execute(BigInteger.valueOf(expected));
115+
Object actual = NarrowBigIntegerNode.executeUncached(BigInteger.valueOf(expected));
118116
Assert.assertTrue(actual instanceof Long);
119117
Assert.assertEquals(expected, (long) actual);
120118
}
121119

122120
private static void expectPInt(BigInteger expected) {
123-
Object actual = narrow.execute(expected);
121+
Object actual = NarrowBigIntegerNode.executeUncached(expected);
124122
Assert.assertTrue(actual instanceof PInt);
125123
Assert.assertEquals(expected, ((PInt) actual).getValue());
126124
}

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/nodes/util/PyObjectLookupAttrTests.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -41,20 +41,20 @@
4141

4242
package com.oracle.graal.python.nodes.util;
4343

44-
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
45-
import com.oracle.graal.python.builtins.objects.PNone;
46-
import com.oracle.graal.python.lib.PyObjectLookupAttr;
47-
import com.oracle.truffle.api.frame.VirtualFrame;
48-
import com.oracle.truffle.api.nodes.Node;
49-
import com.oracle.truffle.api.nodes.RootNode;
44+
import static com.oracle.graal.python.util.PythonUtils.tsLiteral;
45+
5046
import org.junit.After;
5147
import org.junit.Assert;
5248
import org.junit.Before;
5349
import org.junit.Test;
5450

51+
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
52+
import com.oracle.graal.python.builtins.objects.PNone;
53+
import com.oracle.graal.python.lib.PyObjectLookupAttr;
5554
import com.oracle.graal.python.test.PythonTests;
56-
57-
import static com.oracle.graal.python.util.PythonUtils.tsLiteral;
55+
import com.oracle.truffle.api.frame.VirtualFrame;
56+
import com.oracle.truffle.api.nodes.Node;
57+
import com.oracle.truffle.api.nodes.RootNode;
5858

5959
public class PyObjectLookupAttrTests {
6060

@@ -78,7 +78,7 @@ public void lookupThroughMRO() {
7878

7979
@Override
8080
public Object execute(VirtualFrame frame) {
81-
return lookupNode.execute(frame, PythonBuiltinClassType.Boolean, tsLiteral("real"));
81+
return lookupNode.executeCached(frame, PythonBuiltinClassType.Boolean, tsLiteral("real"));
8282
}
8383
}.getCallTarget().call();
8484
Assert.assertNotSame(PNone.NO_VALUE, v);

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/datatype/PRangeTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void loopWithOnlyStop() throws UnexpectedResultException {
6868
PRange range = factory.createIntRange(10);
6969
int index = 0;
7070
TestRoot testRoot = new TestRoot(PythonLanguage.get(factory));
71-
Object iter = PyObjectGetIter.getUncached().execute(null, range);
71+
Object iter = PyObjectGetIter.executeUncached(range);
7272
GetNextNode next = GetNextNode.create();
7373
testRoot.doInsert(next);
7474
IsBuiltinObjectProfile errorProfile = IsBuiltinObjectProfile.getUncached();
@@ -96,7 +96,7 @@ public void loopWithStep() throws UnexpectedResultException {
9696
PRange range = PythonObjectFactory.getUncached().createIntRange(0, 10, 2, 5);
9797
int index = 0;
9898
TestRoot testRoot = new TestRoot(PythonLanguage.get(factory));
99-
Object iter = PyObjectGetIter.getUncached().execute(null, range);
99+
Object iter = PyObjectGetIter.executeUncached(range);
100100
GetNextNode next = GetNextNode.create();
101101
testRoot.doInsert(next);
102102
IsBuiltinObjectProfile errorProfile = IsBuiltinObjectProfile.getUncached();

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/engine/SharedEngineMultithreadingTestBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -64,7 +64,7 @@
6464
*/
6565
public class SharedEngineMultithreadingTestBase extends PythonTests {
6666
// To increase the chances of hitting concurrency issues, we run each test repeatedly.
67-
protected static final int RUNS_COUNT_FACTOR = 4;
67+
protected static final int RUNS_COUNT_FACTOR = Integer.getInteger("com.oracle.graal.python.test.SharedEngineMultithreadingRunCountFactor", 4);
6868
protected static final int THREADS_COUNT = Runtime.getRuntime().availableProcessors();
6969
private static final boolean LOG = false;
7070

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/objects/ObjectHashMapTests.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,18 @@
5757

5858
import com.oracle.graal.python.builtins.objects.common.EconomicMapStorage;
5959
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
60+
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageForEach;
6061
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageForEachCallback;
6162
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageGetIterator;
63+
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageGetReverseIterator;
6264
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageIterator;
6365
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageIteratorKey;
6466
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageIteratorNext;
65-
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodesFactory.HashingStorageForEachNodeGen;
66-
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodesFactory.HashingStorageGetReverseIteratorNodeGen;
6767
import com.oracle.graal.python.builtins.objects.common.ObjectHashMap;
6868
import com.oracle.graal.python.builtins.objects.common.ObjectHashMap.MapCursor;
6969
import com.oracle.graal.python.lib.PyObjectHashNode;
7070
import com.oracle.graal.python.lib.PyObjectRichCompareBool;
71+
import com.oracle.graal.python.lib.PyObjectRichCompareBool.Comparison;
7172
import com.oracle.truffle.api.frame.Frame;
7273
import com.oracle.truffle.api.interop.TruffleObject;
7374
import com.oracle.truffle.api.nodes.Node;
@@ -85,7 +86,7 @@ public static final class DictKey implements TruffleObject {
8586

8687
private static final class EqNodeStub extends PyObjectRichCompareBool.EqNode {
8788
@Override
88-
public boolean execute(Frame frame, Object a, Object b) {
89+
protected boolean execute(Frame frame, Node inliningTarget, Object a, Object b, Comparison cmp) {
8990
// Sanity check: we do not use any other keys in the tests
9091
assert a instanceof Long || a instanceof DictKey;
9192
assert b instanceof Long || b instanceof DictKey;
@@ -295,7 +296,7 @@ static <T> void assertEqual(String message, LinkedHashMap<T, Object> expected, O
295296

296297
EconomicMapStorage storage = new EconomicMapStorage(actual, false);
297298
int[] size = new int[]{0};
298-
HashingStorageForEachNodeGen.getUncached().execute(null, storage, new HashingStorageForEachCallback<>() {
299+
HashingStorageForEach.executeUncached(storage, new HashingStorageForEachCallback<>() {
299300
@Override
300301
public Object execute(Frame frame, Node inliningTarget, HashingStorage s, HashingStorageIterator cbIt, Object accumulator) {
301302
Object key = HashingStorageIteratorKey.executeUncached(s, cbIt);
@@ -314,7 +315,7 @@ private static Object[] keysToArray(ObjectHashMap m) {
314315

315316
private static Object[] reverseKeysToArray(ObjectHashMap m) {
316317
EconomicMapStorage s = new EconomicMapStorage(m, false);
317-
return iteratorToArray(s, HashingStorageGetReverseIteratorNodeGen.getUncached().execute(s));
318+
return iteratorToArray(s, HashingStorageGetReverseIterator.executeUncached(s));
318319
}
319320

320321
private static Object[] iteratorToArray(HashingStorage s, HashingStorageIterator it) {
@@ -337,23 +338,23 @@ private static long getKeyHash(Object key) {
337338

338339
private static Object get(ObjectHashMap map, Object key, long hash) {
339340
InlinedCountingConditionProfile uncachedCounting = InlinedCountingConditionProfile.getUncached();
340-
return ObjectHashMap.GetNode.doGetWithRestart(null, map, key, hash,
341-
null, InlinedBranchProfile.getUncached(), uncachedCounting, uncachedCounting, uncachedCounting,
341+
return ObjectHashMap.GetNode.doGetWithRestart(null, null, map, key, hash,
342+
InlinedBranchProfile.getUncached(), uncachedCounting, uncachedCounting, uncachedCounting,
342343
uncachedCounting, uncachedCounting,
343344
new EqNodeStub());
344345
}
345346

346347
private static void remove(ObjectHashMap map, Object key, long hash) {
347348
InlinedCountingConditionProfile uncachedCounting = InlinedCountingConditionProfile.getUncached();
348-
ObjectHashMap.RemoveNode.doRemoveWithRestart(null, map, key, hash,
349-
null, InlinedBranchProfile.getUncached(), uncachedCounting, uncachedCounting, uncachedCounting,
349+
ObjectHashMap.RemoveNode.doRemoveWithRestart(null, null, map, key, hash,
350+
InlinedBranchProfile.getUncached(), uncachedCounting, uncachedCounting, uncachedCounting,
350351
uncachedCounting, InlinedBranchProfile.getUncached(), new EqNodeStub());
351352
}
352353

353354
private static void put(ObjectHashMap map, Object key, long hash, Object value) {
354355
InlinedCountingConditionProfile uncachedCounting = InlinedCountingConditionProfile.getUncached();
355-
ObjectHashMap.PutNode.doPutWithRestart(null, map, key, hash, value,
356-
null, InlinedBranchProfile.getUncached(), uncachedCounting, uncachedCounting, uncachedCounting,
356+
ObjectHashMap.PutNode.doPutWithRestart(null, null, map, key, hash, value,
357+
InlinedBranchProfile.getUncached(), uncachedCounting, uncachedCounting, uncachedCounting,
357358
uncachedCounting, InlinedBranchProfile.getUncached(), InlinedBranchProfile.getUncached(),
358359
new EqNodeStub());
359360
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ public Object execute(VirtualFrame frame) {
694694
Object[] arguments = PArguments.create();
695695
// escape?
696696
PFrame pFrame = materializeFrameNode.execute(this, false, true, frame);
697-
Object pLocals = getFrameLocalsNode.execute(pFrame);
697+
Object pLocals = getFrameLocalsNode.executeCached(pFrame);
698698
PArguments.setSpecialArgument(arguments, pLocals);
699699
PArguments.setGlobals(arguments, PArguments.getGlobals(frame));
700700
boolean wasAcquired = gilNode.acquire();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -875,22 +875,22 @@ private void initializeImportlib() {
875875
loadFile(toTruffleStringUncached("importlib/_bootstrap"), getContext().getStdlibHome(), bootstrap);
876876
} else {
877877
bootstrapExternal = ImpModuleBuiltins.importFrozenModuleObject(this, T__FROZEN_IMPORTLIB_EXTERNAL, true);
878-
setItem.execute(null, sysModules, T_IMPORTLIB_BOOTSTRAP, bootstrap);
879-
setItem.execute(null, sysModules, T_IMPORTLIB_BOOTSTRAP_EXTERNAL, bootstrapExternal);
878+
setItem.execute(null, null, sysModules, T_IMPORTLIB_BOOTSTRAP, bootstrap);
879+
setItem.execute(null, null, sysModules, T_IMPORTLIB_BOOTSTRAP_EXTERNAL, bootstrapExternal);
880880
LOGGER.log(Level.FINE, () -> "import '" + T__FROZEN_IMPORTLIB + "' # <frozen>");
881881
LOGGER.log(Level.FINE, () -> "import '" + T__FROZEN_IMPORTLIB_EXTERNAL + "' # <frozen>");
882882
}
883-
setItem.execute(null, sysModules, T__FROZEN_IMPORTLIB, bootstrap);
884-
setItem.execute(null, sysModules, T__FROZEN_IMPORTLIB_EXTERNAL, bootstrapExternal);
883+
setItem.execute(null, null, sysModules, T__FROZEN_IMPORTLIB, bootstrap);
884+
setItem.execute(null, null, sysModules, T__FROZEN_IMPORTLIB_EXTERNAL, bootstrapExternal);
885885

886886
// __package__ needs to be set and doesn't get set by _bootstrap setup
887887
writeNode.execute(bootstrap, T___PACKAGE__, T_IMPORTLIB);
888888
writeNode.execute(bootstrapExternal, T___PACKAGE__, T_IMPORTLIB);
889889

890-
callNode.execute(null, bootstrap, toTruffleStringUncached("_install"), getSysModule(), lookupBuiltinModule(T__IMP));
890+
callNode.execute(null, null, bootstrap, toTruffleStringUncached("_install"), getSysModule(), lookupBuiltinModule(T__IMP));
891891
writeNode.execute(getBuiltins(), T___IMPORT__, readNode.execute(bootstrap, T___IMPORT__));
892892
// see CPython's init_importlib_external
893-
callNode.execute(null, bootstrap, toTruffleStringUncached("_install_external_importers"));
893+
callNode.execute(null, null, bootstrap, toTruffleStringUncached("_install_external_importers"));
894894
if (!PythonOptions.WITHOUT_COMPRESSION_LIBRARIES) {
895895
// see CPython's _PyImportZip_Init
896896
Object pathHooks = readNode.execute(sysModule, toTruffleStringUncached("path_hooks"));
@@ -911,7 +911,7 @@ private void initializeImportlib() {
911911
removeBuiltinModule(t_zipimport);
912912
}
913913
} else {
914-
setItem.execute(null, sysModules, t_zipimport, zipimport);
914+
setItem.execute(null, null, sysModules, t_zipimport, zipimport);
915915
LOGGER.log(Level.FINE, () -> "import 'zipimport' # <frozen>");
916916
}
917917
if (zipimport == null) {
@@ -1055,7 +1055,7 @@ public final PFunction getImportFunc() {
10551055
*/
10561056
public final Object getStderr() {
10571057
try {
1058-
return PyObjectLookupAttr.getUncached().execute(null, sysModule, T_STDERR);
1058+
return PyObjectLookupAttr.executeUncached(sysModule, T_STDERR);
10591059
} catch (PException e) {
10601060
try {
10611061
getContext().getEnv().err().write("lost sys.stderr\n".getBytes());

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonOS.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -40,11 +40,11 @@
4040
*/
4141
package com.oracle.graal.python.builtins;
4242

43+
import static com.oracle.graal.python.util.PythonUtils.toTruffleStringUncached;
44+
4345
import com.oracle.truffle.api.CompilerDirectives;
4446
import com.oracle.truffle.api.strings.TruffleString;
4547

46-
import static com.oracle.graal.python.util.PythonUtils.toTruffleStringUncached;
47-
4848
public enum PythonOS {
4949
PLATFORM_JAVA("java"),
5050
PLATFORM_CYGWIN("cygwin"),

0 commit comments

Comments
 (0)