Skip to content

Commit 7217549

Browse files
committed
use node inlining in CApiTransitions
1 parent 860d296 commit 7217549

File tree

1 file changed

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

1 file changed

+35
-22
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/CApiTransitions.java

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
import com.oracle.graal.python.builtins.objects.cext.capi.TruffleObjectNativeWrapper;
6565
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitionsFactory.NativeToPythonNodeGen;
6666
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;
6867
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;
6969
import com.oracle.graal.python.builtins.objects.cext.common.CExtToJavaNode;
7070
import com.oracle.graal.python.builtins.objects.cext.common.CExtToNativeNode;
7171
import com.oracle.graal.python.builtins.objects.getsetdescriptor.DescriptorDeleteMarker;
@@ -77,7 +77,10 @@
7777
import com.oracle.truffle.api.CompilerDirectives;
7878
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
7979
import com.oracle.truffle.api.TruffleLogger;
80+
import com.oracle.truffle.api.dsl.Bind;
8081
import com.oracle.truffle.api.dsl.Cached;
82+
import com.oracle.truffle.api.dsl.Cached.Shared;
83+
import com.oracle.truffle.api.dsl.GenerateInline;
8184
import com.oracle.truffle.api.dsl.GenerateUncached;
8285
import com.oracle.truffle.api.dsl.ImportStatic;
8386
import com.oracle.truffle.api.dsl.Specialization;
@@ -87,7 +90,8 @@
8790
import com.oracle.truffle.api.library.CachedLibrary;
8891
import com.oracle.truffle.api.library.ExportLibrary;
8992
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;
9195
import com.oracle.truffle.api.strings.TruffleString;
9296
import com.oracle.truffle.api.strings.TruffleString.FromJavaStringNode;
9397

@@ -587,14 +591,16 @@ public static void setRefCount(PythonNativeWrapper nativeWrapper, long value) {
587591
private static final InteropLibrary LIB = InteropLibrary.getUncached();
588592

589593
@GenerateUncached
594+
@GenerateInline(false)
590595
public abstract static class CharPtrToPythonNode extends CExtToJavaNode {
591596

592597
@Specialization
593598
static Object doForeign(Object value,
599+
@Bind("$node") Node inliningTarget,
594600
@CachedLibrary(limit = "3") InteropLibrary interopLibrary,
595-
@Cached ConditionProfile isNullProfile) {
601+
@Cached InlinedConditionProfile isNullProfile) {
596602
// 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))) {
598604
return PNone.NO_VALUE;
599605
}
600606
return nativeCharToJava(value);
@@ -639,6 +645,7 @@ public static Object nativeCharToJava(Object value) {
639645
}
640646

641647
@GenerateUncached
648+
@GenerateInline(false)
642649
@ImportStatic(CApiGuards.class)
643650
public abstract static class PythonToNativeNode extends CExtToNativeNode {
644651

@@ -715,6 +722,7 @@ Object doOther(Object obj,
715722
* </p>
716723
*/
717724
@GenerateUncached
725+
@GenerateInline(false)
718726
public abstract static class PythonToNativeNewRefNode extends PythonToNativeNode {
719727

720728
@Specialization
@@ -735,6 +743,7 @@ protected boolean needsTransfer() {
735743
}
736744

737745
@GenerateUncached
746+
@GenerateInline(false)
738747
@ImportStatic(CApiGuards.class)
739748
public abstract static class NativeToPythonNode extends CExtToJavaNode {
740749

@@ -751,27 +760,30 @@ protected boolean needsTransfer() {
751760

752761
@Specialization
753762
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);
756766
}
757767

758768
@Specialization(guards = "!isNativeWrapper(value)", limit = "3")
769+
@SuppressWarnings({"truffle-static-method", "truffle-sharing"})
759770
Object doNonWrapper(Object value,
771+
@Bind("$node") Node inliningTarget,
760772
@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) {
768780
assert !(value instanceof TruffleString);
769781
assert !(value instanceof PythonAbstractObject);
770782
assert !(value instanceof Number);
771783
assert !(value instanceof PythonAbstractNativeObject);
772784

773785
// this is just a shortcut
774-
if (isNullProfile.profile(interopLibrary.isNull(value))) {
786+
if (isNullProfile.profile(inliningTarget, interopLibrary.isNull(value))) {
775787
return PNone.NO_VALUE;
776788
}
777789
PythonNativeWrapper wrapper;
@@ -787,10 +799,10 @@ Object doNonWrapper(Object value,
787799
} catch (final UnsupportedMessageException e) {
788800
throw CompilerDirectives.shouldNotReachHere(e);
789801
}
790-
if (isZeroProfile.profile(pointer == 0)) {
802+
if (isZeroProfile.profile(inliningTarget, pointer == 0)) {
791803
return PNone.NO_VALUE;
792804
}
793-
if (isHandleSpaceProfile.profile(HandleTester.pointsToPyHandleSpace(pointer))) {
805+
if (isHandleSpaceProfile.profile(inliningTarget, HandleTester.pointsToPyHandleSpace(pointer))) {
794806
PythonObjectReference reference = nativeContext.nativeHandles.get((int) (pointer - HandleFactory.HANDLE_BASE));
795807
if (reference == null) {
796808
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -803,13 +815,13 @@ Object doNonWrapper(Object value,
803815
}
804816
} else {
805817
IdReference<?> lookup = nativeLookupGet(nativeContext, pointer);
806-
if (isNativeProfile.profile(lookup != null)) {
818+
if (isNativeProfile.profile(inliningTarget, lookup != null)) {
807819
Object ref = lookup.get();
808-
if (createNativeProfile.profile(ref == null)) {
820+
if (createNativeProfile.profile(inliningTarget, ref == null)) {
809821
LOGGER.fine(() -> "re-creating collected PythonAbstractNativeObject reference" + Long.toHexString(pointer));
810822
return createAbstractNativeObject(value, needsTransfer(), pointer);
811823
}
812-
if (isNativeWrapperProfile.profile(ref instanceof PythonNativeWrapper)) {
824+
if (isNativeWrapperProfile.profile(inliningTarget, ref instanceof PythonNativeWrapper)) {
813825
wrapper = (PythonNativeWrapper) ref;
814826
} else {
815827
PythonAbstractNativeObject result = (PythonAbstractNativeObject) ref;
@@ -822,15 +834,15 @@ Object doNonWrapper(Object value,
822834
return createAbstractNativeObject(value, needsTransfer(), pointer);
823835
}
824836
}
825-
return handleWrapper(isPrimitiveProfile, needsTransfer(), wrapper);
837+
return handleWrapper(inliningTarget, isPrimitiveProfile, needsTransfer(), wrapper);
826838
}
827839

828-
private static Object handleWrapper(ConditionProfile isPrimitiveProfile, boolean transfer, PythonNativeWrapper wrapper) {
840+
private static Object handleWrapper(Node node, InlinedConditionProfile isPrimitiveProfile, boolean transfer, PythonNativeWrapper wrapper) {
829841
if (transfer) {
830842
assert wrapper.getRefCount() >= PythonNativeWrapper.MANAGED_REFCNT;
831843
decRef(wrapper, 1);
832844
}
833-
if (isPrimitiveProfile.profile(wrapper instanceof PrimitiveNativeWrapper)) {
845+
if (isPrimitiveProfile.profile(node, wrapper instanceof PrimitiveNativeWrapper)) {
834846
PrimitiveNativeWrapper primitive = (PrimitiveNativeWrapper) wrapper;
835847
if (primitive.isBool()) {
836848
return primitive.getBool();
@@ -864,6 +876,7 @@ private static Object getManagedReference(Object value, HandleContext nativeCont
864876
}
865877

866878
@GenerateUncached
879+
@GenerateInline(false)
867880
public abstract static class NativeToPythonStealingNode extends NativeToPythonNode {
868881

869882
@Specialization

0 commit comments

Comments
 (0)