Metaspace
Native memory, outside the Java heap, holding the metadata of loaded classes: structures, methods and constant pools. It replaced the permanent generation in JDK 8.
Native memory, outside the Java heap, holding the metadata of loaded classes: structures, methods and constant pools. It replaced the permanent generation in JDK 8.
Metaspace grows when classes are loaded and shrinks when their class loader is garbage collected. By default it is limited only by the available native memory. -XX:MaxMetaspaceSize sets a cap, and reaching it throws OutOfMemoryError: Metaspace. -XX:MetaspaceSize sets the threshold at which the first collection is triggered (log cause Metadata GC Threshold).
Typical causes of growth: frameworks that generate classes at runtime (proxies, bytecode generation, scripting), redeployments that leak class loaders, or a limit set too low for the number of classes. A saw tooth with Metadata GC Threshold collections means that the threshold is too low and every increase triggers a full collection: set MetaspaceSize higher. Since JDK 16 (JEP 387) unused metaspace is returned to the operating system more promptly.
Official documentation: JEP 387: Elastic Metaspace, The java command (Oracle)
Full GC
A stop-the-world collection of the entire heap: mark, then compact. The slowest collection; in a healthy application it is rare or absent.
Typical triggers: no room to promote or allocate after a young collection (Allocation Failure), an explicit System.gc() call, the metaspace threshold, a heap inspection or heap dump request, a concurrent collector that fell behind. The cost grows with the live data, since all of it must be marked and moved: seconds on a multi-gigabyte heap.
Serial and Parallel collect their old generation with a full collection by design. G1 uses a parallel full collection since JDK 10, but it remains a last resort. The sign of a problem is frequent full collections that reclaim little: the live data set is close to the heap size, and the application either leaks memory or is under-provisioned. Read the cause in the log line, Pause Full (cause), then the heap after the collection. GC Doctor lists every full GC with its cause and its heap before and after.
Metaspace