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.21k stars 1.62k forks source link

[native-image] Building a native image for the Apache Felix framework jar fails with multiple DeletedElementException instances #1814

Open rombert opened 4 years ago

rombert commented 4 years ago

Using

openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-20191008104205.buildslave.jdk8u-src-tar--b07)
OpenJDK 64-Bit GraalVM CE 19.2.1 (build 25.232-b07-jvmci-19.2-b03, mixed mode)

I am trying to build a native image of the Apache Felix Framework jar. Felix is an OSGi framework implementation and does a lot of work with custom classloaders. Building an image of the framework is not expected to do anything meaningful since it would require additional jars, but the first step is to validate that building an image for the framework works.

Steps to reproduce:

  1. Download the Felix Framework distribution archive from http://felix.apache.org/downloads.cgi#framework ( right now the latest is 6.0.3 )
  2. Extract the archive
  3. Go to felix-framework-6.0.3/bin and run $ native-image -jar felix.jar

I've attached the output as a log file - native-image-build.log .

cstancu commented 4 years ago

As the error message suggests you can use --report-unsupported-elements-at-runtime to push those errors to run time. This should allow you to build a native image, but that may not get you too far if those unimplemented methods are actually on the execution path. We are currently working on a re-implementation of our ClassLoader support, so I'll get back to this issue once that is done. However, be warned that if the framework does need to load bytecodes at run time native-image doesn't support that use case.

gurkerl83 commented 4 years ago

Hi, there is another project called Atomos which implements a first draft of Connected OSGi within Equinox, a different OSGi Framework. There is a Build instruction for Substrate which utilizes native-image to bundle a single application from multiple OSGi bundles. Maybe it’s a good starting point bringing AOT towards the OSGi ecosystem. https://github.com/tjwatson/atomos

rombert commented 4 years ago

@cstancu - unimplemented methods are used at runtime, yes, as that's when OSGI frameworks do most of the class loading.

I was wondering whether conceptually there is an option to accommodate such behaviour, e.g. by making the dynamic class loading work only on a subset of existing classes that are defined at build time.

@gurkerl83 - thanks for the hint, I'll make sure to watch that.

linghengqian commented 2 years ago

@rombert

rombert commented 2 years ago

@linghengqian - hm, not sure why that link broke, a working one is https://felix.apache.org/documentation/downloads.html#_felix_framework_distribution .

That will point you to the latest version, the 6.0.3 version I referenced can be downloaded from https://archive.apache.org/dist/felix/org.apache.felix.main.distribution-6.0.3.zip .