Abstract
Program synthesis aims to automate implementation by generating code from high-level specifications. JSKETCH introduces a sketching framework for Java, enabling developers to define partial programs with missing logic ("holes") that are automatically completed. This paper details the translation of object-oriented features like inheritance and dynamic dispatch into an imperative format suitable for the SKETCH synthesis engine, and the subsequent back-translation into valid Java source code.
Introduction
Sketching is a middle-ground approach to program synthesis where a human provides a template (a sketch) with high-level structure, and a synthesizer fills in low-level details. While the original SKETCH tool was a landmark, it was limited to C-like imperative languages. Java developers, who rely on complex class hierarchies and dynamic dispatch, lacked access to these tools. JSKETCH addresses this by providing a frontend that maps rich object-oriented features to a non-OO synthesizer.
System Architecture
JSKETCH operates as a sophisticated frontend for the SKETCH synthesis system. The workflow consists of three primary stages: translation, synthesis, and back-translation.
- Translation (Java to SKETCH): JSKETCH "flattens" Java by representing all objects using a single generic structure (
V_Object) and handling dynamic dispatch via a global dispatch function based on class IDs. - Synthesis: The translated problem is passed to the SKETCH solver. A key innovation is the class-level generator, which allows class templates to be specialized based on their superclass context.
- Back-translation: The solver's output is interpreted and unparsed back into a complete, executable Java file.
Key Insights
The "V_Object" abstraction proves that OO synthesis can be reduced to imperative synthesis without losing semantic correctness. Furthermore, the use of minimization as a heuristic helps prevent "overfitting," ensuring the synthesizer finds logic that more closely resembles human-written code. Class generators further allow the synthesizer to "specialize" templates for different parts of the class hierarchy, a vital feature for object-oriented programming.
Evaluation and Results
JSKETCH was evaluated using micro-benchmarks and real-world framework models for Swing and Android. It successfully synthesized complex models involving up to 117 classes and 4,300 lines of code. Performance-wise, the tool can navigate massive search spaces (e.g., $73^{18} \times 164^{28}$ choices) in approximately two minutes, thanks to the Adaptive Concretization backend algorithm. The tool produces valid Java source code that replaces the original "holes" with concrete logic satisfying all provided assertions.
Limitations and Future Work
Currently, JSKETCH supports a core subset of Java, excluding features like packages, access control, exceptions, and concurrency. It also assumes input sketches are type-correct and requires manual translation of standard libraries. Future directions include expanding supported Java features and improving the tool's ability to handle underconstrained problems where the synthesizer might find valid but non-intuitive solutions.
Conclusion
JSKETCH demonstrates the feasibility of applying sketch-based synthesis to complex object-oriented languages, providing a path toward automating the development of framework models and other intricate Java components.
Summary updated