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

[GR-44282] BeforeAnalysisAccess#registerMethodOverrideReachabilityHandler not getting invoked as expected in GraalVM 22.2 #5194

Closed
mpeddada1 opened this issue Oct 11, 2022 · 6 comments · Fixed by #6154

Comments

@mpeddada1
Copy link

mpeddada1 commented Oct 11, 2022

Describe the issue
Upgrading from GraalVM 22.1 to GraalVM 22.2 is resulting in changed behavior in reachability handlers.

Steps to reproduce the issue
Reproducer: https://github.com/mpeddada1/graalvm22.2-reachability
As seen in the reproducer, the method, BeforeAnalysisAccess.registerMethodOverrideReachabilityHandler() in a custom Feature implementation , doesn't get invoked.when using graalvm 22.2. This leads to classes not being registered for reflection and results in runtime errors like this:

Failures (1):
  JUnit Vintage:MySampleTest:testSample
    MethodSource [className = 'com.example.MySampleTest', methodName = 'testSample', methodParameterTypes = '']
    => java.lang.RuntimeException: Generated message class "com.example.MySampleClass" missing method "getName".
       com.anotherpackage.GeneratedMessage.retrieveMethod(GeneratedMessage.java:31)
       com.anotherpackage.GeneratedMessage.access$000(GeneratedMessage.java:5)
       com.anotherpackage.GeneratedMessage$MethodAccessor.<init>(GeneratedMessage.java:20)
       com.anotherpackage.GeneratedMessage$A.initializeMethodAccessor(GeneratedMessage.java:11)
       com.example.MySampleClass.invokeAccessor(MySampleClass.java:13)
       [...]
     Caused by: java.lang.NoSuchMethodException: com.example.MySampleClass.getName()
       java.lang.Class.getMethod(DynamicHub.java:2108)
       com.anotherpackage.GeneratedMessage.retrieveMethod(GeneratedMessage.java:28)
       [...]

However, that same method is invoked when using graal-sdk 22.1.0 and runs successfully.

Describe GraalVM and your environment:

  • GraalVM version (latest snapshot builds can be found here), or commit id if built from source: 22.2.0
  • JDK major version: 11
  • OS: Linux

More details
Concurrent reachability handlers were enabled by default starting with 22.2.0 so I wonder if we're hitting some sort of a race condition?

Workaround: Adding the -H:-RunReachabilityHandlersConcurrently parameter results in a successful build.

@mpeddada1 mpeddada1 changed the title NoSuchMethodException at runtime when using reachability handlers in GraalVM 22.2 BeforeAnalysisAccess#registerMethodOverrideReachabilityHandler not getting invoked as expected in GraalVM 22.2 Oct 11, 2022
@fniephaus
Copy link
Member

Could you please retry with a recent dev build? 22.3 will be released this month.

@mpeddada1
Copy link
Author

Hi @fniephaus apologies for the delay and thanks for the suggestion! Using the recent dev build of 22.3 still seems to result in the same issue:


Failures (1):
  JUnit Vintage:MySampleTest:testSample
    MethodSource [className = 'com.example.MySampleTest', methodName = 'testSample', methodParameterTypes = '']
    => java.lang.RuntimeException: Generated message class "com.example.MySampleClass" missing method "getName".
       com.anotherpackage.GeneratedMessage.retrieveMethod(GeneratedMessage.java:31)
       com.anotherpackage.GeneratedMessage.access$000(GeneratedMessage.java:5)
       com.anotherpackage.GeneratedMessage$MethodAccessor.<init>(GeneratedMessage.java:20)
       com.anotherpackage.GeneratedMessage$A.initializeMethodAccessor(GeneratedMessage.java:11)
       com.example.MySampleClass.invokeAccessor(MySampleClass.java:13)
       [...]
     Caused by: java.lang.NoSuchMethodException: com.example.MySampleClass.getName()
       [email protected]/java.lang.Class.getMethod(DynamicHub.java:2108)
       com.anotherpackage.GeneratedMessage.retrieveMethod(GeneratedMessage.java:28)
       [...]

Here is a full stacktrace that we're seeing: https://gist.github.com/mpeddada1/9989f8b8fc600d398ceb982380cf45b3

@fniephaus
Copy link
Member

What if you set export USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM=true before running this? Maybe this has something to do with the builder running on the module path.

@fniephaus
Copy link
Member

Assigning to @cstancu since the workaround is to use -H:-RunReachabilityHandlersConcurrently.

@mpeddada1
Copy link
Author

Thanks again @fniephaus! That is indeed an interesting idea. Unfortunately, running export USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM=true also results in the same failure:

**********VALUE of USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM************
true
com.example.MySampleTest > testSample FAILED


Failures (1):
  JUnit Vintage:MySampleTest:testSample
    MethodSource [className = 'com.example.MySampleTest', methodName = 'testSample', methodParameterTypes = '']
    => java.lang.RuntimeException: Generated message class "com.example.MySampleClass" missing method "getName".
       com.anotherpackage.GeneratedMessage.retrieveMethod(GeneratedMessage.java:31)
       com.anotherpackage.GeneratedMessage.access$000(GeneratedMessage.java:5)
       com.anotherpackage.GeneratedMessage$MethodAccessor.<init>(GeneratedMessage.java:20)
       com.anotherpackage.GeneratedMessage$A.initializeMethodAccessor(GeneratedMessage.java:11)
       com.example.MySampleClass.invokeAccessor(MySampleClass.java:13)
       [...]
     Caused by: java.lang.NoSuchMethodException: com.example.MySampleClass.getName()
       [email protected]/java.lang.Class.getMethod(DynamicHub.java:2108)
       com.anotherpackage.GeneratedMessage.retrieveMethod(GeneratedMessage.java:28)
       [...]

For documentation purposes, I've also updated the reproducer with these troubleshooting results.

@fniephaus fniephaus changed the title BeforeAnalysisAccess#registerMethodOverrideReachabilityHandler not getting invoked as expected in GraalVM 22.2 [GR-44282] BeforeAnalysisAccess#registerMethodOverrideReachabilityHandler not getting invoked as expected in GraalVM 22.2 Feb 16, 2023
@fniephaus
Copy link
Member

Thanks a lot for the reproducer. I can confirm this still happens in a current 23.0.0-dev build and I believe we've isolated the issue and are working on a fix.

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

Successfully merging a pull request may close this issue.

3 participants