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

Another follow up to parser library loading issue #10134

Closed
wants to merge 1 commit into from

Conversation

hubertp
Copy link
Collaborator

@hubertp hubertp commented May 30, 2024

Pull Request Description

Parser is present in both runtime.jar and runner.jar jars, leading to shared library loading issues:

Caused by: java.lang.UnsatisfiedLinkError: Native Library <...>/component/libenso_parser.so already loaded in another classloader
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:167)
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:139)
    at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2418)
    at java.base/java.lang.Runtime.load0(Runtime.java:852)
    at java.base/java.lang.System.load(System.java:2025)
    at org.enso.runtime/org.enso.syntax2.Parser.initializeLibraries(Parser.java:36)
    ... 43 common frames omitted
Caused by: java.lang.UnsatisfiedLinkError: Can't load library: <...>/target/rust/debug/libenso_parser.so
    at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2422)

This change ensures that library is only loaded once.

Important Notes

Follow up to #10123

Parser is present in both `runtime.jar` and `runner.jar` jars, leading
to shared library loading issues:
```
Caused by: java.lang.UnsatisfiedLinkError: Native Library <...>/component/libenso_parser.so already loaded in another classloader
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:167)
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:139)
    at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2418)
    at java.base/java.lang.Runtime.load0(Runtime.java:852)
    at java.base/java.lang.System.load(System.java:2025)
    at org.enso.runtime/org.enso.syntax2.Parser.initializeLibraries(Parser.java:36)
    ... 43 common frames omitted
Caused by: java.lang.UnsatisfiedLinkError: Can't load library: <...>/target/rust/debug/libenso_parser.so
    at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2422)
```

This change ensures that library is only loaded once.
@hubertp hubertp added the CI: No changelog needed Do not require a changelog entry for this PR. label May 30, 2024
@JaroslavTulach
Copy link
Member

I don't understand why this change should help with classloading.

Caused by: java.lang.UnsatisfiedLinkError: Native Library <...>/component/libenso_parser.so already loaded in another classloader
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:167)
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:139)
    at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2418)
    at java.base/java.lang.Runtime.load0(Runtime.java:852)
    at java.base/java.lang.System.load(System.java:2025)
    at org.enso.runtime/org.enso.syntax2.Parser.initializeLibraries(Parser.java:36)
    ... 43 common frames omitted
Caused by: java.lang.UnsatisfiedLinkError: Can't load library: <...>/target/rust/debug/libenso_parser.so
    at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2422)

Clearly the class is being loaded twice. With your change it is still going to be loaded twice - e.g. I don't think this fixes anything.

@JaroslavTulach
Copy link
Member

The hotfix is to disable Y.doc server being started automatically.

@hubertp
Copy link
Collaborator Author

hubertp commented May 30, 2024

Clearly the class is being loaded twice. With your change it is still going to be loaded twice - e.g. I don't think this fixes anything.

This was a stacktrace from before this PR. If you move loading the library to the static initializer the classloaders will match and it will not complain. I built IDE and it was happy.

Having said that, the constructed native image has a problem with this change:

       java.lang.UnsatisfiedLinkError: org.enso.syntax2.Parser.allocState()J [symbol: Java_org_enso_syntax2_Parser_allocState or Java_org_enso_syntax2_Parser_allocState__]
       	at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.access.JNINativeLinkage.getOrFindEntryPoint(JNINativeLinkage.java:152)
       	at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.JNIGeneratedMethodSupport.nativeCallAddress(JNIGeneratedMethodSupport.java:54)
       	at org.enso.syntax2.Parser.allocState(Native Method)
       	at org.enso.syntax2.Parser.create(Parser.java:90)
       	at org.enso.compiler.core.EnsoParser.<init>(EnsoParser.java:14)
       	at org.enso.compiler.phase.BuiltinsIrBuilder$.$anonfun$build$1(BuiltinsIrBuilder.scala:45)
       	at scala.util.Using$.$anonfun$apply$1(Using.scala:113)
       	at scala.util.Using$.apply(Using.scala:113)

Making it initialize the class at runtime also won't work now because the newly added Feature itself uses Parser thus forcing the initialization at build time.

I can see one way to resolve this - statically linking the libenso_parser.so library in the native image, which appears to be supported. The documentation is rather poor, though, and we would need to satisfy non-NI and NI setup.

@hubertp
Copy link
Collaborator Author

hubertp commented May 30, 2024

Rendered obsolete as noted in the above comment and #10141

@hubertp hubertp closed this May 30, 2024
mergify bot pushed a commit that referenced this pull request May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants