Memory optimization method, apparatus and device, and storage medium
Through dynamic addressing and expanded memory management parameters, the system lag caused by frequent garbage collection in Android systems is solved, and the fluency and stability of the equipment are improved.
Patent Information
- Application Number
- PCT/CN2024/119604
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-12-05
- Filing Date
- 2024-09-19
- Publication Date
- 2025-06-12
AI Technical Summary
The system stuttering due to memory reasons during use of the Android system is mainly due to the frequent garbage collection operations of the operating system, which leads to the unresponsiveness of the application.
By responding to memory adjustment events for the target application, obtaining its virtual machine running instance, and dynamically addressing based on the running status address and preset memory management instance, positioning the heap memory instance. Then, the initial memory management parameters are obtained based on the instance address and pointer position of the memory management instance, and the capacity expansion processing is performed according to the device performance parameters to obtain the capacity expansion memory management parameters for memory optimization.
It reduces the number of memory recycling times the system performs, reduces the resource usage of memory recycling threads, and improves the fluency and stability of the device.
Smart Images

Figure CN2024119604_12062025_PF_FP_ABST
Abstract
Description
Memory optimization method, device, equipment and storage medium
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on December 5, 2023, with application number 202311658525.X and application name “Memory Optimization Method, Device, Equipment and Storage Medium”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of memory control technology, and in particular to a memory optimization method, apparatus, device and storage medium. Background Art
[0003] With the rapid development of smart devices and mobile operating systems, the number of smart devices powered by the Android system is increasing. The Android system is popular among developers and users for its high degree of freedom, open source nature, and affordability. However, during use, the Android system may experience system lag due to memory issues. Specifically, due to frequent daily user operations of various application functions, applications are constantly requesting and releasing memory, causing the operating system to frequently perform garbage collection operations on memory, resulting in application unresponsiveness. In such application unresponsiveness scenarios, the garbage collection thread preempts the smart device processor's time slice, preventing other threads from executing, thereby causing system lag. Technical Solutions
[0004] The embodiments of the present application provide a memory optimization method, apparatus, device, and storage medium, which aim to solve the technical problem in the prior art that an operating system frequently performs garbage collection operations, resulting in unresponsive applications and system freezes.
[0005] In one aspect, an embodiment of the present application provides a memory optimization method, the memory optimization method comprising the following steps:
[0006] In response to a memory adjustment event for a target application, obtaining a virtual machine running instance of the target application; the memory adjustment event is an application adjustment event requesting to reduce garbage collection event activity of the target application;
[0007] Performing dynamic addressing based on the running state address of the virtual machine running instance and a preset memory management instance to locate the heap memory instance of the target application;
[0008] Acquire initial memory management parameters of the heap memory instance according to the instance address and pointer position of the memory management instance in the heap memory instance, wherein the initial memory management parameters include an initial minimum memory threshold and an initial maximum memory threshold;
[0009] The initial memory management parameters are expanded according to the device performance parameters to obtain expanded memory management parameters, and memory optimization processing is performed on the target application based on the expanded memory management parameters.
[0010] In a possible implementation of the present application, the dynamic addressing based on the running state address of the virtual machine running instance and the preset memory management instance to locate the heap memory instance of the target application includes:
[0011] Obtaining the running state address of the running instance of the virtual machine by loading a preset addressing method of the target application source code corresponding to the target application;
[0012] Traversing each running instance in the virtual machine running instance based on the running state address and the preset anchor instance address to obtain a candidate addressing instance;
[0013] A secondary search is performed on the candidate addressing instance based on a preset memory management instance to locate the heap memory instance containing the memory management instance.
[0014] In a possible implementation of the present application, traversing each running instance in the virtual machine running instance based on the running state address and the preset anchor instance address to obtain a candidate addressing instance includes:
[0015] Acquire each running instance and a preset anchor instance in the running instance of the virtual machine based on the running state address;
[0016] The running instances are traversed according to the preset anchor instance and the preset search range to obtain candidate addressing instances.
[0017] In a possible implementation of the present application, obtaining the initial memory management parameters of the heap memory instance according to the instance address and pointer position of the memory management instance in the heap memory instance includes:
[0018] Obtaining the instance address and pointer position of the memory management instance in the heap memory instance;
[0019] Perform a first shift operation according to the instance address and the pointer position to obtain an initial minimum memory threshold in the heap memory instance;
[0020] Perform a second shift operation according to the instance address and the pointer position to obtain an initial maximum memory threshold in the heap memory instance;
[0021] The initial minimum memory threshold and the initial maximum memory threshold are set as initial memory management parameters of the heap memory instance.
[0022] In a possible implementation of the present application, the expanding the initial memory management parameters according to the device performance parameters to obtain the expanded memory management parameters includes:
[0023] Obtain device performance parameters corresponding to the target application, the device performance parameters including device memory capacity and current performance indicators;
[0024] Expanding the initial minimum memory threshold based on the initial maximum memory threshold and the device performance parameter to obtain an expanded minimum memory threshold;
[0025] Expanding the initial maximum memory threshold according to the device memory capacity and the current performance indicator to obtain an expanded maximum memory threshold;
[0026] The minimum memory expansion threshold and the maximum memory expansion threshold are set as expansion memory management parameters of the target application.
[0027] In a possible implementation of the present application, the maximum memory expansion threshold includes any one of a first maximum memory expansion threshold and a second maximum memory expansion threshold;
[0028] The expanding the initial maximum memory threshold according to the device memory capacity and the current performance indicator to obtain the expanded maximum memory threshold includes:
[0029] Calculating a current expansion score of the target application based on the device memory capacity and the current performance indicator;
[0030] If the current expansion score is less than the preset expansion threshold, the initial maximum memory threshold is expanded according to the first expansion multiple to obtain a first expansion maximum memory threshold;
[0031] If the current expansion score is greater than a preset expansion threshold, the initial maximum memory threshold is expanded according to a second expansion multiple to obtain a second expanded maximum memory threshold, wherein the first expansion multiple is less than the second expansion multiple.
[0032] In a possible implementation of the present application, the performing memory optimization processing on the target application based on the expanded memory management parameter further includes:
[0033] Updating the initial memory reclaiming policy of the target application according to the minimum memory threshold for expansion and the maximum memory threshold for expansion to obtain an updated memory reclaiming policy;
[0034] Memory optimization processing is performed on the target application based on the updated memory reclaiming policy and the current application memory of the target application.
[0035] On the other hand, the present application provides a memory optimization device, the memory optimization device comprising:
[0036] An instance acquisition module is configured to respond to a memory adjustment event for a target application and acquire a virtual machine running instance of the target application; the memory adjustment event is an application adjustment event requesting to reduce garbage collection event activity of the target application;
[0037] a heap memory locating module configured to perform dynamic addressing based on the running state address of the virtual machine running instance and a preset memory management instance to locate the heap memory instance of the target application;
[0038] a parameter acquisition module configured to acquire initial memory management parameters of the heap memory instance according to the instance address and pointer position of the memory management instance in the heap memory instance, the initial memory management parameters including an initial minimum memory threshold and an initial maximum memory threshold;
[0039] The memory expansion module is configured to expand the initial memory management parameters according to the device performance parameters to obtain expanded memory management parameters, and perform memory optimization processing on the target application based on the expanded memory management parameters.
[0040] On the other hand, the present application also provides a memory optimization device, the memory optimization device comprising:
[0041] one or more processors;
[0042] Memory; and
[0043] One or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the processor to implement the steps of the memory optimization method.
[0044] On the other hand, the present application also provides a computer-readable storage medium having a computer program stored thereon, and the computer program is loaded by a processor to execute the steps in the memory optimization method.
[0045] In this application, by responding to a memory adjustment event for a target application, a virtual machine running instance of the target application is obtained; the memory adjustment event is an application adjustment event that requests to reduce the activity of the garbage collection event of the target application; dynamic addressing is performed based on the running state address of the virtual machine running instance and a preset memory management instance to locate the heap memory instance of the target application; the initial memory management parameters of the heap memory instance are obtained according to the instance address and pointer position of the memory management instance in the heap memory instance, and the initial memory management parameters include an initial minimum memory threshold and an initial maximum memory threshold; the initial memory management parameters are expanded according to the device performance parameters to obtain expanded memory management parameters, and memory optimization processing is performed on the target application based on the expanded memory management parameters. By dynamically addressing the virtual machine corresponding to the application to be memory optimized, the memory management parameters of the application are obtained, and the memory management parameters are modified, thereby reducing the number of memory recycling times of the system, reducing the resource usage of the system memory recycling thread, and improving the fluency and stability of the device. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0047] FIG1 is a schematic diagram of a scenario of a memory optimization method according to an embodiment of the present application;
[0048] FIG2 is a flow chart of an embodiment of a memory optimization method according to an embodiment of the present application;
[0049] FIG3 is a flow chart of an embodiment of expanding the initial maximum memory threshold in the memory optimization method provided in an embodiment of the present application;
[0050] FIG4 is a flow chart of an embodiment of performing memory optimization processing on the target application based on the expanded memory management parameters in the memory optimization method provided in an embodiment of the present application;
[0051] FIG5 is a schematic structural diagram of an embodiment of a memory optimization device provided in an embodiment of the present application;
[0052] FIG6 is a schematic structural diagram of an embodiment of a memory optimization device provided in an embodiment of the present application.
[0053] Implementation Methods of the Application
[0054] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without making creative efforts are within the scope of protection of this application.
[0055] In the description of the present application, it should be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside" and the like indicate orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present application. In addition, the terms "first" and "second" are used for descriptive purposes only and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the said features. In the description of the present application, "multiple" means two or more, unless otherwise clearly and specifically defined.
[0056] In this application, the word "exemplary" is used to mean "serving as an example, illustration, or illustration." Any embodiment described in this application as "exemplary" is not necessarily to be construed as preferred or advantageous over other embodiments. The following description is given to enable any person skilled in the art to implement and use the present application. In the following description, details are listed for the purpose of explanation. It should be understood that one of ordinary skill in the art can recognize that the present application can be implemented without using these specific details. In other instances, well-known structures and processes are not elaborated in detail to avoid obscuring the description of the present application with unnecessary details. Therefore, the present application is not intended to be limited to the embodiments shown, but is consistent with the widest scope consistent with the principles and features disclosed in this application.
[0057] With the rapid development of smart devices and mobile operating systems, the number of smart devices powered by the Android system is increasing. The Android system is popular among developers and users for its high degree of freedom, open source nature, and affordability. However, during use, the Android system may experience system lag due to memory issues. Specifically, due to frequent daily user operations of various application functions, applications are constantly requesting and releasing memory, causing the operating system to frequently perform garbage collection operations on memory, resulting in application unresponsiveness. In such application unresponsiveness scenarios, the garbage collection thread preempts the smart device processor's time slice, preventing other threads from executing, thereby causing system lag.
[0058] Based on this, the present application proposes a memory optimization method, apparatus, device and computer-readable storage medium to solve the technical problem in the prior art that the operating system frequently performs garbage collection operations, resulting in application unresponsiveness and system freezes.
[0059] The memory optimization method in the embodiment of the present application is applied to a memory optimization device, and the memory optimization device is arranged in a memory optimization device. The memory optimization device is provided with one or more processors, memories, and one or more applications, wherein the one or more applications are stored in the memories and are configured to be executed by the processor to implement the memory optimization method; wherein the memory optimization device can be a smart terminal, such as a mobile phone, a tablet computer, a network device, and a smart computer.
[0060] As shown in Figure 1, Figure 1 is a scenario diagram of the memory optimization method in an embodiment of the present application. The memory optimization scenario in the embodiment of the present application includes a memory optimization device 100 (a memory optimization device is integrated in the memory optimization device 100), and a computer-readable storage medium corresponding to the memory optimization method is running in the memory optimization device 100 to execute the steps of the memory optimization method.
[0061] It can be understood that the memory optimization device in the memory optimization method scenario shown in Figure 1, or the devices included in the memory optimization device, does not constitute a limitation on the embodiments of the present application, that is, the number of devices and types of devices of the memory optimization device included in the memory optimization method scenario, or the number and types of devices included in each device do not affect the overall implementation of the technical solution in the embodiments of the present application, and can all be regarded as equivalent replacements or derivatives of the technical solution claimed to be protected in the embodiments of the present application.
[0062] In the embodiment of the present application, the memory optimization device 100 is mainly used to: respond to a memory adjustment event for a target application, and obtain a virtual machine running instance of the target application; the memory adjustment event is an application adjustment event requesting to reduce the activity of garbage collection events of the target application; dynamically addressing is performed based on the running status address of the virtual machine running instance and a preset memory management instance to locate the heap memory instance of the target application; the initial memory management parameters of the heap memory instance are obtained according to the instance address and pointer position of the memory management instance in the heap memory instance, and the initial memory management parameters include an initial minimum memory threshold and an initial maximum memory threshold; the initial memory management parameters are expanded according to the device performance parameters to obtain expanded memory management parameters, and the target application is memory optimized based on the expanded memory management parameters.
[0063] The memory optimization device 100 in the embodiment of the present application can be an independent memory optimization device, such as a smart terminal such as a mobile phone, tablet computer, network device, server and smart computer, or it can be a memory optimization network or memory optimization cluster composed of multiple memory optimization devices.
[0064] The embodiments of the present application provide a memory optimization method, apparatus, device, and computer-readable storage medium, which are described in detail below.
[0065] Those skilled in the art will understand that the application environment shown in FIG1 is merely one of the application scenarios related to the solution of the present application, and does not constitute a limitation on the application scenario of the solution of the present application. Other application environments may also include more or fewer memory optimization devices than shown in FIG1 , or memory optimization network connection relationships. For example, only one memory optimization device is shown in FIG1 , and it can be understood that the scenario of the memory optimization method may also include one or more memory optimization devices, which are not specifically limited here; the memory optimization device 100 may also include a memory for storing application data and other data.
[0066] It should be noted that the scenario diagram of the memory optimization method shown in Figure 1 is only an example. The scenario of the memory optimization method described in the embodiment of the present application is to more clearly illustrate the technical solution of the embodiment of the present application, and does not constitute a limitation on the technical solution provided by the embodiment of the present application.
[0067] Based on the scenario of the above-mentioned memory optimization method, various embodiments of the memory optimization method disclosed in this application are proposed.
[0068] As shown in FIG2 , FIG2 is a flow chart of an embodiment of a memory optimization method according to an embodiment of the present application, and the memory optimization method includes the following steps 201 to 204:
[0069] 201. Responding to a memory adjustment event for a target application, obtaining a virtual machine running instance of the target application;
[0070] The memory optimization method in this embodiment is applied to memory optimization devices. The type and number of memory optimization devices are not specifically limited. That is, the memory optimization device can be one or more smart terminals or servers. In a specific embodiment, the memory optimization device is a smart phone equipped with an Android system and installed with one or more applications.
[0071] Specifically, during operation, the memory optimization device responds to memory adjustment events for target applications. These memory adjustment events are instructions that drive the memory optimization device to expand the initial memory management parameters of the target applications, thereby reducing the number of garbage collection events triggered by the target applications. The triggering method for these memory adjustment events is not specifically limited herein. For example, the memory adjustment event can be triggered proactively by the user, such as by clicking a memory optimization button on the memory optimization device, thereby proactively triggering memory adjustment events for one or more target applications. Alternatively, the memory adjustment event can be triggered automatically by the memory optimization device, such as by presetting an automatic optimization process that automatically triggers memory adjustment events for target applications. Garbage collection (GC) events are operational events that automatically identify and recycle unused objects, freeing up the memory space they occupy. Frequently triggering GC events on a terminal can cause the GC thread to preempt device processor time slices, preventing other threads from executing and resulting in program lag.
[0072] Specifically, after receiving the memory adjustment event, the memory optimization device obtains the virtual machine running instance of the Java virtual machine corresponding to the target application to be optimized. The target application can be any one or more applications installed in the terminal. For example, applications such as WeChat, Taobao, JD.com and Xiaohongshu. Optionally, the target application can also be a terminal system application or the terminal system itself. The virtual machine running instance is the Runtime instance of the Java virtual machine corresponding to the target application. That is, the virtual machine running instance is the object responsible for managing the JVM running status in the Java application. The target application of the terminal can query system information, manage memory, execute other processes, and perform other operations through the virtual machine running instance, and perform memory adjustments on the target application through the virtual machine running instance to reduce the activity of the garbage collection process.
[0073] 202. Perform dynamic addressing based on the running state address of the virtual machine running instance and a preset memory management instance to locate the heap memory instance of the target application;
[0074] Specifically, after determining the virtual machine running instance of the target application, the memory optimization device also obtains the running state address of the virtual machine running instance, and dynamically addresses through the running state address and the preset memory management instance to search for the heap memory instance in the target application.
[0075] Specifically, the memory optimization device obtains the target application source code corresponding to the target application and loads a preset addressing method through the target application source code, so that the target application source code can derive the running state address of the virtual machine running instance at runtime. The preset addressing method can be a JNI (Java Native Interface) method.
[0076] Specifically, the memory optimization device declares the preset addressing method in the target application source code, generates an addressing header file corresponding to the preset addressing method, and generates a corresponding link library based on the addressing header file, thereby loading the preset addressing method during the execution of the target application source code and obtaining the running status address of the virtual machine running instance.
[0077] Specifically, after obtaining the running state address of the virtual machine running instance, the memory optimization device also obtains a preset anchor instance address within the virtual machine running instance. The preset anchor instance address is the instance address of a specific Java instance object within the virtual machine running instance, used as a starting point for traversing each running instance within the virtual machine running instance. In one specific embodiment, the preset anchor instance is the java_vm instance.
[0078] Specifically, the memory optimization device traverses each running instance in the virtual machine running instance based on the preset anchor instance address and the running state address to obtain each candidate addressing instance in the virtual machine running instance. That is, the memory optimization device uses the preset anchor instance address as a starting point, searches for each running instance corresponding to the running state address according to a preset search range corresponding to a preset traversal direction, and sets the retrieved running instances as candidate addressing instances. The candidate addressing instances are running instances in the virtual machine running instance that are within the preset search range corresponding to the preset traversal direction and starting from the preset anchor instance address.
[0079] Specifically, the memory optimization device also performs a secondary search on each candidate addressing instance based on a preset memory management instance to locate the target application's heap memory instance. The heap memory instance is an instance object used to store object instances and arrays. The heap memory instance stores initial memory management parameters.
[0080] Specifically, the memory optimization device performs a secondary search on the candidate addressing instances pointed to, determining whether a memory management instance exists in each candidate addressing instance. If the memory management instance exists in the candidate addressing instance, the candidate addressing instance containing the memory management instance is determined to be a heap memory instance, locates the heap memory instance, and obtains the instance address of the heap memory instance. The memory management instance is a region_space instance.
[0081] 203. Acquire initial memory management parameters of the heap memory instance according to the instance address and pointer position of the memory management instance in the heap memory instance;
[0082] Specifically, after obtaining the heap memory instance, the memory optimization device also obtains the instance address and pointer position of the memory management instance in the heap memory instance, and obtains the initial memory management parameters in the heap memory instance based on the instance address and pointer position.
[0083] Specifically, the memory optimization device obtains the pointer position of the memory management instance in the heap memory instance by specifying a name pointer, and further obtains the instance address of the memory management instance, performs a displacement operation based on the pointer position and the instance address, and obtains the initial memory parameters in the heap memory instance. The initial memory parameters include an initial minimum memory threshold and an initial maximum memory threshold. The initial minimum memory threshold is the minimum memory threshold that triggers a garbage collection event. The initial maximum memory threshold is the maximum memory threshold that triggers a garbage collection event.
[0084] Specifically, the memory optimization device performs a first shift operation using the instance address and the pointer position to locate the initial minimum memory threshold in the heap memory instance, as well as the instance address of the initial minimum memory threshold. The first shift operation controls the pointer position by a first number. In one specific embodiment, the first shift operation is plus one. That is, the first shift operation controls the pointer position to move one instance position below the memory management instance in the heap memory instance. Optionally, in other embodiments, the first shift operation can also control the pointer position to move a custom instance position.
[0085] Specifically, the memory optimization device performs a second shift operation using the instance address and the pointer position to locate the initial maximum memory threshold in the heap memory instance and the instance address of the initial maximum memory threshold. The second shift operation controls the pointer position to shift by a second instance number. In one specific embodiment, the second shift operation is plus two. That is, the second shift operation controls the pointer position to move down two instance positions from the memory management instance.
[0086] Specifically, the memory optimization device sets the obtained initial minimum memory threshold and initial maximum memory threshold as initial memory management parameters of the heap memory instance.
[0087] 204. Expand the initial memory management parameters according to the device performance parameters to obtain expanded memory management parameters, and perform memory optimization processing on the target application based on the expanded memory management parameters.
[0088] Specifically, since the garbage collection event triggering conditions of each application in the terminal are associated with the initial memory management parameters, after locating the instance address of the initial memory management parameters, the memory optimization device also expands the initial memory management parameters according to the device performance parameters and the instance address of the initial memory management parameters to obtain the expanded memory management parameters, and performs memory optimization processing on the target application through the expanded memory management parameter stack, thereby reducing the garbage collection event activity of the target application, that is, reducing the number of times the garbage collection event is triggered, so as to improve the stability and smoothness of the terminal operation.
[0089] Specifically, before expanding the initial memory management parameters, the memory optimization device also obtains the terminal's device performance parameters, which include the device memory capacity and current performance indicators. The device memory capacity represents the maximum and current memory capacity of the terminal corresponding to the target application. The current performance indicators represent parameters that characterize the terminal's performance, such as the current processor utilization and processing speed of the terminal corresponding to the target application.
[0090] Specifically, after obtaining the device performance parameters of the terminal, the memory optimization device also expands the initial minimum memory threshold according to the device performance parameters and the initial maximum memory threshold to obtain the expanded minimum memory threshold. That is, the memory optimization device determines the expansion multiple of the initial minimum memory threshold through the device performance parameters, updates the initial minimum memory threshold through the initial maximum memory threshold, sets the initial maximum memory threshold to the updated initial minimum memory threshold, and multiplies the expansion multiple by the updated initial minimum memory threshold to obtain the expanded minimum memory threshold. Among them, the expanded minimum memory threshold is greater than the initial minimum memory threshold. The expansion multiple of the initial minimum memory threshold is proportional to the device performance parameters.
[0091] Specifically, the memory optimization device expands the initial maximum memory threshold according to the memory capacity of the device and the current performance indicators to obtain the expanded maximum memory threshold, and sets the expanded minimum memory threshold and the expanded maximum memory threshold as the expanded memory management parameters of the target application, and updates the garbage collection event triggering conditions of the target application based on the expanded memory management parameters, thereby reducing the number of garbage collection events triggered.
[0092] In this embodiment, a memory optimization device obtains a virtual machine running instance of a target application by responding to a memory adjustment event for the target application; the memory adjustment event is an application adjustment event requesting to reduce the garbage collection event activity of the target application; dynamically addresses the running state address of the virtual machine running instance and a preset memory management instance to locate the heap memory instance of the target application; obtains initial memory management parameters of the heap memory instance based on the instance address and pointer position of the memory management instance in the heap memory instance, the initial memory management parameters including an initial minimum memory threshold and an initial maximum memory threshold; expands the initial memory management parameters based on device performance parameters to obtain expanded memory management parameters, and performs memory optimization on the target application based on the expanded memory management parameters. By dynamically addressing the virtual machine corresponding to the application to be memory optimized, obtaining the memory management parameters of the application, and modifying the memory management parameters, the number of memory recycles performed by the system is reduced, thereby reducing the resource usage of the system memory recycle thread and improving the smoothness and stability of the device.
[0093] As shown in FIG3 , FIG3 is a flow chart of an embodiment of expanding the initial maximum memory threshold in the memory optimization method provided in an embodiment of the present application. Specifically, in this embodiment, the memory optimization method includes steps 301 to 303:
[0094] 301. Calculate a current expansion score of the target application based on the device memory capacity and the current performance indicator;
[0095] Based on the above embodiments, in this embodiment, the memory optimization device expands the initial minimum memory threshold based on the initial maximum memory threshold and the device performance parameters to obtain the expanded minimum memory threshold, and also expands the initial maximum memory threshold according to the device memory capacity and the current performance indicators to obtain the expanded maximum memory threshold.
[0096] Specifically, the memory optimization device calculates the current expansion score of the target application based on the device memory capacity and the current performance index, wherein the current expansion score is a current terminal performance score that characterizes the target application.
[0097] Specifically, the memory optimization device pre-sets a first expansion weight corresponding to the device memory capacity and a second expansion weight corresponding to the second current performance indicator.
[0098] Optionally, the memory optimization device performs normalized scoring processing on the device memory capacity and current performance indicators to obtain a device memory score and a device performance score, and weights the device memory score by the first capacity expansion weight to obtain a weighted device memory score. Furthermore, the device performance score is weighted by the second capacity expansion weight to obtain a weighted device performance score, and the sum of the weighted device memory score and the weighted device performance score is calculated to obtain the current capacity expansion score.
[0099] Optionally, in other embodiments, the memory optimization device also pre-trains a preset model using preset memory capacity samples and performance indicator samples to obtain an expansion scoring model, and inputs the device memory capacity and current performance indicators into the expansion scoring model to calculate the current expansion score of the target application.
[0100] 302. If the current expansion score is less than the preset expansion threshold, expand the initial maximum memory threshold according to a first expansion multiple to obtain a first expansion maximum memory threshold;
[0101] Specifically, the memory optimization device pre-sets a preset expansion threshold for determining the performance level corresponding to the target application. By comparing the current expansion score with the preset expansion threshold, an expansion multiple is determined. The initial maximum memory threshold is expanded according to the expansion multiple to obtain a first expanded maximum memory threshold, thereby preventing the target application from occupying the terminal's running memory due to an unlimited increase in garbage collection event conditions. The expansion multiple includes a first expansion multiple and a second expansion multiple. The first expansion multiple is an expansion multiple for a low-amplitude expansion of the initial maximum memory threshold when the terminal's current performance level is relatively weak. The second expansion multiple is an expansion multiple for a high-amplitude expansion of the initial maximum memory threshold when the terminal's current performance level is relatively high. In one specific embodiment, the first expansion multiple is 1.2 times, and the second expansion multiple is 2 times. Optionally, in other embodiments, the first expansion multiple and the second expansion multiple can be customized according to the actual performance level of the terminal, ensuring that the first expansion multiple is less than the second expansion multiple.
[0102] Optionally, if the current expansion score is less than the preset expansion threshold, the memory optimization device determines that the current performance level of the terminal corresponding to the target application is weak, and the memory optimization device expands the initial maximum memory threshold according to the first expansion multiple, that is, uses the first expansion multiple to multiply the initial maximum memory threshold for expansion to obtain the first expansion maximum memory threshold.
[0103] 303. If the current expansion score is greater than the preset expansion threshold, the initial maximum memory threshold is expanded according to a second expansion multiple to obtain a second expansion maximum memory threshold.
[0104] Optionally, if the current expansion score is greater than or equal to the preset expansion threshold, the memory optimization device determines that the current performance level of the terminal corresponding to the target application is relatively strong, and the memory optimization device expands the initial maximum memory threshold according to the second expansion multiple, that is, uses the second expansion multiple to multiply the initial maximum memory threshold for expansion to obtain the second expansion maximum memory threshold.
[0105] Specifically, after obtaining the minimum expansion memory threshold and the first maximum expansion memory threshold or the second maximum expansion memory threshold, the terminal also updates the garbage collection event triggering condition of the target application according to the minimum expansion memory threshold and the first maximum expansion memory threshold or the second maximum expansion memory threshold, thereby reducing the number of garbage collection events triggered.
[0106] In this embodiment, the memory optimization device calculates the current expansion score of the target application based on the device memory capacity and the current performance index; if the current expansion score is less than the preset expansion threshold, the initial maximum memory threshold is expanded according to the first expansion multiple to obtain the first expansion maximum memory threshold; if the current expansion score is greater than the preset expansion threshold, the initial maximum memory threshold is expanded according to the second expansion multiple to obtain the second expansion maximum memory threshold, wherein the first expansion multiple is less than the second expansion multiple. The initial maximum memory threshold is dynamically increased according to the terminal performance index corresponding to the target application, thereby reducing the number of garbage collection events triggered and avoiding the target application occupying the terminal running memory due to unlimited increase in garbage collection event conditions, thereby improving application stability.
[0107] As shown in FIG4 , FIG4 is a flow chart of an embodiment of the memory optimization method provided in the present application, in which memory optimization processing is performed on the target application based on the expanded memory management parameters. Specifically, in this embodiment, the memory optimization method further includes steps 401 to 402:
[0108] 401. Update the initial memory reclaiming policy of the target application according to the minimum memory threshold for expansion and the maximum memory threshold for expansion to obtain an updated memory reclaiming policy;
[0109] 402. Perform memory optimization processing on the target application based on the updated memory reclaiming policy and the current application memory of the target application.
[0110] Specifically, after the memory optimization device expands the initial minimum memory threshold and the initial maximum memory threshold of the target application to obtain the expanded minimum memory threshold and the expanded maximum memory threshold, it also updates the initial memory recovery strategy of the target application according to the expanded minimum threshold and the expanded maximum threshold to obtain an updated recovery strategy.
[0111] Specifically, the memory optimization device obtains the initial minimum deactivation parameter and the initial maximum deactivation parameter in the initial memory recycling strategy of the target application, updates the initial minimum deactivation parameter according to the expanded minimum memory threshold, and updates the initial maximum deactivation parameter according to the expanded maximum memory threshold to obtain an updated recycling strategy. The initial minimum deactivation parameter is the minimum discrimination threshold for determining whether a garbage collection event is triggered. The initial maximum deactivation parameter is the maximum discrimination threshold for determining whether a garbage collection event is triggered. The initial minimum deactivation parameter is calculated by setting the product of the preset deactivation coefficient multiplied by the initial minimum memory threshold as the initial minimum deactivation parameter. The initial maximum deactivation parameter is the product of the preset deactivation coefficient multiplied by the initial maximum memory threshold as the initial maximum deactivation parameter. Optionally, in a specific embodiment, the preset deactivation coefficient is 3.
[0112] Specifically, the memory optimization device replaces the initial minimum memory threshold in the initial minimum deactivation parameter with the expanded minimum memory threshold, calculates the product of the preset deactivation coefficient and the expanded minimum memory threshold, and sets the product of the preset deactivation coefficient and the expanded minimum memory threshold as the updated minimum deactivation parameter.
[0113] Specifically, the memory optimization device replaces the initial maximum memory threshold in the initial maximum deactivation parameter with the expanded maximum memory threshold, calculates the product of the preset deactivation coefficient and the expanded maximum memory threshold, and sets the product of the preset deactivation coefficient and the expanded maximum memory threshold as the updated maximum deactivation parameter.
[0114] Specifically, after obtaining the updated minimum deactivation parameter and the updated maximum deactivation parameter, the memory optimization device configures the garbage collection condition of the target application according to the updated minimum deactivation parameter and the updated maximum deactivation parameter to obtain an updated memory recycling policy.
[0115] Specifically, after obtaining the updated memory recycling policy of the target application, the memory optimization device counts the current application memory of the target application and determines whether the current application memory falls into the garbage collection conditions. If it does not fall into the garbage collection conditions, the garbage collection event will not be triggered. If it falls into the garbage collection conditions, the garbage collection event will be triggered, thereby reducing the number of times the garbage collection events are triggered.
[0116] In this embodiment, the memory optimization device updates the target application's initial memory reclamation policy based on the minimum memory expansion threshold and the maximum memory expansion threshold to obtain an updated memory reclamation policy. The device then performs memory optimization processing on the target application based on the updated memory reclamation policy and the target application's current application memory. This updates the target application's memory reclamation policy and reduces the number of garbage collection events triggered.
[0117] In order to better implement the memory optimization method in the embodiment of the present application, based on the memory optimization method, the embodiment of the present application further provides a memory optimization device, as shown in FIG5 . FIG5 is a schematic structural diagram of the memory optimization device provided in the embodiment of the present application. Specifically, the memory optimization device 500 includes:
[0118] The instance acquisition module 501 is configured to respond to a memory adjustment event for a target application and acquire a virtual machine running instance of the target application; the memory adjustment event is an application adjustment event requesting to reduce the garbage collection event activity of the target application;
[0119] A heap memory locating module 502 is configured to perform dynamic addressing based on the running state address of the virtual machine running instance and a preset memory management instance to locate the heap memory instance of the target application;
[0120] a parameter acquisition module 503 configured to acquire initial memory management parameters of the heap memory instance according to the instance address and pointer position of the memory management instance in the heap memory instance, wherein the initial memory management parameters include an initial minimum memory threshold and an initial maximum memory threshold;
[0121] The memory expansion module 504 is configured to expand the initial memory management parameters according to the device performance parameters to obtain expanded memory management parameters, and perform memory optimization processing on the target application based on the expanded memory management parameters.
[0122] In a possible implementation of this embodiment, the memory optimization device performs dynamic addressing based on the running state address of the virtual machine running instance and a preset memory management instance to locate the heap memory instance of the target application, including:
[0123] Obtaining the running state address of the running instance of the virtual machine by loading a preset addressing method of the target application source code corresponding to the target application;
[0124] Traversing each running instance in the virtual machine running instance based on the running state address and the preset anchor instance address to obtain a candidate addressing instance;
[0125] A secondary search is performed on the candidate addressing instance based on a preset memory management instance to locate the heap memory instance containing the memory management instance.
[0126] In a possible implementation of this embodiment, the memory optimization device traverses each running instance in the virtual machine running instance based on the running state address and the preset anchor instance address to obtain a candidate addressing instance, including:
[0127] Acquire each running instance and a preset anchor instance in the running instance of the virtual machine based on the running state address;
[0128] The running instances are traversed according to the preset anchor instance and the preset search range to obtain candidate addressing instances.
[0129] In a possible implementation of this embodiment, the memory optimization device obtains the initial memory management parameters of the heap memory instance according to the instance address and pointer position of the memory management instance in the heap memory instance, including:
[0130] Obtaining the instance address and pointer position of the memory management instance in the heap memory instance;
[0131] Perform a first shift operation according to the instance address and the pointer position to obtain an initial minimum memory threshold in the heap memory instance;
[0132] Perform a second shift operation according to the instance address and the pointer position to obtain an initial maximum memory threshold in the heap memory instance;
[0133] The initial minimum memory threshold and the initial maximum memory threshold are set as initial memory management parameters of the heap memory instance.
[0134] In a possible implementation of this embodiment, the memory optimization apparatus performs expansion processing on the initial memory management parameters according to the device performance parameters to obtain the expanded memory management parameters, including:
[0135] Obtain device performance parameters corresponding to the target application, the device performance parameters including device memory capacity and current performance indicators;
[0136] Expanding the initial minimum memory threshold based on the initial maximum memory threshold and the device performance parameter to obtain an expanded minimum memory threshold;
[0137] Expanding the initial maximum memory threshold according to the device memory capacity and the current performance indicator to obtain an expanded maximum memory threshold;
[0138] The minimum memory expansion threshold and the maximum memory expansion threshold are set as expansion memory management parameters of the target application.
[0139] In a possible implementation of this embodiment, the memory optimization apparatus expands the initial maximum memory threshold according to the device memory capacity and the current performance indicator to obtain the expanded maximum memory threshold, including:
[0140] Calculating a current expansion score of the target application based on the device memory capacity and the current performance indicator;
[0141] If the current expansion score is less than the preset expansion threshold, the initial maximum memory threshold is expanded according to the first expansion multiple to obtain a first expansion maximum memory threshold;
[0142] If the current expansion score is greater than a preset expansion threshold, the initial maximum memory threshold is expanded according to a second expansion multiple to obtain a second expanded maximum memory threshold, wherein the first expansion multiple is less than the second expansion multiple.
[0143] In a possible implementation of this embodiment, the memory optimization device performs memory optimization processing on the target application based on the expanded memory management parameter, further comprising:
[0144] Updating the initial memory reclaiming policy of the target application according to the minimum memory threshold for expansion and the maximum memory threshold for expansion to obtain an updated memory reclaiming policy;
[0145] Memory optimization processing is performed on the target application based on the updated memory reclaiming policy and the current application memory of the target application.
[0146] In this embodiment, the memory optimization device obtains a virtual machine running instance of the target application by responding to a memory adjustment event for the target application; the memory adjustment event is an application adjustment event requesting to reduce the garbage collection event activity of the target application; dynamically addresses the running state address of the virtual machine running instance and a preset memory management instance to locate the heap memory instance of the target application; obtains initial memory management parameters of the heap memory instance based on the instance address and pointer position of the memory management instance in the heap memory instance, the initial memory management parameters including an initial minimum memory threshold and an initial maximum memory threshold; expands the initial memory management parameters according to device performance parameters to obtain expanded memory management parameters, and performs memory optimization on the target application based on the expanded memory management parameters. By dynamically addressing the virtual machine corresponding to the application to be memory optimized, obtaining the memory management parameters of the application, and modifying the memory management parameters, the number of memory recycling times of the system is reduced, thereby reducing the resource usage of the system memory recycling thread and improving the fluency and stability of the device.
[0147] An embodiment of the present application also provides a memory optimization device, as shown in FIG6 , which is a schematic structural diagram of an embodiment of the memory optimization device provided in an embodiment of the present application.
[0148] The memory optimization device integrates any one of the memory optimization devices provided in the embodiments of the present application, and the memory optimization device includes:
[0149] one or more processors;
[0150] Memory; and
[0151] One or more applications, wherein the one or more applications are stored in the memory and configured so that the processor executes the steps of the memory optimization method described in any of the above-mentioned memory optimization method embodiments.
[0152] Specifically, the memory optimization device may include one or more processing cores (processors 601), one or more computer-readable storage media (memory 602), a power supply 603, and an input unit 604. Those skilled in the art will appreciate that the memory optimization device structure shown in FIG6 does not limit the memory optimization device, and may include more or fewer components than shown, or combine certain components, or arrange the components differently. Among them:
[0153] Processor 601 is the control center of the memory optimization device. It connects the various components of the device using various interfaces and circuits. By running or executing software programs and / or modules stored in memory 602 and accessing data stored in memory 602, it performs various functions of the device and processes data, thereby providing overall monitoring of the device. Optionally, processor 601 may include one or more processing cores. Preferably, processor 601 integrates an application processor and a modem processor. The application processor primarily handles the operating system, user interface, and application programs, while the modem processor primarily handles wireless communications. It is understood that the modem processor may not be integrated into processor 601.
[0154] Memory 602 can be used to store software programs and modules. Processor 601 executes various functional applications and data processing by running the software programs and modules stored in memory 602. Memory 602 may primarily include a program storage area and a data storage area. The program storage area may store an operating system and at least one application required for a function (such as sound playback or image playback). The data storage area may store data generated by the use of the memory optimization device. Furthermore, memory 602 may include high-speed random access memory and non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, memory 602 may also include a memory controller to provide processor 601 with access to memory 602.
[0155] The memory optimization device also includes a power supply 603 for supplying power to various components. Preferably, the power supply 603 can be logically connected to the processor 601 via a power management system, thereby enabling the power management system to manage charging, discharging, and power consumption. The power supply 603 can also include one or more DC or AC power supplies, a recharging system, a power failure detection circuit, a power converter or inverter, a power status indicator, and other arbitrary components.
[0156] The memory optimization device may further include an input unit 604, which may be configured to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.
[0157] Although not shown, the memory optimization device may also include a display unit, etc., which will not be described in detail here. Specifically, in this embodiment, the processor 601 in the memory optimization device will load the executable files corresponding to one or more application processes into the memory 602 according to the following instructions, and the processor 601 will run the application stored in the memory 602 to implement various functions as follows:
[0158] In response to a memory adjustment event for a target application, obtaining a virtual machine running instance of the target application; the memory adjustment event is an application adjustment event requesting to reduce garbage collection event activity of the target application;
[0159] Performing dynamic addressing based on the running state address of the virtual machine running instance and a preset memory management instance to locate the heap memory instance of the target application;
[0160] Acquire initial memory management parameters of the heap memory instance according to the instance address and pointer position of the memory management instance in the heap memory instance, wherein the initial memory management parameters include an initial minimum memory threshold and an initial maximum memory threshold;
[0161] The initial memory management parameters are expanded according to the device performance parameters to obtain expanded memory management parameters, and memory optimization processing is performed on the target application based on the expanded memory management parameters.
[0162] To this end, embodiments of the present application provide a computer-readable storage medium, which may include a read-only memory (ROM), random access memory (RAM), a disk, or an optical disk. A computer program is stored thereon, and the computer program is loaded by a processor to execute the steps of any of the memory optimization methods provided in embodiments of the present application. For example, the computer program loaded by the processor may execute the following steps:
[0163] In response to a memory adjustment event for a target application, obtaining a virtual machine running instance of the target application; the memory adjustment event is an application adjustment event requesting to reduce garbage collection event activity of the target application;
[0164] Performing dynamic addressing based on the running state address of the virtual machine running instance and a preset memory management instance to locate the heap memory instance of the target application;
[0165] Acquire initial memory management parameters of the heap memory instance according to the instance address and pointer position of the memory management instance in the heap memory instance, wherein the initial memory management parameters include an initial minimum memory threshold and an initial maximum memory threshold;
[0166] The initial memory management parameters are expanded according to the device performance parameters to obtain expanded memory management parameters, and memory optimization processing is performed on the target application based on the expanded memory management parameters.
[0167] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, please refer to the detailed description of other embodiments above and will not be repeated here.
[0168] In specific implementation, the above units or structures can be implemented as independent entities, or can be arbitrarily combined to implement as the same or several entities. The specific implementation of the above units or structures can refer to the previous method embodiments and will not be repeated here.
[0169] The specific implementation of the above operations can be found in the previous embodiments and will not be repeated here.
[0170] The above is a detailed introduction to a memory optimization method provided in an embodiment of the present application. Specific embodiments are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for technical personnel in this field, based on the ideas of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A memory optimization method, wherein: The memory optimization method comprises: In response to a memory adjustment event for a target application, obtaining a virtual machine running instance of the target application; the memory adjustment event is an application adjustment event requesting to reduce the activity of a garbage collection event of the target application; Performing dynamic addressing based on the running state address of the running instance of the virtual machine and a preset memory management instance to locate the heap memory instance of the target application; Acquire initial memory management parameters of the heap memory instance according to the instance address and pointer position of the memory management instance in the heap memory instance, wherein the initial memory management parameters include an initial minimum memory threshold and an initial maximum memory threshold; The initial memory management parameters are expanded according to the device performance parameters to obtain expanded memory management parameters, and memory optimization processing is performed on the target application based on the expanded memory management parameters.
2. The memory optimization method according to claim 1, wherein: The dynamically addressing based on the running state address of the running instance of the virtual machine and the preset memory management instance to locate the heap memory instance of the target application includes: Obtaining the running state address of the running instance of the virtual machine by loading a preset addressing method through the target application source code corresponding to the target application; Traversing each running instance in the running instance of the virtual machine based on the running state address and the preset anchor instance address to obtain a candidate addressing instance; A secondary search is performed on the candidate addressing instance based on a preset memory management instance to locate the heap memory instance containing the memory management instance.
3. The memory optimization method according to claim 2, wherein: The traversing each running instance in the running instance of the virtual machine based on the running state address and the preset anchor instance address to obtain a candidate addressing instance includes: Acquire each running instance and a preset anchor instance in the running instance of the virtual machine based on the running state address; The running instances are traversed according to the preset anchor instance and the preset search range to obtain candidate addressing instances.
4. The memory optimization method according to claim 1, wherein: The obtaining the initial memory management parameters of the heap memory instance according to the instance address and the pointer position of the memory management instance in the heap memory instance includes: Obtaining the instance address and pointer position of the memory management instance in the heap memory instance; Perform a first displacement operation according to the instance address and the pointer position to obtain an initial minimum memory threshold in the heap memory instance; Perform a second shift operation according to the instance address and the pointer position to obtain an initial maximum memory threshold in the heap memory instance; The initial minimum memory threshold and the initial maximum memory threshold are set as initial memory management parameters of the heap memory instance.
5. The memory optimization method according to claim 1, wherein: The step of performing capacity expansion processing on the initial memory management parameter according to the device performance parameter to obtain the expanded memory management parameter includes: Obtaining device performance parameters corresponding to the target application, wherein the device performance parameters include device memory capacity and current performance indicators; Expanding the initial minimum memory threshold based on the initial maximum memory threshold and the device performance parameter to obtain an expanded minimum memory threshold; Expanding the initial maximum memory threshold according to the device memory capacity and the current performance indicator to obtain an expanded maximum memory threshold; The expansion minimum memory threshold and the expansion maximum memory threshold are set as expansion memory management parameters of the target application.
6. The memory optimization method according to claim 5, wherein: The maximum memory threshold for capacity expansion includes any one of a first maximum memory threshold for capacity expansion and a second maximum memory threshold for capacity expansion; The step of expanding the initial maximum memory threshold according to the device memory capacity and the current performance index to obtain the expanded maximum memory threshold includes: Calculating a current expansion score of the target application according to the device memory capacity and the current performance indicator; If the current expansion score is less than the preset expansion threshold, the initial maximum memory threshold is expanded according to the first expansion multiple to obtain a first expansion maximum memory threshold; If the current expansion score is greater than a preset expansion threshold, the initial maximum memory threshold is expanded according to a second expansion multiple to obtain a second expansion maximum memory threshold, wherein the first expansion multiple is less than the second expansion multiple.
7. The memory optimization method according to claim 5, wherein: The performing memory optimization processing on the target application based on the expanded memory management parameter further includes: The initial memory reclaiming policy of the target application is updated according to the minimum memory threshold for expansion and the maximum memory threshold for expansion to obtain an updated memory reclaiming policy; Memory optimization processing is performed on the target application based on the updated memory reclaiming policy and the current application memory of the target application.
8. The memory optimization method according to claim 7, wherein: The updating of the initial memory reclaiming strategy of the target application according to the minimum memory threshold for expansion and the maximum memory threshold for expansion to obtain an updated memory reclaiming strategy includes: Obtaining an initial minimum deactivation parameter in an initial memory reclaim policy of the target application and an initial maximum deactivation parameter in the initial memory reclaim policy; The initial minimum deactivation parameter is updated according to the expansion minimum memory threshold, and the initial maximum deactivation parameter threshold is updated according to the expansion maximum memory threshold to obtain an update recovery strategy.
9. The memory optimization method according to claim 8, wherein: The updating of the initial minimum deactivation parameter according to the expansion minimum memory threshold, and the updating of the initial maximum deactivation parameter threshold according to the expansion maximum memory threshold, to obtain an update recovery strategy, includes: Replacing the initial minimum memory threshold in the initial minimum deactivation parameter with the expansion minimum memory threshold, calculating the product of a preset deactivation coefficient and the expansion minimum memory threshold, and obtaining an updated minimum deactivation parameter; Replacing the initial maximum memory threshold in the initial maximum deactivation parameter with the expanded maximum memory threshold, calculating the product of the preset deactivation coefficient and the expanded maximum memory threshold, and obtaining an updated maximum deactivation parameter; The garbage collection condition of the target application is configured according to the updated minimum deactivation parameter and the updated maximum deactivation parameter to obtain an updated memory recovery strategy.
10. A memory optimization device, wherein: The memory optimization device comprises: An instance acquisition module is configured to respond to a memory adjustment event for a target application and acquire a virtual machine running instance of the target application; the memory adjustment event is an application adjustment event requesting to reduce the activity of garbage collection events of the target application; A heap memory locating module is configured to perform dynamic addressing based on the running state address of the running instance of the virtual machine and a preset memory management instance to locate the heap memory instance of the target application; A parameter acquisition module is configured to acquire initial memory management parameters of the heap memory instance according to the instance address and pointer position of the memory management instance in the heap memory instance, wherein the initial memory management parameters include an initial minimum memory threshold and an initial maximum memory threshold; The memory expansion module is configured to expand the initial memory management parameters according to the device performance parameters to obtain the expanded memory management parameters, and perform memory optimization processing on the target application based on the expanded memory management parameters.
11. The memory optimization device according to claim 10, wherein: The heap memory positioning module is also used to perform dynamic addressing based on the running state address of the virtual machine running instance and the preset memory management instance to locate the heap memory instance of the target application, including: Obtaining the running state address of the running instance of the virtual machine by loading a preset addressing method through the target application source code corresponding to the target application; Traversing each running instance in the running instance of the virtual machine based on the running state address and the preset anchor instance address to obtain a candidate addressing instance; A secondary search is performed on the candidate addressing instance based on a preset memory management instance to locate the heap memory instance containing the memory management instance.
12. The memory optimization device according to claim 11, wherein: The heap memory positioning module is further used to traverse each running instance in the virtual machine running instance based on the running state address and the preset anchor instance address to obtain a candidate addressing instance, including: Acquire each running instance and a preset anchor instance in the running instance of the virtual machine based on the running state address; The running instances are traversed according to the preset anchor instance and the preset search range to obtain candidate addressing instances.
13. The memory optimization device according to claim 10, wherein: The parameter acquisition module is also used to acquire the initial memory management parameters of the heap memory instance according to the instance address and pointer position of the memory management instance in the heap memory instance, including: Obtaining the instance address and pointer position of the memory management instance in the heap memory instance; Perform a first displacement operation according to the instance address and the pointer position to obtain an initial minimum memory threshold in the heap memory instance; Perform a second shift operation according to the instance address and the pointer position to obtain an initial maximum memory threshold in the heap memory instance; The initial minimum memory threshold and the initial maximum memory threshold are set as initial memory management parameters of the heap memory instance.
14. The memory optimization device according to claim 10, wherein: The memory expansion module is further used to expand the initial memory management parameters according to the device performance parameters to obtain the expanded memory management parameters, including: Obtaining device performance parameters corresponding to the target application, wherein the device performance parameters include device memory capacity and current performance indicators; Expanding the initial minimum memory threshold based on the initial maximum memory threshold and the device performance parameter to obtain an expanded minimum memory threshold; Expanding the initial maximum memory threshold according to the device memory capacity and the current performance indicator to obtain an expanded maximum memory threshold; The expansion minimum memory threshold and the expansion maximum memory threshold are set as expansion memory management parameters of the target application.
15. The memory optimization device according to claim 14, wherein: The maximum memory expansion threshold in the memory expansion module includes any one of a first maximum memory expansion threshold and a second maximum memory expansion threshold; The memory expansion module is further used to expand the initial maximum memory threshold according to the device memory capacity and the current performance index to obtain the expanded maximum memory threshold, including: Calculating a current expansion score of the target application according to the device memory capacity and the current performance indicator; If the current expansion score is less than the preset expansion threshold, the initial maximum memory threshold is expanded according to the first expansion multiple to obtain a first expansion maximum memory threshold; If the current expansion score is greater than a preset expansion threshold, the initial maximum memory threshold is expanded according to a second expansion multiple to obtain a second expansion maximum memory threshold, wherein the first expansion multiple is less than the second expansion multiple.
16. The memory optimization device according to claim 14, wherein: The memory expansion module is also used to perform memory optimization processing on the target application based on the expanded memory management parameter, and also includes: The initial memory reclaiming policy of the target application is updated according to the minimum memory threshold for expansion and the maximum memory threshold for expansion to obtain an updated memory reclaiming policy; Memory optimization processing is performed on the target application based on the updated memory reclaiming policy and the current application memory of the target application.
17. The memory optimization device according to claim 16, wherein: The memory expansion module is further used to update the initial memory recovery strategy of the target application according to the expansion minimum memory threshold and the expansion maximum memory threshold to obtain an updated memory recovery strategy, including: Obtaining an initial minimum deactivation parameter in an initial memory reclaim policy of the target application and an initial maximum deactivation parameter in the initial memory reclaim policy; The initial minimum deactivation parameter is updated according to the expansion minimum memory threshold, and the initial maximum deactivation parameter threshold is updated according to the expansion maximum memory threshold to obtain an update recovery strategy.
18. The memory optimization device according to claim 17, wherein: The memory expansion module is further used to update the initial minimum deactivation parameter according to the expansion minimum memory threshold, and to update the initial maximum deactivation parameter threshold according to the expansion maximum memory threshold, to obtain an update recovery strategy, including: Replacing the initial minimum memory threshold in the initial minimum deactivation parameter with the expansion minimum memory threshold, calculating the product of a preset deactivation coefficient and the expansion minimum memory threshold, and obtaining an updated minimum deactivation parameter; Replacing the initial maximum memory threshold in the initial maximum deactivation parameter with the expanded maximum memory threshold, calculating the product of the preset deactivation coefficient and the expanded maximum memory threshold, and obtaining an updated maximum deactivation parameter; The garbage collection condition of the target application is configured according to the updated minimum deactivation parameter and the updated maximum deactivation parameter to obtain an updated memory recovery strategy.
19. A memory optimization device, wherein: The memory optimization device comprises: one or more processors; Memory; and One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the processor to implement the steps of the memory optimization method according to any one of claims 1 to 9.
20. A computer-readable storage medium, wherein: A computer program is stored thereon, and the computer program is loaded by a processor to execute the steps of the memory optimization method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Java virtual machine optimization method and system
CN110888712A
Storage space using method and device, storage medium and electronic device
CN112035379A
Memory optimization method and device, equipment and storage medium
CN117632371A
System and method for two-tier adaptive heap management in a virtual machine environment
US20140324924A1