Skip to content

Commit 1a9f1d8

Browse files
committed
opt GIL: CArrayWrappers
1 parent 9d8910f commit 1a9f1d8

File tree

1 file changed

+26
-56
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi

1 file changed

+26
-56
lines changed

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

Lines changed: 26 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -75,44 +75,29 @@ public CArrayWrapper(Object delegate) {
7575

7676
@ExportMessage
7777
public boolean isPointer(
78-
@Exclusive @Cached IsPointerNode pIsPointerNode, @Exclusive @Cached GilNode gil) {
79-
boolean mustRelease = gil.acquire();
80-
try {
81-
return pIsPointerNode.execute(this);
82-
} finally {
83-
gil.release(mustRelease);
84-
}
78+
@Exclusive @Cached IsPointerNode pIsPointerNode) {
79+
return pIsPointerNode.execute(this);
8580
}
8681

8782
@ExportMessage
8883
public long asPointer(
8984
@CachedLibrary("this") PythonNativeWrapperLibrary lib,
90-
@CachedLibrary(limit = "1") InteropLibrary interopLibrary, @Exclusive @Cached GilNode gil) throws UnsupportedMessageException {
91-
boolean mustRelease = gil.acquire();
92-
try {
93-
Object nativePointer = lib.getNativePointer(this);
94-
if (nativePointer instanceof Long) {
95-
return (long) nativePointer;
96-
}
97-
return interopLibrary.asPointer(nativePointer);
98-
} finally {
99-
gil.release(mustRelease);
85+
@CachedLibrary(limit = "1") InteropLibrary interopLibrary) throws UnsupportedMessageException {
86+
Object nativePointer = lib.getNativePointer(this);
87+
if (nativePointer instanceof Long) {
88+
return (long) nativePointer;
10089
}
90+
return interopLibrary.asPointer(nativePointer);
10191
}
10292

10393
@ExportMessage
10494
public void toNative(
10595
@CachedLibrary("this") PythonNativeWrapperLibrary lib,
10696
@Exclusive @Cached AsCharPointerNode asCharPointerNode,
107-
@Exclusive @Cached InvalidateNativeObjectsAllManagedNode invalidateNode, @Exclusive @Cached GilNode gil) {
108-
boolean mustRelease = gil.acquire();
109-
try {
110-
invalidateNode.execute();
111-
if (!lib.isNative(this)) {
112-
setNativePointer(asCharPointerNode.execute(lib.getDelegate(this)));
113-
}
114-
} finally {
115-
gil.release(mustRelease);
97+
@Exclusive @Cached InvalidateNativeObjectsAllManagedNode invalidateNode) {
98+
invalidateNode.execute();
99+
if (!lib.isNative(this)) {
100+
setNativePointer(asCharPointerNode.execute(lib.getDelegate(this)));
116101
}
117102
}
118103
}
@@ -147,25 +132,20 @@ final boolean hasArrayElements() {
147132

148133
@ExportMessage
149134
final Object readArrayElement(long index,
150-
@CachedLibrary("this") PythonNativeWrapperLibrary lib, @Exclusive @Cached GilNode gil) throws InvalidArrayIndexException {
151-
boolean mustRelease = gil.acquire();
135+
@CachedLibrary("this") PythonNativeWrapperLibrary lib) throws InvalidArrayIndexException {
152136
try {
153-
try {
154-
int idx = PInt.intValueExact(index);
155-
String s = (String) lib.getDelegate(this);
156-
if (idx >= 0 && idx < s.length()) {
157-
return s.charAt(idx);
158-
} else if (idx == s.length()) {
159-
return '\0';
160-
}
161-
} catch (OverflowException e) {
162-
// fall through
137+
int idx = PInt.intValueExact(index);
138+
String s = (String) lib.getDelegate(this);
139+
if (idx >= 0 && idx < s.length()) {
140+
return s.charAt(idx);
141+
} else if (idx == s.length()) {
142+
return '\0';
163143
}
164-
CompilerDirectives.transferToInterpreterAndInvalidate();
165-
throw InvalidArrayIndexException.create(index);
166-
} finally {
167-
gil.release(mustRelease);
144+
} catch (OverflowException e) {
145+
// fall through
168146
}
147+
CompilerDirectives.transferToInterpreterAndInvalidate();
148+
throw InvalidArrayIndexException.create(index);
169149
}
170150

171151
@ExportMessage
@@ -176,25 +156,15 @@ final boolean isArrayElementReadable(long identifier,
176156

177157
@ExportMessage
178158
@SuppressWarnings("static-method")
179-
protected boolean hasNativeType(@Exclusive @Cached GilNode gil) {
180-
boolean mustRelease = gil.acquire();
181-
try {
182-
return true;
183-
} finally {
184-
gil.release(mustRelease);
185-
}
159+
protected boolean hasNativeType() {
160+
return true;
186161
}
187162

188163
@ExportMessage
189164
protected Object getNativeType(
190165
@CachedLibrary("this") PythonNativeWrapperLibrary lib,
191-
@Exclusive @Cached PCallCapiFunction callByteArrayTypeIdNode, @Exclusive @Cached GilNode gil) {
192-
boolean mustRelease = gil.acquire();
193-
try {
194-
return callByteArrayTypeIdNode.call(FUN_GET_BYTE_ARRAY_TYPE_ID, ((String) lib.getDelegate(this)).length());
195-
} finally {
196-
gil.release(mustRelease);
197-
}
166+
@Exclusive @Cached PCallCapiFunction callByteArrayTypeIdNode) {
167+
return callByteArrayTypeIdNode.call(FUN_GET_BYTE_ARRAY_TYPE_ID, ((String) lib.getDelegate(this)).length());
198168
}
199169
}
200170

0 commit comments

Comments
 (0)