Skip to content

(0.44) Avoid heap walk and GC for MemberName fix-up on class redefinition #19213

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

Merged
merged 1 commit into from
Mar 25, 2024

Conversation

jdmpapin
Copy link
Contributor

This is a cherry-pick of e06a34c (#19187).

In class redefinition the affected MemberName objects were previously
identified by iterating over all objects in the heap. The heap walk also
necessitated a GC cycle to eliminate dead objects, which could otherwise
cause the fix-up to crash.

This heap walk and GC cycle were causing a significant performance
regression in redefinition for builds using OpenJDK MethodHandles (i.e.
Java 17+) vs. ones using J9 MethodHandles. The regression was especially
drastic in fast HCR mode, where no other heap walk is necessary and
therefore the time taken for redefinition should be largely independent
of the number of objects in the heap.

Now instead each J9Class has a list of JNI weak global references to all
of the MemberName objects that are resolved (i.e. have vmtarget set) to
a member of that class (as determined by the clazz field). Redefinition
uses these lists to identify the affected MemberNames without inspecting
any other objects, and in particular without walking the heap. Because
the heap walk is no longer needed, neither is the GC cycle, and both are
eliminated.

The use of weak references ensures that these lists don't prevent
MemberName objects from being reclaimed, and in particular that they
don't prevent class unloading.

When a MemberName is reclaimed, its corresponding weak reference is
cleared, and both that reference and its linked list node become
unnecessary. To avoid leaking this memory, such entries are removed just
prior to the addition of a MemberName, but only if it can be expected
that there are any. To this end, the VM now provides an implementation
of a native method MethodHandleNatives.markClassForMemberNamePruning(),
which is expected to (exist and) be called when a MemberName that is on
a per-class list becomes unreachable (really, phantom reachable), such
as from a cleaning action or finalizer.

Without this adjustment to the Java sources, the mechanism implemented
in this commit will still work, but the MemberName list will leak memory
if many MemberNames for the same class are created and then reclaimed.

(cherry picked from commit e06a34c)
@pshipton pshipton merged commit e14f0f0 into eclipse-openj9:v0.44.0-release Mar 25, 2024
@jdmpapin jdmpapin changed the title Avoid heap walk and GC for MemberName fix-up on class redefinition (0.44) Avoid heap walk and GC for MemberName fix-up on class redefinition Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants