Bug 2000557
Summary: | Missing class unload events over JDI with Java 17 | ||||||
---|---|---|---|---|---|---|---|
Product: | Red Hat Enterprise Linux 8 | Reporter: | Simeon Andreev <simeon.andreev> | ||||
Component: | java-17-openjdk | Assignee: | Andrew Dinn <adinn> | ||||
Status: | CLOSED MIGRATED | QA Contact: | OpenJDK QA <java-qa> | ||||
Severity: | unspecified | Docs Contact: | |||||
Priority: | unspecified | ||||||
Version: | 8.6 | CC: | ahughes, loskutov, mmillson, neugens, sgehwolf | ||||
Target Milestone: | rc | Keywords: | MigratedToJIRA | ||||
Target Release: | --- | ||||||
Hardware: | Unspecified | ||||||
OS: | Unspecified | ||||||
Whiteboard: | |||||||
Fixed In Version: | Doc Type: | If docs needed, set a value | |||||
Doc Text: | Story Points: | --- | |||||
Clone Of: | Environment: | ||||||
Last Closed: | 2023-09-12 21:52:16 UTC | Type: | Bug | ||||
Regression: | --- | Mount Type: | --- | ||||
Documentation: | --- | CRM: | |||||
Verified Versions: | Category: | --- | |||||
oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |||||
Cloudforms Team: | --- | Target Upstream Version: | |||||
Embargoed: | |||||||
Attachments: |
|
Description
Simeon Andreev
2021-09-02 11:58:31 UTC
I believe this is same as https://bugs.openjdk.java.net/browse/JDK-8256811, which is linked to original optimization bug https://bugs.openjdk.java.net/browse/JDK-8212879 (In reply to Andrey Loskutov from comment #3) > I believe this is same as https://bugs.openjdk.java.net/browse/JDK-8256811, > which is linked to original optimization bug > https://bugs.openjdk.java.net/browse/JDK-8212879 I've tried adding more waiting in our test, as well as waiting in the snippet that is being debugged (to give the JVM a chance to send events). Neither helps. The jdb based example also finishes without the patched JDK code ever printing anything for some of the class unloads. So if this is https://bugs.openjdk.java.net/browse/JDK-8256811, then the problem there is more than just delayed events; its lost events. I do see a 2nd GC trigger seems to get all events to be sent, at least with the snippet from the description (slightly adjusted) and jdb: public void execute() throws Exception { beforeClassLoading(); loadClasses(); afterClassLoading(); for (int i = 0; i < 5; ++i) { unloadClasses(); afterClassUnloading(); } } ... private void unloadClasses() throws Exception { if (urlClassLoader != null) { urlClassLoader.close(); } urlClassLoader = null; System.gc(); System.runFinalization(); } ... AFTER CLASS LOADING [4.287s][info][class,load] java.io.RandomAccessFile$1 source: /data/git/jdk17/build/linux-x86_64-server-release/jdk/modules/java.base [4.290s][info][class,unload] unloading class sample.C9 0x00000008001c5c30 [4.290s][info][class,unload] unloading class sample.C8 0x00000008001c5a28 [4.290s][info][class,unload] unloading class sample.C7 0x00000008001c5820 [4.290s][info][class,unload] unloading class sample.C6 0x00000008001c5618 [4.290s][info][class,unload] unloading class sample.C5 0x00000008001c5410 [4.290s][info][class,unload] unloading class sample.C4 0x00000008001c5208 [4.290s][info][class,unload] unloading class sample.C3 0x00000008001c5000 [4.290s][info][class,unload] unloading class sample.C2 0x00000008001c4c10 [4.290s][info][class,unload] unloading class sample.C1 0x00000008001c4a08 [4.290s][info][class,unload] unloading class sample.C0 0x00000008001c4800 [4.299s][info][class,load ] java.lang.ref.Finalizer$2 source: /data/git/jdk17/build/linux-x86_64-server-release/jdk/modules/java.base Sending class unload event for: Lsample/C9; Sending class unload event for: Lsample/C7; Sending class unload event for: Lsample/C5; [4.299s][info][class,load ] java.lang.ref.Finalizer$1 source: /data/git/jdk17/build/linux-x86_64-server-release/jdk/modules/java.base AFTER CLASS UNLOADING Sending class unload event for: Lsample/C3; Sending class unload event for: Lsample/C1; Sending class unload event for: Lsample/C0; Sending class unload event for: Lsample/C8; Sending class unload event for: Lsample/C6; Sending class unload event for: Lsample/C4; Sending class unload event for: Lsample/C2; AFTER CLASS UNLOADING AFTER CLASS UNLOADING AFTER CLASS UNLOADING AFTER CLASS UNLOADING ... (from my 10-20 test runs, the 2nd GC would result in prints for any events that were missed in the first GC) Same for our test, if I add a 2nd GC trigger JDI receives all class unload events as expected. I'll have to check whether our application can have problems due to this. I remember Eclipse JDT using ClassUnloadEvent for something (HCR related maybe) but so far I'm not finding such code. Eclipse JDT has a cache, based on class loaded and unloaded events: org.eclipse.jdi.internal.VirtualMachineImpl.fCachedReftypes I'm guessing we can construct a situation where a cache item is used after its respective class has been unloaded. I'm not sure what the implications are. I think there also can be problems with "out of order" loads and unloads, see e.g.: https://bugs.eclipse.org/bugs/show_bug.cgi?id=449791 That is, when a class is loaded, and unloaded, then loaded and unloaded again. We could have load, load events arrive, and then unload unload events. So the 2nd load will replace the cache entry, and the first unload will remove that entry. I'll have to check whether such a sequence (load,load,unload,unload) can occur though. Likely the "delayed" unload will be sent before the 2nd load (though again, I'll have to double check). The cache also is accessed by JDT HCR, see: * org.eclipse.jdt.internal.debug.core.hcr.JavaHotCodeReplaceManager.redefineTypesJDK(JDIDebugTarget, List<IResource>, List<String>) * org.eclipse.jdt.internal.debug.core.hcr.JavaHotCodeReplaceManager.doHotCodeReplace(List<JDIDebugTarget>, List<IResource>, List<String>) Here though elements from the cache are being removed, and not iterated over. So I assume JDT HCR itself is "safe". Possibly the impact for Eclipse is not that big, seeing that the missing unloads are sent on the next GC. The Eclipse-based test we have seems to still fail, from time to time. So apparently triggering GC twice is not sufficient to avoid the problem. It might be that the 2nd GC trigger is ignored by the JVM - its hard to know. I do see JVM logging for the class unload events, as expected. But I have no way of knowing whether the 2nd GC resulted in any work being done, in particular detecting the class unloads and sending events for them (as implied by this comment: https://bugs.openjdk.org/browse/JDK-8256811?focusedCommentId=14397616&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14397616). I think there was a deterministic way of triggering GC with Java 17, i.e. that the GC triggers are always obeyed? Or that was depending on the GC strategy used? First of all, the bug is filed against java-11-openjdk, but seems should be jdk17. The second, what exactly version of the "early release"? since I could not reproduce with current jdk17u head. Okay, I was able to reproduce with current jdk17u head once, so it is intermittent. There was no JDK 17 target when I created the bug (I'm not sure there is one now). And I was testing with early release at the time. Now I see it also with the official JDK 17 release. It is reproducible with jdk head, and yes, it is related to https://bugs.openjdk.java.net/browse/JDK-8256811 and Kim's suggestion seems to work. I will purpose the fix there. (In reply to Simeon Andreev from comment #10) > There was no JDK 17 target when I created the bug (I'm not sure there is one > now). And I was testing with early release at the time. Now I see it also > with the official JDK 17 release. This is because it's filed against RHEL 7. Does it need to be? java-17-openjdk is available as an option for RHEL 8 & 9. We don't provide java-17-openjdk packages for RHEL 7. Based on comments, this is not a problem with java-11-openjdk, as JDK-8212879 is not in jdk11u. (In reply to Andrew John Hughes from comment #12) > This is because it's filed against RHEL 7. Does it need to be? We need a fix in OpenJDK 17, the RHEL version is irrelevant here. Please adjust it to RHEL 9 if this is needed. (In reply to Simeon Andreev from comment #14) > (In reply to Andrew John Hughes from comment #12) > > This is because it's filed against RHEL 7. Does it need to be? > > We need a fix in OpenJDK 17, the RHEL version is irrelevant here. Please > adjust it to RHEL 9 if this is needed. I have moved it to RHEL8. Engineering can adjust as appropriate. PR for JDK20: https://github.com/openjdk/jdk/pull/9168 Will backport to 17u when ready. (In reply to Zhengyu from comment #18) > PR for JDK20: https://github.com/openjdk/jdk/pull/9168 Thank you! > Will backport to 17u when ready. Any estimation in which Java 17 build we can see the fix? The next release of jdk17u (January 2023) will include all the upstream fixes that address this problem. (In reply to Andrew Dinn from comment #28) > The next release of jdk17u (January 2023) will include all the upstream > fixes that address this problem. Sounds great, thanks! OK, I validated with the RHEL 9 OpenJDK 17.0.6 packages. I also validated with the latest master from https://github.com/openjdk/jdk17u.git (top commit 2fe42855c48c49b515b97312ce64a5a8ef3af407 (HEAD -> master, tag: jdk-17.0.6-ga, tag: jdk-17.0.6+10, origin/master, origin/HEAD)). The bug is fixed. Thank you very much! Issue migration from Bugzilla to Jira is in process at this time. This will be the last message in Jira copied from the Bugzilla bug. This BZ has been automatically migrated to the issues.redhat.com Red Hat Issue Tracker. All future work related to this report will be managed there. Due to differences in account names between systems, some fields were not replicated. Be sure to add yourself to Jira issue's "Watchers" field to continue receiving updates and add others to the "Need Info From" field to continue requesting information. To find the migrated issue, look in the "Links" section for a direct link to the new issue location. The issue key will have an icon of 2 footprints next to it, and begin with "RHEL-" followed by an integer. You can also find this issue by visiting https://issues.redhat.com/issues/?jql= and searching the "Bugzilla Bug" field for this BZ's number, e.g. a search like: "Bugzilla Bug" = 1234567 In the event you have trouble locating or viewing this issue, you can file an issue by sending mail to rh-issues. You can also visit https://access.redhat.com/articles/7032570 for general account information. |