Skip to content

Commit 867a7bf

Browse files
committed
don't synchronize handle table access, we should be holding the GIL anyway
1 parent c722323 commit 867a7bf

File tree

1 file changed

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

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@
234234
import com.oracle.graal.python.nodes.object.GetClassNode;
235235
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
236236
import com.oracle.graal.python.runtime.AsyncHandler;
237+
import com.oracle.graal.python.runtime.GilNode;
237238
import com.oracle.graal.python.runtime.PythonContext;
238239
import com.oracle.graal.python.runtime.PythonOptions;
239240
import com.oracle.graal.python.runtime.PythonOptions.HPyBackendMode;
@@ -2485,7 +2486,8 @@ public GraalHPyHandle createField(Object delegate, int idx) {
24852486
return GraalHPyHandle.createField(delegate, idx);
24862487
}
24872488

2488-
public synchronized GraalHPyHandle createGlobal(Object delegate, int idx) {
2489+
public GraalHPyHandle createGlobal(Object delegate, int idx) {
2490+
assert !GilNode.getUncached().acquire(PythonContext.get(null)) : "Gil not held when creating global";
24892491
final int newIdx;
24902492
if (idx <= 0) {
24912493
newIdx = allocateHPyGlobal();
@@ -2500,7 +2502,7 @@ public synchronized GraalHPyHandle createGlobal(Object delegate, int idx) {
25002502
return h;
25012503
}
25022504

2503-
private synchronized int allocateHPyGlobal() {
2505+
private int allocateHPyGlobal() {
25042506
int handle = 0;
25052507
for (int i = 1; i < hpyGlobalsTable.length; i++) {
25062508
if (hpyGlobalsTable[i] == null) {
@@ -2620,17 +2622,20 @@ private void allocateNativeSpacePointersMirror() {
26202622
}
26212623
}
26222624

2623-
public synchronized GraalHPyHandle getObjectForHPyHandle(int handle) {
2625+
public GraalHPyHandle getObjectForHPyHandle(int handle) {
2626+
assert !GilNode.getUncached().acquire(PythonContext.get(null)) : "Gil not held when resolving object from handle";
26242627
assert !GraalHPyBoxing.isBoxedInt(handle) && !GraalHPyBoxing.isBoxedDouble(handle) : "trying to lookup boxed primitive";
26252628
return hpyHandleTable[handle];
26262629
}
26272630

2628-
public synchronized GraalHPyHandle getObjectForHPyGlobal(int handle) {
2631+
public GraalHPyHandle getObjectForHPyGlobal(int handle) {
2632+
assert !GilNode.getUncached().acquire(PythonContext.get(null)) : "Gil not held when resolving object from global";
26292633
assert !GraalHPyBoxing.isBoxedInt(handle) && !GraalHPyBoxing.isBoxedDouble(handle) : "trying to lookup boxed primitive";
26302634
return hpyGlobalsTable[handle];
26312635
}
26322636

2633-
synchronized boolean releaseHPyHandleForObject(int handle) {
2637+
boolean releaseHPyHandleForObject(int handle) {
2638+
assert !GilNode.getUncached().acquire(PythonContext.get(null)) : "Gil not held when releasing handle";
26342639
assert handle != 0 : "NULL handle cannot be released";
26352640
assert hpyHandleTable[handle] != null : PythonUtils.format("releasing handle that has already been released: %d", handle);
26362641
if (LOGGER.isLoggable(Level.FINER)) {

0 commit comments

Comments
 (0)