metaspace.cpp: why are counters in ChunkManager updated atomically?

Thomas Stüfe thomas.stuefe at
Thu Oct 27 12:08:03 UTC 2016

Hi all,

I am currently working on a prototype for and have a question about
the ChunkManager class in metaspace.cpp.

ChunkManager has the _free_chunks_total, _free_chunks_count counters. It
seems the coding goes some lengths to avoid updating them often, so instead
of updating them when a chunk is freed it attemps to delay and accumulate
updates. This makes changing the MetaChunk allocation quite complicated,
because there are large windows during which the counters are invalid and
do not reflect reality.

I see that the counters are updated atomically, so I assume the reason for
delaying the updates is that atomics are expensive. But I could not find a
good reason why the counters are updated atomically. To me, all
modifications seem happen under lock protection
(SpaceManager::expand_lock()). What am I overlooking?

Thanks a lot,

Kind Regards, Thomas

More information about the hotspot-runtime-dev mailing list