-
Bug
-
Resolution: Fixed
-
P3
-
None
-
repo-panama
-
generic
-
generic
File: Main.java
import java.lang.foreign.*;
import java.util.function.*;
import java.lang.invoke.*;
import java.util.Optional;
import static java.lang.foreign.ValueLayout.*;
public class Main {
private final static CLinker LINKER = CLinker.systemCLinker();
private final static ClassLoader LOADER = Main.class.getClassLoader();
private static final Function<String, Optional<NativeSymbol>> SYMBOL_LOOKUP;
static {
// Manual change to handle platform specific library name difference
String libName = System.getProperty("os.name").startsWith("Windows")? "libclang" : "clang";
System.loadLibrary(libName);
SYMBOL_LOOKUP = name -> LOADER.findNative(name).or(() -> LINKER.lookup(name));
}
static final MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) {
return SYMBOL_LOOKUP.apply(name).map(
addr -> LINKER.downcallHandle(addr, fdesc)
).orElse(null);
}
static final FunctionDescriptor clang_getFileName$FUNC = FunctionDescriptor.of(MemoryLayout.structLayout(
ADDRESS.withName("data"),
JAVA_INT.withName("private_flags"),
MemoryLayout.paddingLayout(32)
),
ADDRESS
);
static final MethodHandle clang_getFileName$MH = downcallHandle(
"clang_getFileName",
clang_getFileName$FUNC
);
public static void main(String[] args) {}
}
# Note: $llvm10 is the directory where LLVM is installed.
$ java --enable-native-access=ALL-UNNAMED -Djava.library.path=$llvm10/lib/ --enable-preview --source 19 Main.java
Note: Main.java uses preview features of Java SE 19.
Note: Recompile with -Xlint:preview for details.
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:488)
at java.base/java.lang.Class.forName(Class.java:467)
at jdk.compiler/com.sun.tools.javac.launcher.Main.execute(Main.java:411)
at jdk.compiler/com.sun.tools.javac.launcher.Main.run(Main.java:192)
at jdk.compiler/com.sun.tools.javac.launcher.Main.main(Main.java:132)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 0
at java.base/jdk.internal.org.objectweb.asm.Frame.getConcreteOutputType(Frame.java:1170)
at java.base/jdk.internal.org.objectweb.asm.Frame.merge(Frame.java:1270)
at java.base/jdk.internal.org.objectweb.asm.MethodWriter.computeAllFrames(MethodWriter.java:1641)
at java.base/jdk.internal.org.objectweb.asm.MethodWriter.visitMaxs(MethodWriter.java:1577)
at java.base/jdk.internal.foreign.abi.BindingSpecializer.specialize(BindingSpecializer.java:153)
at java.base/jdk.internal.foreign.abi.ProgrammableInvoker.getBoundMethodHandle(ProgrammableInvoker.java:102)
at java.base/jdk.internal.foreign.abi.x64.sysv.CallArranger.arrangeDowncall(CallArranger.java:124)
at java.base/jdk.internal.foreign.abi.x64.sysv.SysVx64Linker.arrangeDowncall(SysVx64Linker.java:62)
at java.base/jdk.internal.foreign.abi.AbstractLinker.lambda$downcallHandle$0(AbstractLinker.java:55)
at java.base/jdk.internal.foreign.abi.AbstractLinker$SoftReferenceCache$Node.get(AbstractLinker.java:101)
at java.base/jdk.internal.foreign.abi.AbstractLinker$SoftReferenceCache.get(AbstractLinker.java:87)
at java.base/jdk.internal.foreign.abi.AbstractLinker.downcallHandle(AbstractLinker.java:53)
at java.base/java.lang.foreign.CLinker.downcallHandle(CLinker.java:195)
at Main.lambda$downcallHandle$2(Main.java:23)
at java.base/java.util.Optional.map(Optional.java:260)
at Main.downcallHandle(Main.java:22)
at Main.<clinit>(Main.java:34)
... 6 more
import java.lang.foreign.*;
import java.util.function.*;
import java.lang.invoke.*;
import java.util.Optional;
import static java.lang.foreign.ValueLayout.*;
public class Main {
private final static CLinker LINKER = CLinker.systemCLinker();
private final static ClassLoader LOADER = Main.class.getClassLoader();
private static final Function<String, Optional<NativeSymbol>> SYMBOL_LOOKUP;
static {
// Manual change to handle platform specific library name difference
String libName = System.getProperty("os.name").startsWith("Windows")? "libclang" : "clang";
System.loadLibrary(libName);
SYMBOL_LOOKUP = name -> LOADER.findNative(name).or(() -> LINKER.lookup(name));
}
static final MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) {
return SYMBOL_LOOKUP.apply(name).map(
addr -> LINKER.downcallHandle(addr, fdesc)
).orElse(null);
}
static final FunctionDescriptor clang_getFileName$FUNC = FunctionDescriptor.of(MemoryLayout.structLayout(
ADDRESS.withName("data"),
JAVA_INT.withName("private_flags"),
MemoryLayout.paddingLayout(32)
),
ADDRESS
);
static final MethodHandle clang_getFileName$MH = downcallHandle(
"clang_getFileName",
clang_getFileName$FUNC
);
public static void main(String[] args) {}
}
# Note: $llvm10 is the directory where LLVM is installed.
$ java --enable-native-access=ALL-UNNAMED -Djava.library.path=$llvm10/lib/ --enable-preview --source 19 Main.java
Note: Main.java uses preview features of Java SE 19.
Note: Recompile with -Xlint:preview for details.
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:488)
at java.base/java.lang.Class.forName(Class.java:467)
at jdk.compiler/com.sun.tools.javac.launcher.Main.execute(Main.java:411)
at jdk.compiler/com.sun.tools.javac.launcher.Main.run(Main.java:192)
at jdk.compiler/com.sun.tools.javac.launcher.Main.main(Main.java:132)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 0
at java.base/jdk.internal.org.objectweb.asm.Frame.getConcreteOutputType(Frame.java:1170)
at java.base/jdk.internal.org.objectweb.asm.Frame.merge(Frame.java:1270)
at java.base/jdk.internal.org.objectweb.asm.MethodWriter.computeAllFrames(MethodWriter.java:1641)
at java.base/jdk.internal.org.objectweb.asm.MethodWriter.visitMaxs(MethodWriter.java:1577)
at java.base/jdk.internal.foreign.abi.BindingSpecializer.specialize(BindingSpecializer.java:153)
at java.base/jdk.internal.foreign.abi.ProgrammableInvoker.getBoundMethodHandle(ProgrammableInvoker.java:102)
at java.base/jdk.internal.foreign.abi.x64.sysv.CallArranger.arrangeDowncall(CallArranger.java:124)
at java.base/jdk.internal.foreign.abi.x64.sysv.SysVx64Linker.arrangeDowncall(SysVx64Linker.java:62)
at java.base/jdk.internal.foreign.abi.AbstractLinker.lambda$downcallHandle$0(AbstractLinker.java:55)
at java.base/jdk.internal.foreign.abi.AbstractLinker$SoftReferenceCache$Node.get(AbstractLinker.java:101)
at java.base/jdk.internal.foreign.abi.AbstractLinker$SoftReferenceCache.get(AbstractLinker.java:87)
at java.base/jdk.internal.foreign.abi.AbstractLinker.downcallHandle(AbstractLinker.java:53)
at java.base/java.lang.foreign.CLinker.downcallHandle(CLinker.java:195)
at Main.lambda$downcallHandle$2(Main.java:23)
at java.base/java.util.Optional.map(Optional.java:260)
at Main.downcallHandle(Main.java:22)
at Main.<clinit>(Main.java:34)
... 6 more