[OpenJDK 2D-Dev] RFR: 8254024: Enhance native libs for AWT and Swing to work with GraalVM Native Image

Andrii Rodionov github.com+1538227+arodionov at openjdk.java.net
Wed Dec 9 21:24:35 UTC 2020


On Wed, 9 Dec 2020 01:26:08 GMT, Phil Race <prr at openjdk.org> wrote:

>> No, we produce only one image. The headless/non-headless mode is defined by the system property `-Djava.awt.headless=...`.
>> Here is a command example for native image generation:
>> `$ ~/graalvm-ce-java11-21.0.0-dev/bin/native-image -H:ConfigurationFileDirectories=./configs -Djava.awt.headless=true AWTFixExample`
>> 
>> With `-Djava.awt.headless=false` to the gcc linker we pass `libawt.a` and `libawt_headless.a`
>> With `-Djava.awt.headless=true` to the gcc linker we pass `libawt.a` and `libawt-xawt.a`
>> If the generated image demands `libmlib_image.a` it will be also linked.
>
>> No, we produce only one image. The headless/non-headless mode is defined by the system property `-Djava.awt.headless=...`.
>> Here is a command example for native image generation:
>> `$ ~/graalvm-ce-java11-21.0.0-dev/bin/native-image -H:ConfigurationFileDirectories=./configs -Djava.awt.headless=true AWTFixExample`
>> 
>> With `-Djava.awt.headless=false` to the gcc linker we pass `libawt.a` and `libawt_headless.a`
>> With `-Djava.awt.headless=true` to the gcc linker we pass `libawt.a` and `libawt-xawt.a`
>> If the generated image demands `libmlib_image.a` it will be also linked.
> 
> -Djava.awt.headless is a runtime property not a build time property. So you are doing domething very weird.
> How does that image with "false" run a UI app ? It can't. And yet the one with "true" still can run without an xserver, except it will not start unless you have X11 libs installed - and I am *reasonably* sure you aren't statically linking all the system provided libraries ... I hope ...
> 
> So how does a "user" use all of this ? Seems they must create their own app by native compile + linking.
> Can they create an image that can run any java app, or must the app like AWTFixExample be linked in to the image ?

At the current stage, we made the `-Djava.awt.headless` option be used during the build time, at the same time it does no influence at the runtime. The user should know the environment where it is planned to run a native image in advance. It is his responsibility to pass correct options to the native image compiler.

For example, for the code snippet `AWTFixExample` (mentioned above https://github.com/openjdk/jdk/pull/562#issuecomment-722023476), that is headless, the following set of static libraries are used for image build:
# Static libraries:
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/svm/clibraries/linux-amd64/liblibchelper.a
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/static/linux-amd64/glibc/liblcms.a
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/static/linux-amd64/glibc/libawt_headless.a
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/static/linux-amd64/glibc/libawt.a
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/static/linux-amd64/glibc/libmlib_image.a
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/static/linux-amd64/glibc/libnet.a
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/static/linux-amd64/glibc/libnio.a
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/static/linux-amd64/glibc/libjava.a
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/static/linux-amd64/glibc/libfdlibm.a
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/static/linux-amd64/glibc/libzip.a
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/svm/clibraries/linux-amd64/libjvm.a
# Other libraries: stdc++,m,pthread,dl,z,rt
For simple AWT UI Java app, the set of libraries are the following:
# Static libraries:
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/static/linux-amd64/glibc/libnet.a
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/static/linux-amd64/glibc/libjavajpeg.a
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/static/linux-amd64/glibc/libnio.a
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/svm/clibraries/linux-amd64/liblibchelper.a
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/static/linux-amd64/glibc/libjava.a
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/static/linux-amd64/glibc/liblcms.a
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/static/linux-amd64/glibc/libfontmanager.a
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/static/linux-amd64/glibc/libawt_xawt.a
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/static/linux-amd64/glibc/libawt.a
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/static/linux-amd64/glibc/libfdlibm.a
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/static/linux-amd64/glibc/libzip.a
#   ../../vms/graalvm-ce-java11-21.0.0-dev/lib/svm/clibraries/linux-amd64/libjvm.a
# Other libraries: X11,Xrender,Xext,Xi,stdc++,m,freetype,pthread,dl,z,rt

> So how does a "user" use all of this ? Seems they must create their own app by native compile + linking.
> Can they create an image that can run any java app, or must the app like AWTFixExample be linked in to the image ?

The global idea is that any existing Java app (even without source code) can be converted into a native image, that's why we have added AWT/Swing support to GraalVM.
To make a native image from the existing Java app, the user needs to have GraalVM, gcc with the set of libraries (platform dependent).
After running `native-image` command (from GraalVM), with a set of options and additional configuration files, and specifying the target jar or class-file, an executable binary for the current platform will be built.
There are limitations and the list of unsupported features (https://www.graalvm.org/reference-manual/native-image/Limitations/) for Java apps, so it may demand re-writing some code or providing so-called substitutions to make it compatible for the native-image compiler.

-------------

PR: https://git.openjdk.java.net/jdk/pull/562


More information about the 2d-dev mailing list