JRuby's JIT create a lot of new classes, which in certain scenarios could result in permgen space being gobbled up until it's all gone. This is because individual classes can't be collected in Java unless the classloader they're associated with gets collected.
The attached patch modifies the JIT and the class-generation code in JRuby to use a specified classloader. In the case of JITted code, this would be a new classloader per method compiled, allowing those methods to be collected.
With it, the following code runs indefinitely without ever using up permgen:
The patch could use some more eyes, but it seems to work well enough. Of course, the memory overhead caused by classloader-per-method is a whole other issue.