Skip to content

H2 1.4.200 does not work with native-image@graalvm whereas 1.4.199 works #2207

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

Closed
rmannibucau opened this issue Oct 27, 2019 · 12 comments
Closed

Comments

@rmannibucau
Copy link

Hi,

A quick issue to report that 1.4.199 works well with graalvm native-image tool (to compile natively an application using h2, I am using this script with graal 19.2.1 - to illustrate how it works:

h2_version="1.4.199"    classpath="target/classes:$HOME/.m2/repository/com/h2database/h2/$h2_version/h2-$h2_version.jar"
build_time_classes="org.h2.Driver"

native-image \
    -classpath "$classpath" \
    -H:+TraceClassInitialization \
    -H:+ReportExceptionStackTraces \
    -H:ResourceConfigurationFiles=src/graal/resource-config.json \
    -H:ReflectionConfigurationFiles=src/graal/reflect-config.json \
    --no-server \
    --no-fallback \
    --allow-incomplete-classpath \
    --report-unsupported-elements-at-runtime \
    --initialize-at-build-time="$build_time_classes" \
    com.github.rmannibucau.h2.Sample \
    target/sample.bin

Side note: config.json files can be generated with the graal agent if needed, it is mainly the reflection needed by h2 and the data.zip file inclusion, nothing crazy.

Now, if I switch to 1.4.200 I can't go native anymore cause a lot of h2 classes are initialized at build time due to Driver enforced initialization. I didn't investigate but it sounds like some more static initializations are done - even transitively - which prevents native-image to works correctly with this setup.

Can you ensure h2 is native-isable for future versions please?

Romain

@katzyn
Copy link
Contributor

katzyn commented Oct 28, 2019

There were no significant changes in that area, but H2 uses reflection in a few places in both these versions. Actually 1.4.200 uses less amount of reflective calls.

Please, report bugs and limitations of that tool to its developers.

@katzyn katzyn closed this as completed Oct 28, 2019
@katzyn
Copy link
Contributor

katzyn commented Oct 28, 2019

And you need to check your configuration first, maybe you need to upgrade it for a new version of H2.

@katzyn
Copy link
Contributor

katzyn commented Oct 28, 2019

I took a look on Native Image Java Limitations section in its documentation and I think it isn't ready yet for H2. It may work somehow, but we don't have a time to support that tool in its current status.

@rmannibucau
Copy link
Author

Hmm, why 199 was working then? I activated reflection and resources as needed by h2 and this part is fine.
Issue is not the reflection but the static initialization which seems to trigger more class loading - almost all h2 - in 200 than 199 (maybe the auto load driver trigger the full h2 loading?).

@katzyn
Copy link
Contributor

katzyn commented Oct 28, 2019

I have no idea how and why older version works. Maybe you need to include more classes to your configuration for 1.4.200.

And because H2 1.4.201 will be Java 8 based, most likely it also will be even less compatible with native images until they will be improved to support more basic features of JVM.

This is a bugtracker of H2. Your issue is not a bug of H2, we don't support that tool. If you need some help, please use our mailing list, StackOverflow, or some other resource for your questions.

@rmannibucau
Copy link
Author

Hmm, what is the issue with java 8? Graal is based on java 8 and next release will support java 11 so not an issue with graal currently.
Since all the microservice ecosystem - using h2 - starts to support graal, i think it makes sense to ensure it is compliant for h2.

@katzyn
Copy link
Contributor

katzyn commented Oct 28, 2019

Native images don't properly support invokedynamic from Java 7 (not widely used before Java 8) and method handles; only a limited subset of them is somehow supported. Other limitations also exist. You should consider native images as an experimental feature that could be suitable for projects specially designed for it, but not as something that will always work with third-party projects, especially with complex ones.

@rmannibucau
Copy link
Author

I do consider it as specific to a deployment but it is no more experimental and officially supported for prod. It is also required in several cloud/k8s cases - to reduce boot times and memory usages - so it is good to be able to use h2 IMHO. What about reporting issues you have to be friendly with native-image on graal bugtracker referencing this issue? They are quick good at fixing things and I dont see why h2 would not be able to run whereas quarkus made most of jboss ecosystem running.

@grandinj
Copy link
Contributor

@rmannibucau you are welcome to debug this issue and report stuff to Graal. However, I am sorry, but no-one here is interested in doing that, and we do not consider Graal a supported feature.

@rmannibucau
Copy link
Author

FYI I put a sample on github https://github.com/rmannibucau/h2graal
Seems the issue was mainly a server cache issue.
That said would be great if h2 can check it still works before releasing ;).

Thanks guys.

@devMls
Copy link

devMls commented Mar 16, 2021

+1 interesed, to use in embeded in a desktop app, compiled with graalvm. Any alternatives if H2 is not gonna be suitable?

@devMls
Copy link

devMls commented Mar 16, 2021

Maybe the error has a early solution oracle/graal#3028

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

No branches or pull requests

4 participants