eclipse-openj9 / openj9

Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo.
Other
3.27k stars 720 forks source link

Issue with instrumenting java.util.regex.Pattern.matches with java version 16+ #18210

Closed Guluis closed 11 months ago

Guluis commented 11 months ago

Java -version output

openjdk version "17.0.8" 2023-07-18 IBM Semeru Runtime Open Edition 17.0.8.0 (build 17.0.8+7) Eclipse OpenJ9 VM 17.0.8.0 (build openj9-0.40.0, JRE 17 Windows 11 amd64-64-Bit Compressed References 20230718_493 (JIT enabled, AOT enabled) OpenJ9 - d12d10c9e OMR - e80bff83b JCL - 77b0f754805 based on jdk-17.0.8+7)

Summary of problem

I have updated this ticket since I was finally able to recreate this with a simple jar application.

Starting with version 16 and up and including to the latest version 20 there is an issue that occurs when using byte buddy to transform the java.util.regex.Pattern.matches() method. The issue is that after this method is transformed, the following error is thrown when matches() is called:

Exception in thread "main" java.lang.IllegalAccessError: Class java/util/regex/Pattern$BmpCharPredicate$$Lambda$20/0x0000000000000000 illegally accessing "private" member of class java/util/regex/Pattern$BmpCharPredicate at java.base/java.util.regex.Pattern$BmpCharPropertyGreedy.match(Pattern.java:4322) at java.base/java.util.regex.Matcher.match(Matcher.java:1755) at java.base/java.util.regex.Matcher.matches(Matcher.java:712) at com.agent.App.premain(App.java:81) at com.agent.App.main(App.java:36)

I have a sample program I attached that shows this issue occurring but it only happens when using the -agentlib:jdwp flag. The issue happens because of line 61: Pattern topicPattern = Pattern.compile("[\w\-]+(/[\w\-]+)*"); If I remove this line, the code works well. it is as if the creation of the pattern, without even using it, before byte buddy transforms it, causes the issue.

untitled.zip

pshipton commented 11 months ago

@TobiAjila

tajila commented 11 months ago

@hangshao0 Please take a look

hangshao0 commented 11 months ago

There was a fix recently in the Lambda class access check https://github.com/eclipse-openj9/openj9/pull/17816, which was merged on July 27. Can you try on a newer build (https://openj9-jenkins.osuosl.org/view/Build_Nightly/job/Build_JDK17_x86-64_windows_Nightly/) to see if this problem still exist ?

Guluis commented 11 months ago

Yes, I will try and let you know

Guluis commented 11 months ago

I have verified that the issue is resolved in the latest nightly build.