Posted at

5 秒で Metaspace の OutOfMemoryError を出す方法

More than 5 years have passed since last update.


実行

$ java -XX:MaxMetaspaceSize=1m -version

Error occurred during initialization of VM
OutOfMemoryError: Metaspace


環境

Metaspace は JDK8 以降から。

$ java -version

openjdk version "1.8.0_05"
OpenJDK Runtime Environment (build 1.8.0_05-b13)
OpenJDK 64-Bit Server VM (build 25.5-b02, mixed mode)


原因

単なる verify 漏れ

$ java -XX:MaxMetaspaceSize=1024 -version

Error occurred during initialization of VM
Too small initial Metaspace size


おまけ

Xmxでも1mと1024は扱いが違う。

$ java -Xmx1m -version

openjdk version "1.8.0_05"
OpenJDK Runtime Environment (build 1.8.0_05-b13)
OpenJDK 64-Bit Server VM (build 25.5-b02, mixed mode)
$ java -Xmx1024 -version
Error occurred during initialization of VM
Too small initial heap