JDK-8283710 : JVMTI: Use BitSet for object marking
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: jvmti
  • Affected Version: 17,19
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2022-03-25
  • Updated: 2023-08-14
  • Resolved: 2022-04-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 19
19 b18Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
JVMTI heap walking marks objects in order to track which have been visited already. In order to do that, it uses bits in the object header. Those are the same bits that are also used by some GCs to mark objects (the lowest two bits, also used by locking code). Some GCs also use the bits in order to indicate 'forwarded' objects, where the upper bits of the header represent the forward-pointer. In the case of Shenandoah, it's even more problematic because this happens concurrently, even while JVMTI heap walks can intercept. So far we carefully worked around that problem, but it becomes very problematic in Lilliput, where accesses to the Klass* also requires to decode the header, and figure out what bits means what.

In addition to that, marking objects in their header requires that the original header gets saved and restored. We only do that for 'interesting' headers, that is headers that have a stack-lock, monitor or hash-code. All other headers are reset to their default value. This means we are losing object's GC age. This is not catastrophic, but nontheless interferes with GC.

Comments
[17u-fix-no] The benefit of this change for 17u seems not big enough to admit this change to a quite sensitive part of the VM. I think this should better be maintained in the liliput repo. Benefit for a downstream repo containing an other project is not an argument to admit changes to 17u. It's biggest purpose is to deliver a stable implementation of OpenJDK for 17.
14-08-2023

Fix-request: I am unsure if this change qualifies for a backport. It improves robustness of the JVMTI heap-walk functions (FollowReferences() and IterateThroughHeap()). In the existing implementation, those functions use the mark-word of objects to mark objects as 'visited'. This is problematic, because the mark-word is also used by GCs - the same bit-pattern in the mark-word identifies 'forwarded' objects. To avoid the conflict, JVMTI saves all relevant (i.e. hashed, locked or forwarded) mark-words, and restores them after the heap-walk. However, this drops the age of objects, thus potentially throwing off generational GCs. In any case, it is all quite questionable and somewhat brittle. The change removes that dependency to the object's mark-word and uses a bitmap instead, pretty much like a marking bitmap. The change is also important for Lilliput and I'll admit that this is my primary motivation to backport the change. If you don't consider the change to be feasible for upstream jdk17u, then I'll happily maintain it in downstream lilliput-jdk17u, but I thought I'd ask to consider it for upstream jdk17u anyway. (It's also the last one that I'd even consider for upstream jdk17u). The backport applies mostly cleanly, except for a bunch of contextual changes (see the PR). The change has originally been included in jdk19 and baked since then, with no relevant follow-up bug-reports. The JVMTI heap-walking API is used in the JDK itself by libjdwp, and it is public API. Note that normal heap-dump (e.g. jmap dump) functionality is not affected by this.
24-07-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk17u-dev/pull/1602 Date: 2023-07-19 13:48:07 +0000
19-07-2023

Changeset: abfd2f98 Author: Roman Kennke <rkennke@openjdk.org> Date: 2022-04-11 14:50:29 +0000 URL: https://git.openjdk.java.net/jdk/commit/abfd2f98dcbe3e96efe52b1d66e4c2efb3542955
11-04-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk/pull/7964 Date: 2022-03-25 20:10:32 +0000
28-03-2022