JDK-8256072 : Eliminate JVMTI tagmap rehashing
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: jvmti
  • Affected Version: 16
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2020-11-09
  • Updated: 2022-11-15
  • Resolved: 2022-11-03
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 20
20 b23Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
The JvmtiTagMap uses address-based hashing to map from oops to the associated tag values.  This means that any time the GC moves objects in a tagmap it invalidates the hashing.  It used to be that the GC was rehashing these tables, but that's being changed to defer rehashing until some JVMTI function needs to use the table (JDK-8212879).  This requires the GC to notify JVMTI that (some, possibly relevant) objects have moved.

It may be possible to eliminate the GC-induced rehashing though, by using Java identity hash values instead of object addresses.

Obtaining the identity hash can be done by calling ObjectSynchronizer::FastHashCode.  However, we might not want to force a hash code on every JVMTI-examined object.

We can reduce it to only inflicting a hash code on the JVMTI-tagged objects. Whenever we tag an object (via SetTag or by callback handlers), we can ensure an identity hash code has been assigned, using FastHashCode. When looking up an object in the table to see if it has an associated tag, use a variant of FastHashCode (perhaps the same function with an additional argument). This variant detects no hash code recorded, and instead of computing and installing one, returns 0 to indicate no hash. An object with no hash is guaranteed to not be present in the tagmap.

[Note: This problem with JVMTI heap walkers was removed by JDK-8283710.]
Another problem is that JVMTI heap walkers use the markWord to mark objects it has visited (similar to GCs).  The real markWord value gets saved in a growable array.  So for marked objects we need to reacquire the original mark word (and possibly temporarily reinstall it) in order to obtain its hash code.  The currently used marked value is `markWord::prototype().set_marked()`.  The prototype is just a dummy value.  We could instead use a markWord with the "ptr" field containing the index of the real mark word from the saved array.

Comments
Changeset: 94eb25a4 Author: Coleen Phillimore <coleenp@openjdk.org> Date: 2022-11-03 17:27:00 +0000 URL: https://git.openjdk.org/jdk/commit/94eb25a4f1ffb0f8c834a03101d98fbff5dd0c5c
03-11-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/10938 Date: 2022-11-01 22:31:03 +0000
02-11-2022

JVMTI heap walkers have been changed to no longer use the markWord to mark visited objects (JDK-8283710). That should simplify the change proposed here pretty significantly.
04-05-2022

This was not addressed by JDK-8212879. This change is specifically a followup for that change, to improve it by eliminating the need for an "objects may have moved" notification from the GC to the tagmap code.
07-05-2021

This was resolved with JDK-8212879.
06-05-2021