Skip to content

Commit 6480427

Browse files
committed
Use explode loop limit >> depth instead of division, assert that dept is PE constant when passed as an argument
1 parent 3e13349 commit 6480427

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ Object doObject(Object value,
10431043
* provide the base for the recursion.
10441044
*/
10451045
public abstract static class RecursiveBinaryCheckBaseNode extends PythonBinaryBuiltinNode {
1046-
static final int MAX_EXPLODE_LOOP = 16; // is also divided by recursion depth+1
1046+
static final int MAX_EXPLODE_LOOP = 16; // is also shifted to the left by recursion depth
10471047
static final byte STOP_RECURSION = Byte.MAX_VALUE;
10481048

10491049
@Child private SequenceStorageNodes.LenNode lenNode;
@@ -1065,7 +1065,7 @@ protected RecursiveBinaryCheckBaseNode createRecursive(@SuppressWarnings("unused
10651065
}
10661066

10671067
protected int getMaxExplodeLoop() {
1068-
return MAX_EXPLODE_LOOP / (depth + 1);
1068+
return MAX_EXPLODE_LOOP >> depth;
10691069
}
10701070

10711071
@Specialization(guards = {"depth != STOP_RECURSION", "depth < getNodeRecursionLimit()", //

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,7 @@ public static GetInstanceShape create() {
15021502
@GenerateUncached
15031503
@ImportStatic(PythonOptions.class)
15041504
public abstract static class GetItemsizeNode extends Node {
1505-
// We cannot easily use options here
1505+
// We cannot easily use PythonOptions here (used on fast-path)
15061506
static final int MAX_RECURSION_DEPTH = 4;
15071507

15081508
public final long execute(Object cls) {
@@ -1522,12 +1522,13 @@ static long getItemsizeManaged(PythonBuiltinClass cls, @SuppressWarnings("unused
15221522
}
15231523

15241524
@Specialization(guards = "depth < MAX_RECURSION_DEPTH")
1525-
static long getItemsizeManagedRecursiveNode(PythonClass cls, @SuppressWarnings("unused") int depth,
1525+
static long getItemsizeManagedRecursiveNode(PythonClass cls, int depth,
15261526
@Shared("hasVal") @Cached ConditionProfile hasValueProfile,
15271527
@Shared("read") @Cached ReadAttributeFromObjectNode readNode,
15281528
@Shared("write") @Cached WriteAttributeToObjectNode writeNode,
15291529
@Shared("getBase") @Cached GetBaseClassNode getBaseNode,
15301530
@Cached GetItemsizeNode baseItemsizeNode) {
1531+
CompilerAsserts.partialEvaluationConstant(depth);
15311532
Object itemsize = readNode.execute(cls, TYPE_ITEMSIZE);
15321533
if (hasValueProfile.profile(itemsize != PNone.NO_VALUE)) {
15331534
return (long) itemsize;
@@ -1541,7 +1542,7 @@ static long getItemsizeManagedRecursiveNode(PythonClass cls, @SuppressWarnings("
15411542
}
15421543

15431544
@Specialization(guards = "depth >= MAX_RECURSION_DEPTH")
1544-
static long getItemsizeManagedRecursiveCall(PythonClass cls, @SuppressWarnings("unused") int depth,
1545+
static long getItemsizeManagedRecursiveCall(PythonClass cls, int depth,
15451546
@Shared("hasVal") @Cached ConditionProfile hasValueProfile,
15461547
@Shared("read") @Cached ReadAttributeFromObjectNode readNode,
15471548
@Shared("write") @Cached WriteAttributeToObjectNode writeNode,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/classes/AbstractObjectIsSubclassNode.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsSameTypeNode;
4747
import com.oracle.graal.python.nodes.PNodeWithContext;
4848
import com.oracle.graal.python.runtime.PythonOptions;
49+
import com.oracle.truffle.api.CompilerAsserts;
4950
import com.oracle.truffle.api.CompilerDirectives;
5051
import com.oracle.truffle.api.dsl.Cached;
5152
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -100,6 +101,7 @@ static boolean doSubclass(VirtualFrame frame, @SuppressWarnings("unused") Object
100101
@Cached AbstractObjectGetBasesNode getBasesNode,
101102
@Cached AbstractObjectIsSubclassNode isSubclassNode,
102103
@Cached GetObjectArrayNode getObjectArrayNode) {
104+
CompilerAsserts.partialEvaluationConstant(depth);
103105
PTuple bases = getBasesNode.execute(frame, cachedDerived);
104106
if (bases == null || isEmpty(bases, lenNode)) {
105107
return false;
@@ -110,7 +112,7 @@ static boolean doSubclass(VirtualFrame frame, @SuppressWarnings("unused") Object
110112
CompilerDirectives.transferToInterpreterAndInvalidate();
111113
observedSizeArray[0] = basesAry.length;
112114
}
113-
if (observedSizeArray[0] > 0 && observedSizeArray[0] < (32 / depth) && observedSizeArray[0] == basesAry.length) {
115+
if (observedSizeArray[0] > 0 && observedSizeArray[0] < (32 >> depth) && observedSizeArray[0] == basesAry.length) {
114116
// we observe a short constant size
115117
return loopBases(frame, cachedCls, basesAry, isSubclassNode, depth);
116118
} else if (observedSizeArray[0] > 0) {
@@ -147,6 +149,7 @@ static boolean doGeneric(VirtualFrame frame, Object derived, Object cls, int dep
147149
@Cached("createRecursive(depth)") AbstractObjectIsSubclassNode isSubclassNode,
148150
@Shared("isSameType") @Cached IsSameTypeNode isSameTypeNode,
149151
@Cached GetObjectArrayNode getObjectArrayNode) {
152+
CompilerAsserts.partialEvaluationConstant(depth);
150153
if (isSameMetaObject(isSameTypeNode, derived, cls)) {
151154
return true;
152155
}

0 commit comments

Comments
 (0)