Non-volatile memory (NVM) is a game-changer, offering the speed of RAM with the persistence of a hard drive. But for managed languages like Java, taking advantage of NVM has been a headache. You either deal with the massive overhead of traditional databases (JPA) or struggle with complex, incompatible "off-heap" libraries.
This paper introduces Espresso, a holistic extension to the Java runtime and language that integrates NVM directly into the JVM. By treating persistent data as native Java objects, Espresso achieves massive performance gains while keeping the programming model familiar and compatible with existing code.
TL;DR
Espresso integrates Non-Volatile Memory (NVM) directly into the Java Virtual Machine through a new "Persistent Java Heap." It allows developers to allocate persistent objects using a simple pnew keyword, outperforming existing persistence frameworks by up to 256x while maintaining compatibility with standard Java data structures.
What Problem Does This Paper Address?
The "persistence wall" in Java is real. Currently, if you want to save data, you usually use the Java Persistence API (JPA). JPA is easy to use but slow because it forces a "data transformation" tax—converting Java objects into SQL statements or serialized formats.
Recent alternatives like Persistent Collections for Java (PCJ) try to be faster by managing data "off-heap" in NVM. However, PCJ forces you to use a completely different type system (e.g., PersistentInteger instead of Integer), making it incompatible with existing libraries and surprisingly slow due to the overhead of managing metadata outside the JVM's view.
The challenge is: How do we give Java programmers the performance of NVM without breaking the language's core features like garbage collection, type safety, and ease of use?
Methods
The authors built Espresso by modifying OpenJDK 8 to support a hybrid memory model. Its architecture rests on three pillars:
- Persistent Java Heap (PJH): Espresso adds a dedicated area in NVM for persistent objects. Unlike off-heap solutions, these are "real" Java objects. To make this work, they introduced Alias Klasses—a clever way for the JVM to recognize that a class stored in DRAM is logically identical to the same class stored in NVM, preventing type-casting errors.
- Language Extensions (
pnew): They added a new keyword,pnew, which tells the JVM to allocate an object in the persistent heap rather than the volatile one. This requires minimal changes to existing code. - Crash-Consistent Runtime: Since NVM survives power failures, the heap's metadata (like where objects are located) must be "crash-consistent." Espresso enhances the JVM's Parallel Scavenge garbage collector to ensure that even if the system crashes mid-collection, the persistent heap remains uncorrupted.
- Persistent Java Object (PJO): This is a high-level abstraction that replaces JPA. It reuses familiar annotations but skips the slow SQL transformation phase, shipping data directly to NVM-backed storage.
Datasets
The authors evaluated Espresso using:
- Microbenchmarks: Measuring primitive operations (create, get, set) on various data types (ArrayList, Hashmap, etc.).
- JPAB (JPA Performance Benchmark): A standard suite testing CRUD operations, inheritance, and complex object relationships.
- H2 Database: A popular open-source Java RDBMS, modified to run atop Espresso's persistent heap.
Key Insights and Ideas
- On-Heap is King: The "aha moment" is that managing persistent data inside the JVM's heap is far more efficient than managing it outside. By letting the JVM "see" persistent objects, Espresso avoids the constant metadata updates and type-checking that cripple off-heap libraries.
- Solving the Identity Crisis: The Alias Klass concept is a vital fix for a subtle problem: the JVM normally treats classes in different memory regions as different types. Espresso's fix allows seamless interaction between DRAM and NVM objects.
- Decoupling Safety from Performance: Espresso offers different "safety levels" (User-guaranteed, Zeroing, and Type-based). This lets developers choose between maximum speed and maximum protection against "dangling" volatile pointers in persistent memory.
Key Results
- Massive Speedups: In microbenchmarks, Espresso outperformed PCJ by up to 256.3x for set operations. Even for simple "get" operations, it was at least 6x faster.
- Database Gains: When running the H2 database, Espresso (via the PJO abstraction) achieved up to 3.24x higher throughput than standard JPA.
- Low GC Overhead: The crash-consistency mechanisms only added about 17.8% to garbage collection pause times—a small price to pay for a heap that survives a reboot.
- Fast Recovery: Loading a persistent heap with 2 million objects takes only ~72ms, which is negligible compared to standard JVM warm-up times.
Limitations and Future Work
- JVM Modification: Espresso requires a custom JVM. It isn't a "drop-in" library you can add to a standard environment.
- Memory Safety: While Espresso provides safety levels, developers still need to be careful. Storing a pointer to a volatile DRAM object inside a persistent NVM object can lead to crashes after a reboot if not handled correctly.
- Future Directions: The authors suggest moving heavy persistence operations (like cache flushes) out of the critical execution path to further boost performance. They also see potential in integrating Espresso with distributed NVM systems like RDMA-based storage.
Summary updated