Skip to content

Commit 7d01470

Browse files
committed
Use fast identity check node in guards of 'LookupAttributeInMRONode'.
1 parent f2248cc commit 7d01470

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,15 +541,29 @@ private static PythonAbstractClass[] cast(Object[] arr) {
541541
@ImportStatic(SpecialMethodNames.class)
542542
public abstract static class IsSameTypeNode extends PNodeWithContext {
543543

544+
protected final boolean fastCheck;
545+
546+
public IsSameTypeNode(boolean fastCheck) {
547+
this.fastCheck = fastCheck;
548+
}
549+
544550
public abstract boolean execute(Object left, Object right);
545551

546552
@Specialization
547553
boolean doManaged(PythonManagedClass left, PythonManagedClass right) {
548554
return left == right;
549555
}
550556

551-
@Specialization
552-
boolean doNative(PythonAbstractNativeObject left, PythonAbstractNativeObject right,
557+
@Specialization(guards = "fastCheck")
558+
boolean doNativeFast(PythonAbstractNativeObject left, PythonAbstractNativeObject right) {
559+
// This check is a bit dangerous since we cannot be sure about the code that is running.
560+
// Currently, we assume that the pointer object is a Sulong pointer and for this it's
561+
// fine.
562+
return left.object.equals(right.object);
563+
}
564+
565+
@Specialization(guards = "!fastCheck")
566+
boolean doNativeSlow(PythonAbstractNativeObject left, PythonAbstractNativeObject right,
553567
@Cached("create(__EQ__)") CExtNodes.PointerCompareNode pointerCompareNode) {
554568
return pointerCompareNode.execute(left, right);
555569
}
@@ -570,7 +584,11 @@ public static boolean doSlowPath(Object left, Object right) {
570584
}
571585

572586
public static IsSameTypeNode create() {
573-
return IsSameTypeNodeGen.create();
587+
return IsSameTypeNodeGen.create(false);
588+
}
589+
590+
public static IsSameTypeNode createFast() {
591+
return IsSameTypeNodeGen.create(true);
574592
}
575593

576594
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/LookupAttributeInMRONode.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.oracle.graal.python.builtins.objects.PNone;
4545
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
4646
import com.oracle.graal.python.builtins.objects.type.PythonAbstractClass;
47+
import com.oracle.graal.python.builtins.objects.type.TypeNodes;
4748
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetMroNode;
4849
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetMroStorageNode;
4950
import com.oracle.graal.python.nodes.PNodeWithContext;
@@ -96,6 +97,7 @@ protected Object lookup(PythonAbstractClass klass, Object key,
9697
}
9798

9899
protected final String key;
100+
@Child private TypeNodes.IsSameTypeNode isSameTypeNode = TypeNodes.IsSameTypeNode.createFast();
99101
@Child private GetMroStorageNode getMroNode;
100102

101103
public LookupAttributeInMRONode(String key) {
@@ -168,7 +170,7 @@ protected PythonClassAssumptionPair findAttrClassAndAssumptionInMRO(PythonAbstra
168170
return new PythonClassAssumptionPair(attrAssumption, PNone.NO_VALUE);
169171
}
170172

171-
@Specialization(guards = {"klass == cachedKlass", "cachedClassInMROInfo != null"}, limit = "getIntOption(getContext(), AttributeAccessInlineCacheMaxDepth)", assumptions = {
173+
@Specialization(guards = {"isSameType(cachedKlass, klass)", "cachedClassInMROInfo != null"}, limit = "getIntOption(getContext(), AttributeAccessInlineCacheMaxDepth)", assumptions = {
172174
"cachedClassInMROInfo.assumption"})
173175
protected Object lookupConstantMROCached(@SuppressWarnings("unused") PythonAbstractClass klass,
174176
@Cached("klass") @SuppressWarnings("unused") PythonAbstractClass cachedKlass,
@@ -184,7 +186,7 @@ protected ReadAttributeFromObjectNode[] create(int size) {
184186
return nodes;
185187
}
186188

187-
@Specialization(guards = {"klass == cachedKlass", "mroLength < 32"}, limit = "getIntOption(getContext(), AttributeAccessInlineCacheMaxDepth)", assumptions = "lookupStable")
189+
@Specialization(guards = {"isSameType(cachedKlass, klass)", "mroLength < 32"}, limit = "getIntOption(getContext(), AttributeAccessInlineCacheMaxDepth)", assumptions = "lookupStable")
188190
@ExplodeLoop(kind = ExplodeLoop.LoopExplosionKind.FULL_EXPLODE_UNTIL_RETURN)
189191
protected Object lookupConstantMRO(@SuppressWarnings("unused") PythonAbstractClass klass,
190192
@Cached("klass") @SuppressWarnings("unused") PythonAbstractClass cachedKlass,
@@ -243,4 +245,8 @@ public static Object lookupSlow(LazyPythonClass klass, String key) {
243245
}
244246
return PNone.NO_VALUE;
245247
}
248+
249+
protected boolean isSameType(PythonAbstractClass cachedKlass, PythonAbstractClass klass) {
250+
return isSameTypeNode.execute(cachedKlass, klass);
251+
}
246252
}

0 commit comments

Comments
 (0)