Skip to content

Commit b7e2c5e

Browse files
committed
Do not materialize Python class flags for 'TO_NATIVE' MR.
1 parent 53fada3 commit b7e2c5e

File tree

2 files changed

+13
-43
lines changed

2 files changed

+13
-43
lines changed

graalpython/com.oracle.graal.python.cext/src/capi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ uint64_t PyTruffle_Wchar_Size() {
247247
return SIZEOF_WCHAR_T;
248248
}
249249

250-
void* PyObjectHandle_ForJavaObject(void* cobj, unsigned long flags) {
250+
void* PyObjectHandle_ForJavaObject(void* cobj) {
251251
if (truffle_cannot_be_handle(cobj)) {
252252
return truffle_deref_handle_for_managed(cobj);
253253
}

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

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import com.oracle.graal.python.builtins.objects.cext.NativeWrappers.PyUnicodeData;
6060
import com.oracle.graal.python.builtins.objects.cext.NativeWrappers.PyUnicodeState;
6161
import com.oracle.graal.python.builtins.objects.cext.NativeWrappers.PythonClassInitNativeWrapper;
62+
import com.oracle.graal.python.builtins.objects.cext.NativeWrappers.PythonClassNativeWrapper;
6263
import com.oracle.graal.python.builtins.objects.cext.NativeWrappers.PythonNativeWrapper;
6364
import com.oracle.graal.python.builtins.objects.cext.NativeWrappers.PythonObjectNativeWrapper;
6465
import com.oracle.graal.python.builtins.objects.cext.PythonObjectNativeWrapperMRFactory.PAsPointerNodeGen;
@@ -856,7 +857,7 @@ abstract static class ToNativeNode extends Node {
856857

857858
Object access(PythonClassInitNativeWrapper obj) {
858859
if (!pIsPointerNode.execute(obj)) {
859-
obj.setNativePointer(getToPyObjectNode().getHandleForObject(getMaterializeDelegateNode().execute(obj), 0));
860+
obj.setNativePointer(getToPyObjectNode().getHandleForObject(getMaterializeDelegateNode().execute(obj)));
860861
}
861862
return obj;
862863
}
@@ -999,7 +1000,7 @@ abstract static class PToNativeNode extends PNodeWithContext {
9991000
@Specialization
10001001
PythonNativeWrapper doInitClass(PythonClassInitNativeWrapper obj) {
10011002
if (!pIsPointerNode.execute(obj)) {
1002-
obj.setNativePointer(getToPyObjectNode().getHandleForObject(getMaterializeDelegateNode().execute(obj), 0));
1003+
obj.setNativePointer(getToPyObjectNode().getHandleForObject(getMaterializeDelegateNode().execute(obj)));
10031004
}
10041005
return obj;
10051006
}
@@ -1050,34 +1051,18 @@ abstract static class ToPyObjectNode extends CExtBaseNode {
10501051
@CompilationFinal private TruffleObject PyNoneHandle;
10511052
@Child private PCallNativeNode callNativeUnary;
10521053
@Child private PCallNativeNode callNativeBinary;
1053-
@Child private GetClassNode getClassNode;
10541054
@Child private CExtNodes.ToSulongNode toSulongNode;
10551055

1056-
public abstract Object execute(Object value);
1056+
public abstract Object execute(PythonNativeWrapper wrapper, Object value);
10571057

1058-
@Specialization
1059-
Object runNativeClass(PythonNativeClass object) {
1060-
return object.object;
1061-
}
1062-
1063-
@Specialization
1064-
Object runNativeObject(PythonNativeObject object) {
1065-
return object.object;
1066-
}
1067-
1068-
@Specialization(guards = "isManagedPythonClass(object)")
1069-
Object runClass(PythonClass object) {
1070-
return callUnaryIntoCapi(getPyObjectHandle_ForJavaType(), getToSulongNode().execute(object));
1058+
@Specialization(guards = "isManagedPythonClass(wrapper)")
1059+
Object doClass(PythonClassNativeWrapper wrapper, PythonClass object) {
1060+
return callUnaryIntoCapi(getPyObjectHandle_ForJavaType(), wrapper);
10711061
}
10721062

10731063
@Fallback
1074-
Object runObject(Object object) {
1075-
PythonClass clazz = getClassNode().execute(object);
1076-
return callBinaryIntoCapi(getPyObjectHandle_ForJavaObject(), getToSulongNode().execute(object), clazz.getFlags());
1077-
}
1078-
1079-
Object getHandleForObject(Object object, long flags) {
1080-
return callBinaryIntoCapi(getPyObjectHandle_ForJavaObject(), object, flags);
1064+
Object doObject(PythonNativeWrapper wrapper, Object object) {
1065+
return callUnaryIntoCapi(getPyObjectHandle_ForJavaObject(), wrapper);
10811066
}
10821067

10831068
private TruffleObject getPyObjectHandle_ForJavaType() {
@@ -1096,8 +1081,9 @@ private TruffleObject getPyObjectHandle_ForJavaObject() {
10961081
return PyObjectHandle_FromJavaObject;
10971082
}
10981083

1099-
protected boolean isManagedPythonClass(PythonAbstractObject klass) {
1100-
return klass instanceof PythonClass && !(klass instanceof PythonNativeClass);
1084+
protected static boolean isManagedPythonClass(PythonClassNativeWrapper wrapper) {
1085+
assert wrapper.getDelegate() instanceof PythonClass;
1086+
return !(wrapper.getDelegate() instanceof PythonNativeClass);
11011087
}
11021088

11031089
private Object callUnaryIntoCapi(TruffleObject fun, Object arg) {
@@ -1108,22 +1094,6 @@ private Object callUnaryIntoCapi(TruffleObject fun, Object arg) {
11081094
return callNativeUnary.execute(fun, new Object[]{arg});
11091095
}
11101096

1111-
private Object callBinaryIntoCapi(TruffleObject fun, Object arg0, Object arg1) {
1112-
if (callNativeBinary == null) {
1113-
CompilerDirectives.transferToInterpreterAndInvalidate();
1114-
callNativeBinary = insert(PCallNativeNode.create());
1115-
}
1116-
return callNativeBinary.execute(fun, new Object[]{arg0, arg1});
1117-
}
1118-
1119-
private GetClassNode getClassNode() {
1120-
if (getClassNode == null) {
1121-
CompilerDirectives.transferToInterpreterAndInvalidate();
1122-
getClassNode = insert(GetClassNode.create());
1123-
}
1124-
return getClassNode;
1125-
}
1126-
11271097
private CExtNodes.ToSulongNode getToSulongNode() {
11281098
if (toSulongNode == null) {
11291099
CompilerDirectives.transferToInterpreterAndInvalidate();

0 commit comments

Comments
 (0)