Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Should not reach here" error compiling a Swing application #4072

Closed
dmclean652 opened this issue Dec 1, 2021 · 17 comments · Fixed by #4474
Closed

"Should not reach here" error compiling a Swing application #4072

dmclean652 opened this issue Dec 1, 2021 · 17 comments · Fixed by #4474
Assignees

Comments

@dmclean652
Copy link

dmclean652 commented Dec 1, 2021

Describe the issue
I have a relatively small and straight forward Swing application that fails during native image compilation. I'm trying to build on Windows 10 and using Visual Studio 2017 Express. The error is the same if I use Visual Studio 2019 Express.

My command line is:

native-image --module-path . -m LogViewer/com.bkin.logviewer.gui.LogViewer

The error during the build is simply "Should not reach here" with no other detail. The java.dll is zero bytes when the build exists.

The code is proprietary, so I can't post it online. I'm mainly looking for extra information about why this is failing.

The GraalVM I'm using is: 21.3.0
JDK 17
Windows 10
AMD 64
Visual Studio 2017, v15.9

More details
The build output is:

Executing [
'C:\java\graalvm-ce-java17-21.3.0\bin\java.exe' \
-XX:+UseParallelGC \
-XX:+UnlockExperimentalVMOptions \
-XX:+EnableJVMCI \
-Dtruffle.TrustAllTruffleRuntimeProviders=true \
-Dtruffle.TruffleRuntime=com.oracle.truffle.api.impl.DefaultTruffleRuntime \
-Dgraalvm.ForcePolyglotInvalid=true \
-Dgraalvm.locatorDisabled=true \
-Dsubstratevm.IgnoreGraalVersionCheck=true \
--add-exports=java.base/com.sun.crypto.provider=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.access.foreign=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.event=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.loader=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.logger=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.misc=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.module=org.graalvm.nativeimage.builder,org.graalvm.nativeimage.pointsto \
--add-exports=java.base/jdk.internal.org.objectweb.asm=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.org.xml.sax.helpers=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.perf=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.platform=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.ref=org.graalvm.nativeimage.objectfile \
--add-exports=java.base/jdk.internal.reflect=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.util.xml.impl=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.util.xml=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.invoke.util=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.nio.ch=org.graalvm.nativeimage.objectfile \
--add-exports=java.base/sun.reflect.annotation=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.reflect.generics.reflectiveObjects=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.reflect.generics.repository=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.reflect.generics.tree=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.security.jca=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.security.provider=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.security.util=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.text.spi=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.util.calendar=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.util.locale.provider=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.util.resources=org.graalvm.nativeimage.builder \
--add-exports=java.xml.crypto/org.jcp.xml.dsig.internal.dom=org.graalvm.nativeimage.builder \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.aarch64=jdk.internal.vm.compiler,org.graalvm.nativeimage.builder \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.amd64=jdk.internal.vm.compiler,org.graalvm.nativeimage.builder \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code.site=jdk.internal.vm.compiler,org.graalvm.nativeimage.builder \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code.stack=jdk.internal.vm.compiler,org.graalvm.nativeimage.builder \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code=jdk.internal.vm.compiler,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.pointsto \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.common=jdk.internal.vm.compiler,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.pointsto \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot.aarch64=jdk.internal.vm.compiler \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot.amd64=jdk.internal.vm.compiler \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot=jdk.internal.vm.compiler,org.graalvm.nativeimage.builder \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.meta=jdk.internal.vm.compiler,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile,org.graalvm.nativeimage.pointsto \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.runtime=jdk.internal.vm.compiler,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.pointsto \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.services=jdk.internal.vm.compiler,org.graalvm.nativeimage.builder \
--add-exports=jdk.jfr/jdk.jfr.events=org.graalvm.nativeimage.builder \
--add-exports=jdk.jfr/jdk.jfr.internal.consumer=org.graalvm.nativeimage.builder \
--add-exports=jdk.jfr/jdk.jfr.internal.handlers=org.graalvm.nativeimage.builder \
--add-exports=jdk.jfr/jdk.jfr.internal.jfc=org.graalvm.nativeimage.builder \
--add-exports=jdk.jfr/jdk.jfr.internal=org.graalvm.nativeimage.builder \
-XX:+UseJVMCINativeLibrary \
-Xss10m \
-Xms1g \
-Xmx14g \
-Duser.country=US \
-Duser.language=en \
-Djava.awt.headless=true \
-Dorg.graalvm.version=21.3.0 \
-Dorg.graalvm.config=CE \
-Dcom.oracle.graalvm.isaot=true \
-Djava.system.class.loader=com.oracle.svm.hosted.NativeImageSystemClassLoader \
-Xshare:off \
-Djdk.internal.lambda.disableEagerInitialization=true \
-Djdk.internal.lambda.eagerlyInitialize=false \
-Djava.lang.invoke.InnerClassLambdaMetafactory.initializeLambdas=false \
'-javaagent:c:\java\graalvm-ce-java17-21.3.0\lib\svm\builder\svm.jar' \
--module-path \
'C:\java\graalvm-ce-java17-21.3.0\lib\truffle\truffle-api.jar;C:\java\graalvm-ce-java17-21.3.0\lib\svm\builder\objectfile.jar;C:\java\graalvm-ce-java17-21.3.0\lib\svm\builder\pointsto.jar;C:\java\graalvm-ce-java17-21.3.0\lib\svm\builder\svm.jar' \
--module \
org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner \
-imagemp \
'C:\code\BKINTools\LogViewer\out\pack;c:\java\graalvm-ce-java17-21.3.0\lib\svm\library-support.jar' \
'-H:Path=C:\code\BKINTools\LogViewer\out\pack' \
-H:+DumpTargetInfo \
-H:Class=com.bkin.logviewer.gui.LogViewer \
-H:Module=LogViewer \
'-H:CLibraryPath=C:\java\graalvm-ce-java17-21.3.0\lib\svm\clibraries\windows-amd64' \
'-H:Name@image-name from module-name=logviewer'
]
[logviewer:17352]    classlist:     758.82 ms,  0.96 GB
[logviewer:17352]        (cap):   1,314.59 ms,  0.96 GB
[logviewer:17352]        setup:   2,492.98 ms,  0.96 GB
 Printing compilation-target information to: C:\code\BKINTools\LogViewer\out\pack\reports\target_info_20211201_144838.txt
[logviewer:17352]     (clinit):     360.01 ms,  3.78 GB
 Printing native-library information to: C:\code\BKINTools\LogViewer\out\pack\reports\native_library_info_20211201_144851.txt
[logviewer:17352]   (typeflow):   6,182.45 ms,  3.78 GB
[logviewer:17352]    (objects):   4,788.44 ms,  3.78 GB
[logviewer:17352]   (features):   1,597.83 ms,  3.78 GB
[logviewer:17352]     analysis:  13,649.90 ms,  3.78 GB
[logviewer:17352]     universe:   1,310.82 ms,  3.80 GB
[logviewer:17352]      (parse):     746.84 ms,  3.80 GB
[logviewer:17352]     (inline):   2,013.42 ms,  4.58 GB
[logviewer:17352]    (compile):  11,405.04 ms,  5.60 GB
[logviewer:17352]      compile:  15,419.49 ms,  5.60 GB
[logviewer:17352]        image:   1,715.71 ms,  5.60 GB
[logviewer:17352]        write:     367.45 ms,  5.60 GB
Fatal error:com.oracle.svm.core.util.VMError$HostedError: should not reach here
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.shouldNotReachHere(VMError.java:64)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.jdk.JNIRegistrationSupport.makeShimDLL(JNIRegistrationSupport.java:256)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.jdk.JNIRegistrationSupport.makeShimDLLs(JNIRegistrationSupport.java:230)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.jdk.JNIRegistrationSupport.afterImageWrite(JNIRegistrationSupport.java:175)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.lambda$doRun$8(NativeImageGenerator.java:663)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:73)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:663)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:488)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:569)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:122)
[logviewer:17352]      [total]:  35,918.53 ms,  5.60 GB
Printing build artifacts to: C:\code\BKINTools\LogViewer\out\pack\logviewer.build_artifacts.txt
Error: Image build request failed with exit status 1
com.oracle.svm.driver.NativeImage$NativeImageError: Image build request failed with exit status 1
        at com.oracle.svm.driver.NativeImage.showError(NativeImage.java:1762)
        at com.oracle.svm.driver.NativeImage.build(NativeImage.java:1473)
        at com.oracle.svm.driver.NativeImage.performBuild(NativeImage.java:1434)
        at com.oracle.svm.driver.NativeImage.main(NativeImage.java:1421)

Thank you for the help!

@munishchouhan
Copy link
Contributor

@dmclean652 thanks for reporting the issue, please share a reproducer.

@munishchouhan munishchouhan self-assigned this Dec 6, 2021
@petermz
Copy link
Contributor

petermz commented Dec 7, 2021 via email

@chirontt
Copy link

chirontt commented Dec 8, 2021

As the original poster couldn't include their proprietary code, here is some simple Swing code that easily reproduces the reported problem (taken from a comment in an old issue: #1327):

import java.awt.*;
import javax.swing.*;

public class JFrameExample {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                displayJFrame();
            }
        });
    }

    static void displayJFrame() {
        JFrame frame = new JFrame("My JFrame Example");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setPreferredSize(new Dimension(400, 200));
        frame.pack();
        frame.setVisible(true);
    }

}

Using the JDK11 version of GraalVM 21.3.0, the above code compiles fine to a native executable. But when using the JDK17 version of GraalVM 21.3.0, the reported "should not reach here" error is reproduced during the link stage.

As mentioned by @petermz, adding the -H:+TraceNativeToolUsage option to the native-image command would show more info about the error during the link stage:

>> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\bin\HostX64\x64\cl.exe' '/FeD:\dev\graal\swing-native\build\native-image-windows\java.dll' 'C:\Users\Tue\AppData\Local\Temp\SVM-3335159323851759057\swing-native.lib' msvcrt.lib /link /dll /implib:java.lib /export:JDK_LoadSystemLibrary /export:JNU_CallMethodByName /export:JNU_CallMethodByNameV /export:JNU_CallStaticMethodByName /export:JNU_ClassString /export:JNU_GetEnv /export:JNU_GetFieldByName /export:JNU_GetStaticFieldByName /export:JNU_IsInstanceOfByName /export:JNU_NewObjectByName /export:JNU_NewStringPlatform /export:JNU_SetFieldByName /export:JNU_ThrowArrayIndexOutOfBoundsException /export:JNU_ThrowByName /export:JNU_ThrowIOException /export:JNU_ThrowIllegalArgumentException /export:JNU_ThrowInternalError /export:JNU_ThrowNullPointerException /export:JNU_ThrowOutOfMemoryError /export:getEncodingFromLangID /export:getJavaIDFromLangID /export:jio_snprintf
># Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29334 for x64
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># Microsoft (R) Incremental Linker Version 14.28.29334.0
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># /out:D:\dev\graal\swing-native\build\native-image-windows\java.dll
># /dll
># /implib:java.lib
># /export:JDK_LoadSystemLibrary
># /export:JNU_CallMethodByName
># /export:JNU_CallMethodByNameV
># /export:JNU_CallStaticMethodByName
># /export:JNU_ClassString
># /export:JNU_GetEnv
># /export:JNU_GetFieldByName
># /export:JNU_GetStaticFieldByName
># /export:JNU_IsInstanceOfByName
># /export:JNU_NewObjectByName
># /export:JNU_NewStringPlatform
># /export:JNU_SetFieldByName
># /export:JNU_ThrowArrayIndexOutOfBoundsException
># /export:JNU_ThrowByName
># /export:JNU_ThrowIOException
># /export:JNU_ThrowIllegalArgumentException
># /export:JNU_ThrowInternalError
># /export:JNU_ThrowNullPointerException
># /export:JNU_ThrowOutOfMemoryError
># /export:getEncodingFromLangID
># /export:getJavaIDFromLangID
># /export:jio_snprintf
># C:\Users\Tue\AppData\Local\Temp\SVM-3335159323851759057\swing-native.lib
># msvcrt.lib
># LINK : warning LNK4001: no object files specified; libraries used
># LINK : warning LNK4068: /MACHINE not specified; defaulting to X64
># LINK : error LNK2001: unresolved external symbol JDK_LoadSystemLibrary
># LINK : error LNK2001: unresolved external symbol JNU_CallMethodByName
># LINK : error LNK2001: unresolved external symbol JNU_CallMethodByNameV
># LINK : error LNK2001: unresolved external symbol JNU_CallStaticMethodByName
># LINK : error LNK2001: unresolved external symbol JNU_ClassString
># LINK : error LNK2001: unresolved external symbol JNU_GetEnv
># LINK : error LNK2001: unresolved external symbol JNU_GetFieldByName
># LINK : error LNK2001: unresolved external symbol JNU_GetStaticFieldByName
># LINK : error LNK2001: unresolved external symbol JNU_IsInstanceOfByName
># LINK : error LNK2001: unresolved external symbol JNU_NewObjectByName
># LINK : error LNK2001: unresolved external symbol JNU_NewStringPlatform
># LINK : error LNK2001: unresolved external symbol JNU_SetFieldByName
># LINK : error LNK2001: unresolved external symbol JNU_ThrowArrayIndexOutOfBoundsException
># LINK : error LNK2001: unresolved external symbol JNU_ThrowByName
># LINK : error LNK2001: unresolved external symbol JNU_ThrowIOException
># LINK : error LNK2001: unresolved external symbol JNU_ThrowIllegalArgumentException
># LINK : error LNK2001: unresolved external symbol JNU_ThrowInternalError
># LINK : error LNK2001: unresolved external symbol JNU_ThrowNullPointerException
># LINK : error LNK2001: unresolved external symbol JNU_ThrowOutOfMemoryError
># java.lib : fatal error LNK1120: 19 unresolved externals
[swing-native:2772]        write:   1,730.67 ms,  5.18 GB
[swing-native:2772]      [total]:   140,543.41 ms,  5.18 GB
Fatal error:com.oracle.svm.core.util.VMError$HostedError: should not reach here
        at com.oracle.svm.core.util.VMError.shouldNotReachHere(VMError.java:64)
        at com.oracle.svm.hosted.jdk.JNIRegistrationSupport.makeShimDLL(JNIRegistrationSupport.java:256)
        at com.oracle.svm.hosted.jdk.JNIRegistrationSupport.makeShimDLLs(JNIRegistrationSupport.java:230)
        at com.oracle.svm.hosted.jdk.JNIRegistrationSupport.afterImageWrite(JNIRegistrationSupport.java:175)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$doRun$8(NativeImageGenerator.java:663)
        at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:73)
        at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:663)
        at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:488)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:569)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:122)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:599)
# Printing build artifacts to: D:\dev\graal\swing-native\build\native-image-windows\swing-native.build_artifacts.txt
Error: Image build request failed with exit status 1
com.oracle.svm.driver.NativeImage$NativeImageError: Image build request failed with exit status 1
        at com.oracle.svm.driver.NativeImage.showError(NativeImage.java:1762)
        at com.oracle.svm.driver.NativeImage.build(NativeImage.java:1473)
        at com.oracle.svm.driver.NativeImage.performBuild(NativeImage.java:1434)
        at com.oracle.svm.driver.NativeImage.main(NativeImage.java:1421)

@dmclean652
Copy link
Author

Thank you @chirontt . When I ran with -H:+TraceNativeToolUsage that was the exact error I received.

@munishchouhan
Copy link
Contributor

@chirontt I tried the reproducer, but it builds and run successfully:

>mkdir META-INF\native-image

C:\Users\mchouhan\Desktop\Issues\github\4072>java -agentlib:native-image-agent=config-output-dir=META-INF/native-image JFrameExample      

C:\Users\mchouhan\Desktop\Issues\github\4072>native-image JFrameExample --no-fallback -H:+TraceNativeToolUsage 
[jframeexample:17168]    classlist:   1,703.42 ms,  0.96 GB
>> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.exe'
># Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29913 for x64
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># usage: cl [ option... ] filename... [ /link linkoption... ]
>> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.exe' /WX /W4 /wd4244 /wd4245 /wd4800 /wd4804 /wd4214 '/FeC:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\AArch64LibCHelperDirectives.exe' 'C:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\AArch64LibCHelperDirectives.c'
># AArch64LibCHelperDirectives.c
># Microsoft (R) Incremental Linker Version 14.28.29913.0
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># /out:C:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\AArch64LibCHelperDirectives.exe
># AArch64LibCHelperDirectives.obj
>> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.exe' /WX /W4 /wd4244 /wd4245 /wd4800 /wd4804 /wd4214 '/FeC:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\WindowsDirectives.exe' 'C:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\WindowsDirectives.c'
># WindowsDirectives.c
># Microsoft (R) Incremental Linker Version 14.28.29913.0
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># /out:C:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\WindowsDirectives.exe
># WindowsDirectives.obj
>> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.exe' /WX /W4 /wd4244 /wd4245 /wd4800 /wd4804 /wd4214 '/FeC:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\BuiltinDirectives.exe' 'C:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\BuiltinDirectives.c'
># BuiltinDirectives.c
># Microsoft (R) Incremental Linker Version 14.28.29913.0
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># /out:C:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\BuiltinDirectives.exe
># BuiltinDirectives.obj
>> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.exe' /WX /W4 /wd4244 /wd4245 /wd4800 /wd4804 /wd4214 '/FeC:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\AMD64LibCHelperDirectives.exe' 'C:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\AMD64LibCHelperDirectives.c'
># AMD64LibCHelperDirectives.c
># Microsoft (R) Incremental Linker Version 14.28.29913.0
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># /out:C:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\AMD64LibCHelperDirectives.exe
># AMD64LibCHelperDirectives.obj
>> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.exe' /WX /W4 /wd4244 /wd4245 /wd4800 /wd4804 /wd4214 '-IC:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\include\win32' '/FeC:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\JNIHeaderDirectives.exe' 'C:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\JNIHeaderDirectives.c'
># JNIHeaderDirectives.c
># Microsoft (R) Incremental Linker Version 14.28.29913.0
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># /out:C:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\JNIHeaderDirectives.exe
># JNIHeaderDirectives.obj
[jframeexample:17168]        (cap):   2,243.90 ms,  0.96 GB
[jframeexample:17168]        setup:   3,952.06 ms,  0.96 GB
[jframeexample:17168]     (clinit):     226.85 ms,  2.96 GB
[jframeexample:17168]   (typeflow):   3,019.63 ms,  2.96 GB
[jframeexample:17168]    (objects):   6,994.10 ms,  2.96 GB
[jframeexample:17168]   (features):   1,514.44 ms,  2.96 GB
[jframeexample:17168]     analysis:  12,180.24 ms,  2.96 GB
[jframeexample:17168]     universe:     846.00 ms,  2.96 GB
[jframeexample:17168]      (parse):     676.65 ms,  2.96 GB
[jframeexample:17168]     (inline):   1,182.39 ms,  3.23 GB
[jframeexample:17168]    (compile):   7,650.35 ms,  3.57 GB
[jframeexample:17168]      compile:  10,443.93 ms,  3.57 GB
[jframeexample:17168]        image:   1,226.67 ms,  3.61 GB
>> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.exe' '/FeC:\Users\mchouhan\Desktop\Issues\github\4072\jframeexample.exe' jframeexample.obj 'C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\svm\clibraries\windows-amd64\libchelper.lib' 'C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\prefs.lib' 'C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\net.lib' 'C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\nio.lib' 'C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\java.lib' 'C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\fdlibm.lib' 'C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\zip.lib' 'C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\svm\clibraries\windows-amd64\jvm.lib' /MD 'C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\svm\clibraries\windows-amd64\libchelper.lib' 'C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\prefs.lib' 'C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\net.lib' 'C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\nio.lib' 'C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\java.lib' 'C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\fdlibm.lib' 'C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\zip.lib' 'C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\svm\clibraries\windows-amd64\jvm.lib' /link /INCREMENTAL:NO /NODEFAULTLIB:LIBCMT '/IMPLIB:C:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\jframeexample.lib' '/LIBPATH:C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64' '/LIBPATH:C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\svm\clibraries\windows-amd64' version.lib advapi32.lib ws2_32.lib secur32.lib iphlpapi.lib userenv.lib setargv.obj /include:JDK_LoadSystemLibrary /include:getEncodingFromLangID /include:getJavaIDFromLangID shell32.lib
># Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29913 for x64
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># Microsoft (R) Incremental Linker Version 14.28.29913.0
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># /out:C:\Users\mchouhan\Desktop\Issues\github\4072\jframeexample.exe
># /INCREMENTAL:NO
># /NODEFAULTLIB:LIBCMT
># /IMPLIB:C:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\jframeexample.lib
># /LIBPATH:C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64
># /LIBPATH:C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\svm\clibraries\windows-amd64
># version.lib
># advapi32.lib
># ws2_32.lib
># secur32.lib
># iphlpapi.lib
># userenv.lib
># setargv.obj
># /include:JDK_LoadSystemLibrary
># /include:getEncodingFromLangID
># /include:getJavaIDFromLangID
># shell32.lib
># jframeexample.obj
># C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\svm\clibraries\windows-amd64\libchelper.lib
># C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\prefs.lib
># C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\net.lib
># C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\nio.lib
># C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\java.lib
># C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\fdlibm.lib
># C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\zip.lib
># C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\svm\clibraries\windows-amd64\jvm.lib
># C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\svm\clibraries\windows-amd64\libchelper.lib
># C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\prefs.lib
># C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\net.lib
># C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\nio.lib
># C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\java.lib
># C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\fdlibm.lib
># C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\static\windows-amd64\zip.lib
># C:\Users\mchouhan\Downloads\graalvm-ce-java11-21.3.0\lib\svm\clibraries\windows-amd64\jvm.lib
>#    Creating library C:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\jframeexample.lib and object C:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\jframeexample.exp
>> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.exe' '/FeC:\Users\mchouhan\Desktop\Issues\github\4072\java.dll' 'C:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\jframeexample.lib' msvcrt.lib /link /dll /implib:java.lib /export:JDK_LoadSystemLibrary /export:JNU_CallMethodByName /export:JNU_CallMethodByNameV /export:JNU_CallStaticMethodByName /export:JNU_ClassString /export:JNU_GetEnv /export:JNU_GetFieldByName /export:JNU_GetStaticFieldByName /export:JNU_IsInstanceOfByName /export:JNU_NewObjectByName /export:JNU_NewStringPlatform /export:JNU_SetFieldByName /export:JNU_ThrowArrayIndexOutOfBoundsException /export:JNU_ThrowByName /export:JNU_ThrowIOException /export:JNU_ThrowIllegalArgumentException /export:JNU_ThrowInternalError 
/export:JNU_ThrowNullPointerException /export:JNU_ThrowOutOfMemoryError /export:getEncodingFromLangID /export:getJavaIDFromLangID /export:jio_snprintf
># Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29913 for x64
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># Microsoft (R) Incremental Linker Version 14.28.29913.0
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># /out:C:\Users\mchouhan\Desktop\Issues\github\4072\java.dll
># /dll
># /implib:java.lib
># /export:JDK_LoadSystemLibrary
># /export:JNU_CallMethodByName
># /export:JNU_CallMethodByNameV
># /export:JNU_CallStaticMethodByName
># /export:JNU_ClassString
># /export:JNU_GetEnv
># /export:JNU_GetFieldByName
># /export:JNU_GetStaticFieldByName
># /export:JNU_IsInstanceOfByName
># /export:JNU_NewObjectByName
># /export:JNU_NewStringPlatform
># /export:JNU_SetFieldByName
># /export:JNU_ThrowArrayIndexOutOfBoundsException
># /export:JNU_ThrowByName
># /export:JNU_ThrowIOException
># /export:JNU_ThrowIllegalArgumentException
># /export:JNU_ThrowInternalError
># /export:JNU_ThrowNullPointerException
># /export:JNU_ThrowOutOfMemoryError
># /export:getEncodingFromLangID
># /export:getJavaIDFromLangID
># /export:jio_snprintf
># C:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\jframeexample.lib
># msvcrt.lib
># LINK : warning LNK4001: no object files specified; libraries used
># LINK : warning LNK4068: /MACHINE not specified; defaulting to X64
>#    Creating library java.lib and object java.exp
>> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.exe' '/FeC:\Users\mchouhan\Desktop\Issues\github\4072\jvm.dll' 'C:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\jframeexample.lib' msvcrt.lib /link /dll /implib:jvm.lib /export:JVM_CurrentTimeMillis /export:JVM_RaiseSignal /export:jio_snprintf
># Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29913 for x64
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># Microsoft (R) Incremental Linker Version 14.28.29913.0
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># /out:C:\Users\mchouhan\Desktop\Issues\github\4072\jvm.dll
># /dll
># /implib:jvm.lib
># /export:JVM_CurrentTimeMillis
># /export:JVM_RaiseSignal
># /export:jio_snprintf
># C:\Users\mchouhan\AppData\Local\Temp\SVM-2104904257493313120\jframeexample.lib
># msvcrt.lib
># LINK : warning LNK4001: no object files specified; libraries used
># LINK : warning LNK4068: /MACHINE not specified; defaulting to X64
>#    Creating library jvm.lib and object jvm.exp
[jframeexample:17168]        write:   2,085.77 ms,  3.61 GB
[jframeexample:17168]      [total]:  32,682.51 ms,  3.61 GB
# Printing build artifacts to: C:\Users\mchouhan\Desktop\Issues\github\4072\jframeexample.build_artifacts.txt

C:\Users\mchouhan\Desktop\Issues\github\4072>jframeexample.exe

C:\Users\mchouhan\Desktop\Issues\github\4072>

@dmclean652
Copy link
Author

dmclean652 commented Dec 9, 2021

I'm not sure what's different. I just performed the exact same test and still had the error. I tried several variants as well and they all behaved the same:

  • Naked classes (as in your test)
  • Classes in a jar
  • Classes in a module
  • Graal's bin folder in the path
  • using explicit path to Graal's bin folder
  • Visual Studio 2019 and 2017

I have a slightly different Visual Studio 2019 version 14.29.30137.0 vs 19.28.29913. But I had an older version and updated today and both gave the same error. I don't have a full Visual Studio 2019, just the build tools.

Are there any other build switches that may be helpful here? Any other parts of the build tools/environment that we can look at that may be different?

C:\code\BKINTools\LogViewer\out\production\BuildTest>native-image JFrameExample --no-fallback -H:+TraceNativeToolUsage
[jframeexample:10924]    classlist:     731.60 ms,  0.96 GB
>> C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe
># Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30137 for x64
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># usage: cl [ option... ] filename... [ /link linkoption... ]
>> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe' /WX /W4 /wd4244 /wd4245 /wd4800 /wd4804 /wd4214 '/FeC:\Users\dmclean\AppData\Local\Temp\SVM-4614138691259221267\WindowsDirectives.exe' 'C:\Users\dmclean\AppData\Local\Temp\SVM-4614138691259221267\WindowsDirectives.c'
># WindowsDirectives.c
># Microsoft (R) Incremental Linker Version 14.29.30137.0
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># /out:C:\Users\dmclean\AppData\Local\Temp\SVM-4614138691259221267\WindowsDirectives.exe
># WindowsDirectives.obj
>> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe' /WX /W4 /wd4244 /wd4245 /wd4800 /wd4804 /wd4214 '/FeC:\Users\dmclean\AppData\Local\Temp\SVM-4614138691259221267\AArch64LibCHelperDirectives.exe' 'C:\Users\dmclean\AppData\Local\Temp\SVM-4614138691259221267\AArch64LibCHelperDirectives.c'
># AArch64LibCHelperDirectives.c
># Microsoft (R) Incremental Linker Version 14.29.30137.0
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># /out:C:\Users\dmclean\AppData\Local\Temp\SVM-4614138691259221267\AArch64LibCHelperDirectives.exe
># AArch64LibCHelperDirectives.obj
>> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe' /WX /W4 /wd4244 /wd4245 /wd4800 /wd4804 /wd4214 '/FeC:\Users\dmclean\AppData\Local\Temp\SVM-4614138691259221267\AMD64LibCHelperDirectives.exe' 'C:\Users\dmclean\AppData\Local\Temp\SVM-4614138691259221267\AMD64LibCHelperDirectives.c'
># AMD64LibCHelperDirectives.c
># Microsoft (R) Incremental Linker Version 14.29.30137.0
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># /out:C:\Users\dmclean\AppData\Local\Temp\SVM-4614138691259221267\AMD64LibCHelperDirectives.exe
># AMD64LibCHelperDirectives.obj
>> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe' /WX /W4 /wd4244 /wd4245 /wd4800 /wd4804 /wd4214 '-IC:\java\graalvm-ce-java17-21.3.0\include\win32' '/FeC:\Users\dmclean\AppData\Local\Temp\SVM-4614138691259221267\JNIHeaderDirectives.exe' 'C:\Users\dmclean\AppData\Local\Temp\SVM-4614138691259221267\JNIHeaderDirectives.c'
># JNIHeaderDirectives.c
># Microsoft (R) Incremental Linker Version 14.29.30137.0
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># /out:C:\Users\dmclean\AppData\Local\Temp\SVM-4614138691259221267\JNIHeaderDirectives.exe
># JNIHeaderDirectives.obj
>> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe' /WX /W4 /wd4244 /wd4245 /wd4800 /wd4804 /wd4214 '/FeC:\Users\dmclean\AppData\Local\Temp\SVM-4614138691259221267\BuiltinDirectives.exe' 'C:\Users\dmclean\AppData\Local\Temp\SVM-4614138691259221267\BuiltinDirectives.c'
># BuiltinDirectives.c
># Microsoft (R) Incremental Linker Version 14.29.30137.0
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># /out:C:\Users\dmclean\AppData\Local\Temp\SVM-4614138691259221267\BuiltinDirectives.exe
># BuiltinDirectives.obj
[jframeexample:10924]        (cap):   1,376.19 ms,  0.96 GB
[jframeexample:10924]        setup:   2,498.61 ms,  0.96 GB
[jframeexample:10924]     (clinit):     270.81 ms,  3.80 GB
[jframeexample:10924]   (typeflow):   3,422.34 ms,  3.80 GB
[jframeexample:10924]    (objects):   7,378.11 ms,  3.80 GB
[jframeexample:10924]   (features):   2,008.98 ms,  3.80 GB
[jframeexample:10924]     analysis:  13,790.68 ms,  3.80 GB
[jframeexample:10924]     universe:     881.51 ms,  3.80 GB
[jframeexample:10924]      (parse):     632.03 ms,  3.80 GB
[jframeexample:10924]     (inline):   1,332.64 ms,  3.81 GB
[jframeexample:10924]    (compile):   8,806.98 ms,  5.03 GB
[jframeexample:10924]      compile:  11,918.46 ms,  5.16 GB
[jframeexample:10924]        image:   1,396.44 ms,  5.16 GB
>> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe' '/FeC:\code\BKINTools\LogViewer\out\production\BuildTest\jframeexample.exe' jframeexample.obj 'C:\java\graalvm-ce-java17-21.3.0\lib\svm\clibraries\windows-amd64\libchelper.lib' 'C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\prefs.lib' 'C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\net.lib' 'C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\nio.lib' 'C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\java.lib' 'C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\fdlibm.lib' 'C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\sunmscapi.lib' 'C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\zip.lib' 'C:\java\graalvm-ce-java17-21.3.0\lib\svm\clibraries\windows-amd64\jvm.lib' /MD 'C:\java\graalvm-ce-java17-21.3.0\lib\svm\clibraries\windows-amd64\libchelper.lib' 'C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\prefs.lib' 'C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\net.lib' 'C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\nio.lib' 'C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\java.lib' 'C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\fdlibm.lib' 'C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\sunmscapi.lib' 'C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\zip.lib' 'C:\java\graalvm-ce-java17-21.3.0\lib\svm\clibraries\windows-amd64\jvm.lib' /link /INCREMENTAL:NO /NODEFAULTLIB:LIBCMT '/IMPLIB:C:\Users\dmclean\AppData\Local\Temp\SVM-4614138691259221267\jframeexample.lib' '/LIBPATH:C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64' '/LIBPATH:C:\java\graalvm-ce-java17-21.3.0\lib\svm\clibraries\windows-amd64' ncrypt.lib crypt32.lib version.lib advapi32.lib ws2_32.lib secur32.lib iphlpapi.lib userenv.lib setargv.obj /include:JDK_LoadSystemLibrary /include:getEncodingFromLangID /include:getJavaIDFromLangID shell32.lib
># Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30137 for x64
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># Microsoft (R) Incremental Linker Version 14.29.30137.0
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># /out:C:\code\BKINTools\LogViewer\out\production\BuildTest\jframeexample.exe
># /INCREMENTAL:NO
># /NODEFAULTLIB:LIBCMT
># /IMPLIB:C:\Users\dmclean\AppData\Local\Temp\SVM-4614138691259221267\jframeexample.lib
># /LIBPATH:C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64
># /LIBPATH:C:\java\graalvm-ce-java17-21.3.0\lib\svm\clibraries\windows-amd64
># ncrypt.lib
># crypt32.lib
># version.lib
># advapi32.lib
># ws2_32.lib
># secur32.lib
># iphlpapi.lib
># userenv.lib
># setargv.obj
># /include:JDK_LoadSystemLibrary
># /include:getEncodingFromLangID
># /include:getJavaIDFromLangID
># shell32.lib
># jframeexample.obj
># C:\java\graalvm-ce-java17-21.3.0\lib\svm\clibraries\windows-amd64\libchelper.lib
># C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\prefs.lib
># C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\net.lib
># C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\nio.lib
># C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\java.lib
># C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\fdlibm.lib
># C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\sunmscapi.lib
># C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\zip.lib
># C:\java\graalvm-ce-java17-21.3.0\lib\svm\clibraries\windows-amd64\jvm.lib
># C:\java\graalvm-ce-java17-21.3.0\lib\svm\clibraries\windows-amd64\libchelper.lib
># C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\prefs.lib
># C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\net.lib
># C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\nio.lib
># C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\java.lib
># C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\fdlibm.lib
># C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\sunmscapi.lib
># C:\java\graalvm-ce-java17-21.3.0\lib\static\windows-amd64\zip.lib
># C:\java\graalvm-ce-java17-21.3.0\lib\svm\clibraries\windows-amd64\jvm.lib
>#    Creating library C:\Users\dmclean\AppData\Local\Temp\SVM-4614138691259221267\jframeexample.lib and object C:\Users\dmclean\AppData\Local\Temp\SVM-4614138691259221267\jframeexample.exp
>> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe' '/FeC:\code\BKINTools\LogViewer\out\production\BuildTest\java.dll' 'C:\Users\dmclean\AppData\Local\Temp\SVM-4614138691259221267\jframeexample.lib' msvcrt.lib /link /dll /implib:java.lib /export:JDK_LoadSystemLibrary /export:JNU_CallMethodByName /export:JNU_CallMethodByNameV /export:JNU_CallStaticMethodByName /export:JNU_ClassString /export:JNU_GetEnv /export:JNU_GetFieldByName /export:JNU_GetStaticFieldByName /export:JNU_IsInstanceOfByName /export:JNU_NewObjectByName /export:JNU_NewStringPlatform /export:JNU_SetFieldByName /export:JNU_ThrowArrayIndexOutOfBoundsException /export:JNU_ThrowByName /export:JNU_ThrowIOException /export:JNU_ThrowIllegalArgumentException /export:JNU_ThrowInternalError /export:JNU_ThrowNullPointerException /export:JNU_ThrowOutOfMemoryError /export:getEncodingFromLangID /export:getJavaIDFromLangID /export:jio_snprintf
># Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30137 for x64
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># Microsoft (R) Incremental Linker Version 14.29.30137.0
># Copyright (C) Microsoft Corporation.  All rights reserved.
>#
># /out:C:\code\BKINTools\LogViewer\out\production\BuildTest\java.dll
># /dll
># /implib:java.lib
># /export:JDK_LoadSystemLibrary
># /export:JNU_CallMethodByName
># /export:JNU_CallMethodByNameV
># /export:JNU_CallStaticMethodByName
># /export:JNU_ClassString
># /export:JNU_GetEnv
># /export:JNU_GetFieldByName
># /export:JNU_GetStaticFieldByName
># /export:JNU_IsInstanceOfByName
># /export:JNU_NewObjectByName
># /export:JNU_NewStringPlatform
># /export:JNU_SetFieldByName
># /export:JNU_ThrowArrayIndexOutOfBoundsException
># /export:JNU_ThrowByName
># /export:JNU_ThrowIOException
># /export:JNU_ThrowIllegalArgumentException
># /export:JNU_ThrowInternalError
># /export:JNU_ThrowNullPointerException
># /export:JNU_ThrowOutOfMemoryError
># /export:getEncodingFromLangID
># /export:getJavaIDFromLangID
># /export:jio_snprintf
># C:\Users\dmclean\AppData\Local\Temp\SVM-4614138691259221267\jframeexample.lib
># msvcrt.lib
># LINK : warning LNK4001: no object files specified; libraries used
># LINK : warning LNK4068: /MACHINE not specified; defaulting to X64
># LINK : error LNK2001: unresolved external symbol JDK_LoadSystemLibrary
># LINK : error LNK2001: unresolved external symbol JNU_CallMethodByName
># LINK : error LNK2001: unresolved external symbol JNU_CallMethodByNameV
># LINK : error LNK2001: unresolved external symbol JNU_CallStaticMethodByName
># LINK : error LNK2001: unresolved external symbol JNU_ClassString
># LINK : error LNK2001: unresolved external symbol JNU_GetEnv
># LINK : error LNK2001: unresolved external symbol JNU_GetFieldByName
># LINK : error LNK2001: unresolved external symbol JNU_GetStaticFieldByName
># LINK : error LNK2001: unresolved external symbol JNU_IsInstanceOfByName
># LINK : error LNK2001: unresolved external symbol JNU_NewObjectByName
># LINK : error LNK2001: unresolved external symbol JNU_NewStringPlatform
># LINK : error LNK2001: unresolved external symbol JNU_SetFieldByName
># LINK : error LNK2001: unresolved external symbol JNU_ThrowArrayIndexOutOfBoundsException
># LINK : error LNK2001: unresolved external symbol JNU_ThrowByName
># LINK : error LNK2001: unresolved external symbol JNU_ThrowIOException
># LINK : error LNK2001: unresolved external symbol JNU_ThrowIllegalArgumentException
># LINK : error LNK2001: unresolved external symbol JNU_ThrowInternalError
># LINK : error LNK2001: unresolved external symbol JNU_ThrowNullPointerException
># LINK : error LNK2001: unresolved external symbol JNU_ThrowOutOfMemoryError
># java.lib : fatal error LNK1120: 19 unresolved externals
[jframeexample:10924]        write:     430.59 ms,  5.16 GB
Fatal error:com.oracle.svm.core.util.VMError$HostedError: should not reach here
        at com.oracle.svm.core.util.VMError.shouldNotReachHere(VMError.java:64)
        at com.oracle.svm.hosted.jdk.JNIRegistrationSupport.makeShimDLL(JNIRegistrationSupport.java:256)
        at com.oracle.svm.hosted.jdk.JNIRegistrationSupport.makeShimDLLs(JNIRegistrationSupport.java:230)
        at com.oracle.svm.hosted.jdk.JNIRegistrationSupport.afterImageWrite(JNIRegistrationSupport.java:175)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$doRun$8(NativeImageGenerator.java:663)
        at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:73)
        at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:663)
        at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:488)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:569)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:122)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:599)
[jframeexample:10924]      [total]:  31,864.00 ms,  5.16 GB
# Printing build artifacts to: C:\code\BKINTools\LogViewer\out\production\BuildTest\jframeexample.build_artifacts.txt
Error: Image build request failed with exit status 1

@chirontt
Copy link

chirontt commented Dec 9, 2021

@mcraj017 if you try it with the JDK17 version of GraalVM, you'll see the error. The JDK11 version works properly, as you've shown.

@dmclean652 try using the JDK11 version of GraalVM to compile your app; it may work. It certainly works for the sample code above. The JDK17 version definitely fails to link, as you've shown.

@munishchouhan
Copy link
Contributor

@chirontt thanks for the correction
I have raised this issue with native-image team

@dmclean652
Copy link
Author

Using JDK11 I found:

  1. I could build and run the JFrameExample demo code
  2. I could not build my project if I use modules
  3. I could build my project if I use just a classpath
  4. When I tried to run my project after building I got NoSuchMethodError on java.awt.Toolkit.getDefaultToolkit()

Building with modules

> java -agentlib:native-image-agent=config-output-dir=META-INF/native-image --module-path . -m LogViewer/com.bkin.logviewer.gui.LogViewer
> native-image --module-path . -m LogViewer/com.bkin.logviewer.gui.LogViewer -H:+ReportExceptionStackTraces -H:+TraceNativeToolUsage
[logviewer:1256]    classlist:     878.09 ms,  0.96 GB
[logviewer:1256]        setup:     146.62 ms,  0.96 GB
Error: Could not find class predefinition configuration resource "META-INF\native-image\predefined-classes-config.json".
com.oracle.svm.core.util.UserError$UserException: Could not find class predefinition configuration resource "META-INF\native-image\predefined-classes-config.json".
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.UserError.abort(UserError.java:73)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.config.ConfigurationParserUtils.lambda$parseAndRegisterConfigurations$2(ConfigurationParserUtils.java:98)
        at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:271)
        at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
        at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:312)
        at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:734)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
        at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.IntPipeline.reduce(IntPipeline.java:491)
        at java.base/java.util.stream.IntPipeline.sum(IntPipeline.java:449)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.config.ConfigurationParserUtils.parseAndRegisterConfigurations(ConfigurationParserUtils.java:115)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.ClassPredefinitionFeature.afterRegistration(ClassPredefinitionFeature.java:73)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.lambda$setupNativeImage$15(NativeImageGenerator.java:825)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:73)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:825)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:527)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:488)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:569)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:122)
[logviewer:1256]      [total]:   1,065.36 ms,  0.96 GB
# Printing build artifacts to: C:\code\BKINTools\LogViewer\out\pack\logviewer.build_artifacts.txt
Error: Image build request failed with exit status 1

Result of building with classpath only

> java -agentlib:native-image-agent=config-output-dir=META-INF/native-image -jar LogViewer_1.2.12.jar
> native-image -jar LogViewer_1.2.12.jar
[LogViewer_1.2.12:5368]    classlist:     844.37 ms,  0.96 GB
[LogViewer_1.2.12:5368]        (cap):   1,242.12 ms,  0.96 GB
[LogViewer_1.2.12:5368]        setup:   2,496.73 ms,  0.96 GB
[LogViewer_1.2.12:5368]     (clinit):     308.49 ms,  2.96 GB
[LogViewer_1.2.12:5368]   (typeflow):   3,303.72 ms,  2.96 GB
[LogViewer_1.2.12:5368]    (objects):   7,775.81 ms,  2.96 GB
[LogViewer_1.2.12:5368]   (features):   1,871.98 ms,  2.96 GB
[LogViewer_1.2.12:5368]     analysis:  13,958.91 ms,  2.96 GB
[LogViewer_1.2.12:5368]     universe:     902.03 ms,  2.96 GB
[LogViewer_1.2.12:5368]      (parse):     635.41 ms,  2.96 GB
[LogViewer_1.2.12:5368]     (inline):   1,048.51 ms,  3.00 GB
[LogViewer_1.2.12:5368]    (compile):  10,624.43 ms,  3.67 GB
[LogViewer_1.2.12:5368]      compile:  13,452.98 ms,  3.70 GB
[LogViewer_1.2.12:5368]        image:   2,280.54 ms,  3.70 GB
[LogViewer_1.2.12:5368]        write:     440.86 ms,  3.70 GB
[LogViewer_1.2.12:5368]      [total]:  34,553.90 ms,  3.70 GB
# Printing build artifacts to: C:\code\BKINTools\LogViewer\out\pack\LogViewer_1.2.12.build_artifacts.txt

> LogViewer_1.2.12.exe 
Exception in thread "main" java.lang.NoSuchMethodError: java.awt.Toolkit.getDefaultToolkit()Ljava/awt/Toolkit;
        at com.oracle.svm.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1114)
        at com.oracle.svm.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1099)
        at com.oracle.svm.jni.functions.JNIFunctions.GetStaticMethodID(JNIFunctions.java:416)
        at java.awt.Toolkit.initIDs(Toolkit.java)
        at java.awt.Toolkit.<clinit>(Toolkit.java:1427)
        at javax.swing.UIManager.<clinit>(UIManager.java:383)
        at com.bkin.logviewer.gui.utils.GUIUtils.setLookAndFeel(Unknown Source)
        at com.bkin.logviewer.gui.LogViewer.main(Unknown Source)

This can be reproduced using the example code:

public class JFrameExample {

    public static void main(String[] args) {

        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            e.printStackTrace();
        }

        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                displayJFrame();
            }
        });
    }

    static void displayJFrame() {
        JFrame frame = new JFrame("My JFrame Example");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setPreferredSize(new Dimension(400, 200));
        frame.pack();
        frame.setVisible(true);
    }
}

@chirontt
Copy link

@dmclean652 Your above example code works fine for me. Using the JDK11 version of GraalVM, here are the simple steps to compile it successfully to a native executable in Windows:

> javac JFrameExample.java
> java -agentlib:native-image-agent=config-output-dir=META-INF/native-image JFrameExample
> jar --create --file JFrameExample.jar --main-class=JFrameExample *.class META-INF
> native-image -jar JFrameExample.jar

Then just run the resulting native image:

> JFrameExample.exe -Djava.home="%JAVA_HOME%"

which would display a simple JFrame on screen.

@kkriske
Copy link
Contributor

kkriske commented Jan 30, 2022

@christianwimmer
for some reason, the created exe does not export these symbols anymore. This is a general issue with the java.dll shim on jdk 17.
Replacing these:

linkerInvocation.addNativeLinkerOption("/include:JDK_LoadSystemLibrary");
linkerInvocation.addNativeLinkerOption("/include:getEncodingFromLangID");
linkerInvocation.addNativeLinkerOption("/include:getJavaIDFromLangID");

With:

linkerInvocation.addNativeLinkerOption("/export:JDK_LoadSystemLibrary");
linkerInvocation.addNativeLinkerOption("/export:JNU_CallMethodByName");
linkerInvocation.addNativeLinkerOption("/export:JNU_CallMethodByNameV");
linkerInvocation.addNativeLinkerOption("/export:JNU_CallStaticMethodByName");
linkerInvocation.addNativeLinkerOption("/export:JNU_ClassString");
linkerInvocation.addNativeLinkerOption("/export:JNU_GetEnv");
linkerInvocation.addNativeLinkerOption("/export:JNU_GetFieldByName");
linkerInvocation.addNativeLinkerOption("/export:JNU_GetStaticFieldByName");
linkerInvocation.addNativeLinkerOption("/export:JNU_IsInstanceOfByName");
linkerInvocation.addNativeLinkerOption("/export:JNU_NewObjectByName");
linkerInvocation.addNativeLinkerOption("/export:JNU_NewStringPlatform");
linkerInvocation.addNativeLinkerOption("/export:JNU_SetFieldByName");
linkerInvocation.addNativeLinkerOption("/export:JNU_ThrowArrayIndexOutOfBoundsException");
linkerInvocation.addNativeLinkerOption("/export:JNU_ThrowByName");
linkerInvocation.addNativeLinkerOption("/export:JNU_ThrowIOException");
linkerInvocation.addNativeLinkerOption("/export:JNU_ThrowIllegalArgumentException");
linkerInvocation.addNativeLinkerOption("/export:JNU_ThrowInternalError");
linkerInvocation.addNativeLinkerOption("/export:JNU_ThrowNullPointerException");
linkerInvocation.addNativeLinkerOption("/export:JNU_ThrowOutOfMemoryError");
linkerInvocation.addNativeLinkerOption("/export:getEncodingFromLangID");
linkerInvocation.addNativeLinkerOption("/export:getJavaIDFromLangID");

seems to fix the issue. Same list that gets passed to the java shim generation:

jniRegistrationSupport.addJavaShimExports(
"JDK_LoadSystemLibrary",
"JNU_CallMethodByName",
"JNU_CallMethodByNameV",
"JNU_CallStaticMethodByName",
"JNU_ClassString",
"JNU_GetEnv",
"JNU_GetFieldByName",
"JNU_GetStaticFieldByName",
"JNU_IsInstanceOfByName",
"JNU_NewObjectByName",
"JNU_NewStringPlatform",
"JNU_SetFieldByName",
"JNU_ThrowArrayIndexOutOfBoundsException",
"JNU_ThrowByName",
"JNU_ThrowIOException",
"JNU_ThrowIllegalArgumentException",
"JNU_ThrowInternalError",
"JNU_ThrowNullPointerException",
"JNU_ThrowOutOfMemoryError",
"getEncodingFromLangID",
"getJavaIDFromLangID");

Seems to do the trick on jdk 17 and doesn't break jdk 11, from a few simple test cases I ran.

@kkriske
Copy link
Contributor

kkriske commented Jan 30, 2022

For anyone else looking for a workaround in the meantime, add a feature containing this in your codebase:

    @Override
    public void beforeImageWrite(BeforeImageWriteAccess access) {
        ((FeatureImpl.BeforeImageWriteAccessImpl) access).registerLinkerInvocationTransformer(linkerInvocation -> {
            linkerInvocation.addNativeLinkerOption("/export:JDK_LoadSystemLibrary");
            linkerInvocation.addNativeLinkerOption("/export:JNU_CallMethodByName");
            linkerInvocation.addNativeLinkerOption("/export:JNU_CallMethodByNameV");
            linkerInvocation.addNativeLinkerOption("/export:JNU_CallStaticMethodByName");
            linkerInvocation.addNativeLinkerOption("/export:JNU_ClassString");
            linkerInvocation.addNativeLinkerOption("/export:JNU_GetEnv");
            linkerInvocation.addNativeLinkerOption("/export:JNU_GetFieldByName");
            linkerInvocation.addNativeLinkerOption("/export:JNU_GetStaticFieldByName");
            linkerInvocation.addNativeLinkerOption("/export:JNU_IsInstanceOfByName");
            linkerInvocation.addNativeLinkerOption("/export:JNU_NewObjectByName");
            linkerInvocation.addNativeLinkerOption("/export:JNU_NewStringPlatform");
            linkerInvocation.addNativeLinkerOption("/export:JNU_SetFieldByName");
            linkerInvocation.addNativeLinkerOption("/export:JNU_ThrowArrayIndexOutOfBoundsException");
            linkerInvocation.addNativeLinkerOption("/export:JNU_ThrowByName");
            linkerInvocation.addNativeLinkerOption("/export:JNU_ThrowIOException");
            linkerInvocation.addNativeLinkerOption("/export:JNU_ThrowIllegalArgumentException");
            linkerInvocation.addNativeLinkerOption("/export:JNU_ThrowInternalError");
            linkerInvocation.addNativeLinkerOption("/export:JNU_ThrowNullPointerException");
            linkerInvocation.addNativeLinkerOption("/export:JNU_ThrowOutOfMemoryError");
            linkerInvocation.addNativeLinkerOption("/export:getEncodingFromLangID");
            linkerInvocation.addNativeLinkerOption("/export:getJavaIDFromLangID");
            return linkerInvocation;
        });
    }

or add them as -H:NativeLinkerOption cli options.

@abhay7dev
Copy link

For anyone else looking for a workaround in the meantime, add a feature containing this in your codebase:

    @Override
    public void beforeImageWrite(BeforeImageWriteAccess access) {
        ((FeatureImpl.BeforeImageWriteAccessImpl) access).registerLinkerInvocationTransformer(linkerInvocation -> {
            linkerInvocation.addNativeLinkerOption("/export:JDK_LoadSystemLibrary");
            linkerInvocation.addNativeLinkerOption("/export:JNU_CallMethodByName");
            linkerInvocation.addNativeLinkerOption("/export:JNU_CallMethodByNameV");
            linkerInvocation.addNativeLinkerOption("/export:JNU_CallStaticMethodByName");
            linkerInvocation.addNativeLinkerOption("/export:JNU_ClassString");
            linkerInvocation.addNativeLinkerOption("/export:JNU_GetEnv");
            linkerInvocation.addNativeLinkerOption("/export:JNU_GetFieldByName");
            linkerInvocation.addNativeLinkerOption("/export:JNU_GetStaticFieldByName");
            linkerInvocation.addNativeLinkerOption("/export:JNU_IsInstanceOfByName");
            linkerInvocation.addNativeLinkerOption("/export:JNU_NewObjectByName");
            linkerInvocation.addNativeLinkerOption("/export:JNU_NewStringPlatform");
            linkerInvocation.addNativeLinkerOption("/export:JNU_SetFieldByName");
            linkerInvocation.addNativeLinkerOption("/export:JNU_ThrowArrayIndexOutOfBoundsException");
            linkerInvocation.addNativeLinkerOption("/export:JNU_ThrowByName");
            linkerInvocation.addNativeLinkerOption("/export:JNU_ThrowIOException");
            linkerInvocation.addNativeLinkerOption("/export:JNU_ThrowIllegalArgumentException");
            linkerInvocation.addNativeLinkerOption("/export:JNU_ThrowInternalError");
            linkerInvocation.addNativeLinkerOption("/export:JNU_ThrowNullPointerException");
            linkerInvocation.addNativeLinkerOption("/export:JNU_ThrowOutOfMemoryError");
            linkerInvocation.addNativeLinkerOption("/export:getEncodingFromLangID");
            linkerInvocation.addNativeLinkerOption("/export:getJavaIDFromLangID");
            return linkerInvocation;
        });
    }

or add them as -H:NativeLinkerOption cli options.

@kkriske , If you can, can you be more specific on how we add this to a codebase or more preferably, how to pass these as cli options because I have not been able to find any useful documentation on this specific option (-H:NativeLinkerOption).

Thanks

@kkriske
Copy link
Contributor

kkriske commented Jan 30, 2022

@EpicGamer007
from the output of native-image --expert-options-all

  -H:NativeLinkerOption=<string>*              Pass the provided raw option that will be appended to the linker command to produce the final binary. The possible
                                               options are platform specific and passed through without any validation.

so your native-image command would become something like:

native-image -H:NativeLinkerOption=/export:JDK_LoadSystemLibrary -H:NativeLinkerOption=/export:JNU_CallMethodByName -H:NativeLinkerOption=/export:JNU_CallMethodByNameV -H:NativeLinkerOption=/export:JNU_CallStaticMethodByName -H:NativeLinkerOption=/export:JNU_ClassString -H:NativeLinkerOption=/export:JNU_GetEnv -H:NativeLinkerOption=/export:JNU_GetFieldByName -H:NativeLinkerOption=/export:JNU_GetStaticFieldByName -H:NativeLinkerOption=/export:JNU_IsInstanceOfByName -H:NativeLinkerOption=/export:JNU_NewObjectByName -H:NativeLinkerOption=/export:JNU_NewStringPlatform -H:NativeLinkerOption=/export:JNU_SetFieldByName -H:NativeLinkerOption=/export:JNU_ThrowArrayIndexOutOfBoundsException -H:NativeLinkerOption=/export:JNU_ThrowByName -H:NativeLinkerOption=/export:JNU_ThrowIOException -H:NativeLinkerOption=/export:JNU_ThrowIllegalArgumentException -H:NativeLinkerOption=/export:JNU_ThrowInternalError -H:NativeLinkerOption=/export:JNU_ThrowNullPointerException -H:NativeLinkerOption=/export:JNU_ThrowOutOfMemoryError

after checking, it appears that getEncodingFromLangID and getJavaIDFromLangID are not required in the list.

@abhay7dev
Copy link

@EpicGamer007 from the output of native-image --expert-options-all

  -H:NativeLinkerOption=<string>*              Pass the provided raw option that will be appended to the linker command to produce the final binary. The possible
                                               options are platform specific and passed through without any validation.

so your native-image command would become something like:

native-image -H:NativeLinkerOption=/export:JDK_LoadSystemLibrary -H:NativeLinkerOption=/export:JNU_CallMethodByName -H:NativeLinkerOption=/export:JNU_CallMethodByNameV -H:NativeLinkerOption=/export:JNU_CallStaticMethodByName -H:NativeLinkerOption=/export:JNU_ClassString -H:NativeLinkerOption=/export:JNU_GetEnv -H:NativeLinkerOption=/export:JNU_GetFieldByName -H:NativeLinkerOption=/export:JNU_GetStaticFieldByName -H:NativeLinkerOption=/export:JNU_IsInstanceOfByName -H:NativeLinkerOption=/export:JNU_NewObjectByName -H:NativeLinkerOption=/export:JNU_NewStringPlatform -H:NativeLinkerOption=/export:JNU_SetFieldByName -H:NativeLinkerOption=/export:JNU_ThrowArrayIndexOutOfBoundsException -H:NativeLinkerOption=/export:JNU_ThrowByName -H:NativeLinkerOption=/export:JNU_ThrowIOException -H:NativeLinkerOption=/export:JNU_ThrowIllegalArgumentException -H:NativeLinkerOption=/export:JNU_ThrowInternalError -H:NativeLinkerOption=/export:JNU_ThrowNullPointerException -H:NativeLinkerOption=/export:JNU_ThrowOutOfMemoryError

after checking, it appears that getEncodingFromLangID and getJavaIDFromLangID are not required in the list.

Thank you so much :)

@chirontt
Copy link

@kkriske thanks a lot for your great workaround. This problem in Windows has stumped us since GraalVM 21.3.0 for JDK17, and still persists in 21.3.1 and in 22.0.0.2.

Talking about 22.0.0.2, it has new link errors in Linux (in addition to in Windows which is fixed by your tip) for the JDK17 version, for the simple Swing code above. But I guess this new Linux problem will be for another issue thread...

@christianwimmer
Copy link

@pejovica can you please check what is going on?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants