RFR: 8301116: Parallelize TLAB resizing in G1

Thomas Schatzl tschatzl at openjdk.org
Thu Feb 2 09:27:52 UTC 2023


On Thu, 2 Feb 2023 09:20:18 GMT, Thomas Schatzl <tschatzl at openjdk.org> wrote:

>> src/hotspot/share/runtime/threadSMR.hpp line 204:
>> 
>>> 202:   JavaThread *const thread_at(uint i) const { return _threads[i]; }
>>> 203: 
>>> 204:   JavaThread *const *threads() const        { return _threads; }
>> 
>> Seems an unrelated change. ??
>
> No, the operations on the `JavaThread` during these phases change the `JavaThread` state (actually, the referenced TLAB state).
> 
> E.g. `g1YoungGCPostEvacuateTasks.cpp:720`:
> 
> void do_work(uint worker_id) override {
>     JavaThread* const* list;
>     uint count;
>     while ((list = _claimer.claim(count)) != nullptr) {
>       for (uint i = 0; i < count; i++) {
>         list[i]->tlab().resize();  <--- here, the tlab needs to be modified (but not the JavaThread)
>       }
>     }
>   }
> 
> 
> I could `const_cast` that one away, but that seemed really ugly to me.
> 
> In a follow-up change there is a similar access to the threads' TLAB. Maybe there is a better way to do that (apart from `const_cast`ing).

To be more exact, the removal of the const happens in `g1CollectedHeap.inline.hpp:124`:

inline JavaThread* const* G1JavaThreadsListClaimer::claim(uint& count) {
  count = 0;
  if (Atomic::load(&_cur_claim) >= _list.length()) {
    return nullptr;
  }
  uint claim = Atomic::fetch_and_add(&_cur_claim, _claim_step);
  if (claim >= _list.length()) {
    return nullptr;
  }
  count = MIN2(_list.length() - claim, _claim_step);
  return _list.list()->threads() + claim;                         <--- here
}

because of the mentioned access in `g1YoungGCPostEvacuateTasks.cpp:720`.

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

PR: https://git.openjdk.org/jdk/pull/12360


More information about the hotspot-gc-dev mailing list