Skip to content

Commit e2ec354

Browse files
committed
opt GIL: GraalHPyContext
1 parent ce14211 commit e2ec354

File tree

1 file changed

+15
-43
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy

1 file changed

+15
-43
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContext.java

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3939
* SOFTWARE.
4040
*/
41+
// skip GIL
4142
package com.oracle.graal.python.builtins.objects.cext.hpy;
4243

4344
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.MemoryError;
@@ -132,7 +133,6 @@
132133
import com.oracle.graal.python.nodes.expression.UnaryArithmetic;
133134
import com.oracle.graal.python.runtime.AsyncHandler;
134135
import com.oracle.graal.python.runtime.ExecutionContext.CalleeContext;
135-
import com.oracle.graal.python.runtime.GilNode;
136136
import com.oracle.graal.python.runtime.PythonContext;
137137
import com.oracle.graal.python.runtime.exception.PException;
138138
import com.oracle.graal.python.util.OverflowException;
@@ -144,7 +144,6 @@
144144
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
145145
import com.oracle.truffle.api.TruffleLogger;
146146
import com.oracle.truffle.api.dsl.Cached;
147-
import com.oracle.truffle.api.dsl.Cached.Exclusive;
148147
import com.oracle.truffle.api.dsl.GenerateUncached;
149148
import com.oracle.truffle.api.dsl.ImportStatic;
150149
import com.oracle.truffle.api.dsl.Specialization;
@@ -541,41 +540,24 @@ public PException getCurrentException() {
541540
}
542541

543542
@ExportMessage
544-
boolean isPointer(@Exclusive @Cached GilNode gil) {
545-
boolean mustRelease = gil.acquire();
546-
try {
547-
return nativePointer != null;
548-
} finally {
549-
gil.release(mustRelease);
550-
}
543+
boolean isPointer() {
544+
return nativePointer != null;
551545
}
552546

553547
@ExportMessage(limit = "1")
554548
@SuppressWarnings("static-method")
555-
long asPointer(
556-
@CachedLibrary("this.nativePointer") InteropLibrary interopLibrary, @Exclusive @Cached GilNode gil) throws UnsupportedMessageException {
557-
boolean mustRelease = gil.acquire();
558-
try {
559-
if (isPointer(gil)) {
560-
return interopLibrary.asPointer(nativePointer);
561-
}
562-
CompilerDirectives.transferToInterpreterAndInvalidate();
563-
throw UnsupportedMessageException.create();
564-
} finally {
565-
gil.release(mustRelease);
549+
long asPointer(@CachedLibrary("this.nativePointer") InteropLibrary interopLibrary) throws UnsupportedMessageException {
550+
if (isPointer()) {
551+
return interopLibrary.asPointer(nativePointer);
566552
}
553+
CompilerDirectives.transferToInterpreterAndInvalidate();
554+
throw UnsupportedMessageException.create();
567555
}
568556

569557
@ExportMessage
570-
void toNative(
571-
@Cached PCallHPyFunction callContextToNativeNode, @Exclusive @Cached GilNode gil) {
572-
boolean mustRelease = gil.acquire();
573-
try {
574-
if (!isPointer(gil)) {
575-
nativePointer = callContextToNativeNode.call(this, GRAAL_HPY_CONTEXT_TO_NATIVE, this);
576-
}
577-
} finally {
578-
gil.release(mustRelease);
558+
void toNative(@Cached PCallHPyFunction callContextToNativeNode) {
559+
if (!isPointer()) {
560+
nativePointer = callContextToNativeNode.call(this, GRAAL_HPY_CONTEXT_TO_NATIVE, this);
579561
}
580562
}
581563

@@ -598,24 +580,14 @@ Object getMembers(@SuppressWarnings("unused") boolean includeInternal) {
598580

599581
@ExportMessage
600582
@SuppressWarnings("static-method")
601-
boolean isMemberReadable(String key, @Exclusive @Cached GilNode gil) {
602-
boolean mustRelease = gil.acquire();
603-
try {
604-
return HPyContextMembers.getByName(key) != null;
605-
} finally {
606-
gil.release(mustRelease);
607-
}
583+
boolean isMemberReadable(String key) {
584+
return HPyContextMembers.getByName(key) != null;
608585
}
609586

610587
@ExportMessage
611588
Object readMember(String key,
612-
@Cached GraalHPyReadMemberNode readMemberNode, @Exclusive @Cached GilNode gil) {
613-
boolean mustRelease = gil.acquire();
614-
try {
615-
return readMemberNode.execute(this, key);
616-
} finally {
617-
gil.release(mustRelease);
618-
}
589+
@Cached GraalHPyReadMemberNode readMemberNode) {
590+
return readMemberNode.execute(this, key);
619591
}
620592

621593
@ExportMessage

0 commit comments

Comments
 (0)