Skip to content

Commit 0f5fe35

Browse files
committed
opt GIL: PyLongDigitsWrapper
1 parent ef5e4f0 commit 0f5fe35

File tree

1 file changed

+10
-32
lines changed

1 file changed

+10
-32
lines changed

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

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import com.oracle.graal.python.runtime.PythonOptions;
5353
import com.oracle.truffle.api.Assumption;
5454
import com.oracle.truffle.api.CompilerAsserts;
55-
import com.oracle.truffle.api.dsl.Bind;
5655
import com.oracle.truffle.api.dsl.Cached;
5756
import com.oracle.truffle.api.dsl.Cached.Exclusive;
5857
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -220,29 +219,19 @@ public void toNative(
220219

221220
@ExportMessage
222221
public boolean isPointer(
223-
@Cached IsPointerNode pIsPointerNode, @Exclusive @Cached GilNode gil) {
224-
boolean mustRelease = gil.acquire();
225-
try {
226-
return pIsPointerNode.execute(this);
227-
} finally {
228-
gil.release(mustRelease);
229-
}
222+
@Cached IsPointerNode pIsPointerNode) {
223+
return pIsPointerNode.execute(this);
230224
}
231225

232226
@ExportMessage
233227
public long asPointer(
234228
@CachedLibrary(limit = "1") InteropLibrary interopLibrary,
235-
@CachedLibrary("this") PythonNativeWrapperLibrary lib, @Exclusive @Cached GilNode gil) throws UnsupportedMessageException {
236-
boolean mustRelease = gil.acquire();
237-
try {
238-
Object nativePointer = lib.getNativePointer(this);
239-
if (nativePointer instanceof Long) {
240-
return (long) nativePointer;
241-
}
242-
return interopLibrary.asPointer(nativePointer);
243-
} finally {
244-
gil.release(mustRelease);
229+
@CachedLibrary("this") PythonNativeWrapperLibrary lib) throws UnsupportedMessageException {
230+
Object nativePointer = lib.getNativePointer(this);
231+
if (nativePointer instanceof Long) {
232+
return (long) nativePointer;
245233
}
234+
return interopLibrary.asPointer(nativePointer);
246235
}
247236

248237
@ExportMessage
@@ -260,25 +249,14 @@ static Object callGetUInt32ArrayTypeIDUncached(@SuppressWarnings("unused") PyLon
260249

261250
@Specialization(assumptions = "singleContextAssumption()")
262251
static Object doByteArray(@SuppressWarnings("unused") PyLongDigitsWrapper object,
263-
@Exclusive @Cached GilNode gil,
264-
@Bind("gil.acquire()") boolean mustRelease,
265252
@Exclusive @Cached("callGetUInt32ArrayTypeIDUncached(object)") Object nativeType) {
266-
try {
267-
return nativeType;
268-
} finally {
269-
gil.release(mustRelease);
270-
}
253+
return nativeType;
271254
}
272255

273256
@Specialization(replaces = "doByteArray")
274257
static Object doByteArrayMultiCtx(@SuppressWarnings("unused") PyLongDigitsWrapper object,
275-
@Cached PCallCapiFunction callGetTypeIDNode, @Exclusive @Cached GilNode gil) {
276-
boolean mustRelease = gil.acquire();
277-
try {
278-
return callGetTypeIDNode.call(FUN_GET_UINT32_ARRAY_TYPE_ID, 0);
279-
} finally {
280-
gil.release(mustRelease);
281-
}
258+
@Cached PCallCapiFunction callGetTypeIDNode) {
259+
return callGetTypeIDNode.call(FUN_GET_UINT32_ARRAY_TYPE_ID, 0);
282260
}
283261

284262
protected static Assumption singleContextAssumption() {

0 commit comments

Comments
 (0)