Garbage Collection Method, Device, Storage Medium and Electronic Device
By converting garbage collection tasks of explicit recycling types into parallel recycling and processing, and using auxiliary threads to perform garbage collection tasks, the task blocking problem caused by explicit recycling types is solved, the garbage collection process is optimized, and the application performance and disaster recovery capabilities are improved.
Patent Information
- Application Number
- CN202111363718.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-17
- Publication Date
- 2025-07-29
- Estimated Expiration
- 2041-11-17
AI Technical Summary
In the prior art, explicit recycling type garbage collection process will cause the target application thread to wait for the garbage collection task to be completed, affecting the task progress and reducing the garbage collection efficiency, and thus affecting the application performance.
By determining that the type of the garbage collection task is an explicit recycling type, the electronic device converts it into parallel recycling and uses auxiliary threads to perform garbage collection tasks to ensure that the target application thread can execute the next task in parallel.
The garbage collection process is optimized, the application performance is guaranteed, the disaster recovery capability in the garbage collection process is improved, the original explicit recycling process corresponding to the explicit recycling type is blocked, and the task processing efficiency is improved.
Smart Images

Figure CN113918350B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular, to a garbage collection method, apparatus, storage medium, and electronic device. Background Art
[0002] With the rapid development of computer technology, more and more applications are installed on electronic devices. During the operation of applications on an electronic device, garbage collection is involved. Garbage collection is a mechanism that reclaims objects to be recycled in the heap through a thread to release memory space. By performing garbage collection, memory can be released to ensure the normal operation of applications. Summary of the Invention
[0003] Embodiments of this application provide a garbage collection method, apparatus, storage medium, and electronic device. The technical solutions are as follows:
[0004] In a first aspect, embodiments of this application provide a garbage collection method, which includes:
[0005] Determine that a target application thread triggers a garbage collection task, and obtain the garbage collection type corresponding to the garbage collection task;
[0006] If the garbage collection type is an explicit collection type, perform parallel collection processing on the garbage collection task.
[0007] In a second aspect, embodiments of this application provide a garbage collection apparatus, which includes:
[0008] A task determination module, configured to determine that a target application thread triggers a garbage collection task, and obtain the garbage collection type corresponding to the garbage collection task;
[0009] A collection processing module, configured to perform parallel collection processing on the garbage collection task if the garbage collection type is an explicit collection type.
[0010] In a third aspect, embodiments of this application provide a computer storage medium, which stores multiple instructions, and the instructions are adapted to be loaded and executed by a processor to perform the above method steps.
[0011] In a fourth aspect, embodiments of this application provide an electronic device, which may include: a processor and a memory; wherein, the memory stores a computer program, and the computer program is adapted to be loaded and executed by the processor to perform the above method steps.
[0012] The beneficial effects brought by the technical solutions provided by some embodiments of this application at least include:
[0013] In one or more embodiments of the present application, the electronic device triggers a garbage collection task by determining a target application thread, obtains the garbage collection type corresponding to the garbage collection task, and if the garbage collection type is an explicit collection type, the electronic device performs parallel collection processing on the garbage collection task, avoiding garbage collection according to the original explicit collection process corresponding to the explicit collection type, optimizing the garbage collection process, and smoothly ensuring the task execution of the target application thread while performing garbage collection, ensuring the application performance during garbage collection and also enhancing the disaster tolerance ability during garbage collection. Description of the Drawings
[0014] To more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.
[0015] Figure 1 It is a flowchart of a garbage collection method provided by an embodiment of the present application;
[0016] Figure 2 It is a schematic diagram of garbage collection related to an explicit collection type provided by an embodiment of the present application;
[0017] Figure 3 It is a flowchart of another embodiment related to the garbage collection method provided by an embodiment of the present application;
[0018] Figure 4 It is a schematic diagram of a scenario related to parallel garbage collection provided by an embodiment of the present application;
[0019] Figure 5 It is a schematic diagram of a scenario for performing garbage collection provided by an embodiment of the present application;
[0020] Figure 6 It is a flowchart of another embodiment related to the garbage collection method provided by an embodiment of the present application;
[0021] Figure 7 It is a schematic diagram of the structure of a garbage collection device provided by an embodiment of the present application;
[0022] Figure 8 It is a schematic diagram of the structure of a recycling processing module provided by an embodiment of the present application;
[0023] Figure 9 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present application;
[0024] Figure 10It is a schematic structural diagram of the operating system and user space provided by the embodiments of the present application;
[0025] Figure 11 is Figure 10 the architecture diagram of the Android operating system in
[0026] Figure 12 is Figure 10 the architecture diagram of the IOS operating system in Specific embodiments
[0027] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0028] In the description of the present application, it should be understood that the terms "first", "second", etc. are only used for descriptive purposes and cannot be construed as indicating or implying relative importance. In the description of the present application, it should be noted that unless otherwise clearly specified and limited, "including" and "having", and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but optionally further includes steps or units not listed, or optionally further includes other steps or units inherent to these processes, methods, products, or devices. For those of ordinary skill in the art, the specific meanings of the above terms in the present application can be understood in specific situations. In addition, in the description of the present application, unless otherwise stated, "a plurality" means two or more. "And / or" describes the association relationship of associated objects and indicates that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. The character " / " generally represents an "or" relationship between the associated objects before and after.
[0029] The present application will be described in detail below with specific embodiments.
[0030] In one embodiment, as Figure 1As shown, a garbage collection method is proposed. This method can be implemented relying on a computer program and can run on a garbage collection device based on the von Neumann architecture. The computer program can be integrated into an application or run as an independent utility application. The garbage collection device can be an electronic device, including but not limited to: personal computers, tablets, handheld devices, in-vehicle devices, wearable devices, computing devices, or other processing devices connected to a wireless modem, etc. In different networks, the terminal device can be called by different names, such as: user equipment, access terminal, user unit, user station, mobile station, mobile device, remote station, remote terminal, mobile device, user terminal, terminal, wireless communication device, user agent or user device, cellular phone, cordless phone, electronic device in a 5G network or future evolved network, etc.
[0031] Specifically, the garbage collection method includes:
[0032] S101: Determine that the target application thread triggers a garbage collection task, and obtain the garbage collection type corresponding to the garbage collection task;
[0033] The garbage collection (GC) can be understood as a mechanism for recycling some objects to be recycled in the heap to release memory space. In some embodiments, the objects to be recycled at least include isolated objects. An isolated object can be understood as an object in the heap that has no reference to other objects.
[0034] The heap can be understood as the area in the memory of an electronic device used to store objects (such as object instances). In some embodiments, if the memory management technology uses the JAVA language, the heap is the largest area in the memory managed by the system virtual machine. This area is a memory area shared by all threads, and the heap is created when the virtual machine starts. Usually, objects can allocate memory in the heap.
[0035] It can be understood that for an electronic device, the electronic device is equipped with at least one application, which can be an application that comes with the electronic device's operating system itself, or a third-party application; the application thread is the smallest unit that the operating system can use to perform application business operations and scheduling. Usually, the application thread is related to the process. The application thread is included in the process and serves as the actual operating unit in the process. Among them, an application thread refers to a single sequential control flow in the process. Multiple application threads can run concurrently in a process, and each application thread executes different application tasks in parallel. Furthermore, the application on the electronic device will correspond to a process when running, and will usually correspond to different application threads depending on the application business of the application. It can also be understood that the application thread is a bridge between the application and the object. When the user operates the application on the electronic device to perform the corresponding function, the application will trigger the application thread corresponding to the function to access the object in the heap to implement the corresponding function.
[0036] The target application thread can be understood as the application thread that currently triggers the garbage collection task.
[0037] It can be understood that the electronic device can monitor each application thread in the thread pool and monitor the application tasks to be executed by the application threads. If it is detected that the task to be executed of a target application thread is a garbage collection task (GC task), it can be determined that the target application thread is about to trigger the garbage collection task. The electronic device then parses the garbage collection task corresponding to the application thread and obtains the garbage collection type corresponding to the garbage collection task.
[0038] In a feasible implementation, the electronic device can monitor the garbage collection interface. Usually, when the target application thread executes the garbage collection task, it will first call the corresponding garbage collection interface. By monitoring the garbage collection interface, the electronic device can determine that the target application thread triggers the garbage collection task; further, garbage collection tasks of different garbage collection types usually correspond to different garbage collection interfaces. The electronic device only needs to determine the garbage collection type corresponding to the garbage collection task based on the type of garbage collection interface triggered by the target application thread. It can be understood that the type of garbage collection interface corresponds to the garbage collection type of the garbage collection task.
[0039] Optionally, a mapping relationship between each "reference garbage collection type corresponding to the garbage collection task" and the corresponding "reference type of the garbage collection interface" can be established in advance. Based on this mapping relationship, the electronic device can determine the garbage collection type corresponding to the garbage collection task based on the type of the garbage collection interface after determining that the current garbage collection interface is triggered (or called) by the target thread.
[0040] It can be understood that the garbage collection types can be at least divided into parallel garbage collection types and blocking garbage collection types. The blocking garbage collection type is distinguished from the garbage collection process: the blocking garbage collection type can be called the serial garbage collection type. In some embodiments, the blocking garbage collection type includes but is not limited to Explicit GC (explicit garbage collection type, which can be understood as the garbage collection type in the scenario of explicit calls), Alloc GC (garbage collection type in the memory allocation scenario), Background GC (garbage collection type in the background running scenario), and so on.
[0041] In a specific implementation scenario, when the garbage collection task is of the Explicit GC explicit garbage collection type, usually the target application thread will call the Explicit GC interface (Explicit garbage collection interface) to execute the garbage collection task. It can be understood that when the electronic device monitors that the Explicit GC interface is called by the target application thread, it can determine that the target application thread is about to trigger the garbage collection task to execute the garbage collection process corresponding to the Explicit GC interface.
[0042] S102: If the garbage collection type is the explicit garbage collection type, then perform parallel garbage collection processing on the garbage collection task.
[0043] It can be understood that when the garbage collection task triggered by the target application thread is of the explicit garbage collection type, if the target application thread is based on the explicit garbage collection process corresponding to the explicit garbage collection type, usually it needs to wait until the garbage collection task is executed before it can execute the next target thread task of the garbage collection task;
[0044] Schematically, as Figure 2 shown, Figure 2 is a schematic diagram of garbage collection involved in an explicit garbage collection type. Thread A of a certain application on the electronic device calls the Explicit GC interface at this time to execute the explicit garbage collection process of the garbage collection task. After the garbage collection task is completed from Figure 2 step 02 to step 07 in, thread A can execute the next task of the garbage collection task.
[0045] As Figure 2 shown, the explicit garbage collection process can usually be:
[0046] Step 02: The target application thread - thread A calls the Explicit GC interface on the application side to trigger garbage collection, such as Runtime.gc() and System.gc();
[0047] Step 03: Call the Native interface through the Explicit GC interface on the local interface side (JNI side) to trigger garbage collection;
[0048] Step 04: Trigger garbage collection by calling the JVM GC interface (Java virtual machine garbage collection interface) on the virtual machine side (ART side) through the Native interface;
[0049] Step 05: Trigger explicit garbage collection by calling the GC interface that executes the explicit GC task through the JVM GC interface on the virtual machine side (ART side), for example, the CollectGarbage interface
[0050] Step 06: Start garbage collection by calling the garbage collection implementation interface through the GC interface that executes the explicit GC task on the virtual machine side (ART side), for example: CollectGarbageInternal()
[0051] Step 07: Complete the garbage collection task of the explicit recovery type through the garbage collection implementation interface on the virtual machine side (ART side).
[0052] It can be understood that the electronic device executes the corresponding explicit recovery process based on the explicit recovery type by the target application thread. In some implementation scenarios, the target application thread needs to wait for the garbage collection of the explicit recovery process to complete before it can execute the next task, resulting in low garbage collection efficiency and increased thread logic running time, which in turn affects the task progress of the target application thread. In this application, if the electronic device determines that the garbage collection type is the explicit recovery type, it can perform parallel recovery processing on the garbage collection task. It can be understood as performing garbage collection based on the parallel recovery process of the parallel recovery type. At the same time, after the target application thread triggers the garbage collection task, it can execute the next task of the garbage collection task in parallel. In some embodiments, the target application thread of the electronic device triggers the parallel garbage collection interface of the parallel recovery process. On the one hand, at this time, the electronic device uses an auxiliary thread other than the target application thread to execute the garbage collection task by triggering the parallel garbage collection interface. On the other hand, after the auxiliary thread calls the parallel garbage collection interface, it executes the next thread task corresponding to the garbage collection task. It can be understood that the target application thread can perform the next task without waiting for the completion of the garbage collection, improving the task processing efficiency and avoiding the impact on the operation of the target application thread when the garbage collection task execution goes wrong.
[0053] It is understandable that during the garbage collection process, by determining the reference relationships of the created objects in the heap and marking and organizing the created objects based on the reference relationships, such as marking live objects and isolated objects, and then the corresponding objects can be recycled to release memory space. For example, deleting isolated objects to release the memory space occupied by the isolated objects. Marking live objects can start from root objects based on the garbage collection strategy. Since root objects can only reference other objects and cannot be referenced by other objects, starting from root objects, recursively mark the objects referenced by root objects as live objects.
[0054] In the embodiments of the present application, the electronic device determines that the target application thread triggers a garbage collection task, obtains the garbage collection type corresponding to the garbage collection task. If the garbage collection type is an explicit collection type, the electronic device performs parallel collection processing on the garbage collection task, avoiding garbage collection according to the original explicit collection process corresponding to the explicit collection type, optimizing the garbage collection process, and smoothly ensuring the task operation of the target application thread while performing garbage collection, ensuring the application performance during the garbage collection process and also improving the disaster tolerance ability during the garbage collection process.
[0055] Please refer to Figure 3 , Figure 3 which is a schematic flowchart of another embodiment of a garbage collection method proposed by the present application. Specifically:
[0056] S201: Determine that the target application thread triggers a garbage collection task, and obtain the garbage collection type corresponding to the garbage collection task;
[0057] According to some embodiments, the electronic device determines that the target application thread triggers a garbage collection task, obtains the garbage collection type corresponding to the garbage collection task, and then if the garbage collection type is an explicit collection type, generally the garbage collection process corresponding to the garbage collection task can be updated to a parallel collection process;
[0058] For the specific method steps, reference can be made to other embodiments of the present application, which will not be elaborated here.
[0059] S202: If the garbage collection type is an explicit collection type, obtain the garbage collection process corresponding to the garbage collection task, and perform interface update processing on the garbage collection interface corresponding to the garbage collection process;
[0060] In some embodiments, when the garbage collection task is of the Explicit GC type, usually the target application thread will call the Explicit GC interface (Explicit garbage collection interface) to execute the garbage collection task. It can be understood that when the electronic device monitors that the Explicit GC interface is called by the target application thread, it can determine that the target application thread is about to trigger the garbage collection task to execute the garbage collection process corresponding to the Explicit GC interface.
[0061] It can be understood that for Explicit GC explicit recycling, usually the working thread corresponding to the application of the electronic device directly calls the relevant garbage collection interface based on the display call method to initiate a garbage collection actively; in the related art, usually after the garbage collection is executed by the initiator (the thread that initiates the explicit recycling), the next thread task of the garbage collection task is continued, such as calling the next function or the next method.
[0062] It can be understood that in order to prevent the target application thread from waiting for the explicit recycling process to complete the garbage collection before it can execute the next task in some implementation scenarios, so as to avoid low garbage collection efficiency. In one or more embodiments of the present application, the garbage collection process corresponding to the garbage collection task can be updated to a parallel recycling process, and the garbage collection is performed in a parallel recycling manner. Specifically, in implementation, the electronic device can achieve this by performing interface update processing on the garbage collection interface corresponding to the garbage collection process. The electronic device obtains the garbage collection process corresponding to the garbage collection task (usually the explicit recycling process corresponding to the explicit recycling type), and then updates the corresponding GC interface in the explicit recycling process, that is, performs interface update processing on the garbage collection interface in the explicit recycling process, so as to release the garbage collection task being executed by the target application thread, enabling the target application thread to execute the next target thread task, while the original garbage collection task is completed by other auxiliary threads after the interface update processing.
[0063] In a feasible implementation, the garbage collection process of the explicit recycling type is usually triggered by the target application thread of the application initiator on the application side through the explicit recycling interface, and the local interface for executing garbage collection on the local interface side is called through the explicit recycling interface. Based on the "local interface for executing garbage collection on the local interface layer", the relevant GC interfaces in the virtual machine side are called. In this application, it can be an interface update process for the underlying relevant GC interfaces in the virtual machine side to avoid task crashes caused by changing the execution logic on the application side or the local interface side, while ensuring the progress of garbage collection. Taking JAVA as an example, the electronic device does not update the execution logic at the application layer and the JNI layer (JAVA local interface layer), but updates the garbage collection interface corresponding to the explicit recycling process at the ART layer (virtual machine), and controls the invocation of other auxiliary threads to complete the garbage collection task, so as to complete the garbage collection task in parallel with the target application thread.
[0064] In a feasible implementation,
[0065] 1. Obtain the first recycling interface corresponding to the garbage collection task.
[0066] The first recycling interface is usually the garbage collection interface in the explicit recycling process corresponding to the explicit recycling type;
[0067] It can be understood that for the garbage collection task of the explicit recycling type, the target application thread at the application layer usually calls the Explicit GC interface. In the explicit recycling process at the virtual machine layer (or virtual machine side, such as the ART layer), the display GC interface in the virtual machine for executing the display GC is involved. In some embodiments, the display GC interface in the virtual machine for executing the display GC can be the CollectGarbage interface, and the GC interface for executing the explicit GC task triggers the explicit garbage collection. It can be understood that the first recycling interface can at least include the display GC interface in the virtual machine layer (for executing the display GC task).
[0068] 2. The electronic device can update the first recycling interface to a second recycling interface, and the second recycling interface is associated with the parallel recycling process.
[0069] The second recycling interface can be understood as a function interface for converting the garbage collection task of the explicit recycling type into a parallel recycling process; in some embodiments, the first recycling interface and the second recycling interface belong to the interfaces of the same virtual machine layer (side).
[0070] In some embodiments, the second recycling interface may be a newly created function interface for converting garbage collection tasks of the explicit recycling type into a parallel recycling process. The interface definition of the second recycling interface may be determined based on the actual application environment. For example, the name of the second recycling interface may be set as the RequestConcurrentGCInExplicit() interface. Further, the Figure 2 CollectGarbage() interface called in step 05 in Figure 2 may be replaced with the newly added RequestConcurrentGCInExplicit() interface;
[0071] It can be understood that the function of the second recycling interface may be set to convert garbage collection tasks of the explicit recycling type into a parallel recycling process;
[0072] Optionally, the function of the second recycling interface may be set to call the parallel recycling interface to add garbage collection tasks to the dedicated thread (i.e., the first recycling thread) of the parallel recycling process.
[0073] Optionally, the function of the second recycling interface may be set to execute the garbage collection process by other working threads.
[0074] It can be understood that the electronic device updates the first recycling interface to the second recycling interface to implement parallel recycling processing of garbage collection tasks. At the same time, the electronic device can control the target application thread to execute the next target thread task of the garbage collection task at this time.
[0075] S203: Associate the garbage collection task with the parallel recycling process through the garbage collection interface after interface update processing.
[0076] It can be understood that the electronic device realizes the association between the garbage collection task and the parallel recycling process through the garbage collection interface after interface update processing, and executes the garbage collection task based on the parallel recycling process. The original target application thread no longer executes the garbage collection task but executes the next target thread task. For example, the target application thread may be the application main thread, rendering thread, etc. corresponding to the application. These target application threads usually initiate an explicit recycling process in the form of an explicit recycling type when initiating a garbage collection task.
[0077] It can be understood that in this application, the target application thread no longer executes the garbage collection task. Based on this, the electronic device can control the auxiliary thread other than the target application thread to execute the garbage collection task. Thus, the garbage collection task and the target thread task (the next task of the garbage collection task) are executed in parallel.
[0078] In a specific implementation scenario, the electronic device can add a parallel garbage collection task to the auxiliary thread by triggering the second recycling interface. For example, the RequestConcurrentGCInExplicit() interface added can be used to adjust the parallel garbage collection task to the auxiliary thread.
[0079] Specifically, by triggering the second recycling interface to add a parallel garbage collection task to the auxiliary thread, the task parameters are set during the process of adding the parallel garbage collection task to ensure that the GC recycling and memory reorganization are consistent with the original GC process. After requesting the auxiliary thread, the auxiliary thread will execute immediately. The setting of task parameters includes but is not limited to: "setting the gc_cause (trigger reason) of the parallel garbage collection task to be triggered by the target application thread, for example, setting it to the name of the target application thread", "setting the task execution time of the parallel garbage collection task to the current time (which can be understood as executing immediately at the current time), for example, setting it to NanoTime", the number of objects to be recycled, the type of objects to be recycled, and so on.
[0080] It can be understood that after adjusting the parallel garbage collection task to the auxiliary thread, when the auxiliary thread receives the parallel garbage collection task added by the target application thread, it wakes up from the sleep state to execute the parallel garbage collection task. Further, the auxiliary thread can also detect whether the execution conditions are met, such as checking whether the task execution time is less than or equal to the current time, and if so, execute the (parallel) garbage collection task.
[0081] It can be understood that the parallel garbage collection task is used to instruct the auxiliary thread to execute the garbage collection task in parallel, which can be understood as implementing the parallel execution of the garbage collection task and the target thread task (the next task of the garbage collection task).
[0082] Further, the parallel garbage collection task can be completed by the default recycling thread corresponding to the parallel recycling process, that is, using the default recycling thread corresponding to the parallel recycling process as the current auxiliary thread;
[0083] Further, the parallel garbage collection task can be completed by an application working thread other than the target application thread and the first recycling thread, that is, using this working thread as the current auxiliary thread;
[0084] In a feasible implementation manner, a parallel garbage collection task can be added to the first recycling thread through the second recycling interface, and the first recycling thread is the default recycling thread corresponding to the parallel recycling process;
[0085] It can be understood that the first recycling thread, as the default recycling thread corresponding to the parallel recycling process, is dedicated to processing the parallel recycling process. In related technologies, if the garbage collection type triggered by the garbage collection task is the parallel recycling type, it usually runs in parallel with the HeapTaskDaemon thread (also known as the dedicated GC recycling thread) in each worker process, and in parallel with the functional logic of the worker thread. In this application, it can be understood that parallel garbage collection is performed on garbage collection tasks belonging to the explicit recycling type.
[0086] Furthermore, as the first recycling thread corresponding to the parallel recycling process, the default recycling thread is usually implemented and called through the corresponding garbage collection interface. It can be understood that the electronic device can call the third recycling interface through the second recycling interface to trigger the first recycling thread to execute the parallel recycling process through the third recycling interface. The third recycling interface can be understood as the garbage collection interface corresponding to the parallel recycling process. For example, the name of the third recycling interface can be the RequestConcurrentGC interface based on the actual application situation.
[0087] Schematically, as Figure 4 shown, Figure 4 is a schematic diagram of a scenario involved in parallel garbage collection. Thread A of a certain application on the electronic device calls the Explicit GC interface at this time to execute the explicit recycling process of the garbage collection task. After adding a parallel garbage collection task to the first recycling thread by triggering the second recycling interface, the subsequent first recycling thread executes the garbage collection task while the target application thread executes the next target thread task of the garbage collection task.
[0088] Specifically, step 12: The target application thread calls the Explicit GC interface on the application side to trigger garbage collection, such as Runtime.gc() and System.gc();
[0089] Step 13: Call the Native interface through the Explicit GC interface on the local interface side (JNI side) to trigger garbage collection;
[0090] Step 14: Call the JVM GC interface (Java virtual machine garbage collection interface) through the Native interface on the virtual machine side (ART side) to trigger garbage collection;
[0091] Step 15: On the virtual machine side (ART side), update the first recycling interface to the second recycling interface to subsequently implement parallel recycling processing of the garbage collection task. At the same time, the electronic device can control the target application thread to execute the next target thread task of the garbage collection task at this time. In specific implementation, add a parallel garbage collection task to the first recycling thread through an interface such as the newly added RequestConcurrentGCInExplicit interface.
[0092] Step 16: Invoke the third recycling interface (RequestConcurrentGC interface) through the second recycling interface (such as the RequestConcurrentGCInExplicit interface) to trigger the invocation of the first recycling thread through the third recycling interface.
[0093] Step 17: Add a parallel garbage collection task to the first recycling thread through the third recycling interface.
[0094] Step 18: The target application thread executes the next target thread task of the garbage collection task.
[0095] Step 19: On the virtual machine side (ART side), the first recycling thread executes the parallel garbage collection task to complete the garbage collection task of the explicit recycling type.
[0096] In a specific implementation scenario, such as Figure 5 shown, Figure 5 is a schematic diagram of a scenario for executing garbage collection.
[0097] Step 191: After setting the task parameters for adding a parallel recycling task to the first recycling thread (such as the HeapTaskDaemon thread) on the virtual machine side (ART side), the electronic device wakes up the first recycling task. Further, the auxiliary thread can also detect whether the execution conditions are met, such as checking whether the task execution time is less than or equal to the current time, and if so, the (parallel) garbage collection task is executed.
[0098] Step 192: The first recycling thread (such as the HeapTaskDaemon thread) executes the parallel garbage collection task;
[0099] Step 193: The first recycling thread executes the parallel garbage collection task to internally call the GC implementation interface for garbage collection inside the virtual machine. The internal GC implementation interface can be the CollectGarbageInternal interface: the GC interface internally called by the virtual machine ART runtime, which can execute various types of GCs.
[0100] Step 193: The parallel garbage collection task is completed, and the garbage collection task of the explicit garbage collection type is completed.
[0101] It should be noted that the above first recycling thread is the default recycling thread corresponding to the parallel recycling process, and can also be understood as a dedicated parallel recycling thread or a (parallel) daemon thread.
[0102] In a feasible implementation, a second recycling thread can be determined, and a parallel garbage collection task can be added to the second recycling thread through a second recycling interface. The second recycling thread is an application working thread other than the target application thread and the first recycling thread. That is to say, the electronic device can execute the current (parallel) garbage collection task not based on the first recycling thread corresponding to the existing parallel recycling process, but adopt a second recycling thread outside of it.
[0103] Optionally, the second recycling thread can be created in the following way: create a second recycling thread and set the second recycling thread as the default recycling thread of the parallel recycling process;
[0104] In specific implementation: The electronic device can create another default recycling thread corresponding to the parallel recycling process as the second recycling thread, and use the newly created second recycling thread to specifically handle garbage collection tasks of the Explicit GC type. It can be understood that the second recycling thread usually performs garbage collection in the parallel garbage collection process at this time.
[0105] Illustratively: 1. After setting the task parameters for adding a parallel recycling task to the second recycling thread (such as the newly created HeapTaskDaemon thread) on the virtual machine side (ART side), the electronic device wakes up the first recycling task. Further, the auxiliary thread can also detect whether the execution conditions are met, such as checking whether the task execution time is less than or equal to the current time. If the conditions are met, the (parallel) garbage collection task is executed.
[0106] 2: The second recycling thread (such as the newly created HeapTaskDaemon thread) executes the parallel garbage collection task;
[0107] 3: The second recycling thread (such as the newly created HeapTaskDaemon thread) executes the parallel garbage collection task to call the GC implementation interface inside the virtual machine to perform garbage collection. The internal GC implementation interface can be the CollectGarbageInternal interface: the GC interface internally called by the virtual machine ART runtime, which can execute various types of GCs.
[0108] 4: After completing the parallel garbage collection task, the garbage collection task of the explicit garbage collection type is completed.
[0109] It should be noted that the above second recycling thread is the default recycling thread corresponding to the newly created parallel recycling process, and can also be understood as a newly created dedicated parallel recycling thread or (parallel) daemon thread.
[0110] Optionally, the second recycling thread can be determined based on existing working threads, that is, the default recycling thread of the parallel recycling process is not newly created; instead, a second recycling thread for executing the current garbage collection task is determined from at least one working thread of the application.
[0111] In specific implementation, the thread states of at least one working thread can be obtained, and the second recycling thread is determined from the at least one working thread based on the thread states;
[0112] The thread state of the working thread can be fed back based on the status information of the working thread, and the thread state of the corresponding working thread can be updated in real time based on the register status information of the working thread.
[0113] The status information of the working thread can be a fitting of one or more types of status type parameters such as register status parameters, task execution parameters, thread processing delay parameters, amount of tasks to be executed parameters, amount of tasks to be executed parameters, task executable time parameters, etc. of the working thread.
[0114] Optionally, the electronic device can periodically obtain the status information of at least one working thread in a polling manner, and perform parameter evaluation on the thread state based on the status information of the working thread to obtain an evaluation value that feedbacks the thread state.
[0115] Further, parameter evaluation can be to set parameter evaluation rules. The parameter evaluation rules can be: set weights for each status type parameter, and obtain the evaluation value by means of weighted summation, and this evaluation value feedbacks the state of the working thread.
[0116] Further, parameter evaluation can be to set parameter evaluation rules. The parameter evaluation rules can be: set at least one parameter range for the status type parameter, and each parameter range corresponds to a type of thread state. In actual application, after obtaining the status type parameter of the working thread, it is only necessary to determine the parameter range into which the status type parameter falls to determine the thread state corresponding to this parameter range.
[0117] The thread state can be defined based on the actual situation. For example, it can be divided into idle state, busy state, normal state, etc.
[0118] It can be understood that the electronic device can select the second recycling thread belonging to the target state from at least one working thread, and the target state can be user-defined, such as the idle state.
[0119] In specific implementation, after determining the second recycling thread from at least one working thread, a parallel garbage collection task is added to the second recycling thread through the second recycling interface. The second recycling thread is a working thread other than the target application thread and the first recycling thread.
[0120] Furthermore, when the second recycling thread executes the parallel garbage collection task at this time, the second recycling thread can adopt the explicit recycling process for garbage collection. That is to say, after adding the parallel garbage collection task to the second recycling thread, "the second recycling thread adopts the explicit recycling process for garbage collection" and "the original target application thread releases the garbage collection task and executes the target thread task after the garbage collection task", and these two are executed in parallel, thus realizing the parallel execution of the garbage collection task and the target thread task, improving the efficiency of garbage collection, avoiding blocking the execution of the target thread task due to the failure of the garbage collection task, and improving the application performance during the garbage collection process.
[0121] S204: Execute the garbage collection task and the target thread task in parallel based on the parallel recycling process.
[0122] For specific details, please refer to other method steps in the method embodiments of this application, which will not be elaborated here.
[0123] In one or more embodiments of this application, the target application thread of the application originally calls the Explicit GC interface to trigger an explicit garbage collection process to start a GC recycle. Usually, this will block the working application thread (i.e., the working application thread of the application, such as the target application thread) with a very high probability, thus causing problems such as stuttering, freezing, and screen freezing during garbage collection. By executing the embodiments of this application, converting the explicit recycling process corresponding to the garbage collection task of the explicit recycling type into a parallel execution of the garbage collection task can effectively solve such problems. And by setting the garbage collection task to be completed based on the target thread, the garbage collection effect before and after optimization can be ensured. For the target application thread of the application, it is no longer necessary to wait for the completion of the garbage collection task to execute the next target thread task, avoiding problems during garbage collection, improving the disaster tolerance of garbage collection, and at the same time realizing the parallel garbage collection task with "the target application thread executing the next task" based on the target thread, also ensuring the progress of the garbage collection task and avoiding waiting for the garbage collection task, and also ensuring the application performance of the application and meeting the recycling effect of the garbage collection task.
[0124] Please refer to Figure 6 , Figure 6 which is a schematic flowchart of another embodiment of a garbage collection method proposed by this application. Specifically:
[0125] S301: Determine that the target application thread triggers a garbage collection task, and obtain the garbage collection type corresponding to the garbage collection task;
[0126] For specific details, please refer to the method steps in other embodiments involved in this application, which will not be elaborated here.
[0127] S302: If the garbage collection type is an explicit collection type, obtain the current status parameters;
[0128] The status parameters may be the virtual machine status related to garbage collection in the feedback system and / or the application running status corresponding to the feedback application thread;
[0129] The virtual machine status may be a fitting of one or more of the current heap memory size, the number of garbage objects, the memory size occupied by garbage objects, the number of object allocations after the last garbage collection, the allocated memory size after the last garbage collection, the number of Explicit GC requests (explicit garbage collection requests), the time of the last garbage collection, etc. that reflect the virtual machine status. It can be understood that garbage collection usually performs garbage collection operations on relevant objects in the heap area corresponding to the virtual machine. In this application, before the garbage collection task is executed, the status parameters reflecting the "status of the virtual machine" can be obtained first to measure the degree of garbage objects in the heap and determine whether to execute the garbage collection task of the display collection type.
[0130] The application running status is used to indicate the load status of the application: a fitting of one or more of the current application throughput, the memory occupied by the current application, the application task volume, etc.
[0131] It can be understood that the electronic device can create a status monitoring thread during the application running process, and collect and save the current status parameters in real time or periodically based on the status monitoring thread. For example, collect the parameters of the virtual machine status related to garbage collection in the current feedback system, or collect the parameters of the application running status corresponding to the feedback application thread. In this way, after the target application thread triggers the garbage collection task of the explicit collection type, the saved current status parameters can be quickly obtained.
[0132] S303: If the status parameters match the reference status parameters, perform the step of parallelly processing the garbage collection task.
[0133] S304: If the status parameters do not match the reference status parameters, perform task ignoring processing on the garbage collection task.
[0134] The reference status parameters can be understood as being set for the status parameters, such as a parameter range set for the status parameters, or a parameter threshold set for the status parameters, etc. Setting the reference status parameters is used to judge whether to execute the garbage collection task of the display collection type, so as to ensure that the display collection type of garbage collection task is not triggered or less triggered when the current status is busy, and to ensure the thread transaction requirements of the application.
[0135] In a feasible implementation, reference state parameters can be set for at least one type of state parameter according to actual requirements. It can be understood that if multiple types of state parameters are included for reference, reference state parameters are set for each type of state parameter respectively. For example, a set occupancy rate parameter threshold based on the memory occupancy rate of the system virtual machine, a set number threshold based on "the number of object allocations after the last garbage collection", and a set throughput range based on the throughput of the application.
[0136] The matching of the state parameter and the reference state parameter can be understood as follows: for the parameter threshold set for the state parameter, if the state parameter meets the parameter threshold, it is considered that the state parameter matches the reference state parameter; otherwise, it does not match.
[0137] The matching of the state parameter and the reference state parameter can be understood as follows: for the parameter range set for the state parameter, if the state parameter falls within the parameter range, it is considered that the state parameter matches the reference state parameter; otherwise, it does not match.
[0138] It can be understood that if multiple types of state parameters are included for reference, when all types of state parameters match the reference state parameters, it is determined that the state parameter matches the reference state parameter; otherwise, if there is one type of state parameter that does not match the reference state parameter, it is determined that the state parameter does not match the reference state parameter.
[0139] In this application, in combination with the state parameter, it is determined whether to perform the step of parallel recycling processing on the garbage collection task. If the state parameter does not match the reference state parameter, the garbage collection task is ignored, that is, the garbage collection task is not executed, so as to reduce unnecessary Explicit GC garbage collection; it can ensure that the processing volume impact caused by garbage collection is reduced when performing explicit garbage collection, and the garbage collection timing can be controlled to avoid garbage blocking situations that affect the application performance; it can realize regular explicit garbage collection based on the current state and improve the system disaster tolerance ability during the garbage collection process.
[0140] S305: Adjust the task parameters of the garbage collection task based on the state parameter, and perform parallel recycling processing on the garbage collection task based on the task parameters;
[0141] The task parameters may be a fitting of one or more of the task type parameters such as the number of garbage collection objects, the execution time point of garbage collection, the execution recovery intensity of garbage collection, the frequency of garbage collection, etc. In practical applications, when the target application thread triggers a garbage collection task, the garbage collection task corresponds to default task parameters, and the default task parameters are used to instruct the electronic device to perform explicit garbage collection processing through the target application thread. In this application, while adjusting the garbage collection task to parallel recovery processing, the current state parameters are incorporated for reference, and the task parameters of the garbage collection task are dynamically adjusted according to the current state, so as to realize regular garbage collection of the display recovery type based on the current state and improve the system disaster tolerance ability during the garbage collection process.
[0142] It can be understood that a parameter mapping relationship between various types of state parameters and reference task parameters can be established in advance. The parameter mapping relationship can be represented in the form of a parameter table, a parameter set, a parameter array, etc. The reference task parameters can be the reference number of garbage collection objects, the reference execution time point of garbage collection, the reference execution recovery intensity of garbage collection, the reference frequency of garbage collection, and so on. Then, based on the foregoing parameter mapping relationship, the garbage collection task can be processed in parallel by combining the current task parameters.
[0143] S306: Set the garbage collection object type of the garbage collection task based on the state parameters, and perform parallel recovery processing on the garbage collection task based on the garbage collection object type.
[0144] The garbage collection object type is usually divided based on the reference relationship of the object. The garbage collection object type can be a strong reference object type, a soft reference object type, a weak reference object type, a phantom reference object type, an isolated object type, etc.
[0145] It can be understood that an object type mapping relationship between various types of state parameters and reference garbage collection object types can be established in advance. The object type mapping relationship can be represented in the form of an object type table, an object type set, an object type array, etc. Based on the foregoing object type mapping relationship, the garbage collection object type of the garbage collection task can be set by combining the current task parameters, so as to perform parallel recovery processing on the garbage collection task based on the garbage collection object type.
[0146] For example, based on the current state parameters, it is determined in the object type mapping relationship that the garbage collection object type should be set to the phantom reference object type and the isolated object type. Then the electronic device traverses the types of all objects in the virtual machine heap and performs garbage collection on the objects belonging to the phantom reference object type and the isolated object type, and reclaims the occupied content of these objects.
[0147] In one or more embodiments of the present application, an electronic device triggers a garbage collection task by determining a target application thread, obtains the garbage collection type corresponding to the garbage collection task, and if the garbage collection type is an explicit collection type, the electronic device performs parallel collection processing on the garbage collection task, avoiding garbage collection according to the original explicit collection process corresponding to the explicit collection type, optimizing the garbage collection process, smoothly ensuring the task operation of the target application thread while performing garbage collection, ensuring the application performance during the garbage collection process, and being able to regularly perform garbage collection of the explicit collection type in combination with the current state parameters, improving the system disaster tolerance ability during the garbage collection process; and by adjusting the task parameters of the original garbage collection task and setting the garbage collection object type, it is possible to not only perform garbage collection on isolated objects, but also realize intelligent garbage collection of corresponding type objects based on the current state, improving the degree of intelligence during the garbage collection process.
[0148] The following will be combined with Figure 7 to introduce the garbage collection device provided by the embodiments of the present application in detail. It should be noted that Figure 7 the garbage collection device shown is used to execute the method of the embodiments of the present application Figures 1 to 6 shown. For the sake of convenience of description, only the parts related to the embodiments of the present application are shown. For the specific technical details not disclosed, please refer to the embodiments Figures 1 to 6 shown in the present application.
[0149] Please refer to Figure 7 , which shows the structural schematic diagram of the garbage collection device of the embodiments of the present application. The garbage collection device 1 can be implemented as all or part of a user terminal through software, hardware, or a combination of both. According to some embodiments, the garbage collection device 1 includes a task determination module 11 and a collection processing module 12, and is specifically used for:
[0150] The task determination module 11 is used to determine that a target application thread triggers a garbage collection task and obtain the garbage collection type corresponding to the garbage collection task;
[0151] The collection processing module 12 is used to perform parallel collection processing on the garbage collection task if the garbage collection type is an explicit collection type.
[0152] Optionally, the collection processing module 12 is specifically used for:
[0153] Updating the garbage collection process corresponding to the garbage collection task to a parallel collection process, and based on the parallel collection process, parallelly execute the garbage collection task and the target thread task;
[0154] where the target thread task is the thread task after the garbage collection task.
[0155] Optionally, as Figure 8 shown, the recycling processing module 12 includes:
[0156] An interface update unit 121, configured to obtain the garbage collection process corresponding to the garbage collection task, and perform interface update processing on the garbage collection interface corresponding to the garbage collection process;
[0157] A process association unit 122, configured to associate the garbage collection task with a parallel collection process through the garbage collection interface after interface update processing.
[0158] Optionally, the interface update unit 121 is specifically configured to:
[0159] Obtain a first collection interface corresponding to the garbage collection task, where the first collection interface is the garbage collection interface in the explicit collection process corresponding to the explicit collection type;
[0160] Update the first collection interface to a second collection interface, where the second collection interface is associated with a parallel collection process.
[0161] Optionally, the interface update unit 121 is specifically configured to:
[0162] Add a parallel garbage collection task to an auxiliary thread through the second collection interface;
[0163] Wherein, the parallel garbage collection task is used to instruct the auxiliary thread to execute the garbage collection task in parallel.
[0164] Optionally, the recycling processing module 12 is specifically configured to:
[0165] Add a parallel garbage collection task to a first collection thread through the second collection interface, where the first collection thread is the default collection thread corresponding to the parallel collection process;
[0166] Determine a second collection thread, and add a parallel garbage collection task to the second collection thread through the second collection interface, where the second collection thread is a thread other than the target application thread and the first collection thread.
[0167] Optionally, the recycling processing module 12 is specifically configured to:
[0168] Create a second collection thread, and set the second collection thread as the default collection thread of the parallel collection process; or,
[0169] Obtain the thread states of at least one working thread, and determine a second collection thread from the at least one working thread based on the thread states.
[0170] Optionally, the recycling processing module 12 is specifically configured to:
[0171] Obtain the current status parameter;
[0172] If the status parameter matches the reference status parameter, perform the step of parallelly recycling the garbage collection task.
[0173] Optionally, the recycling processing module 12 is specifically configured to:
[0174] If the status parameter does not match the reference status parameter, perform task ignoring processing on the garbage collection task.
[0175] Optionally, the recycling processing module 12 is specifically configured to:
[0176] Obtain the current status parameter, adjust the task parameter of the garbage collection task based on the status parameter, and perform parallel recycling processing on the garbage collection task based on the task parameter; and / or,
[0177] Obtain the current status parameter, set the garbage collection object type of the garbage collection task based on the status parameter, and perform parallel recycling processing on the garbage collection task based on the garbage collection object type.
[0178] It should be noted that when the garbage collection device provided in the above embodiments executes the garbage collection method, only the above-mentioned division of each functional module is used for illustration. In actual applications, the above functions can be allocated to different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the garbage collection device provided in the above embodiments and the embodiments of the garbage collection method belong to the same concept, and the implementation process thereof can be seen in the method embodiments, which will not be elaborated here.
[0179] The serial numbers of the above embodiments of the present application are only for description and do not represent the advantages and disadvantages of the embodiments.
[0180] The embodiments of the present application also provide a computer storage medium, which can store multiple instructions, and the instructions are suitable for being loaded and executed by a processor to perform the garbage collection method as described in the above Figures 1 to 6 shown embodiments. The specific execution process can be seen in Figures 1 to 6 the specific description of the shown embodiments, which will not be elaborated here.
[0181] The present application also provides a computer program product, which stores at least one instruction, and the at least one instruction is loaded and executed by the processor to perform the garbage collection method as described in the above Figures 1 to 6 shown embodiments. The specific execution process can be seen in Figures 1 to 6 the specific description of the shown embodiments, which will not be elaborated here.
[0182] Please refer to Figure 9 , which shows a block diagram of the structure of an electronic device provided by an exemplary embodiment of the present application. The electronic device in the present application may include one or more of the following components: a processor 110, a memory 120, an input device 130, an output device 140, and a bus 150. The processor 110, the memory 120, the input device 130, and the output device 140 may be connected through the bus 150.
[0183] The processor 110 may include one or more processing cores. The processor 110 utilizes various interfaces and lines to connect various parts within the entire electronic device, and by running or executing instructions, programs, code sets, or instruction sets stored in the memory 120, as well as calling data stored in the memory 120, it executes various functions of the electronic device 100 and processes data. Optionally, the processor 110 may be implemented in at least one of the hardware forms of digital signal processing (DSP), field-programmable gate array (FPGA), and programmable logic array (PLA). The processor 110 may integrate one or several combinations of a central processing unit (CPU), a graphics processing unit (GPU), and a modem, etc. Among them, the CPU mainly processes the operating system, user interface, application programs, etc.; the GPU is responsible for rendering and drawing display content; the modem is used to process wireless communication. It can be understood that the above modem may not be integrated into the processor 110 and may be implemented separately through a communication chip.
[0184] The memory 120 may include a random access memory (RAM), and may also include a read-only memory (ROM). Optionally, the memory 120 includes a non-transitory computer-readable storage medium. The memory 120 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 120 may include a program storage area and a data storage area. Among them, the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the following various method embodiments, etc. The operating system may be an Android system, including a system developed based on the Android system in depth, an IOS system developed by Apple Inc., including a system developed based on the IOS system in depth, or other systems. The data storage area may also store data created during the use of the electronic device, such as a phone book, audio and video data, chat record data, etc.
[0185] See Figure 10 As shown, the memory 120 can be divided into an operating system space and a user space. The operating system runs in the operating system space, and native and third-party application programs run in the user space. In order to ensure that different third-party application programs can achieve better running effects, the operating system allocates corresponding system resources for different third-party application programs. However, there are also differences in the system resource requirements of different application scenarios in the same third-party application program. For example, in the local resource loading scenario, the third-party application program has higher requirements for the disk read speed; in the animation rendering scenario, the third-party application program has higher requirements for the GPU performance. The operating system and the third-party application program are independent of each other, and the operating system often cannot timely perceive the current application scenario of the third-party application program, resulting in the operating system being unable to perform targeted system resource adaptation according to the specific application scenario of the third-party application program.
[0186] In order to enable the operating system to distinguish the specific application scenarios of third-party application programs, it is necessary to open up the data communication between the third-party application programs and the operating system, so that the operating system can obtain the current scenario information of the third-party application programs at any time, and then perform targeted system resource adaptation based on the current scenario.
[0187] Taking the Android system as an example of the operating system, the programs and data stored in the memory 120 are as Figure 11As shown, the memory 120 may store a Linux kernel layer 320, a system runtime library layer 340, an application framework layer 360, and an application layer 380. The Linux kernel layer 320, the system runtime library layer 340, and the application framework layer 360 belong to the operating system space, and the application layer 380 belongs to the user space. The Linux kernel layer 320 provides underlying drivers for various hardware components of electronic devices, such as display drivers, audio drivers, camera drivers, Bluetooth drivers, Wi-Fi drivers, power management, etc. The system runtime library layer 340 provides major feature support for the Android system through some C / C++ libraries. For example, the SQLite library provides database support, the OpenGL / ES library provides 3D drawing support, and the Webkit library provides browser kernel support. The system runtime library layer 340 also provides the Android runtime library (Android runtime), which mainly provides some core libraries that allow developers to write Android applications using the Java language. The application framework layer 360 provides various APIs that may be used when building applications. Developers can also use these APIs to build their own applications, such as activity management, window management, view management, notification management, content provider management, package management, call management, resource management, and location management. The application layer 380 runs at least one application. These applications can be native applications that come with the operating system, such as contacts, SMS, clock, and camera applications, or third-party applications developed by third-party developers, such as games, instant messaging programs, and photo enhancement programs.
[0188] Taking the operating system as the IOS system as an example, the programs and data stored in the memory 120 are as follows: Figure 12As shown in the figure, the iOS system includes: the Core OS layer 420, the Core Services layer 440, the Media layer 460, and the Cocoa Touch Layer 480. The Core OS layer 420 includes the operating system kernel, drivers, and underlying program frameworks, which provide functions closer to the hardware for the program frameworks located in the Core Services layer 440 to use. The Core Services layer 440 provides the system services and / or program frameworks required by applications, such as the Foundation framework, the Account framework, the Advertising framework, the Data Storage framework, the Network Connection framework, the Location framework, the Motion framework, and so on. The Media layer 460 provides interfaces related to audio-visual aspects for applications, such as interfaces related to graphics and images, interfaces related to audio technology, interfaces related to video technology, and the AirPlay interface for audio-video transmission technology. The Cocoa Touch Layer 480 provides various commonly used interface-related frameworks for application development and is responsible for the touch interaction operations of users on electronic devices. For example, the Local Notification service, the Remote Push service, the Advertising framework, the Game Tools framework, the Message User Interface (UI) framework, the UIKit framework for the user interface, the Map framework, and so on.
[0189] In Figure 12 Among the frameworks shown, the frameworks related to most applications include but are not limited to: the Foundation framework in the Core Services layer 440 and the UIKit framework in the Cocoa Touch Layer 480. The Foundation framework provides many basic object classes and data types, provides the most basic system services for all applications, and is independent of the UI. The classes provided by the UIKit framework are the basic UI class libraries, used to create touch-based user interfaces. iOS applications can provide the UI based on the UIKit framework, so it provides the infrastructure for applications to build user interfaces, draw, process, and handle user interaction events, respond to gestures, and so on.
[0190] Among them, the method and principle of implementing data communication between third-party applications and the operating system in the iOS system can refer to the Android system, and this application will not elaborate on it here.
[0191] Among them, the input device 130 is used to receive input instructions or data. The input device 130 includes, but is not limited to, a keyboard, a mouse, a camera, a microphone, or a touch device. The output device 140 is used to output instructions or data. The output device 140 includes, but is not limited to, a display device, a speaker, and the like. In one example, the input device 130 and the output device 140 can be combined. The input device 130 and the output device 140 are a touch display screen, which is used to receive touch operations of a user using any suitable object such as a finger or a stylus on or near it, and to display the user interfaces of various application programs. The touch display screen is usually arranged on the front panel of the electronic device. The touch display screen can be designed as a full-screen, a curved screen, or a special-shaped screen. The touch display screen can also be designed as a combination of a full-screen and a curved screen, or a combination of a special-shaped screen and a curved screen. The embodiments of the present application do not limit this.
[0192] In addition, those skilled in the art can understand that the structure of the electronic device shown in the above drawings does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than those shown in the drawings, or combine some components, or have different component arrangements. For example, the electronic device also includes components such as a radio frequency circuit, an input unit, a sensor, an audio circuit, a wireless fidelity (WiFi) module, a power supply, and a Bluetooth module, which will not be elaborated here.
[0193] In the embodiments of the present application, the execution subject of each step can be the electronic device introduced above. Optionally, the execution subject of each step is the operating system of the electronic device. The operating system can be an Android system, an IOS system, or other operating systems. The embodiments of the present application do not limit this.
[0194] The electronic device according to the embodiment of the present application may also be equipped with a display device. The display device may be various devices capable of implementing a display function, such as: cathode ray tube display (abbreviated as CR), light-emitting diode display (abbreviated as LED), electronic ink screen, liquid crystal display (abbreviated as LCD), plasma display panel (abbreviated as PDP), etc. The user may use the display device on the electronic device 101 to view information such as displayed text, images, videos, etc. The electronic device may be a smart phone, a tablet computer, a gaming device, an AR (Augmented Reality) device, an automobile, a data storage device, an audio playback device, a video playback device, a notebook, a desktop computing device, a wearable device such as an electronic watch, electronic glasses, an electronic helmet, an electronic bracelet, an electronic necklace, electronic clothing, etc.
[0195] In Figure 9 In the electronic device shown, where the electronic device may be a terminal, the processor 110 may be used to call the garbage collection application program stored in the memory 120 and specifically perform the following operations:
[0196] Determine that the target application thread triggers a garbage collection task, and obtain the garbage collection type corresponding to the garbage collection task;
[0197] If the garbage collection type is an explicit collection type, perform parallel collection processing on the garbage collection task.
[0198] In one embodiment, when the processor 1001 executes the parallel collection processing on the garbage collection task, it specifically performs the following steps:
[0199] Update the garbage collection process corresponding to the garbage collection task to a parallel collection process, and based on the parallel collection process, execute the garbage collection task and the target thread task in parallel;
[0200] Wherein, the target thread task is the thread task after the garbage collection task.
[0201] In one embodiment, when the processor 1001 executes the update of the garbage collection process corresponding to the garbage collection task to a parallel collection process, it specifically performs the following steps:
[0202] Obtain the garbage collection process corresponding to the garbage collection task, and perform interface update processing on the garbage collection interface corresponding to the garbage collection process;
[0203] The garbage collection interface after interface update associates the garbage collection task with the parallel collection process through the interface.
[0204] In one embodiment, when the processor 1001 performs interface update processing on the garbage collection interface corresponding to the garbage collection process, the following steps are specifically executed:
[0205] Obtain a first collection interface corresponding to the garbage collection task, where the first collection interface is the garbage collection interface in the explicit collection process corresponding to the explicit collection type;
[0206] Update the first collection interface to a second collection interface, where the second collection interface is associated with the parallel collection process.
[0207] In one embodiment, when the processor 1001 associates the garbage collection task with the parallel collection process through the garbage collection interface after interface update processing, the following steps are specifically executed:
[0208] Add a parallel garbage collection task to the auxiliary thread through the second collection interface;
[0209] Wherein, the parallel garbage collection task is used to instruct the auxiliary thread to execute the garbage collection task in parallel.
[0210] In one embodiment, when the processor 1001 adds a parallel garbage collection task to the auxiliary thread by calling a third collection interface through the second collection interface, the following steps are specifically executed:
[0211] Add a parallel garbage collection task to the first collection thread through the second collection interface, where the first collection thread is the default collection thread corresponding to the parallel collection process; or,
[0212] Determine a second collection thread, and add a parallel garbage collection task to the second collection thread through the second collection interface, where the second collection thread is a thread other than the target application thread and the first collection thread.
[0213] In one embodiment, when the processor 1001 determines the second collection thread, the following steps are specifically executed:
[0214] Create a second collection thread and set the second collection thread as the default collection thread of the parallel collection process; or,
[0215] Obtain the thread states of at least one working thread, and determine the second collection thread from the at least one working thread based on the thread states.
[0216] In one embodiment, when the processor 1001 executes the parallel recycling process for the garbage collection task, the following steps are specifically executed:
[0217] Obtain the current status parameters;
[0218] If the status parameters match the reference status parameters, execute the steps of the parallel recycling process for the garbage collection task.
[0219] In one embodiment, when the processor 1001 executes the garbage collection method, the following steps are also executed:
[0220] If the status parameters do not match the reference status parameters, perform task ignoring processing on the garbage collection task.
[0221] In one embodiment, when the processor 1001 executes the parallel recycling process for the garbage collection task, the following steps are specifically executed:
[0222] Obtain the current status parameters, adjust the task parameters of the garbage collection task based on the status parameters, and perform parallel recycling processing on the garbage collection task based on the task parameters; and / or,
[0223] Obtain the current status parameters, set the garbage collection object type of the garbage collection task based on the status parameters, and perform parallel recycling processing on the garbage collection task based on the garbage collection object type. Those of ordinary skill in the art can understand that all or part of the processes of implementing the methods in the above embodiments can be completed by instructing related hardware through a computer program. The program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above methods. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only memory, or a random access memory, etc.
[0224] The above-disclosed are only the preferred embodiments of the present application. Of course, the scope of the rights of the present application cannot be limited thereby. Therefore, equivalent changes made according to the claims of the present application still fall within the scope covered by the present application.
Claims
1. A garbage collection method, characterized in that, The method includes: Determine that a target application thread triggers a garbage collection task, and obtain the garbage collection type corresponding to the garbage collection task; If the garbage collection type is an explicit collection type, perform parallel collection processing on the garbage collection task; The performing parallel collection processing on the garbage collection task includes: Obtain the garbage collection process corresponding to the garbage collection task, obtain the first collection interface corresponding to the garbage collection task, where the first collection interface is the garbage collection interface in the explicit collection process corresponding to the explicit collection type, and update the first collection interface to a second collection interface, where the second collection interface is associated with a parallel collection process; Associate the garbage collection task with the parallel collection process through the second collection interface after interface update processing; Based on the parallel collection process, execute the garbage collection task and the target thread task in parallel; Wherein, the target thread task is the thread task after the garbage collection task.
2. The method according to claim 1, characterized in that, The associating the garbage collection task with the parallel collection process through the garbage collection interface after interface update processing includes: Add a parallel garbage collection task to an auxiliary thread through the second collection interface; Wherein, the parallel garbage collection task is used to instruct the auxiliary thread to execute the garbage collection task in parallel.
3. The method according to claim 2, wherein The adding a parallel garbage collection task to an auxiliary thread by calling a third collection interface through the second collection interface includes: Add a parallel garbage collection task to a first collection thread through the second collection interface, where the first collection thread is the default collection thread corresponding to the parallel collection process; or, Determine a second collection thread, and add a parallel garbage collection task to the second collection thread through the second collection interface, where the second collection thread is a thread other than the target application thread and the first collection thread.
4. The method according to claim 3, wherein The determining the second collection thread includes: Create a second collection thread, and set the second collection thread as the default collection thread of the parallel collection process; or, Obtain the thread states of at least one working thread, and determine a second collection thread from the at least one working thread based on the thread states.
5. The method according to claim 1, wherein The performing parallel collection processing on the garbage collection task includes: Obtain the current state parameter; If the state parameter matches the reference state parameter, execute the steps of performing parallel collection processing on the garbage collection task.
6. The method according to claim 5, characterized in that, The method further includes: If the state parameter does not match the reference state parameter, perform task ignoring processing on the garbage collection task.
7. The method according to claim 1, wherein The performing parallel collection processing on the garbage collection task includes: Obtain the current state parameter, adjust the task parameter of the garbage collection task based on the state parameter, and perform parallel collection processing on the garbage collection task based on the task parameter; and / or, Obtain the current state parameter, set the garbage collection object type of the garbage collection task based on the state parameter, and perform parallel collection processing on the garbage collection task based on the garbage collection object type.
8. A garbage collection device, characterized in that, The device includes: A task determination module, configured to determine that a target application thread triggers a garbage collection task, and obtain the garbage collection type corresponding to the garbage collection task; A recycling processing module, which is used to perform parallel recycling processing on the garbage recycling task if the garbage recycling type is an explicit recycling type; The parallel recycling processing of the garbage recycling task includes: Obtaining the garbage recycling process corresponding to the garbage recycling task, obtaining a first recycling interface corresponding to the garbage recycling task, where the first recycling interface is a garbage recycling interface in the explicit recycling process corresponding to the explicit recycling type, updating the first recycling interface to a second recycling interface, the second recycling interface is associated with the parallel recycling process, associating the garbage recycling task with the parallel recycling process through the second recycling interface after interface update processing, and executing the garbage recycling task and the target thread task in parallel based on the parallel recycling process; Wherein, the target thread task is a thread task after the garbage recycling task.
9. A computer storage medium, characterized in that, The computer storage medium stores multiple instructions, and the instructions are suitable for being loaded and executed by a processor to perform the method steps of any one of claims 1 to 7.
10. An electronic device, characterized in that, Including: A processor and a memory; wherein, the memory stores a computer program, and the computer program is suitable for being loaded and executed by the processor to perform the method steps of any one of claims 1 to 7.
Citation Information
Patent Citations
Method for processing Java instance garbage collection of search system
CN110795248A