Page 10 - 《软件学报》2026年第7期
P. 10
赵英全 等: 基于大语言模型的 Java 新特性测试程序生成 2695
driving progress in the whole software ecosystem. To ensure the security and stability of the Java ecosystem, researchers have designed
multiple test program generation methods for Java compilers and virtual machines to detect potential defects. However, the existing
research primarily focuses on designing test program generation methods or mutation strategies for mature Java syntax, making it
challenging to effectively test new language features. To this end, this study proposes LumiX, a test program generation method for Java’s
new features based on large language models (LLMs). First, LumiX adopts LLMs to summarize new language features using natural
language descriptions and obtains the usage descriptions of the new features. Then, it employs historically bug-revealing test programs as
seed programs and applies program analysis tools to extract reusable program elements from the seed programs. By combining the usage
descriptions of new features, LLMs are employed to generate code snippets that incorporate the new features. The newly generated code
snippets are then inserted into the seed programs to generate test programs that can cover the new features. Finally, LumiX designs a dual-
layer differential testing method, which utilizes different Java compilers (javac and ECJ) and virtual machines (HotSpot and OpenJ9) to
compile and execute the newly generated test programs, with potential defects detected by comparing the execution results of different
compilers and virtual machines. Experimental results show that LumiX can effectively generate test programs that cover Java’s new
language features and enhance the testing capabilities of existing tools for Java’s new language features. Additionally, this study applies
LumiX to the latest released Java compilers and virtual machines, and a total of 16 unknown defects have been discovered, 12 of which
have been confirmed or fixed by developers.
Key words: large language model (LLM); test program generation; Java compiler; Java virtual machine (JVM); compiler testing; JVM testing
自 1995 年诞生以来, Java 编程语言就始终保持着旺盛的生命力. 从最初 “一次编写, 随处运行”的理念到近年
来对云原生架构的支持, Java 持续的语言特性和编程范式更新, 不仅推动了自身生态的发展, 也对整个软件工程领
[1]
域产生了深远的影响. 如今, Java 编程语言仍在以每半年一次的速度进行版本迭代, 目前版本号已经更新至 Java 24 .
每个版本都引入了不同的新语言特性 (即新特性) 或编程范式, 例如 Java 8 中的 Lambda 表达式 [2] 、Java 19 中的结
[3]
构化并发 (structured concurrency) 等. 然而, 新特性的引入在提升语言功能的同时, 也带来了诸如新特性实现正确
性以及兼容性等方面的挑战. 作为 Java 软件生态的重要组成部分, 新特性实现的正确性直接关系到 Java 编译器、
Java 虚拟机 (Java virtual machine, JVM) 等核心基础设施的稳定性和可靠性. 其中, Java 编译器旨在将由高级语言
编写的 Java 源程序编译为平台无关的字节码文件, 编译生成的字节码文件则由 JVM 进行加载、验证与执行. 因
此, 对引入的新特性进行针对性的测试, 确保新特性的引入不会破坏 Java 生态的稳定性和可靠性至关重要 [4] .
为了保障 Java 生态核心基础设施 (即 Java 编译器及 JVM) 的质量安全, 现有研究工作大多通过设计基于规约 [5–8]
或基于变异 [9–14] 的测试程序生成方法来对其进行测试. 其中, 基于规约的测试程序生成工作大多通过随机组合目
标语言的不同语法规则, 从无到有地生成新测试程序 [6] . 例如基于 Java 语法的测试程序生成方法 JavaFuzzer , 其
[5]
通过组合已有的不同 Java 语法来生成新的测试程序, 以验证 JVM 对不同语法规则的解析及执行是否正确. 基于
变异的测试程序生成方法则针对特定的语法结构或代码优化功能, 设计相应的变异策略来生成新的测试程序. 例
如, 针对 JVM 启动阶段进行测试的 classfuzz [15] , 其设计了大量针对 Java 语法层面的变异策略 (如, 修改变量修饰
符等) 来生成新的测试程序, 以检测 JVM 对特定语法结构的解析是否正确. JITFuzz [12] 则针对 JVM 即时编译器
(just-in-time, JIT) 的代码优化功能进行测试, 设计能够触发 JIT 编译器优化的变异策略 (如, 插入可内联函数等) 来
生成新的测试程序. 然而, 现有的研究方法仅针对较为稳定的语法结构或代码优化进行测试, 对于新引入的语言特
性, 现有方法往往很难直接应用. 其主要原因在于: (1) 针对新特性的测试往往需要针对性地设计代码生成规则或
变异策略, 而现有方法往往仅针对特定的语法结构或代码优化, 且大多在字节码层面操作, 难以覆盖体现于源码的
语言新特性, 例如, Java 语法糖; (2) 现有方法大多依赖包含特定特性特征的种子程序, 并借助程序分析工具 (例如,
Soot [16] ) 进行解析. 但新特性在发布初期通常缺乏具有代表性的种子程序, 且主流的分析工具在未适配前难以正确
解析新特性的语法, 这限制了部分方法的应用. 此外, 尽管已有大量利用大模型生成测试程序的研究工作 [17–20] , 但
这些工作均不是针对语言新特性而设计, 因此同样无法对其进行有效的测试. 因此, 如何生成针对新特性的测试程
序, 保障新特性实现的正确性, 是亟待解决的问题.
为此, 本文提出一种基于大语言模型的 Java 新特性测试程序生成方法 LumiX, 旨在利用大模型强大的文本理
解及代码生成能力, 结合程序分析方法, 生成能够覆盖语言新特性的测试程序, 从而检测 Java 编译器及 JVM 对新

