We present JAttack, a framework that enables template-based testing for compilers. Using JAttack, a developer writes a template program that describes a set of programs to be generated and given as test inputs to a compiler. Such a framework enables developers to incorporate their domain knowledge on testing compilers, giving a basic program structure that allows for exploring complex programs that can trigger sophisticated compiler optimizations. A developer writes a template program in the host language (Java) that contains holes to be filled by JAttack. Each hole, written using a domain-specific language, constructs a node within an extended abstract syntax tree (eAST). An eAST node defines the search space for the hole, i.e., a set of expressions and values. JAttack generates programs by executing templates and filling each hole by randomly choosing expressions and values (available within the search space defined by the hole). Additionally, we introduce several optimizations to reduce JAttack's generation cost. While JAttack could be used to test various compiler features, we demonstrate its capabilities in helping test just-in-time (JIT) Java compilers, whose optimizations occur at runtime after a sufficient number of executions. Using JAttack, we have found six critical bugs that were confirmed by Oracle developers. Four of them were previously unknown, including two unknown CVEs (Common Vulnerabilities and Exposures). JAttack shows the power of combining developers' domain knowledge (via templates) with random testing to detect bugs in JIT compilers.
异构编程已经开始成为规范,以便通过在最合适的硬件资源上运行部分代码来实现更好的性能。目前,为了使现有的程序设计语言能够主要在GPU上执行异构执行,进行了大量的工程工作。在本文中,我们描述了Jacc,一个实验框架,允许开发人员直接从Java编程GPGPU。通过使用Jacc框架,开发人员能够以最少的代码重构将GPGPU支持添加到他们的应用程序中。为了简化GPGPU应用程序的开发,我们允许开发人员使用两个关键的抽象来建模异构代码:\textit{tasks},它封装了在GPGPU上执行代码所需的所有信息;以及\textit{task graphs},它捕获应用程序的任务间控制流。利用这些信息,Jacc运行时能够自动处理主机和GPGPU之间的数据移动和同步;消除了显式管理不同内存空间的需要。为了生成高度并行的GPGPU代码,Jacc为开发人员提供了使用注释装饰代码关键方面的能力。编译器反过来利用这些信息来自动生成代码,而不需要额外的代码重构。最后,我们展示了Jacc的优势,无论是在可编程性和性能方面,通过评估它对现有的Java框架。实验结果显示,在NVIDIA Tesla K20 m GPU上进行的八个评估基准测试中,平均性能加速为32倍,代码减少了4.4倍。