A cache management method, system, electronic device and storage medium

By extending an unmanageable first heap memory within the Java Virtual Machine's memory space, the memory manager skips objects in the first heap memory during scanning, solving the high performance overhead caused by frequent cleanup by the Java Virtual Machine's memory manager and achieving more efficient memory management.

CN115237539BActive Publication Date: 2026-01-13ALIBABA (CHINA) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210891801.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-27
Publication Date
2026-01-13
Estimated Expiration
2042-07-27

AI Technical Summary

Technical Problem

The Java Virtual Machine's memory manager frequently triggers memory cleanup events when cleaning up heap memory, resulting in high performance overhead and application thread pauses, especially when using off-heap caching.

Method used

An additional heap memory, which is not managed by the memory manager, is extended in the Java Virtual Machine's memory space. This allows the memory manager to skip objects in the first heap memory during scanning and directly determine the objects referenced by the root object as valid, thus reducing the number of scan traversals.

Benefits of technology

It reduces the frequency of memory cleanup events, shortens memory cleanup time, reduces the workload of the memory manager, and reduces performance overhead and the impact of application thread pauses.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115237539B_ABST
    Figure CN115237539B_ABST
Patent Text Reader

Abstract

The embodiment of the present specification provides a cache management method, comprising: in response to a triggered memory cleaning event, a memory manager of a Java virtual machine performs scanning processing on an object referenced by a root object of the Java virtual machine; wherein the scanning processing comprises: determining the in-heap memory used for caching the first object referenced by the root object; if the first object referenced by the root object is cached in the first in-heap memory which is not managed by the memory manager, skipping the scanning process for the first in-heap memory, and determining the first object as a valid state; the memory manager of the Java virtual machine determines the object in an invalid state cached in the memory space of the Java virtual machine, and cleans the object in the invalid state. In the above process, the frequency of triggering the memory cleaning event can be reduced, and the duration of memory cleaning can be shortened, thereby effectively reducing the performance overhead during memory management, and weakening the adverse effects caused by the application thread pause due to memory cleaning.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present specification relates to the technical field of cache, and in particular, to a cache management method and system, an electronic device, and a storage medium. BACKGROUND

[0002] A Java Virtual Machine (JVM) is an abstract computer that runs all Java programs and is the runtime environment of the Java language. The JVM can apply a region in the memory to be automatically managed by the JVM to meet the space requirements of object allocation of an application program, and this region of memory is called a heap.

[0003] During the running of a certain thread, if there is a new method call, a new object will be created in the heap, but after the end of the method call, the object will continue to exist in the heap. Therefore, if new objects are continuously created, the memory space will eventually be exhausted.

[0004] In order to solve the above problem, Java provides a built-in memory manager to automatically empty the objects in the heap that are no longer used. The memory manager can scan the space in the heap, identify the objects that are no longer used by the application program, and release the space thereof, and this process is called garbage collection (GC). SUMMARY

[0005] Therefore, one or more embodiments of the present specification provide a cache management method and system, an electronic device, and a storage medium to solve the problems in the related art.

[0006] To achieve the above object, one or more embodiments of the present specification provide the technical solutions as follows.

[0007] According to a first aspect of an embodiment of the present specification, a cache management method is provided, applied to a Java virtual machine, and a memory space of the Java virtual machine includes an extended first in-heap memory; the method comprises:

[0008] In response to a triggered memory cleaning event, a memory manager of the Java virtual machine performs scanning processing on objects referenced by root objects of the Java virtual machine to determine the state of the cached objects in the memory space of the Java virtual machine; wherein the scanning processing comprises: determining the in-heap memory for caching the first objects referenced by the root objects; if the first objects referenced by the root objects are cached in the first in-heap memory that is not managed by the memory manager, skipping the scanning process for the first in-heap memory, and determining the first objects as valid state.

[0009] The memory manager of the Java virtual machine determines the invalid state objects cached in the memory space of the Java virtual machine, and cleans up the invalid state objects.

[0010] According to a second aspect of the embodiments of the present specification, a cache management system is provided, comprising:

[0011] A Java virtual machine, the memory space of the Java virtual machine comprising an extended first heap memory;

[0012] The first heap memory is a heap memory that is not manageable by the memory manager of the Java virtual machine;

[0013] The memory manager of the Java virtual machine is configured to, in response to a triggered memory cleaning event, perform scanning processing on objects referenced by root objects of the Java virtual machine to determine the state of the cached objects in the memory space of the Java virtual machine; wherein the scanning processing comprises: determining the heap memory used to cache the first objects referenced by the root objects; if the first objects referenced by the root objects are cached in the first heap memory that is not manageable by the memory manager, skipping the scanning process for the first heap memory, and determining the first objects as valid state; and determining invalid state objects cached in the memory space of the Java virtual machine, and cleaning up the invalid state objects.

[0014] According to a third aspect of the embodiments of the present specification, an electronic device is provided, comprising a communication interface, a processor, a memory and a bus, the communication interface, the processor and the memory being connected to each other through the bus;

[0015] The memory stores machine readable instructions, and the processor executes the above method by invoking the machine readable instructions.

[0016] According to a fourth aspect of the embodiments of the present specification, a machine readable storage medium is provided, which stores machine readable instructions, and the machine readable instructions, when invoked and executed by a processor, implement the above method.

[0017] The technical solutions provided by the embodiments of the present specification can include the following beneficial effects:

[0018] By the above technical solution, the first in-heap memory which is not managed by the memory manager is extended in the memory space of the Java virtual machine, so that when the memory manager scans the root object reference object of the Java virtual machine, the first object cached in the first in-heap memory is directly determined as an effective state. In the above process, since the traversal of other objects cached in the first in-heap memory is skipped, the scanning process of other objects cached in the first in-heap memory is not required, so that the triggering frequency of the memory cleaning event can be reduced, and the duration of the memory cleaning can be shortened, thereby reducing the workload of the memory manager. Further, the performance overhead during memory management can be effectively reduced, and the adverse effects caused by the application thread pause due to memory cleaning can be weakened. BRIEF DESCRIPTION OF DRAWINGS

[0019] Figure 1 A flow chart of a cache management method provided for an exemplary embodiment of the present specification;

[0020] Figure 2 A schematic diagram of a scanning process provided for an exemplary embodiment of the present specification;

[0021] Figure 3 A structural schematic diagram of a cache management system provided for an exemplary embodiment of the present specification;

[0022] Figure 4 A structural schematic diagram of an electronic device in which a cache management device provided for an exemplary embodiment of the present specification is located;

[0023] Figure 5 A block diagram of a cache management device provided for an exemplary embodiment of the present specification. DETAILED DESCRIPTION

[0024] The exemplary embodiments will be described in detail herein with reference to the attached drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of the present specification. Instead, they are merely examples of apparatuses and methods consistent with some aspects of one or more embodiments of the present specification as detailed in the appended claims.

[0025] It should be noted that the steps of the respective methods are not necessarily performed in the order shown and described in this specification in other embodiments. In some other embodiments, the steps included in the methods thereof can be more or less than described in this specification. In addition, a single step described in this specification can be broken down into multiple steps for description in other embodiments; and multiple steps described in this specification can be combined into a single step for description in other embodiments.

[0026] At present, in the process of data caching, in addition to using the aforementioned in-heap caching technology, an out-of-heap caching technology can also be used. Through out-of-heap caching, the memory limit of JVM can be broken through, which is suitable for storing a large number of cache entries, and the data is stored out of the heap and can be manually managed by the user. The user can flexibly configure according to the business needs of the user.

[0027] However, compared with the objects in the Java process, since the out-of-heap cache is not part of the Java process, when using the out-of-heap cache, a cross-language interface (JNI, Java Native Interface) call must be made, and such a call will bring a considerable performance overhead, and the later maintenance is also more difficult, and the operation and maintenance cost is higher.

[0028] In addition, when the Java process uses the objects of the out-of-heap cache, serialization and deserialization must be performed, that is, binary data is converted into objects that the process can recognize, and this process also generates a performance overhead.

[0029] For example, assuming that 10w pieces of data among 100w pieces of data need to be frequently read, the 10w pieces of data can be cached. However, as known from the foregoing, the performance overhead brought by caching in the out-of-heap memory cannot be underestimated.

[0030] Therefore, in the case where the in-heap memory space allows, the 10w pieces of data can be stored in the in-heap memory, and since Java does not need to be called when using in-heap caching, the performance overhead can be reduced.

[0031] However, in actual applications, the 10w pieces of data can be hot data, and the user hopes that the hot data can always be retained in the in-heap memory. As known from the foregoing, the memory manager will automatically perform memory cleaning and recycle the useless memory space, so it is likely that the hot data will be stored in the in-heap memory again after being cleaned, resulting in unnecessary performance overhead.

[0032] Therefore, the present specification provides a technical solution for extending the first heap memory which is not managed by the memory manager in the memory space of the Java virtual machine, so that the memory manager directly determines the first object cached in the first heap memory as valid when scanning the root object reference of the Java virtual machine, thereby skipping the scanning process of the cached object in the first heap memory.

[0033] In implementation, in response to the triggered memory cleaning event, the memory manager of the Java virtual machine can perform scanning processing on the object referenced by the root object of the Java virtual machine to determine the state of the cached object in the memory space of the Java virtual machine.

[0034] For example, in response to the memory cleaning event triggered by the Java virtual machine based on the preset cleaning period timing, the memory manager of the Java virtual machine can perform scanning processing on the object referenced by the root object of the Java virtual machine to determine whether the state of the cached object in the memory space of the Java virtual machine is valid or invalid.

[0035] The scanning processing includes: determining the heap memory for caching the first object referenced by the root object; if the first object referenced by the root object is cached in the first heap memory which is not managed by the memory manager, the scanning process for the first heap memory is skipped, and the first object is determined as valid.

[0036] For example, the memory manager can perform scanning processing on the object referenced by the root object of the Java virtual machine to determine whether the heap memory for caching the first object referenced by the root object is the first heap memory which is not managed by the memory manager; if so, the scanning process for the first heap memory is skipped, and the first object is determined as valid.

[0037] The memory manager of the Java virtual machine can determine the invalid object cached in the memory space of the Java virtual machine and clean up the invalid object.

[0038] For example, after determining the valid object, other objects cached in the memory space of the Java virtual machine can be determined as invalid objects, and the invalid objects are cleaned up.

[0039] By the above technical solution, the first in-heap memory which is not manageable by the memory manager is extended in the memory space of the Java virtual machine, so that when the memory manager performs scanning processing on the objects referenced by the root objects of the Java virtual machine, the first objects cached in the first in-heap memory which are scanned are directly determined as valid states. In the above process, since the traversal of other objects cached in the first in-heap memory is skipped, the scanning processing of the other objects cached in the first in-heap memory is not required, so that the triggering frequency of the memory cleaning event can be reduced, and the duration of the memory cleaning can be shortened, thereby reducing the workload of the memory manager, and further, the performance overhead during the memory management can be effectively reduced, and the adverse effects caused by the application thread pause due to the memory cleaning can be weakened.

[0040] The cache management method of the present specification will be described in detail below with reference to the accompanying drawings.

[0041] Please refer to Figure 1 , Figure 1 A flowchart of a cache management method provided by an exemplary embodiment of the present specification is applied to a Java virtual machine, and the memory space of the Java virtual machine includes an extended first in-heap memory. As shown in Figure 1 , the method includes the following execution steps:

[0042] Step 101, in response to a triggered memory cleaning event, the memory manager of the Java virtual machine performs scanning processing on the objects referenced by the root objects of the Java virtual machine to determine the state of the objects cached in the memory space of the Java virtual machine; wherein the scanning processing includes: determining the in-heap memory for caching the first objects referenced by the root objects; if the first objects referenced by the root objects are cached in the first in-heap memory which is not manageable by the memory manager, then the scanning process for the first in-heap memory is skipped, and the first objects are determined as valid states;

[0043] Step 102, the memory manager of the Java virtual machine determines the objects in invalid states cached in the memory space of the Java virtual machine, and cleans the objects in invalid states.

[0044] In the present embodiment, in response to a triggered memory cleaning event, the memory manager of the Java virtual machine can perform scanning processing on the objects referenced by the root objects of the Java virtual machine to determine the state of the objects cached in the memory space of the Java virtual machine.

[0045] For example, in response to a memory cleaning event triggered in the Java virtual machine, the memory manager of the Java virtual machine can perform scanning processing on the objects referenced by the root objects of the Java virtual machine, and determine whether the state of the cached objects in the memory space of the Java virtual machine is a valid state through the scanning.

[0046] In addition, in the Java virtual machine, common root objects include thread stacks, constant pools, code caches, etc., which are not limited in the present specification.

[0047] In an embodiment shown, the memory cleaning event is a memory cleaning event triggered by the Java virtual machine based on a preset cleaning period; or, the memory cleaning event is a memory cleaning event triggered when the available memory space of any process on the Java virtual machine is lower than a threshold.

[0048] In one example, the Java virtual machine can trigger a memory cleaning event based on a preset cleaning period to make the memory manager perform memory cleaning; in another example, when the available memory space of any process on the Java virtual machine is lower than a threshold, a memory cleaning event can be triggered to make the memory manager perform memory cleaning and release the available memory space.

[0049] The state of the cached objects in the memory space of the Java virtual machine includes a valid state and an invalid state. The object in the valid state is an object whose life cycle has not ended, i.e., the object is still in a state of survival and does not need to be recycled; and the object in the invalid state is an object whose life cycle has ended, i.e., the object is in a state of death and needs to be recycled.

[0050] Therefore, the memory manager can determine whether to clean the object by determining the state of the cached object in the memory space of the Java virtual machine, and in order to determine the state of the object, as described in step 101, the memory manager can perform scanning processing on the objects referenced by the root objects of the Java virtual machine, and determine whether the heap memory for caching the first object referenced by the root object is the first heap memory through the scanning processing.

[0051] If the first object referenced by the root object is cached in the first heap memory which is not manageable by the memory manager, the process of scanning the first heap memory is skipped, and the first object is determined as a valid state. Correspondingly, if the first object referenced by the root object is not cached in the first heap memory, the process of scanning the heap memory where the first object referenced by the root object is located is performed, and the state of the objects cached in the heap memory where the first object is located is determined by traversing the objects cached in the heap memory where the first object is located starting from the first object referenced by the root object. For example, the user can store the objects which he / she hopes to skip the memory cleaning in the first heap memory, and when it is determined that the memory space address of the object referenced by the root object is located in the address range of the first heap memory, the memory manager can directly determine the objects in the first heap memory as valid states, thereby skipping the subsequent processes. Conversely, if the memory space address of the object referenced by the root object is not located in the address range of the first heap memory, the state of the other objects is determined by traversing the other objects cached in the heap memory where the object referenced by the root object is located starting from the object referenced by the root object.

[0052] In an embodiment shown, the memory space of the Java virtual machine further comprises a second heap memory; wherein the second heap memory is a heap memory which is manageable by the memory manager of the Java virtual machine.

[0053] It is worth noting that, different from the first heap memory which is a heap memory not manageable by the memory manager of the Java virtual machine, the second heap memory is a heap memory manageable by the memory manager of the Java virtual machine.

[0054] Therefore, when it is determined that the first object referenced by the root object is cached in the second heap memory, the memory manager can continue the following scanning process:

[0055] traversing the second heap memory further starting from the first object to determine whether a second object referenced by the first object is cached in the second heap memory, and in response to that the second object referenced by the first object is cached in the second heap memory, determining the second object as a valid state object;

[0056] and continuing to traverse the objects cached in the second heap memory to determine whether a third object referenced by the second object is cached in the second heap memory, and in response to that the third object referenced by the second object is cached in the second heap memory, determining the third object as a valid state object, and so on until the object which does not reference other objects is reached.

[0057] In an embodiment shown, if any target object cached in the second heap memory references a fourth object cached in the first heap memory, the target object and the fourth object are determined as valid objects.

[0058] In the embodiment, the memory manager of the Java virtual machine can determine the invalid objects cached in the memory space of the Java virtual machine and clean up the invalid objects.

[0059] For example, after the valid objects are determined, other objects cached in the memory space of the Java virtual machine can be determined as invalid objects and cleaned up.

[0060] In an embodiment shown, the memory manager of the Java virtual machine can determine other objects cached in the second heap memory as invalid objects except the valid objects cached in the second heap memory.

[0061] Next, the above process is described with an example of Figure 2 . Please refer to Figure 2 , Figure 2 a schematic diagram of the scanning process provided by an exemplary embodiment of the present specification. As shown in Figure 2 , the memory space of the Java virtual machine includes a first heap memory and a second heap memory; wherein the first heap memory is the heap memory that is not manageable by the memory manager of the Java virtual machine; and the second heap memory is the heap memory that is manageable by the memory manager of the Java virtual machine.

[0062] For example, in Figure 2 , the first heap memory stores object A, object B and object C, and root object 1 references object A, object A references object B, and object B references object C. When performing the aforementioned step 101, the memory manager scans the object A referenced by the root object 1 and determines that the heap memory for caching the object A referenced by the root object 1 is the first heap memory.

[0063] As described above, when the first object referenced by the root object is cached in the first heap memory that is not manageable by the memory manager, the first object can be directly determined as valid, and thus the memory manager can determine that the state of object A is valid.

[0064] Further, for the object B referenced by object A and the object C referenced by object B, the process of determining the state of the object can be skipped and the scanning process is not needed.

[0065] Continue with the example in Figure 2In the diagram, the second heap memory stores objects D, E, F, and G, with reference relationships as shown. The memory manager can scan for object D referenced by root object 2 and determine that the heap memory used to cache object D referenced by root object 2 is the second heap memory.

[0066] As mentioned above, when the first object referenced by the root object is cached in the second heap memory manageable by the memory manager, it is necessary to start from the first object and further traverse the second heap memory. Figure 2 Starting with object D, by further traversing the second heap memory, it can be determined that object E, which is referenced by object D, is cached in the second heap memory. In response to the fact that object E, which is referenced by object D, is cached in the second heap memory, it can be determined that the state of object E is valid.

[0067] Then, by continuing to traverse the objects cached in the second heap memory, it can be determined that object E references object F. Therefore, in response to the fact that object F referenced by object E is cached in the second heap memory, it can be determined that the state of object F is valid.

[0068] Then, by continuing to traverse the objects cached in the second heap memory, it can be determined that object F references object G. Therefore, in response to the fact that object F references object G in the second heap memory, it can be determined that the state of object G is valid.

[0069] Finally, for the last object G, since there are no subsequent referenced objects, the scanning process can be stopped. At this point, the memory manager can continue scanning the objects referenced by other root objects.

[0070] Continuing with the example, in Figure 2 In the diagram, object H, referenced by root object 3, resides in the second heap memory, while object I, referenced by object H, resides in the first heap memory. Therefore, the memory manager can scan object H referenced by root object 3 and determine that the heap memory used to cache object H referenced by root object 3 is the second heap memory. As mentioned earlier, this confirms that object H is in a valid state.

[0071] Furthermore, for object I referenced by object H, since the heap memory used to cache object I is the first heap memory, it can be determined that the state of object I is valid.

[0072] It's worth noting that the memory manager can store objects other than those with valid state cached in the second heap memory, such as... Figure 2 Object J in the data is identified as invalid, and the invalid object J is cleaned up.

[0073] In an embodiment shown, the Java virtual machine is a Java virtual machine deployed on a server corresponding to a marketing platform; the objects cached in the first heap memory include discount information related to marketing services provided by the marketing platform to users.

[0074] For example, the Java virtual machine can be a Java virtual machine deployed on a server corresponding to an e-commerce marketing platform, and the e-commerce marketing platform can have a large amount of discount information. When the platform holds a shopping festival or other promotional activities, the pressure generated by a large number of users accessing a large amount of discount information is huge. Therefore, discount information related to marketing services provided by the marketing platform to users can be cached in the first heap memory, thereby improving the reading efficiency of the coupon and reducing the performance overhead when performing memory management to ensure the smooth progress of the business.

[0075] In an embodiment shown, the discount information is cached in the memory space of the Java virtual machine in the form of a key-value pair; wherein the value of the discount information is cached in the first heap memory; and the key of the discount information is cached in the second heap memory.

[0076] The above discount information can be composed of a discount information identifier and discount content. The discount information identifier can be a product ID, a store ID, a SKU (Stock Keeping Unit) ID, etc. The discount content can be a discount activity, a coupon rule, etc.

[0077] In an example, the discount information identifier and the discount content can be cached in the memory space of the Java virtual machine in the form of a key-value pair. The discount information identifier as the key can be cached in the second heap memory, and the discount content as the value can be cached in the first heap memory.

[0078] It is worth noting that the above key can also be cached in the first heap memory, but considering that the value exists for a long time, such as the discount content is usually planned in advance and will not be changed temporarily, and the write of the discount content can also be prohibited during the actual promotional activities. Therefore, by caching the key in the second heap memory, when the discount content of a merchant or product needs to be changed, only the reference relationship between the key and the value needs to be changed to achieve the change.

[0079] In an embodiment shown, the first heap memory is a GC Invisible Heap, and the second heap memory is a Java Heap.

[0080] For example, the second in-heap memory can be a traditional Java Heap in Java, and the extended first in-heap memory can be a GC Invisible Heap.

[0081] In an embodiment shown, the object cached in the first in-heap memory is open to manual setting of a valid period;

[0082] Further, the Java virtual machine can receive a setting instruction initiated by a user for setting a valid period for the object cached in the first in-heap memory; and in response to the setting instruction, set the valid period for the object.

[0083] For example, since the discount information cached in the first in-heap memory is open to manual setting of a valid period, the user can set the valid period of the discount information as the time period of the promotion activity. After receiving the setting instruction, the Java virtual machine can set the valid period for the discount information in response to the setting instruction.

[0084] In an embodiment shown, the Java virtual machine can determine whether the valid period is over; if yes, clean up the object cached in the first in-heap memory.

[0085] For example, when the valid period of the discount information is over, the Java virtual machine can clean up the discount information cached in the first in-heap memory.

[0086] In an embodiment shown, the life cycle of the object cached in the first in-heap memory is by default infinite.

[0087] As known from the foregoing, for the object stored in the first in-heap memory, the user usually expects that the object is not cleaned up by the memory manager and can be stored persistently, and thus the life cycle of the object cached in the first in-heap memory can be by default infinite. By open to the user the authority of manually setting a valid period, manual management of the object in the first in-heap memory can be realized, manual management can be achieved, and the caching scheme can be more flexible.

[0088] By the above technical solution, the first in-heap memory which is not manageable by the memory manager is extended in the memory space of the Java virtual machine, so that when the memory manager performs scanning processing on the objects referenced by the root objects of the Java virtual machine, the first object cached in the first in-heap memory and scanned is determined as an effective state. In the above process, since the traversal of other objects cached in the first in-heap memory is skipped, the scanning processing of the other objects cached in the first in-heap memory is not required, so that the triggering frequency of the memory cleaning event can be reduced, and the duration of the memory cleaning can be shortened, thereby reducing the workload of the memory manager, and further, the performance overhead during memory management can be effectively reduced, and the adverse effects caused by the application thread pause due to memory cleaning can be weakened.

[0089] Please refer to Figure 3 , Figure 3 A structural schematic diagram of a cache management system is provided for an exemplary embodiment of the present specification. As shown in Figure 3 , the system includes a Java virtual machine 301, a first in-heap memory 302, and a memory manager 303 of the Java virtual machine.

[0090] As shown in Figure 3 , the memory space of the Java virtual machine 301 includes the extended first in-heap memory 302;

[0091] It is worth noting that the first in-heap memory 302 is the in-heap memory which is not manageable by the memory manager 303 of the Java virtual machine;

[0092] The memory manager 303 of the Java virtual machine can perform scanning processing on the objects referenced by the root objects of the Java virtual machine 301 in response to the triggered memory cleaning event, to determine the state of the objects cached in the memory space of the Java virtual machine;

[0093] The scanning processing includes: determining the in-heap memory for caching the first object referenced by the root object;

[0094] It should be noted that if the first object referenced by the root object is cached in the first in-heap memory which is not manageable by the memory manager, the scanning process for the first in-heap memory is skipped, and the first object is determined as an effective state;

[0095] The memory manager 303 of the Java virtual machine can determine the objects in the memory space of the Java virtual machine which are in an invalid state, and clean the objects in the invalid state.

[0096] For details on the specific implementation process of the above system, please refer to the implementation process of the corresponding steps in the above cache management method. For relevant details, please refer to the description of the method implementation method. It will not be repeated here.

[0097] In an exemplary embodiment of this specification, an apparatus capable of implementing the above-described method is also provided.

[0098] Figure 4 This is a schematic structural diagram of a device provided in an exemplary embodiment. Please refer to... Figure 4 At the hardware level, the device includes a processor 402, an internal bus 404, a network interface 406, memory 408, and non-volatile memory 410, and may also include other hardware required for business operations. One or more embodiments of this specification can be implemented in software, for example, the processor 402 reads the corresponding computer program from the non-volatile memory 410 into memory 409 and then runs it. Of course, in addition to software implementation, one or more embodiments of this specification do not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. That is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.

[0099] Please refer to Figure 5 In one software implementation, a cache management device 500 is provided, applied to a Java Virtual Machine, the memory space of which includes an extended first heap memory. For example... Figure 5 As shown, the device 500 includes:

[0100] The scanning module 501, in response to a triggered memory cleanup event, performs a scanning process on the objects referenced by the root object of the Java Virtual Machine to determine the state of cached objects in the memory space of the Java Virtual Machine; wherein, the scanning process includes: determining the heap memory used to cache the first object referenced by the root object; if the first object referenced by the root object is cached in the first heap memory that is not managed by the memory manager, then the process of scanning the first heap memory is skipped, and the first object is determined to be in a valid state;

[0101] The cleanup module 502 is used by the Java Virtual Machine's memory manager to identify and clean up invalid objects cached in the Java Virtual Machine's memory space.

[0102] Optionally, the memory cleanup event is a memory cleanup event triggered periodically by the Java Virtual Machine based on a preset cleanup cycle; or, the memory cleanup event is a memory cleanup event triggered when the available memory space of any process on the Java Virtual Machine is lower than a threshold.

[0103] Optionally, the memory space of the Java Virtual Machine further includes a second heap memory; wherein the second heap memory is the heap memory that can be managed by the memory manager of the Java Virtual Machine.

[0104] Furthermore, the scanning process also includes:

[0105] If the first object referenced by the root object is cached in the second heap memory, then starting from the first object, the second heap memory is further traversed to determine whether the second object referenced by the first object is cached in the second heap memory, and in response to the second object referenced by the first object being cached in the second heap memory, the second object is determined to be a valid object.

[0106] Furthermore, continue traversing the objects cached in the second heap memory to determine whether the third object referenced by the second object is cached in the second heap memory, and in response to the third object referenced by the second object being cached in the second heap memory, determine the third object as a valid object, and so on, until an object that does not reference other objects is encountered.

[0107] Optionally, the device 500 further includes:

[0108] The determination module 503 (not shown in the figure) determines that, during the traversal of the second heap memory, if any fourth object referenced by any target object cached in the second heap memory is cached in the first heap memory, the target object and the fourth object are determined to be objects in a valid state.

[0109] Optionally, the cleaning module 502 further includes:

[0110] The Java Virtual Machine's memory manager determines objects other than those with valid states cached in the second heap memory as invalid objects.

[0111] Optionally, the Java Virtual Machine is a Java Virtual Machine deployed on a server corresponding to the marketing platform; the objects cached in the first heap memory include preferential information related to the marketing services provided by the marketing platform to users.

[0112] Optionally, the discount information is cached in the memory space of the Java Virtual Machine in the form of key-value pairs; wherein the value of the discount information is cached in the first heap memory; and the key of the discount information is cached in the second heap memory.

[0113] Optionally, the first heap memory is a GC Invisible Heap, and the second heap memory is a Java Heap.

[0114] Optionally, the objects cached in the first heap memory are given the permission to manually set their validity period;

[0115] Furthermore, the device 500 also includes:

[0116] The receiving module 504 (not shown in the figure) receives a setting instruction initiated by the user to set the validity period of objects cached in the first heap memory;

[0117] Setting module 505 (not shown in the figure) sets a validity period for the object in response to the setting instruction.

[0118] Optionally, the device 500 further includes:

[0119] The cycle module 506 (not shown in the figure) determines whether the effective cycle has ended;

[0120] Clean up submodule 507 (not shown in the figure), if so, clean up the cached objects in the first heap memory.

[0121] Optionally, the lifetime of objects cached in the first heap memory is set to infinite by default.

[0122] The implementation process of the functions and roles of each module in the above-mentioned device 500 is detailed in the implementation process of the corresponding steps in the above-mentioned cache management method. For relevant parts, please refer to the description of the method implementation method. It will not be repeated here.

[0123] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical modules; that is, they may be located in one place or distributed across multiple network modules. Some or all of the units or modules can be selected to achieve the purpose of the solution described in this specification, depending on actual needs. Those skilled in the art can understand and implement this without any inventive effort.

[0124] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which can take the form of a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email sending and receiving device, game console, tablet computer, wearable device, or any combination of these devices.

[0125] In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0126] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0127] Computer-readable media, including both permanent and non-permanent, removable and non-removable media, can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.

[0128] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0129] The foregoing has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.

[0130] The terminology used in one or more embodiments of this specification is for the purpose of describing particular embodiments only and is not intended to limit the scope of one or more embodiments of this specification. The singular forms “a,” “described,” and “the” used in one or more embodiments of this specification and in the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0131] It should be understood that although the terms first, second, third, etc., may be used to describe various information in one or more embodiments of this specification, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, first information may also be referred to as second information without departing from the scope of one or more embodiments of this specification, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "in response to a determination," or "when," or "in the event of a determination."

[0132] The above description is merely a preferred embodiment of one or more embodiments of this specification and is not intended to limit the scope of one or more embodiments of this specification. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of one or more embodiments of this specification should be included within the scope of protection of one or more embodiments of this specification.

Claims

1. A cache management method applied to a Java Virtual Machine, wherein the memory space of the Java Virtual Machine includes an extended first heap memory; the method includes: In response to a triggered memory cleanup event, the Java Virtual Machine's memory manager scans the objects referenced by the root object of the Java Virtual Machine to determine the state of cached objects in the Java Virtual Machine's memory space. The scanning process includes: determining the heap memory used to cache a first object referenced by the root object; if the first object referenced by the root object is cached in a first heap memory that the memory manager cannot manage, the scanning process for the first heap memory is skipped, and the first object is determined to be in a valid state. The Java Virtual Machine's memory manager identifies and cleans up invalid objects cached in the Java Virtual Machine's memory space.

2. The method according to claim 1, wherein the memory cleanup event is a memory cleanup event triggered periodically by the Java Virtual Machine based on a preset cleanup cycle; or, the memory cleanup event is a memory cleanup event triggered when the available memory space of any process on the Java Virtual Machine is lower than a threshold.

3. The method according to claim 1, wherein the memory space of the Java Virtual Machine further includes a second heap memory; wherein, The second heap memory is the heap memory that can be managed by the memory manager of the Java Virtual Machine; The scanning process also includes: If the first object referenced by the root object is cached in the second heap memory, then starting from the first object, the second heap memory is further traversed to determine whether the second object referenced by the first object is cached in the second heap memory, and in response to the second object referenced by the first object being cached in the second heap memory, the second object is determined to be a valid object. Furthermore, continue traversing the objects cached in the second heap memory to determine whether the third object referenced by the second object is cached in the second heap memory, and in response to the third object referenced by the second object being cached in the second heap memory, determine the third object as a valid object, and so on, until an object that does not reference other objects is encountered.

4. The method according to claim 3, further comprising: During the traversal of the second heap memory, if a fourth object referenced by any target object cached in the second heap memory is cached in the first heap memory, then the target object and the fourth object are determined to be valid objects.

5. The method according to claim 4, wherein the Java Virtual Machine's memory manager determines objects in an invalid state cached in the Java Virtual Machine's memory space, comprising: The Java Virtual Machine's memory manager determines objects other than those with valid states cached in the second heap memory as invalid objects.

6. The method according to claim 1, wherein the Java Virtual Machine is a Java Virtual Machine deployed on a server corresponding to the marketing platform; the objects cached in the first heap memory include preferential information related to the marketing services provided by the marketing platform to users.

7. The method according to claim 6, wherein the discount information is cached in the memory space of the Java Virtual Machine in the form of key-value pairs.

8. The method according to claim 1, wherein the Java Virtual Machine is a Java Virtual Machine deployed on a server corresponding to the marketing platform; the memory space of the Java Virtual Machine caches, in the form of key-value pairs, promotional information related to the marketing services provided by the marketing platform to users; wherein, The Java Virtual Machine's memory space also includes a second heap memory, where the value of the discount information is cached in the first heap memory, and the key of the discount information is cached in the second heap memory.

9. The method according to claim 3, wherein the first heap memory is a GC Invisible Heap, and the second heap memory is a Java Heap.

10. The method according to claim 1, wherein the objects cached in the first heap memory have the permission to have their validity period manually set; The method further includes: Receive a user-initiated setting instruction to set the validity period of objects cached in the first heap memory; In response to the setting instruction, a validity period is set for the object.

11. The method according to claim 10, further comprising: Determine whether the effective period has ended; If so, clean up the cached objects in the first heap memory.

12. The method according to claim 10, wherein the lifetime of objects cached in the first heap memory is assumed to be infinite.

13. A cache management system, comprising: The Java Virtual Machine, whose memory space includes the extended first heap memory; The first heap memory is the heap memory that is not managed by the memory manager of the Java Virtual Machine; The Java Virtual Machine's memory manager is configured to, in response to a triggered memory cleanup event, scan objects referenced by the root object of the Java Virtual Machine to determine the state of cached objects in the Java Virtual Machine's memory space. The scanning process includes: determining the heap memory used to cache a first object referenced by the root object; if the first object referenced by the root object is cached in a first heap memory unmanageable by the memory manager, skipping the scanning process for the first heap memory and determining the first object as valid; and determining and cleaning up cached objects in an invalid state in the Java Virtual Machine's memory space.

14. An electronic device, comprising: processor; Memory used to store processor-executable instructions; The processor implements the method as described in any one of claims 1-12 by executing the executable instructions.

15. A machine-readable storage medium having stored thereon machine-readable instructions that, when executed by a processor, implement the steps of the method as claimed in any one of claims 1-12.

Citation Information

Patent Citations

  • Garbage recovery mobile communication terminal of Java virtual machine and recovery method thereof

    CN101221535A

  • Global data storage and reporting method, device and system

    CN104808968A