typesafehub/activator — pull request #506 by jroper (2014-05-19 00:57:51+00:00)
Title: Configure -XX:MaxMetaspaceSize

As we all know, permgen space is gone in Java 8, which is great, now classes take no space, so no more classloader leaks, right? Of course not. It's been replaced with "metaspace", which differs to permgen space in that it's not a Java heap, it's allocated directly from memory (ie, when a new class is loaded, a malloc is done to store the meta data). So what that means is when there's a classloader leak, instead of running out of space on the permgen heap, it just keeps consuming main memory, so the symptoms of a leak will now be that the whole system will go slow as the app starts swapping. This is not being a very good citizen, I would personally rather that activator fails in case of a leak before it hogs all my main memory. It will also make it harder to remotely identify classloader leaks, since the only symptoms a user will report will be the process taking too much memory.

Fortunately, the size of metaspace that the JVM can be limited, via the `-XX:MaxMetaspaceSize` flag, once this is reached, `java.lang.OutOfMemoryError: Metadata space` will be thrown. This makes it easy to know the cause of the JVM taking too much memory (distinguishing it from JNI memory leaks, for example).

I think given the dynamic classloading environment of activator, and the frequency under which we see users with these sorts of bugs in Play, that we should configure this flag by default in Activator. According to http://java.dzone.com/articles/java-8-permgen-metaspace, the amount of metaspace required by an app is very similar to the amount of permgen space required, so we should be able to just reuse the existing permgen space sizing logic.