Java "OutOfMemoryError: Compressed class space" in CI
The JVM ran out of compressed class space - a sub-region of class metadata storage used when compressed class pointers are enabled. It is bounded by CompressedClassSpaceSize (default ~1 GB), separate from heap.
What this error means
A build or app with very many classes fails with java.lang.OutOfMemoryError: Compressed class space. Like Metaspace, raising -Xmx does not help - this is class-metadata memory.
java.lang.OutOfMemoryError: Compressed class space
at java.base/java.lang.ClassLoader.defineClass1(Native Method)Common causes
CompressedClassSpaceSize too small for the class count
When tens of thousands of classes load (big frameworks, many generated classes), the compressed class space can fill before Metaspace does.
Classloader leak in a reused JVM
A long-lived daemon or app server that loads classes without unloading old classloaders leaks class metadata until the space is exhausted.
How to fix it
Raise the compressed class space
Increase the cap (and Metaspace alongside it).
java -XX:CompressedClassSpaceSize=1g -XX:MaxMetaspaceSize=1g -jar app.jarReduce class-loading pressure
- Use a fresh JVM per build (
--no-daemon) so class metadata does not accumulate. - Lower test fork parallelism so fewer JVMs load the full class set at once.
- Investigate classloader leaks in any long-lived process.
How to prevent it
- Set
CompressedClassSpaceSize/MaxMetaspaceSizegenerously when many classes load. - Prefer fresh JVMs in ephemeral CI.
- Watch for classloader leaks in reused processes.