TLAB pointer movement in Hotspot implementation

Krystal Mok rednaxelafx at gmail.com
Fri Aug 4 06:18:45 UTC 2017


Hi CJ,

The JavaThread::_allocated_bytes field is updated every time the thread's
TLAB is being retired (ThreadLocalAllocBuffer::make_parsable()), and also
when there's a big allocation that goes through the slow path
(CollectedHeap::common_mem_allocate_noinit()). So, that keeps track of the
cumulative sum of all GC heap memory allocated from this thread.

By adding that with the current TLAB's used(), you'd get a fairly accurate
number of the allocated bytes of a thread. There's no intentional delay.
The only "delay" would come from the fact that the _allocated_bytes field
is only loaded with acquire semantics, but not written to with release
semantics, so there might be a slight gap there due to lack of
synchronization, by design.

Hope it helps,
Kris

On Thu, Aug 3, 2017 at 12:28 PM, Chandra Shekahr Jammi <csjammi at gmail.com>
wrote:

> Hi all,
> We are working on a project where we want to use
> com.sun.management.ThreadMXBean#getThreadAllocatedBytes(long) (
> https://goo.gl/j5FDDz) to monitor a thread's memory usage via its TLAB.
> The
> java doc says that
> "some Java virtual machine implementations may use object allocation
> mechanisms that result in a delay between the time an object is allocated
> and the time its size is recorded".
>
> For Hotspot implementation, we traced native call to
> src/share/vm/services/management.cpp::jmm_GetThreadAllocatedMemory
>  and
> src/share/vm/runtime/thread.inline.hpp::cooked_allocated_bytes
>
> We are still browsing the code. But, we haven't yet figured out if
> Hotspot's implementation uses object allocation mechanisms that result in a
> delay between the time an object is allocated and the time its size is
> recorded.
>
> It would be much appreciated if anyone can tell us whether the mechanisms
> are used in Hotspot could cause a delay. Or, even point us to the code
> where our time will be best spent.
>
> Thanks for your time
> CJ
>
>
> Here is the java version Im running
>
> [root@~]# java -version
>
> java version "1.8.0_102"
>
> Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
>
> Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
>


More information about the hotspot-dev mailing list