@@ -953,11 +953,11 @@ static long doGeneric(Node inliningTarget, PythonAbstractObjectNativeWrapper wra
953
953
long taggedPointer = HandlePointerConverter .stubToPointer (stubPointer );
954
954
955
955
writeLongNode .write (stubPointer , CFields .PyObject__ob_refcnt , initialRefCount );
956
- writeObjectNode .write (stubPointer , CFields .PyObject__ob_type , type );
957
956
958
957
// TODO(fa): this should not require the GIL (GR-51314)
959
958
boolean acquired = gil .acquire ();
960
959
try {
960
+ writeObjectNode .write (stubPointer , CFields .PyObject__ob_type , type );
961
961
int idx = nativeStubLookupReserve (handleContext );
962
962
// We don't allow 'handleTableIndex == 0' to avoid that zeroed memory
963
963
// accidentally maps to some valid object.
@@ -1214,6 +1214,7 @@ static Object doOther(Object obj,
1214
1214
@ Cached InlinedConditionProfile isStrongProfile ,
1215
1215
@ CachedLibrary (limit = "3" ) InteropLibrary lib ) {
1216
1216
CompilerAsserts .partialEvaluationConstant (needsTransfer );
1217
+ assert PythonContext .get (inliningTarget ).ownsGil ();
1217
1218
pollReferenceQueue ();
1218
1219
PythonNativeWrapper wrapper = getWrapper .execute (obj );
1219
1220
@@ -1222,7 +1223,6 @@ static Object doOther(Object obj,
1222
1223
return replacement ;
1223
1224
}
1224
1225
1225
- assert PythonContext .get (inliningTarget ).isNativeAccessAllowed ();
1226
1226
assert obj != PNone .NO_VALUE ;
1227
1227
if (!lib .isPointer (wrapper )) {
1228
1228
lib .toNative (wrapper );
@@ -1532,6 +1532,7 @@ Object doNonWrapper(long pointer, boolean stealing,
1532
1532
@ Cached InlinedConditionProfile isHandleSpaceProfile ,
1533
1533
@ Cached InlinedExactClassProfile wrapperProfile ) {
1534
1534
1535
+ assert PythonContext .get (null ).ownsGil ();
1535
1536
CompilerAsserts .partialEvaluationConstant (stealing );
1536
1537
PythonNativeWrapper wrapper ;
1537
1538
@@ -1588,6 +1589,7 @@ private static long addNativeRefCount(long pointer, long refCntDelta) {
1588
1589
1589
1590
private static long addNativeRefCount (long pointer , long refCntDelta , boolean ignoreIfDead ) {
1590
1591
assert PythonContext .get (null ).isNativeAccessAllowed ();
1592
+ assert PythonContext .get (null ).ownsGil ();
1591
1593
long refCount = UNSAFE .getLong (pointer + TP_REFCNT_OFFSET );
1592
1594
if (ignoreIfDead && refCount == 0 ) {
1593
1595
return 0 ;
@@ -1603,6 +1605,7 @@ private static long addNativeRefCount(long pointer, long refCntDelta, boolean ig
1603
1605
1604
1606
private static long subNativeRefCount (long pointer , long refCntDelta ) {
1605
1607
assert PythonContext .get (null ).isNativeAccessAllowed ();
1608
+ assert PythonContext .get (null ).ownsGil ();
1606
1609
long refCount = UNSAFE .getLong (pointer + TP_REFCNT_OFFSET );
1607
1610
assert (refCount & 0xFFFFFFFF00000000L ) == 0 : String .format ("suspicious refcnt value during managed adjustment for %016x (%d %016x - %d)\n " , pointer , refCount , refCount , refCntDelta );
1608
1611
assert (refCount - refCntDelta ) >= 0 : String .format ("refcnt below zero during managed adjustment for %016x (%d %016x - %d)\n " , pointer , refCount , refCount , refCntDelta );
@@ -1615,6 +1618,7 @@ private static long subNativeRefCount(long pointer, long refCntDelta) {
1615
1618
1616
1619
public static long readNativeRefCount (long pointer ) {
1617
1620
assert PythonContext .get (null ).isNativeAccessAllowed ();
1621
+ assert PythonContext .get (null ).ownsGil ();
1618
1622
long refCount = UNSAFE .getLong (pointer + TP_REFCNT_OFFSET );
1619
1623
assert refCount == IMMORTAL_REFCNT || (refCount & 0xFFFFFFFF00000000L ) == 0 : String .format ("suspicious refcnt value for %016x (%d %016x)\n " , pointer , refCount , refCount );
1620
1624
if (LOGGER .isLoggable (Level .FINEST )) {
@@ -1624,6 +1628,8 @@ public static long readNativeRefCount(long pointer) {
1624
1628
}
1625
1629
1626
1630
public static void writeNativeRefCount (long pointer , long newValue ) {
1631
+ assert PythonContext .get (null ).isNativeAccessAllowed ();
1632
+ assert PythonContext .get (null ).ownsGil ();
1627
1633
assert newValue > 0 : PythonUtils .formatJString ("refcnt value to write below zero for %016x (%d %016x)\n " , pointer , newValue , newValue );
1628
1634
if (LOGGER .isLoggable (Level .FINEST )) {
1629
1635
LOGGER .finest (PythonUtils .formatJString ("writeNativeRefCount(%x, %d (%x))" , pointer , newValue , newValue ));
0 commit comments