一句话:提出轻量采样剖析器 OJXPerf,借助硬件 PMU 与调试寄存器概率性识别同类型重复对象,指导 Java 程序消除内存膨胀。
内存膨胀是 Java 等托管语言复杂生产软件中低效的重要来源。已有方法多关注超出生命周期的对象,却很少研究同类型对象之间在多大程度上是完全相同的。本文提出 OJXPerf,一个轻量级采样剖析器,它概率性地识别重复对象:利用硬件性能监控单元(PMU)与硬件调试寄存器,对在同一调用上下文分配、但可能在不同程序点访问的同类型对象的字段值进行采样比较,最终给出按重复频率排序的对象分配上下文与使用上下文组合。这类重复对象相对更容易优化,开发者可据此重构代码以复用已有对象,从而降低内存压力、减少分配与垃圾回收、提升数据局部性并避免重复计算。OJXPerf 平均仅带来 9% 的运行时开销和 6% 的内存开销。作者用其剖析结果指导多个知名基准与真实 Java 应用的优化,测得内存占用最多降低 11%、性能最多提升 25%,实证了该工具的有效性。
Memory bloat is an important source of inefficiency in complex production software, especially in software written in managed languages such as Java. Prior approaches to this problem have focused on identifying objects that outlive their life span. Few studies have, however, looked into whether and to what extent myriad objects of the same type are identical. A quantitative assessment of identical objects with code-level attribution can assist developers in refactoring code to eliminate object bloat, and favor reuse of existing object(s). The result is reduced memory pressure, reduced allocation and garbage collection, enhanced data locality, and reduced re-computation, all of which result in superior performance. We develop OJXPerf, a lightweight sampling-based profiler, which probabilistically identifies identical objects. OJXPerf employs hardware performance monitoring units (PMU) in conjunction with hardware debug registers to sample and compare field values of different objects of the same type allocated at the same calling context but potentially accessed at different program points. The result is a lightweight measurement – a combination of object allocation contexts and usage contexts ordered by duplication frequency. This class of duplicated objects is relatively easier to optimize. OJXPerf incurs 9% runtime and 6% memory overheads on average. We empirically show the benefit of OJXPerf by using its profiles to instruct us to optimize a number of Java programs, including well-known benchmarks and real-world applications. The results show a noticeable reduction in memory usage (up to 11%) and a significant speedup (up to 25%).