38
38
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39
39
* SOFTWARE.
40
40
*/
41
+ // skip GIL
41
42
package com .oracle .graal .python .builtins .objects .cext .capi ;
42
43
43
44
import static com .oracle .graal .python .builtins .objects .cext .capi .NativeCAPISymbol .FUN_GET_THREAD_STATE_TYPE_ID ;
57
58
import com .oracle .graal .python .builtins .objects .type .PythonClass ;
58
59
import com .oracle .graal .python .nodes .PNodeWithContext ;
59
60
import com .oracle .graal .python .nodes .object .GetClassNode ;
60
- import com .oracle .graal .python .runtime .GilNode ;
61
61
import com .oracle .graal .python .runtime .PythonContext ;
62
62
import com .oracle .graal .python .runtime .PythonOptions ;
63
63
import com .oracle .graal .python .runtime .exception .PException ;
64
64
import com .oracle .graal .python .runtime .object .PythonObjectFactory ;
65
65
import com .oracle .truffle .api .Assumption ;
66
66
import com .oracle .truffle .api .CompilerDirectives ;
67
67
import com .oracle .truffle .api .Truffle ;
68
- import com .oracle .truffle .api .dsl .Bind ;
69
68
import com .oracle .truffle .api .dsl .Cached ;
70
69
import com .oracle .truffle .api .dsl .Cached .Exclusive ;
71
70
import com .oracle .truffle .api .dsl .Cached .Shared ;
@@ -141,13 +140,8 @@ protected Object getMembers(@SuppressWarnings("unused") boolean includeInternal,
141
140
142
141
@ ExportMessage
143
142
protected Object readMember (String member ,
144
- @ Exclusive @ Cached ThreadStateReadNode readNode , @ Exclusive @ Cached GilNode gil ) {
145
- boolean mustRelease = gil .acquire ();
146
- try {
147
- return readNode .execute (member );
148
- } finally {
149
- gil .release (mustRelease );
150
- }
143
+ @ Exclusive @ Cached ThreadStateReadNode readNode ) {
144
+ return readNode .execute (member );
151
145
}
152
146
153
147
@ ImportStatic (PThreadState .class )
@@ -304,13 +298,8 @@ protected boolean isMemberInsertable(@SuppressWarnings("unused") String member)
304
298
@ ExportMessage
305
299
protected void writeMember (String member , Object value ,
306
300
@ Exclusive @ Cached ThreadStateWriteNode writeNode ,
307
- @ Exclusive @ Cached ToJavaNode toJavaNode , @ Exclusive @ Cached GilNode gil ) throws UnknownIdentifierException {
308
- boolean mustRelease = gil .acquire ();
309
- try {
310
- writeNode .execute (member , toJavaNode .execute (value ));
311
- } finally {
312
- gil .release (mustRelease );
313
- }
301
+ @ Exclusive @ Cached ToJavaNode toJavaNode ) throws UnknownIdentifierException {
302
+ writeNode .execute (member , toJavaNode .execute (value ));
314
303
}
315
304
316
305
@ ExportMessage
@@ -441,44 +430,29 @@ protected static boolean isCaughtExceptionMember(Object key) {
441
430
// TO POINTER / AS POINTER / TO NATIVE
442
431
@ ExportMessage
443
432
protected boolean isPointer (
444
- @ Exclusive @ Cached IsPointerNode pIsPointerNode , @ Exclusive @ Cached GilNode gil ) {
445
- boolean mustRelease = gil .acquire ();
446
- try {
447
- return pIsPointerNode .execute (this );
448
- } finally {
449
- gil .release (mustRelease );
450
- }
433
+ @ Exclusive @ Cached IsPointerNode pIsPointerNode ) {
434
+ return pIsPointerNode .execute (this );
451
435
}
452
436
453
437
@ ExportMessage
454
438
public long asPointer (
455
439
@ CachedLibrary ("this" ) PythonNativeWrapperLibrary lib ,
456
- @ CachedLibrary (limit = "1" ) InteropLibrary interopLibrary , @ Exclusive @ Cached GilNode gil ) throws UnsupportedMessageException {
457
- boolean mustRelease = gil .acquire ();
458
- try {
459
- Object nativePointer = lib .getNativePointer (this );
460
- if (nativePointer instanceof Long ) {
461
- return (long ) nativePointer ;
462
- }
463
- return interopLibrary .asPointer (nativePointer );
464
- } finally {
465
- gil .release (mustRelease );
440
+ @ CachedLibrary (limit = "1" ) InteropLibrary interopLibrary ) throws UnsupportedMessageException {
441
+ Object nativePointer = lib .getNativePointer (this );
442
+ if (nativePointer instanceof Long ) {
443
+ return (long ) nativePointer ;
466
444
}
445
+ return interopLibrary .asPointer (nativePointer );
467
446
}
468
447
469
448
@ ExportMessage
470
449
protected void toNative (
471
450
@ CachedLibrary ("this" ) PythonNativeWrapperLibrary lib ,
472
451
@ Exclusive @ Cached ToPyObjectNode toPyObjectNode ,
473
- @ Exclusive @ Cached InvalidateNativeObjectsAllManagedNode invalidateNode , @ Exclusive @ Cached GilNode gil ) {
474
- boolean mustRelease = gil .acquire ();
475
- try {
476
- invalidateNode .execute ();
477
- if (!lib .isNative (this )) {
478
- setNativePointer (toPyObjectNode .execute (this ));
479
- }
480
- } finally {
481
- gil .release (mustRelease );
452
+ @ Exclusive @ Cached InvalidateNativeObjectsAllManagedNode invalidateNode ) {
453
+ invalidateNode .execute ();
454
+ if (!lib .isNative (this )) {
455
+ setNativePointer (toPyObjectNode .execute (this ));
482
456
}
483
457
}
484
458
@@ -491,26 +465,15 @@ protected boolean hasNativeType() {
491
465
abstract static class GetTypeIDNode {
492
466
@ Specialization (assumptions = "singleNativeContextAssumption()" )
493
467
static Object doByteArray (@ SuppressWarnings ("unused" ) PThreadState receiver ,
494
- @ Exclusive @ Cached GilNode gil ,
495
- @ Bind ("gil.acquire()" ) boolean mustRelease ,
496
468
@ Exclusive @ Cached ("callGetThreadStateTypeIDUncached()" ) Object nativeType ) {
497
- try {
498
- // TODO(fa): use weak reference ?
499
- return nativeType ;
500
- } finally {
501
- gil .release (mustRelease );
502
- }
469
+ // TODO(fa): use weak reference ?
470
+ return nativeType ;
503
471
}
504
472
505
473
@ Specialization (replaces = "doByteArray" )
506
474
static Object doByteArrayMultiCtx (@ SuppressWarnings ("unused" ) PThreadState receiver ,
507
- @ Exclusive @ Cached PCallCapiFunction callUnaryNode , @ Exclusive @ Cached GilNode gil ) {
508
- boolean mustRelease = gil .acquire ();
509
- try {
510
- return callUnaryNode .call (FUN_GET_THREAD_STATE_TYPE_ID );
511
- } finally {
512
- gil .release (mustRelease );
513
- }
475
+ @ Exclusive @ Cached PCallCapiFunction callUnaryNode ) {
476
+ return callUnaryNode .call (FUN_GET_THREAD_STATE_TYPE_ID );
514
477
}
515
478
516
479
protected static Object callGetThreadStateTypeIDUncached () {
0 commit comments