Skip to content

Commit 5fc1798

Browse files
committed
make singleton pointers constant as soon as we have them
1 parent 470dfe5 commit 5fc1798

File tree

1 file changed

+22
-5
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext

1 file changed

+22
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/CExtNodes.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,12 +1694,29 @@ public abstract static class GetSpecialSingletonPtrNode extends Node {
16941694

16951695
public abstract Object execute(Object obj);
16961696

1697-
@Specialization
1698-
Object doGeneric(Object obj,
1697+
protected static Assumption singleContextAssumption() {
1698+
return PythonLanguage.getCurrent().singleContextAssumption;
1699+
}
1700+
1701+
// n.b.: since we guard that there is a pointer, we can be sure that
1702+
// this is a singleton and we can cache it directly
1703+
@Specialization(guards = {"cachedObj == obj", "ptr != null"}, assumptions = "singleContextAssumption()")
1704+
@SuppressWarnings("unused")
1705+
Object doCached(PythonAbstractObject obj,
1706+
@CachedContext(PythonLanguage.class) PythonContext context,
1707+
@Cached("obj") PythonAbstractObject cachedObj,
1708+
@Cached("context.getSingletonNativePtr(cachedObj)") Object ptr) {
1709+
return ptr;
1710+
}
1711+
1712+
@Specialization(replaces = "doCached")
1713+
Object doAbstract(PythonAbstractObject obj,
16991714
@CachedContext(PythonLanguage.class) PythonContext context) {
1700-
if (obj instanceof PythonAbstractObject) {
1701-
return context.getSingletonNativePtr((PythonAbstractObject) obj);
1702-
}
1715+
return context.getSingletonNativePtr(obj);
1716+
}
1717+
1718+
@Fallback
1719+
Object doGeneric(@SuppressWarnings("unused") Object obj) {
17031720
return null;
17041721
}
17051722
}

0 commit comments

Comments
 (0)