Fix several issues with JNI compression

The libraries will require a recompile.
This commit is contained in:
Andrew Steinborn 2022-06-08 00:53:15 -04:00
parent 04d3ed6820
commit 01c6777948
3 changed files with 12 additions and 8 deletions

View File

@ -27,7 +27,7 @@ Java_com_velocitypowered_natives_compression_NativeZlibDeflate_free(JNIEnv *env,
libdeflate_free_compressor((struct libdeflate_compressor *) ctx); libdeflate_free_compressor((struct libdeflate_compressor *) ctx);
} }
JNIEXPORT jboolean JNICALL JNIEXPORT jlong JNICALL
Java_com_velocitypowered_natives_compression_NativeZlibDeflate_process(JNIEnv *env, Java_com_velocitypowered_natives_compression_NativeZlibDeflate_process(JNIEnv *env,
jclass clazz, jclass clazz,
jlong ctx, jlong ctx,

View File

@ -70,11 +70,13 @@ public class LibdeflateVelocityCompressor implements VelocityCompressor {
destinationAddress, destination.writableBytes()); destinationAddress, destination.writableBytes());
if (produced > 0) { if (produced > 0) {
destination.writerIndex(destination.writerIndex() + produced); destination.writerIndex(destination.writerIndex() + produced);
return; break;
} } else if (produced == 0) {
// Insufficient room - enlarge the buffer. // Insufficient room - enlarge the buffer.
destination.capacity(destination.capacity() * 2); destination.capacity(destination.capacity() * 2);
} else {
throw new DataFormatException("libdeflate returned unknown code " + produced);
}
} }
} }

View File

@ -39,7 +39,8 @@ public class NativeConstraints {
// HotSpot on Intel macOS prefers x86_64, but OpenJ9 on macOS and HotSpot/OpenJ9 elsewhere // HotSpot on Intel macOS prefers x86_64, but OpenJ9 on macOS and HotSpot/OpenJ9 elsewhere
// give amd64. // give amd64.
IS_AMD64 = osArch.equals("amd64") || osArch.equals("x86_64"); IS_AMD64 = osArch.equals("amd64") || osArch.equals("x86_64");
IS_AARCH64 = osArch.equals("aarch64"); IS_AARCH64 = osArch.equals("aarch64") || osArch.equals("arm64");
System.out.println(System.getProperty("os.name", ""));
} }
static final BooleanSupplier NATIVE_BASE = () -> NATIVES_ENABLED && CAN_GET_MEMORYADDRESS; static final BooleanSupplier NATIVE_BASE = () -> NATIVES_ENABLED && CAN_GET_MEMORYADDRESS;
@ -52,6 +53,7 @@ public class NativeConstraints {
&& System.getProperty("os.name", "").equalsIgnoreCase("Linux") && System.getProperty("os.name", "").equalsIgnoreCase("Linux")
&& IS_AARCH64; && IS_AARCH64;
static final BooleanSupplier JAVA_11 = () -> Double.parseDouble( static final BooleanSupplier MACOS_AARCH64 = () -> NATIVE_BASE.getAsBoolean()
System.getProperty("java.specification.version")) >= 11; && System.getProperty("os.name", "").equalsIgnoreCase("Mac OS X")
&& IS_AARCH64;
} }