1

We are using tools.nsc.interpreter.IMain's interpret() method to execute scala scripts on a server. Works great, no memory leaks etc. Only issue is that jvisualvm reports that the "Total loaded" classes is increasing for this process (doesn't ever saturate).

Is it caused due to interpret()?

Is the total classes loaded by the process something we should be concerned of? the heap size is very well behaved.

We are on scala 2.9.0 and Java 7u2

Debajyoti Roy
  • 985
  • 2
  • 12
  • 34

2 Answers2

2

I think you should be concerned because classes tend to get loaded into the perm gen space (which is reported seperatly to the heap)

As you are running the compiler at "run time" (over and over again by the sounds of it) you may end up with lots of classes loaded into the perm gen. If I were you I would test out the system with a much larger number of files than you intend to use in live and see if your in danger of filling the perm gen.

There is an option to the JVM which will tern on the ability for the JVM to unload classes at run time. This may help but I would recommend you test before and after

-XX:+CMSClassUnloadingEnabled
om-nom-nom
  • 62,329
  • 13
  • 183
  • 228
Mark
  • 467
  • 3
  • 14
  • With -XX:+CMSClassUnloadingEnabled Total loaded classes keeps increasing however, unloaded =0. Without -XX:+CMSClassUnloadingEnabled we get same behavior. Is there any API in scala tools that i should use instead of interpret() or, is that a way to unload the classes loaded by the script once it has been interpreted? – Debajyoti Roy Jan 26 '12 at 18:14
  • It may be that you have to reach the perm gen limit before the JVM will start trying to unload classes. What about reducing the perm gen size in a test environment and then firing lots of scripts at it to see what happens over time. – Mark Jan 26 '12 at 18:18
  • Sounds like this is not quite as simple as I thought... it depends on what GC you are using. http://stackoverflow.com/questions/3334911/what-does-jvm-flag-cmsclassunloadingenabled-actually-do – Mark Jan 26 '12 at 18:21
0

If I'm correct, it's due to the fact that class definition are stored in an immutable space insight JVM (PermGen) and it's not specific to Scala. Any Java application that do dynamic class loading suffer from that (i. e. JRebel).

I heard there is planned change for that, perhaps already in JRE7

Alois Cochard
  • 9,812
  • 2
  • 29
  • 30