A method and device for accessing Java objects
By detecting garbage collection in the Java heap and updating the memory address, the direct memory access error problem caused by Java heap memory recycling is solved, and efficient Java object access is achieved.
Patent Information
- Application Number
- CN202111122033.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-24
- Publication Date
- 2024-11-05
- Estimated Expiration
- 2041-09-24
AI Technical Summary
When the Java heap is memory management, the memory address of the Java object changes due to the garbage collection mechanism, causing the direct memory to access the wrong content.
When the target hardware accesses the target Java object in the Java heap directly in the memory, it saves the status information when it is detected that it is about to start reclaiming memory and stops access. When the recycling is over, it obtains a new memory address to update the hardware access, ensuring the accuracy of the access.
It is compatible with Java heap memory recycling and direct memory access, avoiding access to wrong content due to garbage collection, improving performance and reducing copy impact.
Smart Images

Figure CN113900743B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of memory technology, and in particular to a method and device for accessing a Java object. Background Art
[0002] In some scenarios, direct memory access (DMA) is required to Java objects stored in the Java heap (the area where Java objects are stored). Since the Java heap has a garbage collection mechanism (GC, GarbageCollection), which is mainly used for memory management of the Java heap, Java objects may be moved when managing the memory of the Java heap, thereby increasing continuous free memory. However, this will cause the memory address of the same Java object to change, which will lead to direct memory access to incorrect content. Summary of the invention
[0003] In view of the above problems, a method and device for accessing a Java object is proposed to overcome the above problems or at least partially solve the above problems, including:
[0004] A method for accessing a Java object, the method comprising:
[0005] During the process of target hardware directly accessing the target Java object in the Java heap, when it is detected that memory is about to be reclaimed in the Java heap, the state information of the target Java object is saved, and the target hardware is controlled to stop directly accessing the target Java object;
[0006] When it is detected that the Java heap memory reclaiming ends, if the memory address of the target Java object changes, a new memory address is obtained according to the state information, and the new memory address is sent to the target hardware, so that the target hardware directly accesses the target Java object through the new memory address.
[0007] Optionally, it also includes:
[0008] When it is detected that memory reclaiming in the Java heap is about to begin, the target hardware is controlled to stop saving the access record of the target Java object, so that the target hardware directly accesses the target Java object through the new memory address and the access record when the Java heap memory reclaiming ends.
[0009] Optionally, it also includes:
[0010] Register the first preset event;
[0011] When it is detected that memory is about to be reclaimed in the Java heap, saving the state information of the target Java object includes:
[0012] When detecting that memory is about to be reclaimed in the Java heap, triggering the first preset event;
[0013] In response to triggering of the first preset event, the state information of the target Java object is saved.
[0014] Optionally, it also includes:
[0015] Register the second preset event;
[0016] When it is detected that the memory reclaiming of the Java heap ends, if the memory address of the target Java object changes, obtaining a new memory address according to the state information includes:
[0017] When it is detected that the Java heap memory is finished being reclaimed, the second preset event is triggered;
[0018] In response to the triggering of the second preset event, if the memory address of the target Java object changes, a new memory address is obtained according to the state information.
[0019] Optionally, the target Java object is an object of a remote procedure call.
[0020] Optionally, the state information includes reference information of the target Java object itself.
[0021] Optionally, the access record includes byte information of the target Java object that has been directly accessed by the memory.
[0022] A device for accessing a Java object, the device comprising:
[0023] A status information saving and access stopping module is used to save the status information of the target Java object and control the target hardware to stop direct memory access to the target Java object when it is detected that memory is about to be reclaimed in the Java heap during the process of the target hardware directly accessing the target Java object in the Java heap;
[0024] A new memory address sending module is used to obtain a new memory address according to the status information when it is detected that the memory address of the target Java object has changed when the Java heap memory is reclaimed, and send the new memory address to the target hardware, so that the target hardware can directly access the target Java object through the new memory address.
[0025] An electronic device comprises a processor, a memory and a computer program stored in the memory and capable of running on the processor, wherein the computer program implements the Java object access method as described above when executed by the processor.
[0026] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for accessing a Java object as described above is implemented.
[0027] The embodiments of the present invention have the following advantages:
[0028] In an embodiment of the present invention, during the process of target hardware directly accessing the target Java object in the Java heap through memory, when it is detected that memory reclaim in the Java heap is about to begin, the state information of the target Java object is saved; when it is detected that the memory address of the target Java object has changed at the end of Java heap memory reclaim, a new memory address is obtained according to the state information, and the new memory address is sent to the target hardware. The target hardware can then directly access the target Java object through the new memory address, thereby achieving compatibility between Java heap memory reclaim and direct memory access, and avoiding direct memory access to erroneous content during Java heap memory reclaim. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] In order to more clearly illustrate the technical solution of the present invention, the accompanying drawings required for use in the description of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0030] Figure 1 is a schematic diagram of a Java object access instance provided by an embodiment of the present invention;
[0031] Figure 2 It is a flowchart of a method for accessing a Java object provided by an embodiment of the present invention;
[0032] Figure 3 is a schematic diagram of another Java object access instance provided by an embodiment of the present invention;
[0033] Figure 4 is a flowchart of another method for accessing a Java object provided by an embodiment of the present invention;
[0034] Figure 5 is a flowchart of another method for accessing a Java object provided by an embodiment of the present invention;
[0035] Figure 6 The present invention is a structural block diagram of a Java object access device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0036] In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0037] In some scenarios, it is necessary to access Java objects in the Java heap through hardware direct memory to improve access performance. For example, for Java distributed applications and big data applications, their programs run on multiple machines, and the machines need to communicate with each other through the network to exchange data. The network communication process often requires the use of remote procedure calls (RPC, Remote Procedure Call), and remote procedure calls to Java objects usually need to be serialized into byte streams before being transmitted on the network.
[0038] In order to improve the performance of remote procedure calls, Java objects can be directly transmitted over the network without serialization, thereby achieving better performance in terms of latency and throughput. Specifically, it can be combined with hardware such as smart network cards to directly access Java objects in the Java heap through hardware such as smart network cards, and then send them through high-performance networks, such as RDMA (Remote Direct Memory Access) networks.
[0039] Of course, the embodiments of the present invention are not limited to the scenario of using remote procedure call, but can also be applied to other scenarios requiring direct memory access.
[0040] During direct memory access, since the Java heap has a garbage collection mechanism (GC, GarbageCollection), which is mainly used for memory management of the Java heap, Java objects will be moved when the Java heap is managed, thereby increasing continuous free memory. However, this will cause the memory address of the same Java object to change, which will lead to direct memory access to incorrect content.
[0041] In one solution, the Java heap is divided into several heap memory partitions (Regions), such as Figure 1The Java heap is divided into region 1 to region-n. The minimum granularity of garbage collection is the heap memory partition. Java objects are also stored in the heap memory partition. At the same time, a pin mechanism is provided. After a heap memory partition is pinned, the garbage collection mechanism will skip the heap memory partition during garbage collection, and will not perform garbage collection and memory compaction on the heap memory partition. That is, the memory address of the Java object in the heap memory partition will not change.
[0042] Based on this, Figure 1 , the hardware can determine the heap memory partition where a Java object is located before direct memory access, and then use the pin mechanism to process the heap memory partition. Even if the garbage collection mechanism is triggered, the Java object can be directly accessed by memory. However, since the complete memory of a Java object may exist discretely in the Java heap, that is, all the memory of a Java object may exist in multiple heap memory partitions, pinning multiple heap memory partitions will pin the entire Java heap in the worst case, which will result in the garbage collection mechanism having no memory to reclaim.
[0043] In another solution, since the Java heap memory is managed by the garbage collection mechanism, but the Java off-heap memory is not managed by the garbage collection mechanism, the Java objects in the heap can be copied to the off-heap first, and then the off-heap memory can be used for direct memory access. However, this method requires a large number of copies, which has a greater impact on performance.
[0044] In an embodiment of the present invention, during the process of target hardware directly accessing the target Java object in the Java heap through memory, when it is detected that memory reclaim in the Java heap is about to begin, the state information of the target Java object is saved. When it is detected that the memory reclaim in the Java heap ends, if the memory address of the target Java object changes, a new memory address is obtained according to the state information and sent to the target hardware. The target hardware can then directly access the target Java object through the new memory address, thereby achieving compatibility between Java heap memory reclaim and direct memory access, and avoiding direct memory access to erroneous content during Java heap memory reclaim.
[0045] Specifically, on the one hand, the embodiment of the present invention does not affect the original process of Java heap memory recovery, and will not cause a low memory recovery rate or even no memory to be recovered due to the use of the pin mechanism. On the other hand, the embodiment of the present invention can perform direct memory access in the case of zero copy of Java objects, has good performance, and avoids the impact of a large number of copies on performance.
[0046] The following is a detailed description:
[0047] Reference Figure 2 , shows a flowchart of a method for accessing a Java object provided by an embodiment of the present invention, which may specifically include the following steps:
[0048] Step 201, during the process of target hardware directly accessing a target Java object in a Java heap, when it is detected that memory is about to be reclaimed in the Java heap, the state information of the target Java object is saved, and the target hardware is controlled to stop directly accessing the target Java object.
[0049] The target Java object may be an object of a remote procedure call, for example, the target Java object may be an object of a remote procedure call of a Java distributed application or a big data application.
[0050] In some scenarios, such as Java distributed applications and big data applications, it is necessary to directly access the target Java object in the Java heap through CPU peripheral hardware such as smart network cards.
[0051] In order to avoid direct memory access to erroneous content due to the garbage collection mechanism, during the process of target hardware directly accessing the target Java object in the Java heap, that is, the target hardware is performing direct memory access to the target Java object in the Java heap, when it is detected that memory reclaiming in the Java heap is about to begin, the state information of the target Java object can be saved. The state information may include the reference information of the target Java object itself. The reference information can be used to point to the location of the target Java object in the memory. When the target Java object needs to be used, its own reference information needs to be called.
[0052] Furthermore, in order to avoid accessing erroneous content due to continued direct memory access, when it is detected that memory is about to be reclaimed in the Java heap, a notification message may be sent to the target hardware to notify the target hardware to stop direct memory access to the target Java object.
[0053] In an embodiment of the present invention, the following step may also be included: registering a first preset event.
[0054] In an embodiment of the present invention, step 201 may include the following steps:
[0055] When it is detected that memory is about to be reclaimed in the Java heap, a first preset event is triggered; in response to the triggering of the first preset event, the state information of the target Java object is saved.
[0056] In order to know the time to start garbage collection, a first preset event can be pre-registered. Specifically, the debugging and analysis interface (JVMTI, Java Virtual Machine Tool Interface) in the Java virtual machine (JVM, Java Virtual Machine) can be used, which can provide an event mechanism.
[0057] Since the use of the debugging and analysis interface requires a debugging and analysis interface agent (JVMTI Agent), all debugging and analysis interface uses are performed in the debugging and analysis interface agent, including event registration, event processing, etc., then the GC START event can be registered in the debugging and analysis interface in the debugging and analysis interface agent, and the GC START event is the first preset event.
[0058] When it is detected that memory is about to be reclaimed in the Java heap and garbage collection is about to start, a first preset event can be triggered. The debugging and analysis interface agent can receive the first preset event and then save the status information of the target Java object. Since the debugging and analysis interface is a function supported by all Java virtual machines, its universal applicability is improved.
[0059] Step 202, when it is detected that the memory address of the target Java object has changed when the Java heap memory is reclaimed, a new memory address is obtained according to the state information, and the new memory address is sent to the target hardware, so that the target hardware directly accesses the target Java object through the new memory address.
[0060] Since the Java object currently being directly accessed by the memory may be moved (i.e., the memory address has changed) when the Java virtual machine performs garbage collection, thereby increasing the continuous free memory, the new memory address can be mapped through the reference information of the saved Java object.
[0061] Based on this, when it is detected that the Java heap memory reclaiming ends, if the memory address of the target Java object changes, that is, the target Java object is moved, the new memory address of the target Java object can be obtained according to the state information (such as reference information).
[0062] After obtaining the new memory address of the target Java object, the new memory address can be notified to the direct memory access unit in the target hardware. After receiving the notification, the direct memory access unit in the target hardware can update the memory address for the target Java object, and then the new address can be used to directly access the target Java object.
[0063] In one embodiment of the present invention, the following steps may also be included: registering a second preset event;
[0064] In one embodiment of the present invention, when it is detected that the memory address of the target Java object changes when the Java heap memory is reclaimed, the new memory address is obtained according to the state information, which may include the following steps:
[0065] When it is detected that the Java heap memory reclaiming ends, a second preset event is triggered; in response to the triggering of the second preset event, if the memory address of the target Java object changes, a new memory address is obtained according to the state information.
[0066] In order to know the timing of the end of garbage collection, a second preset event may be pre-registered. Specifically, the debugging and analysis interface in the Java virtual machine may be used, which may provide an event mechanism.
[0067] Since the use of the debugging and analysis interface requires a debugging and analysis interface agent, all debugging and analysis interface uses are performed in the debugging and analysis interface agent, including event registration, event processing, etc., the GC STOP event can be registered in the debugging and analysis interface in the debugging and analysis interface agent. The GC STOP event is the second preset event.
[0068] When it is detected that memory is about to be reclaimed in the Java heap, that is, garbage collection is about to start, a second preset event can be triggered, and the debugging and analysis interface agent can receive the second preset event and obtain the new memory address of the target Java object based on the status information (such as reference information).
[0069] In one embodiment of the present invention, the following steps may also be included:
[0070] When it is detected that memory is about to be reclaimed in the Java heap, the target hardware is controlled to save the access record of the target Java object, so that the target hardware directly accesses the target Java object through the new memory address and access record when the Java heap memory is reclaimed.
[0071] Since a Java object occupies multiple bytes of memory, the hardware may not access the memory it occupies all at once, but may access it multiple times. In the process of multiple accesses, when memory recycling occurs, the target hardware can record the size of the memory it has accessed, that is, save the access record of the target Java object. The access record may include the byte information of the target Java object that has been directly accessed by the memory.
[0072] When it is detected that the Java heap memory reclaiming process has ended, if the memory address of the target Java object has changed, the direct memory access unit in the target hardware can find the storage location of the target Java object through the new memory address, and then skip the previously accessed location through the access record and directly access the unaccessed location.
[0073] For example, Java object A is 32 bytes in size and is being accessed by direct memory. Before garbage collection, the reference information of Java object A is saved, the hardware direct memory access is stopped, and the number of bytes currently accessed is saved (20 bytes have been accessed and 12 bytes have not been accessed).
[0074] After garbage collection is completed, the new object address of Java object A can be obtained through reference, and the new memory address can be notified to the hardware. After the hardware obtains the new memory address, it can skip the previously accessed 20 bytes and access the remaining 12 bytes based on the number of bytes currently accessed.
[0075] In an embodiment of the present invention, during the process of target hardware directly accessing the target Java object in the Java heap, when it is detected that memory recovery in the Java heap is about to begin, the state information of the target Java object is saved and the target hardware is controlled to stop direct memory access to the target Java object; when it is detected that at the end of Java heap memory recovery, if the memory address of the target Java object changes, a new memory address is obtained according to the state information, and the new memory address is sent to the target hardware, and the target hardware can then directly access the target Java object through the new memory address, thereby achieving compatibility between Java heap memory recovery and direct memory access, and avoiding direct memory access to erroneous content during Java heap memory recovery.
[0076] The following combination Figure 3 The present invention is exemplified;
[0077] exist Figure 3 In JVM, JVM provides Java heap and JVMTI. Java objects are stored in Java heap. JVMTI is used through JVMTIAgent and communicates with the hardware DMA unit. The hardware DMA unit directly accesses Java objects in Java heap.
[0078] 1. Register events with JVMTI through JVMTI Agent;
[0079] 2. Before the GC unit starts garbage collection, the GC Start event in JVMTI can be triggered;
[0080] 3. JVMTI can send a notification of garbage collection start (GC Start Notify) to the JVMTI Agent, and the JVMTIAgent can retain the reference of the Java object being DMAed;
[0081] 4. JVMTI Agent can notify the hardware DMA unit to stop DMA and save the DMA state;
[0082] 5. The GC unit can perform garbage collection on Java objects in the Java heap;
[0083] 6. After garbage collection is completed, the GC unit can trigger a GC Stop event;
[0084] 7. When JVMTI detects the GC Stop event, it can send a message (GCStop Notify) about the completion of garbage collection to the JVMTI Agent. The JVMTI Agent can obtain the new address of the Java object through reference.
[0085] 8. JVMTI Agent can pass the new object address through the hardware DMA unit and continue DMA.
[0086] Reference Figure 4 , shows a flowchart of another method for accessing a Java object provided by an embodiment of the present invention, which may specifically include the following steps:
[0087] Step 401, during the process of target hardware directly accessing the target Java object in the Java heap, when it is detected that memory is about to be reclaimed in the Java heap, the state information of the target Java object is saved, and the target hardware is controlled to stop directly accessing the target Java object and save the access record of the target Java object.
[0088] The target Java object may be an object of a remote procedure call, for example, the target Java object may be an object of a remote procedure call of a Java distributed application or a big data application.
[0089] In some scenarios, such as Java distributed applications and big data applications, it is necessary to directly access the target Java object in the Java heap through CPU peripheral hardware such as smart network cards.
[0090] In order to avoid direct memory access to erroneous content due to the garbage collection mechanism, during the process of target hardware directly accessing the target Java object in the Java heap, that is, the target hardware is performing direct memory access to the target Java object in the Java heap, when it is detected that memory reclaiming in the Java heap is about to begin, the state information of the target Java object can be saved. The state information may include the reference information of the target Java object itself. The reference information can be used to point to the location of the target Java object in the memory. When the target Java object needs to be used, its own reference information needs to be called.
[0091] Furthermore, in order to avoid accessing erroneous content due to continued direct memory access, when it is detected that memory is about to be reclaimed in the Java heap, a notification message may be sent to the target hardware to notify the target hardware to stop direct memory access to the target Java object.
[0092] Since a Java object occupies multiple bytes of memory, the hardware may not access the memory it occupies all at once, but may access it multiple times. In the process of multiple accesses, when memory recycling occurs, the target hardware can record the size of the memory it has accessed, that is, save the access record of the target Java object. The access record may include the byte information of the target Java object that has been directly accessed by the memory.
[0093] Step 402, when it is detected that when the Java heap memory is reclaimed, if the memory address of the target Java object changes, a new memory address is obtained according to the state information, and the new memory address is sent to the target hardware, so that the target hardware directly accesses the target Java object through the new memory address and access record.
[0094] Since the Java object currently being directly accessed by the memory may be moved (i.e., the memory address has changed) when the Java virtual machine performs garbage collection, thereby increasing the continuous free memory, the new memory address can be mapped through the reference information of the saved Java object.
[0095] Based on this, when it is detected that the Java heap memory reclaiming ends, if the memory address of the target Java object changes, that is, the target Java object is moved, the new memory address of the target Java object can be obtained according to the state information (such as reference information).
[0096] After obtaining the new memory address of the target Java object, the new memory address can be notified to the direct memory access unit in the target hardware. After receiving the notification, the direct memory access unit in the target hardware can find the storage location of the target Java object through the new memory address, and then skip the previously accessed location through the access record and directly access the unaccessed location.
[0097] For example, Java object A is 32 bytes in size and is being accessed by direct memory. Before garbage collection, the reference information of Java object A is saved, the hardware direct memory access is stopped, and the number of bytes currently accessed is saved (20 bytes have been accessed and 12 bytes have not been accessed).
[0098] After garbage collection is completed, the new object address of Java object A can be obtained through reference, and the new memory address can be notified to the hardware. After the hardware obtains the new memory address, it can skip the previously accessed 20 bytes and access the remaining 12 bytes based on the number of bytes currently accessed.
[0099] Reference Figure 5 , shows a flowchart of another method for accessing a Java object provided by an embodiment of the present invention, which may specifically include the following steps:
[0100] Step 501: register a first preset event and a second preset event.
[0101] In order to know the start and end timing of garbage collection, the first preset event and the second preset event may be pre-registered. Specifically, the debugging and analysis interface in the Java virtual machine may be used, which may provide an event mechanism.
[0102] Since the use of the debugging and analysis interface requires a debugging and analysis interface agent, all debugging and analysis interface uses are performed in the debugging and analysis interface agent, including event registration, event processing, etc., then the GC START event can be registered in the debugging and analysis interface in the debugging and analysis interface agent, and the GC START event is the first preset event, and the GC STOP event can be registered in the debugging and analysis interface in the debugging and analysis interface agent, and the GC STOP event is the second preset event.
[0103] Step 502 : During the process of target hardware directly accessing a target Java object in a Java heap, when it is detected that memory is about to be reclaimed in the Java heap, a first preset event is triggered.
[0104] The target Java object may be an object of a remote procedure call, for example, the target Java object may be an object of a remote procedure call of a Java distributed application or a big data application.
[0105] In some scenarios, such as Java distributed applications and big data applications, it is necessary to directly access the target Java object in the Java heap through CPU peripheral hardware such as smart network cards.
[0106] In order to avoid direct memory access to erroneous content due to the garbage collection mechanism, during the process of target hardware directly accessing the target Java object in the Java heap, that is, the target hardware is performing direct memory access to the target Java object in the Java heap, when it is detected that memory is about to be reclaimed in the Java heap and garbage collection is about to start, a first preset event can be triggered. Since the debugging and analysis interface is a function supported by all Java virtual machines, the universal applicability is improved.
[0107] Step 503: In response to the triggering of the first preset event, save the state information of the target Java object, control the target hardware to stop direct memory access to the target Java object and save the access record of the target Java object.
[0108] When the debugging and analysis interface agent receives the first preset event, the state information of the target Java object can be saved. The state information may include the reference information of the target Java object itself. The reference information can be used to point to the location of the target Java object in the memory. When the target Java object needs to be used, its own reference information needs to be called.
[0109] Furthermore, when the debugging and analysis interface agent receives the first preset event, it may send a notification message to the target hardware to notify the target hardware to stop directly accessing the target Java object through the memory.
[0110] Since a Java object occupies multiple bytes of memory, the hardware may not access the memory it occupies all at once, but may access it multiple times. In the process of multiple accesses, when memory recycling occurs, the target hardware can record the size of the memory it has accessed, that is, save the access record of the target Java object. The access record may include the byte information of the target Java object that has been directly accessed by the memory.
[0111] Step 504: When it is detected that the Java heap memory is reclaimed, a second preset event is triggered.
[0112] When it is detected that memory is about to be reclaimed in the Java heap, that is, garbage collection is about to start, a second preset event may be triggered.
[0113] Step 505, in response to the triggering of the second preset event, if the memory address of the target Java object changes, a new memory address is obtained according to the state information, and the new memory address is sent to the target hardware, so that the target hardware directly accesses the target Java object through the new memory address and access record.
[0114] Since the Java object currently being directly accessed by the memory may be moved (i.e., the memory address has changed) when the Java virtual machine performs garbage collection, thereby increasing the continuous free memory, the new memory address can be mapped through the reference information of the saved Java object.
[0115] Based on this, when the debugging and analysis interface agent can receive the second preset event, if the memory address of the target Java object changes, that is, the target Java object is moved, the new memory address of the target Java object can be obtained according to the state information (such as reference information).
[0116] After obtaining the new memory address of the target Java object, the new memory address can be notified to the direct memory access unit in the target hardware. After receiving the notification, the direct memory access unit in the target hardware can find the storage location of the target Java object through the new memory address, and then skip the previously accessed location through the access record and directly access the unaccessed location.
[0117] For example, Java object A is 32 bytes in size and is being accessed by direct memory. Before garbage collection, the reference information of Java object A is saved, the hardware direct memory access is stopped, and the number of bytes currently accessed is saved (20 bytes have been accessed and 12 bytes have not been accessed).
[0118] After garbage collection is completed, the new object address of Java object A can be obtained through reference, and the new memory address can be notified to the hardware. After the hardware obtains the new memory address, it can skip the previously accessed 20 bytes and access the remaining 12 bytes based on the number of bytes currently accessed.
[0119] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.
[0120] Reference Figure 6, shows a schematic diagram of the structure of a Java object access device provided by an embodiment of the present invention, which may specifically include the following modules:
[0121] The state information saving and access stopping module 601 is used to save the state information of the target Java object and control the target hardware to stop directly accessing the target Java object in the Java heap when it is detected that memory is about to be reclaimed in the Java heap during the process of the target hardware directly accessing the target Java object in the Java heap;
[0122] The new memory address sending module 602 is used to obtain a new memory address according to the status information when it is detected that the memory address of the target Java object has changed when the Java heap memory is reclaimed, and send the new memory address to the target hardware so that the target hardware can directly access the target Java object through the new memory address.
[0123] In one embodiment of the present invention, the method may further include:
[0124] The access record saving module is used to control the target hardware to save the access record of the target Java object when it is detected that the memory is about to be reclaimed in the Java heap, so that the target hardware can directly access the target Java object through the new memory address and access record when the Java heap memory is reclaimed.
[0125] In one embodiment of the present invention, the method may further include:
[0126] The first preset event registration module is used to register a first preset event.
[0127] The state information saving module 601 may include:
[0128] The first preset event triggering submodule is used to trigger a first preset event when it is detected that memory is about to be reclaimed in the Java heap.
[0129] The first preset event response submodule is used to save the state information of the target Java object in response to the triggering of the first preset event.
[0130] In one embodiment of the present invention, the method may further include:
[0131] The second preset event registration module is used to register the second preset event.
[0132] The new memory address sending module 602 may include:
[0133] The second preset event triggering submodule is used to trigger the second preset event when it is detected that the Java heap memory reclaiming ends.
[0134] The second preset event response submodule is used to respond to the triggering of the second preset event and, if the memory address of the target Java object changes, obtain a new memory address according to the state information.
[0135] In one embodiment of the present invention, the target Java object may be an object of a remote procedure call.
[0136] In one embodiment of the present invention, the state information may include reference information of the target Java object itself.
[0137] In one embodiment of the present invention, the access record may include byte information of the target Java object that has been directly accessed by the memory.
[0138] In an embodiment of the present invention, during the process of target hardware directly accessing the target Java object in the Java heap, when it is detected that memory recovery in the Java heap is about to begin, the state information of the target Java object is saved and the target hardware is controlled to stop direct memory access to the target Java object; when it is detected that at the end of Java heap memory recovery, if the memory address of the target Java object changes, a new memory address is obtained according to the state information, and the new memory address is sent to the target hardware, and the target hardware can then directly access the target Java object through the new memory address, thereby achieving compatibility between Java heap memory recovery and direct memory access, and avoiding direct memory access to erroneous content during Java heap memory recovery.
[0139] An embodiment of the present invention further provides an electronic device, which may include a processor, a memory, and a computer program stored in the memory and capable of running on the processor, and when the computer program is executed by the processor, the above Java object access method is implemented.
[0140] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method for accessing a Java object as described above is implemented.
[0141] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0142] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0143] Those skilled in the art will appreciate that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0144] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0145] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0146] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0147] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0148] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0149] The above is a detailed introduction to a method and device for accessing a Java object. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A method for accessing a Java object, characterized in that: The method comprises: In the process of target hardware directly accessing a target Java object in a Java heap, when it is detected that memory is about to be reclaimed in the Java heap, in response to the triggering of a first preset event, state information of the target Java object is saved, and the target hardware is controlled to stop directly accessing the target Java object; the state information includes reference information of the target Java object itself; When it is detected that the Java heap memory reclaiming ends, in response to the triggering of a second preset event, if the memory address of the target Java object changes, a new memory address is obtained according to the status information, and the new memory address is sent to the target hardware, so that the target hardware directly accesses the target Java object through the new memory address.
2. The method according to claim 1, characterized in that Also includes: When it is detected that memory reclaiming in the Java heap is about to begin, the target hardware is controlled to stop saving the access record of the target Java object, so that the target hardware directly accesses the target Java object through the new memory address and the access record when the Java heap memory reclaiming ends.
3. The method according to claim 1 or 2, characterized in that: Also includes: Register the first preset event; When it is detected that memory is about to be reclaimed in the Java heap, saving the state information of the target Java object includes: When detecting that memory is about to be reclaimed in the Java heap, triggering the first preset event; In response to triggering of the first preset event, the state information of the target Java object is saved.
4. The method according to claim 3, characterized in that Also includes: Register the second preset event; When it is detected that the memory reclaiming of the Java heap ends, if the memory address of the target Java object changes, obtaining a new memory address according to the state information includes: When it is detected that the Java heap memory is finished being reclaimed, the second preset event is triggered; In response to the triggering of the second preset event, if the memory address of the target Java object changes, a new memory address is obtained according to the state information.
5. The method according to claim 1, characterized in that The target Java object is the object of the remote procedure call.
6. The method according to claim 2, characterized in that The access record includes byte information of the target Java object that has been directly accessed by memory.
7. A device for accessing a Java object, characterized in that: The device comprises: A state information saving and access stopping module is used to save the state information of the target Java object and control the target hardware to stop direct memory access to the target Java object in the Java heap when it is detected that memory is about to be reclaimed in the Java heap during the process of the target hardware directly accessing the target Java object in the Java heap in response to the triggering of a first preset event; the state information includes reference information of the target Java object itself; A new memory address sending module is used to, when it is detected that the Java heap memory reclaiming ends, respond to the triggering of a second preset event, if the memory address of the target Java object changes, obtain a new memory address according to the status information, and send the new memory address to the target hardware, so that the target hardware directly accesses the target Java object through the new memory address.
8. An electronic device, characterized in that: The invention comprises a processor, a memory and a computer program stored in the memory and capable of running on the processor, wherein the computer program implements the Java object access method according to any one of claims 1 to 6 when executed by the processor.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for accessing a Java object according to any one of claims 1 to 6 is implemented.
