RFR: 8305903: Deflate monitors of dead objects before they become unreachable

Daniel D. Daugherty dcubed at openjdk.org
Tue May 2 22:03:14 UTC 2023


On Tue, 2 May 2023 09:26:26 GMT, Roman Kennke <rkennke at openjdk.org> wrote:

> how can we deflate and delete the monitor, yet not update the object header?

This is the code in `ObjectMonitor::deflate_monitor()` that detects the object has died:


  if (obj == nullptr) {
    // If the object died, we can recycle the monitor without racing with
    // Java threads. The GC already broke the association with the object.
    set_owner_from(nullptr, DEFLATER_MARKER);
    assert(contentions() >= 0, "must be non-negative: contentions=%d", contentions());
    _contentions = INT_MIN; // minimum negative int
  } else {


It used to be that ObjectMonitors were considered strong roots so the object
could not die while an ObjectMonitor was still holding its oop reference. We
changed that a release or two back and ObjectMonitor now holds a weak ref
to the object. That required addition of the above block to handle the case
when we wanted to deflate the ObjectMonitor and discovered that the object
had "left the building".

Of course, because the object is now gone, the `deflate_monitor()` code
can't fix the header and that didn't used to be a problem. Well actually it's
not really a problem in the current mainline, but will be with Lilliput.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/13721#issuecomment-1532208836


More information about the hotspot-dev mailing list