Java虚拟机在运行过程中使用即时编译器编译Java程序的热点方法,然后直接执行热点方法的本地代码.锁cache机制允许Java虚拟机将编译方法的本地代码锁在cache中,以提高编译执行时的指令cache命中率.通过分析Java虚拟机中编译方法的调用规律,得到编译方法的活跃时间段、平均大小和内存分布情况.基于编译方法的调用规律,给出Java虚拟机中的动态锁cache优化方法.在Java热点方法的活跃期将其本地代码段锁在cache中,以减少cache失效.最后,在龙芯3A的HotSpot虚拟机上实现了动态锁cache优化方法.实验结果表明,Java虚拟机中的动态锁cache优化方法能够使SPECjvm2008运行时的cache失效次数平均降低8.5%,性能平均提升4%.
JVM uses just-in-time compiler(JIT) to improve its performance.JIT compiles the method that has been invoked for a given number of times,and then JVM executes the compiled method when this method is invoked the next time.Cache locking mechanism allows JVM to lock the compiled methods in the cache.This can improve cache performance,because JVM will execute the compiled methods frequently.By analyzing the calling law of the compiled methods in JVM,the calling distribution law,average size and memory distribution of the compiled methods can be obtained.Based on the calling law of the compiled methods,a dynamic cache locking optimization algorithm is proposed,which can lock the active compiled methods in the cache and reduce the cache miss rate when JVM executes the compiled methods.The algorithm has been implemented in HotSpot based on Loongson-3A.Experiment results show that,on average,the dynamic cache locking algorithm reduces the cache miss rate by 8.5% and improves performance by 4% on the benchmark SPECjvm2008.