Why AI Agents Get JVM Codebases Wrong — and How Bytecode Changes That
Agents that read source code miss compiler-driven changes and cross-file resolution, producing incorrect call graphs; bytecode reveals the actual execution structure.
重點摘要
Source-level parsers (e.g., Tree-sitter) lack cross-file type resolution and miss compiler transformations.
Bytecode contains resolved types, inlined functions, synthetic methods, annotations, and constant values.
Graphite builds a program graph from bytecode and answers structural queries quickly and accurately.
Source-based analysis often misleads AI agents because parsers like Tree-sitter operate at the syntax layer and lack type resolution, cross-file dataflow, and compiler-expanded constructs. In real JVM projects this causes missed call sites (e.g., Kotlin inline functions erased at compile time, synthetic bridge methods, inherited Spring annotations, and constants defined in other modules). Bytecode, by contrast, is what the JVM actually executes: types are resolved, inline bodies are expanded, synthetic methods and constant pool values are present, and annotations can be traversed across hierarchies. Graphite leverages compiled bytecode to construct a program graph (methods, fields, constants, call sites, and relations) and exposes it via Cypher queries. The result is far more accurate call graphs (19 actual AB test constants vs. 6 seen in source) and huge token/efficiency savings for LLM agents querying structure instead of re-reading millions of source tokens.
为什么 AI 代理在 JVM 代码库上出错——以及字节码如何改变这一切
直接读取源代码会漏掉编译器展开和跨文件解析,从而产生错误的调用图;字节码能揭示实际的执行路径。
重點摘要
语法层工具(如 Tree-sitter)无法做跨文件类型解析与数据流追踪。
字节码含已解析的类型、内联展开、合成方法、注解与常量值。
Graphite 从字节码构建程序图并通过 Cypher 查询,快速且高准确度。
基于源代码的代码智能容易出错,因为像 Tree-sitter 这样的解析器只处理语法,无法解析跨文件的类型或数据流,也看不到编译器生成或消除的结构(如 Kotlin 的 inline 展开、为 lambda/私有字段生成的 synthetic 方法、抽象控制器继承的注解,以及在不同模块定义的常量)。字节码是编译器的最终产物:类型被解析、内联函数被展开、合成方法和常量存在于常量池中,注解可通过类层次遍历查询。Graphite 利用字节码构建程序图(方法、字段、常量、调用点与关系),并用 Cypher 提供结构化查询,因此能准确找出真实的调用位点(例如返回 19 个 AB 常数而不是源代码能见的 6 個),并大幅降低 LLM 需要处理的 token 数量。
為何 AI 代理在 JVM 原始碼上出錯 — 以及位元組碼如何改變這一點
直接讀源碼會遺漏編譯器展開與跨檔案解析,導致錯誤的呼叫圖;位元組碼揭示實際的執行結構。
重點摘要
語法解析器(如 Tree-sitter)只看語法,缺乏型別解析與跨檔案資料流。
位元組碼包含已解析的型別、內聯展開、合成方法、註解與常數值。
Graphite 從位元組碼建構程式圖並用 Cypher 查詢,快速且更精確。
以原始碼為基礎的程式分析對 AI 代理常常會產生誤導:Tree-sitter 等工具只解析語法樹,無法進行跨檔案型別解析或看到編譯器所做的變換,例如 Kotlin 的 inline 展開、為 lambda 或私有欄位產生的 synthetic 方法、抽象控制器上繼承的註解,以及定義在不同模組的常數。位元組碼則反映編譯後的真實執行:型別被解析、內聯已展開、合成方法可見、常數在常數池中可查。Graphite 以 JAR/WAR 等位元組碼建構節點與關係的程式圖,並透過結構化查詢回應問題,提供更完整的呼叫位點、端點映射與類別階層解析,且顯著減少 LLM 需掃描的原始碼量。