Object Graph Programming (OGO) enables manipulating the JVM heap
declaratively through queries. The queries are written using the
Cypher Query Language. OGO
supports two high-level modes,
-
Searching an
ArrayListfor a given element.ArrayList<Long> lst = new ArrayList<Long>(); lst.add(10L); lst.add(20L); lst.add(30L); query("MATCH ({$1})-[:elementData]->()-[]->({value : 20}) RETURN TRUE");
In this example, we use imperative code to instantiate and add elements to an
ArrayListand then useCypherquery throughOGOto querylstto check if it contains element 20. -
Implementing the
containsKeymethod ofjava.util.HashMapclass.public boolean containsKeyOgoImpl(HashMap map, object key){ queryBool("MATCH ({$1})-[:table]->()-[]->()-[:key]->(n)" +"MATCH (m {$2})" +"WHERE n.`equals`(m)" +"RETURN COUNT(n) <> 0", map, key); }
In this example, the first
MATCHclause matches a pattern that collects all the objects corresponding to thekeyfield ofHashMap'sinner classNodeinto the variablen. The secondMATCHclause collects the given key object into the variablem. TheWHEREclause filters the elements ofnbased on the output of thejava.lang.Objectclass'sequalsmethod evaluating to true for pairwise inputs fromnandm. This predicate is expected to filter number of elements ofnto 1 if the given key is present in themapand to 0 if absent. Finally, we use theRETURNclause to return the value of the expression that compares equality of number of elements ofnto 0. The query is hence expected to return true iff the number of elements innis non-zero which is true only if the given key is contained inmap.
The project requires the following dependencies:
- Maven
- Java 21
- Conan 2.24.0
- CMake
- Clang Format
Run the installation script to automatically install all required dependencies:
./tasks.sh install_depsThis will check for and install any missing dependencies on your system.
Alternatively, verify your dependencies are correctly installed:
./tasks.sh check_depsCompile the OGO project:
./tasks.sh compileTo compile and install the complete project:
./tasks.sh installExecute the test suite:
./tasks.sh testsTest out the OGO application by running it against Main.java
./tasks.sh execAuto-format Java and C++ code according to project standards:
./tasks.sh formatPerform a complete setup with dependency checks and full installation:
./tasks.sh end_to_endAfter packaging, OGO can be used in any maven project.
-
The client jar can be added as a dependency to a third-party project by adding the following to its pom.
<dependency> <groupId>org.ogo</groupId> <artifactId>ogo</artifactId> <version>0.1.0</version> <scope>system</scope> <systemPath><!-- ENTER full path to client jar including jar name --></systemPath> </dependency>
-
The native agent can be included during execution by adding the following to the third-party pom.
<configuration> <!-- for adding native agent ogoAgent --> <argLine>-agentpath:<!-- ENTER full path to native agent including native agent name --></argLine> </configuration>
Some third-party project tend to use other plugins which may overwrite
argLine. It may be necessary to explicitly specify this argument while running the tests using maven. This can be done using:mvn test -DargLine="-agentpath:<ENTER full path to native agent including native agent name>"
If you use OGO in your research, please cite the following paper:
@inproceedings{ThimmaiahETAL24OGO,
author = {Thimmaiah, Aditya and Lampropoulos, Leonidas and Rossbach, Christopher and Gligoric, Milos},
title = {Object Graph Programming},
year = {2024},
doi = {10.1145/3597503.3623319},
booktitle = {International Conference on Software Engineering},
pages = {1--13},
}The paper can be found here.
