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

graal_tear_down_isolate stuck when Java2D Disposer is running #5339

Open
k-x7 opened this issue Nov 1, 2022 · 8 comments
Open

graal_tear_down_isolate stuck when Java2D Disposer is running #5339

k-x7 opened this issue Nov 1, 2022 · 8 comments
Assignees

Comments

@k-x7
Copy link

k-x7 commented Nov 1, 2022

Describe the issue
I have created a small shared lib using native image, which call ImageIO.read(...).
when I call graal_tear_down_isolate from the C code the program will not return anything after printing an error :

Exception while removing reference.

My assumption is Disposer when the thread interrupted it will just print the error and call wait() somewhere else, which will stuck in waiting state or the infinite while loop.

I tried to get Java2D Disposer thread and call interrupt() many times without success.

Steps to reproduce the issue

  1. create a new java class GetImageInfo.java:
import org.graalvm.nativeimage.IsolateThread;
import org.graalvm.nativeimage.c.function.CEntryPoint;
import org.graalvm.nativeimage.c.type.CCharPointer;
import org.graalvm.nativeimage.c.type.CTypeConversion;

import javax.imageio.ImageIO;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class GetImageInfo {

    // For Testing
    public static void main(String[] args) {
        printImageInfo(args[0]);
    }

    @CEntryPoint(name = "get_image_info")
    private static void GetImageInfo(IsolateThread thread, CCharPointer path) {
        String Path = CTypeConversion.toJavaString(path);
        printImageInfo(Path);
    }

    private static void printImageInfo(String path) {
        System.out.println("loading img in path: " + path);
        try {
            BufferedImage input = ImageIO.read(new File(path));
            System.out.println("Height: " + input.getHeight() + ", Width: " + input.getWidth());
        } catch (IOException e) {
            System.err.println(e);
        }
    }

}
  1. run javac:
javac GetImageInfo.java
  1. create config file for JNI and reflection:
java -agentlib:native-image-agent=config-output-dir=META-INF/native-image GetImageInfo PATH_TO_ANY_IMAGE.jpg

output:

loading img in path: sample.jpg
Height: 720, Width: 1200
  1. create a shared lib:
native-image -H:Name=libgetimageinfo GetImageInfo --shared
  1. create a c file main.c:
#include <stdio.h>
#include <stdlib.h>

#include "libgetimageinfo.h"

int main(int argc, char **argv) {
    // printf("[*] using libgetimageinfo main:\n");
    // run_main(argc, argv);

    printf("[*] using libgetimageinfo centrypoint:\n");
    graal_isolate_t *isolate = NULL;
    graal_isolatethread_t *thread = NULL;

    if (graal_create_isolate(NULL, &isolate, &thread) != 0) {
        fprintf(stderr, "initialization error\n");
        return 1;
    }

    get_image_info(thread, argv[1]);

    if (graal_tear_down_isolate(thread) != 0) {
        fprintf(stderr, "shutdown error\n");
        return 1;
    }

    // if (graal_detach_all_threads_and_tear_down_isolate(thread) != 0) {
    //     fprintf(stderr, "shutdown error\n");
    //     return 1;
    // }
}
  1. compile main.c:
gcc -L$(pwd) -I$(pwd) -Wall -o main main.c -lgetimageinfo
  1. run main:
env LD_LIBRARY_PATH=$(pwd) ./main PATH_TO_ANY_IMAGE.jpg

[*] using libgetimageinfo centrypoint:
loading img in path: qrcode.jpg
Height: 720, Width: 1200
Exception while removing reference.

now the program stuck forever.

  1. calling ps in the running program will show the following:
ps -T -p $(pidof main)

    PID    SPID TTY          TIME CMD
1091924 1091924 pts/12   00:02:43 main
1091924 1091931 pts/12   00:00:00 Java2D Disposer

Describe GraalVM and your environment:
Tested on release and last snapshot, Linux amd64:

openjdk version "17.0.5" 2022-10-18
OpenJDK Runtime Environment GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08)
OpenJDK 64-Bit Server VM GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08, mixed mode, sharing)
openjdk 19 2022-09-20
OpenJDK Runtime Environment GraalVM CE 23.0.0-dev (build 19+36-jvmci-23.0-b01)
OpenJDK 64-Bit Server VM GraalVM CE 23.0.0-dev (build 19+36-jvmci-23.0-b01, mixed mode, sharing)
@k-x7 k-x7 changed the title graal_tear_down_isolate stuck when Java2D Disposer is running graal_tear_down_isolate stuck when Java2D Disposer is running Nov 1, 2022
@oubidar-Abderrahim oubidar-Abderrahim self-assigned this Nov 7, 2022
@oubidar-Abderrahim
Copy link
Member

Hi, Thank you for reporting this issue, this is tracked internally on GR 42292.

@zingermax
Copy link

experiencing similar issue (win and macos)

@k-x7
Copy link
Author

k-x7 commented Nov 17, 2022

@oubidar-Abderrahim is there any update?

1 similar comment
@k-x7
Copy link
Author

k-x7 commented Nov 30, 2022

@oubidar-Abderrahim is there any update?

@oubidar-Abderrahim
Copy link
Member

The team is still investigating the issue.

@k-x7
Copy link
Author

k-x7 commented Dec 20, 2022

any update you may have would be greatly appreciated

@wirthi
Copy link
Member

wirthi commented Jan 2, 2023

Hi @k-x7

we are currently working on #4921 to quite generally improve support for AWT and related technologies. Once that is merged (work is in progress already, so expect that to be merged in the next months, but no definite ETA), we will have a look at this. Could easily be affected by the current changes so we will have a look once the major changes are in.

-- Christian

@oubidar-Abderrahim oubidar-Abderrahim removed their assignment Jan 16, 2024
@nmammeri
Copy link

any updates on this?? Facing similar issue while using a dependency that relies on awt. Even tried it with the latest graalvm dev builds, doesn't work. The issue described by @k-x7 is still reproducible with:

native-image 23 2024-09-17
GraalVM Runtime Environment GraalVM CE 23-dev+24.1 (build 23+24-jvmci-b01)
Substrate VM GraalVM CE 23-dev+24.1 (build 23+24, serial gc)

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

No branches or pull requests

5 participants