8314592: Add shortcut to SymbolLookup::find

Reviewed-by: jvernee, prr
This commit is contained in:
Per Minborg 2024-04-24 11:56:44 +00:00
parent 15190816f7
commit e923dfe4c5
22 changed files with 151 additions and 63 deletions

View File

@ -88,7 +88,7 @@ import java.util.stream.Stream;
* {@snippet lang = java:
* Linker linker = Linker.nativeLinker();
* MethodHandle strlen = linker.downcallHandle(
* linker.defaultLookup().find("strlen").orElseThrow(),
* linker.defaultLookup().findOrThrow("strlen"),
* FunctionDescriptor.of(JAVA_LONG, ADDRESS)
* );
* }
@ -306,7 +306,7 @@ import java.util.stream.Stream;
* {@snippet lang = java:
* Linker linker = Linker.nativeLinker();
* MethodHandle qsort = linker.downcallHandle(
* linker.defaultLookup().find("qsort").orElseThrow(),
* linker.defaultLookup().findOrThrow("qsort"),
* FunctionDescriptor.ofVoid(ADDRESS, JAVA_LONG, JAVA_LONG, ADDRESS)
* );
* }
@ -397,12 +397,12 @@ import java.util.stream.Stream;
* Linker linker = Linker.nativeLinker();
*
* MethodHandle malloc = linker.downcallHandle(
* linker.defaultLookup().find("malloc").orElseThrow(),
* linker.defaultLookup().findOrThrow("malloc"),
* FunctionDescriptor.of(ADDRESS, JAVA_LONG)
* );
*
* MethodHandle free = linker.downcallHandle(
* linker.defaultLookup().find("free").orElseThrow(),
* linker.defaultLookup().findOrThrow("free"),
* FunctionDescriptor.ofVoid(ADDRESS)
* );
* }
@ -530,7 +530,7 @@ import java.util.stream.Stream;
* {@snippet lang = java:
* Linker linker = Linker.nativeLinker();
* MethodHandle printf = linker.downcallHandle(
* linker.defaultLookup().find("printf").orElseThrow(),
* linker.defaultLookup().findOrThrow("printf"),
* FunctionDescriptor.of(JAVA_INT, ADDRESS, JAVA_INT, JAVA_INT, JAVA_INT),
* Linker.Option.firstVariadicArg(1) // first int is variadic
* );

View File

@ -39,6 +39,7 @@ import jdk.internal.reflect.Reflection;
import java.lang.invoke.MethodHandles;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiFunction;
@ -79,7 +80,7 @@ import java.util.function.BiFunction;
* {@snippet lang = java:
* try (Arena arena = Arena.ofConfined()) {
* SymbolLookup libGL = SymbolLookup.libraryLookup("libGL.so", arena); // libGL.so loaded here
* MemorySegment glGetString = libGL.find("glGetString").orElseThrow();
* MemorySegment glGetString = libGL.findOrThrow("glGetString");
* ...
* } // libGL.so unloaded here
*}
@ -93,7 +94,7 @@ import java.util.function.BiFunction;
* System.loadLibrary("GL"); // libGL.so loaded here
* ...
* SymbolLookup libGL = SymbolLookup.loaderLookup();
* MemorySegment glGetString = libGL.find("glGetString").orElseThrow();
* MemorySegment glGetString = libGL.findOrThrow("glGetString");
* }
*
* This symbol lookup, which is known as a <em>loader lookup</em>, is dynamic with
@ -130,7 +131,7 @@ import java.util.function.BiFunction;
* {@snippet lang = java:
* Linker nativeLinker = Linker.nativeLinker();
* SymbolLookup stdlib = nativeLinker.defaultLookup();
* MemorySegment malloc = stdlib.find("malloc").orElseThrow();
* MemorySegment malloc = stdlib.findOrThrow("malloc");
*}
*
* @since 22
@ -144,9 +145,40 @@ public interface SymbolLookup {
* @param name the symbol name
* @return a zero-length memory segment whose address indicates the address of
* the symbol, if found
* @see #findOrThrow(String)
*/
Optional<MemorySegment> find(String name);
/**
* Returns the address of the symbol with the given name or throws an exception.
*<p>
* This is equivalent to the following code, but is more efficient:
* to:
* {@snippet lang= java :
* String name = ...
* MemorySegment address = lookup.find(name)
* .orElseThrow(() -> new NoSuchElementException("Symbol not found: " + name));
* }
*
* @param name the symbol name
* @return a zero-length memory segment whose address indicates the address of
* the symbol
* @throws NoSuchElementException if no symbol address can be found for the
* given name
* @see #find(String)
*
* @since 23
*/
default MemorySegment findOrThrow(String name) {
Objects.requireNonNull(name);
Optional<MemorySegment> address = find(name);
// Avoid lambda capturing
if (address.isPresent()) {
return address.get();
}
throw new NoSuchElementException("Symbol not found: " + name);
}
/**
* {@return a composed symbol lookup that returns the result of finding the symbol
* with this lookup if found, otherwise returns the result of finding

View File

@ -100,7 +100,7 @@
* Linker linker = Linker.nativeLinker();
* SymbolLookup stdlib = linker.defaultLookup();
* MethodHandle strlen = linker.downcallHandle(
* stdlib.find("strlen").orElseThrow(),
* stdlib.findOrThrow("strlen"),
* FunctionDescriptor.of(ValueLayout.JAVA_LONG, ValueLayout.ADDRESS)
* );
*
@ -111,7 +111,7 @@
*}
*
* Here, we obtain a {@linkplain java.lang.foreign.Linker#nativeLinker() native linker}
* and we use it to {@linkplain java.lang.foreign.SymbolLookup#find(java.lang.String) look up}
* and we use it to {@linkplain java.lang.foreign.SymbolLookup#findOrThrow(java.lang.String) look up}
* the {@code strlen} function in the standard C library; a <em>downcall method handle</em>
* targeting said function is subsequently
* {@linkplain java.lang.foreign.Linker#downcallHandle(FunctionDescriptor, Linker.Option...) obtained}.

View File

@ -163,7 +163,7 @@ class Snippets {
void downcall() throws Throwable {
Linker linker = Linker.nativeLinker();
MethodHandle strlen = linker.downcallHandle(
linker.defaultLookup().find("strlen").orElseThrow(),
linker.defaultLookup().findOrThrow("strlen"),
FunctionDescriptor.of(JAVA_LONG, ADDRESS)
);
@ -177,7 +177,7 @@ class Snippets {
void qsort() throws Throwable {
Linker linker = Linker.nativeLinker();
MethodHandle qsort = linker.downcallHandle(
linker.defaultLookup().find("qsort").orElseThrow(),
linker.defaultLookup().findOrThrow("qsort"),
FunctionDescriptor.ofVoid(ADDRESS, JAVA_LONG, JAVA_LONG, ADDRESS)
);
@ -208,12 +208,12 @@ class Snippets {
Linker linker = Linker.nativeLinker();
MethodHandle malloc = linker.downcallHandle(
linker.defaultLookup().find("malloc").orElseThrow(),
linker.defaultLookup().findOrThrow("malloc"),
FunctionDescriptor.of(ADDRESS, JAVA_LONG)
);
MethodHandle free = linker.downcallHandle(
linker.defaultLookup().find("free").orElseThrow(),
linker.defaultLookup().findOrThrow("free"),
FunctionDescriptor.ofVoid(ADDRESS)
);
@ -282,7 +282,7 @@ class Snippets {
Linker linker = Linker.nativeLinker();
MethodHandle printf = linker.downcallHandle(
linker.defaultLookup().find("printf").orElseThrow(),
linker.defaultLookup().findOrThrow("printf"),
FunctionDescriptor.of(JAVA_INT, ADDRESS, JAVA_INT, JAVA_INT, JAVA_INT),
Linker.Option.firstVariadicArg(1) // first int is variadic
);
@ -568,7 +568,7 @@ class Snippets {
Linker linker = Linker.nativeLinker();
SymbolLookup stdlib = linker.defaultLookup();
MethodHandle strlen = linker.downcallHandle(
stdlib.find("strlen").orElseThrow(),
stdlib.findOrThrow("strlen"),
FunctionDescriptor.of(ValueLayout.JAVA_LONG, ValueLayout.ADDRESS)
);
@ -626,14 +626,14 @@ class Snippets {
void header() {
try (Arena arena = Arena.ofConfined()) {
SymbolLookup libGL = libraryLookup("libGL.so", arena); // libGL.so loaded here
MemorySegment glGetString = libGL.find("glGetString").orElseThrow();
MemorySegment glGetString = libGL.findOrThrow("glGetString");
// ...
} // libGL.so unloaded here
System.loadLibrary("GL"); // libGL.so loaded here
// ...
SymbolLookup libGL = loaderLookup();
MemorySegment glGetString = libGL.find("glGetString").orElseThrow();
MemorySegment glGetString = libGL.findOrThrow("glGetString");
Arena arena = Arena.ofAuto();
@ -647,7 +647,7 @@ class Snippets {
Linker nativeLinker = Linker.nativeLinker();
SymbolLookup stdlib = nativeLinker.defaultLookup();
MemorySegment malloc = stdlib.find("malloc").orElseThrow();
MemorySegment malloc = stdlib.findOrThrow("malloc");
}
}

View File

@ -102,7 +102,7 @@ public final class SystemLookup implements SymbolLookup {
libLookup(libs -> libs.load(jdkLibraryPath("syslookup")));
@SuppressWarnings("restricted")
MemorySegment funcs = fallbackLibLookup.find("funcs").orElseThrow()
MemorySegment funcs = fallbackLibLookup.findOrThrow("funcs")
.reinterpret(WindowsFallbackSymbols.LAYOUT.byteSize());
Function<String, Optional<MemorySegment>> fallbackLookup = name -> Optional.ofNullable(WindowsFallbackSymbols.valueOfOrNull(name))

View File

@ -168,22 +168,22 @@ public class HBShaper {
SYM_LOOKUP = SymbolLookup.loaderLookup().or(LINKER.defaultLookup());
FunctionDescriptor mallocDescriptor =
FunctionDescriptor.of(ADDRESS, JAVA_LONG);
Optional<MemorySegment> malloc_symbol = SYM_LOOKUP.find("malloc");
MemorySegment malloc_symbol = SYM_LOOKUP.findOrThrow("malloc");
@SuppressWarnings("restricted")
MethodHandle tmp1 = LINKER.downcallHandle(malloc_symbol.get(), mallocDescriptor);
MethodHandle tmp1 = LINKER.downcallHandle(malloc_symbol, mallocDescriptor);
malloc_handle = tmp1;
FunctionDescriptor createFaceDescriptor =
FunctionDescriptor.of(ADDRESS, ADDRESS);
Optional<MemorySegment> create_face_symbol = SYM_LOOKUP.find("HBCreateFace");
MemorySegment create_face_symbol = SYM_LOOKUP.findOrThrow("HBCreateFace");
@SuppressWarnings("restricted")
MethodHandle tmp2 = LINKER.downcallHandle(create_face_symbol.get(), createFaceDescriptor);
MethodHandle tmp2 = LINKER.downcallHandle(create_face_symbol, createFaceDescriptor);
create_face_handle = tmp2;
FunctionDescriptor disposeFaceDescriptor = FunctionDescriptor.ofVoid(ADDRESS);
Optional<MemorySegment> dispose_face_symbol = SYM_LOOKUP.find("HBDisposeFace");
MemorySegment dispose_face_symbol = SYM_LOOKUP.findOrThrow("HBDisposeFace");
@SuppressWarnings("restricted")
MethodHandle tmp3 = LINKER.downcallHandle(dispose_face_symbol.get(), disposeFaceDescriptor);
MethodHandle tmp3 = LINKER.downcallHandle(dispose_face_symbol, disposeFaceDescriptor);
dispose_face_handle = tmp3;
FunctionDescriptor shapeDesc = FunctionDescriptor.ofVoid(
@ -204,9 +204,9 @@ public class HBShaper {
ADDRESS, // ptr to harfbuzz font_funcs object.
ADDRESS); // store_results_fn
Optional<MemorySegment> shape_sym = SYM_LOOKUP.find("jdk_hb_shape");
MemorySegment shape_sym = SYM_LOOKUP.findOrThrow("jdk_hb_shape");
@SuppressWarnings("restricted")
MethodHandle tmp4 = LINKER.downcallHandle(shape_sym.get(), shapeDesc);
MethodHandle tmp4 = LINKER.downcallHandle(shape_sym, shapeDesc);
jdk_hb_shape_handle = tmp4;
Arena garena = Arena.global(); // creating stubs that exist until VM exit.
@ -260,10 +260,10 @@ public class HBShaper {
ADDRESS, // h_advance_fn upcall stub
ADDRESS, // v_advance_fn upcall stub
ADDRESS); // contour_pt_fn upcall stub
Optional<MemorySegment> create_font_funcs_symbol = SYM_LOOKUP.find("HBCreateFontFuncs");
MemorySegment create_font_funcs_symbol = SYM_LOOKUP.findOrThrow("HBCreateFontFuncs");
@SuppressWarnings("restricted")
MethodHandle create_font_funcs_handle =
LINKER.downcallHandle(create_font_funcs_symbol.get(), createFontFuncsDescriptor);
LINKER.downcallHandle(create_font_funcs_symbol, createFontFuncsDescriptor);
MemorySegment s = null;
try {

View File

@ -49,7 +49,7 @@ public class TestLinkToNativeRBP {
final static Linker abi = Linker.nativeLinker();
static final SymbolLookup lookup = SymbolLookup.loaderLookup();
final static MethodHandle foo = abi.downcallHandle(lookup.find("foo").get(),
final static MethodHandle foo = abi.downcallHandle(lookup.findOrThrow("foo"),
FunctionDescriptor.of(ValueLayout.JAVA_INT));
static int foo() throws Throwable {

View File

@ -0,0 +1,56 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @run junit/othervm --enable-native-access=ALL-UNNAMED TestSymbolLookupFindOrThrow
*/
import java.lang.foreign.MemorySegment;
import java.lang.foreign.SymbolLookup;
import java.util.NoSuchElementException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.*;
final class TestSymbolLookupFindOrThrow {
static {
System.loadLibrary("Foo");
}
@Test
void findOrThrow() {
MemorySegment symbol = SymbolLookup.loaderLookup().findOrThrow("foo");
Assertions.assertNotEquals(0, symbol.address());
}
@Test
void findOrThrowNotFound() {
assertThrows(NoSuchElementException.class, () ->
SymbolLookup.loaderLookup().findOrThrow("bar"));
}
}

View File

@ -88,7 +88,7 @@ public class AllocTest extends CLayouts {
static final MethodHandle CALLOC = Linker.nativeLinker()
.downcallHandle(
Linker.nativeLinker().defaultLookup().find("calloc").get(),
Linker.nativeLinker().defaultLookup().findOrThrow("calloc"),
FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.JAVA_LONG, ValueLayout.JAVA_LONG));
static MemorySegment calloc(long size) {

View File

@ -33,7 +33,7 @@ import java.lang.foreign.ValueLayout;
import java.lang.invoke.MethodHandle;
public class CLayouts {
private static Linker LINKER = Linker.nativeLinker();
private static final Linker LINKER = Linker.nativeLinker();
// the constants below are useful aliases for C types. The type/carrier association is only valid for 64-bit platforms.
@ -73,10 +73,10 @@ public class CLayouts {
.withTargetLayout(MemoryLayout.sequenceLayout(Long.MAX_VALUE, C_CHAR));
private static final MethodHandle FREE = LINKER.downcallHandle(
LINKER.defaultLookup().find("free").get(), FunctionDescriptor.ofVoid(C_POINTER));
LINKER.defaultLookup().findOrThrow("free"), FunctionDescriptor.ofVoid(C_POINTER));
private static final MethodHandle MALLOC = LINKER.downcallHandle(
LINKER.defaultLookup().find("malloc").get(), FunctionDescriptor.of(C_POINTER, ValueLayout.JAVA_LONG));
LINKER.defaultLookup().findOrThrow("malloc"), FunctionDescriptor.of(C_POINTER, ValueLayout.JAVA_LONG));
public static void freeMemory(MemorySegment address) {
try {

View File

@ -109,7 +109,7 @@ public class CallOverheadHelper extends CLayouts {
System.loadLibrary("CallOverhead");
SymbolLookup loaderLibs = SymbolLookup.loaderLookup();
{
func_addr = loaderLibs.find("func").orElseThrow();
func_addr = loaderLibs.findOrThrow("func");
MethodType mt = MethodType.methodType(void.class);
FunctionDescriptor fd = FunctionDescriptor.ofVoid();
func_v = abi.downcallHandle(fd);
@ -118,59 +118,59 @@ public class CallOverheadHelper extends CLayouts {
func_critical = insertArguments(func_critical_v, 0, func_addr);
}
{
identity_addr = loaderLibs.find("identity").orElseThrow();
identity_addr = loaderLibs.findOrThrow("identity");
FunctionDescriptor fd = FunctionDescriptor.of(C_INT, C_INT);
identity_v = abi.downcallHandle(fd);
identity_critical_v = abi.downcallHandle(fd, Linker.Option.critical(false));
identity = insertArguments(identity_v, 0, identity_addr);
identity_critical = insertArguments(identity_critical_v, 0, identity_addr);
}
identity_struct_addr = loaderLibs.find("identity_struct").orElseThrow();
identity_struct_addr = loaderLibs.findOrThrow("identity_struct");
identity_struct_v = abi.downcallHandle(
FunctionDescriptor.of(POINT_LAYOUT, POINT_LAYOUT));
identity_struct = insertArguments(identity_struct_v, 0, identity_struct_addr);
identity_struct_3_addr = loaderLibs.find("identity_struct_3").orElseThrow();
identity_struct_3_addr = loaderLibs.findOrThrow("identity_struct_3");
identity_struct_3_v = abi.downcallHandle(
FunctionDescriptor.of(POINT_LAYOUT, POINT_LAYOUT, POINT_LAYOUT, POINT_LAYOUT));
identity_struct_3 = insertArguments(identity_struct_3_v, 0, identity_struct_3_addr);
identity_memory_address_addr = loaderLibs.find("identity_memory_address").orElseThrow();
identity_memory_address_addr = loaderLibs.findOrThrow("identity_memory_address");
identity_memory_address_v = abi.downcallHandle(
FunctionDescriptor.of(C_POINTER, C_POINTER));
identity_memory_address = insertArguments(identity_memory_address_v, 0, identity_memory_address_addr);
identity_memory_address_3_addr = loaderLibs.find("identity_memory_address_3").orElseThrow();
identity_memory_address_3_addr = loaderLibs.findOrThrow("identity_memory_address_3");
identity_memory_address_3_v = abi.downcallHandle(
FunctionDescriptor.of(C_POINTER, C_POINTER, C_POINTER, C_POINTER));
identity_memory_address_3 = insertArguments(identity_memory_address_3_v, 0, identity_memory_address_3_addr);
args1_addr = loaderLibs.find("args1").orElseThrow();
args1_addr = loaderLibs.findOrThrow("args1");
args1_v = abi.downcallHandle(
FunctionDescriptor.ofVoid(C_LONG_LONG));
args1 = insertArguments(args1_v, 0, args1_addr);
args2_addr = loaderLibs.find("args2").orElseThrow();
args2_addr = loaderLibs.findOrThrow("args2");
args2_v = abi.downcallHandle(
FunctionDescriptor.ofVoid(C_LONG_LONG, C_DOUBLE));
args2 = insertArguments(args2_v, 0, args2_addr);
args3_addr = loaderLibs.find("args3").orElseThrow();
args3_addr = loaderLibs.findOrThrow("args3");
args3_v = abi.downcallHandle(
FunctionDescriptor.ofVoid(C_LONG_LONG, C_DOUBLE, C_LONG_LONG));
args3 = insertArguments(args3_v, 0, args3_addr);
args4_addr = loaderLibs.find("args4").orElseThrow();
args4_addr = loaderLibs.findOrThrow("args4");
args4_v = abi.downcallHandle(
FunctionDescriptor.ofVoid(C_LONG_LONG, C_DOUBLE, C_LONG_LONG, C_DOUBLE));
args4 = insertArguments(args4_v, 0, args4_addr);
args5_addr = loaderLibs.find("args5").orElseThrow();
args5_addr = loaderLibs.findOrThrow("args5");
args5_v = abi.downcallHandle(
FunctionDescriptor.ofVoid(C_LONG_LONG, C_DOUBLE, C_LONG_LONG, C_DOUBLE, C_LONG_LONG));
args5 = insertArguments(args5_v, 0, args5_addr);
args10_addr = loaderLibs.find("args10").orElseThrow();
args10_addr = loaderLibs.findOrThrow("args10");
args10_v = abi.downcallHandle(
FunctionDescriptor.ofVoid(C_LONG_LONG, C_DOUBLE, C_LONG_LONG, C_DOUBLE, C_LONG_LONG,
C_DOUBLE, C_LONG_LONG, C_DOUBLE, C_LONG_LONG, C_DOUBLE));

View File

@ -61,7 +61,7 @@ public class CriticalCalls {
System.loadLibrary("CriticalCalls");
SymbolLookup lookup = SymbolLookup.loaderLookup();
MemorySegment sumIntsSym = lookup.find("sum_ints").get();
MemorySegment sumIntsSym = lookup.findOrThrow("sum_ints");
FunctionDescriptor sumIntsDesc = FunctionDescriptor.of(JAVA_INT, ADDRESS, JAVA_INT);
PINNED = Linker.nativeLinker().downcallHandle(

View File

@ -58,13 +58,13 @@ public class PointerInvoke extends CLayouts {
static {
Linker abi = Linker.nativeLinker();
SymbolLookup loaderLibs = SymbolLookup.loaderLookup();
F_LONG_LONG = abi.downcallHandle(loaderLibs.find("id_long_long").get(),
F_LONG_LONG = abi.downcallHandle(loaderLibs.findOrThrow("id_long_long"),
FunctionDescriptor.of(C_LONG_LONG, C_LONG_LONG));
F_PTR_LONG = abi.downcallHandle(loaderLibs.find("id_ptr_long").get(),
F_PTR_LONG = abi.downcallHandle(loaderLibs.findOrThrow("id_ptr_long"),
FunctionDescriptor.of(C_LONG_LONG, C_POINTER));
F_LONG_PTR = abi.downcallHandle(loaderLibs.find("id_long_ptr").get(),
F_LONG_PTR = abi.downcallHandle(loaderLibs.findOrThrow("id_long_ptr"),
FunctionDescriptor.of(C_POINTER, C_LONG_LONG));
F_PTR_PTR = abi.downcallHandle(loaderLibs.find("id_ptr_ptr").get(),
F_PTR_PTR = abi.downcallHandle(loaderLibs.findOrThrow("id_ptr_ptr"),
FunctionDescriptor.of(C_POINTER, C_POINTER));
}

View File

@ -58,7 +58,7 @@ public class QSort extends CLayouts {
static final int[] INPUT = { 5, 3, 2, 7, 8, 12, 1, 7 };
static final MemorySegment INPUT_SEGMENT;
static MemorySegment qsort_addr = abi.defaultLookup().find("qsort").get();
static MemorySegment qsort_addr = abi.defaultLookup().findOrThrow("qsort");
static {
MemoryLayout layout = MemoryLayout.sequenceLayout(INPUT.length, JAVA_INT);
@ -74,7 +74,7 @@ public class QSort extends CLayouts {
FunctionDescriptor.ofVoid(C_POINTER, C_LONG_LONG, C_LONG_LONG, C_POINTER)
);
System.loadLibrary("QSort");
native_compar = SymbolLookup.loaderLookup().find("compar").orElseThrow();
native_compar = SymbolLookup.loaderLookup().findOrThrow("compar");
panama_upcall_compar = abi.upcallStub(
lookup().findStatic(QSort.class,
"panama_upcall_compar",

View File

@ -69,7 +69,7 @@ public class StrLenTest extends CLayouts {
static {
Linker abi = Linker.nativeLinker();
STRLEN = abi.downcallHandle(abi.defaultLookup().find("strlen").get(),
STRLEN = abi.downcallHandle(abi.defaultLookup().findOrThrow("strlen"),
FunctionDescriptor.of(C_INT, C_POINTER));
}

View File

@ -66,7 +66,7 @@ public class ToCStringTest extends CLayouts {
static {
Linker abi = Linker.nativeLinker();
STRLEN = abi.downcallHandle(abi.defaultLookup().find("strlen").get(),
STRLEN = abi.downcallHandle(abi.defaultLookup().findOrThrow("strlen"),
FunctionDescriptor.of(C_INT, C_POINTER));
}

View File

@ -120,7 +120,7 @@ public class Upcalls extends CLayouts {
static MethodHandle linkFunc(String name, FunctionDescriptor baseDesc) {
return abi.downcallHandle(
SymbolLookup.loaderLookup().find(name).orElseThrow(),
SymbolLookup.loaderLookup().findOrThrow(name),
baseDesc.appendArgumentLayouts(C_POINTER)
);
}

View File

@ -48,11 +48,11 @@ public class PanamaPoint extends CLayouts implements AutoCloseable {
System.loadLibrary("Point");
SymbolLookup loaderLibs = SymbolLookup.loaderLookup();
MH_distance = abi.downcallHandle(
loaderLibs.find("distance").get(),
loaderLibs.findOrThrow("distance"),
FunctionDescriptor.of(C_DOUBLE, LAYOUT, LAYOUT)
);
MH_distance_ptrs = abi.downcallHandle(
loaderLibs.find("distance_ptrs").get(),
loaderLibs.findOrThrow("distance_ptrs"),
FunctionDescriptor.of(C_DOUBLE, C_POINTER, C_POINTER)
);
}

View File

@ -17,7 +17,7 @@ public class GetArrayForeignXorOpCriticalImpl implements XorOp {
Linker linker;
linker = Linker.nativeLinker();
FunctionDescriptor xor_op_func = FunctionDescriptor.ofVoid(C_POINTER, C_POINTER, C_INT);
xor_op = linker.downcallHandle(SymbolLookup.loaderLookup().find("xor_op").orElseThrow(), xor_op_func, critical(true));
xor_op = linker.downcallHandle(SymbolLookup.loaderLookup().findOrThrow("xor_op"), xor_op_func, critical(true));
}
static final MethodHandle xor_op;

View File

@ -19,7 +19,7 @@ public class GetArrayForeignXorOpImpl implements XorOp {
Linker linker;
linker = Linker.nativeLinker();
FunctionDescriptor xor_op_func = FunctionDescriptor.ofVoid(C_POINTER, C_POINTER, C_INT);
xor_op = linker.downcallHandle(SymbolLookup.loaderLookup().find("xor_op").orElseThrow(), xor_op_func, critical(false));
xor_op = linker.downcallHandle(SymbolLookup.loaderLookup().findOrThrow("xor_op"), xor_op_func, critical(false));
}
static final MethodHandle xor_op;

View File

@ -20,7 +20,7 @@ public class GetArrayForeignXorOpInitImpl implements XorOp {
Linker linker;
linker = Linker.nativeLinker();
FunctionDescriptor xor_op_func = FunctionDescriptor.ofVoid(C_POINTER, C_POINTER, C_INT);
xor_op = linker.downcallHandle(SymbolLookup.loaderLookup().find("xor_op").orElseThrow(), xor_op_func, critical(false));
xor_op = linker.downcallHandle(SymbolLookup.loaderLookup().findOrThrow("xor_op"), xor_op_func, critical(false));
}
static final MethodHandle xor_op;

View File

@ -25,7 +25,7 @@ public class GetArrayUnsafeXorOpImpl implements XorOp {
Linker linker;
linker = Linker.nativeLinker();
FunctionDescriptor xor_op_func = FunctionDescriptor.ofVoid(C_POINTER, C_POINTER, C_INT);
xor_op = linker.downcallHandle(SymbolLookup.loaderLookup().find("xor_op").orElseThrow(), xor_op_func, critical(false));
xor_op = linker.downcallHandle(SymbolLookup.loaderLookup().findOrThrow("xor_op"), xor_op_func, critical(false));
}
static final MethodHandle xor_op;