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

NativeImageWin32MppImpls - UnsupportedFeatureException in GraalVM 23 #236

Open
iamcalledrob opened this issue Oct 15, 2024 · 7 comments
Open

Comments

@iamcalledrob
Copy link

Attempting to build a native image with Oracle GraalVM 23 leads to the following build-time error:

Fatal error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: An object of type 'com.github.ajalt.mordant.internal.nativeimage.NativeImageWin32MppImpls' was found in the image heap. This type, however, is marked for initialization at image run time for the following reason: classes are initialized at run time by default.
This is not allowed for correctness reasons: All objects that are stored in the image heap must be initialized at build time.

You now have two options to resolve this:

1) If it is intended that objects of type 'com.github.ajalt.mordant.internal.nativeimage.NativeImageWin32MppImpls' are persisted in the image heap, add 

    '--initialize-at-build-time=com.github.ajalt.mordant.internal.nativeimage.NativeImageWin32MppImpls'

to the native-image arguments. Note that initializing new types can store additional objects to the heap. It is advised to check the static fields of 'com.github.ajalt.mordant.internal.nativeimage.NativeImageWin32MppImpls' to see if they are safe for build-time initialization,  and that they do not contain any sensitive data that should not become part of the image.

2) If these objects should not be stored in the image heap, you can use 

    '--trace-object-instantiation=com.github.ajalt.mordant.internal.nativeimage.NativeImageWin32MppImpls'

to find classes that instantiate these objects. Once you found such a class, you can mark it explicitly for run time initialization with 

    '--initialize-at-run-time=<culprit>'

to prevent the instantiation of the object.

If you are seeing this message after upgrading to a new GraalVM release, this means that some objects ended up in the image heap without their type being marked with --initialize-at-build-time.
To fix this, include '--initialize-at-build-time=com.github.ajalt.mordant.internal.nativeimage.NativeImageWin32MppImpls' in your configuration. If the classes do not originate from your code, it is advised to update all library or framework dependencies to the latest version before addressing this error.

The following detailed trace displays from which field in the code the object was reached.
Object was reached by
  scanning root com.github.ajalt.mordant.internal.nativeimage.NativeImageWin32MppImpls@b7b8425: com.github.ajalt.mordant.internal.nativeimage.NativeImageWin32MppImpls@b7b8425 embedded in
    com.github.ajalt.mordant.internal.MppImplKt.stdinInteractive(MppImpl.kt:140)
  parsing method com.github.ajalt.mordant.internal.MppImplKt.stdinInteractive(MppImpl.kt:140) reachable via the parsing context <no parsing context available> 

It appears that some specific effort has been put in to supporting GraalVM, so wanted to flag.

@ajalt
Copy link
Owner

ajalt commented Oct 15, 2024

We test against graal 22 in CI. Do you know if something changed in 23 that would cause this? What OS are you running this on?

@iamcalledrob
Copy link
Author

I'm afraid I don't have a ton of context, though the release notes appear to include something relevant.

Deprecated Functionality

The old class initialization strategy, which was deprecated in GraalVM for JDK 22, is now removed. The option --StrictImageHeap no longer has any effect.
Reporting unsupported elements at run time is now enabled by default. The option --report-unsupported-elements-at-runtime is deprecated.

I'm using Windows x64 -- I'm only coincidentally using mordant (as a dependency of Clikt)

@ajalt
Copy link
Owner

ajalt commented Oct 15, 2024

As a temporary workaround, you can exclude the three :mordant-jvm-* modules through gradle or use clikt-core. You'll lose some functionality, but it should compile at least.

@iamcalledrob
Copy link
Author

I used the suggested workaround (--initialize-at-build-time=com.github.ajalt.mordant.internal.nativeimage.NativeImageWin32MppImpls) which seemed to work too!

@hubvd
Copy link
Contributor

hubvd commented Oct 16, 2024

Are you using the latest mordant version ? The class NativeImageWin32MppImpls no longer exists.
Missing --initialize-at-build-time should have been fixed by 45b19ff.
In any case, the workaround works for older mordant versions 👍

@hubvd
Copy link
Contributor

hubvd commented Oct 16, 2024

@ajalt While looking at this, I found that I forgot to remove

// Inlined version of ImageInfo.inImageCode()
val imageCode = System.getProperty("org.graalvm.nativeimage.imagecode")
val isNativeImage = imageCode == "buildtime" || imageCode == "runtime"
if (isNativeImage) return null
which is now useless since that method will never be called in native images. Should I open a PR ?

@ajalt
Copy link
Owner

ajalt commented Oct 16, 2024

@hubvd yes thank you!

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

3 participants