Class ZstdHeapFallback

java.lang.Object
org.elasticsearch.nativeaccess.lib.ZstdHeapFallback

public final class ZstdHeapFallback extends Object
JDK 21 @Critical fallback for ZstdLibrary.compressHeap(java.lang.foreign.MemorySegment, long, java.lang.foreign.MemorySegment, long, int) / ZstdLibrary.decompressHeap(java.lang.foreign.MemorySegment, long, java.lang.foreign.MemorySegment, long).

On JDK 21 the raw libzstd downcall handle is linked without Linker.Option.critical(true) (the option doesn't exist there), so it rejects heap-backed MemorySegment arguments. The annotation processor wires @Critical(fallbackAdapter = ZstdHeapFallback.class) so that on JDK 21 each compressHeap$mh / decompressHeap$mh field holds an adapter that points at the matching method below: the heap input is staged into a confined Arena, the raw handle is invoked with native segments, and the decoded length is copied back into the caller's heap output. On JDK 22+ this class is not referenced.