Resource garbage recycling method and device, electronic equipment, terminal and storage medium
The method of determining the target recycling strategy and recycling referenced data by monitoring the triggering method solves the resource garbage collection problem of application operating systems that support post-download procedural programming languages, and achieves better resource garbage collection adaptation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-29
- Publication Date
- 2026-03-10
AI Technical Summary
Existing resource reclamation methods are not applicable to operating systems that support applications written in post-download procedural programming languages, making it impossible to solve the resource garbage collection problem.
The target recycling strategy is determined by monitoring the triggering method. The target recycling strategy is used to identify the referenced data to be recycled and to reclaim the resources occupied by it. Different recycling strategies are set according to different triggering methods.
It achieves effective resource garbage collection for resource electronic devices that support application operating systems written in post-download procedural programming languages, with better adaptability and solves the problem of resource garbage collection.
Smart Images

Figure CN121636128A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of information technology, and in particular to a resource garbage collection method and device, an electronic device, a terminal and a storage medium. BACKGROUND
[0002] With the development of technology, electronic terminals are increasingly widely used, and people can install and delete various application programs on electronic terminals to meet different functional needs. During the installation and deletion of application programs, the resources of electronic terminals are constantly allocated and recycled.
[0003] Currently, resource electronic devices usually use an operating system that supports application programs written in a post-download object-oriented programming language, and the corresponding resource recycling method is usually related to its data structure. For resource electronic devices that support application programs written in a post-download procedural programming language, since their data structure is different from that of the prior art, the existing resource recycling method cannot be applied to resource electronic devices that support application programs written in a post-download procedural programming language. SUMMARY
[0004] The present application provides a resource garbage collection method and device, an electronic device, a terminal and a storage medium to solve the problem of resource garbage collection for resource electronic devices that support an operating system for application programs written in a post-download procedural programming language.
[0005] According to an aspect of the present application, a resource garbage collection method is provided, the method comprising:
[0006] In the case where any triggering mode of resource garbage collection is monitored, a target recycling strategy is determined according to the triggering mode;
[0007] The target recycling strategy is used to determine the reference data to be recycled, and the resources occupied by the reference data to be recycled are recycled.
[0008] According to another aspect of the present application, a resource garbage collection device is provided, the device comprising:
[0009] A determination module is configured to determine a target recycling strategy according to any triggering mode of resource garbage collection in the case where the triggering mode is monitored;
[0010] A recycling module is configured to determine reference data to be recycled using the target recycling strategy, and recycle the resources occupied by the reference data to be recycled.
[0011] According to another aspect of the present application, an electronic device is provided,
[0012] The electronic device is provided with an embedded operating system, and a runtime environment is executed in the embedded operating system.
[0013] at least one processor; and
[0014] a memory in communication connection with the at least one processor; wherein
[0015] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to execute the resource garbage collection method of any of the embodiments of the present application.
[0016] According to another aspect of the present application, a terminal is provided, comprising the electronic device of any of the embodiments of the present application.
[0017] According to another aspect of the present application, a computer readable storage medium is provided, which stores computer instructions for enabling a processor to implement the resource garbage collection method of any of the embodiments of the present application when executed by the processor.
[0018] According to another aspect of the present application, a computer program product is provided, characterized in that the computer program product comprises a computer program which, when executed by a processor, implements the resource garbage collection method of any of the embodiments of the present application.
[0019] The technical solution of the embodiments of the present application, in the case of monitoring any triggering mode of resource garbage collection, determines the target recovery strategy according to the triggering mode; determines the to-be-recovered reference data using the target recovery strategy, and recovers the resources occupied by the to-be-recovered reference data, and by setting the corresponding recovery strategy for different triggering modes, the resource electronic device supporting the operating system of the application written in the post-downloaded process-oriented programming language can better adapt to resource garbage collection, and the problem that the resource electronic device supporting the operating system of the application written in the post-downloaded process-oriented programming language cannot perform resource garbage collection is solved.
[0020] It should be understood that the content described in this part is not intended to identify the key or important features of the embodiments of the present application, nor is it used to limit the scope of the present application. Other features of the present application will become apparent from the following description. BRIEF DESCRIPTION OF DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0022] Figure 1 A flow chart of a resource garbage collection method is provided for Embodiment One of the present application;
[0023] Figure 2 A flow chart of a resource garbage collection method is provided for Embodiment Two of the present application;
[0024] Figure 3 A flow chart of a resource garbage collection method is provided for Embodiment Three of the present application;
[0025] Figure 4 A flow chart of a resource garbage collection method is provided for Embodiment Four of the present application;
[0026] Figure 5 A structural schematic diagram of a resource garbage collection device is provided for Embodiment Five of the present application;
[0027] Figure 6 A structural schematic diagram of an electronic device that can be used to implement embodiments of the present application is shown. DETAILED DESCRIPTION
[0028] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the 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 skilled in the art without creative work should fall within the scope of protection of the present application.
[0029] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily have to be used to describe a specific order or sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "include" and "have" 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 does not have to be limited to only those steps or units clearly listed, but can include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0030] Embodiment One
[0031] Figure 1A flowchart of a resource garbage recycling method is provided for the embodiment one of the present application. The embodiment can be applicable to the case where resource garbage needs to be recycled. The method can be executed by a resource garbage recycling device, which can be realized in the form of hardware and / or software and can be configured in an electronic device. As shown in Figure 1 The method comprises the following steps.
[0032] In step 101, when any triggering mode of resource garbage recycling is monitored, the target recycling strategy is determined according to the triggering mode.
[0033] In this step, the resource garbage can be the resource occupied by the garbage data. The garbage data can be the redundant data remaining in the system after the application is deleted. The resource occupied by such data is usually various types of memory.
[0034] In addition, the triggering mode can be any mode that can prompt the resource garbage recycling, such as an instruction, a bit value of certain identification bit, etc.
[0035] Different triggering modes correspond to different recycling strategies. The embodiment can use the instruction mechanism of monitoring. As long as a certain triggering mode is monitored, the recycling process corresponding to the recycling strategy corresponding to the triggering mode is executed.
[0036] In step 102, the target recycling strategy is used to determine the to-be-recycled reference data, and the resource occupied by the to-be-recycled reference data is recycled.
[0037] In this step, the to-be-recycled reference data is the garbage data mentioned above. The embodiment is the recycling of the resource occupied by the garbage data.
[0038] In the embodiment, when any triggering mode of resource garbage recycling is monitored, the target recycling strategy is determined according to the triggering mode. The target recycling strategy is used to determine the to-be-recycled reference data, and the resource occupied by the to-be-recycled reference data is recycled. By setting the corresponding recycling strategy for different triggering modes, the resource electronic device of the operating system supporting the application written in the process-oriented programming language after downloading can better adapt to the resource garbage recycling, and the problem that the resource electronic device carrying the operating system constructed in the binary format cannot perform resource garbage recycling is solved.
[0039] Embodiment two
[0040] Figure 2 A flowchart of a resource garbage recycling method is provided for the embodiment two of the present application. The embodiment is a lower embodiment of the above-mentioned embodiment. The embodiment can be used for recycling the resource garbage in the case where the application is deleted. As shown in Figure 2As shown, the method includes:
[0041] Step 201: Periodically check the value of the waste recycling start flag. If the value of the flag changes to the first preset value, it is determined that resource waste recycling has been triggered in the first triggering mode.
[0042] In this step, the garbage collection start flag is a parameter in the system, and the value of the garbage collection start flag is the parameter value. When deleting any target application, the value of the garbage collection start flag is set to the first preset value.
[0043] Specifically, after the target application is deleted, the garbage collection start flag can be set to the first preset value.
[0044] In this step, the value of the waste recycling start flag can be periodically detected. As long as the value changes to the first preset value, it can be determined that the resource waste recycling has been triggered in the first triggering mode.
[0045] Specifically, when detecting a change in bit value, the current bit value can be compared with the expected first preset bit value. If the current bit value is the first preset value, it can be determined that the bit value has changed to the first preset value.
[0046] In order to shorten the total detection time of this bit value, that is, the total time of periodic detection of this bit value, this embodiment can start the periodic detection of this bit value only when an application deletion event is detected.
[0047] In a specific example, the first preset value can be "1", but it can also be other values such as 0xA5.
[0048] Step 202: If the triggering method is the first triggering method, determine the traversal recycling strategy corresponding to the first triggering method as the target recycling strategy.
[0049] In this step, the recycling strategy corresponding to the first triggering method can be a traversal recycling strategy, which mainly achieves resource recycling through traversal. The specific process can be referred to in the following steps.
[0050] Step 203: Use the target reclamation strategy to determine the reference data to be reclaimed, and reclaim the resources occupied by the reference data to be reclaimed.
[0051] Before traversing the reference values in this step, this embodiment can initialize the starting address of the heap space and the total size of the space to be freed. It should be noted that this initialization operation is to set both the starting address of the heap space and the total size of the space to be freed to 0. Furthermore, the number of reference data to be deleted can also be initialized, for example, by setting the number of reference data to be deleted to 0.
[0052] The starting address of the heap space and the total size of the space to be freed are predefined parameters, mainly used to record some key information required for garbage collection. Subsequent steps will involve assigning values to and using these two parameters, which will not be elaborated here. Furthermore, the number of referenced data items to be deleted can also be set to a predefined parameter.
[0053] After the initialization operation is completed, you can first traverse the reference values in the reference data storage area; for each reference value encountered, determine whether the reference data corresponding to the reference value is reference data to be reclaimed; if so, reclaim the resources occupied by the reference data to be reclaimed.
[0054] It should be noted that when traversing based on the reference values in the reference data storage area, you can start traversing from the smallest reference value in the storage area allocated for the reference data, and then increment the reference values to traverse all the reference data.
[0055] The increment in the increment process is related to the definition of the reference value in the system. In a specific example, the increment can be 1, and the reference value can be incremented by 1.
[0056] When any reference value is encountered, the corresponding entry in the reference table can be indexed based on the reference value, and the starting address of the reference data in the heap space can be located based on the entry value. Then, based on the starting address, the attribute information of the reference data is read. If the attribute information stores the identifier of the target application, the reference data is determined to be reference data to be reclaimed; otherwise, the next reference value is traversed.
[0057] It should be noted that the data structure of the reference table can be referenced from relevant technologies, and will not be elaborated here. In this embodiment, based on the indexing characteristic between the reference value and the reference table entry, the reference value can be used to index the corresponding entry in the reference table, and the entry value can then locate the starting address of the corresponding reference data in the heap space.
[0058] Since this starting address is the starting address where the corresponding reference data is stored in the heap space, once the starting address is obtained, the corresponding reference data stored in the heap space can be accessed based on this starting address.
[0059] When determining whether the referenced data is referenced data to be reclaimed, it is usually only necessary to use the attribute information of the application data, that is, the referenced data management information or header information. Therefore, in this embodiment, the attribute information can be read directly.
[0060] This attribute information usually contains the identifier of the application to which it belongs. Therefore, this embodiment can determine whether the attribute information contains the identifier of the target application. If it does, the reference data can be identified as reference data to be recycled; if it does not, the next reference value will be traversed.
[0061] To improve the efficiency of resource reclamation, when reclaiming resources occupied by referenced data, it is advisable to accumulate a whole block of memory before reclamation.
[0062] Specifically, it can be determined whether the heap space address of the currently traversed reference data to be reclaimed is continuous with the heap space address of the reference data to be reclaimed in the previous traversal. If the heap space address of the currently traversed reference data to be reclaimed is continuous with the heap space address of the reference data to be reclaimed in the previous traversal, the total size of the released space is added to the address size of the reference data to be reclaimed in the heap space, so that the released space is merged and the resources are not immediately reclaimed.
[0063] Furthermore, the number of references to be deleted can be incremented by 1 to merge the space to be released.
[0064] If the heap space address of the currently traversed reference data to be reclaimed is not contiguous with the heap space address of the previously traversed reference data to be reclaimed, then the resources are reclaimed immediately. That is, the corresponding heap space is reclaimed according to the starting address of the heap space and the total size of the space to be released, and an initialization operation is performed. Furthermore, the corresponding heap space can also be reclaimed and initialized according to the number of reference data to be deleted.
[0065] After resource reclamation, the starting address of the heap space for the currently traversed reference data to be reclaimed is written to the initial starting address of the heap space. The total size of the space to be released is then added to the address size of the currently traversed reference data to be reclaimed in the heap space. Furthermore, the number of reference data to be deleted can be incremented by 1.
[0066] It should be noted that the recycling process here utilizes the two initialization parameters mentioned above. For ease of explanation, this embodiment will begin with the first reference data to be recycled encountered.
[0067] When the first piece of reference data to be reclaimed is encountered, its starting address is used as a parameter value and assigned to the aforementioned heap space starting address parameter. The size of this piece of reference data is then added to the aforementioned total size of the space to be released parameter. Furthermore, the number of reference data items to be deleted could also be incremented by 1.
[0068] When iterating to the second piece of reference data to be reclaimed, first check if its address is contiguous with the first piece of reference data in the heap space. If they are contiguous, then add the address of the second piece of reference data to the total size of the space to be released. Furthermore, the number of reference data items to be deleted can also be incremented by 1. The aforementioned heap space start address parameter is not assigned a value here.
[0069] This process continues until the Nth reference data to be reclaimed is reached. The address of the Nth reference data to be reclaimed in the heap space is not contiguous with the address of the (N-1)th reference data to be reclaimed. At this point, the corresponding heap space can be merged and released according to the aforementioned two parameters.
[0070] Of course, it is understandable that the second reference data to be reclaimed may not be contiguous with the first reference data to be reclaimed in the heap space. In this case, the corresponding heap space can be released directly based on the first reference data to be reclaimed.
[0071] Specifically, the heap space start address indicates the starting position of the heap space that needs to be reclaimed, and the total size of the space to be released indicates the size of the heap space that needs to be reclaimed. Therefore, the heap space size can be released starting from this starting position to complete the resource reclamation of this part of the heap space.
[0072] Since the addresses of the Nth reference data to be reclaimed are not contiguous with those of the (N-1)th reference data to be reclaimed, after the aforementioned release is completed, the initialization operation can be continued again. Then, the starting address of the Nth reference data to be reclaimed is used as a parameter value and assigned to the aforementioned heap space starting address parameter. The size of the Nth reference data to be reclaimed is added to the aforementioned total size of the space to be released parameter. Then, the traversal continues. Furthermore, before continuing the traversal, the parameter of the number of reference data to be deleted can be incremented by 1.
[0073] Furthermore, once a piece of referenced data to be reclaimed is identified, the table entries in the reference table can be cleared based on the reference value of the data to be reclaimed. Specifically, the table entries corresponding to the reference value can be directly cleared. To ensure that the reference table can be used normally, in this embodiment, if the reference table is a first-level table, the number of valid table entries recorded in the reference table is decremented by 1; if the reference table is a second-level table, the number of valid table entries in the first-level reference table recorded in the 0th-level reference table of the reference table is decremented by 1; if the reference table is a second-level table and the number of valid table entries in the 1st-level sub-table recorded in the 0th-level table of the second-level table is 0, the space of the 1st-level sub-table of the reference table is released.
[0074] It should be noted that the relationship between the first-level table, the second-level table, and the zero-level table can be found in relevant technical documents, and will not be elaborated here.
[0075] After all reference data has been traversed, that is, after all reference values have been traversed, the value of the garbage collection start flag can be set to the second preset value to indicate that garbage collection is complete. This second preset value can be, but is not limited to, "0".
[0076] During the above process, the garbage data remaining after the application is deleted, i.e. the heap space resources occupied by the reference data to be reclaimed, can be reclaimed.
[0077] Example 3
[0078] Figure 3 This is a flowchart of a resource garbage collection method provided in Embodiment 3 of this application. This embodiment is a further inclusion of Embodiment 2 above. This embodiment can be used for the collection of temporary static transient resource (ASR) space and temporary dynamic transient resource (ADR) space in the scenario of deleting an application. Figure 3 As shown, the method includes:
[0079] Step 301: After identifying the referenced data as the referenced data to be reclaimed, if the referenced data to be reclaimed is ASR data, set the ASR space compaction flag to the third preset value; if the referenced data to be reclaimed is ADR data, set the ADR space compaction flag to the fourth preset value according to the application to which the referenced data to be reclaimed belongs.
[0080] In this step, ASR data is temporary static variable data, typically used to store data related to a specific session or transaction to ensure security and data isolation. ADR data is temporary dynamic variable data, typically used to store temporary or sensitive data within the application, such as temporary counters and caches.
[0081] Among them, the ASR space compaction flag and the ADR space compaction flag are preset parameters. By setting the corresponding values, it can be determined whether ASR space compaction and ADR space compaction need to be performed later.
[0082] It should be noted that the third preset value can be, but is not limited to, "1". Since the ADR space is related to whether the application is selected, the fourth preset value needs to be set in conjunction with the application to which the reference data to be recycled belongs. For example, it can be set to two parts: the first part is used to reflect the bit state of the identifier, and the second part is the identifier of the application. The first part can be, but is not limited to, taking the value of "1".
[0083] Step 302: After traversing all reference values, determine whether the ASR space compaction flag is the third preset value and whether the ADR space compaction flag is the fourth preset value.
[0084] In this step, determining whether the ADR space compaction indicator is the fourth preset value is mainly to determine whether the first part of the ADR space compaction indicator is the fourth preset value.
[0085] Step 303: If the ASR space compaction flag is the third preset value or the ADR space compaction flag is the fourth preset value, compact the ASR space and ADR space in the memory space.
[0086] In this step, the current ADR space allocation information and ASR space allocation information are first initialized. Then, the reference data can be traversed. For each reference data traversed, it is determined whether the reference data is ASR data or ADR data.
[0087] If the referenced data is ASR data, reallocate ASR space for the ASR data. Specifically, first obtain the size of the current ASR data, and then request ASR space based on the size of the ASR data to obtain the first address space; obtain the first address space after the ASR data is reallocated and the second address space of the original array elements; determine whether the first address space and the second address space are consistent; if they are inconsistent, migrate the array elements of the second address space to the first address space, and update the ASR space in the attribute information of the ASR data to the first address space; if they are consistent, do not perform migration and update operations.
[0088] Since the application deletion process only deletes a portion of the ASR data, only a part of the overall ASR space may be free. This free space may exist in the middle, at the beginning, or at the end of the ASR space.
[0089] Therefore, for the ASR data that has been traversed, the first address space that was newly allocated can be compared with the second address space of the original array elements of the ASR data. If they match, it means that the space released by the deleted ASR data has not affected the ASR data that has been traversed this time, and no migration or update operation is required. If they do not match, it means that the space released by the deleted ASR data has affected the ASR data that has been traversed this time, and migration and update operations are required. That is, the array elements of the second address space are migrated to the first address space, and the ASR space in the attribute information of the ASR data is updated to the first address space.
[0090] If the referenced data is ADR data, obtain the identifier of the application to which the ADR data belongs, and reallocate ADR space for the ADR data based on the identifier of the application to which the ADR data belongs. Specifically, the size of the current ADR data can be obtained, and ADR space can be requested based on the size of the ADR data to obtain the third address space; the third address space of the array elements after the ADR data is reallocated and the fourth address space of the original array elements can be obtained; it is determined whether the third address space and the fourth address space are consistent; if they are inconsistent, the ADR space in the attribute information of the ADR data is updated to the third address space information, and other applications in the same creation module as the application to which the ADR data belongs are determined based on the attribute information of the application to which the ADR data belongs, and whether they are selected on the logical channel; if they are selected, the array elements in the fourth address space are migrated to the third address space; if they are not selected, no migration operation is performed; if they are consistent, no migration operation and update operation are performed.
[0091] Since only the selected application occupies the ADR space, and applications in the same module are usually in the same ADR space, the compaction of the ADR space can be further adjusted based on the inconsistency between the third and fourth address spaces. This adjustment can also include whether other applications in the same module are selected. If selected, a migration operation is performed; otherwise, no migration is required.
[0092] In addition, in this embodiment, the compaction operations of the ASR space and ADR space in the memory space are completed in one transaction. Before performing the traversal in this embodiment, the ADR data and all ASR data of the selected application on the logical channel can be backed up; and in the event of an abnormality in the compaction operation, the backed-up ADR data and all ASR data can be used to roll back to the state before compaction.
[0093] Example 4
[0094] Figure 4This is a flowchart illustrating a resource waste recycling method provided in Embodiment 4 of this application. This embodiment is a subordinate embodiment of Embodiment 1 above, and it can be used for resource waste recycling in scenarios where application-related reference data is deleted. Figure 4 As shown, the method includes:
[0095] Step 401: If the application is detected calling the space release API interface, it is determined that resource garbage collection has been triggered in the second triggering method.
[0096] In this step, when deleting some of the application's referenced data, it is necessary to call the space release API interface. When calling, parameter information will be passed, which includes the reference value of the referenced data to be deleted.
[0097] Step 402: If the triggering method is the second triggering method, determine the partial recycling strategy corresponding to the second triggering method as the target recycling strategy.
[0098] In this step, the second triggering method corresponds to a partial recycling strategy. Unlike the aforementioned traversal recycling strategy, this step does not traverse but instead performs targeted direct deletion.
[0099] Step 403: Use the target reclamation strategy to determine the reference data to be reclaimed, and reclaim the resources occupied by the reference data to be reclaimed.
[0100] In this step, the call information when calling the space release API interface is obtained, and the target reference value is extracted from the call information; the reference data corresponding to the target reference value is determined as the reference data to be reclaimed, and the resources occupied by the reference data to be reclaimed are reclaimed.
[0101] The resource reclamation of the heap space it occupies can be referred to in the aforementioned embodiments, and will not be repeated here. For clearing table entries, this embodiment can also clear the reference table entries corresponding to the target reference value; if the reference table is a second-level table, the number of valid table entries in the first-level reference table recorded in the 0th-level reference table of the reference table is decremented by 1; if the reference table is a second-level table and the number of valid table entries in the first-level sub-table recorded in the 0th-level table of the second-level table is 0, the space of the first-level sub-table corresponding to the reference table is released.
[0102] Example 5
[0103] Figure 5 This is a schematic diagram of a resource waste recycling device provided in Embodiment 5 of this application. Figure 3 As shown, the device includes:
[0104] The determination module 501 is used to determine the target recycling strategy based on the triggering method when any triggering method for resource garbage recycling is detected.
[0105] The recycling module 502 is used to determine the reference data to be recycled using the target recycling strategy and to reclaim the resources occupied by the reference data to be recycled.
[0106] In this embodiment, when any triggering method for resource garbage collection is detected, a target collection strategy is determined based on the triggering method; the target collection strategy is used to determine the reference data to be collected, and the resources occupied by the reference data to be collected are collected. By setting corresponding collection strategies for different triggering methods, resource electronic devices that support operating systems written in post-download procedural programming languages can be better adapted to resource garbage collection, thus solving the problem that resource electronic devices that support operating systems written in post-download procedural programming languages cannot perform resource garbage collection.
[0107] Example 6
[0108] Figure 6 A schematic diagram of an electronic device that can be used to implement embodiments of this application is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (such as helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the application described and / or claimed herein.
[0109] In this embodiment, the electronic device may also include a restricted device, which is a resource-restricted device, referring to a device with very limited hardware resources, such as memory resources. Furthermore, the restricted device may be a smart card, a security element (SE), or an embedded device.
[0110] like Figure 6 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 may also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0111] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0112] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as resource garbage collection methods.
[0113] In some embodiments, the resource garbage collection method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the resource garbage collection method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to perform the resource garbage collection method by any other suitable means (e.g., by means of firmware).
[0114] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0115] Computer programs used to implement the methods of this application may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0116] In the context of this application, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium can be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0117] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0118] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0119] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0120] Example 7
[0121] Embodiment 7 of this application provides a terminal, which includes the electronic device provided in Embodiment 6.
[0122] Example 8
[0123] This application provides a computer-readable storage medium storing computer instructions that are used to cause a processor to execute the resource garbage collection method of any embodiment of this application.
[0124] Example 9
[0125] This application provides a computer program product, which includes a computer program that, when executed by a processor, implements the resource garbage collection method provided in any embodiment of this application.
[0126] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this application can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this application can be achieved, and this is not limited herein.
[0127] The specific embodiments described above do not constitute a limitation on the scope of protection of this application. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A resource garbage collection method characterized by, The method comprises: In the case that any trigger mode of resource garbage collection is monitored, a target recovery strategy is determined according to the trigger mode; The target recovery strategy is used to determine the reference data to be recovered, and the resources occupied by the reference data to be recovered are recovered.
2. The method of claim 1, wherein, The method further comprises: Periodically detecting the bit value of the garbage collection start identification bit, and if the value of the bit is detected to be changed to a first preset value, it is determined that the resource garbage collection is triggered in the first trigger mode.
3. The method of claim 2, wherein, The target recovery strategy is determined according to the trigger mode, comprising: If the trigger mode is the first trigger mode, the traversal recovery strategy corresponding to the first trigger mode is determined as the target recovery strategy.
4. The method of claim 3, wherein, The target recovery strategy is used to determine the reference data to be recovered, and the resources occupied by the reference data to be recovered are recovered, comprising: Traversing based on the reference value of the reference data storage area; Every time a reference value is traversed, it is judged whether the reference data corresponding to the reference value is the reference data to be recovered; If yes, the resources occupied by the reference data to be recovered are recovered.
5. The method of claim 4, wherein, The method further comprises: When any target application is deleted, the bit value of the garbage collection start identification bit is set to a first preset value. The target recovery strategy is determined according to the trigger mode, comprising: The table entry of the corresponding reference table is indexed according to the reference value, and the starting address of the reference data in the heap space is located according to the table entry value of the table entry; The attribute information of the reference data is read based on the starting address; If the attribute information stores the identification of the target application, the reference data is determined as the reference data to be recovered; Otherwise, the next reference value is traversed.
6. The method of claim 4, wherein, Before the traversal based on the reference value of the reference data storage area, the method further comprises: The starting address of the heap space and the total size of the space to be released are initialized; The resources occupied by the reference data to be recovered are recovered, comprising: If the heap space address of the reference data to be recovered currently traversed is not continuous with the heap space address of the reference data to be recovered last traversed, the resources are immediately recovered, that is, the resources of the corresponding heap space are recovered according to the starting address of the heap space and the total size of the space to be released, and the initialization operation is performed; After the resources are recovered, the starting address of the heap space address of the reference data to be recovered currently traversed is written into the initialized starting address of the heap space, and the total size of the space to be released is added to the address size of the reference data to be recovered in the heap space.
7. The method of claim 6, wherein, The resources occupied by the reference data to be recovered are recovered, further comprising: If the heap space address of the reference data to be recovered currently traversed is continuous with the heap space address of the reference data to be recovered last traversed, the total size of the space to be released is added to the address size of the reference data to be recovered in the heap space to merge the released space, and the resources are not immediately recovered; Based on the reference value of the reference data to be recovered, the table entry data in the reference table is cleared.
8. The method of claim 6, wherein, The resource recycling of the corresponding heap space according to the heap space start address and the total size of the space to be released comprises: Directly releasing the corresponding space according to the heap space start address and the total size of the space to be released.
9. The method of claim 8, wherein, The clearing of the table item data in the reference table based on the reference value of the reference data to be recycled comprises: Clearing the reference table item corresponding to the reference value; If the reference table is a first-level table, decreasing the number of valid table items recorded in the reference table by 1; If the reference table is a second-level table, decreasing the number of valid table items recorded in the first-level reference table of the reference table by 1; If the reference table is a second-level table and the number of valid table items recorded in the first-level table of the second-level table is 0, releasing the sub-table space of the reference table.
10. The method of claim 4, wherein, The recycling of the resource occupied by the reference data to be recycled comprises: After the traversal of all reference values is completed, setting the bit value of the garbage collection start identification bit to a second preset value, indicating that the garbage collection is completed.
11. The method of claim 5, wherein, After the reference data is determined as the reference data to be recycled, the method further comprises: If the reference data to be recycled is ASR data, setting an ASR space compaction identification to a third preset value; If the reference data to be recycled is ADR data, setting an ADR space compaction identification to a fourth preset value according to the application to which the reference data to be recycled belongs.
12. The method of claim 11, wherein, The recycling of the resource occupied by the reference data to be recycled further comprises: After the traversal of all reference values is completed, judging whether the ASR space compaction identification is the third preset value and whether the ADR space compaction identification is the fourth preset value; If the ASR space compaction identification is the third preset value or the ADR space compaction identification is the fourth preset value, compacting the ASR space and the ADR space in the memory space.
13. The method of claim 12, wherein, The compacting of the ASR space and the ADR space in the memory space comprises: Initializing the current ADR space allocation information and the ASR space allocation information; Traversing the reference data, and judging whether the reference data is ASR data or ADR data after each traversal of the reference data; If the reference data is ASR data, reallocating ASR space for the ASR data; If the reference data is ADR data, obtaining the identification of the application to which the ADR data belongs, and reallocating ADR space for the ADR data based on the identification of the application; If neither the ASR data nor the ADR data, traversing the next reference data until all reference data are traversed; After the traversal is completed, setting the ASR space compaction identification and the ADR space compaction identification to a fifth preset value.
14. The method of claim 13, wherein, The reallocating of ASR space for the ASR data comprises: Obtaining the size of the current ASR data, and applying for ASR space based on the size of the ASR data to obtain a first address space; Obtaining the first address space after the ASR data is reallocated and the second address space of the original array element; Judging whether the first address space and the second address space are consistent; If not consistent, array elements of the second address space are migrated into the first address space, and the ASR space in the attribute information of the ASR data is updated to the first address space; If consistent, no migration operation and update operation are performed.
15. The method of claim 13, wherein, The ADR space of the ADR data is reassigned based on the identifier of the application to which the ADR data belongs, including: The size of the current ADR data is obtained, and ADR space is applied based on the size of the ADR data, to obtain a third address space; The third address space of the array elements after the ADR data is reassigned and the fourth address space of the original array elements are obtained; It is judged whether the third address space and the fourth address space are consistent; If not consistent, the ADR space in the attribute information of the ADR data is updated to the third address space information, and it is determined whether other applications in the same creation module as the application to which the ADR data belongs are selected on a logical channel based on the identifier of the application; If selected, array elements of the fourth address space are migrated into the third address space, and if not selected, no migration operation is performed; If consistent, no migration operation and update operation are performed.
16. The method of claim 12, wherein, The operations of compacting the ASR space and the ADR space in the memory space are completed in one transaction, and the method further includes: The ADR data and all ASR data of the selected application on the logical channel are backed up; In the case of an exception in the compacting operation, the state before the compacting is rolled back according to the backed-up ADR data and all ASR data.
17. The method according to any one of claims 1 to 16, characterized in that, The method further includes: If it is monitored that the release space API interface is called by an application, it is determined that the resource garbage collection is triggered in the second triggering mode.
18. The method of claim 17, wherein, The target recovery strategy is determined according to the triggering mode, including: If the triggering mode is the second triggering mode, the part of the recovery strategy corresponding to the second triggering mode is determined as the target recovery strategy.
19. The method of claim 18, wherein, The reference data to be recovered is determined by using the target recovery strategy, and the resources occupied by the reference data to be recovered are recovered, including: The calling information when the release space API interface is called is obtained, and a target reference value is extracted from the calling information; The reference data corresponding to the target reference value is determined as the reference data to be recovered, and the resources occupied by the reference data to be recovered are recovered.
20. The method of claim 19, wherein, The resources occupied by the reference data to be recovered are recovered, including: The reference table entry corresponding to the target reference value is cleared; If the reference table is a two-level table, the number of valid table entries in the first-level reference table recorded in the 0th-level reference table of the reference table is decremented by 1; If the reference table is a two-level table and the number of valid table entries of the first-level sub-table recorded in the 0th-level table of the two-level table is 0, the space of the first-level sub-table corresponding to the reference table is released.
21. A resource garbage collection apparatus characterized by comprising: The device includes: A determination module configured to determine a target recovery strategy according to a triggering mode of resource garbage collection in the case that any triggering mode of resource garbage collection is monitored; A recovery module configured to determine reference data to be recovered by using the target recovery strategy, and recover the resources occupied by the reference data to be recovered.
22. An electronic device, comprising: The electronic device is installed with an embedded operating system, and a runtime environment is executed in the embedded operating system, and the electronic device comprises: at least one processor; and a memory connected in communication with the at least one processor; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to execute the resource garbage collection method according to any one of claims 1-20.
23. The electronic device of claim 21, wherein, The electronic device comprises a resource-constrained device.
24. The electronic device of claim 23, wherein, The resource-constrained device comprises a smart card, a secure element SE, or an embedded device.
25. A computer readable storage medium, characterized in that, The computer readable storage medium stores computer instructions for enabling the processor to implement the resource garbage collection method according to any one of claims 1-20 when executed.
26. A computer program product, characterised in that, The computer program product comprises a computer program, and the computer program implements the resource garbage collection method according to any one of claims 1-20 when executed by the processor.