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

[native-image] Windows with a swing application #1327

Open
Skhmt opened this issue May 24, 2019 · 103 comments
Open

[native-image] Windows with a swing application #1327

Skhmt opened this issue May 24, 2019 · 103 comments

Comments

@Skhmt
Copy link

Skhmt commented May 24, 2019

Running: C:\graalvm-ce-19.0.0\bin\native-image.cmd -jar jPatcher.jar --no-fallback

I get the following:

Error: Unsupported features in 2 methods
Detailed message:
Error: Detected a started Thread in the image heap. Threads running in the image generator are no longer running at image run time. The object was probably created by a class initializer and is reachable from a static field. By default, all class initialization is done during native image building.You can manually delay class initialization to image run time by using the option -H:ClassInitialization=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
Trace:  object sun.awt.AWTAutoShutdown
        method sun.awt.AWTAutoShutdown.getInstance()
Call path from entry point to sun.awt.AWTAutoShutdown.getInstance():
        at sun.awt.AWTAutoShutdown.getInstance(AWTAutoShutdown.java:133)
        at java.awt.EventQueue.detachDispatchThread(EventQueue.java:1137)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:88)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:473)
        at com.oracle.svm.core.windows.WindowsJavaThreads.osThreadStartRoutine(WindowsJavaThreads.java:137)
        at com.oracle.svm.core.code.IsolateEnterStub.WindowsJavaThreads_osThreadStartRoutine_4bc03aa26f8cdfc97ebd54050e8ae4bce1023851(generated:0)
Error: Detected a started Thread in the image heap. Threads running in the image generator are no longer running at image run time. The object was probably created by a class initializer and is reachable from a static field. By default, all class initialization is done during native image building.You can manually delay class initialization to image run time by using the option -H:ClassInitialization=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
Trace:  object sun.java2d.opengl.OGLRenderQueue
        field sun.java2d.opengl.OGLRenderQueue.theInstance

Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
Error: Image build request failed with exit status 1

So then I run: C:\graalvm-ce-19.0.0\bin\native-image.cmd -jar jPatcher.jar --no-fallback --initialize-at-run-time=sun.awt.AWTAutoShutdown,sun.java2d.opengl.OGLRenderQueue

Now I get:

Error: Unsupported features in 4 methods
Detailed message:
Error: No instances are allowed in the image heap for a class that is initialized or reinitialized at image runtime: sun.java2d.opengl.OGLRenderQueue. Try marking this class for build-time initialization with --initialize-at-build-time=sun.java2d.opengl.OGLRenderQueue
Trace:  object sun.java2d.opengl.OGLMaskBlit
        object sun.java2d.loops.GraphicsPrimitive[]
        field sun.java2d.loops.GraphicsPrimitiveMgr.primitives
Error: No instances are allowed in the image heap for a class that is initialized or reinitialized at image runtime: sun.java2d.opengl.OGLRenderQueue. Try marking this class for build-time initialization with --initialize-at-build-time=sun.java2d.opengl.OGLRenderQueue
Trace:  object sun.java2d.opengl.OGLMaskFill
        object sun.java2d.loops.GraphicsPrimitive[]
        field sun.java2d.loops.GraphicsPrimitiveMgr.primitives
Error: No instances are allowed in the image heap for a class that is initialized or reinitialized at image runtime: sun.java2d.opengl.OGLRenderQueue. Try marking this class for build-time initialization with --initialize-at-build-time=sun.java2d.opengl.OGLRenderQueue
Trace:  object sun.java2d.opengl.OGLRenderer
        field sun.java2d.opengl.OGLSurfaceData.oglRenderPipe
Error: No instances are allowed in the image heap for a class that is initialized or reinitialized at image runtime: sun.java2d.opengl.OGLRenderQueue. Try marking this class for build-time initialization with --initialize-at-build-time=sun.java2d.opengl.OGLRenderQueue
Trace:  object sun.java2d.opengl.OGLTextRenderer
        field sun.java2d.opengl.OGLSurfaceData.oglTextPipe

What do I do now? It's saying to mark sun.java2d.opengl.OGLRenderQueue for initialization at run time when it's marked for initialization at build time and it says to mark it for initialization at build time when it's marked for initialization at run time.

@vjovanov
Copy link
Member

The problem here is that we still mark the whole JDK as build-time by default. The error message is misleading here--I am improving this case in a separate PR.

Here you need to see what pulls those instances in the heap and mark that as run-time as well. We have another improvement that should show you the stack trace for when those got initialized.

Till those PRs, you can attach with a debugger (--debug-attach) and see when the classes get instantiated. Then you can delay the classes that instantiate the illegal elements.

@Dirzei
Copy link

Dirzei commented Jul 9, 2019

Anything new on this issue? I also run over it using the following code:

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.WindowConstants;

public class GUIlauncher {
private static void createAndShowGUI() {
JFrame frame = new JFrame("Hello World from Java");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setPreferredSize(new Dimension(750, 500));
JComboBox clustersCombo = new JComboBox<>(new Integer[]{2, 3, 4, 5, 6, 7});
clustersCombo.setSelectedIndex(2);
frame.setLayout(new BorderLayout(20, 20));
Container pane = frame.getContentPane();
pane.add(clustersCombo, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) throws Exception {
javax.swing.SwingUtilities.invokeLater(() -> createAndShowGUI());
}
}

[guilauncher:11788] classlist: 4,565.27 ms
[guilauncher:11788] (cap): 2,597.87 ms
[guilauncher:11788] setup: 4,542.97 ms
[guilauncher:11788] analysis: 25,561.63 ms
Warning: Aborting stand-alone image build. Unsupported features in 2 methods
Detailed message:
Error: Detected a started Thread in the image heap. Threads running in the image generator are no longer running at image run time. The object was probably created by a class initializer and is reachable from a static field. By default, all class initialization is done during native image building.You can manually delay class initialization to image run time by using the option -H:ClassInitialization=. Or you can write your own initialization methods and call them explicitly from your main entry point.
Trace: object sun.awt.AWTAutoShutdown
method sun.awt.AWTAutoShutdown.getInstance()
Call path from entry point to sun.awt.AWTAutoShutdown.getInstance():
at sun.awt.AWTAutoShutdown.getInstance(AWTAutoShutdown.java:133)
at java.awt.EventQueue.detachDispatchThread(EventQueue.java:1137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:88)
at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:473)
at com.oracle.svm.core.windows.WindowsJavaThreads.osThreadStartRoutine(WindowsJavaThreads.java:137)
at com.oracle.svm.core.code.IsolateEnterStub.WindowsJavaThreads_osThreadStartRoutine_4bc03aa26f8cdfc97ebd54050e8ae4bce1023851(generated:0)
Error: Detected a started Thread in the image heap. Threads running in the image generator are no longer running at image run time. The object was probably created by a class initializer and is reachable from a static field. By default, all class initialization is done during native image building.You can manually delay class initialization to image run time by using the option -H:ClassInitialization=. Or you can write your own initialization methods and call them explicitly from your main entry point.
Trace: object sun.java2d.opengl.OGLRenderQueue
field sun.java2d.opengl.OGLRenderQueue.theInstance

@hogfilho
Copy link

hogfilho commented Jul 17, 2019

Any update on this? I am also unable to build a swing application on linux using native-image and --no-fallback option.

I can build using this:

[helder@priceshooter bin]$ ./native-image -Dsun.java2d.opengl=false GraalTest graaltest --no-fallback --initialize-at-run-time=sun.java2d.opengl
Build on Server(pid: 22022, port: 34217)*
[graaltest:22022]    classlist:   1,033.71 ms
[graaltest:22022]        (cap):     757.28 ms
[graaltest:22022]        setup:   1,752.65 ms
[graaltest:22022]   (typeflow):   8,958.36 ms
[graaltest:22022]    (objects):   7,474.16 ms
[graaltest:22022]   (features):     396.55 ms
[graaltest:22022]     analysis:  17,254.32 ms
[graaltest:22022]     (clinit):     220.61 ms
[graaltest:22022]     universe:     593.90 ms
[graaltest:22022]      (parse):   1,054.77 ms
[graaltest:22022]     (inline):   2,159.05 ms
[graaltest:22022]    (compile):  12,253.07 ms
[graaltest:22022]      compile:  16,189.83 ms
[graaltest:22022]        image:   1,013.48 ms
[graaltest:22022]        write:     217.79 ms
[graaltest:22022]      [total]:  38,185.44 ms

But when I run the executable:

[helder@priceshooter bin]$ ./graaltest
Exception in thread "main" java.lang.IllegalArgumentException: AWT is currently not supported on Substrate VM
        at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:37)
        at java.awt.Toolkit.getEventQueue(Toolkit.java:1736)
        at java.awt.EventQueue.invokeLater(EventQueue.java:1294)
        at GraalTest.main(GraalTest.java:7)

Any idea if Swing/AWT will be supported?

@dvzs1
Copy link

dvzs1 commented Jul 20, 2019

I have the same problem. Unfortunately the compiled exe is not working alone. If you store the jar file in the same folder with the exe, it works, but without the jar could not be run… The program breaks with a AWT Thread.. If you compile the program, without reffering a swing window instance, then it could be compiled.. but running with a swing window, the system could not find the MAIN entrance point of the compiled exe.. Instantiating the swing window with a method, then ERRORS are coming all the time and all the way….

@dvzs1
Copy link

dvzs1 commented Jul 20, 2019

It seems that only console applications can be made .. But this is nonsense, mixture with NET Framework and Java.. appjav source code makking.. Would it be good if it worked, but how long would it take? I tried with 8u221, but unfortunately the end result is not a standalone executable .. The JAR is already an executable, then why is this all?

@dvzs1
Copy link

dvzs1 commented Jul 20, 2019

I would suggest that if the EXE only work with JAR, put the resources and required codes for running the EXE into the JAR.

@alvinj
Copy link

alvinj commented Jul 20, 2019

I’m curious if there is a solution for this? I’m having the same problem with a relatively simple Swing application.

@alvinj
Copy link

alvinj commented Jul 20, 2019

If it helps to know it, here’s a simple test app:

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);
    }

}

And this is the result I get with the native-image command:

> native-image JFrameExample
Build on Server(pid: 18953, port: 55329)
[jframeexample:18953]    classlist:     169.84 ms
[jframeexample:18953]        (cap):     808.36 ms
[jframeexample:18953]        setup:   1,050.86 ms
[jframeexample:18953]     analysis:   4,669.92 ms
Warning: Aborting stand-alone image build. Unsupported features in 2 methods
Detailed message:
Error: Detected a started Thread in the image heap. Threads running in the image generator are no longer running at image run time. The object was probably created by a class initializer and is reachable from a static field. By default, all class initialization is done during native image building.You can manually delay class initialization to image run time by using the option -H:ClassInitialization=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
Trace: 	object sun.awt.AWTAutoShutdown
	method sun.awt.AWTAutoShutdown.getInstance()
Call path from entry point to sun.awt.AWTAutoShutdown.getInstance(): 
	at sun.awt.AWTAutoShutdown.getInstance(AWTAutoShutdown.java:133)
	at java.awt.EventQueue.detachDispatchThread(EventQueue.java:1137)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:88)
	at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:460)
	at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
	at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
Error: Detected a started Thread in the image heap. Threads running in the image generator are no longer running at image run time. The object was probably created by a class initializer and is reachable from a static field. By default, all class initialization is done during native image building.You can manually delay class initialization to image run time by using the option -H:ClassInitialization=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
Trace: 	object sun.java2d.opengl.OGLRenderQueue
	field sun.java2d.opengl.OGLRenderQueue.theInstance

Warning: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
Build on Server(pid: 18953, port: 55329)
[jframeexample:18953]    classlist:     179.46 ms
[jframeexample:18953]        (cap):     809.14 ms
[jframeexample:18953]        setup:   1,064.64 ms
[jframeexample:18953]   (typeflow):   1,339.48 ms
[jframeexample:18953]    (objects):   1,492.08 ms
[jframeexample:18953]   (features):     100.08 ms
[jframeexample:18953]     analysis:   2,981.23 ms
[jframeexample:18953]     (clinit):      55.78 ms
[jframeexample:18953]     universe:     156.34 ms
[jframeexample:18953]      (parse):     210.12 ms
[jframeexample:18953]     (inline):     531.07 ms
[jframeexample:18953]    (compile):   1,324.18 ms
[jframeexample:18953]      compile:   2,226.73 ms
[jframeexample:18953]        image:     217.91 ms
[jframeexample:18953]        write:      89.76 ms
[jframeexample:18953]      [total]:   6,959.42 ms
Warning: Image 'jframeexample' is a fallback image that requires a JDK for execution (use --no-fallback to suppress fallback image generation).

I’m just getting started with GraalVM, but I thought it would be great to create Swing apps as executables because they tend to start so slow, and consume a lot of RAM for even basic apps.

Thanks!

@hogfilho
Copy link

I am still out of luck... Devs, please help us!

@vjovanov
Copy link
Member

vjovanov commented Jul 24, 2019

From the next release (already in master) you can use -H:+TraceClassInitialization to see how this Thread got initialized. You need to use --initialize-at-build-time in the right places to prevent this from happening.

When you come up with a working formula, we should merge this into the repo as this falls under the JDK.

@alvinj
Copy link

alvinj commented Jul 24, 2019

That will be great, I’m looking forward to it!

@pquiring
Copy link

pquiring commented Aug 8, 2019

I think once Graal is built with later JDKs that support for AWT will be included. The newer JDKs will most likely avoid using class init threads that are not supported by native-image.

@Skhmt
Copy link
Author

Skhmt commented Aug 21, 2019

I tried again to build a "hello world" Swing jar with GraalVM CE 19.2.0 and got a huge amount of errors that I have no idea how to solve:

C:\nitest>C:\graalvm-ce-19.2.0\bin\native-image -jar .\helloworlds.jar --no-fallback --initialize-at-run-time=sun.java2d.d3d,sun.java2d.opengl
[helloworlds:13808]    classlist:   1,453.93 ms
[helloworlds:13808]        (cap):   1,604.06 ms
[helloworlds:13808]        setup:   2,355.57 ms
[helloworlds:13808]   (typeflow):   6,219.09 ms
[helloworlds:13808]    (objects):   5,413.88 ms
[helloworlds:13808]   (features):     355.08 ms
[helloworlds:13808]     analysis:  12,229.48 ms
[helloworlds:13808]     (clinit):     191.90 ms
[helloworlds:13808]     universe:     472.52 ms
[helloworlds:13808]      (parse):     775.62 ms
[helloworlds:13808]     (inline):   2,242.06 ms
[helloworlds:13808]    (compile):   6,919.82 ms
[helloworlds:13808]      compile:  10,547.76 ms
[helloworlds:13808]        image:     909.52 ms
[helloworlds:13808]        write:     160.69 ms
Fatal error: java.lang.RuntimeException: java.lang.RuntimeException: host C compiler or linker does not seem to work: java.lang.RuntimeException: returned 2

Running command: CL /MD /Zi /PDBSTRIPPED /FeC:\nitest\helloworlds.exe C:\Users\S\AppData\Local\Temp\SVM-4777097413826739274\helloworlds.obj C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\ffi.lib C:\graalvm-ce-19.2.0\jre\lib\java.lib C:\graalvm-ce-19.2.0\jre\lib\net.lib C:\graalvm-ce-19.2.0\jre\lib\nio.lib C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\libchelper.lib C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\strictmath.lib C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\jvm.lib C:\graalvm-ce-19.2.0\jre\lib\zip.lib C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\ffi.lib C:\graalvm-ce-19.2.0\jre\lib\java.lib C:\graalvm-ce-19.2.0\jre\lib\net.lib C:\graalvm-ce-19.2.0\jre\lib\nio.lib C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\libchelper.lib C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\strictmath.lib C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\jvm.lib C:\graalvm-ce-19.2.0\jre\lib\zip.lib /link /INCREMENTAL:NO /NODEFAULTLIB:LIBCMT /NODEFAULTLIB:OLDNAMES /LIBPATH:C:\graalvm-ce-19.2.0\jre\lib /LIBPATH:C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64 advapi32.lib ws2_32.lib secur32.lib iphlpapi.lib

Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

cl : Command line warning D9002 : ignoring unknown option '/PDBSTRIPPED'
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/debug
/out:C:\nitest\helloworlds.exe
/INCREMENTAL:NO /NODEFAULTLIB:LIBCMT /NODEFAULTLIB:OLDNAMES
/LIBPATH:C:\graalvm-ce-19.2.0\jre\lib
/LIBPATH:C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64
advapi32.lib
ws2_32.lib
secur32.lib
iphlpapi.lib
C:\Users\S\AppData\Local\Temp\SVM-4777097413826739274\helloworlds.obj
C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\ffi.lib
C:\graalvm-ce-19.2.0\jre\lib\java.lib
C:\graalvm-ce-19.2.0\jre\lib\net.lib
C:\graalvm-ce-19.2.0\jre\lib\nio.lib
C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\libchelper.lib
C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\strictmath.lib
C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\jvm.lib
C:\graalvm-ce-19.2.0\jre\lib\zip.lib
C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\ffi.lib
C:\graalvm-ce-19.2.0\jre\lib\java.lib
C:\graalvm-ce-19.2.0\jre\lib\net.lib
C:\graalvm-ce-19.2.0\jre\lib\nio.lib
C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\libchelper.lib
C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\strictmath.lib
C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\jvm.lib
C:\graalvm-ce-19.2.0\jre\lib\zip.lib
   Creating library C:\nitest\helloworlds.lib and object C:\nitest\helloworlds.exp
java.lib(AccessController.obj) : error LNK2019: unresolved external symbol JVM_DoPrivileged referenced in function Java_java_security_AccessController_doPrivileged__Ljava_security_PrivilegedAction_2
java.lib(AccessController.obj) : error LNK2019: unresolved external symbol JVM_GetStackAccessControlContext referenced in function Java_java_security_AccessController_getStackAccessControlContext
java.lib(AccessController.obj) : error LNK2019: unresolved external symbol JVM_GetInheritedAccessControlContext referenced in function Java_java_security_AccessController_getInheritedAccessControlContext
C:\nitest\helloworlds.exe : fatal error LNK1120: 3 unresolved externals

        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:593)
        at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1005)
        at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:461)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:310)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:448)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:113)
Caused by: java.lang.RuntimeException: host C compiler or linker does not seem to work: java.lang.RuntimeException: returned 2

Running command: CL /MD /Zi /PDBSTRIPPED /FeC:\nitest\helloworlds.exe C:\Users\S\AppData\Local\Temp\SVM-4777097413826739274\helloworlds.obj C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\ffi.lib C:\graalvm-ce-19.2.0\jre\lib\java.lib C:\graalvm-ce-19.2.0\jre\lib\net.lib C:\graalvm-ce-19.2.0\jre\lib\nio.lib C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\libchelper.lib C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\strictmath.lib C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\jvm.lib C:\graalvm-ce-19.2.0\jre\lib\zip.lib C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\ffi.lib C:\graalvm-ce-19.2.0\jre\lib\java.lib C:\graalvm-ce-19.2.0\jre\lib\net.lib C:\graalvm-ce-19.2.0\jre\lib\nio.lib C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\libchelper.lib C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\strictmath.lib C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\jvm.lib C:\graalvm-ce-19.2.0\jre\lib\zip.lib /link /INCREMENTAL:NO /NODEFAULTLIB:LIBCMT /NODEFAULTLIB:OLDNAMES /LIBPATH:C:\graalvm-ce-19.2.0\jre\lib /LIBPATH:C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64 advapi32.lib ws2_32.lib secur32.lib iphlpapi.lib

Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

cl : Command line warning D9002 : ignoring unknown option '/PDBSTRIPPED'
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/debug
/out:C:\nitest\helloworlds.exe
/INCREMENTAL:NO /NODEFAULTLIB:LIBCMT /NODEFAULTLIB:OLDNAMES
/LIBPATH:C:\graalvm-ce-19.2.0\jre\lib
/LIBPATH:C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64
advapi32.lib
ws2_32.lib
secur32.lib
iphlpapi.lib
C:\Users\S\AppData\Local\Temp\SVM-4777097413826739274\helloworlds.obj
C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\ffi.lib
C:\graalvm-ce-19.2.0\jre\lib\java.lib
C:\graalvm-ce-19.2.0\jre\lib\net.lib
C:\graalvm-ce-19.2.0\jre\lib\nio.lib
C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\libchelper.lib
C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\strictmath.lib
C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\jvm.lib
C:\graalvm-ce-19.2.0\jre\lib\zip.lib
C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\ffi.lib
C:\graalvm-ce-19.2.0\jre\lib\java.lib
C:\graalvm-ce-19.2.0\jre\lib\net.lib
C:\graalvm-ce-19.2.0\jre\lib\nio.lib
C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\libchelper.lib
C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\strictmath.lib
C:\graalvm-ce-19.2.0\jre\lib\svm\clibraries\windows-amd64\jvm.lib
C:\graalvm-ce-19.2.0\jre\lib\zip.lib
   Creating library C:\nitest\helloworlds.lib and object C:\nitest\helloworlds.exp
java.lib(AccessController.obj) : error LNK2019: unresolved external symbol JVM_DoPrivileged referenced in function Java_java_security_AccessController_doPrivileged__Ljava_security_PrivilegedAction_2
java.lib(AccessController.obj) : error LNK2019: unresolved external symbol JVM_GetStackAccessControlContext referenced in function Java_java_security_AccessController_getStackAccessControlContext
java.lib(AccessController.obj) : error LNK2019: unresolved external symbol JVM_GetInheritedAccessControlContext referenced in function Java_java_security_AccessController_getInheritedAccessControlContext
C:\nitest\helloworlds.exe : fatal error LNK1120: 3 unresolved externals

        at com.oracle.svm.hosted.image.NativeBootImageViaCC.write(NativeBootImageViaCC.java:350)
        at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:657)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:444)
        at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
        at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
        at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
        at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
        at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error: Image build request failed with exit status 1

I can build trivial .jars with native-image just fine.

@vjovanov
Copy link
Member

@pejovica assigning to you as the problem is in missing native implementations for security functions.

@rastislavpapp
Copy link

I'm having the same problem as @Skhmt

@Skhmt
Copy link
Author

Skhmt commented Sep 24, 2019

@vjovanov @pejovica any update?

@kangert
Copy link

kangert commented Oct 18, 2019

This is a major shortcoming. I'm unable to find any workaround to build even simplest swing applications.

@pquiring
Copy link

It would appear as though SubstrateVM doesn't support AWT.

https://github.com/oracle/graal/blob/master/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaAWTSubstitutions.java#L37

It's taken 5+ years to get to here. Adding AWT could take many more years.

@vjovanov
Copy link
Member

Don't think so, it is just not our priority. If you want, you would probably get it running in a matter of days.

@pquiring
Copy link

Probably the only thing needed is to create the JNI config. But what about threads started in ctors? I think that was another issue.

@vjovanov
Copy link
Member

vjovanov commented Nov 1, 2019

You would need to define which classes should be marked with --initialize-at-run-time. The nasty thing is that -H:+TraceClassInitialization does not work for most of the JDK so you would have to use a debugger (--attach-debug) and put breakpoints in constructors of classes that end up in the image heap.

@alvinj
Copy link

alvinj commented Nov 6, 2019

If there’s ever anything I can do as a Swing developer, just let me know, I’ll be glad to help. I know Swing/GUI apps aren’t as popular as web apps, but I still have customers that want them, and I’m always apologizing for the RAM they consume. If GraalVM could help with that issue, that would be awesome.

@vjovanov
Copy link
Member

vjovanov commented Nov 6, 2019

You just start building an image and adding a flag by flag that fixes the problems. If you want to invest the time I will guide you through the process.

@alvinj
Copy link

alvinj commented Nov 6, 2019

Sure, I’ll be glad to do what I can.

@kangert
Copy link

kangert commented Nov 7, 2019

If it were possible to publish some detailed instructions, it would be great.

@vjovanov
Copy link
Member

vjovanov commented Nov 8, 2019

The error messages should lead you through the problems, simply try to build your app and see what goes wrong. We can go through them one by one and fix everything that is unclear on the way.

@kangert
Copy link

kangert commented Nov 8, 2019

Before the next attempt, is there anyone here who has really been able to make it work? I mean, who has been able to make a 100% functional build.

EDIT: Ok, partially functional?

@pquiring
Copy link

pquiring commented Dec 9, 2020

After building the Reflection config file, the resulting app generates a Headless exception. If I add -Djava.awt.headless=false to native-image it generates compile errors.

@kristofdho
Copy link

If I remember correctly, that is caused by java.awt.GraphicsEnvironment being initialized at build time, so it stores the -Djava.awt.headless=true that native-image uses. So you need to mark that one for runtime initialization, and of course everything that somehow initializes it as well.

@joerg-wille
Copy link

@pquiring do you have a repo for your example?

Is there any example code for a minimal swing application with native-image?

@jonpalmisc
Copy link

I am also awaiting Swing support with native-image. Hopefully this is possible soon.

@Jire
Copy link

Jire commented Jan 26, 2021

Even on the latest Graal dev build, still the same no awt in java.library.path error. Is this intended or is there a workaround?

@kristofdho
Copy link

kristofdho commented Jan 26, 2021

Even on the latest Graal dev build, still the same no awt in java.library.path error. Is this intended or is there a workaround?

AWT is not yet supported on windows, but as a workaround you need to package awt.dll, java.dll, verify.dll and jvm.dll so they're available in the same directory as your exe. On top of that it will possibly require loads of jni config for awt (you could take a look at my PR draft if it helps #3079 )
For the official support you can follow #3084

The swing side I have no experience with.

@janbodnar
Copy link

janbodnar commented Apr 22, 2021

I have tested the newest current GraalVM 21.0.0.2.r11-grl 21.1.0.r16-grl with a simple Swing application on Linux. It failed with
Error: Unsupported type sun.awt.X11.XBaseWindow is reachable.

I also tested JavaFX. The build finished, but the program failed at runtime with
Caused by: java.lang.NoClassDefFoundError: Ljava/nio/ByteBuffer;

It's a pity; it would be great to have Java GUI binaries.

@kristofdho
Copy link

kristofdho commented Apr 22, 2021

JavaFX is an entirely different story and requires Gluon Substrate: https://docs.gluonhq.com/#_the_gluon_client_plugin_for_maven
It has native-image support for unix for over a year now.

Sidenote, the newest current GraalVM would be 21.1, released 2 days ago.

@janbodnar
Copy link

OK, my mistake, I have copied the wrong line. I have tested the examples against 21.1.0.r16-grl.

Thanks for pointing to the Gluon Substrate, I will test it.

@kristofdho
Copy link

kristofdho commented Apr 22, 2021

Oh I remembered something else, with AWT and unix. I think native-image by default runs with -Djava.awt.headless=true. And it only links headless awt stuff. I think the X11 stuff is only linked when running heady, and the subsitution you're running into is also conditional on this:

@TargetClass(className = "sun.awt.X11.XBaseWindow", onlyWith = IsHeadless.class)
@Delete
static final class Target_sun_awt_X11_XBaseWindow {
}

TL;DL: try adding -Djava.awt.headless=false to your native-image command.

@janbodnar
Copy link

janbodnar commented Apr 22, 2021

I tried to set the headless option to false and it passed. But later it failed with some linker error:

/usr/bin/ld: native-app.o: warning: relocation in read-only section `.svm_heap'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:78)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
        at java.base/java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:605)
        at java.base/java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1011)
        at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:499)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:370)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:531)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:119)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:568)
Caused by: java.lang.RuntimeException: There was an error linking the native image: Linker command exited with 1

@kristofdho
Copy link

Sorry, can't help you with that, it's a unix linker failure which I don't know anything about.

@pquiring
Copy link

pquiring commented May 5, 2021

With Graal 21.1 still getting errors. Used -H:+TraceNativeToolUsage to get more detailed reason for the failure.
Looks like /implib:java.lib is missing a path.

     [java] [main:6880]    classlist:   1,094.05 ms,  0.96 GB
     [java] >> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.exe'
     [java] ># Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29913 for x64
     [java] ># Copyright (C) Microsoft Corporation.  All rights reserved.
     [java] ># 
     [java] ># usage: cl [ option... ] filename... [ /link linkoption... ]
     [java] >> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.exe' /WX /W4 /wd4244 /wd4245 /wd4800 /wd4804 /wd4214 '/FeC:\Users\pquiring\AppData\Local\Temp\SVM-5520187135493742461\BuiltinDirectives.exe' 'C:\Users\pquiring\AppData\Local\Temp\SVM-5520187135493742461\BuiltinDirectives.c'
     [java] ># BuiltinDirectives.c
     [java] ># Microsoft (R) Incremental Linker Version 14.28.29913.0
     [java] ># Copyright (C) Microsoft Corporation.  All rights reserved.
     [java] ># 
     [java] ># /out:C:\Users\pquiring\AppData\Local\Temp\SVM-5520187135493742461\BuiltinDirectives.exe 
     [java] ># BuiltinDirectives.obj 
     [java] >> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.exe' /WX /W4 /wd4244 /wd4245 /wd4800 /wd4804 /wd4214 '/FeC:\Users\pquiring\AppData\Local\Temp\SVM-5520187135493742461\AMD64LibCHelperDirectives.exe' 'C:\Users\pquiring\AppData\Local\Temp\SVM-5520187135493742461\AMD64LibCHelperDirectives.c'
     [java] ># AMD64LibCHelperDirectives.c
     [java] ># Microsoft (R) Incremental Linker Version 14.28.29913.0
     [java] ># Copyright (C) Microsoft Corporation.  All rights reserved.
     [java] ># 
     [java] ># /out:C:\Users\pquiring\AppData\Local\Temp\SVM-5520187135493742461\AMD64LibCHelperDirectives.exe 
     [java] ># AMD64LibCHelperDirectives.obj 
     [java] >> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.exe' /WX /W4 /wd4244 /wd4245 /wd4800 /wd4804 /wd4214 '/FeC:\Users\pquiring\AppData\Local\Temp\SVM-5520187135493742461\WindowsDirectives.exe' 'C:\Users\pquiring\AppData\Local\Temp\SVM-5520187135493742461\WindowsDirectives.c'
     [java] ># WindowsDirectives.c
     [java] ># Microsoft (R) Incremental Linker Version 14.28.29913.0
     [java] ># Copyright (C) Microsoft Corporation.  All rights reserved.
     [java] ># 
     [java] ># /out:C:\Users\pquiring\AppData\Local\Temp\SVM-5520187135493742461\WindowsDirectives.exe 
     [java] ># WindowsDirectives.obj 
     [java] >> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.exe' /WX /W4 /wd4244 /wd4245 /wd4800 /wd4804 /wd4214 '/FeC:\Users\pquiring\AppData\Local\Temp\SVM-5520187135493742461\AArch64LibCHelperDirectives.exe' 'C:\Users\pquiring\AppData\Local\Temp\SVM-5520187135493742461\AArch64LibCHelperDirectives.c'
     [java] ># AArch64LibCHelperDirectives.c
     [java] ># Microsoft (R) Incremental Linker Version 14.28.29913.0
     [java] ># Copyright (C) Microsoft Corporation.  All rights reserved.
     [java] ># 
     [java] ># /out:C:\Users\pquiring\AppData\Local\Temp\SVM-5520187135493742461\AArch64LibCHelperDirectives.exe 
     [java] ># AArch64LibCHelperDirectives.obj 
     [java] >> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.exe' /WX /W4 /wd4244 /wd4245 /wd4800 /wd4804 /wd4214 '-IC:\bin\jdk\include\win32' '/FeC:\Users\pquiring\AppData\Local\Temp\SVM-5520187135493742461\JNIHeaderDirectives.exe' 'C:\Users\pquiring\AppData\Local\Temp\SVM-5520187135493742461\JNIHeaderDirectives.c'
     [java] ># JNIHeaderDirectives.c
     [java] ># Microsoft (R) Incremental Linker Version 14.28.29913.0
     [java] ># Copyright (C) Microsoft Corporation.  All rights reserved.
     [java] ># 
     [java] ># /out:C:\Users\pquiring\AppData\Local\Temp\SVM-5520187135493742461\JNIHeaderDirectives.exe 
     [java] ># JNIHeaderDirectives.obj 
     [java] [main:6880]        (cap):   1,179.53 ms,  0.96 GB
     [java] [main:6880]        setup:   2,552.84 ms,  0.96 GB
     [java] [main:6880]     (clinit):     259.50 ms,  1.77 GB
     [java] [main:6880]   (typeflow):   8,419.55 ms,  1.77 GB
     [java] [main:6880]    (objects):   4,994.76 ms,  1.77 GB
     [java] [main:6880]   (features):     418.86 ms,  1.77 GB
     [java] [main:6880]     analysis:  14,461.35 ms,  1.77 GB
     [java] [main:6880]     universe:     648.02 ms,  1.77 GB
     [java] [main:6880]      (parse):   2,206.18 ms,  1.76 GB
     [java] [main:6880]     (inline):   2,055.75 ms,  2.33 GB
     [java] [main:6880]    (compile):  14,165.19 ms,  2.86 GB
     [java] [main:6880]      compile:  19,272.34 ms,  2.86 GB
     [java] [main:6880]        image:   1,792.16 ms,  2.86 GB
     [java] >> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.exe' '/Fec:\files\workspace\jf\projects\jfawt\main.dll' main.obj 'C:\bin\jdk\lib\svm\clibraries\windows-amd64\libchelper.lib' 'D:\bin\jdk\lib\static\windows-amd64\prefs.lib' 'D:\bin\jdk\lib\static\windows-amd64\net.lib' 'D:\bin\jdk\lib\static\windows-amd64\nio.lib' 'D:\bin\jdk\lib\static\windows-amd64\java.lib' 'D:\bin\jdk\lib\static\windows-amd64\fdlibm.lib' 'D:\bin\jdk\lib\static\windows-amd64\zip.lib' 'C:\bin\jdk\lib\svm\clibraries\windows-amd64\jvm.lib' /MD /LD 'C:\bin\jdk\lib\svm\clibraries\windows-amd64\libchelper.lib' 'D:\bin\jdk\lib\static\windows-amd64\prefs.lib' 'D:\bin\jdk\lib\static\windows-amd64\net.lib' 'D:\bin\jdk\lib\static\windows-amd64\nio.lib' 'D:\bin\jdk\lib\static\windows-amd64\java.lib' 'D:\bin\jdk\lib\static\windows-amd64\fdlibm.lib' 'D:\bin\jdk\lib\static\windows-amd64\zip.lib' 'C:\bin\jdk\lib\svm\clibraries\windows-amd64\jvm.lib' /link /INCREMENTAL:NO /NODEFAULTLIB:LIBCMT '/IMPLIB:C:\Users\pquiring\AppData\Local\Temp\SVM-5520187135493742461\main.lib' '/LIBPATH:D:\bin\jdk\lib\static\windows-amd64' '/LIBPATH:C:\bin\jdk\lib\svm\clibraries\windows-amd64' version.lib advapi32.lib ws2_32.lib secur32.lib iphlpapi.lib userenv.lib /include:JDK_LoadSystemLibrary /include:getEncodingFromLangID /include:getJavaIDFromLangID shell32.lib
     [java] ># Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29913 for x64
     [java] ># Copyright (C) Microsoft Corporation.  All rights reserved.
     [java] ># 
     [java] ># Microsoft (R) Incremental Linker Version 14.28.29913.0
     [java] ># Copyright (C) Microsoft Corporation.  All rights reserved.
     [java] ># 
     [java] ># /out:c:\files\workspace\jf\projects\jfawt\main.dll 
     [java] ># /dll 
     [java] ># /implib:c:\files\workspace\jf\projects\jfawt\main.lib 
     [java] ># /INCREMENTAL:NO 
     [java] ># /NODEFAULTLIB:LIBCMT 
     [java] ># /IMPLIB:C:\Users\pquiring\AppData\Local\Temp\SVM-5520187135493742461\main.lib 
     [java] ># /LIBPATH:D:\bin\jdk\lib\static\windows-amd64 
     [java] ># /LIBPATH:C:\bin\jdk\lib\svm\clibraries\windows-amd64 
     [java] ># version.lib 
     [java] ># advapi32.lib 
     [java] ># ws2_32.lib 
     [java] ># secur32.lib 
     [java] ># iphlpapi.lib 
     [java] ># userenv.lib 
     [java] ># /include:JDK_LoadSystemLibrary 
     [java] ># /include:getEncodingFromLangID 
     [java] ># /include:getJavaIDFromLangID 
     [java] ># shell32.lib 
     [java] ># main.obj 
     [java] ># C:\bin\jdk\lib\svm\clibraries\windows-amd64\libchelper.lib 
     [java] ># D:\bin\jdk\lib\static\windows-amd64\prefs.lib 
     [java] ># D:\bin\jdk\lib\static\windows-amd64\net.lib 
     [java] ># D:\bin\jdk\lib\static\windows-amd64\nio.lib 
     [java] ># D:\bin\jdk\lib\static\windows-amd64\java.lib 
     [java] ># D:\bin\jdk\lib\static\windows-amd64\fdlibm.lib 
     [java] ># D:\bin\jdk\lib\static\windows-amd64\zip.lib 
     [java] ># C:\bin\jdk\lib\svm\clibraries\windows-amd64\jvm.lib 
     [java] ># C:\bin\jdk\lib\svm\clibraries\windows-amd64\libchelper.lib 
     [java] ># D:\bin\jdk\lib\static\windows-amd64\prefs.lib 
     [java] ># D:\bin\jdk\lib\static\windows-amd64\net.lib 
     [java] ># D:\bin\jdk\lib\static\windows-amd64\nio.lib 
     [java] ># D:\bin\jdk\lib\static\windows-amd64\java.lib 
     [java] ># D:\bin\jdk\lib\static\windows-amd64\fdlibm.lib 
     [java] ># D:\bin\jdk\lib\static\windows-amd64\zip.lib 
     [java] ># C:\bin\jdk\lib\svm\clibraries\windows-amd64\jvm.lib 
     [java] >#    Creating library C:\Users\pquiring\AppData\Local\Temp\SVM-5520187135493742461\main.lib and object C:\Users\pquiring\AppData\Local\Temp\SVM-5520187135493742461\main.exp
     [java] >> 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.exe' '/Fec:\files\workspace\jf\projects\jfawt\java.dll' 'c:\files\workspace\jf\projects\jfawt\main.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
     [java] ># Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29913 for x64
     [java] ># Copyright (C) Microsoft Corporation.  All rights reserved.
     [java] ># 
     [java] ># Microsoft (R) Incremental Linker Version 14.28.29913.0
     [java] ># Copyright (C) Microsoft Corporation.  All rights reserved.
     [java] ># 
     [java] ># /out:c:\files\workspace\jf\projects\jfawt\java.dll 
     [java] ># /dll 
     [java] ># /implib:java.lib 
     [java] ># /export:JDK_LoadSystemLibrary 
     [java] ># /export:JNU_CallMethodByName 
     [java] ># /export:JNU_CallMethodByNameV 
     [java] ># /export:JNU_CallStaticMethodByName 
     [java] ># /export:JNU_ClassString 
     [java] ># /export:JNU_GetEnv 
     [java] ># /export:JNU_GetFieldByName 
     [java] ># /export:JNU_GetStaticFieldByName 
     [java] ># /export:JNU_IsInstanceOfByName 
     [java] ># /export:JNU_NewObjectByName 
     [java] ># /export:JNU_NewStringPlatform 
     [java] ># /export:JNU_SetFieldByName 
     [java] ># /export:JNU_ThrowArrayIndexOutOfBoundsException 
     [java] ># /export:JNU_ThrowByName 
     [java] ># /export:JNU_ThrowIOException 
     [java] ># /export:JNU_ThrowIllegalArgumentException 
     [java] ># /export:JNU_ThrowInternalError 
     [java] ># /export:JNU_ThrowNullPointerException 
     [java] ># /export:JNU_ThrowOutOfMemoryError 
     [java] ># /export:getEncodingFromLangID 
     [java] ># /export:getJavaIDFromLangID 
     [java] ># /export:jio_snprintf 
     [java] ># c:\files\workspace\jf\projects\jfawt\main.lib 
     [java] ># msvcrt.lib 
     [java] ># LINK : warning LNK4001: no object files specified; libraries used
     [java] ># LINK : warning LNK4068: /MACHINE not specified; defaulting to X64
     [java] ># LINK : error LNK2001: unresolved external symbol JDK_LoadSystemLibrary
     [java] ># LINK : error LNK2001: unresolved external symbol JNU_CallMethodByName
     [java] ># LINK : error LNK2001: unresolved external symbol JNU_CallMethodByNameV
     [java] ># LINK : error LNK2001: unresolved external symbol JNU_CallStaticMethodByName
     [java] ># LINK : error LNK2001: unresolved external symbol JNU_ClassString
     [java] ># LINK : error LNK2001: unresolved external symbol JNU_GetEnv
     [java] ># LINK : error LNK2001: unresolved external symbol JNU_GetFieldByName
     [java] ># LINK : error LNK2001: unresolved external symbol JNU_GetStaticFieldByName
     [java] ># LINK : error LNK2001: unresolved external symbol JNU_IsInstanceOfByName
     [java] ># LINK : error LNK2001: unresolved external symbol JNU_NewObjectByName
     [java] ># LINK : error LNK2001: unresolved external symbol JNU_NewStringPlatform
     [java] ># LINK : error LNK2001: unresolved external symbol JNU_SetFieldByName
     [java] ># LINK : error LNK2001: unresolved external symbol JNU_ThrowArrayIndexOutOfBoundsException
     [java] ># LINK : error LNK2001: unresolved external symbol JNU_ThrowByName
     [java] ># LINK : error LNK2001: unresolved external symbol JNU_ThrowIOException
     [java] ># LINK : error LNK2001: unresolved external symbol JNU_ThrowIllegalArgumentException
     [java] ># LINK : error LNK2001: unresolved external symbol JNU_ThrowInternalError
     [java] ># LINK : error LNK2001: unresolved external symbol JNU_ThrowNullPointerException
     [java] ># LINK : error LNK2001: unresolved external symbol JNU_ThrowOutOfMemoryError
     [java] ># java.lib : fatal error LNK1120: 19 unresolved externals
     [java] [main:6880]        write:     252.36 ms,  2.86 GB
     [java] Fatal error:com.oracle.svm.core.util.VMError$HostedError: should not reach here
     [java] 	at com.oracle.svm.core.util.VMError.shouldNotReachHere(VMError.java:64)
     [java] 	at com.oracle.svm.hosted.jdk.JNIRegistrationSupport.makeShimDLL(JNIRegistrationSupport.java:248)
     [java] 	at com.oracle.svm.hosted.jdk.JNIRegistrationSupport.makeShimDLLs(JNIRegistrationSupport.java:222)
     [java] 	at com.oracle.svm.hosted.jdk.JNIRegistrationSupport.afterImageWrite(JNIRegistrationSupport.java:167)
     [java] 	at com.oracle.svm.hosted.NativeImageGenerator.lambda$doRun$12(NativeImageGenerator.java:716)
     [java] 	at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:71)
     [java] 	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:716)
     [java] 	at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$2(NativeImageGenerator.java:495)
     [java] 	at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1414)
     [java] 	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:295)
     [java] 	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1016)
     [java] 	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1665)
     [java] 	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1598)
     [java] 	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
     [java] Error: Image build request failed with exit status 1

@BullyWiiPlaza
Copy link

When compiling my simple hello world Swing application, I still get an exception:

D:\JavaProjects\Hello World GraalVM>native-image -jar "Hello World.jar" "native/Hello World" --verbose
Executing [
'C:\graalvm_jdk11\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=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.event=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.loader=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.logger=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.module=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.org.xml.sax.helpers=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.perf=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.util.xml.impl=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.util.xml=ALL-UNNAMED \
--add-exports=java.base/sun.invoke.util=ALL-UNNAMED \
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED \
--add-exports=java.base/sun.reflect.annotation=ALL-UNNAMED \
--add-exports=java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED \
--add-exports=java.base/sun.reflect.generics.repository=ALL-UNNAMED \
--add-exports=java.base/sun.reflect.generics.tree=ALL-UNNAMED \
--add-exports=java.base/sun.security.jca=ALL-UNNAMED \
--add-exports=java.base/sun.security.provider=ALL-UNNAMED \
--add-exports=java.base/sun.security.util=ALL-UNNAMED \
--add-exports=java.base/sun.text.spi=ALL-UNNAMED \
--add-exports=java.base/sun.util.calendar=ALL-UNNAMED \
--add-exports=java.base/sun.util.locale.provider=ALL-UNNAMED \
--add-exports=java.base/sun.util.resources=ALL-UNNAMED \
--add-exports=java.xml.crypto/org.jcp.xml.dsig.internal.dom=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.aarch64=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.amd64=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code.site=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code.stack=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.common=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot.aarch64=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot.amd64=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot.sparc=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.meta=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.runtime=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.services=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.sparc=ALL-UNNAMED \
--add-exports=jdk.jfr/jdk.jfr.events=ALL-UNNAMED \
--add-exports=jdk.jfr/jdk.jfr.internal.consumer=ALL-UNNAMED \
--add-exports=jdk.jfr/jdk.jfr.internal.handlers=ALL-UNNAMED \
--add-exports=jdk.jfr/jdk.jfr.internal.jfc=ALL-UNNAMED \
--add-exports=jdk.jfr/jdk.jfr.internal=ALL-UNNAMED \
-XX:+UseJVMCINativeLibrary \
-Xss10m \
-Xms1g \
-Xmx14g \
-Duser.country=US \
-Duser.language=en \
-Djava.awt.headless=true \
-Dorg.graalvm.version=21.2.0 \
-Dorg.graalvm.config=CE \
-Dcom.oracle.graalvm.isaot=true \
-Djava.system.class.loader=com.oracle.svm.hosted.NativeImageSystemClassLoader \
-Xshare:off \
--module-path \
'C:\graalvm_jdk11\lib\truffle\truffle-api.jar' \
-Djdk.internal.lambda.disableEagerInitialization=true \
-Djdk.internal.lambda.eagerlyInitialize=false \
-Djava.lang.invoke.InnerClassLambdaMetafactory.initializeLambdas=false \
'-javaagent:C:\graalvm_jdk11\lib\svm\builder\svm.jar' \
-cp \
'C:\graalvm_jdk11\lib\svm\builder\objectfile.jar;C:\graalvm_jdk11\lib\svm\builder\pointsto.jar;C:\graalvm_jdk11\lib\svm\builder\svm.jar' \
'com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus' \
-imagecp \
'D:\JavaProjects\Hello World GraalVM\Hello World.jar;C:\graalvm_jdk11\lib\svm\library-support.jar' \
'-H:Path=D:\JavaProjects\Hello World GraalVM' \
'-H:Class@manifest from file:///D:/JavaProjects/Hello%20World%20GraalVM/Hello%20World.jar=Main' \
'-H:Name@manifest from file:///D:/JavaProjects/Hello%20World%20GraalVM/Hello%20World.jar=Hello World' \
'-H:CLibraryPath=C:\graalvm_jdk11\lib\svm\clibraries\windows-amd64' \
'-H:Name@explicit image name=native/Hello World'
]
[native/Hello World:43812]    classlist:   1,051.07 ms,  0.96 GB
[native/Hello World:43812]        (cap):   1,765.72 ms,  0.96 GB
[native/Hello World:43812]        setup:   3,893.39 ms,  0.96 GB
[native/Hello World:43812]     (clinit):     342.94 ms,  1.81 GB
[native/Hello World:43812]   (typeflow):   6,233.65 ms,  1.81 GB
[native/Hello World:43812]    (objects):   3,558.88 ms,  1.81 GB
[native/Hello World:43812]   (features):     568.83 ms,  1.81 GB
[native/Hello World:43812]     analysis:  11,163.60 ms,  1.81 GB
[native/Hello World:43812]     universe:     885.09 ms,  1.82 GB
[native/Hello World:43812]      (parse):     682.04 ms,  1.82 GB
[native/Hello World:43812]     (inline):   1,135.86 ms,  2.31 GB
[native/Hello World:43812]    (compile):   9,532.36 ms,  3.59 GB
[native/Hello World:43812]      compile:  12,125.54 ms,  3.59 GB
[native/Hello World:43812]        image:   2,221.66 ms,  3.59 GB
[native/Hello World:43812]        write:     665.25 ms,  3.59 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:666)
        at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:71)
        at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:666)
        at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:491)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:380)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:543)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:119)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:573)
[native/Hello World:43812]      [total]:  32,220.86 ms,  3.59 GB
# Printing build artifacts to: D:\JavaProjects\Hello World GraalVM\native\Hello World.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:1916)
        at com.oracle.svm.driver.NativeImage.build(NativeImage.java:1584)
        at com.oracle.svm.driver.NativeImage.performBuild(NativeImage.java:1545)
        at com.oracle.svm.driver.NativeImage.main(NativeImage.java:1532)

D:\JavaProjects\Hello World GraalVM>

Can this please be fixed or is there any command line switch I need to add? Swing is the most popular Java GUI framework for the desktop, why is that still not working even in a hello world fashion?

@rubyFeedback
Copy link

Some folks say they managed to get it to work, others wrote they did not.

Would it be possible to add a simple "hello world" button via native-image + swing, as part of the official documentation,
INCLUDING the syntax how to get it to run, IF it works eventually? I tried some of the examples, and while others
said it worked for them, I failed to get that to work right now ... may be an user problem but this is why the documentation
should mention this clearly HOW to get it to work, IMO.

@ShalokShalom
Copy link

Doing that does suggest, that Scala + Swing = Native actually works, beyond Hello World.

If not even that is consistent, I see it as detrimental to encourage people in the official documentation to use it.

Do you agree?

@vjovanov
Copy link
Member

At this point, we are striving to support all libraries (given they are configured correctly). I don't see why we would treat Swing any different in terms of documentation.

I think a blog post in this space would be great to show the process of using Swing with Native Image. Two interesting things here are the configuration experience with Swing, great startup time, and all the benefits that come with a native&standalone deliverable.

@mklhmnn
Copy link

mklhmnn commented Jan 28, 2022

It would be great if AWT and Swing would be supported by default (without the need to configure anything), because they are part of the JDK, not some external library.

@kkriske
Copy link
Contributor

kkriske commented Jan 31, 2022

without the need to configure anything

The problem with that is that awt is huge, and adding config for all of that probably means that a bunch config gets added when it isn't really required just because the calling class is reachable. AWT is a bit of a mess imo and once 1 thing is accidentally or intentionally required, it can cascade a lot. To give you an idea how much config is required: #3079

@Snoopy137
Copy link

so for record, I was able to run the native image command for a simple swing app. Here is what I did

Swing app
public class Ventana extends javax.swing.JFrame {
public Ventana() {
initComponents();
}
}

Main class
public class SimplreSwing {

public static void main(String[] args) {
    new Ventana().setVisible(true);
}

}

I used the following coomands

C:\graalvm-ce-java17-22.1.0\bin\java -agentlib:native-image-agent=config-output-dir=config -jar c:\Users\mis_p\OneDrive\Documentos\NetBeansProjects\SimplreSwing\target\SimplreSwing-1.0-SNAPSHOT-jar-with-dependencies.jar

c:\graalvm-ce-java17-22.1.0\bin\native-image.cmd -jar c:\Users\mis_p\OneDrive\Documentos\NetBeansProjects\SimplreSwing\target\SimplreSwing-1.0-SNAPSHOT-jar-with-dependencies.jar test --initialize-at-build-time=sun.awt.Toolkit -Djava.awt.headless=false -H:ConfigurationFileDirectories=config

Image was created and run without issues, but when I tried to add a look and feel it started failing. Had anyone else been able to add a look and feel?

@Snoopy137
Copy link

so for record, I was able to run the native image command for a simple swing app. Here is what I did

Swing app
public class Ventana extends javax.swing.JFrame {
public Ventana() {
initComponents();
}
}

Main class
public class SimplreSwing {

public static void main(String[] args) {
new Ventana().setVisible(true);
}

}

I used the following coomands

C:\graalvm-ce-java17-22.1.0\bin\java -agentlib:native-image-agent=config-output-dir=config -jar c:\Users\mis_p\OneDrive\Documentos\NetBeansProjects\SimplreSwing\target\SimplreSwing-1.0-SNAPSHOT-jar-with-dependencies.jar

c:\graalvm-ce-java17-22.1.0\bin\native-image.cmd -jar c:\Users\mis_p\OneDrive\Documentos\NetBeansProjects\SimplreSwing\target\SimplreSwing-1.0-SNAPSHOT-jar-with-dependencies.jar test --initialize-at-build-time=sun.awt.Toolkit -Djava.awt.headless=false -H:ConfigurationFileDirectories=config

Image was created and run without issues, but when I tried to add a look and feel it started failing. Had anyone else been able to add a look and feel?

@Snoopy137
Copy link

@vjovanov I don't know if you're still involved in this or Graal, but something that might be useful is, I created an app with a simple jframe and was able to create the native image, I was able to add a panel and other containers, when adding a button or lable made the image fail not at build but when trying to run it, mostly the error points to Java.lang.reflect and fontmanager, but, when adding an awt button everything works. I wonder if there's a way to include the swing components at the image some how through config files or command line parameters, that should be enough to make it work

@vjovanov
Copy link
Member

@Snoopy137 in the long run yes. We strive to provide metadata for the JDK libraries as much as possible. However, due to the surface of the JDK we didn't have time to do it for all libraries. These kinds of issues are a good place for the community to contribute to the project.

@yeroc
Copy link

yeroc commented Oct 26, 2022

I was just investigating this myself and ran across a blog post from Bellsoft with instructions for building SwingSet2 on Windows, Linux and macOS. This uses their Graal-based Liberica Native Image Kit. Not sure whether it's just a repackaging of GraalVM community edition or whether they're actually adding some extra bits to it. Thought this might be helpful to others.

@ldkjdk
Copy link

ldkjdk commented Jan 16, 2023

build swing jfilechooser Component

image
image

@Koishi-Satori
Copy link

Building an program using java2d for render tasks.
Command Line: native-image -H:-CheckToolchain -Ob -march=native --initialize-at-run-time=sun.awt.AWTAutoShutdown,sun.java2d.opengl.OGLRenderQueue --no-fallback -jar .\KStg.jar

This only happens when running the native executive file built by native-image, and if needed, the source code: here

The output:
error_out_put

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

No branches or pull requests