Garbage recycling method, garbage recycling device and storage medium
By identifying and adjusting the long-term stages of the garbage collection process in the Android operating system, the pauses and performance losses caused by garbage collection are solved, and the system fluency and response speed are improved.
Patent Information
- Application Number
- CN202311510198.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-13
- Publication Date
- 2025-05-13
AI Technical Summary
In the Android operating system, there is a pause during the garbage collection process, which leads to too long terminal time, slow speed, unstable display, and an application unresponsive (ANR) error, which consumes a lot of resources and loses application performance.
By retrieving garbage collection when the available capacity in the electronic device heap space reaches the threshold, the time-consuming phases that consume more than the threshold are identified and the processing method is adjusted, such as increasing priority, so that the adjusted time-consuming is less than the threshold.
The garbage collection process is optimized, the garbage collection pause time and running time is reduced, the system is used smoothly, and the problem of lag and frame drop caused by garbage collection is avoided.
Smart Images

Figure CN119987987A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of mobile operating systems, and in particular to a garbage collection method, a garbage collection device, and a storage medium. Background Art
[0002] Android is still the mainstream operating system for mobile devices. The Art (Android Runtime) virtual machine hosts applications and some system services on Android. One of its very important functions is to manage system memory through garbage collection.
[0003] In the related technology, Art virtual machine introduces parallel garbage collection mechanism, but still cannot avoid a pause in the garbage collection process. If the terminal time is too long, it will inevitably cause the response speed to slow down, the display to be unstable, and the application not responding dialog box (Application Not Responding, ANR) to appear, resulting in a large amount of resource consumption and loss of application performance. Summary of the invention
[0004] In order to overcome the problems existing in the related art, the present disclosure provides a garbage collection method, a garbage collection device and a storage medium.
[0005] According to a first aspect of an embodiment of the present disclosure, a garbage collection method is provided, the method comprising performing garbage collection in response to the available capacity in the electronic device stack space reaching a capacity threshold; identifying a time-consuming stage in the garbage collection process that consumes a time greater than a time-consuming threshold; and adjusting a processing method for the time-consuming stage so that the time consumed by the adjusted time-consuming stage is less than the time-consuming threshold.
[0006] In one implementation, the adjusting of the processing method of the time-consuming stage includes: increasing the priority of the time-consuming stage of the electronic device.
[0007] In one embodiment, the available capacity of the heap space is pre-determined in the following manner: based on multiple parameter pairs, a target parameter pair is selected, the target parameter pair includes maximum free memory and minimum free memory, and the target parameter pair makes the adjusted time consumption less than the time consumption threshold; the target parameter pair is used to determine the available capacity of the heap space.
[0008] In one embodiment, the selecting of a target parameter pair based on multiple parameter pairs includes: performing garbage collection based on the available capacity of the heap space corresponding to each parameter pair in the multiple parameter pairs, and monitoring one or more performance data of the garbage collection execution process; and determining, based on the one or more performance data, a parameter pair corresponding to the performance data that meets the performance indicator requirements as the target parameter pair.
[0009] In one implementation, the one or more performance data include at least one of the following: average garbage collection times data, average processor occupancy time data, and average memory occupancy data.
[0010] According to a second aspect of an embodiment of the present disclosure, a garbage collection device is provided, the device comprising a response unit for performing garbage collection in response to the available capacity in the electronic device stack space reaching a capacity threshold; an identification unit for identifying a time-consuming stage in the garbage collection process that consumes time greater than a time-consuming threshold; and an adjustment unit for adjusting a processing method for the time-consuming stage so that the time consumed by the adjusted time-consuming stage is less than the time-consuming threshold.
[0011] In one implementation, the processing method of the time-consuming stage is adjusted, and the adjustment unit is further used to: increase the priority of the time-consuming stage of the electronic device.
[0012] In one embodiment, the response unit predetermines the available capacity of the heap space in the following manner: based on multiple parameter pairs, a target parameter pair is selected, the target parameter pair includes a maximum free memory and a minimum free memory, and the target parameter pair makes the adjusted time consumption less than the time consumption threshold; the target parameter pair is used to determine the available capacity of the heap space.
[0013] In one embodiment, the response unit selects a target parameter pair based on multiple parameter pairs in the following manner: based on the available capacity of the heap space corresponding to each parameter pair in the multiple parameter pairs, garbage collection is performed separately, and one or more performance data of the garbage collection execution process are monitored; based on the one or more performance data, the parameter pair corresponding to the performance data that meets the performance indicator requirements is determined as the target parameter pair.
[0014] In one implementation, the one or more performance data include at least one of the following: average garbage collection times data, average processor occupancy time data, and average memory occupancy data.
[0015] According to a third aspect of an embodiment of the present disclosure, a garbage collection device is provided, comprising: a processor; and a memory for storing processor executable instructions; wherein the processor is configured to: execute the garbage collection method described in the first aspect or any one of the embodiments of the first aspect.
[0016] According to a fourth aspect of an embodiment of the present disclosure, a storage medium is provided, in which instructions are stored. When the instructions in the storage medium are executed by a processor, the processor is enabled to execute the garbage collection method described in the second aspect or any one of the embodiments of the second aspect.
[0017] The technical solution provided by the embodiments of the present disclosure may include the following beneficial effects: in response to the available capacity in the electronic device stack space reaching a threshold, garbage collection is performed, and if a time-consuming stage that takes longer than a time-consuming threshold is identified during the garbage collection process, the processing method of the time-consuming stage is adjusted so that the time-consuming stage after the adjustment is less than the time-consuming threshold. Through the present disclosure, the garbage collection process is optimized, the garbage collection pause time and the garbage collection running time are reduced, and the smoothness of the system is improved.
[0018] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0020] Figure 1 It is a schematic diagram showing main parameters of a stack according to an exemplary embodiment.
[0021] Figure 2 The figure is a flowchart showing a garbage collection process according to an exemplary embodiment.
[0022] Figure 3 The figure is a flowchart of a garbage collection method according to an exemplary embodiment.
[0023] Figure 4 The present invention is a flowchart showing a method for predetermining available capacity of a heap space according to an exemplary embodiment.
[0024] Figure 5 The figure is a schematic diagram showing the effect of different parameters on a specific situation of garbage collection according to an exemplary embodiment.
[0025] Figure 6 The figure is a flowchart of a method for determining a target parameter pair according to an exemplary embodiment.
[0026] Figure 7 The figure is a schematic diagram showing the effect of different values on the memory usage of an application according to an exemplary embodiment.
[0027] Figure 8 The figure is a block diagram of a garbage collection device according to an exemplary embodiment.
[0028] Fig. 9 The invention is a block diagram showing a garbage collection device according to an exemplary embodiment.
[0029] Fig.10The invention is a block diagram showing a garbage collection device according to an exemplary embodiment. DETAILED DESCRIPTION
[0030] Here, exemplary embodiments will be described in detail, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present disclosure.
[0031] Art (Android Runtime) virtual machine was released in Android 4.4, replacing Dalvik virtual machine, hosting applications and some system services on Android. One of its very important functions is to manage system memory through garbage collection. When the total application memory exceeds the maximum heap memory limit given by the system, a memory leak (Out Of Memory, OOM) will occur, which is the significance of the existence of garbage collection (Garbage Collection, GC).
[0032] Garbage collection is an automatic storage management mechanism that automatically identifies garbage objects and normal objects. When a part of the memory space is no longer accessed by the program, it returns the part of the memory space to the operating system. The garbage collection algorithm has greatly reduced the burden on programmers and reduced the probability of program errors. There are three main times to trigger garbage collection, namely, failure to allocate memory, heap space reaching the threshold, and the program actively applying for garbage collection. As mentioned earlier, the Dalvik virtual machine was used in the early days of Android. It is divided into two stages of garbage collection, namely Mark and Sweep, namely the Mark-Sweep algorithm. The Mark stage is mainly to mark all referenced objects of the current program, and the Sweep stage is responsible for recycling garbage objects. During the operation of the garbage collection thread, in order to correctly mark each object, the operation of all threads in the current program except the garbage collection thread will be temporarily interrupted, namely, Stop-the-World (STW), which will cause the program to pause. The Dalvik virtual machine needs to pause twice in the Mark stage and once in the Sweep stage. The three times are too expensive and will cause obvious jams. The ART virtual machine has optimized this and adopted a concurrent design so that each garbage collection is paused only once, thereby minimizing the pause time; the heap is divided more finely, and more diverse recycling strategies are implemented for different recycling scenarios, effectively reducing the use of background memory and memory fragmentation; the efficiency of garbage collection is optimized, and garbage objects are recycled in a timely manner.
[0033] Among them, the heap space is responsible for the allocation of object memory, and the size of the heap memory directly affects the size of the memory space that an application can use. Specifically, there are several important parameters related to the heap: Figure 1 is a schematic diagram showing main parameters of a stack according to an exemplary embodiment, such as Figure 1 "dalvik.vm.heapstart" indicates the starting size, "dalvik.vm.heapgrowthlimit" indicates the growth limit, "dalvik.vm.heapsize" indicates the theoretical maximum value, "dalvik.vm.heaptargetutilization" indicates memory utilization, "dalvik.vm.heapminfree" indicates the minimum free memory, and "dalvik.vm.heapmaxfree" indicates the maximum free memory.
[0034] Among them, the starting size of the heap memory specifies the size of physical memory that needs to be requested from the operating system when the virtual machine starts. In order to dynamically adjust the available memory size of the heap, the virtual machine introduces a growth upper limit, mainly to avoid the uncontrolled growth of the allocated part of the heap memory (active heap) and effectively reduce memory fragmentation.
[0035] In the related art, in order to minimize the pauses in the garbage collection process, the ART virtual machine allows other threads in the current program to execute conditionally in the Mark phase, that is, parallel garbage collection. To achieve this function, the Mark phase is divided into two sub-phases: first, only the stack variables, global variables and objects referenced by registers at the beginning of garbage collection are marked, that is, the root set objects (GC Root); second, based on the root base object, the remaining referenced variables, that is, the objects referenced by the root set objects, are found.
[0036] Garbage collection of the ART virtual machine consumes a lot of resources and impairs application performance. Even if a parallel garbage collection mechanism is introduced, it is still impossible to avoid a STW during the garbage collection process. As mentioned earlier, if the interruption time is too long, it will inevitably cause a slow response speed, unstable display, and even an Application Not Responding (ANR) error.
[0037] In view of this, the present application proposes a garbage collection method.
[0038] The embodiments of the present disclosure provide a garbage collection process, which is applied to a garbage collection scenario.
[0039] Figure 2 is a flowchart of a garbage collection process according to an exemplary embodiment. Figure 2As shown, the process includes the following:
[0040] In the disclosed embodiment, the garbage collection process is divided into two processes, non-parallel and parallel. Among them, the marking phase and recycling phase of non-parallel garbage collection are performed under the premise of suspending all ART runtime threads. In the marking phase of parallel processing, the virtual machine locks the Java heap, then scans and marks it. In the recycling phase, the lock of the Java heap is released after the marking is completed, and then all threads are suspended to recycle the marked objects, and in the parallel phase, the virtual machine restores the execution site of all threads and continues to run.
[0041] The following is an explanation of the steps of garbage collection in the embodiment of the present disclosure.
[0042] Figure 3 is a flowchart of a garbage collection method according to an exemplary embodiment. Figure 3 As shown, the method includes steps S11 to S13.
[0043] In step S11 , in response to the available capacity in the electronic device stack space reaching a capacity threshold, garbage collection is performed.
[0044] In the disclosed embodiment, in response to the available capacity in the heap space of the electronic device reaching the capacity threshold, the electronic device can be a terminal, a television, a car system, etc. with a mobile Android operating system. There are three types of Android memory allocation strategies, namely static, stack, and heap. The heap area is also called the dynamic memory allocation area, which is the memory directly created when the program is running. It determines the size of memory that an application can use, so the garbage collection process is managed based on the heap space memory. Among them, the capacity threshold can be understood as the maximum heap memory given by the system. When the total application memory exceeds the maximum heap memory limit given by the system, garbage collection will be performed.
[0045] In step S12, a time-consuming phase in the garbage collection process that consumes time greater than a time-consuming threshold is identified.
[0046] In the disclosed embodiment, the processing stage in the garbage collection process that takes longer than a time-consuming threshold can be understood as a time-consuming stage, and the thread stack information including the duration can be obtained by generating logs or using the Thread.currentThread().getStackTrace() code.
[0047] In one example, through a large amount of research and development data statistics, the time-consuming part of the garbage collection process mainly occurs in the three stages of finding the root set object (visitCurrentRoots), pausing the thread globally (stop theworld), and cleaning up (sweepSystemWeaks). That is, the three stages of finding the root set object, pausing the thread globally, and cleaning up can be mainly processed.
[0048] In step S13, the processing method of the time-consuming stage is adjusted so that the time consumption of the adjusted time-consuming stage is less than the time consumption threshold.
[0049] In the embodiment of the present disclosure, based on the identified time-consuming stages, the time-consuming stages are processed so that the time-consuming stages that originally took longer than the time-consuming threshold are converted into time-consuming stages that take less than the time-consuming threshold after adjustment.
[0050] In the disclosed embodiment, by adjusting the processing method of the time-consuming stage in the garbage collection process, the time-consuming time can be shortened, the running time of the garbage collection process can be reduced, and problems such as lag and frame drop caused by garbage collection can be avoided.
[0051] The following is an explanation of the processing method of adjusting the time-consuming stage in the embodiment of the present disclosure.
[0052] Adjustments to the handling of time-consuming phases, including:
[0053] Increase the priority of time-consuming stages of electronic equipment.
[0054] In the disclosed embodiment, when a terminal, television, vehicle-mounted system, etc. performs garbage collection, if it is identified that there is a time-consuming stage that takes longer than a time-consuming threshold during the processing, the priority of the time-consuming stage can be increased. Among them, the priority increase process can be understood as increasing the priority of the time-consuming stage of the mobile device such as the terminal, television, and vehicle-mounted system, or dynamically adding the thread of the mobile device such as the terminal, television, and vehicle-mounted system corresponding to the time-consuming stage to the scheduling queue.
[0055] In one example, if there is frame loss due to a time-consuming phase, two actions can be taken. First, the processor priority of the time-consuming phase is increased from 120 to 100. Second, the thread of the time-consuming phase is dynamically added to the VIP scheduling queue, where the VIP scheduling queue is a thread scheduling queue with a relatively high priority, which usually contains tasks that need to be executed before other threads, ensuring that the threads in the VIP scheduling queue can be completed in time without being interfered by other low-priority tasks.
[0056] In the disclosed embodiments, the frequency of the time-consuming phase of electronic equipment processing is increased, the duration of the time-consuming phase is shortened, and the duration of the garbage collection process is correspondingly shortened, thereby optimizing the garbage collection process.
[0057] The following is an explanation of predetermining the available capacity of the heap space in the embodiment of the present disclosure.
[0058] Figure 4 is a flowchart of a method for predetermining the available capacity of a heap space according to an exemplary embodiment. Figure 4 As shown, the method includes steps S21 to S22.
[0059] In step S21, based on multiple parameter pairs, a target parameter pair is selected, the target parameter pair includes a maximum free memory and a minimum free memory, and the target parameter pair makes the adjusted time consumption less than a time consumption threshold.
[0060] In the disclosed embodiment, the minimum free memory of the heap, the maximum free memory of the heap and the utilization rate of the heap memory directly determine the ratio of the used memory and the free memory in the heap after the garbage collection is completed. Therefore, a parameter pair can be composed of the minimum free memory of the heap and the maximum free memory of the heap. By modifying the parameter pair, that is, the values of the minimum free memory of the heap and the maximum free memory of the heap, adjusting the parameter ratio of the minimum free memory of the heap and the maximum free memory of the heap, and finding a more appropriate ratio between the used memory of the heap and the free memory, the time of the time-consuming stage can be reduced. Among them, the parameter pair is adjusted for the system of the electronic device, that is, all applications in this system uniformly use the adjusted parameter pair.
[0061] In an example, Figure 5 , Figure 5 is a schematic diagram showing a specific situation of garbage collection with different parameters according to an exemplary embodiment, see Figure 5 As shown in the figure, there are three parameter pairs, namely, the minimum free memory of the heap (MinFree): the maximum free memory of the heap (MaxFree), where MinFree can be understood as the minimum amount of free memory that the system considers acceptable for allocating new objects during program operation, in megabytes. If the remaining free memory is less than this value after garbage collection, the system will perform garbage collection more frequently, so the minimum value cannot be less than MinFree. MaxFree can be understood as the maximum amount of memory that can be immediately allocated to new objects after garbage collection, in megabytes, and the maximum free memory space cannot be greater than MaxFree. ":" represents the ratio of MinFree to MaxFree. The three parameter pairs are 2:8, 8:32, and 16:24, respectively. Based on these three parameter pairs, one parameter pair is selected as the target parameter pair, which satisfies the requirement that the time consumption of the time-consuming stage in the garbage collection process based on this parameter pair is less than the time consumption threshold.
[0062] In step S22, the target parameter pair is used to determine the available capacity of the heap space.
[0063] In the disclosed embodiment, the target parameter pair is a parameter pair selected from multiple parameter pairs, that is, the target parameter pair is also the ratio of MinFree to MaxFree, and MinFree and MaxFree determine the ratio of used memory and free memory in the heap, so the available capacity of the heap space can be determined by the target parameter pair.
[0064] In the disclosed embodiment, MinFree and MaxFree are modified to find a suitable ratio between the used memory and the free memory of the heap, which can reduce the number of garbage collections and the number of ANR errors that occur in electronic devices.
[0065] The following is an explanation of the embodiment of the present disclosure on determining a target parameter pair based on multiple parameter pairs.
[0066] Figure 6 is a flowchart of a method for determining a target parameter pair according to an exemplary embodiment. Figure 6 As shown, the method includes steps S31 to S32.
[0067] In step S31, garbage collection is performed based on the available capacity of the heap space corresponding to each parameter pair in the plurality of parameter pairs, and one or more performance data of the garbage collection execution process are monitored.
[0068] In the embodiment of the present disclosure, the garbage collection process is executed separately using each parameter pair, and the function of generating log messages is used to monitor one or more performance data that determine the time-consuming stage, and the one or more performance data corresponding to each parameter pair are recorded, and the one or more performance data of each parameter pair are compared.
[0069] In step S32, based on one or more performance data, a parameter pair corresponding to the performance data that meets the performance index requirement is determined as a target parameter pair.
[0070] In the embodiment of the present disclosure, based on one or more performance data obtained through monitoring, a parameter pair corresponding to the performance data that meets the performance index requirement is determined as a target parameter pair. Among them, meeting the performance index requirement can be understood as reducing the number of garbage collections and shortening the processor processing time, that is, meeting one or more performance data that takes less than a time threshold, and the parameter pair corresponding to the one or more performance data at this time is used as the target parameter pair.
[0071] In the disclosed embodiment, based on the adjustment parameters, performance data that can optimize the performance of the garbage collection process is selected as a target parameter pair, and the target parameter pair is applied to the garbage collection process, thereby reducing the number of garbage collections, reducing the consumption of system applications, and improving the fluency of system use.
[0072] The embodiments of the present disclosure describe one or more performance data below.
[0073] The one or more performance data include at least one of the following:
[0074] Average garbage collection times, average processor usage time, and average memory usage.
[0075] In the embodiments of the present disclosure, refer to Figure 5 As shown in the figure, garbage collection is related to the average garbage collection times, average processor usage time, and average memory usage data. The average memory usage can be understood as the average memory usage of all applications in the current system. By generating logs, the average garbage collection times, average processor usage time, and average memory usage data within one minute can be obtained when the system is currently using a certain parameter pair. When adjusting MinFree and MaxFree, the corresponding changes of these three data are mainly monitored to select the appropriate target parameter pair.
[0076] In an example, when MinFree:MaxFree is 2:8, the average number of garbage collections is 14, the average processor usage time is 590ms, and the average memory usage is 7697990. When MinFree:MaxFree is 8:32, the average number of garbage collections is 7, the average processor usage time is 156ms, and the average memory usage is 7993147. When MinFree:MaxFree is 16:64, the average number of garbage collections is 5, the average processor usage time is 68ms, and the average memory usage is 8559068. Based on one or more performance data, the parameter pair corresponding to the performance data that meets the performance indicator requirements is determined as the target parameter pair. Figure 5The three sets of data given show that when MinFree:MaxFree is 16:64, the average number of garbage collections is 5, which is the least, but the average memory usage is the largest. When MinFree:MaxFree is 16:64, the average processor usage time is 156ms, which is the least, but the average memory usage is the largest. When MinFree:MaxFree is 2:8, the average memory usage is the smallest, but the average number of garbage collections and the average processor usage time are both the largest. Therefore, a suitable balance value is selected, and finally MinFree:MaxFree is selected as 8:32, which is applied to all applications in the entire system.
[0077] In the disclosed embodiment, target parameter pairs are selected based on performance data to optimize the garbage collection process, thereby reducing the time spent in the time-consuming stage, that is, reducing the number of garbage collection pauses and the running time of garbage collection, thereby reducing problems such as lag and frame drops caused by garbage collection, and improving the smoothness of system use.
[0078] Figure 7 is a schematic diagram showing the relationship between different values and the memory usage of an application according to an exemplary embodiment. Figure 7 As shown, including the following:
[0079] In the disclosed embodiment, the application memory usage corresponding to different value pairs is shown. For example, in the figure, when MinFree:MaxFree is 16:64, WeChat occupies about 140,000 memory, when MinFree:MaxFree is 2:8, WeChat occupies about 160,000 memory, when MinFree:MaxFree is 8:32, WeChat occupies about 120,000 memory, and finally MinFree:MaxFree is 8:32 as the target parameter corresponding to the application of the entire system.
[0080] In the disclosed embodiment, based on different parameters, the memory occupied by the corresponding application during use can be seen that after adjusting the memory size, the memory usage of the application memory changes, which optimizes the entire garbage collection process and improves the fluency of system use.
[0081] The above disclosed embodiment increases the frequency of processing in the time-consuming stage of point device processing based on adjustment parameters, shortens the garbage collection time, reduces the number of garbage collections, reduces the problem of system freezes and frame drops, and improves the fluency of system use.
[0082] Based on the same concept, the embodiment of the present disclosure also provides a garbage collection device 100 .
[0083] It is understandable that, in order to realize the above functions, the garbage collection device 100 provided in the embodiment of the present disclosure includes hardware structures and / or software modules corresponding to the execution of each function. In combination with the units and algorithm steps of each example disclosed in the embodiment of the present disclosure, the embodiment of the present disclosure can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art may use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the technical solution of the embodiment of the present disclosure.
[0084] Figure 8 is a block diagram of a garbage collection device 100 according to an exemplary embodiment. Figure 8 The device includes a responding unit 101, an identifying unit 102 and an adjusting unit 103.
[0085] The response unit 101 is used to perform garbage collection in response to the available capacity in the electronic device stack space reaching a capacity threshold.
[0086] The identification unit 103 is used to identify a time-consuming phase in the garbage collection process that consumes more time than a time-consuming threshold.
[0087] The adjusting unit 103 is used to adjust the processing method of the time-consuming stage so that the time consumption of the adjusted time-consuming stage is less than the time consumption threshold.
[0088] In one implementation, the processing method of the time-consuming phase is adjusted, and the adjusting unit 103 is further used to: increase the priority of the time-consuming phase of the electronic device.
[0089] In one embodiment, the response unit 101 predetermines the available capacity of the heap space in the following manner: based on multiple parameter pairs, a target parameter pair is selected, the target parameter pair includes a maximum free memory and a minimum free memory, and the target parameter pair makes the adjusted time consumption less than a time consumption threshold; the target parameter pair is used to determine the available capacity of the heap space.
[0090] In one embodiment, the response unit 101 selects a target parameter pair based on multiple parameter pairs in the following manner: based on the available capacity of the heap space corresponding to each parameter pair in the multiple parameter pairs, garbage collection is performed separately, and one or more performance data of the garbage collection execution process are monitored; based on one or more performance data, a parameter pair corresponding to the performance data that meets the performance indicator requirements is determined as the target parameter pair.
[0091] In one implementation, the one or more performance data include at least one of the following: average garbage collection times data, average processor occupancy time data, and average memory occupancy data.
[0092] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0093] Fig. 9 2 is a block diagram of a device 200 for garbage collection according to an exemplary embodiment. The device 200 may be provided as a terminal. For example, the device 200 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0094] Reference Fig. 9 , the device 200 may include one or more of the following components: a processing component 202 , a memory 204 , a power component 206 , a multimedia component 208 , an audio component 210 , an input / output (I / O) interface 212 , a sensor component 214 , and a communication component 216 .
[0095] The processing component 202 generally controls the overall operation of the device 200, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 202 may include one or more processors 220 to execute instructions to perform all or part of the steps of the above-described method. In addition, the processing component 202 may include one or more modules to facilitate interaction between the processing component 202 and other components. For example, the processing component 202 may include a multimedia module to facilitate interaction between the multimedia component 208 and the processing component 202.
[0096] The memory 204 is configured to store various types of data to support operations on the device 200. Examples of such data include instructions for any application or method operating on the device 200, contact data, phone book data, messages, pictures, videos, etc. The memory 204 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0097] The power component 206 provides power to the various components of the device 200. The power component 206 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device 200.
[0098] The multimedia component 208 includes a screen that provides an output interface between the device 200 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 208 includes a front camera and / or a rear camera. When the device 200 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0099] The audio component 210 is configured to output and / or input audio signals. For example, the audio component 210 includes a microphone (MIC), and when the device 200 is in an operating mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 204 or sent via the communication component 216. In some embodiments, the audio component 210 also includes a speaker for outputting audio signals.
[0100] I / O interface 212 provides an interface between processing component 202 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0101] The sensor assembly 214 includes one or more sensors for providing various aspects of the status assessment of the device 200. For example, the sensor assembly 214 can detect the open / closed state of the device 200, the relative positioning of components, such as the display and keypad of the device 200, the sensor assembly 214 can also detect the position change of the device 200 or a component of the device 200, the presence or absence of user contact with the device 200, the orientation or acceleration / deceleration of the device 200 and the temperature change of the device 200. The sensor assembly 214 can include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 214 can also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 214 can also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor or a temperature sensor.
[0102] The communication component 216 is configured to facilitate wired or wireless communication between the device 200 and other devices. The device 200 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 216 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 216 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0103] In an exemplary embodiment, the apparatus 200 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to perform the above method.
[0104] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 204 including instructions, and the instructions can be executed by the processor 220 of the device 200 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0105] Fig.10 is a block diagram of a garbage collection device 300 according to an exemplary embodiment. For example, the device 300 may be provided as a server. Fig.10 , the apparatus 300 includes a processing component 322, which further includes one or more processors, and a memory resource represented by a memory 332 for storing instructions, such as an application, that can be executed by the processing component 322. The application stored in the memory 332 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 322 is configured to execute the instructions to perform the above method.
[0106] The device 300 may also include a power supply component 326 configured to perform power management of the device 300, a wired or wireless network interface 350 configured to connect the device 300 to a network, and an input / output (I / O) interface 358. The device 300 may operate based on an operating system stored in the memory 332, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, or the like.
[0107] It is to be understood that in the present disclosure, "plurality" refers to two or more than two, and other quantifiers are similar. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the associated objects before and after are in an "or" relationship. The singular forms "a", "the" and "the" are also intended to include plural forms, unless the context clearly indicates other meanings.
[0108] It is further understood that the terms "first", "second", etc. are used to describe various information, but such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other, and do not indicate a specific order or degree of importance. In fact, the expressions "first", "second", etc. can be used interchangeably. For example, without departing from the scope of the present disclosure, the first information can also be referred to as the second information, and similarly, the second information can also be referred to as the first information.
[0109] It can be further understood that, unless otherwise specified, “connection” includes a direct connection without other components between the two, and also includes an indirect connection with other components between the two.
[0110] It is further understood that, although the operations are described in a specific order in the drawings in the embodiments of the present disclosure, it should not be understood as requiring the operations to be performed in the specific order shown or in a serial order, or requiring the execution of all the operations shown to obtain the desired results. In certain environments, multitasking and parallel processing may be advantageous.
[0111] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any modifications, uses or adaptations of the present disclosure, which follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure.
[0112] It should be understood that the present disclosure is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the scope of the appended claims.
Claims
1. A garbage collection method, characterized in that: include: In response to the available capacity in the electronic device heap space reaching a capacity threshold, performing garbage collection; Identifying a time-consuming phase in the garbage collection process that consumes more time than a time-consuming threshold; The processing method of the time-consuming stage is adjusted so that the time consumption of the adjusted time-consuming stage is less than the time consumption threshold.
2. The method according to claim 1, characterized in that: The adjustment of the processing method of the time-consuming stage includes: Raise the priority of the time-consuming phase of the electronic device.
3. The method according to claim 1, characterized in that The available capacity of the heap space is predetermined in the following manner: Based on the plurality of parameter pairs, selecting a target parameter pair, the target parameter pair comprising a maximum free memory and a minimum free memory, the target parameter pair making the adjusted time consumption less than the time consumption threshold; The target parameter pair is used to determine the available capacity of the heap space.
4. The method according to claim 3, characterized in that The step of selecting a target parameter pair based on a plurality of parameter pairs comprises: Based on the available capacity of the heap space corresponding to each of the plurality of parameter pairs, respectively perform garbage collection, and monitor one or more performance data of the garbage collection execution process; Based on the one or more performance data, a parameter pair corresponding to the performance data that meets the performance indicator requirement is determined as a target parameter pair.
5. The method according to claim 4, characterized in that The one or more performance data include at least one of the following: Average garbage collection times, average processor usage time, and average memory usage.
6. A garbage collection device, characterized in that: include: a response unit, configured to perform garbage collection in response to the available capacity in the electronic device stack space reaching a capacity threshold; An identification unit, used to identify a time-consuming phase in the garbage collection process that consumes more time than a time-consuming threshold; The adjusting unit is used to adjust the processing method of the time-consuming stage so that the time consumption of the adjusted time-consuming stage is less than the time consumption threshold.
7. The device according to claim 6, characterized in that The processing method of the time-consuming stage is adjusted, and the adjusting unit is further used for: Raise the priority of the time-consuming phase of the electronic device.
8. The device according to claim 6, characterized in that The response unit predetermines the available capacity of the heap space in the following manner: Based on the plurality of parameter pairs, selecting a target parameter pair, the target parameter pair comprising a maximum free memory and a minimum free memory, the target parameter pair making the adjusted time consumption less than the time consumption threshold; The target parameter pair is used to determine the available capacity of the heap space.
9. The device according to claim 8, characterized in that The response unit selects a target parameter pair based on multiple parameter pairs in the following manner: Based on the available capacity of the heap space corresponding to each of the plurality of parameter pairs, respectively perform garbage collection, and monitor one or more performance data of the garbage collection execution process; Based on the one or more performance data, a parameter pair corresponding to the performance data that meets the performance indicator requirement is determined as a target parameter pair.
10. The device according to claim 9, characterized in that The one or more performance data include at least one of the following: Average garbage collection times, average processor usage time, and average memory usage.
11. A garbage collection device, characterized in that: include: processor: a memory for storing processor-executable instructions; Wherein, the processor is configured to: execute the garbage collection method described in any one of claims 1 to 5.
12. A storage medium, characterized in that: The storage medium stores instructions, and when the instructions in the storage medium are executed by a processor, the processor is enabled to execute the garbage collection method according to any one of claims 1 to 5.