RFR: 8373114: Redundant MethodCounters in the preimage generated by training run [v3]

Ioi Lam iklam at openjdk.org
Thu Jan 15 17:55:15 UTC 2026


On Thu, 15 Jan 2026 15:23:21 GMT, Ashutosh Mehra <asmehra at openjdk.org> wrote:

>> Thank you, that is what I missed. `find()` and find_fast()` call `make()`.
>
>> But I have a question though. Why do we treat the presence of the cache MTD value in MC as a proof that MTD refers to a MC?
> 
> That's a valid point. Ideally we should do the alternate approach mentioned [here](https://github.com/openjdk/jdk/pull/28670#issuecomment-3629940217). But the CDS code has limitations in implementing it (see [comment](https://github.com/openjdk/jdk/pull/28670#issuecomment-3640384909)). The current approach is more of a workaround. If this is not acceptable, we can wait until we modify the CDS code to remember follow-mode for each reference rather than the referenced object. @veresov what do you suggest?

I have an idea to implement the alternative approach:

Change the meaning of `set_to_null` from:
-  the pointer is set to null. The pointee is excluded from the archive

to:
- do no follow the pointee. The pointer is set to null. The pointee may still be included if another reference returns `make_a_copy`.

We need to have a new hashtable that remembers all the cases of `set_to_null`. Then, in `RelocateEmbeddedPointers::doit`:


    address* ptr_loc = (address*)(_buffered_obj + field_offset);
+   address* src_ptr_loc = (address*)(_source_obj + field_offset);

    address old_p_with_tags = *ptr_loc;
    assert(old_p_with_tags != nullptr, "null ptrs shouldn't have been marked");

    address old_p = MetaspaceClosure::strip_tags(old_p_with_tags);
    uintx tags = MetaspaceClosure::decode_tags(old_p_with_tags);
-   address new_p = _builder->get_buffered_addr(old_p);
+   address new_p;
+   if (should_point_to_null(src_ptr_loc)) {
+    new_p = nullptr;
+  } else {
+    new_p = _builder->get_buffered_addr(old_p);
+ }

    bool nulled;
    if (new_p == nullptr) {
      // old_p had a FollowMode of set_to_null
      nulled = true;
    } else {
      new_p = MetaspaceClosure::add_tags(new_p, tags);
      nulled = false;
    }


the `_source_obj` can be added to the constructor of `RelocateEmbeddedPointers`.

I am not sure if we still have a need for the old semantic of `set_to_null`. If so, we may add a new `FollowMode`. If not, maybe `set_to_null` should be changed to `point_to_null`, which I think would be a better name.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28670#discussion_r2695388041


More information about the hotspot-dev mailing list