CN110764874B - Dalvik garbage recycling and inhibiting method and device, terminal and storage medium - Google Patents

Dalvik garbage recycling and inhibiting method and device, terminal and storage medium Download PDF

Info

Publication number
CN110764874B
CN110764874B CN201911009656.9A CN201911009656A CN110764874B CN 110764874 B CN110764874 B CN 110764874B CN 201911009656 A CN201911009656 A CN 201911009656A CN 110764874 B CN110764874 B CN 110764874B
Authority
CN
China
Prior art keywords
garbage collection
memory
garbage
thread
suppression
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201911009656.9A
Other languages
Chinese (zh)
Other versions
CN110764874A (en
Inventor
艾永标
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing ByteDance Network Technology Co Ltd
Original Assignee
Beijing ByteDance Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing ByteDance Network Technology Co Ltd filed Critical Beijing ByteDance Network Technology Co Ltd
Priority to CN201911009656.9A priority Critical patent/CN110764874B/en
Publication of CN110764874A publication Critical patent/CN110764874A/en
Application granted granted Critical
Publication of CN110764874B publication Critical patent/CN110764874B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • G06F12/0253Garbage collection, i.e. reclamation of unreferenced memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45583Memory management, e.g. access or allocation

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Memory System (AREA)

Abstract

The present disclosure provides methods and apparatus, terminals, and storage media for Dalvik garbage reclamation suppression. The Dalvik garbage recycling and inhibiting method comprises the following steps: acquiring an initialization condition of a garbage recycling inhibition process; acquiring an object, and judging whether the object is in a garbage recycling process; triggering a garbage collection suppression process when the initialization condition is met and the object is in a garbage collection process; and detecting the memory state, and closing the garbage collection suppression process if the memory overflows. The Dalvik garbage recycling inhibiting method can save time consumed by garbage recycling, does not affect the speed of memory allocation, accelerates the starting speed of the application, and improves the use efficiency and use experience of users.

Description

Dalvik garbage recycling and inhibiting method and device, terminal and storage medium
Technical Field
The disclosure relates to the technical field of computers, and in particular, to a Dalvik garbage recycling suppression method and device, a terminal, and a storage medium.
Background
The default use of the Android 4.x system is that a Dalvik virtual machine is used for Java heap memory management, and the main function of the system is to provide memory allocation and memory recovery functions for Android applications. A drawback of this technique is that the garbage collection operation is too heavy and can seriously affect some speed-intensive user experience.
Disclosure of Invention
In order to solve the existing problems, the present disclosure provides a method and an apparatus for Dalvik garbage recycling suppression, a terminal, and a storage medium.
The present disclosure adopts the following technical solutions.
In some embodiments, the present disclosure provides a method of Dalvik waste reclamation suppression, comprising:
acquiring an initialization condition of a garbage recycling inhibition process;
acquiring an object, and judging whether the object is in a garbage recycling process;
triggering a garbage collection suppression process when the initialization condition is met and the object is in a garbage collection process;
and detecting the memory state, and closing the garbage collection suppression process if the memory overflows.
In some embodiments, the present disclosure provides a device for Dalvik waste recycling suppression, comprising:
the acquisition module is used for acquiring the initialization condition and the acquisition object of the garbage recycling inhibition process;
the judging module is used for judging whether the initialization condition is met and whether the object is in a garbage recycling process;
the detection module is used for detecting the memory state; and
and the operation module is used for triggering and closing the garbage recycling inhibition progress.
In some embodiments, the present disclosure provides a terminal comprising: at least one memory and at least one processor;
the memory is used for storing program codes, and the processor is used for calling the program codes stored in the memory to execute the method.
In some embodiments, the present disclosure provides a storage medium for storing program code for performing the above-described method.
The Dalvik garbage recycling inhibiting method and device, the terminal and the storage medium provided by the disclosure can save time consumed by garbage recycling, do not affect the speed of memory allocation, accelerate the starting speed of applications, and improve the use efficiency and use experience of users.
Drawings
The above and other features, advantages and aspects of various embodiments of the present disclosure will become more apparent by referring to the following detailed description when taken in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numbers refer to the same or similar elements. It should be understood that the drawings are schematic and that elements and elements are not necessarily drawn to scale.
Fig. 1 is a flowchart of a Dalvik garbage collection suppression method according to an embodiment of the present disclosure.
Fig. 2 is a schematic diagram of a memory without turning on a garbage suppression function according to an embodiment of the present disclosure.
Fig. 3 is a schematic memory diagram of turning on a garbage collection suppression function according to an embodiment of the present disclosure.
Fig. 4 is a schematic structural diagram of a Dalvik waste recycling suppression apparatus according to an embodiment of the present disclosure.
Fig. 5 is a schematic structural view of a Dalvik waste recycling and restraining apparatus according to another embodiment of the present disclosure.
Fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present disclosure.
Detailed Description
Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While certain embodiments of the present disclosure are shown in the drawings, it is to be understood that the present disclosure may be embodied in various forms and should not be construed as limited to the embodiments set forth herein, but rather are provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the disclosure are for illustration purposes only and are not intended to limit the scope of the disclosure.
It should be understood that various steps recited in method embodiments of the present disclosure may be performed in parallel and/or in parallel. Moreover, method embodiments may include additional steps and/or omit performing the illustrated steps. The scope of the present disclosure is not limited in this respect.
The term "include" and variations thereof as used herein are open-ended, i.e., "including but not limited to". The term "based on" is "based, at least in part, on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Relevant definitions for other terms will be given in the following description.
It should be noted that the terms "first", "second", and the like in the present disclosure are only used for distinguishing different devices, modules or units, and are not used for limiting the order or interdependence relationship of the functions performed by the devices, modules or units.
It is noted that references to "a" or "an" in this disclosure are intended to be illustrative rather than limiting, and that those skilled in the art will recognize that reference to "one or more" unless the context clearly dictates otherwise.
The names of messages or information exchanged between devices in the embodiments of the present disclosure are for illustrative purposes only, and are not intended to limit the scope of the messages or information.
The Dalvik virtual machine uses a mark-and-clear method to realize memory reclamation, during which the virtual machine will mark according to the Root object, if the virtual machine is not directly or indirectly referenced by the Root object, the virtual machine will be marked one by one at this stage, and then the unreferenced memory garbage is cleared uniformly at the clearing stage. Unlike the generation-by-generation and concurrency mechanism adopted by the Art virtual machine, Dalvik stops all threads except garbage collection when the garbage collection operation needs to be triggered until the memory garbage is marked and cleaned one by one. The method aims at solving the problem that the garbage recycling operation of the Dalvik virtual machine is too time-consuming, and aims to solve the problem that the garbage recycling speed is too slow. For example, during application startup, a large number of objects will be created and destroyed, during which it is easy to trigger a garbage collection operation, resulting in a slow startup speed of the application. Such problems are particularly evident in the android system version 4.x, and therefore it is necessary to intervene in the execution of the Dalvik virtual machine from the application point of view, so as to trigger as little as possible a heavy garbage collection operation during the start-up, speeding up the start-up of the application.
As shown in fig. 1, fig. 1 is a flowchart of a Dalvik garbage collection suppression method according to an embodiment of the present disclosure. The method provided by the embodiment of the disclosure comprises the following steps.
S100, acquiring an initialization condition of the garbage collection suppression process.
First, an allocable memory maximum limit (font) mechanism of the soft limit (softlimit) and the memory heap space (mspace) in Dalvik is described as follows. softlimit is a mechanism set by Dalvik and represents the maximum memory value which can be allocated from the Active heap by an application; the Active heap is a part of a Java heap, and the Java heap consists of the Active heap and the Zygote heap. msspace is an encapsulation of anonymous shared memory (ashmem) and Dalvik manages the Java heap by allocating memory heap space (msspace _ malloc) and bulk release memory heap space (msspace _ bulk _ free). The size of the mspace, i.e. the fotopprint, Dalvik does not set the fotopprint to the maximum allowed at start-up, but gives a currently allocable memory maximum (startingSize), which is then gradually increased at the time of allocation.
Then, specifically, during the functional environment initialization, all the function addresses and base addresses involved during the function on and off periods need to be initialized, including a Dalvik library file such as libdvm. These addresses are simply unavailable or otherwise the function is not normally used. In particular, the initialization period does not involve modification of the machine code, so no lock protection is required.
S200, acquiring an object and judging whether the object is in a garbage collection process.
Specifically, the following ordering may be made for garbage collection operations from strong to weak:
1. the first recovery process, such as the garbage recovery operation triggered BEFORE the memory is insufficient (GC _ BEFORE _ OOM), is synchronous operation, soft reference cleaning, Active heap cleaning and Zygote heap cleaning. This garbage collection is the last memory clean operation before an application crashes out of memory (OOM), which will crash if not enough space has been made available for the application.
2. A second reclaim thread, e.g., GC _ EXPLICIT, garbage reclaim operation, triggered actively by the upper layer calling the system. GC () method, is partially asynchronous, but cleans up the zygate heap.
3. The third recycling thread, FOR example, the garbage collection operation (GC _ FOR _ ALLOC) triggered after the failure of memory space allocation, is the most frequent garbage collection operation, and is triggered when the mspace allocation fails or the softlimit is reached.
4. The fourth reclamation thread, e.g., asynchronously triggered garbage reclamation operation (GC _ CONCURRENT), is the lightest garbage reclamation operation, partially asynchronous and less intensive to clean.
In the above four classes, except that GC _ current and GC _ EXPLICIT are partially asynchronous, the other operations are completely synchronous, which means that the entire virtual machine will be tentative and the application will not continue to execute until the garbage cleaning operation is completed. This has the disadvantage that the garbage collection operation is too heavy and can seriously affect some speed-intensive user experiences.
And S300, when the initialization condition is met and the object is in a garbage collection process, triggering a garbage collection suppression process.
Specifically, in the practical implementation of garbage collection suppression, the most frequently occurring GC _ FOR _ ALLOC synchronization operation is prevented as much as possible, GC _ beam _ OOM is released to avoid OOM, and at least part of GC _ current and GC _ EXPLICIT operations are released, so that enough space is provided FOR an application program to avoid GC _ beam _ OOM while the influence of the garbage collection operation on the application is reduced.
More specifically, because the garbage suppression is turned on and off, the data and execution flow are changed indirectly or directly, the lock is needed to be performed before the garbage suppression related operation is performed, and other non-garbage collection threads are suspended (suspend) for a short time. In actual implementation, a garbage collection operation of a virtual machine is replaced by Inline replacement (Inline Hook) to be an application-defined operation, so that the purpose of preventing the garbage collection operation is achieved. However, simply shutting down the garbage collection operation cannot speed up the execution speed of other threads of the application, because the Dalvik virtual machine performs many optimizations in the memory allocation process, for example, in the process of initializing the heap, although a maximum threshold is specified for the size of the heap, in actual use, the virtual machine does not enable the application to directly take the maximum heap for allocation, but uses the softlimit mechanism and the footprint mechanism of the mspace to slowly increase the heap of the memory that the application can allocate until the maximum heap is reached. If the garbage collection operation is simply closed, the softlimit mechanism or the footprint mechanism is triggered when the application allocates the object each time, and the currently usable heap size is tried to be enlarged first, and then the memory is allocated. In other words, in an ideal situation, the most lightweight method for allocating memory is to directly pass through allocation once, but now because the softlimit mechanism and the footprint mechanism are not closed, the most complicated allocation path is taken every time memory is allocated. For the problem, the footprint needs to be set to the maximum value when the garbage collection suppression is started, and the lightweight flow can be carried out in each distribution by matching with the closing of the softlimit. When garbage collection suppression is turned on, the two operations of cancelling softlimit and maximizing mspace lifetime allow the application to allocate memory within the maximum threshold of the heap. The function of maximizing the msspace footprint can be realized by, for example, GOT entry replacement (GOT Hook). And after the garbage collection suppression operation, the thread can be unlocked.
In particular, when the initialization condition is satisfied and the object is in the garbage collection process, and the garbage collection suppression process is not triggered after a predetermined time period is exceeded, for example, 2 seconds, a timeout mechanism may be introduced in the upper layer, and the garbage collection suppression process is selected not to be started. For another example, when the trigger garbage collection suppression operation has an error, the garbage collection suppression operation may not be started after the report.
S400, detecting the memory state, and if the memory overflows, closing the garbage collection inhibition process.
Specifically, the memory has an upper limit, so garbage collection suppression cannot be turned on endlessly. Therefore, when there is insufficient memory, Dalvik triggers GC _ BEFORE _ OOM, at which time garbage collection operations can no longer be suppressed, otherwise the problem of OutOfMemoryError occurs. And (3) stopping garbage collection inhibition, calling a method (dvmCllectGarbageInternal) in the garbage collection operation of the original virtual machine of Dalvik, and cleaning the memory by marking collection. Finally, Dalvik returns to normal flow, and the memory is normally allocated. If the GC _ BEFORE _ OOM is not successfully allocated, the program crashes. And closing the garbage recovery suppression operation, still locking the garbage recovery suppression thread, suspending the non-garbage recovery suppression thread, restoring the footprint, recovering softlimit detection, awakening the garbage recovery process according to positioning, and unlocking the object thread, thereby avoiding the problem of the virtual machine caused by concurrence of the application threads. It will be appreciated that when memory is sufficient, the garbage collection suppression operation may be retriggered.
Comparing fig. 2 and fig. 3, fig. 2 is a schematic diagram of a memory without turning on the garbage suppression function according to the embodiment of the present disclosure, and fig. 3 is a schematic diagram of a memory with turning on the garbage collection suppression function according to the embodiment of the present disclosure. As can be seen from fig. 2, the allocated memory stays smoothly for about 30MB, because the garbage collection operation releases the memory while the application allocates the memory. As can be seen from fig. 3, the allocated memory continues to rise first, is not released until 15s or so, and finally stays at 30 MB. This is because the garbage collection operation is suppressed during the GC suppression period, and there is no more frequent trigger to collect memory.
Furthermore, the mspace font method differs in 4.1 and 4.2+ systems, requiring additional adaptation compatibility. The embodiment of the disclosure achieves version compatibility by applying the got hook technology, and is compatible with android 4 series system versions.
In effect, the method provided by the present disclosure can achieve an average 15% speed increase on an android 4.x system, see in particular the following table.
Figure BDA0002243816420000061
Figure BDA0002243816420000071
As can be seen from the above table, the velocity boost effect is between 9.4% and 29.6%, with an average velocity boost of 14.9%.
The following table lists the cold start times.
Serial number Refuse recovery inhibition time (second) without opening Opening refuse recovery inhibition time (second)
1 10.5 8.4
2 10.7 8.2
3 10.5 8.2
4 10.8 8
5 10.8 8
6 10.7 8.2
7 10.8 8.3
8 11.1 8.8
9 10.5 7.9
10 10.6 8
Max/min 11.1/10.5 8.8/7.9
avg 10.7 8.2
From the above table, it can be seen that the average velocity is increased by 23.3%.
The embodiment of the disclosure also provides a device for recovering and inhibiting Dalvik garbage. As shown in fig. 4, the apparatus 10 includes an obtaining module 20, a determining module 30, a detecting module 40 and an operating module 50. The obtaining module 20 may be configured to obtain an initialization condition and an obtaining object of the garbage collection suppression process. The determining module 30 may be configured to determine whether the initialization condition is satisfied and whether the object is in a garbage collection process. The detection module 40 may be used to detect the memory status. Operational module 50 may be used to trigger and shut down the garbage collection suppression process.
As shown in fig. 5, fig. 5 is a schematic structural view of a Dalvik garbage collection inhibiting apparatus according to another embodiment of the present disclosure. Unlike the previous embodiment, the present embodiment may further include a positioning module 60, a locking module 70, an adjustment module 80, and a control module 90. Wherein, the positioning module 60 can be used to position the garbage collection process. The locking module 70 may be used to lock and unlock the object. The adjustment module 80 may be used to adjust the threshold. The control module 90 may be used to control the turning on and off of the memory value detection. It can be understood that the newly added modules may be added simultaneously or separately, and only need to exert their functions, and the embodiment of the present disclosure is not specifically limited.
For the embodiments of the apparatus, since they correspond substantially to the method embodiments, reference may be made to the partial description of the method embodiments for relevant points. The above-described apparatus embodiments are merely illustrative, wherein the modules described as separate modules may or may not be separate. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
The Dalvik garbage collection suppression method and device according to the present disclosure are described above based on the embodiments and application examples. In addition, the present disclosure also provides a terminal and a storage medium, which are described below.
Referring now to fig. 6, a schematic diagram of an electronic device (e.g., a terminal device or server) 800 suitable for use in implementing embodiments of the present disclosure is shown. The terminal device in the embodiments of the present disclosure may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a vehicle terminal (e.g., a car navigation terminal), and the like, and a stationary terminal such as a digital TV, a desktop computer, and the like. The electronic device shown in fig. 6 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 6, the electronic device 800 may include a processing means (e.g., a central processing unit, a graphics processor, etc.) 801 that may perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)802 or a program loaded from a storage means 808 into a Random Access Memory (RAM) 803. In the RAM803, various programs and data necessary for the operation of the electronic apparatus 800 are also stored. The processing apparatus 801, the ROM 802, and the RAM803 are connected to each other by a bus 804. An input/output (I/O) interface 805 is also connected to bus 804.
Generally, the following devices may be connected to the I/O interface 805: input devices 806 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; output devices 807 including, for example, a Liquid Crystal Display (LCD), speakers, vibrators, and the like; storage 808 including, for example, magnetic tape, hard disk, etc.; and a communication device 809. The communication means 809 may allow the electronic device 800 to communicate wirelessly or by wire with other devices to exchange data. While fig. 6 illustrates an electronic device 800 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication means 809, or installed from the storage means 808, or installed from the ROM 802. The computer program, when executed by the processing apparatus 801, performs the above-described functions defined in the methods of the embodiments of the present disclosure.
It should be noted that the computer readable medium in the present disclosure can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
In some embodiments, the clients, servers may communicate using any currently known or future developed network Protocol, such as HTTP (HyperText Transfer Protocol), and may interconnect with any form or medium of digital data communication (e.g., a communications network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), the Internet (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future developed network.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device.
The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to perform the methods of the present disclosure as described above.
Computer program code for carrying out operations for aspects of the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present disclosure may be implemented by software or hardware. Where the name of an element does not in some cases constitute a limitation on the element itself.
The functions described herein above may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), systems on a chip (SOCs), Complex Programmable Logic Devices (CPLDs), and the like.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
According to one or more embodiments of the present disclosure, there is provided a method of Dalvik garbage recycling suppression, including:
acquiring an initialization condition of a garbage recycling inhibition process;
acquiring an object, and judging whether the object is in a garbage recycling process or not;
triggering a garbage collection suppression process when the initialization condition is met and the object is in a garbage collection process;
and detecting the memory state, and closing the garbage collection suppression process if the memory overflows.
According to one or more embodiments of the present disclosure, there is provided a method, where the step of obtaining an initialization condition of a garbage collection suppression process includes:
detecting an allocated memory value;
detecting a threshold value of the package; and
and positioning the garbage recycling process.
According to one or more embodiments of the present disclosure, there is provided a method, wherein the step of triggering a garbage collection suppression process when the initialization condition is satisfied and the object is in a garbage collection process includes:
locking the object, maximizing the threshold, closing the detection of the memory value, stopping the garbage collection process according to the positioning, and unlocking the object.
According to one or more embodiments of the present disclosure, there is provided a method, where the step of detecting a memory status, and if the memory overflows, closing the garbage collection suppression process includes:
locking the object, restoring the threshold value, recovering the detection of the memory value, awakening the garbage collection process according to positioning, and unlocking the object.
According to one or more embodiments of the present disclosure, there is provided a method characterized in that the object includes a first object and a second object; the garbage collection process comprises a first garbage collection thread, a second garbage collection thread, a third garbage collection thread and a fourth garbage collection thread; wherein the content of the first and second substances,
the step of acquiring the object and judging whether the object is in a garbage collection process comprises the following steps:
if the first object and the second object are cleaned and other processes except the garbage collection process are stopped, determining that the object is in the first garbage collection thread;
if the first object is cleaned, the second object is not cleaned, and other processes except the garbage collection process are not all stopped, determining that the object is in the second garbage collection thread;
if all processes except the garbage collection process stop, judging that the object is in the third garbage collection thread; and
if all processes except the garbage collection process are not stopped, determining that the object is in the fourth garbage collection thread;
and the cleaning intensity of the first garbage recycling thread, the second garbage recycling thread, the third garbage recycling thread and the fourth garbage recycling thread is weakened in sequence.
According to one or more embodiments of the present disclosure, there is provided a method, wherein the step of triggering a garbage collection suppression process when the initialization condition is satisfied and the object is in a garbage collection process further includes:
and keeping the running state of the first garbage collection thread, preventing part of the second garbage collection thread and the fourth garbage collection thread, and preventing the third garbage collection thread.
According to one or more embodiments of the present disclosure, there is provided a method, after the steps of obtaining an object and determining whether the object is in a garbage collection process, further including:
and if the object is not in the garbage collection process, suspending the object.
According to one or more embodiments of the present disclosure, there is provided a method, where the step of detecting a memory state, and if the memory overflows, closing the garbage collection suppression process further includes:
and if the object is not in the garbage collection suppression process, suspending the object.
According to one or more embodiments of the present disclosure, there is provided a method, after the step of detecting a memory state and closing the garbage collection suppression process if the memory overflows, the method further includes:
and detecting the state of the memory, and triggering the garbage collection inhibition process again when the memory does not overflow.
According to one or more embodiments of the present disclosure, there is provided a method, characterized in that the method further comprises:
and when the initialization condition is met and the object is in a garbage collection process, the garbage collection suppression process is not triggered after the preset time length is exceeded, and the garbage collection suppression process is not started.
According to one or more embodiments of the present disclosure, there is provided a Dalvik waste recycling suppression apparatus including:
the acquisition module is used for acquiring the initialization condition and the acquisition object of the garbage recycling inhibition process;
the judging module is used for judging whether the initialization condition is met and whether the object is in a garbage recycling process;
the detection module is used for detecting the memory state; and
and the operation module is used for triggering and closing the garbage recycling inhibition process.
According to one or more embodiments of the present disclosure, there is provided an apparatus, characterized in that the apparatus further comprises:
the positioning module is used for positioning the garbage recycling process; and/or
A locking module for locking and unlocking the object; and/or
An adjustment module for adjusting the threshold; and/or
And the control module is used for controlling the on and off of the detection of the memory value.
According to one or more embodiments of the present disclosure, there is provided a terminal including: at least one memory and at least one processor;
wherein the at least one memory is configured to store program code and the at least one processor is configured to invoke the program code stored in the at least one memory to perform any of the methods described above.
According to one or more embodiments of the present disclosure, there is provided a storage medium for storing program code for performing the above-described method.
The foregoing description is only exemplary of the preferred embodiments of the disclosure and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the disclosure herein is not limited to the particular combination of features described above, but also encompasses other embodiments in which any combination of the features described above or their equivalents does not depart from the spirit of the disclosure. For example, the above features and (but not limited to) the features disclosed in this disclosure having similar functions are replaced with each other to form the technical solution.
Further, while operations are depicted in a particular order, this should not be understood as requiring that such operations be performed in the particular order shown or in sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Likewise, while several specific implementation details are included in the above discussion, these should not be construed as limitations on the scope of the disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims.

Claims (11)

1. A method of Dalvik waste recovery suppression comprising:
acquiring an initialization condition of a garbage collection inhibition process, comprising the following steps: detecting an allocated memory value; detecting a threshold value of the package; positioning the garbage recycling process;
acquiring an object, and judging whether the object is in a garbage recycling process;
when the initialization condition is met and the object is in a garbage collection process, triggering a garbage collection suppression process, including: locking the object, maximizing the threshold value, closing the detection of the memory value, stopping the garbage collection process according to the positioning, and unlocking the object;
detecting the memory state, and if the memory overflows, closing the garbage collection inhibition process, including: locking the object, restoring the threshold value, recovering the detection of the memory value, awakening the garbage collection process according to positioning, and unlocking the object.
2. The method of claim 1, wherein the object comprises a first object and a second object; the garbage collection process comprises a first garbage collection thread, a second garbage collection thread, a third garbage collection thread and a fourth garbage collection thread; wherein the content of the first and second substances,
the step of acquiring the object and judging whether the object is in a garbage collection process comprises the following steps:
if the first object and the second object are cleaned and other processes except the garbage collection process are stopped, determining that the object is in the first garbage collection thread;
if the first object is cleaned, the second object is not cleaned, and other processes except the garbage collection process are not all stopped, determining that the object is in the second garbage collection thread;
if all processes except the garbage collection process stop, judging that the object is in the third garbage collection thread; and
if all processes except the garbage collection process are not stopped, judging that the object is in the fourth garbage collection thread;
and the cleaning intensity of the first garbage recycling thread, the second garbage recycling thread, the third garbage recycling thread and the fourth garbage recycling thread is weakened in sequence.
3. The method according to claim 2, wherein the step of triggering a garbage collection suppression process when the initialization condition is satisfied and the object is in a garbage collection process further comprises:
and keeping the running state of the first garbage collection thread, preventing part of the second garbage collection thread and the fourth garbage collection thread, and preventing the third garbage collection thread.
4. The method according to claim 1, wherein after the step of obtaining the object and determining whether the object is in a garbage collection process, further comprising:
and if the object is not in the garbage collection process, suspending the object.
5. The method of claim 4, wherein the step of detecting the memory status and closing the garbage collection suppression process if the memory overflows further comprises:
and if the object is not in the garbage collection suppression process, suspending the object.
6. The method according to claim 1, wherein after the step of detecting the memory status and closing the garbage collection suppression process if the memory overflows, the method further comprises:
and detecting the state of the memory, and triggering the garbage collection inhibition process again when the memory does not overflow.
7. The method of claim 1, further comprising:
and when the initialization condition is met and the object is in a garbage collection process, the garbage collection suppression process is not triggered after the preset time length is exceeded, and the garbage collection suppression process is not started.
8. A Dalvik waste reclamation suppression apparatus comprising:
an obtaining module, configured to obtain an initialization condition of a garbage collection suppression process and an obtaining object, where the obtaining of the initialization condition of the garbage collection suppression process includes: detecting an allocated memory value; detecting a threshold value of the package; positioning the garbage recycling process;
the judging module is used for judging whether the initialization condition is met and whether the object is in a garbage recycling process, and comprises the following steps: locking the object, maximizing the threshold value, closing the detection of the memory value, stopping the garbage collection process according to the positioning, and unlocking the object;
the detection module is used for detecting the memory state; and
an operation module, configured to trigger and close the garbage collection suppression process if the memory overflow occurs, including: locking the object, restoring the threshold value, recovering the detection of the memory value, awakening the garbage collection process according to positioning, and unlocking the object.
9. The apparatus of claim 8, further comprising:
the positioning module is used for positioning the garbage recycling process; and/or
A locking module for locking and unlocking the object; and/or
An adjustment module for adjusting the threshold; and/or
And the control module is used for controlling the on and off of the detection of the memory value.
10. A terminal, comprising:
at least one memory and at least one processor;
wherein the at least one memory is configured to store program code and the at least one processor is configured to invoke the program code stored in the at least one memory to perform the method of any of claims 1 to 7.
11. A storage medium for storing program code for performing the method of any one of claims 1 to 7.
CN201911009656.9A 2019-10-23 2019-10-23 Dalvik garbage recycling and inhibiting method and device, terminal and storage medium Active CN110764874B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911009656.9A CN110764874B (en) 2019-10-23 2019-10-23 Dalvik garbage recycling and inhibiting method and device, terminal and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911009656.9A CN110764874B (en) 2019-10-23 2019-10-23 Dalvik garbage recycling and inhibiting method and device, terminal and storage medium

Publications (2)

Publication Number Publication Date
CN110764874A CN110764874A (en) 2020-02-07
CN110764874B true CN110764874B (en) 2022-06-24

Family

ID=69333150

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911009656.9A Active CN110764874B (en) 2019-10-23 2019-10-23 Dalvik garbage recycling and inhibiting method and device, terminal and storage medium

Country Status (1)

Country Link
CN (1) CN110764874B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115080221B (en) * 2021-03-15 2024-06-18 北京字节跳动网络技术有限公司 Memory resource use control method, device, equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2007011422A2 (en) * 2005-07-15 2007-01-25 Bea Systems, Inc. System and method for deterministic garbage collection in a virtual machine environment
CN104035879A (en) * 2014-06-04 2014-09-10 江南大学 Memory allocation and garbage collection method based on life-period prediction
CN108459898A (en) * 2017-02-20 2018-08-28 阿里巴巴集团控股有限公司 A kind of recovery method as resource and device
CN109117242A (en) * 2017-06-22 2019-01-01 龙芯中科技术有限公司 Virtual machine garbage reclamation tuning method, apparatus, electronic equipment and storage medium

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2007011422A2 (en) * 2005-07-15 2007-01-25 Bea Systems, Inc. System and method for deterministic garbage collection in a virtual machine environment
CN104035879A (en) * 2014-06-04 2014-09-10 江南大学 Memory allocation and garbage collection method based on life-period prediction
CN108459898A (en) * 2017-02-20 2018-08-28 阿里巴巴集团控股有限公司 A kind of recovery method as resource and device
CN109117242A (en) * 2017-06-22 2019-01-01 龙芯中科技术有限公司 Virtual machine garbage reclamation tuning method, apparatus, electronic equipment and storage medium

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
android Dalvik GC;keen_zuxwang;《CSDN,http://blog.csdn.net/keen_zuxwang/article/details/72850066?locationNum=2&fps=1》;20170603;全文 *
Android虚拟机内存性能优化;曹耀斌;《2016年"学术金秋"论文集》;20161122;全文 *

Also Published As

Publication number Publication date
CN110764874A (en) 2020-02-07

Similar Documents

Publication Publication Date Title
US9471378B2 (en) Adaptive resource management of a data processing system
US20210311749A1 (en) Resource management with dynamic resource policies
EP3514689B1 (en) Memory management method and apparatus
US10114740B2 (en) Memory management techniques
US10353704B2 (en) Prevention of classloader memory leaks in multitier enterprise applications
US11360884B2 (en) Reserved memory in memory management system
CN102027453B (en) System and method for optimizing interrupt processing in virtualized environments
US10725914B2 (en) Lightweight mechanisms for selecting infrequently executed methods for eviction from code cache
US10649889B2 (en) Method and apparatus for managing kernel memory of data processing systems
US9898217B2 (en) Two stage memory allocation using a cache
CN110764874B (en) Dalvik garbage recycling and inhibiting method and device, terminal and storage medium
US7380087B2 (en) Reclaiming application isolated storage
WO2019128542A1 (en) Application processing method, electronic device, computer readable storage medium
US7395386B2 (en) Method and apparatus for data versioning and recovery using delta content save and restore management
US20090013017A1 (en) Methods, Systems, and Computer Program Products for Optimizing Virtual Machine Memory Consumption
CN104184817A (en) Download optimizing method and device and terminal
CN111858393B (en) Memory page management method, memory page management device, medium and electronic equipment
CN111488316B (en) File cache recovery method and device
CN111522645A (en) Object processing method and device, electronic equipment and computer-readable storage medium
CN111475299A (en) Memory allocation method and device, storage medium and electronic equipment
WO2023273564A1 (en) Virtual machine memory management method and apparatus, storage medium, and electronic device
CN105912592A (en) Cache management method, device and mobile terminal
CN112860439A (en) Application starting method and device, terminal and storage medium
CN114625433B (en) Application program starting method and system
CN116431338A (en) Memory optimization method, memory manager, electronic device and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant