Skip to content

native-image: fails to create image with --language:js, types reachable for JIT compilation must not have linkage errors #4640

Closed
@ahoora08

Description

@ahoora08

Describe GraalVM and your environment :

  • GraalVM version or commit id if built from source: [21.3.1]
  • CE or EE: [CE]
  • JDK version: [JDK8]
  • OS and OS Version: [Linux Ubunti 22.04]
  • Architecture: [amd64]
  • The output of java -Xinternalversion:
 **OpenJDK 64-Bit Server VM GraalVM CE 21.3.1 (25.302-b06-jvmci-21.3-b05) for linux-amd64 JRE (1.8.0), built on Oct 16 2021 10:47:15 by "buildslave" with gcc 7.3.0**

Describe the issue
Hello,
I'm using ScriptEngine API to call some JS scripts in my application.

ScriptEngineManager sem = new ScriptEngineManager();
ScriptEngine jsEngine = sem.getEngineByName("graal.js");
.....
jsEngine.eval(mathFunctionScript)

In normal execution it's fine. Trying to package it as a native-image app I got NullPointerException when trying to call the eval method on the ScriptEngine instance at the runtime.
After investigating some related issues here, I added --language:js to the build properties and then I got the below exceptions:

[app:7434]    classlist:  16,051.19 ms,  1.79 GB
[app:7434]        (cap):   1,107.08 ms,  2.37 GB
[app:7434]        setup:   6,493.77 ms,  2.37 GB
[app:7434]     analysis: 204,468.56 ms,  5.49 GB
Fatal error:com.oracle.svm.core.util.VMError$HostedError: types reachable for JIT compilation must not have linkage errors
        at com.oracle.svm.core.util.VMError.shouldNotReachHere(VMError.java:68)
        at com.oracle.svm.core.util.VMError.guarantee(VMError.java:89)
        at com.oracle.svm.graal.hosted.GraalObjectReplacer.createType(GraalObjectReplacer.java:290)
        at com.oracle.svm.graal.hosted.GraalObjectReplacer.createField(GraalObjectReplacer.java:248)
        at com.oracle.svm.graal.hosted.GraalObjectReplacer.createAllInstanceFields(GraalObjectReplacer.java:325)
        at com.oracle.svm.graal.hosted.GraalObjectReplacer.createType(GraalObjectReplacer.java:301)
        at com.oracle.svm.graal.hosted.GraalObjectReplacer.createField(GraalObjectReplacer.java:248)
        at com.oracle.svm.graal.hosted.GraalObjectReplacer.createAllInstanceFields(GraalObjectReplacer.java:325)
        at com.oracle.svm.graal.hosted.GraalObjectReplacer.createType(GraalObjectReplacer.java:301)
        at com.oracle.svm.graal.hosted.GraalObjectReplacer.createMethod(GraalObjectReplacer.java:214)
        at com.oracle.svm.graal.hosted.GraalObjectReplacer.updateDataDuringAnalysis(GraalObjectReplacer.java:369)
        at com.oracle.svm.graal.hosted.GraalFeature.duringAnalysis(GraalFeature.java:508)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$12(NativeImageGenerator.java:727)
        at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:73)
        at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:727)
        at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:529)
        at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:488)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:569)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:122)
[app:7434]      [total]: 229,493.38 ms,  5.49 GB

Here is the list of the flags I'm using for building the image:

--verbose \
--no-fallback \
--enable-http \
--enable-https \
--allow-incomplete-classpath \
--enable-all-security-services \
--report-unsupported-elements-at-runtime \
--language:js \
-H:EnableURLProtocols=http,https \
-H:ReflectionConfigurationResources=${.}/reflect-config.json \
-H:ResourceConfigurationResources=${.}/resource-config.json \
-H:+ReportExceptionStackTraces \
--allow-incomplete-classpath \
--report-unsupported-elements-at-runtime \
--initialize-at-build-time=\
org.slf4j.LoggerFactory,\
org.slf4j.simple.SimpleLogger,\
org.slf4j.impl.StaticLoggerBinder,\
org.slf4j.MDC,\
ch.qos.logback,\
javax.xml.parsers.FactoryFinder,\
com.sun.org.apache.xerces.internal,\
javax.xml.datatype.DatatypeFactory,\
jdk.xml.internal.JdkXmlUtils \
--initialize-at-run-time=\
io.netty.util.internal.logging.Log4JLogger,\
io.netty.util.AbstractReferenceCounted,\
io.netty.channel.epoll,\
io.netty.handler.ssl,\
io.netty.channel.unix,\
io.netty.internal.tcnative.AsyncSSLPrivateKeyMethod,\
io.netty.internal.tcnative.CertificateCompressionAlgo,\
io.netty.internal.tcnative.CertificateVerifier,\
io.netty.internal.tcnative.SSL,\
io.netty.internal.tcnative.SSLPrivateKeyMethod,\
io.netty.internal.tcnative.AsyncSSLPrivateKeyMethod,\
io.netty.internal.tcnative.CertificateCompressionAlgo,\
io.netty.internal.tcnative.CertificateVerifier

Finally the version of the related dependencies:

<!-- GraalVM runtime -->
       <dependency>
            <groupId>org.graalvm.js</groupId>
            <artifactId>js-scriptengine</artifactId>
            <version>22.0.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.graalvm.truffle</groupId>
            <artifactId>truffle-api</artifactId>
            <version>22.0.0.2</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.graalvm.js</groupId>
            <artifactId>js</artifactId>
            <version>22.0.0.2</version>
            <scope>runtime</scope>
        </dependency>

The prerequisite packages are installed
sudo apt-get install build-essential libz-dev zlib1g-dev

Update1
Exact same exception with GraalVM version CE 22.1.0 JDK 11:

[1/7] Initializing...                                                                                   (16.0s @ 0.36GB)
 Version info: 'GraalVM 22.1.0 Java 11 CE'
 C compiler: gcc (linux, x86_64, 11.2.0)
 Garbage collector: Serial GC
 1 user-provided feature(s)
  - com.oracle.svm.thirdparty.gson.GsonFeature

Update2
I found out that having below dependency is causing the exception. Removing it I get no exception at the build time and both building and execution are fine with --language:js flag.

<dependency>
    <groupId>io.vertx</groupId>
    <artifactId>vertx-micrometer-metrics</artifactId>
    <version>4.2.3</version>
</dependency>

Here is a repos to reproduce the exception:
https://github.com/ahoora08/graalvm-js

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions