We introduce Object Graph Programming (OGO), which enables reading and modifying an object graph (i.e., the entire state of the object heap) via declarative queries. OGO models the objects and their relations in the heap as an object graph thereby treating the heap as a graph database: each node in the graph is an object (e.g., an instance of a class or an instance of a metadata class) and each edge is a relation between objects (e.g., a field of one object references another object). We leverage Cypher, the most popular query language for graph databases, as OGO's query language. Unlike LINQ, which uses collections (e.g., List) as a source of data, OGO views the entire object graph as a single "collection". OGO is ideal for querying collections (just like LINQ), introspecting the runtime system state (e.g., finding all instances of a given class or accessing fields via reflection), and writing assertions that have access to the entire program state. We prototyped OGO for Java in two ways: (a) by translating an object graph into a Neo4j database on which we run Cypher queries, and (b) by implementing our own in-memory graph query engine that directly queries the object heap. We used OGO to rewrite hundreds of statements in large open-source projects into OGO queries. We report our experience and performance of our prototypes.
翻译:我们提出对象图编程(Object Graph Programming,OGO),该方法通过声明式查询实现对对象图(即对象堆的完整状态)的读取与修改。OGO将堆中的对象及其关系建模为对象图,从而将堆视为图数据库:图中每个节点是一个对象(如类的实例或元数据类的实例),每条边是对象间的关系(如某对象的字段引用另一对象)。我们采用图数据库最流行的查询语言Cypher作为OGO的查询语言。与LINQ使用集合(如List)作为数据源不同,OGO将整个对象图视为单一的"集合"。OGO既适用于查询集合(类似LINQ),也适用于运行时系统状态内省(如查找给定类的所有实例或通过反射访问字段),以及编写能访问完整程序状态的断言。我们通过两种方式为Java实现了OGO原型:(a)将对象图转换为Neo4j数据库,在其上执行Cypher查询;(b)实现自研内存图查询引擎,直接查询对象堆。我们使用OGO将大型开源项目中的数百条语句重写为OGO查询,并报告了原型系统的实践经验与性能表现。