Java Object Initialization via Native Buffer Decoupling
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing ORM systems for Java, such as Hibernate and GreenDAO, face inefficiencies in object initialization and data transfer from databases to Java objects, particularly due to excessive JNI calls, suboptimal cache locality, and data copying, which lead to performance issues and increased cache misses.
Innovation Solution
A system and method that utilize a data extraction kernel on the native side and an object initialization kernel on the VM-side, employing multi-cursors and buffer APIs to coordinate data transfer, ensuring efficient data pipeline and cache-friendly memory access, with the kernel generator dynamically producing kernels based on isomorphisms between object types and buffer layouts.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Productivity
If traditional ORM systems use standard data transfer mechanisms, then compatibility with existing technologies is maintained, but object initialization performance is slow and CPU time is high
Solution Approach 1:
The data transfer process is segmented into distinct phases: database query execution, data extraction to buffer, and object initialization. The buffer acts as an intermediate layer that decouples the database access from object creation, allowing parallel processing and reducing CPU time spent on sequential operations.
Solution Approach 2:
The buffer is prepared and populated with raw database data before object initialization occurs. This preliminary data extraction and buffering allows the object initialization phase to proceed faster without waiting for sequential data retrieval from the database, thereby reducing overall CPU time.
2Reliability
If excessive JNI calls are used for data transfer, then inter-process communication is achieved, but performance deteriorates due to call overhead
Solution Approach 1:
A buffer serves as an intermediary data structure between the native database layer and the Java object layer. This buffer eliminates the need for excessive JNI calls by providing a direct memory access pathway, reducing the frequency of cross-language function calls while maintaining reliable data transfer.
Solution Approach 2:
Instead of transferring data through multiple JNI-call-based layers, the system copies raw database data directly into a buffer that can be efficiently accessed by both native and Java code. This copying approach reduces the overhead associated with repeated serialization and deserialization through JNI boundaries.
3Productivity
If standard data copying methods are used, then data transfer is achieved, but cache efficiency is poor due to suboptimal memory access patterns
Solution Approach 1:
The buffer is designed with specific memory layout characteristics that optimize for local data access patterns. By organizing data in the buffer to match the access requirements of subsequent object initialization operations, the system improves cache efficiency and reduces cache misses during data processing.
Solution Approach 2:
The system introduces an intermediate buffer dimension between database data and final objects. This buffer layer reorganizes data into a format that is more cache-friendly, transforming the memory access pattern from sequential database retrieval to optimized block-based access, thereby reducing cache misses.
Data Source
Figure 1A~1B
Figure 2A
Figure 2B
AI summary
The present invention relates to an apparatus for extracting data from a database for object initialization, and apparatus for writing object data to a database, a data extraction method, and a method for writing data to a database. The disclosure facilitates fast and memory efficient data exchange between a native side and a virtual machine (VM-) side. In particular, a data extraction kernel on the native-side reads database data from a plurality of locations in the database using a database interface and writes the database data to a buffer using a native-side buffer API (application programming interface). An object initialization kernel on the VM-side reads the database data from the buffer using a native-side buffer API and initializes a plurality of objects. Information indicating one of the plural memory regions in the buffer where the data extraction kernel writes the database data is known to the native-side buffer API and to the VM-side buffer API.