|
116 | 116 | import com.oracle.truffle.api.interop.InteropLibrary;
|
117 | 117 | import com.oracle.truffle.api.interop.UnsupportedMessageException;
|
118 | 118 | import com.oracle.truffle.api.nodes.Node;
|
| 119 | +import com.oracle.truffle.api.profiles.InlinedBranchProfile; |
119 | 120 | import com.oracle.truffle.api.strings.TruffleString;
|
120 | 121 |
|
121 | 122 | /**
|
@@ -955,21 +956,28 @@ static TpSlots doManaged(PythonManagedClass klass) {
|
955 | 956 | }
|
956 | 957 |
|
957 | 958 | @Specialization
|
958 |
| - static TpSlots doNative(PythonAbstractNativeObject nativeKlass) { |
| 959 | + static TpSlots doNative(Node inliningTarget, PythonAbstractNativeObject nativeKlass, |
| 960 | + @Cached InlinedBranchProfile slotsNotInitializedProfile) { |
959 | 961 | TpSlots tpSlots = nativeKlass.getTpSlots();
|
960 |
| - if (tpSlots == null) { |
| 962 | + if (CompilerDirectives.injectBranchProbability(CompilerDirectives.SLOWPATH_PROBABILITY, tpSlots == null)) { |
961 | 963 | /*
|
962 | 964 | * This happens when we try to get slots of a type that didn't go through
|
963 | 965 | * PyType_Ready yet. Specifically, numpy has a "fortran" type (defined in
|
964 | 966 | * `fortranobject.c`) that they never ready and just expect it to work because it's
|
965 | 967 | * simple. So just do the minimum to make the slots available.
|
966 | 968 | */
|
967 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
968 |
| - tpSlots = TpSlots.fromNative(nativeKlass, PythonContext.get(null)); |
969 |
| - nativeKlass.setTpSlots(tpSlots); |
| 969 | + slotsNotInitializedProfile.enter(inliningTarget); |
| 970 | + tpSlots = initializeNativeSlots(nativeKlass); |
970 | 971 | }
|
971 | 972 | return tpSlots;
|
972 | 973 | }
|
| 974 | + |
| 975 | + @TruffleBoundary |
| 976 | + private static TpSlots initializeNativeSlots(PythonAbstractNativeObject nativeKlass) { |
| 977 | + TpSlots tpSlots = TpSlots.fromNative(nativeKlass, PythonContext.get(null)); |
| 978 | + nativeKlass.setTpSlots(tpSlots); |
| 979 | + return tpSlots; |
| 980 | + } |
973 | 981 | }
|
974 | 982 |
|
975 | 983 | @GenerateInline(inlineByDefault = true)
|
|
0 commit comments