Brussels / 1 & 2 February 2020


Taming Metaspace: a look at the machinery, and a proposal for a better one

When examining memory footprint of a JVM process, the delta between Java heap usage and actual working set size can be surprisingly large. The JVM uses off-heap memory for a lot of things: thread stacks, compiler arenas, code heap, byte buffers, GC control... however, one of the largest consumers of off-heap memory can be class metadata. Class metadata are stored in Metaspace, which includes the Compressed Class Space.

The talk will explore what Metaspace actually is and what is stored there; describe the architecture of the Metaspace allocator and the Compressed Class Space; how it interacts with the GC; how it is sized. We will highlight waste areas and demonstrate how to use jcmd to examine Metaspace internals.

The current implementation of the Metaspace allocator suffers from a number of shortcomings. They can manifest in excessive waste and a certain "clinginess" - an unwillingness to let go of unused memory.

At SAP, we developed an improved version which is more frugal with memory and provides a much improved elasticity. So the second part of this talk will concentrate on our new implementation. We will highlight the differences to the old architecture, demonstrate advantages and examine how it works.


Thomas Stüfe