The array is a data structure used in a wide range of programs. Its compact storage and constant time random access makes it highly efficient, but arbitrary indexing complicates the analysis of code containing array accesses. Such analyses are important for compiler optimisations such as bounds check elimination. The aim of this work is to gain a better understanding of how arrays are used in real-world programs. While previous work has applied static analyses to understand how arrays are accessed and used, we take a dynamic approach. We empirically examine various characteristics of array usage by instrumenting programs to log all array accesses, allowing for analysis of array sizes, element types, from where arrays are accessed and to which extent sequences of array accesses form recognizable patterns. The programs in the study were collected from the Renaissance benchmark suite, all running on the Java Virtual Machine. We account for characteristics displayed by the arrays investigated, finding that most arrays have a small size, are accessed by only one or two classes and by a single thread. On average over the benchmarks, 69.8% of the access patterns consist of uncomplicated traversals. Most of the instrumented classes (over 95%) do not use arrays directly at all. These results come from tracing data covering 3,803,043,390 array accesses made across 168,686 classes. While our analysis has only been applied to the Renaissance benchmark suite, the methodology can be applied to any program running on the Java Virtual Machine. This study, and the methodology in general, can inform future runtime implementations and compiler optimisations.
翻译:数组是一种广泛应用于各类程序的数据结构。其紧凑的存储结构与常数时间的随机访问特性使其具备极高的效率,但任意索引机制却增加了包含数组访问的代码分析难度。这类分析对于边界检查消除等编译器优化至关重要。本研究旨在深入理解实际程序中数组的使用方式。与以往采用静态分析方法研究数组访问模式的研究不同,我们采用动态分析方法。通过插桩程序记录所有数组访问操作,我们实证考察了数组使用中的多种特征,包括数组大小、元素类型、访问来源,以及数组访问序列形成可识别模式的程度。研究程序均来自Renaissance基准测试套件,运行于Java虚拟机环境。我们对所研究数组呈现的特征进行归因分析,发现多数数组尺寸较小,仅由一至两个类访问,且由单一线程操作。在基准测试中,平均69.8%的访问模式为简单遍历。绝大多数被插桩的类(超过95%)完全不直接使用数组。这些结果基于对168,686个类中3,803,043,390次数组访问的追踪数据。虽然本分析仅针对Renaissance基准测试套件,但该方法可适用于任何运行于Java虚拟机上的程序。本研究及其方法学可为未来的运行时实现与编译器优化提供参考。