JVM CodeCache

The main parts of memory of JVM are Heap, Perm Space and Code Cache. On one hand Heap and Perm sizes are well known as we need to set these sizes quite often, but on the other hand the Code Cache remains not so well known.

With the introduction of JIT (Just in time compiler) I believe in JDK 1.2 version, not all code was compiled to machine code from the byte code at a time. This compilation is completely different from javac compilation we have to convert Java source files to byte codes. The JVM, maintains a certain number that a method should be called (executed), before it decides to compile the code and cache it. By default its 1500 executions but can be overridden using -XX:CompileThreshold=10000. The initial calls to methods when not cached are just executed in interpreted fashion.

So where does code cache fits in all this? Well code cache is part of memory where all the compiled code is cached. There are options (-XX:ReservedCodeCacheSize=32m) to set the size of this cache memory. This memory stays outside of heap memory. So if you decide to make your system reach to peak performance early, by using some extra amount of memory, you should look at these options. Reducing the CompileThreshold and increasing the CodeCache Size, might help you to make your application the peak performance stage faster.

More details on various option configurations:

No comments: