Tiered compilation, introduced in Java SE 7, brings client startup speeds to the server VM. A server VM uses the interpreter to collect profiling information about methods that is fed into the compiler. In the tiered scheme, in addition to the interpreter, the client compiler generates compiled versions of methods that collect profiling information about themselves. Since the compiled code is substantially faster than the interpreter, the program executes with greater performance during this profiling phase. In many cases, a startup that is even faster than with the client VM can be achieved because the final code produced by the server compiler may be already available during the early stages of application initialization. The tiered scheme can also achieve better peak performance than a regular server VM because the faster profiling phase allows a longer period of profiling, which may yield better optimization. Use the -XX:+TieredCompilation flag with the java command to enable tiered compilation.
CompileThreshold
CompileThreshold表示触发JIT编译之前,解释执行一个方法的代码的执行次数的阈值(the number of method invocations needed before the method is compiled.),该参数的使用方式如下:
This kind of compilation is called On-Stack Replacement (OSR), because even if the loop is compiled, that isn’t sufficient: the JVM has to have the ability to start executing the compiled version of the loop while the loop is still running. When the code for the loop has finished compiling, the JVM replaces the code (on-stack), and the next iteration of the loop will execute the much-faster compiled version of the code.
默认情况下,在Liunx环境,该值的大小为500K。code cache full一旦被处理,将会打印”CodeCache is full”的日志,但是这条日志只会打印一次:
Java HotSpot(TM) 64-Bit Server VM warning: CodeCache is full. Compiler has been disabled. Java HotSpot(TM) 64-Bit Server VM warning: Try increasing the code cachesizeusing -XX:ReservedCodeCacheSize= Code Cache [0xffffffff77400000, 0xffffffff7a390000, 0xffffffff7a400000) total_blobs=11659 nmethods=10690 adapters=882 free_code_cache=909Kb largest_free_block=502656
本篇我们了解了JVM中的另外一个比较重要的区域CodeCache,也了解了JVM中的动态编译机制JIT,针对大多数小流量的应用服务,对于这两个JVM的相关配置可以不用特别关注,但是针对大流量并非的互联网应用场景,则是需要关注的,配置合理合适的值,以保证服务的稳定运行。本文参考: Why do I get message "CodeCache is full. Compiler has been disabled"? http://blogs.oracle.com/poonam/why-do-i-get-message-codecache-is-full-compiler-has-been-disabledOracle CodeCache Tuning http://docs.oracle.com/javase/8/embedded/develop-apps-platforms/codecache.htmOracle Compilation Optimizationhttp://docs.oracle.com/javacomponents/jrockit-hotspot/migration-guide/comp-opt.htm#JRHMG117JVM系列六(JVM-codecache内存区域介绍) http://thinkhejie.github.io/2016/05/05/JVM%E7%B3%BB%E5%88%97_06/