Java thread dynamic memory allocation

Andrew Haley aph at redhat.com
Mon Sep 28 10:22:34 UTC 2020


On 28/09/2020 10:49, Manavjeet Singh wrote:
> I was looking around the uses of Thread::_tlab. I found
> MemAllocator::allocate() tends to use in most of the cases, by calling
> MemAllocator::allocate_inside_tlab.
> To understand it's working, I added a boolean field in oopDesc class

oopDesc is a well-known struct, and is shared between a lot of code.
Adding a field to it won't work reliably because a great deal of that
code knows the shape of an oopDesc but doesn't use its definition in
oop. hpp. So don't do that.

> with default value false. And while returning from
> MemAllocator::allocate(), I alter that boolean field to true.

> I also added a native function in System class that would print the value
> of the boolean variable in that oopDesc pointer given as an argument.
> I observed that only the first allocated object af any class gets the
> variable set as true and in others the value of that variable was false.
> Can someone help me to comprehend this variation. Also does it mean other
> objects are being allocated somewhere else.

Oh, yes. There are many places that allocate objects. In particular,
JIT-compiled code allocates objects without calling
MemAllocator::allocate(). Did you read and understand the code in my
first reply to you?

-- 
Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671




More information about the hotspot-gc-dev mailing list