Skip to content

Commit 45ffd7e

Browse files
committed
simplify HPy argument array wrapper allocation code
1 parent 741ef10 commit 45ffd7e

File tree

2 files changed

+101
-318
lines changed

2 files changed

+101
-318
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2620,4 +2620,32 @@ public void finalizeContext() {
26202620
}
26212621
}
26222622
}
2623+
2624+
private static final long NATIVE_ARGUMENT_STACK_SIZE = (2 ^ 15) * SIZEOF_LONG; // 32k entries
2625+
private long nativeArgumentsStack = 0;
2626+
private int nativeArgumentStackPos = 0;
2627+
2628+
public final long createNativeArguments(Object[] delegate) {
2629+
if (nativeArgumentsStack == 0) {
2630+
CompilerDirectives.transferToInterpreterAndInvalidate();
2631+
nativeArgumentsStack = unsafe.allocateMemory(NATIVE_ARGUMENT_STACK_SIZE);
2632+
}
2633+
long arraySize = delegate.length * SIZEOF_LONG;
2634+
if (nativeArgumentStackPos + arraySize > NATIVE_ARGUMENT_STACK_SIZE) {
2635+
CompilerDirectives.transferToInterpreterAndInvalidate();
2636+
throw new InternalError("overflow on native argument stack");
2637+
}
2638+
long arrayPtr = nativeArgumentsStack;
2639+
nativeArgumentsStack += arraySize;
2640+
2641+
for (int i = 0; i < delegate.length; i++) {
2642+
unsafe.putLong(arrayPtr + i * SIZEOF_LONG, ((GraalHPyHandle) delegate[i]).getId(this, ConditionProfile.getUncached()));
2643+
}
2644+
return arrayPtr;
2645+
}
2646+
2647+
public final void freeNativeArgumentsArray(int size) {
2648+
long arraySize = size * SIZEOF_LONG;
2649+
nativeArgumentsStack -= arraySize;
2650+
}
26232651
}

0 commit comments

Comments
 (0)