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

Tinylog with graalvm thows java.lang.UnsatisfiedLinkError: #145

Closed
shoneslab opened this issue Mar 23, 2020 · 9 comments
Closed

Tinylog with graalvm thows java.lang.UnsatisfiedLinkError: #145

shoneslab opened this issue Mar 23, 2020 · 9 comments
Labels
bug

Comments

@shoneslab
Copy link

@shoneslab shoneslab commented Mar 23, 2020

Getting error in executing a simple java code using tinylog , graalvm. Any help is appreciated.

gradle dependencies

  implementation 'org.tinylog:tinylog-api:2.1.0'
  implementation 'org.tinylog:tinylog-impl:2.1.0'

When running the executable, generated by graalvm, it throws error.

Exception in thread "main" java.lang.UnsatisfiedLinkError: sun.reflect.Reflection.getCallerClass(I)Ljava/lang/Class; [symbol: Java_sun_reflect_Reflection_getCallerClass or Java_sun_reflect_Reflection_getCallerClass__I]
        at com.oracle.svm.jni.access.JNINativeLinkage.getOrFindEntryPoint(JNINativeLinkage.java:145)
        at com.oracle.svm.jni.JNIGeneratedMethodSupport.nativeCallAddress(JNIGeneratedMethodSupport.java:57)
        at sun.reflect.Reflection.getCallerClass(Reflection.java)
        at org.tinylog.runtime.LegacyJavaRuntime.verifySunReflection(LegacyJavaRuntime.java:123)
        at org.tinylog.runtime.LegacyJavaRuntime.<init>(LegacyJavaRuntime.java:35)
        at org.tinylog.runtime.RuntimeProvider.resolveDialect(RuntimeProvider.java:144)
        at org.tinylog.runtime.RuntimeProvider.<clinit>(RuntimeProvider.java:26)
        at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:350)
        at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:270)
        at java.lang.Class.ensureInitialized(DynamicHub.java:467)
        at org.tinylog.configuration.Configuration.load(Configuration.java:225)
        at org.tinylog.configuration.Configuration.<clinit>(Configuration.java:66)
        at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:350)
        at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:270)
        at java.lang.Class.ensureInitialized(DynamicHub.java:467)
        at org.tinylog.Logger.<clinit>(Logger.java:33)
        at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:350)
        at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:270)
        at java.lang.Class.ensureInitialized(DynamicHub.java:467)
        at com.shoneslabs.automation.OtherClass.printSomeThing(OtherClass.java:9)
        at com.shoneslabs.automation.Main.main(Main.java:58)

The steps are

$ ./gradlew clean build --refresh-dependencies --warning-mode all
$  ./gradlew nativeImage
$ build/graal/crauto

and the error throws on build/graal/crauto command

@pmwmedia

This comment has been minimized.

Copy link
Owner

@pmwmedia pmwmedia commented Mar 23, 2020

@shoneslab Could you provide a minimal example project to reproduce the error? Which Java / GraalVM versions are you using?

@shoneslab

This comment has been minimized.

Copy link
Author

@shoneslab shoneslab commented Mar 23, 2020

Please find the github repo for the same: https://github.com/shoneslab/graal-logging
I am using Java 8
GraalVM is provided by the plugin com.palantir.graal and managed by gradle which is 19.2.0

@pmwmedia

This comment has been minimized.

Copy link
Owner

@pmwmedia pmwmedia commented Mar 23, 2020

Which steps do I have to follow to reproduce your issue?

Run task:

23:46:16: Executing task 'run'...

> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE

> Task :run
23:46:17.350 TRACE: Starting... (trace)
23:46:17.359 DEBUG: Starting... (debug)
23:46:17.359 INFO: Starting... (info)

BUILD SUCCESSFUL in 0s
3 actionable tasks: 1 executed, 2 up-to-date
23:46:17.360 WARN: Starting... (warn)
23:46:17: Task execution finished 'run'.

Native Image Task:

23:50:04: Executing task 'nativeImage'...

> Task :downloadGraalTooling SKIPPED
> Task :extractGraalTooling SKIPPED
> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :jar UP-TO-DATE

> Task :nativeImage FAILED
4 actionable tasks: 1 executed, 3 up-to-date
Der Befehl "static" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':nativeImage'.
> Process 'command 'cmd.exe'' finished with non-zero exit value 255

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
23:50:04: Task execution finished 'nativeImage'.
@pmwmedia

This comment has been minimized.

Copy link
Owner

@pmwmedia pmwmedia commented Mar 23, 2020

In the meantime, I built a tinylog version that can handle the java.lang.UnsatisfiedLinkError and fallback to other stack trace extract methods. Could you test it?

tinylog-2.1-SNAPSHOT.zip

@pmwmedia pmwmedia added the bug label Mar 23, 2020
@shoneslab

This comment has been minimized.

Copy link
Author

@shoneslab shoneslab commented Mar 24, 2020

Sorry the steps are

$ ./gradlew clean build --refresh-dependencies --warning-mode all
$  ./gradlew nativeImage
$ build/graal/crauto

and the error throws on build/graal/crauto command

@shoneslab

This comment has been minimized.

Copy link
Author

@shoneslab shoneslab commented Mar 24, 2020

After updating with the provided jar files, here is the new Error.

build.gradle

implementation files("libs/tinylog-api-2.1-SNAPSHOT.jar")
implementation files("libs/tinylog-impl-2.1-SNAPSHOT.jar")

Error

 $ build/graal/crauto
LOGGER ERROR: Service implementation 'org.tinylog.writers.ConsoleWriter' has no matching constructor
@pmwmedia

This comment has been minimized.

Copy link
Owner

@pmwmedia pmwmedia commented Mar 24, 2020

Thank you for testing! We are already one step further.

It is (almost) impossible to build a native imagine with GraalVM on Windows. I will set up a Linux VM for reproducing the issue.

@pmwmedia

This comment has been minimized.

Copy link
Owner

@pmwmedia pmwmedia commented Mar 24, 2020

You have to generate a native image configuration for GraalVM. Using the Gradle build script below, you just need to do the following steps to make the build working:

  1. ./gradlew clean generateConfiguration
  2. ./gradlew nativeImage
  3. Voila, ./build/graal/crauto is working :)

Gradle build script:

plugins {
    id "base"
    id "java"
    id "application"
    id "com.palantir.graal" version "0.6.0"
}

group "com.shoneslabs.automation"
version "1.0-SNAPSHOT"

ext {
    javaMainClass = "com.shoneslabs.automation.Main"
    graalVmVersion = "19.2.0"
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    implementation files("libs/tinylog-api-2.1-SNAPSHOT.jar")
    implementation files("libs/tinylog-impl-2.1-SNAPSHOT.jar")
}

graal {
    mainClass javaMainClass
    graalVersion graalVmVersion
    outputName "crauto"
    option("--allow-incomplete-classpath")
}

application {
    mainClassName = javaMainClass
}

task generateConfiguration(type: Exec) {
    group = "graal"
    description = "Run application to generate the configuration for native image"
    dependsOn build
    commandLine project.gradle.gradleUserHomeDir.toPath().resolve("caches/com.palantir.graal/$graalVmVersion/graalvm-ce-$graalVmVersion/bin/java"), "-agentlib:native-image-agent=config-output-dir=" + project.buildDir.toPath().resolve("resources/main/META-INF/native-image"), "-cp", sourceSets.main.runtimeClasspath.getAsPath(), javaMainClass

    doFirst {
        mkdir project.buildDir.toPath().resolve("resources/main/META-INF/native-image")
    }
}
@pmwmedia pmwmedia closed this Mar 24, 2020
@shoneslab

This comment has been minimized.

Copy link
Author

@shoneslab shoneslab commented Mar 24, 2020

Thanks a lot. I totally forgot about that. It works like a charm!!!

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.