mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 17:34:17 -04:00
Different string allocation on jdk 21/22 (#106492)
Similar to https://github.com/elastic/elasticsearch/pull/106360, the methods for allocating a native string changed between Java 21 and 22. This commit adds another util method to handle the differences and uses it in the jdk systemd impl.
This commit is contained in:
parent
e14dd54ae9
commit
6731538bbe
3 changed files with 11 additions and 1 deletions
|
@ -58,7 +58,7 @@ class JdkSystemdLibrary implements SystemdLibrary {
|
|||
@Override
|
||||
public int sd_notify(int unset_environment, String state) {
|
||||
try (Arena arena = Arena.ofConfined()) {
|
||||
MemorySegment nativeState = arena.allocateUtf8String(state);
|
||||
MemorySegment nativeState = MemorySegmentUtil.allocateString(arena, state);
|
||||
return (int) sd_notify$mh.invokeExact(unset_environment, nativeState);
|
||||
} catch (Throwable t) {
|
||||
throw new AssertionError(t);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
package org.elasticsearch.nativeaccess.jdk;
|
||||
|
||||
import java.lang.foreign.Arena;
|
||||
import java.lang.foreign.MemorySegment;
|
||||
|
||||
/**
|
||||
|
@ -19,5 +20,9 @@ class MemorySegmentUtil {
|
|||
return segment.getUtf8String(offset);
|
||||
}
|
||||
|
||||
static MemorySegment allocateString(Arena arena, String s) {
|
||||
return arena.allocateUtf8String(s);
|
||||
}
|
||||
|
||||
private MemorySegmentUtil() {}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
package org.elasticsearch.nativeaccess.jdk;
|
||||
|
||||
import java.lang.foreign.Arena;
|
||||
import java.lang.foreign.MemorySegment;
|
||||
|
||||
public class MemorySegmentUtil {
|
||||
|
@ -16,5 +17,9 @@ public class MemorySegmentUtil {
|
|||
return segment.getString(offset);
|
||||
}
|
||||
|
||||
static MemorySegment allocateString(Arena arena, String s) {
|
||||
return arena.allocateFrom(s);
|
||||
}
|
||||
|
||||
private MemorySegmentUtil() {}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue