Skip to content

Commit eb0319b

Browse files
committed
Profile initializing native slots for non-ready types
1 parent ecc514c commit eb0319b

File tree

1 file changed

+13
-5
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type

1 file changed

+13
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
import com.oracle.truffle.api.interop.InteropLibrary;
117117
import com.oracle.truffle.api.interop.UnsupportedMessageException;
118118
import com.oracle.truffle.api.nodes.Node;
119+
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
119120
import com.oracle.truffle.api.strings.TruffleString;
120121

121122
/**
@@ -955,21 +956,28 @@ static TpSlots doManaged(PythonManagedClass klass) {
955956
}
956957

957958
@Specialization
958-
static TpSlots doNative(PythonAbstractNativeObject nativeKlass) {
959+
static TpSlots doNative(Node inliningTarget, PythonAbstractNativeObject nativeKlass,
960+
@Cached InlinedBranchProfile slotsNotInitializedProfile) {
959961
TpSlots tpSlots = nativeKlass.getTpSlots();
960-
if (tpSlots == null) {
962+
if (CompilerDirectives.injectBranchProbability(CompilerDirectives.SLOWPATH_PROBABILITY, tpSlots == null)) {
961963
/*
962964
* This happens when we try to get slots of a type that didn't go through
963965
* PyType_Ready yet. Specifically, numpy has a "fortran" type (defined in
964966
* `fortranobject.c`) that they never ready and just expect it to work because it's
965967
* simple. So just do the minimum to make the slots available.
966968
*/
967-
CompilerDirectives.transferToInterpreterAndInvalidate();
968-
tpSlots = TpSlots.fromNative(nativeKlass, PythonContext.get(null));
969-
nativeKlass.setTpSlots(tpSlots);
969+
slotsNotInitializedProfile.enter(inliningTarget);
970+
tpSlots = initializeNativeSlots(nativeKlass);
970971
}
971972
return tpSlots;
972973
}
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+
}
973981
}
974982

975983
@GenerateInline(inlineByDefault = true)

0 commit comments

Comments
 (0)