ACER: An AST-based Call Graph Generator Framework

Andrew Chen, Yanfu Yan, Denys PoshyvanykarXiv 2023

TL;DR

ACER is a new, language-agnostic framework for building call graph generators that operate directly on Abstract Syntax Trees (ASTs) rather than compiled bytecode. By leveraging the tree-sitter library, it enables fast, "compile-free" static analysis that significantly outperforms traditional IR-based tools in setup time while maintaining flexibility across different programming languages.

What Problem Does This Paper Address?

Call graphs—diagrams showing which functions in a program call which other functions—are foundational for everything from compiler optimization to security vulnerability detection. However, generating them is a balancing act.

Traditional high-precision tools usually rely on Intermediate Representations (IR), like JVM bytecode. The catch? To get that IR, you must successfully compile the code, which requires having every single library dependency perfectly configured. This makes "quick and dirty" analysis of a partial codebase nearly impossible. On the other end of the spectrum, simple source-code scanners are fast but often too imprecise to be useful. ACER fills this gap by providing a framework for AST-based generation, which is faster than IR-based methods and more structured than raw source-code analysis.

Methods

ACER is built on two main pillars:

  1. Tree-sitter Integration: It uses the tree-sitter parsing library to interface with almost any programming language, providing a common interface for concrete syntax trees.
  2. A Two-Stage Framework: Users implement two core classes to build a generator for a specific language:
  3. Preprocessor: Scans the source files to build lookup structures like method_dict (mapping methods to their code) and class_cache (mapping class hierarchies to handle polymorphism).
  4. Generator: Executes the actual traversal. It uses two abstract methods: seek_call_sites (to find where calls happen) and resolve (to figure out exactly which method is being called).
Fig. 4: Call graph Generation Flow. Preprocessor and Gener- ator are user-implemented.

The authors implemented two specific Java generators using this framework: a simple Name-based Resolution (NR) tool and a Simple Class Hierarchy Analysis (SCHA) tool.

Datasets

The authors evaluated ACER using two primary benchmarks:

  • ArgoUML: A large, open-source Java UML modeling application used to compare the "edges" (calls) discovered by ACER against six established tools (Soot, WALA, JCG, etc.).
  • JDK8: The standard Java library was used to measure the speed and scalability of the generators.

Key Insights and Ideas

  • The "Compile-Free" Advantage: Because ACER operates on ASTs, it doesn't need a buildable environment. This makes it ideal for "application-only" analysis where you only care about the code you wrote, not the millions of lines in your dependencies.
  • Speed vs. Precision Trade-off: IR-based tools are highly precise because the compiler has already done the hard work of resolving types. AST-based tools must re-implement some of this logic, but they gain massive speed by skipping the heavy compilation step.
  • Ambiguity is the Enemy: In an application-only scope, if a method call relies on a type defined in an external library, an AST-based tool might not know exactly which version of a method is being called (e.g., add(int, int) vs add(float, float)), leading to "unnecessary" edges in the graph.

Key Results

The evaluation showed that ACER-based tools are remarkably efficient in terms of developer effort and execution time:

  • Developer Effort: The framework itself is only 800 lines of Python. The NR generator took only 100 lines to write, and the SCHA took 300.
  • Execution Speed: While IR-based tools like WALA and JCG have very fast "generation" times, they require a massive 20-minute preprocessing step to build the IR for JDK8. In contrast, ACER's NR and SCHA tools completed the entire process (preprocessing + generation) in under 4 minutes.
Comparison of generation speeds shows ACER tools (NR, SCHA) avoid the heavy 20-minute preprocessing tax of IR-based tools.
  • Edge Comparison: As expected, the NR tool had high recall (it found almost everything) but low precision (it found many "fake" calls). The SCHA tool was much more conservative, generating the fewest edges among all tested tools due to its simplified handling of complex receivers.

Limitations and Future Work

The authors identify a few key areas for improvement:

  • Type Resolution Complexity: Implementing full type resolution (e.g., handling (builder.make_class()).method()) on an AST is difficult and currently leads to skipped edges in their simple SCHA implementation.
  • Ambiguity: Without library source code, AST-based tools will always struggle with perfectly resolving calls to external APIs.
  • Future Directions: The team plans to build language-agnostic abstractions to help with name resolution and to expand the framework to support other languages beyond Java and Python to prove its multi-lingual capabilities.

Summary updated

BibTeX
@misc{chen2023acer,
  author = {Andrew Chen and Yanfu Yan and Denys Poshyvanyk},
  title = {{ACER: An AST-based Call Graph Generator Framework}},
  year = {2023},
  eprint = {2308.15669},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2308.15669},
}
Figure