@@ -189,25 +189,20 @@ public Object asIndexWithState(ThreadState threadState,
189189 @ Exclusive @ Cached ConditionProfile resultProfile ,
190190 @ Exclusive @ Cached ConditionProfile gotState ,
191191 @ 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 );
204198 }
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" );
208202 }
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 );
211206 }
212207 }
213208
@@ -216,19 +211,14 @@ public PDict getDict(
216211 @ Exclusive @ Cached PRaiseNode raiseNode ,
217212 @ Exclusive @ Cached ToSulongNode toSulong ,
218213 @ 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 );
232222 }
233223 }
234224
@@ -243,8 +233,7 @@ static Assumption getSingleContextAssumption() {
243233 @ SuppressWarnings ("unused" )
244234 static Object getNativeClassCachedIdentity (PythonAbstractNativeObject object ,
245235 @ 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 ) {
248237 // TODO: (tfel) is this really something we can do? It's so rare for this class to
249238 // change that it shouldn't be worth the effort, but in native code, anything can
250239 // happen. OTOH, CPython also has caches that can become invalid when someone just
@@ -256,8 +245,7 @@ static Object getNativeClassCachedIdentity(PythonAbstractNativeObject object,
256245 @ SuppressWarnings ("unused" )
257246 static Object getNativeClassCached (PythonAbstractNativeObject object ,
258247 @ 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 ,
261249 @ CachedLibrary (limit = "3" ) @ SuppressWarnings ("unused" ) InteropLibrary lib ) {
262250 // TODO same as for 'getNativeClassCachedIdentity'
263251 return cachedClass ;
@@ -270,15 +258,9 @@ static Object getNativeClassCached(PythonAbstractNativeObject object,
270258 static Object getNativeClassByMember (PythonAbstractNativeObject object ,
271259 @ CachedLibrary ("object.getPtr()" ) InteropLibrary lib ,
272260 @ 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 ())));
282264 }
283265
284266 @ Specialization (guards = {"!lib.hasMembers(object.getPtr())" }, //
@@ -290,38 +272,27 @@ static Object getNativeClassByMemberAttachType(PythonAbstractNativeObject object
290272 @ Exclusive @ Cached PCallCapiFunction callGetObTypeNode ,
291273 @ Exclusive @ Cached CExtNodes .GetLLVMType getLLVMType ,
292274 @ 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 ())));
301278 }
302279
303280 @ Specialization (replaces = {"getNativeClassCached" , "getNativeClassCachedIdentity" , "getNativeClassByMember" , "getNativeClassByMemberAttachType" })
304281 static Object getNativeClass (PythonAbstractNativeObject object ,
305282 @ Exclusive @ Cached PCallCapiFunction callGetObTypeNode ,
306283 @ 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 ())));
316287 }
317288
318289 static boolean isSame (InteropLibrary lib , PythonAbstractNativeObject cachedObject , PythonAbstractNativeObject object ) {
319290 return lib .isIdentical (cachedObject .object , object .object , lib );
320291 }
321292
322- public static Object getNativeClassUncached (PythonAbstractNativeObject object , GilNode gil ) {
293+ public static Object getNativeClassUncached (PythonAbstractNativeObject object ) {
323294 // 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 ());
325296 }
326297
327298 }
@@ -336,7 +307,8 @@ boolean isIdentical(Object other, InteropLibrary otherInterop,
336307 @ Cached ("createClassProfile()" ) ValueProfile otherProfile ,
337308 @ CachedLibrary (limit = "1" ) InteropLibrary thisLib ,
338309 @ 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 ) {
340312 boolean mustRelease = gil .acquire ();
341313 try {
342314 Object profiled = otherProfile .profile (other );
@@ -368,7 +340,8 @@ static TriState doOther(PythonAbstractNativeObject receiver, Object other) {
368340 @ ExportMessage (library = PythonObjectLibrary .class , name = "isLazyPythonClass" )
369341 @ ExportMessage (library = InteropLibrary .class )
370342 boolean isMetaObject (
371- @ Exclusive @ Cached TypeNodes .IsTypeNode isType , @ Exclusive @ Cached GilNode gil ) {
343+ @ Exclusive @ Cached TypeNodes .IsTypeNode isType ,
344+ @ Exclusive @ Cached GilNode gil ) {
372345 boolean mustRelease = gil .acquire ();
373346 try {
374347 return isType .execute (this );
@@ -382,7 +355,8 @@ boolean isMetaInstance(Object instance,
382355 @ Shared ("isType" ) @ Cached TypeNodes .IsTypeNode isType ,
383356 @ CachedLibrary (limit = "3" ) PythonObjectLibrary plib ,
384357 @ Cached PForeignToPTypeNode convert ,
385- @ Cached IsSubtypeNode isSubtype , @ Exclusive @ Cached GilNode gil ) throws UnsupportedMessageException {
358+ @ Cached IsSubtypeNode isSubtype ,
359+ @ Exclusive @ Cached GilNode gil ) throws UnsupportedMessageException {
386360 boolean mustRelease = gil .acquire ();
387361 try {
388362 if (!isType .execute (this )) {
@@ -398,7 +372,8 @@ boolean isMetaInstance(Object instance,
398372 String getMetaSimpleName (
399373 @ Shared ("isType" ) @ Cached TypeNodes .IsTypeNode isType ,
400374 @ 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 {
402377 return getSimpleName (getMetaQualifiedName (isType , getTpNameNode , castToJavaStringNode , gil ));
403378 }
404379
@@ -415,7 +390,8 @@ private static String getSimpleName(String fqname) {
415390 String getMetaQualifiedName (
416391 @ Shared ("isType" ) @ Cached TypeNodes .IsTypeNode isType ,
417392 @ 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 {
419395 boolean mustRelease = gil .acquire ();
420396 try {
421397 if (!isType .execute (this )) {
0 commit comments