64
64
import com .oracle .graal .python .builtins .objects .cext .capi .TruffleObjectNativeWrapper ;
65
65
import com .oracle .graal .python .builtins .objects .cext .capi .transitions .CApiTransitionsFactory .NativeToPythonNodeGen ;
66
66
import com .oracle .graal .python .builtins .objects .cext .capi .transitions .CApiTransitionsFactory .NativeToPythonStealingNodeGen ;
67
- import com .oracle .graal .python .builtins .objects .cext .capi .transitions .CApiTransitionsFactory .PythonToNativeNodeGen ;
68
67
import com .oracle .graal .python .builtins .objects .cext .capi .transitions .CApiTransitionsFactory .PythonToNativeNewRefNodeGen ;
68
+ import com .oracle .graal .python .builtins .objects .cext .capi .transitions .CApiTransitionsFactory .PythonToNativeNodeGen ;
69
69
import com .oracle .graal .python .builtins .objects .cext .common .CExtToJavaNode ;
70
70
import com .oracle .graal .python .builtins .objects .cext .common .CExtToNativeNode ;
71
71
import com .oracle .graal .python .builtins .objects .getsetdescriptor .DescriptorDeleteMarker ;
77
77
import com .oracle .truffle .api .CompilerDirectives ;
78
78
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
79
79
import com .oracle .truffle .api .TruffleLogger ;
80
+ import com .oracle .truffle .api .dsl .Bind ;
80
81
import com .oracle .truffle .api .dsl .Cached ;
82
+ import com .oracle .truffle .api .dsl .Cached .Shared ;
83
+ import com .oracle .truffle .api .dsl .GenerateInline ;
81
84
import com .oracle .truffle .api .dsl .GenerateUncached ;
82
85
import com .oracle .truffle .api .dsl .ImportStatic ;
83
86
import com .oracle .truffle .api .dsl .Specialization ;
87
90
import com .oracle .truffle .api .library .CachedLibrary ;
88
91
import com .oracle .truffle .api .library .ExportLibrary ;
89
92
import com .oracle .truffle .api .library .ExportMessage ;
90
- import com .oracle .truffle .api .profiles .ConditionProfile ;
93
+ import com .oracle .truffle .api .nodes .Node ;
94
+ import com .oracle .truffle .api .profiles .InlinedConditionProfile ;
91
95
import com .oracle .truffle .api .strings .TruffleString ;
92
96
import com .oracle .truffle .api .strings .TruffleString .FromJavaStringNode ;
93
97
@@ -587,14 +591,16 @@ public static void setRefCount(PythonNativeWrapper nativeWrapper, long value) {
587
591
private static final InteropLibrary LIB = InteropLibrary .getUncached ();
588
592
589
593
@ GenerateUncached
594
+ @ GenerateInline (false )
590
595
public abstract static class CharPtrToPythonNode extends CExtToJavaNode {
591
596
592
597
@ Specialization
593
598
static Object doForeign (Object value ,
599
+ @ Bind ("$node" ) Node inliningTarget ,
594
600
@ CachedLibrary (limit = "3" ) InteropLibrary interopLibrary ,
595
- @ Cached ConditionProfile isNullProfile ) {
601
+ @ Cached InlinedConditionProfile isNullProfile ) {
596
602
// this branch is not a shortcut; it actually returns a different object
597
- if (isNullProfile .profile (interopLibrary .isNull (value ))) {
603
+ if (isNullProfile .profile (inliningTarget , interopLibrary .isNull (value ))) {
598
604
return PNone .NO_VALUE ;
599
605
}
600
606
return nativeCharToJava (value );
@@ -639,6 +645,7 @@ public static Object nativeCharToJava(Object value) {
639
645
}
640
646
641
647
@ GenerateUncached
648
+ @ GenerateInline (false )
642
649
@ ImportStatic (CApiGuards .class )
643
650
public abstract static class PythonToNativeNode extends CExtToNativeNode {
644
651
@@ -715,6 +722,7 @@ Object doOther(Object obj,
715
722
* </p>
716
723
*/
717
724
@ GenerateUncached
725
+ @ GenerateInline (false )
718
726
public abstract static class PythonToNativeNewRefNode extends PythonToNativeNode {
719
727
720
728
@ Specialization
@@ -735,6 +743,7 @@ protected boolean needsTransfer() {
735
743
}
736
744
737
745
@ GenerateUncached
746
+ @ GenerateInline (false )
738
747
@ ImportStatic (CApiGuards .class )
739
748
public abstract static class NativeToPythonNode extends CExtToJavaNode {
740
749
@@ -751,27 +760,30 @@ protected boolean needsTransfer() {
751
760
752
761
@ Specialization
753
762
static Object doWrapper (PythonNativeWrapper value ,
754
- @ Cached ConditionProfile isPrimitiveProfile ) {
755
- return handleWrapper (isPrimitiveProfile , false , value );
763
+ @ Bind ("$node" ) Node inliningTarget ,
764
+ @ Shared ("primitive" ) @ Cached InlinedConditionProfile isPrimitiveProfile ) {
765
+ return handleWrapper (inliningTarget , isPrimitiveProfile , false , value );
756
766
}
757
767
758
768
@ Specialization (guards = "!isNativeWrapper(value)" , limit = "3" )
769
+ @ SuppressWarnings ({"truffle-static-method" , "truffle-sharing" })
759
770
Object doNonWrapper (Object value ,
771
+ @ Bind ("$node" ) Node inliningTarget ,
760
772
@ CachedLibrary ("value" ) InteropLibrary interopLibrary ,
761
- @ Cached ConditionProfile isNullProfile ,
762
- @ Cached ConditionProfile isZeroProfile ,
763
- @ Cached ConditionProfile createNativeProfile ,
764
- @ Cached ConditionProfile isNativeProfile ,
765
- @ Cached ConditionProfile isNativeWrapperProfile ,
766
- @ Cached ConditionProfile isHandleSpaceProfile ,
767
- @ Cached ConditionProfile isPrimitiveProfile ) {
773
+ @ Cached InlinedConditionProfile isNullProfile ,
774
+ @ Cached InlinedConditionProfile isZeroProfile ,
775
+ @ Cached InlinedConditionProfile createNativeProfile ,
776
+ @ Cached InlinedConditionProfile isNativeProfile ,
777
+ @ Cached InlinedConditionProfile isNativeWrapperProfile ,
778
+ @ Cached InlinedConditionProfile isHandleSpaceProfile ,
779
+ @ Shared ( "primitive" ) @ Cached InlinedConditionProfile isPrimitiveProfile ) {
768
780
assert !(value instanceof TruffleString );
769
781
assert !(value instanceof PythonAbstractObject );
770
782
assert !(value instanceof Number );
771
783
assert !(value instanceof PythonAbstractNativeObject );
772
784
773
785
// this is just a shortcut
774
- if (isNullProfile .profile (interopLibrary .isNull (value ))) {
786
+ if (isNullProfile .profile (inliningTarget , interopLibrary .isNull (value ))) {
775
787
return PNone .NO_VALUE ;
776
788
}
777
789
PythonNativeWrapper wrapper ;
@@ -787,10 +799,10 @@ Object doNonWrapper(Object value,
787
799
} catch (final UnsupportedMessageException e ) {
788
800
throw CompilerDirectives .shouldNotReachHere (e );
789
801
}
790
- if (isZeroProfile .profile (pointer == 0 )) {
802
+ if (isZeroProfile .profile (inliningTarget , pointer == 0 )) {
791
803
return PNone .NO_VALUE ;
792
804
}
793
- if (isHandleSpaceProfile .profile (HandleTester .pointsToPyHandleSpace (pointer ))) {
805
+ if (isHandleSpaceProfile .profile (inliningTarget , HandleTester .pointsToPyHandleSpace (pointer ))) {
794
806
PythonObjectReference reference = nativeContext .nativeHandles .get ((int ) (pointer - HandleFactory .HANDLE_BASE ));
795
807
if (reference == null ) {
796
808
CompilerDirectives .transferToInterpreterAndInvalidate ();
@@ -803,13 +815,13 @@ Object doNonWrapper(Object value,
803
815
}
804
816
} else {
805
817
IdReference <?> lookup = nativeLookupGet (nativeContext , pointer );
806
- if (isNativeProfile .profile (lookup != null )) {
818
+ if (isNativeProfile .profile (inliningTarget , lookup != null )) {
807
819
Object ref = lookup .get ();
808
- if (createNativeProfile .profile (ref == null )) {
820
+ if (createNativeProfile .profile (inliningTarget , ref == null )) {
809
821
LOGGER .fine (() -> "re-creating collected PythonAbstractNativeObject reference" + Long .toHexString (pointer ));
810
822
return createAbstractNativeObject (value , needsTransfer (), pointer );
811
823
}
812
- if (isNativeWrapperProfile .profile (ref instanceof PythonNativeWrapper )) {
824
+ if (isNativeWrapperProfile .profile (inliningTarget , ref instanceof PythonNativeWrapper )) {
813
825
wrapper = (PythonNativeWrapper ) ref ;
814
826
} else {
815
827
PythonAbstractNativeObject result = (PythonAbstractNativeObject ) ref ;
@@ -822,15 +834,15 @@ Object doNonWrapper(Object value,
822
834
return createAbstractNativeObject (value , needsTransfer (), pointer );
823
835
}
824
836
}
825
- return handleWrapper (isPrimitiveProfile , needsTransfer (), wrapper );
837
+ return handleWrapper (inliningTarget , isPrimitiveProfile , needsTransfer (), wrapper );
826
838
}
827
839
828
- private static Object handleWrapper (ConditionProfile isPrimitiveProfile , boolean transfer , PythonNativeWrapper wrapper ) {
840
+ private static Object handleWrapper (Node node , InlinedConditionProfile isPrimitiveProfile , boolean transfer , PythonNativeWrapper wrapper ) {
829
841
if (transfer ) {
830
842
assert wrapper .getRefCount () >= PythonNativeWrapper .MANAGED_REFCNT ;
831
843
decRef (wrapper , 1 );
832
844
}
833
- if (isPrimitiveProfile .profile (wrapper instanceof PrimitiveNativeWrapper )) {
845
+ if (isPrimitiveProfile .profile (node , wrapper instanceof PrimitiveNativeWrapper )) {
834
846
PrimitiveNativeWrapper primitive = (PrimitiveNativeWrapper ) wrapper ;
835
847
if (primitive .isBool ()) {
836
848
return primitive .getBool ();
@@ -864,6 +876,7 @@ private static Object getManagedReference(Object value, HandleContext nativeCont
864
876
}
865
877
866
878
@ GenerateUncached
879
+ @ GenerateInline (false )
867
880
public abstract static class NativeToPythonStealingNode extends NativeToPythonNode {
868
881
869
882
@ Specialization
0 commit comments