@@ -189,25 +189,20 @@ public Object asIndexWithState(ThreadState threadState,
189
189
@ Exclusive @ Cached ConditionProfile resultProfile ,
190
190
@ Exclusive @ Cached ConditionProfile gotState ,
191
191
@ Cached IsBuiltinClassProfile isInt ,
192
- @ Cached WarnNode warnNode , @ Exclusive @ Cached GilNode gil ) {
193
- boolean mustRelease = gil .acquire ();
194
- try {
195
- if (isSubtypeNode .execute (plib .getLazyPythonClass (this ), PythonBuiltinClassType .PInt )) {
196
- if (!isInt .profileObject (this , PythonBuiltinClassType .PInt )) {
197
- VirtualFrame frame = null ;
198
- if (gotState .profile (threadState != null )) {
199
- frame = PArguments .frameForCall (threadState );
200
- }
201
- warnNode .warnFormat (frame , null , PythonBuiltinClassType .DeprecationWarning , 1 ,
202
- ErrorMessages .P_RETURNED_NON_P ,
203
- this , "__index__" , "int" , this , "int" );
192
+ @ Cached WarnNode warnNode ) {
193
+ if (isSubtypeNode .execute (plib .getLazyPythonClass (this ), PythonBuiltinClassType .PInt )) {
194
+ if (!isInt .profileObject (this , PythonBuiltinClassType .PInt )) {
195
+ VirtualFrame frame = null ;
196
+ if (gotState .profile (threadState != null )) {
197
+ frame = PArguments .frameForCall (threadState );
204
198
}
205
- return this ; // subclasses of 'int' should do early return
206
- } else {
207
- return asIndexWithState ( threadState , plib , methodLib , resultLib , raise , isSubtypeNode , noIndex , resultProfile , gotState , isInt , warnNode , gil );
199
+ warnNode . warnFormat ( frame , null , PythonBuiltinClassType . DeprecationWarning , 1 ,
200
+ ErrorMessages . P_RETURNED_NON_P ,
201
+ this , "__index__" , "int" , this , "int" );
208
202
}
209
- } finally {
210
- gil .release (mustRelease );
203
+ return this ; // subclasses of 'int' should do early return
204
+ } else {
205
+ return asIndexWithState (threadState , plib , methodLib , resultLib , raise , isSubtypeNode , noIndex , resultProfile , gotState , isInt , warnNode );
211
206
}
212
207
}
213
208
@@ -216,19 +211,14 @@ public PDict getDict(
216
211
@ Exclusive @ Cached PRaiseNode raiseNode ,
217
212
@ Exclusive @ Cached ToSulongNode toSulong ,
218
213
@ Exclusive @ Cached ToJavaNode toJava ,
219
- @ Exclusive @ Cached PCallCapiFunction callGetDictNode , @ Exclusive @ Cached GilNode gil ) {
220
- boolean mustRelease = gil .acquire ();
221
- try {
222
- Object javaDict = toJava .execute (callGetDictNode .call (FUN_PY_OBJECT_GENERIC_GET_DICT , toSulong .execute (this )));
223
- if (javaDict instanceof PDict ) {
224
- return (PDict ) javaDict ;
225
- } else if (javaDict == PNone .NO_VALUE ) {
226
- return null ;
227
- } else {
228
- throw raiseNode .raise (PythonBuiltinClassType .TypeError , ErrorMessages .DICT_MUST_BE_SET_TO_DICT , javaDict );
229
- }
230
- } finally {
231
- gil .release (mustRelease );
214
+ @ Exclusive @ Cached PCallCapiFunction callGetDictNode ) {
215
+ Object javaDict = toJava .execute (callGetDictNode .call (FUN_PY_OBJECT_GENERIC_GET_DICT , toSulong .execute (this )));
216
+ if (javaDict instanceof PDict ) {
217
+ return (PDict ) javaDict ;
218
+ } else if (javaDict == PNone .NO_VALUE ) {
219
+ return null ;
220
+ } else {
221
+ throw raiseNode .raise (PythonBuiltinClassType .TypeError , ErrorMessages .DICT_MUST_BE_SET_TO_DICT , javaDict );
232
222
}
233
223
}
234
224
@@ -243,8 +233,7 @@ static Assumption getSingleContextAssumption() {
243
233
@ SuppressWarnings ("unused" )
244
234
static Object getNativeClassCachedIdentity (PythonAbstractNativeObject object ,
245
235
@ Exclusive @ Cached (value = "object" , weak = true ) PythonAbstractNativeObject cachedObject ,
246
- @ Exclusive @ Cached GilNode gil ,
247
- @ Exclusive @ Cached ("getNativeClassUncached(object, gil)" ) Object cachedClass ) {
236
+ @ Exclusive @ Cached ("getNativeClassUncached(object)" ) Object cachedClass ) {
248
237
// TODO: (tfel) is this really something we can do? It's so rare for this class to
249
238
// change that it shouldn't be worth the effort, but in native code, anything can
250
239
// happen. OTOH, CPython also has caches that can become invalid when someone just
@@ -256,8 +245,7 @@ static Object getNativeClassCachedIdentity(PythonAbstractNativeObject object,
256
245
@ SuppressWarnings ("unused" )
257
246
static Object getNativeClassCached (PythonAbstractNativeObject object ,
258
247
@ Exclusive @ Cached (value = "object" , weak = true ) PythonAbstractNativeObject cachedObject ,
259
- @ Exclusive @ Cached GilNode gil ,
260
- @ Exclusive @ Cached ("getNativeClassUncached(object, gil)" ) Object cachedClass ,
248
+ @ Exclusive @ Cached ("getNativeClassUncached(object)" ) Object cachedClass ,
261
249
@ CachedLibrary (limit = "3" ) @ SuppressWarnings ("unused" ) InteropLibrary lib ) {
262
250
// TODO same as for 'getNativeClassCachedIdentity'
263
251
return cachedClass ;
@@ -270,15 +258,9 @@ static Object getNativeClassCached(PythonAbstractNativeObject object,
270
258
static Object getNativeClassByMember (PythonAbstractNativeObject object ,
271
259
@ CachedLibrary ("object.getPtr()" ) InteropLibrary lib ,
272
260
@ Exclusive @ Cached ToJavaNode toJavaNode ,
273
- @ Exclusive @ Cached ProfileClassNode classProfile , @ Exclusive @ Cached GilNode gil ) throws UnknownIdentifierException , UnsupportedMessageException {
274
- boolean mustRelease = gil .acquire ();
275
- try {
276
- // do not convert wrap 'object.object' since that is really the native pointer
277
- // object
278
- return classProfile .profile (toJavaNode .execute (lib .readMember (object .getPtr (), NativeMember .OB_TYPE .getMemberName ())));
279
- } finally {
280
- gil .release (mustRelease );
281
- }
261
+ @ Exclusive @ Cached ProfileClassNode classProfile ) throws UnknownIdentifierException , UnsupportedMessageException {
262
+ // do not convert wrap 'object.object' since that is really the native pointer object
263
+ return classProfile .profile (toJavaNode .execute (lib .readMember (object .getPtr (), NativeMember .OB_TYPE .getMemberName ())));
282
264
}
283
265
284
266
@ Specialization (guards = {"!lib.hasMembers(object.getPtr())" }, //
@@ -290,38 +272,27 @@ static Object getNativeClassByMemberAttachType(PythonAbstractNativeObject object
290
272
@ Exclusive @ Cached PCallCapiFunction callGetObTypeNode ,
291
273
@ Exclusive @ Cached CExtNodes .GetLLVMType getLLVMType ,
292
274
@ Exclusive @ Cached ToJavaNode toJavaNode ,
293
- @ Exclusive @ Cached ProfileClassNode classProfile , @ Exclusive @ Cached GilNode gil ) throws UnknownIdentifierException , UnsupportedMessageException {
294
- boolean mustRelease = gil .acquire ();
295
- try {
296
- Object typedPtr = callGetObTypeNode .call (NativeCAPISymbol .FUN_POLYGLOT_FROM_TYPED , object .getPtr (), getLLVMType .execute (CApiContext .LLVMType .PyObject ));
297
- return classProfile .profile (toJavaNode .execute (lib .readMember (typedPtr , NativeMember .OB_TYPE .getMemberName ())));
298
- } finally {
299
- gil .release (mustRelease );
300
- }
275
+ @ Exclusive @ Cached ProfileClassNode classProfile ) throws UnknownIdentifierException , UnsupportedMessageException {
276
+ Object typedPtr = callGetObTypeNode .call (NativeCAPISymbol .FUN_POLYGLOT_FROM_TYPED , object .getPtr (), getLLVMType .execute (CApiContext .LLVMType .PyObject ));
277
+ return classProfile .profile (toJavaNode .execute (lib .readMember (typedPtr , NativeMember .OB_TYPE .getMemberName ())));
301
278
}
302
279
303
280
@ Specialization (replaces = {"getNativeClassCached" , "getNativeClassCachedIdentity" , "getNativeClassByMember" , "getNativeClassByMemberAttachType" })
304
281
static Object getNativeClass (PythonAbstractNativeObject object ,
305
282
@ Exclusive @ Cached PCallCapiFunction callGetObTypeNode ,
306
283
@ Exclusive @ Cached AsPythonObjectNode toJavaNode ,
307
- @ Exclusive @ Cached ProfileClassNode classProfile , @ Exclusive @ Cached GilNode gil ) {
308
- boolean mustRelease = gil .acquire ();
309
- try {
310
- // do not convert wrap 'object.object' since that is really the native pointer
311
- // object
312
- return classProfile .profile (toJavaNode .execute (callGetObTypeNode .call (FUN_GET_OB_TYPE , object .getPtr ())));
313
- } finally {
314
- gil .release (mustRelease );
315
- }
284
+ @ Exclusive @ Cached ProfileClassNode classProfile ) {
285
+ // do not convert wrap 'object.object' since that is really the native pointer object
286
+ return classProfile .profile (toJavaNode .execute (callGetObTypeNode .call (FUN_GET_OB_TYPE , object .getPtr ())));
316
287
}
317
288
318
289
static boolean isSame (InteropLibrary lib , PythonAbstractNativeObject cachedObject , PythonAbstractNativeObject object ) {
319
290
return lib .isIdentical (cachedObject .object , object .object , lib );
320
291
}
321
292
322
- public static Object getNativeClassUncached (PythonAbstractNativeObject object , GilNode gil ) {
293
+ public static Object getNativeClassUncached (PythonAbstractNativeObject object ) {
323
294
// do not wrap 'object.object' since that is really the native pointer object
324
- return getNativeClass (object , PCallCapiFunction .getUncached (), AsPythonObjectNodeGen .getUncached (), ProfileClassNodeGen .getUncached (), gil );
295
+ return getNativeClass (object , PCallCapiFunction .getUncached (), AsPythonObjectNodeGen .getUncached (), ProfileClassNodeGen .getUncached ());
325
296
}
326
297
327
298
}
@@ -336,7 +307,8 @@ boolean isIdentical(Object other, InteropLibrary otherInterop,
336
307
@ Cached ("createClassProfile()" ) ValueProfile otherProfile ,
337
308
@ CachedLibrary (limit = "1" ) InteropLibrary thisLib ,
338
309
@ CachedLibrary ("this.object" ) InteropLibrary objLib ,
339
- @ CachedLibrary (limit = "1" ) InteropLibrary otherObjLib , @ Exclusive @ Cached GilNode gil ) {
310
+ @ CachedLibrary (limit = "1" ) InteropLibrary otherObjLib ,
311
+ @ Exclusive @ Cached GilNode gil ) {
340
312
boolean mustRelease = gil .acquire ();
341
313
try {
342
314
Object profiled = otherProfile .profile (other );
@@ -368,7 +340,8 @@ static TriState doOther(PythonAbstractNativeObject receiver, Object other) {
368
340
@ ExportMessage (library = PythonObjectLibrary .class , name = "isLazyPythonClass" )
369
341
@ ExportMessage (library = InteropLibrary .class )
370
342
boolean isMetaObject (
371
- @ Exclusive @ Cached TypeNodes .IsTypeNode isType , @ Exclusive @ Cached GilNode gil ) {
343
+ @ Exclusive @ Cached TypeNodes .IsTypeNode isType ,
344
+ @ Exclusive @ Cached GilNode gil ) {
372
345
boolean mustRelease = gil .acquire ();
373
346
try {
374
347
return isType .execute (this );
@@ -382,7 +355,8 @@ boolean isMetaInstance(Object instance,
382
355
@ Shared ("isType" ) @ Cached TypeNodes .IsTypeNode isType ,
383
356
@ CachedLibrary (limit = "3" ) PythonObjectLibrary plib ,
384
357
@ Cached PForeignToPTypeNode convert ,
385
- @ Cached IsSubtypeNode isSubtype , @ Exclusive @ Cached GilNode gil ) throws UnsupportedMessageException {
358
+ @ Cached IsSubtypeNode isSubtype ,
359
+ @ Exclusive @ Cached GilNode gil ) throws UnsupportedMessageException {
386
360
boolean mustRelease = gil .acquire ();
387
361
try {
388
362
if (!isType .execute (this )) {
@@ -398,7 +372,8 @@ boolean isMetaInstance(Object instance,
398
372
String getMetaSimpleName (
399
373
@ Shared ("isType" ) @ Cached TypeNodes .IsTypeNode isType ,
400
374
@ Shared ("getTypeMember" ) @ Cached GetTypeMemberNode getTpNameNode ,
401
- @ Shared ("castToJavaStringNode" ) @ Cached CastToJavaStringNode castToJavaStringNode , @ Exclusive @ Cached GilNode gil ) throws UnsupportedMessageException {
375
+ @ Shared ("castToJavaStringNode" ) @ Cached CastToJavaStringNode castToJavaStringNode ,
376
+ @ Exclusive @ Cached GilNode gil ) throws UnsupportedMessageException {
402
377
return getSimpleName (getMetaQualifiedName (isType , getTpNameNode , castToJavaStringNode , gil ));
403
378
}
404
379
@@ -415,7 +390,8 @@ private static String getSimpleName(String fqname) {
415
390
String getMetaQualifiedName (
416
391
@ Shared ("isType" ) @ Cached TypeNodes .IsTypeNode isType ,
417
392
@ Shared ("getTypeMember" ) @ Cached GetTypeMemberNode getTpNameNode ,
418
- @ Shared ("castToJavaStringNode" ) @ Cached CastToJavaStringNode castToJavaStringNode , @ Exclusive @ Cached GilNode gil ) throws UnsupportedMessageException {
393
+ @ Shared ("castToJavaStringNode" ) @ Cached CastToJavaStringNode castToJavaStringNode ,
394
+ @ Exclusive @ Cached GilNode gil ) throws UnsupportedMessageException {
419
395
boolean mustRelease = gil .acquire ();
420
396
try {
421
397
if (!isType .execute (this )) {
0 commit comments