Memory management method, apparatus, device, and computer-readable storage medium

By encoding depth information in object pointers, shallow recursive objects are identified and marked for depth-first traversal, solving the problem of low efficiency in processing shallow recursive objects in existing technologies and achieving more efficient memory management.

CN115495226BActive Publication Date: 2026-07-03TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
TENCENT TECHNOLOGY (SHENZHEN) CO LTD
Filing Date
2021-06-17
Publication Date
2026-07-03

AI Technical Summary

Technical Problem

Existing memory management methods do not distinguish between shallow recursive objects and ordinary objects during the marking phase. This leads to increased CPU and memory resource consumption during push and pop operations, as well as frequent invalid memory accesses, which reduces memory management efficiency.

Method used

By encoding depth information in object pointers, shallow traversal objects can be identified using this depth-encoded information. This allows for direct depth-first traversal marking, avoiding push and pop operations and reducing invalid memory accesses.

Benefits of technology

It improves the marking speed and efficiency of memory management, reduces CPU consumption and memory access overhead, and enhances the overall performance of memory management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115495226B_ABST
    Figure CN115495226B_ABST
Patent Text Reader

Abstract

This application provides a memory management method, apparatus, device, and computer-readable storage medium. The method includes: upon determining that a memory management opportunity has been reached, obtaining an object pointer of an object node from a marking stack, the object pointer including depth encoding information of the object node; when it is determined based on the depth encoding information that the encoding depth of the object node is lower than a preset depth threshold, marking the child object nodes of the root object node according to a preset traversal method until leaf nodes are marked; marking the child objects of other object nodes based on the depth encoding information of other object nodes in the marking stack until the marking stack is empty; determining an unmarked target object node based on the marked object nodes, deleting the target object node to release the memory space corresponding to the target object node. This application improves memory management efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to memory management technology, and more particularly to a method, apparatus, device, and computer-readable storage medium. Background Technology

[0002] During program development, deleting a previously created object only removes the variable's reference; it doesn't immediately clear the occupied memory space. Objects without references become garbage in memory. Garbage collection (GC) is one of the core technologies of the Java language. Garbage collection typically uses a mark-and-sweep mechanism, which first marks accessible objects and then traverses the heap to reclaim unmarked objects. In related technologies, the marking phase uses a stack-based method to mark the object graph, usually starting from a set of root object pointers and traversing the entire object graph. This can lead to invalid memory accesses, thus reducing memory management efficiency. Summary of the Invention

[0003] This application provides a memory management method, apparatus, and computer-readable storage medium that can improve memory management efficiency.

[0004] The technical solution of this application embodiment is implemented as follows:

[0005] This application provides a memory management method, including:

[0006] When it is determined that the memory management time has been reached, the object pointer of the object node is obtained from the tag stack, and the object pointer includes the depth encoding information of the object node;

[0007] When it is determined based on the depth encoding information that the encoding depth of the object node is lower than a preset depth threshold, the child object nodes of the object node are marked according to a preset traversal method until the leaf node is marked.

[0008] The child objects of the other object nodes are marked based on the depth encoding information of the other object nodes in the marking stack until the marking stack is empty;

[0009] Based on the marked object nodes, determine the unmarked target object nodes, delete the target object nodes, and release the memory space corresponding to the target object nodes.

[0010] This application provides a memory management device, including:

[0011] The first acquisition module is used to acquire an object pointer of an object node from the tag stack when it is determined that the memory management time has been reached. The object pointer includes the depth encoding information of the object node.

[0012] The first marking module is used to mark the child object nodes of the object node according to a preset traversal method until the leaf node is marked when the encoding depth of the object node is determined to be lower than a preset depth threshold based on the depth encoding information.

[0013] The second marking module is used to mark the child objects of other object nodes based on the depth encoding information of other object nodes in the marking stack until the marking stack is empty;

[0014] The clearing module is used to determine unmarked target object nodes based on the marked object nodes, and delete the target object nodes to release the memory space corresponding to the target object nodes.

[0015] In some embodiments, the device further includes:

[0016] The second acquisition module is used to obtain the initial object pointer of the newly created object allocated from the heap physical memory;

[0017] The third acquisition module is used to acquire the actual depth information and preset depth threshold of the newly created object;

[0018] The first determining module is used to determine the encoding depth of the newly created object based on the actual depth information of the newly created object and the depth threshold.

[0019] The second determining module is used to determine the final object pointer of the newly created object by using the encoding depth of the newly created object and the initial object pointer.

[0020] In some embodiments, the third acquisition module is further configured to:

[0021] Obtain the type information of the newly created object;

[0022] Load the type information to determine the actual depth information of the newly created object.

[0023] In some embodiments, the first determining module is further configured to:

[0024] When the actual depth information is less than the depth threshold, the actual depth information is determined as the encoding depth of the newly created object;

[0025] When the actual depth information is greater than or equal to the depth threshold, the depth threshold is determined as the encoding depth of the newly created object.

[0026] In some embodiments, the second determining module is further configured to:

[0027] Obtain the starting bit length of the preset depth encoding information, wherein the starting bit length is greater than the total bit length of the initial object pointer;

[0028] The binary value of the encoding depth is determined as the depth encoding information of the object node;

[0029] The depth encoding information is shifted left according to the starting number of bits to obtain the shifted depth information;

[0030] The shift depth information and the initial object pointer are logically ORed to obtain the final object pointer of the newly created object.

[0031] In some embodiments, the device further includes:

[0032] The shift module is used to shift the object pointer of the object node to the right according to the starting number of bits to obtain the depth encoding information;

[0033] The third determining module is used to determine the decimal value of the depth encoding information as the encoding depth of the object node.

[0034] In some embodiments, the first marking module is further configured to:

[0035] When it is determined based on the depth encoding information that the encoding depth of the object node is lower than a preset depth threshold, it is determined whether the object node is a leaf node.

[0036] When the object node is not a leaf node, obtain and mark the child object nodes of the object node;

[0037] Obtain the encoding depth of the child object node;

[0038] When the encoding depth of the child object node is less than the encoding depth of the object node, the child object nodes of the child object node are marked according to the preset traversal method until the leaf node is marked.

[0039] In some embodiments, the device further includes:

[0040] The first push-to-stack module is used to add the marked child object node to the marking stack when the encoding depth of the child object node is greater than or equal to the encoding depth of the object node.

[0041] In some embodiments, the device further includes:

[0042] The fourth acquisition module is used to acquire the child object nodes of the object node when it is determined based on the depth encoding information that the encoding depth of the object node is not lower than a preset depth threshold.

[0043] The third marking module is used to mark the child node of the child object if the child object node is not marked.

[0044] The second push module is used to add the marked child object node to the marking stack.

[0045] In some embodiments, the device further includes:

[0046] The fifth acquisition module is used to acquire the memory information of the heap physical memory;

[0047] The mapping module is used to map the heap physical memory to virtual memory corresponding to different depth encoding information based on multiple mapping technology, the memory information, and the starting bit.

[0048] This application provides a memory management device, including:

[0049] Memory, used to store executable instructions;

[0050] The processor, when executing executable instructions stored in the memory, implements the memory management method provided in the embodiments of this application.

[0051] This application provides a computer-readable storage medium storing executable instructions for inducing a processor to execute and implement the memory management method provided in this application.

[0052] The embodiments of this application have the following beneficial effects:

[0053] When the memory management timing is determined, the object pointer of the object node is obtained from the marking stack. The object pointer includes the depth encoding information of the object node. During the marking phase of memory management, different marking processes are performed based on the depth encoding information. When the depth encoding information is lower than a preset depth threshold, the child object nodes of the object node are marked according to a preset traversal method until the leaf node is marked. Then, the child objects of other object nodes in the marking stack are marked until the marking stack is empty. Then, in the cleanup phase, the unmarked target object node is determined based on the marked object nodes, and the target object node is deleted to release the memory space corresponding to the target object node. In this way, the child object nodes of shallowly traversed objects with depth encoding information lower than the depth threshold are directly marked instead of being pushed and popped from the stack. This not only reduces the time for pushing and popping from the stack, but also reduces the stack space required for memory access and pushing onto the stack, thereby improving the marking speed of memory management and thus improving memory management efficiency. Attached Figure Description

[0054] Figure 1 This is an optional structural diagram of the memory management system architecture provided in the embodiments of this application;

[0055] Figure 2This is a schematic diagram of the structure of the memory management device provided in the embodiments of this application;

[0056] Figure 3 This is a schematic diagram illustrating an implementation flow of the memory management method provided in an embodiment of this application;

[0057] Figure 4 A schematic diagram illustrating another implementation flow of the memory management method provided in this application embodiment;

[0058] Figure 5 A schematic diagram illustrating another implementation of the memory management method provided in this application embodiment;

[0059] Figure 6A This is a schematic diagram illustrating the color coding design of object pointers provided in an embodiment of this application.

[0060] Figure 6B A schematic diagram illustrating the classification of object pointers provided in embodiments of this application;

[0061] Figure 7 This is a schematic diagram illustrating how physical memory is mapped to different virtual memories, provided as an embodiment of this application.

[0062] Figure 8 A schematic diagram illustrating the runtime implementation of adding traversal depth during object allocation, as provided in the embodiments of this application;

[0063] Figure 9 This is a schematic diagram illustrating the implementation process of the marking phase in memory management, as provided in an embodiment of this application. Detailed Implementation

[0064] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limitations on this application. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0065] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.

[0066] In the following description, the terms "first, second, third" are used merely to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first, second, third" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.

[0067] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.

[0068] Before providing a further detailed description of the embodiments of this application, the nouns and terms involved in the embodiments of this application will be explained, and the nouns and terms involved in the embodiments of this application shall be interpreted as follows.

[0069] 1) Colored Pointer: A pointer that encodes a color with other meanings in bits that are not used by the pointer.

[0070] 2) A class is a reflection of an entity in the real world or the world of thought in a computer. It encapsulates data and the operations on that data together.

[0071] 3) An object is a variable with a class type.

[0072] Class and object are two collective terms used in computer languages. An object is an abstraction of an objective thing, while a class is an abstraction of an object. A class is an abstract data type. Their relationship is that an object is an instance of a class, and a class is a template for objects. Objects are created using `new classname` and are used to call methods of the class.

[0073] To better understand the memory management method provided in the embodiments of this application, the garbage collection-based memory management methods in related technologies and their shortcomings are first explained.

[0074] All current tracing-based memory management algorithms (GC algorithms) use a mark-and-push method to mark the object graph. Typically, they start from a set of root object pointers and traverse the entire object graph. When processing the child nodes of the current object, a uniform marking strategy is used, without distinguishing between leaf nodes (shallow recursive objects) and ordinary objects. Whether it's the currently popular Java Virtual Machine (JVM) algorithms like Concurrent MarkSweep (CMS), Garbage First (G1), and ZGC (Z Garbage Collector), or Concurrent Copying in the ART Runtime, or Go's CMS algorithm, their marking process maintains the same logic as the aforementioned marking processes. The difference lies in their respective processor processes undergoing some cache optimization and parallelization optimization, but the processing logic for the child nodes of each object pointer remains consistent, without distinguishing between shallow recursive objects and ordinary objects.

[0075] The memory management methods in related technologies mainly have the following drawbacks:

[0076] First, the classic Mark algorithm does not distinguish between shallowly recursive object nodes and ordinary object nodes. During the marking process, shallowly traversed object nodes need to be pushed onto the Mark Stack and then removed from the Mark Stack in subsequent stages. This requires shallowly traversed object nodes to undergo push and pop operations, increasing the workload of the Mark phase and consuming CPU resources and memory resources of the Mark Stack. Furthermore, for shallowly traversed objects, especially leaf nodes (pointers to child objects with a traversal depth of 0), it is also necessary to access their child node information. Accessing child node information typically requires two memory jumps (getting the object's class information pointer from the memory corresponding to the object pointer, and then getting the child node information from the memory corresponding to the class information pointer, i.e., the Pointers(ref) operation). This requires two memory jumps, which violates the locality of reference in the CPU cache, and for leaf node objects, this memory access is invalid.

[0077] Second, the optimized Mark algorithm can read the child node information of the object's class information during the Mark phase to determine whether the object is a shallow traversal object, thereby reducing the push and pop operations of shallow traversal objects. However, for both shallow traversal objects and ordinary objects, memory access is still required to determine their type (whether they are shallow traversal objects), increasing memory access overhead. This memory access, like the aforementioned memory access, requires two indirect memory jumps, resulting in poor management efficiency.

[0078] This application provides a memory management method, apparatus, device, and computer-readable storage medium that can achieve a more efficient Mark process and improve GC efficiency by adding a slight traversal information encoding operation during the object allocation phase in exchange for efficient identification of shallowly traversed objects during the Mark phase.

[0079] The following describes exemplary applications of the memory management device provided in the embodiments of this application. The device provided in the embodiments of this application can be implemented as various types of user terminals such as laptops, tablets, desktop computers, set-top boxes, and mobile devices (e.g., mobile phones, portable music players, personal digital assistants, dedicated messaging devices, portable gaming devices), or as a server. The following will describe exemplary applications when the device is implemented as a server.

[0080] See Figure 1 , Figure 1 This is a schematic diagram of the architecture of the network system 100 provided in the embodiments of this application, as shown below. Figure 1 As shown, the network system 100 includes a terminal 200, a network 300, and a server 400. The terminal 200 is connected to the server 400 through the network 300. The network 300 can be a wide area network or a local area network, or a combination of both.

[0081] Terminal 200 has multiple applications installed, such as instant messaging applications, shopping applications, video viewing applications, etc. Terminal 200 interacts with server 400 via a network. Server 400 may run a language virtual machine. The memory management method provided in this embodiment can be applied to the memory management module of the language virtual machine runtime based on tracing. When the language virtual machine in server 400 creates an object, it obtains the traversal depth of the newly created object and encodes the traversal depth into the unused high-order bits of the object pointer. When memory management is started, during the Marking phase, the pointers of object nodes retrieved from the Mark Stack are shifted to obtain the traversal depth information of the object. The overhead of the shift operation is almost zero compared to the memory read operation, thereby achieving lower-cost identification of shallow traversal objects and performing depth-first search (DFS) traversal processing in real time, avoiding the pushing and popping of such objects from the stack, reducing the memory consumption of the Mark Stack and the entry and exit of Mark Stack objects. The CPU consumption of the stack is reduced; for leaf node object pointers, it can be directly determined that there are no child nodes by shifting, without needing to access the child node information, thus eliminating two indirect memory accesses to the leaf node, thereby effectively reducing the CPU consumption related to memory access in the marking stage.

[0082] The memory management method provided in this application can be applied to the big data field, such as various Java big data applications like Hadoop, HBase, and Zookeeper. These applications typically use large heaps and cache a lot of data. For example, Zookeeper usually caches a large amount of configuration information, which is usually in the form of strings. In Java, a String object only contains a single byte[] object. If the GC needs to traverse the object tree starting from the String object, it only needs to traverse down one level to reach the leaf node byte[] object. Therefore, String is a shallow traversal object. Thus, during the GC Marking phase, if shallow traversal objects like String are directly marked using DFS traversal, the number of pushes and pops from the String itself and its child byte[] arrays can be reduced, thereby significantly reducing the GC Marking time and Mark Stack memory consumption.

[0083] In some embodiments, server 400 may be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. Server 400 may be a smartphone, tablet, laptop, desktop computer, smart speaker, smartwatch, etc., but is not limited thereto. The terminal and the server can be directly or indirectly connected via wired or wireless communication, which is not limited in this embodiment of the invention.

[0084] See Figure 2 , Figure 2 This is a schematic diagram of the structure of the server 400 provided in this embodiment of the application. Figure 2 The server 400 shown includes at least one processor 410, memory 440, and at least one network interface 420. The various components of server 400 are coupled together via a bus system 430. It is understood that the bus system 430 is used to implement communication between these components. In addition to a data bus, the bus system 430 also includes a power bus, a control bus, and a status signal bus. However, for clarity, ... Figure 2 The general labeled all buses as Bus System 430.

[0085] Processor 410 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor can be a microprocessor or any conventional processor, etc.

[0086] The memory 440 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state storage, hard disk drives, optical disk drives, etc. The memory 440 may optionally include one or more storage devices physically located away from the processor 410.

[0087] The memory 440 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), and the volatile memory may be random access memory (RAM). The memory 440 described in this application embodiment is intended to include any suitable type of memory.

[0088] In some embodiments, memory 440 is capable of storing data to support various operations, examples of which include programs, modules, and data structures or subsets or supersets thereof, as illustrated below.

[0089] Operating system 441 includes system programs for handling various basic system services and performing hardware-related tasks, such as the framework layer, core library layer, driver layer, etc., for implementing various basic business functions and handling hardware-based tasks;

[0090] The network communication module 442 is used to reach other computing devices via one or more (wired or wireless) network interfaces 420, exemplary network interfaces 420 including: Bluetooth, WiFi, and Universal Serial Bus (USB), etc.

[0091] In some embodiments, the apparatus provided in this application can be implemented in software. Figure 2 A memory management device 443 stored in memory 440 is shown. It may be software in the form of programs and plug-ins, including the following software modules: a first acquisition module 4431, a first marking module 4432, a second marking module 4433, and a cleanup module 4434. These modules are logical and can therefore be arbitrarily combined or further split according to the functions they implement.

[0092] The functions of each module will be explained below.

[0093] In other embodiments, the apparatus provided in this application can be implemented in hardware. As an example, the apparatus provided in this application can be a processor in the form of a hardware decoding processor, which is programmed to execute the memory management method provided in this application. For example, the processor in the form of a hardware decoding processor can be one or more application-specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs), or other electronic components.

[0094] The memory management method provided in this application will be described in conjunction with exemplary applications and implementations of the terminal provided in the embodiments of this application.

[0095] See Figure 3 , Figure 3 This is a schematic diagram illustrating an implementation flow of the memory management method provided in this application embodiment, which will be combined with... Figure 3 The steps shown are explained.

[0096] Step S101: When it is determined that the memory management time has been reached, the object pointer of the object node is obtained from the mark stack.

[0097] In this embodiment, a memory management opportunity is considered to have been reached when the remaining memory space is less than a preset space threshold. A preset interval for memory management can also be established. When the time between the current moment and the last memory management moment reaches the preset interval, a memory management opportunity is determined to have been reached. In this embodiment, when a memory management opportunity is reached, a set of root object nodes is determined, and each root object node is marked and added to a marking stack. Then, object nodes are sequentially retrieved from the marking stack to mark the child object nodes of the object nodes in the marking stack.

[0098] The object pointer includes depth encoding information for the object node. In some embodiments, the depth encoding information is also called color encoding information, and the object pointer with color encoding can also be called a color pointer. In implementation, the traversal depth of the object node can be encoded into the unused high-order bits of the object pointer. For example, if the object pointer has 64 bits and occupies 32 bits (bits 0 to 31), leaving bits 32 to 63 as unused high-order bits, then several bits can be selected from bits 32 to 63 to encode the traversal depth of the object node. It should be noted that the traversal depth here can be determined based on the actual depth and a preset depth threshold. For example, if two unused high-order bits of the object pointer are used to encode the depth information of the object node, then the depth encoding information can be 00, 01, 10, and 11, and the corresponding traversal depths can be 0, 1, 2, and 3.

[0099] Step S102: When it is determined based on the depth encoding information that the encoding depth of the object node is lower than a preset depth threshold, the child object nodes of the object node are marked according to a preset traversal method until the leaf node is marked.

[0100] In this embodiment, the depth encoding information of the object node can be obtained by right-shifting the object pointer, and then the decimal number of the depth encoding information is determined, thus obtaining the encoding depth of the object node. For example, if the object pointer is 0x1000abcd0000, the 44th and 45th bits of this object pointer are the bits containing the depth encoding information, meaning the starting number of bits for the depth encoding information is 44. Shifting the object pointer right by 44 bits yields the depth encoding information, which is 01, corresponding to a decimal number of 2. Therefore, the traversal depth of this object pointer is 2.

[0101] In this embodiment, the depth threshold is determined based on the number of bits occupied by the depth-encoded information. For example, if the depth-encoded information occupies 2 bits, then the depth threshold is 2. 2 -1, which is equivalent to 3.

[0102] When the encoding depth is less than the depth threshold, it indicates that the object node is a shallow traversal object. In this case, it is not necessary to mark, push, and pop the child object nodes of the object node. Instead, based on the class relationship graph, the child object nodes of the object node are directly traversed and marked according to the preset traversal method until all the child object nodes starting from the object node are marked, that is, until the leaf node is marked.

[0103] Step S103: Mark the child objects of the other object nodes based on the depth encoding information of the other object nodes in the marking stack until the marking stack is empty.

[0104] After marking the child nodes of the object node, other nodes are popped from the marking stack, and the child nodes of the other object node are marked in the same way as in step S102, based on the depth encoding information of the other object node, until all object nodes in the marking stack are marked.

[0105] Step S104: Based on the marked object nodes, determine the unmarked target object nodes and delete the target object nodes to release the memory space corresponding to the target object nodes.

[0106] An object node is a live node. The child object nodes of an object node are objects that reference the object node, and therefore are also live nodes. After marking the live objects through steps S101 to S103, the unmarked object nodes in the class relationship graph are also dead object nodes. The dead object nodes are identified as target object nodes. At this time, the target object nodes are deleted, thereby releasing the memory space corresponding to the target object nodes.

[0107] In the memory management method provided in this application embodiment, when the memory management timing is determined, an object pointer of an object node is obtained from the marking stack. The object pointer includes the depth encoding information of the object node. During the marking phase of memory management, different marking processes are performed based on the depth encoding information. When the depth encoding information is lower than a preset depth threshold, the child object nodes of the object node are marked according to a preset traversal method until the leaf node is marked. Then, the child objects of other object nodes in the marking stack are marked until the marking stack is empty. Then, in the cleanup phase, the unmarked target object node is determined based on the marked object nodes, and the target object node is deleted to release the memory space corresponding to the target object node. In this way, the child object nodes of shallowly traversed objects with depth encoding information lower than the depth threshold are not pushed onto or popped from the stack but are directly marked. This not only reduces the time for pushing and popping from the stack but also reduces the stack space required for memory access and its push, thereby improving the marking speed of memory management and thus improving memory management efficiency.

[0108] In some embodiments, such as Figure 4 As shown, before step S101, depth encoding information can be added when creating an object pointer through the following steps:

[0109] Step S001: Obtain the initial object pointer of the newly created object allocated from the heap physical memory.

[0110] During the execution of a Java program, the Java Virtual Machine (JVM) divides the memory it manages into several different data areas. These data areas can be divided into two parts: one part is shared by threads, and the other part is private to threads. The thread-shared data areas include the method area and the heap, while the thread-private data areas include the virtual machine stack, the native method stack, and the program counter.

[0111] The heap stores object instances, and almost all object instances (and arrays) are allocated memory in the heap. Objects of a class are allocated memory space from the heap physical memory, which means allocating an initial object pointer for the newly created object. These objects are created using instructions such as `new`, `newarray`, `anewarray`, and `multianewarray`. They do not require explicit release by program code; therefore, the heap physical memory area is the primary object for memory management.

[0112] Step S002: Obtain the actual depth information and preset depth threshold of the newly created object.

[0113] The step S002, "obtaining the actual depth information of the newly created object," can be achieved through the following steps:

[0114] Step S0021: Obtain the type information of the newly created object. That is, obtain the Class information of the newly created object.

[0115] Step S0022: Load the type information and determine the actual depth information of the newly created object.

[0116] The actual depth information of a newly created object can be statically calculated when the object's type information is loaded. For example, in Java, this can be statically calculated during class loading; that is, the `depth(Class)` function can be calculated and stored once during type loading for subsequent calls. `depth(Class)` can be calculated using Dijkstra's algorithm. In implementation, starting from the current class, traverse its child nodes to the leaf nodes, constructing a class reference graph where the weight of each edge is set to -1. The maximum length from the current class to any other leaf node can then be transformed into a shortest path problem. Finally, the maximum value of the maximum lengths from the current class to all leaf node classes is the actual depth of the current class.

[0117] In this embodiment, the depth threshold is determined using the width of the bits occupied by the depth-coded information. For example, if the depth-coded information occupies the 44th and 45th bits, the bit width is 2, and therefore the depth threshold is 2. 2 -1, which is equivalent to 3; when the bit width is 3, the depth threshold is 2. 3-1, which is equivalent to 7, means that when the bit width is D, the depth threshold is 2. D -1.

[0118] Step S003: Determine the encoding depth of the newly created object based on the actual depth information of the newly created object and the depth threshold.

[0119] Since the depth threshold is determined based on the bit width, only 2 can be determined based on the bit width D. D Encoding depth, that is, 0 to 2 D -1, for example, when the bit width is 2, only four encoding depths can be represented by two bits: 00, 01, 10, and 11.

[0120] Therefore, in implementing step S003, when the actual depth information is less than the depth threshold, the actual depth information is determined as the encoding depth of the newly created object; when the actual depth information is greater than or equal to the depth threshold, the depth threshold is determined as the encoding depth of the newly created object.

[0121] For example, if the depth threshold is 3 and the actual depth information of the newly created object is 2, then the encoding depth of the newly created object is 2. If the actual depth information of the newly created object is 5, then the encoding depth of the newly created object is 3.

[0122] Step S004: Using the encoding depth of the newly created object and the initial object pointer, determine the final object pointer of the newly created object.

[0123] In implementing step S004, the binary value of the encoding depth can be determined first, then the binary value can be shifted and logically ORed with the initial object pointer to encode the traversal depth into the object pointer of the newly created object, so that the final object pointer of the newly created object includes the depth information.

[0124] Since virtual machines typically use an interpreter to interpret the application's code and a JIT compiler to compile the application code into binary code to accelerate application execution, all object allocation locations need to encode the depth information of newly created or allocated objects into the object pointers based on steps S001 to S004 above. This allows the depth information to determine whether an object is a shallow traversal object during the marking phase of memory management, and the child object nodes of shallow traversal objects can be marked directly according to a certain traversal method without performing push and pop operations. This not only improves memory management efficiency but also reduces the occupation of stack space.

[0125] In some embodiments, step S004 above, "determining the final object pointer of the newly created object using the depth encoding information of the newly created object and the initial object pointer," can be implemented through the following steps:

[0126] Step S0041: Obtain the starting number of bits of the preset depth encoding information.

[0127] The starting bit length is greater than the total bit length of the initial object pointer. For example, if the initial object pointer is 0xabcd0000, meaning the total bit length is 32 bits, then the starting bit length must be greater than 32. This means that the depth-encoded information occupies the high bits that the initial object pointer does not occupy. For example, the starting bit length can be 44, 35, 48, etc.

[0128] Step S0042: The binary value of the encoding depth is shifted left according to the starting number of bits to obtain the shift depth information.

[0129] In step S0042, the binary value of the encoding depth is shifted left by the starting number of bits to obtain the shift depth information. For example, if the encoding depth is 2, the binary value of the encoding depth is 10, and the starting number of bits is 44, then the binary number 10 is shifted left by 44 bits to obtain the shift depth information 0x100000000000.

[0130] Step S0043: Perform a logical OR operation on the shift depth information and the initial object pointer to obtain the final object pointer of the newly created object.

[0131] Assuming the initial object pointer is 0xabcd0000 and the shift depth information is 0x100000000000, performing a logical OR operation between the shift depth information and the initial object pointer yields the final object pointer of the newly created object, 0x1000abcd0000.

[0132] When encoding the depth information of a newly created object into the object pointer, if the depth information is encoded in the unused low bits of the object pointer, all subsequent uses of the pointer will require additional operations to remove the encoded information, affecting performance. Therefore, in steps S0041 to S0043, the depth information is encoded in the high bits of the object pointer to obtain the final object pointer of the newly created object. The encoded depth of the object node can be obtained in the subsequent marking process through the following steps:

[0133] Step S005: Shift the object pointer of the object node to the right according to the starting bit position to obtain the depth encoding information of the object node.

[0134] Based on the distance mentioned above, the object pointer of the object node is 0x1000abcd0000, with a starting bit length of 44. When implementing step S005, 0x1000abcd0000 is shifted right by 44 bits to obtain the depth encoding information of the object node, 0x000000000001.

[0135] Step S006: Determine the decimal value of the depth encoding information as the encoding depth of the object node.

[0136] The decimal value of this depth encoding information is 2, therefore the encoding depth of this object node is 2.

[0137] As can be seen from the above steps S005 to S006, depth information is encoded in the high bits of the object pointer to obtain the final object pointer of the newly created object. In the subsequent marking process, only the object pointer needs to be shifted to determine the depth encoded information and the encoding depth. The overhead of the shift operation is almost zero compared to the memory read operation, thereby achieving the identification of shallow traversal objects at a lower cost and improving memory management efficiency.

[0138] Furthermore, deep information is encoded in the high-order bits of the object pointer to obtain the final object pointer of the newly created object. Based on this final object pointer, it can be effectively combined with heap multi-mapping to map heap physical memory to different virtual memory locations.

[0139] Step S201: Obtain the memory information of the heap physical memory.

[0140] Here, the memory information of the heap physical memory includes at least the storage space size of the heap physical memory, such as 16G, 32G, etc. In some embodiments, the memory information of the heap physical memory may also include the start address, end address, etc. of the heap physical memory.

[0141] Step S202: Based on the multi-mapping technology, the memory information, and the starting bit, the heap physical memory is mapped to virtual memory corresponding to different depth encoding information.

[0142] In implementation, the starting address of each virtual memory can be determined based on the starting bit and depth encoding information, and the space occupied by the virtual memory corresponding to different depth encoding information is the space occupied by the heap physical memory.

[0143] In this way, the heap is mapped to virtual memory addresses corresponding to different traversal depths using multi-mapping technology. Different types of object pointers point to the same heap, thus ensuring that object pointers with different encodings can work correctly when the program runs.

[0144] Based on the foregoing embodiments, this application further provides a memory management method applied to a server. Figure 5 This is a schematic diagram illustrating another implementation of the memory management method provided in the embodiments of this application, as shown below. Figure 5 As shown, the process includes:

[0145] Step S301: Obtain the initial object pointer of the newly created object allocated from the heap physical memory.

[0146] Step S302: Obtain the actual depth information and preset depth threshold of the newly created object.

[0147] Step S303: Determine the encoding depth of the newly created object based on the actual depth information of the newly created object and the depth threshold.

[0148] Step S304: Using the encoding depth of the newly created object and the initial object pointer, determine the final object pointer of the newly created object.

[0149] Step S305: When the memory management time is reached, obtain the root object node set.

[0150] The root object node is the object that is determined to be alive.

[0151] Step S306: Mark the object pointers of each root object node in the root object node set and add them to the marking stack.

[0152] In other words, the mark stack stores object pointers to live objects.

[0153] Step S307: Obtain the object pointer of the object node from the tag stack.

[0154] In implementing step S307, the object pointer at the top of the tag stack may be popped from the stack, and the object pointer includes the depth encoding information of the object node.

[0155] Step S308: Determine whether the encoding depth determined based on the depth encoding information of the object node is lower than a preset depth threshold.

[0156] When the encoding depth is lower than the preset depth threshold, it indicates that the actual depth of the object node is small and can be considered as a shallow traversal object. At this time, proceed to step S309. When the encoding depth is not lower than the depth threshold, it indicates that the object node is not a shallow traversal object. At this time, proceed to step S315.

[0157] Step S309: Determine whether the object node is a leaf node.

[0158] Determining whether an object node is a leaf node can be achieved by checking if its encoding depth is 0. If the encoding depth is not 0, the object node is not a leaf node, meaning it has child nodes, and the process proceeds to step S310. If the encoding depth is 0, the object node is a leaf node, meaning it has no child nodes, and the process exits the marking process for that object node and proceeds to step S318.

[0159] Step S310: Obtain and mark the child object nodes of the object node.

[0160] Step S311: Obtain the encoding depth of the sub-object node.

[0161] Step S312: Determine whether the encoding depth of the child object node is less than the traversal depth of the object node.

[0162] When the encoding depth of a child object node is less than the traversal depth of the object node, it indicates that the child object node is also a shallow traversal node, and the process proceeds to step S313. When the encoding depth of a child object node is greater than or equal to the depth threshold, it indicates that the actual depth information calculated statically does not match the runtime information, and the process proceeds to step S314.

[0163] Step S313: Mark the child object nodes of the child object node according to the preset traversal method until the leaf node is marked.

[0164] The implementation of this step is similar to that of step S102 in the aforementioned embodiment. Specifically, it first marks the child nodes of the child object node, then determines whether the child node of the child object node is a leaf node. If the child node of the child object node is a leaf node, the marking process for that child object node is exited, and the next child object node is marked. If the child node of the child object node is not a leaf node, the child nodes of the child object node of the child object node are marked according to a preset traversal method until a leaf node is marked. The preset traversal method can be a depth-first traversal method, a breadth-first traversal method, etc.

[0165] After step S313, proceed to step S318.

[0166] Step S314: Add the marked child object node to the marking stack.

[0167] Because class inheritance is common in most programming languages, allowing a field of a class to store a sub-object of that class, the statically calculated traversal depth may not match the runtime depth. If the actual depth information calculated statically does not match the runtime depth information, then the sub-object is treated as a non-shallow traversal, and the marked object node is added to the marking stack. After step S314, the process proceeds to step S318 to continue marking the sub-object nodes of other object nodes in the marking stack.

[0168] Step S315: Obtain the child object nodes of the object node.

[0169] When the traversal depth of an object node is determined to be no less than a depth threshold based on the depth encoding information of the object node, it means that the object node is not a shallow traversal object. In this case, only the child object nodes of the object node are marked.

[0170] Step S316: If the child object node is not marked, mark the child object node.

[0171] Since the child nodes of this object node may be child nodes of other object nodes, and the child nodes of other object nodes have already been marked, only the unmarked child nodes are marked in this step.

[0172] Step S317: Add the marked child object node to the marking stack.

[0173] Step S318: Mark the child objects of the other object nodes based on the depth encoding information of the other object nodes in the marking stack until the marking stack is empty.

[0174] If the object node retrieved above is a leaf node, or if all the child object nodes of the object node popped from the stack have been marked, then continue to pop an object node from the marking stack and perform the marking process until the marking stack is empty. At this point, the marking of the live objects in the entire class relationship graph is completed.

[0175] Step S319: Based on the marked object nodes, determine the unmarked target object nodes and delete the target object nodes to release the memory space corresponding to the target object nodes.

[0176] In the memory management method provided in this application embodiment, after creating an initial object pointer for a new object node from the heap physical memory, the actual depth information of the new object is determined by loading the Class information of the new object, and the encoding depth is determined based on the depth threshold. The encoding depth is encoded into the unused high bits of the object pointer to obtain the final object pointer with depth encoding information. In the marking phase of memory management, the traversal depth of the object node is obtained by shifting the object pointer. When it is determined based on the encoding depth that the object node is not a shallow traversal object, the child object nodes of the object node are marked and pushed onto the stack. When the object node is a shallow traversal object, the child object nodes of the object node are not marked and pushed onto the stack again. Instead, the child object nodes of the object node are marked directly through a preset traversal method. This not only reduces the space occupied by the marking stack, but also reduces the memory access of the class fields of the child object nodes of the shallow traversal object node, thereby reducing the time spent in the marking phase and improving memory management efficiency.

[0177] The following will describe an exemplary application of the embodiments of this application in a real-world application scenario.

[0178] This application provides a memory management method in which, during object allocation, the high-order unused bits of the object pointer are used to store the traversal depth of the object. Then, during the GC Marking stage, the traversal depth stored in the object pointer is used to identify shallowly traversed objects, thereby improving memory management efficiency.

[0179] The memory management method provided in this application can be applied to the memory management module of all tracing-based language virtual machine runtimes to reduce CPU and memory consumption during the GC Mark phase. It is a low-level software optimization and has inherent universality. The improvement is greater for applications with more shallowly traversed objects, especially under large memory heaps, where the number of objects to be processed is in the billions, resulting in a significant improvement in GC Mark time.

[0180] Currently, it is mainly used in the big data field, such as various Java big data applications like Hadoop, HBase, and Zookeeper. These applications typically use large heaps and cache a lot of data. For example, Zookeeper usually caches a large amount of configuration information, which is usually stored in the form of strings. In Java, a String object only contains a single byte array. If the GC needs to traverse the object tree starting from the String object, it only needs to traverse down one level to reach the leaf node byte array. Therefore, String is a shallow traversal object. Thus, during the GC Marking phase, if shallow traversal objects like String are directly marked using DFS traversal, the number of pushes and pops from the String itself and its child byte arrays can be reduced, thereby significantly reducing the GC Marking time and Mark Stack memory consumption.

[0181] By using color pointers to encode the traversal depth of the current object in the high-order bits of the object pointer returned during object allocation, and then directly using the object pointer retrieved from the Mark Stack to perform bitwise decoding of the traversal depth during the GC Mark phase, shallow traversal objects can be distinguished in a near-zero-overhead manner. This accelerates the processing of shallow traversal objects, reduces the time for popping and pushing shallow traversal objects onto the stack, memory access, and the Mark Stack space required for pushing them onto the stack, thereby improving the efficiency of the GC Mark phase.

[0182] The implementation process of the memory management method provided in the embodiments of this application is described below.

[0183] The memory management method provided in this application can be implemented through the following three steps:

[0184] Step S601, color pointer encoding design.

[0185] In this embodiment, to effectively transmit the traversal depth information of a shallow traversal object, a portion of the unused bits in the high-order bits of the object pointer are used to encode the object's depth information. Encoding information in the high-order bits of the object pointer can be effectively combined with heap multi-mapping, ensuring that pointers with different color codes point to the same heap and can be used normally without decoding. However, the number of unused bits in the low-order bits of the object pointer is limited (in a 64-bit system, the lowest 3 bits are unused). If color information is encoded in the low-order bits, all subsequent uses of the pointers would require additional operations to remove the encoded information, impacting performance.

[0186] like Figure 6AAs shown, for a 64-bit object pointer, D bits starting from the Kth bit can be selected as the encoding field 501 for the object's traversal depth, which can encode... This depth information, that is, the traversal depth information, corresponds to... A variety of colors.

[0187] For example, when the selected width is 2, that is, D=2, such as Figure 6B The objects shown can be divided into four categories: three shallow traversal objects and one ordinary object.

[0188] The binary encoding of the traversal depth of the shallow traversal object 611 with a traversal depth of 0 is: The pointer to an object with this type of encoding is a leaf node pointer, that is, it does not contain any child nodes, such as various primitive array objects (byte[], short[], int[], etc.);

[0189] The binary encoding of the traversal depth of the shallow traversal object 612 with a traversal depth of 1 is: When traversing pointers to objects of this type, it is necessary to traverse down one level to reach the leaf node, such as the String object commonly found in Java;

[0190] The binary encoding of the traversal depth of the shallow traversal object 613 with a traversal depth of 2 is: When traversing this object, it is necessary to traverse down two levels to reach the leaf node, such as a String[] object;

[0191] For a regular object 614, the binary encoding of its traversal depth is: Ordinary objects may contain child nodes of any depth, and they do not require special handling in GC Marking like the three types of shallow traversal objects mentioned earlier.

[0192] When K=44 and D=2 are selected, for the object pointer 0xabcd0000 just allocated from the heap, different traversal depths can be encoded for this pointer based on the class pointer graph contained in the object's class information, such as... Figure 7 As shown, if the object is a shallow traversal object with a traversal depth of 0, the final object pointer is 0xabcd0000; if it is a shallow traversal object with a traversal depth of 1, the final object pointer is 0x1000abcd0000; if it is a shallow traversal object with a traversal depth of 2, the final object pointer is 0x2000abcd0000; and if it is a regular object, the final object pointer is 0x3000abcd0000. To ensure that object pointers with different encodings work correctly at runtime—that is, that object pointers of different types see the same heap—the heap needs to be mapped to the virtual memory addresses corresponding to different traversal depth encodings using multi-mapping technology. Figure 7The heap where the pointer resides needs to be mapped to the physical memory corresponding to the heap, and simultaneously mapped to a certain offset of the virtual address corresponding to 0x0, 0x100000000000, 0x200000000000, or 0x3000000000000.

[0193] Step S602: Generation of color information in the object pointer.

[0194] To provide traversal depth information to the Mark phase of GC, in step S601, the traversal depth is encoded as a color into the object pointer during object allocation. The virtual machine runtime typically uses an interpreter to interpret the application's code and a JIT compiler to compile the application code into binary code to accelerate application execution. Therefore, the following logical modifications are required at all object allocation points:

[0195] First, when calling object allocation in the Interpreter, the traversal depth information needs to be encoded into the allocated object pointer.

[0196] Second, the JIT compiler needs to add logic to encode color information in the code generation for object allocation so that the final allocated object pointer contains traversal depth information.

[0197] Figure 8 The document describes the runtime logic for adding traversal depth during object allocation, such as... Figure 8 The steps shown are as follows:

[0198] Step S801: Create an object obj.

[0199] Step S802: Determine whether the object is a shallow traversal object, that is, determine whether the depth of its type (Class) reaching any leaf node type (Leaf Child Class) is less than the maximum encoding length (2). D -1).

[0200] If the depth to which the type of the object reaches all leaf node types (Leaf Child Class) is less than the maximum encoding length (2... D -1) indicates that the object is a shallow traversal object, and proceed to step S803; if the depth of any leaf node type (Leaf Child Class) is greater than or equal to the maximum encoding length (2 D -1), determine that the object is not a shallow traversal object, and then proceed to step S804.

[0201] Step S803: Determine the traversal depth information as depth(Class).

[0202] Step S804: Determine the traversal depth information as 2. D -1.

[0203] Step S805: Encode different traversal depths into the final object pointer based on the shallow traversal object information.

[0204] The traversal depth information of an object can be statically calculated when the object's type information is loaded. For example, in Java, it can be statically calculated during class loading; that is, the `depth(Class)` function can be calculated and stored once during type loading for subsequent calls. The `depth(Class)` function can be calculated using Dijkstra's algorithm. Figure 8 As shown in the right-hand box 811, starting from the current class, traverse its child nodes to the leaf nodes to construct a class reference graph. The weight of each edge is set to -1. The maximum length from the current class to any other leaf node can be transformed into the Shortest path problem[1]. Finally, the maximum value of the maximum length from the current class to all leaf node classes is the traversal depth of the current class.

[0205] Because class inheritance exists in most programming languages, a field of a class can store a sub-object of the corresponding class. This can cause a mismatch between the statically calculated traversal depth and the runtime. However, since all object pointers carry traversal depth information, the runtime can easily identify these dynamic mismatches in traversal depth processing. For example, if a mismatched object pointer is encountered, the runtime can fall back to the default processing.

[0206] Step S603, GC marking phase, processing of color pointers.

[0207] Tracing-based memory management GC modules typically require a Mark phase to mark all live objects, then clean up the remaining unmarked dead objects in subsequent phases. The GC Mark phase usually starts from a set of root object nodes (such as object pointers on the thread stack) and recursively marks the entire live object graph, thus marking every object in the live object graph. Figure 9 The diagram shows the marking process of "marking first and then pushing onto the stack". Other marking methods, such as "pushing onto the stack first and then marking", only differ in the location of the "marking object" function method call in the flowchart.

[0208] Figure 9 This is a schematic diagram illustrating the implementation process of color pointer processing during the GC marking phase, as provided in an embodiment of this application. Figure 9 As shown, the process includes:

[0209] Step S901: Determine if the Mark Stack is empty.

[0210] If the Mark Stack is not empty, proceed to step S902; if the Mark Stack is empty, proceed to step S906.

[0211] Step S902: Pop an object pointer.

[0212] Step S903: Check if the object pointer is a shallow-traversed object.

[0213] In implementation, the traversal depth of the object is obtained through a shift operation, and this depth is used to check whether the object is a shallow traversal object. If the depth... obj Less than If the object pointer is a shallow traversal object, proceed to step S904; if the object pointer is not a shallow traversal object, proceed to step S905.

[0214] Step S904: Mark all child objects of the object to the leaf nodes using DFS.

[0215] Figure 9 The left-hand marker box 911 contains the implementation code for step S904. This code shows that step S904 includes the following steps:

[0216] In step S9041, if a leaf node is reached, return directly.

[0217] Step S9042: Traverse all child node objects of the object. First, mark the child nodes. If they are already marked, continue to the next child node.

[0218] In step S9043, if the traversal depth of the child node in step S9042 is less than depthobj, that is, the node is on the path that needs to be recursively marked, then continue to scan the child node using DFS.

[0219] In step S9044, if the traversal depth of the child node in step S9042 is not less than depthobj, then the node is a dynamically generated subclass node, which is an exception to the static analysis of traversal depth in the previous section. The pointer of the node needs to be put into the Mark Stack for subsequent processing.

[0220] Step S905: Mark all child objects of the object.

[0221] If depth obj equal If the object is not marked, the traditional Marking process will be followed, that is, the child objects of the object will be marked, and if the object is not marked, it will be put into the Mark Stack.

[0222] In the memory management method provided in this application embodiment, the high-bit encoding of the traversal depth of the current object is used by the color pointer when the object is allocated, and the traversal depth is directly decoded by the object pointer retrieved from the Mark Stack during the GC Mark phase. This can distinguish shallow traversal objects in a near-zero-overhead manner, thereby reducing the workload of the GC Mark phase, accelerating the processing of shallow traversal objects, reducing the time for popping and pushing shallow traversal objects onto the stack, memory access, and the Mark Stack space required for pushing them onto the stack, and improving the efficiency of the GC Mark phase.

[0223] The following description continues to illustrate the exemplary structure of the memory management device 443 provided in the embodiments of this application as a software module. In some embodiments, such as Figure 2 As shown, the software modules stored in the memory management device 443 of the memory 440 may include:

[0224] The first acquisition module 4431 is used to acquire an object pointer of an object node from the tag stack when it is determined that the memory management time has been reached. The object pointer includes the depth encoding information of the object node.

[0225] The first marking module 4432 is used to mark the child object nodes of the object node according to a preset traversal method until the leaf node is marked when the encoding depth of the object node is determined to be lower than a preset depth threshold based on the depth encoding information.

[0226] The second marking module 4433 is used to mark the child objects of other object nodes based on the depth encoding information of other object nodes in the marking stack until the marking stack is empty;

[0227] The clearing module 4434 is used to determine unmarked target object nodes based on the marked object nodes, and delete the target object nodes to release the memory space corresponding to the target object nodes.

[0228] In some embodiments, the device further includes:

[0229] The second acquisition module is used to obtain the initial object pointer of the newly created object allocated from the heap physical memory;

[0230] The third acquisition module is used to acquire the actual depth information and preset depth threshold of the newly created object;

[0231] The first determining module is used to determine the encoding depth of the newly created object based on the actual depth information of the newly created object and the depth threshold.

[0232] The second determining module is used to determine the final object pointer of the newly created object by using the encoding depth of the newly created object and the initial object pointer.

[0233] In some embodiments, the third acquisition module is further configured to:

[0234] Obtain the type information of the newly created object;

[0235] Load the type information to determine the actual depth information of the newly created object.

[0236] In some embodiments, the first determining module is further configured to:

[0237] When the actual depth information is less than the depth threshold, the actual depth information is determined as the encoding depth of the newly created object;

[0238] When the actual depth information is greater than or equal to the depth threshold, the depth threshold is determined as the encoding depth of the newly created object.

[0239] In some embodiments, the second determining module is further configured to:

[0240] Obtain the starting bit length of the preset depth encoding information, wherein the starting bit length is greater than the total bit length of the initial object pointer;

[0241] The binary value of the encoding depth is determined as the depth encoding information of the object node;

[0242] The depth encoding information is shifted left according to the starting number of bits to obtain the shifted depth information;

[0243] The shift depth information and the initial object pointer are logically ORed to obtain the final object pointer of the newly created object.

[0244] In some embodiments, the device further includes:

[0245] The shift module is used to shift the object pointer of the object node to the right according to the starting number of bits to obtain the depth encoding information;

[0246] The third determining module is used to determine the decimal value of the depth encoding information as the encoding depth of the object node.

[0247] In some embodiments, the first marking module is further configured to:

[0248] When it is determined based on the depth encoding information that the encoding depth of the object node is lower than a preset depth threshold, it is determined whether the object node is a leaf node.

[0249] When the object node is not a leaf node, obtain and mark the child object nodes of the object node;

[0250] Obtain the encoding depth of the child object node;

[0251] When the encoding depth of the child object node is less than the encoding depth of the object node, the child object nodes of the child object node are marked according to the preset traversal method until the leaf node is marked.

[0252] In some embodiments, the device further includes:

[0253] The first push-to-stack module is used to add the marked child object node to the marking stack when the encoding depth of the child object node is greater than or equal to the encoding depth of the object node.

[0254] In some embodiments, the device further includes:

[0255] The fourth acquisition module is used to acquire the child object nodes of the object node when it is determined based on the depth encoding information that the encoding depth of the object node is not lower than a preset depth threshold.

[0256] The third marking module is used to mark the child node of the child object if the child object node is not marked.

[0257] The second push module is used to add the marked child object node to the marking stack.

[0258] In some embodiments, the device further includes:

[0259] The fifth acquisition module is used to acquire the memory information of the heap physical memory;

[0260] The mapping module is used to map the heap physical memory to virtual memory corresponding to different depth encoding information based on multiple mapping technology, the memory information, and the starting bit.

[0261] It should be noted that the descriptions of the above memory management device embodiments are similar to the descriptions of the above methods, and have the same beneficial effects as the method embodiments. For technical details not disclosed in the memory management device embodiments of this application, those skilled in the art should refer to the descriptions of the method embodiments of this application for understanding.

[0262] This application provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the memory management method described above in this application.

[0263] This application provides a computer-readable storage medium storing executable instructions. When these executable instructions are executed by a processor, they cause the processor to perform the method provided in this application, for example... Figure 3 , Figure 4 , Figure 5 The method shown.

[0264] In some embodiments, the computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or it may be a variety of devices including one or any combination of the above-mentioned memories.

[0265] In some embodiments, executable instructions may take the form of a program, software, software module, script, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a standalone program or as a module, component, subroutine, or other unit suitable for use in a computing environment.

[0266] As an example, executable instructions may, but do not necessarily, correspond to files in a file system. They may be stored as part of a file that holds other programs or data, for example, in one or more scripts in a Hyper Text Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple collaborating files (e.g., a file that stores one or more modules, subroutines, or code sections).

[0267] As an example, executable instructions can be deployed to execute on a single computing device, or on multiple computing devices located in one location, or on multiple computing devices distributed across multiple locations and interconnected via a communication network.

[0268] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, and improvements made within the spirit and scope of this application are included within the scope of protection of this application.

Claims

1. A memory management method characterized by comprising: include: When it is determined that the memory management time has been reached, the object pointer of the object node is obtained from the mark stack. The object pointer includes the depth encoding information of the object node. The depth encoding information is obtained by encoding the traversal depth of the object node. The traversal depth is determined based on the actual depth information of the object node and a preset depth threshold. The actual depth information is determined based on the type information of the object node. When it is determined based on the depth encoding information that the encoding depth of the object node is lower than the preset depth threshold, the child object nodes of the object node are marked according to the preset traversal method until the leaf node is marked; The child objects of the other object nodes are marked based on the depth encoding information of the other object nodes in the marking stack until the marking stack is empty; Based on the marked object nodes, determine the unmarked target object nodes, delete the target object nodes, and release the memory space corresponding to the target object nodes.

2. The method of claim 1, wherein, The method further includes: Get the initial object pointer of the newly created object allocated from the heap physical memory; Obtain the actual depth information and preset depth threshold of the newly created object; The encoding depth of the newly created object is determined based on the actual depth information of the newly created object and the depth threshold. The final object pointer of the newly created object is determined using the encoding depth of the newly created object and the initial object pointer.

3. The method of claim 2, wherein, The step of obtaining the actual depth information of the newly created object includes: Obtain the type information of the newly created object; Load the type information to determine the actual depth information of the newly created object.

4. The method according to claim 2, characterized in that, Determining the encoding depth of the newly created object based on its actual depth information and the depth threshold includes: When the actual depth information is less than the depth threshold, the actual depth information is determined as the encoding depth of the newly created object; When the actual depth information is greater than or equal to the depth threshold, the depth threshold is determined as the encoding depth of the newly created object.

5. The method according to claim 2, characterized in that, The step of determining the final object pointer of the newly created object using the encoding depth of the newly created object and the initial object pointer includes: Obtain the starting bit length of the preset depth encoding information, wherein the starting bit length is greater than the total bit length of the initial object pointer; The binary value of the encoding depth is determined as the depth encoding information of the newly created object; The depth encoding information is shifted left according to the starting number of bits to obtain the shifted depth information; The shift depth information and the initial object pointer are logically ORed to obtain the final object pointer of the newly created object.

6. The method according to claim 5, characterized in that, The method further includes: The object pointer of the object node is shifted to the right according to the starting number of bits to obtain the depth encoding information; The decimal value of the depth encoding information is determined as the encoding depth of the object node.

7. The method according to claim 1, characterized in that, When the encoding depth of the object node is determined to be lower than the preset depth threshold based on the depth encoding information, the child object nodes of the object node are marked according to a preset traversal method until the leaf node is marked, including: When it is determined based on the depth encoding information that the encoding depth of the object node is lower than the preset depth threshold, it is determined whether the object node is a leaf node; When the object node is not a leaf node, obtain and mark the child object nodes of the object node; Obtain the encoding depth of the child object node; When the encoding depth of the child object node is less than the encoding depth of the object node, the child object nodes of the child object node are marked according to the preset traversal method until the leaf node is marked.

8. The method according to claim 7, characterized in that, The method further includes: When the encoding depth of the child object node is greater than or equal to the encoding depth of the object node, the marked child object node is added to the marking stack.

9. The method according to claim 1, characterized in that, The method further includes: When it is determined based on the depth encoding information that the encoding depth of the object node is not lower than a preset depth threshold, the child object nodes of the object node are obtained; If the child object node is not marked, mark the child object node; The marked child object node is added to the marking stack.

10. The method according to claim 5, characterized in that, The method further includes: Obtain the memory information of the heap physical memory; Based on the multi-mapping technique, the memory information, and the starting bit, the heap physical memory is mapped to virtual memory corresponding to different depth encoding information.

11. A memory management device, characterized in that, include: The first acquisition module is used to acquire an object pointer of an object node from the tag stack when it is determined that the memory management time has been reached. The object pointer includes the depth encoding information of the object node. The depth encoding information is obtained by encoding the traversal depth of the object node. The traversal depth is determined based on the actual depth information of the object node and a preset depth threshold. The actual depth information is determined based on the type information of the object node. The first marking module is used to mark the child object nodes of the object node according to a preset traversal method until the leaf node is marked when the encoding depth of the object node is determined to be lower than the preset depth threshold based on the depth encoding information. The second marking module is used to mark the child objects of other object nodes based on the depth encoding information of other object nodes in the marking stack until the marking stack is empty; The clearing module is used to determine unmarked target object nodes based on the marked object nodes, delete the target object nodes, and release the memory space corresponding to the target object nodes.

12. A memory management device, characterized in that, include: Memory, used to store executable instructions; A processor, when executing executable instructions stored in the memory, implements the memory management method according to any one of claims 1 to 10.

13. A computer-readable storage medium, characterized in that, It stores executable instructions for implementing the memory management method according to any one of claims 1 to 10 when executed by a processor.

Citation Information

Patent Citations

  • CN111258926A

  • US20130151565A1