actually use PAGE_SIZE

This commit is contained in:
2024-08-24 00:35:31 +02:00
parent 5dddd7bf56
commit 2622d8073b
3 changed files with 8 additions and 3 deletions

View File

@@ -5,8 +5,11 @@ import java.nio.ByteBuffer;
class DhfsSupportNative {
static public final int PAGE_SIZE;
static {
System.load(DhfsNativeLibFinder.getLibPath().toAbsolutePath().toString());
PAGE_SIZE = getPageSizeInternal();
}
public static native void hello();
@@ -15,6 +18,5 @@ class DhfsSupportNative {
static native void dropByteBuffer(long token);
static native int getPageSize();
private static native int getPageSizeInternal();
}

View File

@@ -7,6 +7,9 @@ public class UninitializedByteBuffer {
private static final Cleaner CLEANER = Cleaner.create();
public static ByteBuffer allocateUninitialized(int size) {
if (size < DhfsSupportNative.PAGE_SIZE)
return ByteBuffer.allocateDirect(size);
var bb = new ByteBuffer[1];
long token = DhfsSupportNative.allocateUninitializedByteBuffer(bb, size);
var ret = bb[0];

View File

@@ -86,7 +86,7 @@ JNIEXPORT void JNICALL Java_com_usatiuk_dhfs_supportlib_DhfsSupportNative_dropBy
free((void*) addr);
}
JNIEXPORT jint JNICALL Java_com_usatiuk_dhfs_supportlib_DhfsSupportNative_getPageSize
JNIEXPORT jint JNICALL Java_com_usatiuk_dhfs_supportlib_DhfsSupportNative_getPageSizeInternal
(JNIEnv*, jclass) {
return checked_cast<jint>(get_page_size());
}