Methods, systems, media, and devices for Java garbage collectors in heterogeneous memory
By dividing the Java heap into young generation and old generation, and optimizing the object storage area with write barriers, the problem of high latency and low durability of non-volatile memory write operations in Java applications is solved, improving memory capacity and performance, and making it suitable for heterogeneous memory systems.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANGHAI JIAOTONG UNIV
- Filing Date
- 2023-07-21
- Publication Date
- 2026-05-26
Smart Images

Figure CN116954900B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the technical field of Java garbage collectors, specifically to a method, system, medium, and device for garbage collection in Java garbage collectors with heterogeneous memory, and more particularly to a heterogeneous memory-friendly Java garbage collector. Background Technology
[0002] In current computer systems, the Central Processing Unit (CPU) reads and writes data from external storage by accessing and writing to main memory. Main memory, due to its caching function during external storage read / write operations, has become a crucial component of modern computer systems. Memory performance is determined by parameters such as capacity, power consumption, and read / write latency. As the number of CPU cores and the size of application working sets continue to increase, the demand for memory capacity is growing daily, posing a significant challenge to memory scalability.
[0003] Dynamic Random Access Memory (DRAM) has become the mainstream memory system due to its advantages such as byte addressability, low read / write latency, and low power consumption. However, DRAM still suffers from poor scalability, making it difficult to meet the current memory capacity requirements of computer applications.
[0004] Non-volatile memory (NDRAM) is ideal for providing large-capacity memory for large applications due to its byte-addressable, persistent, and high-density characteristics. While NDRAM's read / write latency is significantly lower than other persistent devices (disks, SSDs), its write latency is higher and its write endurance is lower than that of dynamic random-access memory (DRAM), making it unsuitable for write-intensive applications. Therefore, recent work aims to fully utilize the large capacity of NDRAM by using heterogeneous memory systems composed of DRAM and NDRAM, while minimizing write operations to extend its lifespan and reduce performance overhead.
[0005] Java is an object-oriented high-level programming language. Its Java Virtual Machine (JVM) abstraction helps Java applications manage memory. Users can directly allocate and initialize objects using Java primitives without needing to reclaim unused objects. Java's memory management mechanism allows users to focus on program logic, reducing their workload and preventing memory leaks. To address the issue of insufficient available memory in Java applications, the language also proposes a technique to map the Java heap to other storage devices to meet memory requirements. This technique allows users to map the Java heap storing objects to a larger storage device (such as non-volatile memory) while retaining metadata other than objects in dynamic random access memory (DRAM). While allocating the heap to other storage devices alleviates the memory shortage problem, the performance difference between the mapped storage device and DRAM causes a performance penalty for Java applications. Furthermore, non-volatile memory generally suffers from insufficient write lifespan; allocating all objects to non-volatile memory leads to a significant increase in write operations, causing wear and tear on the non-volatile memory.
[0006] Therefore, a new technical solution is needed to improve the above-mentioned technical problems. Summary of the Invention
[0007] To address the shortcomings of existing technologies, the purpose of this invention is to provide a method, system, medium, and device for garbage collection in a Java garbage collector for heterogeneous memory.
[0008] According to the present invention, a garbage collection method for heterogeneous memory using a Java garbage collector includes the following steps:
[0009] Step S1: When creating the Java heap, divide the heap into the young generation and the old generation;
[0010] Step S2: Reserve an observation space in the young generation of the heap and map the young generation to the dynamic random access memory;
[0011] Step S3: Divide the old generation of the heap into a write-dominant region and a read-dominant region, and map the dynamic random access memory and non-volatile memory to these two regions respectively;
[0012] Step S4: Place objects created during application runtime into the young generation, and use write barriers to record objects in the observation space to determine their write operation tendencies;
[0013] Step S5: When the young generation space is insufficient, perform a young generation garbage collection, that is, scan the young generation and move all live objects to the corresponding area according to their survival time and the tendency to perform write operations. Among them, objects that are mainly write operations should be moved to the write-dominant area of the old generation, and the rest of the objects should be moved to the read-dominant area of the old generation.
[0014] Step S6: When there is insufficient space in one of the regions of the old generation, scan all live objects in the heap and compress the write-dominated region and the read-dominated region of the old generation, and transfer the objects of the young generation to the write-dominated region of the old generation.
[0015] Preferably, in step S2, the size of the observation space is adjusted by the user, and the size of the observation space is 1 / 10 of the total size of the young generation.
[0016] Preferably, in step S3, the ratio of the younger generation to the older generation is set by the user according to their own configuration, and the ratio of the younger generation to the older generation is preset to 1:2.
[0017] Preferably, in step S5, the promotion threshold for an object in the young generation is set by the user, and the preset promotion threshold for an object in the young generation is that the object has undergone one young generation garbage collection.
[0018] This invention also provides a garbage collection system for a Java garbage collector in heterogeneous memory, the system comprising the following modules:
[0019] Module M1: Divides the Java heap into young generation and old generation when creating the heap;
[0020] Module M2: Reserves an observation space in the young generation of the heap and maps the young generation to dynamic random access memory;
[0021] Module M3: Divides the old generation of the heap into a write-oriented region and a read-oriented region, and maps dynamic random access memory and non-volatile memory to these two regions respectively;
[0022] Module M4: Places objects created during application runtime into the young generation and uses write barriers to record objects in the observation space to determine their write operation tendencies;
[0023] Module M5: When the young generation space is insufficient, perform a young generation garbage collection, that is, scan the young generation and move all live objects to the corresponding area according to their survival time and the tendency to perform write operations. Among them, objects that are mainly write operations should be moved to the write-dominant area of the old generation, and the rest of the objects should be moved to the read-dominant area of the old generation.
[0024] Module M6: When there is insufficient space in one of the old generation regions, scan all live objects in the heap and compress the write-dominated region and read-dominated region of the old generation, and move the young generation objects to the write-dominated region of the old generation.
[0025] Preferably, the size of the observation space in module M2 is adjustable by the user, and the size of the observation space is 1 / 10 of the total size of the young generation.
[0026] Preferably, the ratio of the younger generation to the older generation in module M3 is set by the user according to their own configuration, and the ratio of the younger generation to the older generation is preset to 1:2.
[0027] Preferably, the promotion threshold for objects in the young generation in module M5 is set by the user, and the preset promotion threshold for objects in the young generation is that objects that have undergone one young generation garbage collection are promoted.
[0028] The present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the garbage collection method of the Java garbage collector for heterogeneous memory described above.
[0029] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the above-described method for garbage collection of heterogeneous memory using a Java garbage collector.
[0030] Compared with the prior art, the present invention has the following beneficial effects:
[0031] 1. This invention does not require modification to hardware or system software (such as operating system, virtual machine monitoring program), making it easy to port and promote;
[0032] 2. This invention integrates Java object-aware heterogeneous memory management into the Java Virtual Machine's memory management module, which is more accurate and has less overhead than modifying system software to achieve page-level memory management.
[0033] 3. This invention introduces a large-capacity non-volatile memory, which solves the problem of insufficient memory capacity caused by the poor expandability of the original dynamic random access memory.
[0034] 4. Based on heterogeneous memory systems, this invention fully utilizes the advantages of dynamic random access memory (DRAM) in terms of high read / write performance and high write endurance by allocating objects with high write tendency to non-volatile memory. Attached Figure Description
[0035] Other features, objects, and advantages of the present invention will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings:
[0036] Figure 1 A flowchart illustrating the workflow of the waste recycling device provided by this invention. Detailed Implementation
[0037] The present invention will now be described in detail with reference to specific embodiments. These embodiments will help those skilled in the art to further understand the present invention, but do not limit the invention in any way. It should be noted that those skilled in the art can make several changes and improvements without departing from the concept of the present invention. These all fall within the scope of protection of the present invention.
[0038] Example 1:
[0039] According to the present invention, a garbage collection method for heterogeneous memory using a Java garbage collector includes the following steps:
[0040] Step S1: When creating the Java heap, divide the heap into the young generation and the old generation;
[0041] Step S2: Reserve an observation space in the young generation of the heap and map the young generation to dynamic random access memory; the size of the observation space is adjusted by the user and is 1 / 10 of the total size of the young generation.
[0042] Step S3: Divide the old generation of the heap into a write-oriented region and a read-oriented region, and map the dynamic random access memory and non-volatile memory to these two regions respectively; the ratio of the young generation to the old generation is set by the user according to their own configuration, and the default ratio of the young generation to the old generation is 1:2.
[0043] Step S4: Place objects created during application runtime into the young generation, and use write barriers to record objects in the observation space to determine their write operation tendencies;
[0044] Step S5: When the young generation space is insufficient, perform a young generation garbage collection, that is, scan the young generation and move all live objects to the corresponding area according to their survival time and tendency to perform write operations. Among them, objects that mainly perform write operations should be moved to the write-dominant area of the old generation, and the rest of the objects should be moved to the read-dominant area of the old generation. The promotion threshold of objects in the young generation is set by the user. The preset promotion threshold of objects in the young generation is that objects that have undergone one young generation garbage collection are promoted.
[0045] Step S6: When there is insufficient space in one of the regions of the old generation, scan all live objects in the heap and compress the write-dominated region and the read-dominated region of the old generation, and transfer the objects of the young generation to the write-dominated region of the old generation.
[0046] The present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the garbage collection method of the Java garbage collector for heterogeneous memory described above.
[0047] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the above-described method for garbage collection of heterogeneous memory using a Java garbage collector.
[0048] The present invention also provides a garbage collection system for a Java garbage collector with heterogeneous memory. The garbage collection system for a Java garbage collector with heterogeneous memory can be implemented by executing the process steps of the garbage collection method for a Java garbage collector with heterogeneous memory. That is, those skilled in the art can understand the garbage collection method for a Java garbage collector with heterogeneous memory as a preferred embodiment of the garbage collection system for a Java garbage collector with heterogeneous memory.
[0049] Example 2:
[0050] This invention also provides a garbage collection system for a Java garbage collector in heterogeneous memory, the system comprising the following modules:
[0051] Module M1: Divides the Java heap into young generation and old generation when creating the heap;
[0052] Module M2: Reserves an observation space in the young generation of the heap and maps the young generation to dynamic random access memory; the size of the observation space can be adjusted by the user, and the size of the observation space is 1 / 10 of the total size of the young generation.
[0053] Module M3: Divides the old generation of the heap into a write-oriented region and a read-oriented region, and maps dynamic random access memory and non-volatile memory to these two regions respectively; the ratio of the young generation to the old generation is set by the user according to their own configuration, and the default ratio of the young generation to the old generation is 1:2.
[0054] Module M4: Places objects created during application runtime into the young generation and uses write barriers to record objects in the observation space to determine their write operation tendencies;
[0055] Module M5: When the young generation space is insufficient, perform a young generation garbage collection, which involves scanning the young generation and moving all live objects to the corresponding regions based on their survival time and tendency to perform write operations. Objects that are primarily write-oriented should be moved to the write-oriented region of the old generation, while other objects should be moved to the read-oriented region of the old generation. The promotion threshold for objects in the young generation is set by the user, and the default promotion threshold is that objects that have undergone one young generation garbage collection are promoted.
[0056] Module M6: When there is insufficient space in one of the old generation regions, scan all live objects in the heap and compress the write-dominated region and read-dominated region of the old generation, and move the young generation objects to the write-dominated region of the old generation.
[0057] Example 3:
[0058] This invention provides a heterogeneous memory-friendly Java garbage collector, implemented through the following technical solution:
[0059] This invention relates to a garbage collector in a Java Virtual Machine that manages heterogeneous memory consisting of non-volatile memory and dynamic random access memory. This garbage collector follows the approach of generational garbage collectors. Its key feature is that, addressing the unsuitability of writing operations on non-volatile memory, the Java heap is re-partitioned to mitigate the impact of poor write performance and low write endurance of non-volatile memory. Specifically, it includes the following steps:
[0060] (1) When creating the Java heap, the heap is divided into the young generation and the old generation;
[0061] (2) Reserve an observation space in the young generation of the heap and map the young generation onto the dynamic random access memory;
[0062] (3) Divide the old generation of the heap into a write-oriented region and a read-oriented region, and map the dynamic random access memory and non-volatile memory to these two regions respectively.
[0063] (4) Place objects created during application operation in the young generation and use write barriers to record objects in the observation space to determine their tendency to perform write operations.
[0064] (5) When the young generation space is insufficient, perform a young generation garbage collection, that is, scan the young generation and move all live objects to the corresponding area according to their survival time and the tendency to perform write operations. Among them, objects that are mainly write operations should be moved to the write-dominant area of the old generation, and the rest of the objects should be moved to the read-dominant area of the old generation.
[0065] (6) When there is insufficient space in one of the regions of the old generation, scan all the live objects in the heap and compress the write-dominated region and the read-dominated region of the old generation, and transfer the objects of the young generation to the write-dominated region of the old generation.
[0066] In step (2), the size of the observation space can be adjusted by the user, and the default value is 1 / 10 of the total size of the young generation.
[0067] In step (3), the ratio of the younger generation to the older generation is set by the user according to their own configuration, with the default being 1:2.
[0068] In step (5), the promotion threshold for objects in the young generation can be set by the user. By default, objects that have undergone one young generation garbage collection can be promoted.
[0069] This invention should run on a computer that simultaneously loads non-volatile memory and dynamic random access memory, and maps the non-volatile memory to a file system. Its characteristic is that the mapping between the space in the Java heap and the non-volatile memory can be established through system calls.
[0070] The heterogeneous memory-friendly Java garbage collector provided by the present invention includes the following steps:
[0071] Application startup steps: Run the Java Virtual Machine via command line or other means to start the Java application and pass some parameters to the Java Virtual Machine via command line arguments;
[0072] Java Virtual Machine initialization steps: The Java Virtual Machine is initialized according to the passed parameters. This invention mainly focuses on the initialization of the Java heap. This invention will construct the corresponding Java heap according to parameters such as the size of the observation space and the ratio of read-oriented to write-oriented.
[0073] Object allocation steps: The Java Virtual Machine allocates objects in the non-observation space of the young generation and completes the object initialization;
[0074] Young generation garbage collection steps: When the allocatable space in the young generation is insufficient, the Java Virtual Machine will perform a young generation garbage collection, copying objects in the young generation that are not in the observation space to the observation space, and copying objects in the observation space to the corresponding old generation space according to their write tendency. That is, write-oriented objects are allocated to the part of the old generation that is mapped to dynamic random access memory, while non-write-oriented objects are allocated to the part of the old generation that is mapped to non-volatile memory.
[0075] Full heap garbage collection steps: When one of the spaces in the old generation is insufficient for allocable memory, the Java Virtual Machine will perform a full heap garbage collection, reclaiming objects whose lifecycles have ended in the two spaces in the old generation and moving live objects to contiguous spaces to obtain contiguous allocable space.
[0076] Application execution steps: During the execution of a Java application, new objects are created, existing objects are modified, and values are read from objects. The object allocation step occurs when new objects are created during application execution. When modifying existing objects, this invention uses write barriers in the Java Virtual Machine to determine whether the modified object is in the observation space. If not, the operation is ignored; if so, the information is recorded in the object's metadata to ensure that the object is in the dynamic random access memory during the young generation garbage collection step.
[0077] The object allocation step, the young generation garbage collection step, and the full-heap garbage collection step all occur during the application runtime process.
[0078] The specific operation process of a heterogeneous memory-friendly Java garbage collector includes four steps: Java heap initialization, Java object allocation and monitoring, young generation garbage collection, and full heap garbage collection.
[0079] The specific steps of this invention are as follows:
[0080] Step S1: The user runs the Java application and specifies the parameters. The Java Virtual Machine starts and initializes the garbage collector according to the parameters specified by the user. This invention will map a part of the old generation space to non-volatile memory and the rest to dynamic random access memory according to the configuration.
[0081] Step S2: Java applications allocate new objects or read and modify existing objects at runtime. This invention helps applications allocate space for objects in the young generation and also monitors modifications to the observed space.
[0082] Step S3: When the allocatable space in the young generation of the Java heap is insufficient, a young generation garbage collection is performed. The garbage collector marks all live objects in the young generation and moves objects in the observation space to the corresponding old generation space based on their recorded write tendency. Simultaneously, the garbage collector also moves objects from the young generation that are not in the observation space to the observation space to ensure sufficient space for subsequent object allocation. Similarly, when the allocatable space in one partition of the old generation is insufficient, the garbage collector performs a full heap garbage collection. At this time, the application temporarily stops running. The garbage collector marks all live objects in the Java heap and moves them to the corresponding areas. Objects in the observation space are moved according to their recorded write tendency; if the write tendency is low, they are moved to non-volatile memory-mapped areas, and vice versa. Objects in other areas of the young generation lack recorded data, so they are moved to DRAM-mapped areas to avoid additional performance overhead. Existing objects in the old generation are moved back to their original areas.
[0083] Step S4: When a Java program terminates, the Java Virtual Machine also terminates, the garbage collector stops working and releases all mapped memory, returning it to the operating system.
[0084] Those skilled in the art can understand this embodiment as a more specific description of Embodiment 1 and Embodiment 2.
[0085] Those skilled in the art will understand that, besides implementing the system and its various devices, modules, and units provided by this invention in the form of purely computer-readable program code, the same functions can be achieved entirely through logical programming of the method steps, making the system and its various devices, modules, and units of this invention function in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers. Therefore, the system and its various devices, modules, and units provided by this invention can be considered as a hardware component, and the devices, modules, and units included therein for implementing various functions can also be considered as structures within the hardware component; alternatively, the devices, modules, and units for implementing various functions can be considered as both software modules implementing the method and structures within the hardware component.
[0086] Specific embodiments of the present invention have been described above. It should be understood that the present invention is not limited to the specific embodiments described above, and those skilled in the art can make various changes or modifications within the scope of the claims, which do not affect the essence of the present invention. Unless otherwise specified, the embodiments and features described in this application can be arbitrarily combined with each other.
Claims
1. A garbage collection method for heterogeneous memory using a Java garbage collector, characterized in that, The method includes the following steps: Step S1: When creating the Java heap, divide the heap into the young generation and the old generation; Step S2: Reserve an observation space in the young generation of the heap and map the young generation to the dynamic random access memory; Step S3: Divide the old generation of the heap into a write-dominant region and a read-dominant region, and map the dynamic random access memory and non-volatile memory to these two regions respectively; Step S4: Place objects created during application runtime into the young generation, and use write barriers to record objects in the observation space to determine their write operation tendencies; Step S5: When the young generation space is insufficient, perform a young generation garbage collection, that is, scan the young generation and move all live objects to the corresponding area according to their survival time and the tendency to perform write operations. Among them, objects that are mainly write operations should be moved to the write-dominant area of the old generation, and the rest of the objects should be moved to the read-dominant area of the old generation. Step S6: When there is insufficient space in one of the regions of the old generation, scan all live objects in the heap and compress the write-dominated region and the read-dominated region of the old generation, and transfer the objects of the young generation to the write-dominated region of the old generation.
2. The garbage collection method for heterogeneous memory using a Java garbage collector according to claim 1, characterized in that, In step S2, the size of the observation space is adjusted by the user, and the size of the observation space is 1 / 10 of the total size of the young generation.
3. The garbage collection method for heterogeneous memory using a Java garbage collector according to claim 1, characterized in that, In step S3, the ratio of the younger generation to the older generation is set by the user according to their own configuration, and the preset ratio of the younger generation to the older generation is 1:
2.
4. The garbage collection method for heterogeneous memory using a Java garbage collector according to claim 1, characterized in that, In step S5, the promotion threshold for an object in the young generation is set by the user. The preset promotion threshold for an object in the young generation is that it has undergone one young generation garbage collection.
5. A garbage collection system for a Java garbage collector in heterogeneous memory, characterized in that, The system includes the following modules: Module M1: Divides the Java heap into young generation and old generation when creating the heap; Module M2: Reserves an observation space in the young generation of the heap and maps the young generation to dynamic random access memory; Module M3: Divides the old generation of the heap into a write-oriented region and a read-oriented region, and maps dynamic random access memory and non-volatile memory to these two regions respectively; Module M4: Places objects created during application runtime into the young generation and uses write barriers to record objects in the observation space to determine their write operation tendencies; Module M5: When the young generation space is insufficient, perform a young generation garbage collection, that is, scan the young generation and move all live objects to the corresponding area according to their survival time and the tendency to perform write operations. Among them, objects that are mainly write operations should be moved to the write-dominant area of the old generation, and the rest of the objects should be moved to the read-dominant area of the old generation. Module M6: When there is insufficient space in one of the old generation regions, scan all live objects in the heap and compress the write-dominated region and read-dominated region of the old generation, and move the young generation objects to the write-dominated region of the old generation.
6. The garbage collection system for heterogeneous memory Java garbage collector according to claim 5, characterized in that, The size of the observation space in module M2 is adjustable by the user, and the size of the observation space is 1 / 10 of the total size of the young generation.
7. The garbage collection system for heterogeneous memory Java garbage collector according to claim 5, characterized in that, The ratio of the young generation to the old generation in module M3 is set by the user according to their own configuration, and the preset ratio of the young generation to the old generation is 1:
2.
8. The garbage collection system for heterogeneous memory Java garbage collector according to claim 5, characterized in that, In module M5, the promotion threshold for objects in the young generation is set by the user. The preset promotion threshold for objects in the young generation is that objects that have undergone one young generation garbage collection are promoted.
9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the garbage collection method of the Java garbage collector for heterogeneous memory as described in any one of claims 1 to 4.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the computer program is executed by a processor, it implements the steps of the garbage collection method of the Java garbage collector for heterogeneous memory as described in any one of claims 1 to 4.