RFR: 8377179: Improve and document racy use of start/end in ThreadLocalAllocBuffer

Albert Mingkun Yang ayang at openjdk.org
Thu Feb 5 13:31:52 UTC 2026


On Wed, 4 Feb 2026 16:28:02 GMT, Thomas Schatzl <tschatzl at openjdk.org> wrote:

> Hi all,
> 
>   please review this change that tries to document and streamline the racy use of `ThreadLocalAllocBuffer` internals.
> 
> Testing: gha
> 
> Thanks,
>   Thomas

Some minor suggestion; up to you.

src/hotspot/share/gc/shared/threadLocalAllocBuffer.cpp line 472:

> 470:   // the used bytes from a semi-initialized TLAB ending up with implausible values.
> 471:   // In this case also just return 0.
> 472:   if ((diff <= 0) || (diff > checked_cast<ptrdiff_t>(ThreadLocalAllocBuffer::max_size_in_bytes()))) {

I think the logic would be much cleaner if the negative case and exceeding-max case are separated, sth like:


if (top < start) {
  return 0;
}
size = pointer_delta(top, start, 1);
if (size > max) {
  return 0;
}
return size;

src/hotspot/share/gc/shared/threadLocalAllocBuffer.hpp line 127:

> 125:   // bytes), and may just incorrectly return 0.
> 126:   // Intented fo external inspection only where accuracy is not 100% required.
> 127:   size_t cooked_used_bytes() const;

Since the doc uses `estimate`, I'd suggest `estimated_used_bytes` as the name.

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

Marked as reviewed by ayang (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/29573#pullrequestreview-3757057837
PR Review Comment: https://git.openjdk.org/jdk/pull/29573#discussion_r2769175209
PR Review Comment: https://git.openjdk.org/jdk/pull/29573#discussion_r2769139918


More information about the hotspot-dev mailing list