Skip to content

Commit ef5e4f0

Browse files
committed
opt GIL: PySequenceArrayWrapper
1 parent 6662d9a commit ef5e4f0

File tree

1 file changed

+20
-55
lines changed

1 file changed

+20
-55
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PySequenceArrayWrapper.java

Lines changed: 20 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,8 @@ public boolean equals(Object obj) {
141141
@ExportMessage
142142
final long getArraySize(
143143
@CachedLibrary("this") PythonNativeWrapperLibrary lib,
144-
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary objectLib, @Exclusive @Cached GilNode gil) {
145-
boolean mustRelease = gil.acquire();
146-
try {
147-
return objectLib.length(lib.getDelegate(this));
148-
} finally {
149-
gil.release(mustRelease);
150-
}
144+
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary objectLib) {
145+
return objectLib.length(lib.getDelegate(this));
151146
}
152147

153148
@ExportMessage
@@ -175,14 +170,9 @@ static int getCallSiteInlineCacheMaxDepth() {
175170
@ExportMessage
176171
final boolean isArrayElementReadable(long identifier,
177172
@CachedLibrary("this") PythonNativeWrapperLibrary lib,
178-
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary objectLib, @Exclusive @Cached GilNode gil) {
179-
boolean mustRelease = gil.acquire();
180-
try {
181-
// also include the implicit null-terminator
182-
return 0 <= identifier && identifier <= getArraySize(lib, objectLib, gil);
183-
} finally {
184-
gil.release(mustRelease);
185-
}
173+
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary objectLib) {
174+
// also include the implicit null-terminator
175+
return 0 <= identifier && identifier <= getArraySize(lib, objectLib);
186176
}
187177

188178
@ImportStatic({SpecialMethodNames.class, PySequenceArrayWrapper.class})
@@ -316,13 +306,8 @@ public void removeArrayElement(@SuppressWarnings("unused") long index) throws Un
316306
@ExportMessage
317307
public boolean isArrayElementModifiable(long index,
318308
@CachedLibrary("this") PythonNativeWrapperLibrary lib,
319-
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary objectLib, @Exclusive @Cached GilNode gil) {
320-
boolean mustRelease = gil.acquire();
321-
try {
322-
return 0 <= index && index <= getArraySize(lib, objectLib, gil);
323-
} finally {
324-
gil.release(mustRelease);
325-
}
309+
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary objectLib) {
310+
return 0 <= index && index <= getArraySize(lib, objectLib);
326311
}
327312

328313
@ExportMessage
@@ -407,15 +392,10 @@ void doGeneric(PythonAbstractObject sequence, Object idx, Object value,
407392
public void toNative(
408393
@CachedLibrary("this") PythonNativeWrapperLibrary lib,
409394
@Exclusive @Cached ToNativeArrayNode toPyObjectNode,
410-
@Exclusive @Cached InvalidateNativeObjectsAllManagedNode invalidateNode, @Exclusive @Cached GilNode gil) {
411-
boolean mustRelease = gil.acquire();
412-
try {
413-
invalidateNode.execute();
414-
if (!lib.isNative(this)) {
415-
setNativePointer(toPyObjectNode.execute(this));
416-
}
417-
} finally {
418-
gil.release(mustRelease);
395+
@Exclusive @Cached InvalidateNativeObjectsAllManagedNode invalidateNode) {
396+
invalidateNode.execute();
397+
if (!lib.isNative(this)) {
398+
setNativePointer(toPyObjectNode.execute(this));
419399
}
420400
}
421401

@@ -484,29 +464,19 @@ protected static boolean isNative(SequenceStorage s) {
484464

485465
@ExportMessage
486466
public boolean isPointer(
487-
@Cached IsPointerNode pIsPointerNode, @Exclusive @Cached GilNode gil) {
488-
boolean mustRelease = gil.acquire();
489-
try {
490-
return pIsPointerNode.execute(this);
491-
} finally {
492-
gil.release(mustRelease);
493-
}
467+
@Cached IsPointerNode pIsPointerNode) {
468+
return pIsPointerNode.execute(this);
494469
}
495470

496471
@ExportMessage
497472
public long asPointer(
498473
@CachedLibrary(limit = "1") InteropLibrary interopLibrary,
499-
@CachedLibrary("this") PythonNativeWrapperLibrary lib, @Exclusive @Cached GilNode gil) throws UnsupportedMessageException {
500-
boolean mustRelease = gil.acquire();
501-
try {
502-
Object nativePointer = lib.getNativePointer(this);
503-
if (nativePointer instanceof Long) {
504-
return (long) nativePointer;
505-
}
506-
return interopLibrary.asPointer(nativePointer);
507-
} finally {
508-
gil.release(mustRelease);
474+
@CachedLibrary("this") PythonNativeWrapperLibrary lib) throws UnsupportedMessageException {
475+
Object nativePointer = lib.getNativePointer(this);
476+
if (nativePointer instanceof Long) {
477+
return (long) nativePointer;
509478
}
479+
return interopLibrary.asPointer(nativePointer);
510480
}
511481

512482
@ExportMessage
@@ -518,13 +488,8 @@ protected boolean hasNativeType() {
518488
@ExportMessage
519489
Object getNativeType(
520490
@CachedLibrary("this") PythonNativeWrapperLibrary lib,
521-
@Exclusive @Cached GetTypeIDNode getTypeIDNode, @Exclusive @Cached GilNode gil) {
522-
boolean mustRelease = gil.acquire();
523-
try {
524-
return getTypeIDNode.execute(lib.getDelegate(this));
525-
} finally {
526-
gil.release(mustRelease);
527-
}
491+
@Exclusive @Cached GetTypeIDNode getTypeIDNode) {
492+
return getTypeIDNode.execute(lib.getDelegate(this));
528493
}
529494

530495
@GenerateUncached

0 commit comments

Comments
 (0)