102
102
import com .oracle .graal .python .nodes .object .GetLazyClassNode ;
103
103
import com .oracle .graal .python .nodes .object .IsBuiltinClassProfile ;
104
104
import com .oracle .graal .python .nodes .truffle .PythonArithmeticTypes ;
105
- import com .oracle .graal .python .runtime .PythonContext ;
106
105
import com .oracle .graal .python .runtime .PythonCore ;
107
106
import com .oracle .graal .python .runtime .exception .PException ;
108
107
import com .oracle .graal .python .runtime .interop .PythonMessageResolution ;
109
108
import com .oracle .graal .python .runtime .sequence .PSequence ;
110
- import com .oracle .truffle .api .Assumption ;
111
109
import com .oracle .truffle .api .CompilerDirectives ;
112
110
import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
113
111
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
@@ -852,32 +850,23 @@ public Object access(Object object) {
852
850
@ Resolve (message = "TO_NATIVE" )
853
851
abstract static class ToNativeNode extends Node {
854
852
@ Child private ToPyObjectNode toPyObjectNode ;
855
- @ Child private MaterializeDelegateNode materializeNode ;
856
853
@ Child private PIsPointerNode pIsPointerNode = PIsPointerNode .create ();
857
854
858
855
Object access (PythonClassInitNativeWrapper obj ) {
859
856
if (!pIsPointerNode .execute (obj )) {
860
- obj .setNativePointer (getToPyObjectNode ().getHandleForObject ( getMaterializeDelegateNode (). execute (obj ) ));
857
+ obj .setNativePointer (getToPyObjectNode ().execute (obj ));
861
858
}
862
859
return obj ;
863
860
}
864
861
865
862
Object access (PythonNativeWrapper obj ) {
866
863
assert !(obj instanceof PythonClassInitNativeWrapper );
867
864
if (!pIsPointerNode .execute (obj )) {
868
- obj .setNativePointer (getToPyObjectNode ().execute (getMaterializeDelegateNode (). execute ( obj ) ));
865
+ obj .setNativePointer (getToPyObjectNode ().execute (obj ));
869
866
}
870
867
return obj ;
871
868
}
872
869
873
- private MaterializeDelegateNode getMaterializeDelegateNode () {
874
- if (materializeNode == null ) {
875
- CompilerDirectives .transferToInterpreterAndInvalidate ();
876
- materializeNode = insert (MaterializeDelegateNode .create ());
877
- }
878
- return materializeNode ;
879
- }
880
-
881
870
private ToPyObjectNode getToPyObjectNode () {
882
871
if (toPyObjectNode == null ) {
883
872
CompilerDirectives .transferToInterpreterAndInvalidate ();
@@ -933,7 +922,7 @@ abstract static class PAsPointerNode extends PNodeWithContext {
933
922
934
923
public abstract long execute (PythonNativeWrapper o );
935
924
936
- @ Specialization (assumptions = "getSingleNativeContextAssumption()" , guards = "!obj.isNative()" )
925
+ @ Specialization (guards = "!obj.isNative()" )
937
926
long doBoolNotNative (BoolNativeWrapper obj ,
938
927
@ Cached ("create()" ) MaterializeDelegateNode materializeNode ) {
939
928
// special case for True and False singletons
@@ -942,25 +931,17 @@ long doBoolNotNative(BoolNativeWrapper obj,
942
931
return doFast (obj );
943
932
}
944
933
945
- @ Specialization (assumptions = "getSingleNativeContextAssumption()" , guards = "obj.isNative()" )
934
+ @ Specialization (guards = "obj.isNative()" )
946
935
long doBoolNative (BoolNativeWrapper obj ) {
947
936
return doFast (obj );
948
937
}
949
938
950
- @ Specialization (assumptions = "getSingleNativeContextAssumption()" , guards = "!isBoolNativeWrapper(obj)" )
939
+ @ Specialization (guards = "!isBoolNativeWrapper(obj)" )
951
940
long doFast (PythonNativeWrapper obj ) {
952
941
// the native pointer object must either be a TruffleObject or a primitive
953
942
return ensureLong (obj .getNativePointer ());
954
943
}
955
944
956
- @ Specialization (replaces = {"doFast" , "doBoolNotNative" , "doBoolNative" })
957
- long doGenericSlow (PythonNativeWrapper obj ,
958
- @ Cached ("create()" ) MaterializeDelegateNode materializeNode ,
959
- @ Cached ("create()" ) ToPyObjectNode toPyObjectNode ) {
960
- Object materialized = materializeNode .execute (obj );
961
- return ensureLong (toPyObjectNode .execute (materialized ));
962
- }
963
-
964
945
private long ensureLong (Object nativePointer ) {
965
946
if (nativePointer instanceof TruffleObject ) {
966
947
if (asPointerNode == null ) {
@@ -981,70 +962,11 @@ protected static boolean isBoolNativeWrapper(Object obj) {
981
962
return obj instanceof BoolNativeWrapper ;
982
963
}
983
964
984
- protected Assumption getSingleNativeContextAssumption () {
985
- return PythonContext .getSingleNativeContextAssumption ();
986
- }
987
-
988
965
public static PAsPointerNode create () {
989
966
return PAsPointerNodeGen .create ();
990
967
}
991
968
}
992
969
993
- abstract static class PToNativeNode extends PNodeWithContext {
994
- @ Child private ToPyObjectNode toPyObjectNode ;
995
- @ Child private MaterializeDelegateNode materializeNode ;
996
- @ Child private PIsPointerNode pIsPointerNode = PIsPointerNode .create ();
997
-
998
- public abstract PythonNativeWrapper execute (PythonNativeWrapper obj );
999
-
1000
- @ Specialization
1001
- PythonNativeWrapper doInitClass (PythonClassInitNativeWrapper obj ) {
1002
- if (!pIsPointerNode .execute (obj )) {
1003
- obj .setNativePointer (getToPyObjectNode ().getHandleForObject (getMaterializeDelegateNode ().execute (obj )));
1004
- }
1005
- return obj ;
1006
- }
1007
-
1008
- @ Specialization
1009
- PythonNativeWrapper doBool (BoolNativeWrapper obj ) {
1010
- if (!pIsPointerNode .execute (obj )) {
1011
- PInt materialized = (PInt ) getMaterializeDelegateNode ().execute (obj );
1012
- obj .setNativePointer (getToPyObjectNode ().execute (materialized ));
1013
- if (!materialized .getNativeWrapper ().isNative ()) {
1014
- assert materialized .getNativeWrapper () != obj ;
1015
- materialized .getNativeWrapper ().setNativePointer (obj .getNativePointer ());
1016
- }
1017
- assert obj .getNativePointer () == materialized .getNativeWrapper ().getNativePointer ();
1018
- }
1019
- return obj ;
1020
- }
1021
-
1022
- @ Fallback
1023
- PythonNativeWrapper doGeneric (PythonNativeWrapper obj ) {
1024
- assert !(obj instanceof PythonClassInitNativeWrapper );
1025
- if (!pIsPointerNode .execute (obj )) {
1026
- obj .setNativePointer (getToPyObjectNode ().execute (getMaterializeDelegateNode ().execute (obj )));
1027
- }
1028
- return obj ;
1029
- }
1030
-
1031
- private MaterializeDelegateNode getMaterializeDelegateNode () {
1032
- if (materializeNode == null ) {
1033
- CompilerDirectives .transferToInterpreterAndInvalidate ();
1034
- materializeNode = insert (MaterializeDelegateNode .create ());
1035
- }
1036
- return materializeNode ;
1037
- }
1038
-
1039
- private ToPyObjectNode getToPyObjectNode () {
1040
- if (toPyObjectNode == null ) {
1041
- CompilerDirectives .transferToInterpreterAndInvalidate ();
1042
- toPyObjectNode = insert (ToPyObjectNode .create ());
1043
- }
1044
- return toPyObjectNode ;
1045
- }
1046
- }
1047
-
1048
970
abstract static class ToPyObjectNode extends CExtBaseNode {
1049
971
@ CompilationFinal private TruffleObject PyObjectHandle_FromJavaObject ;
1050
972
@ CompilationFinal private TruffleObject PyObjectHandle_FromJavaType ;
@@ -1053,15 +975,15 @@ abstract static class ToPyObjectNode extends CExtBaseNode {
1053
975
@ Child private PCallNativeNode callNativeBinary ;
1054
976
@ Child private CExtNodes .ToSulongNode toSulongNode ;
1055
977
1056
- public abstract Object execute (PythonNativeWrapper wrapper , Object value );
978
+ public abstract Object execute (PythonNativeWrapper wrapper );
1057
979
1058
980
@ Specialization (guards = "isManagedPythonClass(wrapper)" )
1059
- Object doClass (PythonClassNativeWrapper wrapper , PythonClass object ) {
981
+ Object doClass (PythonClassNativeWrapper wrapper ) {
1060
982
return callUnaryIntoCapi (getPyObjectHandle_ForJavaType (), wrapper );
1061
983
}
1062
984
1063
985
@ Fallback
1064
- Object doObject (PythonNativeWrapper wrapper , Object object ) {
986
+ Object doObject (PythonNativeWrapper wrapper ) {
1065
987
return callUnaryIntoCapi (getPyObjectHandle_ForJavaObject (), wrapper );
1066
988
}
1067
989
@@ -1094,14 +1016,6 @@ private Object callUnaryIntoCapi(TruffleObject fun, Object arg) {
1094
1016
return callNativeUnary .execute (fun , new Object []{arg });
1095
1017
}
1096
1018
1097
- private CExtNodes .ToSulongNode getToSulongNode () {
1098
- if (toSulongNode == null ) {
1099
- CompilerDirectives .transferToInterpreterAndInvalidate ();
1100
- toSulongNode = insert (CExtNodes .ToSulongNode .create ());
1101
- }
1102
- return toSulongNode ;
1103
- }
1104
-
1105
1019
public static ToPyObjectNode create () {
1106
1020
return ToPyObjectNodeGen .create ();
1107
1021
}
0 commit comments