Abstract
Specifications carrying formal parameters that are bound to concrete data at runtime can effectively and elegantly capture multi-object behaviors or protocols. Unfortunately, parametric specifications are not easy to formulate by nonexperts and, consequently, are rarely available. This paper presents a general approach for mining parametric specifications from program executions, based on a strict separation of concerns: (1) a trace slicer first extracts sets of independent interactions from parametric execution traces; and (2) the resulting non-parametric trace slices are then passed to any conventional non-parametric property learner. The presented technique has been implemented in jMiner, which has been used to automatically mine many meaningful and non-trivial parametric properties of OpenJDK 6.
Introduction
Modern software development relies heavily on Application Programming Interfaces (APIs). However, these APIs often come with complex, implicit rules governing how multiple objects must interact. For instance, a common protocol dictates that a collection should not be modified while an iterator is traversing it. These are known as parametric specifications because they involve specific object instances (parameters) at runtime.
Manually documenting these protocols is error-prone and time-consuming. Automated mining from execution traces offers a solution, but it faces significant hurdles. Real-world program traces are "noisy," containing interleaved events from thousands of unrelated objects. Extracting coherent "life stories" for specific object combinations—a process called slicing—is computationally expensive and often results in over-generalized models that fail to catch subtle bugs.
The jMiner Architecture
To address these challenges, the authors developed jMiner, a tool designed to automatically discover parametric specifications through a modular "divide and conquer" strategy.
As shown in the architecture diagram, the process begins by instrumenting programs (using AspectJ) to generate parametric traces during execution on a JVM. These traces are then processed by a specialized Trace Slicer, which produces non-parametric trace slices. These simplified slices are finally fed into a Specification Learner to produce the formal model.
Efficient Trace Slicing and Learning
The core innovation in jMiner lies in its $M\langle X \rangle$ slicing algorithm. Traditional slicers often attempt to track all possible combinations of objects, leading to exponential complexity. jMiner instead focuses on connected parameter instances. It only tracks combinations of objects that appear together in at least one event (e.g., a specific List and the Iterator created from it). This "connectedness" filter ignores the vast majority of irrelevant data, resulting in performance improvements of several orders of magnitude.
Once sliced, the traces are processed using a Probabilistic Finite State Automata (PFSA) learner. To prevent the learner from "guessing" illegal behaviors (over-generalization), jMiner includes an Automaton Refiner. This component unrolls the learned state machine and prunes any transitions not explicitly supported by the observed trace data, ensuring the final specification is a precise reflection of actual program behavior.
Key Results and Bug Discovery
The effectiveness of jMiner was evaluated on several large-scale Java projects, including the OpenJDK 6 libraries, Apache Lucene, and Apache JAMES.
The tool successfully mined complex, human-readable protocols, such as the one illustrated above for the Collection-Iterator relationship. Beyond theoretical modeling, these specifications proved practically useful for bug hunting. By monitoring other programs against the mined rules, the authors identified several real-world issues:
- Resource Leaks: A
Writerin theXalanbenchmark was used after being closed. - Protocol Violations: An iterator in
pmdwas used without the requiredhasNext()check. - Data Loss: An
IndexWriterinLucenewas not properly flushed before program termination.
Conclusion
jMiner demonstrates that by separating trace slicing from property learning, it is possible to efficiently mine high-quality parametric specifications from complex software systems. While the approach currently relies on observed behavior (the "negative evidence" problem) and requires manual event definition, it represents a significant step toward automated API documentation and verification. Future work aims to integrate static analysis to further refine these models by identifying legal but unobserved execution paths.
Summary updated