oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.07k stars 1.6k forks source link

Inherited JavaFX launch method call not invoked #5374

Closed ghost closed 1 year ago

ghost commented 1 year ago

Describe the issue A method that is clearly called within the source code gets eliminated from the binary.

Steps to reproduce the issue

cd /tmp
git clone https://github.com/DaveJarvis/keenwrite
cd keenwrite
wget https://github.com/gluonhq/graal/releases/download/gluon-22.1.0.1-Final/graalvm-svm-java17-linux-gluon-22.1.0.1-Final.tar.gz
tar xf graalvm-svm-java17-linux-gluon-22.1.0.1-Final.tar.gz
rm graalvm*
mv graalvm* graalvm
gradle jar
./graalvm/bin/native-image \
   --verbose \
   -H:+ReportExceptionStackTraces \
   --no-fallback \
   --report-unsupported-elements-at-runtime \
   -Djava.awt.headless=false \
   -jar build/libs/keenwrite.jar

./keenwrite

Expected results JavaFX GUI appears.

Actual results Program terminates.

Environment Although JDK 19 is installed, the build.gradle file targets JDK 17. Additional environment details:

$ gradle -version
Gradle 7.6-rc-1
$ uname -a
Linux hostname 6.0.6-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 29 Oct 2022 14:08:39 +0000 x86_64 GNU/Linux
$ java -version
openjdk version "19.0.1" 2022-10-18
OpenJDK Runtime Environment (build 19.0.1+11)
OpenJDK 64-Bit Server VM (build 19.0.1+11, mixed mode, sharing)
$ ./graalvm/bin/native-image --version
GraalVM 22.1.0.1 Java 17 CE (Java Version 17.0.3+7-jvmci-22.1-b06)

Source code When no command-line arguments are given, the Launcher class is expected to call the static main method of the "MainApp" class:

      if( argCount <= 0 ) {
        // When no command-line arguments are provided, launch the GUI.
        MainApp.main( mArgs );
      }
      else {
        // When command-line arguments are supplied, run in headless mode.
        HeadlessApp.main( args );
      }

The MainApp class inherits from javafx.application.Application and invokes the JavaFX entry point as follows:

  public static void main( final String[] args ) {
    launch( args );
  }

I believe the launch method is never called because the MainApp class is removed by GraalVM (for no reason that's immediately apparent).

ghost commented 1 year ago

Presumably, this was caused by not running the Agent to perform reflection analysis.