Skip to content

Commit f9988e1

Browse files
committed
opt GIL: PyMemoryViewBufferWrapper
1 parent 1a9f1d8 commit f9988e1

File tree

1 file changed

+14
-41
lines changed

1 file changed

+14
-41
lines changed

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

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import com.oracle.graal.python.runtime.sequence.storage.NativeSequenceStorage;
5555
import com.oracle.truffle.api.Assumption;
5656
import com.oracle.truffle.api.CompilerDirectives;
57-
import com.oracle.truffle.api.dsl.Bind;
5857
import com.oracle.truffle.api.dsl.Cached;
5958
import com.oracle.truffle.api.dsl.Cached.Exclusive;
6059
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -278,44 +277,29 @@ static Object error(@SuppressWarnings("unused") PMemoryView object, String key)
278277

279278
@ExportMessage
280279
protected boolean isPointer(
281-
@Exclusive @Cached CExtNodes.IsPointerNode pIsPointerNode, @Exclusive @Cached GilNode gil) {
282-
boolean mustRelease = gil.acquire();
283-
try {
284-
return pIsPointerNode.execute(this);
285-
} finally {
286-
gil.release(mustRelease);
287-
}
280+
@Exclusive @Cached CExtNodes.IsPointerNode pIsPointerNode) {
281+
return pIsPointerNode.execute(this);
288282
}
289283

290284
@ExportMessage
291285
public long asPointer(
292286
@CachedLibrary("this") PythonNativeWrapperLibrary lib,
293-
@CachedLibrary(limit = "1") InteropLibrary interopLibrary, @Exclusive @Cached GilNode gil) throws UnsupportedMessageException {
294-
boolean mustRelease = gil.acquire();
295-
try {
296-
Object nativePointer = lib.getNativePointer(this);
297-
if (nativePointer instanceof Long) {
298-
return (long) nativePointer;
299-
}
300-
return interopLibrary.asPointer(nativePointer);
301-
} finally {
302-
gil.release(mustRelease);
287+
@CachedLibrary(limit = "1") InteropLibrary interopLibrary) throws UnsupportedMessageException {
288+
Object nativePointer = lib.getNativePointer(this);
289+
if (nativePointer instanceof Long) {
290+
return (long) nativePointer;
303291
}
292+
return interopLibrary.asPointer(nativePointer);
304293
}
305294

306295
@ExportMessage
307296
protected void toNative(
308297
@CachedLibrary("this") PythonNativeWrapperLibrary lib,
309298
@Exclusive @Cached DynamicObjectNativeWrapper.ToPyObjectNode toPyObjectNode,
310-
@Exclusive @Cached InvalidateNativeObjectsAllManagedNode invalidateNode, @Exclusive @Cached GilNode gil) {
311-
boolean mustRelease = gil.acquire();
312-
try {
313-
invalidateNode.execute();
314-
if (!lib.isNative(this)) {
315-
setNativePointer(toPyObjectNode.execute(this));
316-
}
317-
} finally {
318-
gil.release(mustRelease);
299+
@Exclusive @Cached InvalidateNativeObjectsAllManagedNode invalidateNode) {
300+
invalidateNode.execute();
301+
if (!lib.isNative(this)) {
302+
setNativePointer(toPyObjectNode.execute(this));
319303
}
320304
}
321305

@@ -329,25 +313,14 @@ protected boolean hasNativeType() {
329313
abstract static class GetNativeType {
330314
@Specialization(assumptions = "singleNativeContextAssumption()")
331315
static Object doByteArray(@SuppressWarnings("unused") PyMemoryViewBufferWrapper receiver,
332-
@Exclusive @Cached GilNode gil,
333-
@Bind("gil.acquire()") boolean mustRelease,
334316
@Exclusive @Cached(value = "callGetThreadStateTypeIDUncached()") Object nativeType) {
335-
try {
336-
return nativeType;
337-
} finally {
338-
gil.release(mustRelease);
339-
}
317+
return nativeType;
340318
}
341319

342320
@Specialization(replaces = "doByteArray")
343321
static Object doByteArrayMultiCtx(@SuppressWarnings("unused") PyMemoryViewBufferWrapper receiver,
344-
@Exclusive @Cached CExtNodes.PCallCapiFunction callUnaryNode, @Exclusive @Cached GilNode gil) {
345-
boolean mustRelease = gil.acquire();
346-
try {
347-
return callUnaryNode.call(FUN_GET_PY_BUFFER_TYPEID);
348-
} finally {
349-
gil.release(mustRelease);
350-
}
322+
@Exclusive @Cached CExtNodes.PCallCapiFunction callUnaryNode) {
323+
return callUnaryNode.call(FUN_GET_PY_BUFFER_TYPEID);
351324
}
352325

353326
protected static Object callGetThreadStateTypeIDUncached() {

0 commit comments

Comments
 (0)