CN113407309A - Virtual machine memory application method and device, storage medium and electronic equipment - Google Patents

Virtual machine memory application method and device, storage medium and electronic equipment Download PDF

Info

Publication number
CN113407309A
CN113407309A CN202110719745.3A CN202110719745A CN113407309A CN 113407309 A CN113407309 A CN 113407309A CN 202110719745 A CN202110719745 A CN 202110719745A CN 113407309 A CN113407309 A CN 113407309A
Authority
CN
China
Prior art keywords
memory
module
preset
virtual machine
type
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.)
Pending
Application number
CN202110719745.3A
Other languages
Chinese (zh)
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 CN202110719745.3A priority Critical patent/CN113407309A/en
Publication of CN113407309A publication Critical patent/CN113407309A/en
Pending legal-status Critical Current

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
    • 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)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The disclosure relates to a virtual machine memory application method, a virtual machine memory application device, a storage medium and an electronic device, wherein the method comprises the following steps: acquiring a memory allocation request, wherein the memory allocation request is used for requesting memory allocation for an object of a target application; intercepting OOM exception thrown out when memory allocation fails; executing a preset memory statistics optimization strategy, wherein the memory statistics optimization strategy is used for reducing the memory occupation amount in the heap memory counted by a memory statistics module of the virtual machine; and allocating the memory for the object of the target application again according to the memory allocation request. The number of times of actually throwing the OOM exception is reduced by intercepting the thrown OOM exception and executing a memory statistics optimization strategy, and the flash quit of the target application caused by the OOM exception is further avoided.

Description

Virtual machine memory application method and device, storage medium and electronic equipment
Technical Field
The present disclosure relates to the field of virtual machine technologies, and in particular, to a method and an apparatus for applying for a memory of a virtual machine, a storage medium, and an electronic device.
Background
At present, internet applications still need to be compatible with low-version electronic devices, and with the increasingly frequent version iterations and product operation requirements Of various applications, various picture or animation resources can be used in large quantities on line every time a major activity or a holiday comes, and due to the fact that more objects need to be allocated to pictures and the like, the use space Of a virtual machine heap Memory may be insufficient, in this case, related technologies directly call a Java OOM (Out Of Memory) abnormal interface, and the Java OOM abnormality is thrown Out, so that application backslash is caused, and the use Of the electronic devices by users is affected.
Disclosure of Invention
This summary is provided to introduce a selection of concepts in a simplified form that are further described below in the detailed description. This summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.
In a first aspect, the present disclosure provides a method for applying for a memory of a virtual machine, including:
acquiring a memory allocation request, wherein the memory allocation request is used for requesting memory allocation for an object of a target application;
intercepting OOM exception thrown out when memory allocation fails;
executing a preset memory statistics optimization strategy, wherein the memory statistics optimization strategy is used for reducing the memory occupation amount in the heap memory counted by a memory statistics module of the virtual machine;
and allocating the memory for the object of the target application again according to the memory allocation request.
In a second aspect, the present disclosure provides a virtual machine memory application apparatus, including:
the system comprises a first acquisition module, a first storage module and a second acquisition module, wherein the first acquisition module is used for acquiring a storage allocation request which is used for requesting the allocation of a storage for an object of a target application;
the interception module is used for intercepting the OOM exception thrown out when the memory allocation fails;
the execution module is used for executing a preset memory statistics optimization strategy, and the memory statistics optimization strategy is used for reducing the memory occupation amount in the heap memory counted by the memory statistics module of the virtual machine;
and the allocation module is used for reallocating the memory for the object of the target application according to the memory allocation request.
In a third aspect, the present disclosure provides a computer-readable medium, on which a computer program is stored, where the computer program, when executed by a processing device, implements the steps of the virtual machine memory application method in the first aspect.
In a fourth aspect, the present disclosure provides an electronic device comprising:
a storage device having a computer program stored thereon;
a processing device, configured to execute the computer program in the storage device to implement the steps of the virtual machine memory application method in the first aspect.
According to the technical scheme, the memory allocation request is obtained and used for requesting memory allocation for the target application object, OOM exception thrown out when the memory allocation fails is intercepted, the memory occupation amount in the heap memory counted by the memory counting module of the virtual machine is reduced through the preset memory counting optimization strategy, and the memory counting module counts the memory which is not counted and can be used for allocation, so that the memory can be allocated for the target application object again. Therefore, the number of times of actually throwing the OOM exception is reduced by intercepting the thrown OOM exception and executing a memory statistics optimization strategy, and the flash quit of the target application caused by the OOM exception is further avoided.
Additional features and advantages of the disclosure will be set forth in the detailed description which follows.
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 features are not necessarily drawn to scale. In the drawings:
fig. 1 is a flowchart illustrating a method for applying for a virtual machine memory according to an exemplary embodiment of the present disclosure.
FIG. 2 is a schematic diagram illustrating a comparison of virtual machine memory management partitions according to an example embodiment of the present disclosure.
Fig. 3 is another flowchart illustrating a method for applying for a virtual machine memory according to an exemplary embodiment of the present disclosure.
FIG. 4 is a block diagram of a virtual machine memory application apparatus according to an exemplary embodiment of the present disclosure
Fig. 5 is a schematic structural diagram of an electronic device according to an exemplary embodiment of the present general application.
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 the various steps recited in the method embodiments of the present disclosure may be performed in a different order, and/or performed 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", "an", and "the" modifications in this disclosure are intended to be illustrative rather than limiting, and that those skilled in the art will recognize that "one or more" may be used 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.
As background art shows, electronic devices are continuously enriching various functions and improving performance, mobile internet is also rapidly developing, various internet applications in the market have become comprehensive flagship-level applications at first, application installation packages are large, and the occupied disk memory is up to 1G after the application installation packages are used for a period of time. More sophisticated applications, while having a higher visual experience, also have higher demands on the system. As mentioned in the background art, internet applications still need to be compatible with low-version electronic devices, and when picture or animation resources are used on the line in large quantities, the use space Of the Memory Of the virtual machine heap may be insufficient due to more objects that need to be allocated. Therefore, how to reduce the number of Java OOM exception throws is crucial.
In view of this, the embodiments of the present disclosure provide a virtual machine memory application method, which intercepts a Java OOM exception, reduces the number of times of OOM exception throwing, and avoids a target application from being flashed back due to the OOM exception.
Fig. 1 is a flowchart illustrating a method for applying for a virtual machine memory according to an exemplary embodiment of the present disclosure. The virtual machine memory application method is applied to electronic equipment, and with reference to fig. 1, the virtual machine memory application method includes:
step 101, a memory allocation request is obtained, where the memory allocation request is used to request allocation of a memory for an object of a target application.
It should be understood that the target application is an application on the electronic device.
Specifically, during the running period of the target application, the target application may execute a certain service execution message, and the virtual machine may allocate a memory space for the service to be executed corresponding to the service execution message, so that a memory allocation request may be generated, and generally, data used by the service to be executed is written into the memory in an object form.
For example, the object of the target application may be an object corresponding to data such as a picture, a video, music, and the like.
And step 102, intercepting the OOM exception thrown out when the memory allocation fails.
It should be noted that, when there is no allocable memory for the memory allocation request, the electronic device returns a NULL object (i.e., a NULL object), and when the target application receives the returned NULL object, a problem of flash back may occur, so that the OOM exception thrown out when the memory allocation fails is intercepted, and the return of the NULL object to the memory allocation request can be avoided.
Step 103, executing a preset memory statistics optimization strategy, wherein the memory statistics optimization strategy is used for reducing the memory occupation amount in the heap memory counted by the memory statistics module of the virtual machine.
It should be noted that the memory statistics optimization strategy is used to reduce the memory occupation amount in the heap memory counted by the memory statistics module of the virtual machine. Specifically, the heap memory counted by the memory counting module does not include the occupied memory in the preset module, and the memory counting module counts that the memory not counted can be used for allocation, so as to release and increase the available memory in the current heap area.
For example, the memory footprint in the preset module in the virtual machine may be removed from the memory statistics module. The present embodiment will be further explained below by taking the example that the memory occupied amount in the preset module is removed from the memory counting module.
Fig. 2 is a schematic diagram illustrating a comparison of virtual machine memory management partitions according to an exemplary embodiment of the present disclosure, and referring to fig. 2, a1 in fig. 2 represents an exemplary diagram of a virtual machine memory management partition in the related art, and a2 represents an exemplary diagram of a virtual machine memory management partition in the present disclosure. First, it should be noted that there is a difference in memory management between the related art and the object of the LargeObjectSpace module in the present disclosure, specifically, in the memory management division of a1, the total memory usage amount (i.e., heap memory) counted by the memory counting module includes two modules, i.e., the other space module and the LargeObjectSpace module (i.e., the preset module in the present disclosure), and does not include the Native mem module (here, the memory extension portion) in the virtual machine in the portion 0-2G in fig. 2. In the memory management partition of a2, the total memory usage counted by the memory counting module only includes 1 module, that is, the Other space module, and does not include the memory usage corresponding to the Other Object stored in the LargeObjectSpace (that is, the preset module in the present disclosure), as can be seen from fig. 2, in the memory structure of a1, since the memory usage of the memory counting module of the virtual machine needs to be limited below a certain memory (for example, 512M in fig. 2), the memory usage of the LargeObjectSpace module is virtually limited. In the memory management division of a2, the memory management module of the virtual machine does not count the memory usage of the LargeObjectSpace module, so that the usage ranges of the memory spaces of the LargeObjectSpace module and the other space module are indirectly increased, and the optimization of the memory usage space range is realized from the optimization of the memory management structure.
Illustratively, the virtual machine is an android virtual machine, and the preset module is a module for storing JAVA large objects.
And step 104, allocating the memory for the object of the target application again according to the memory allocation request.
The implementation of the present disclosure is further explained by taking fig. 3 as an example. Referring to fig. 3, firstly, executing a memory application for a memory allocation request, monitoring an OOM exception in a memory application process, when monitoring that the OOM exception occurs, representing that the memory application fails, intercepting the OOM exception and executing a memory statistics optimization strategy, and executing the memory application for the memory allocation request again to ensure that the memory application succeeds; and when the OOM exception is not monitored, directly determining that the memory application is successful.
By the method, a memory allocation request is obtained, the memory allocation request is used for requesting to allocate memory to the target application object, OOM abnormity thrown out when memory allocation fails is intercepted, and the memory counting module counts that the memory which is not counted can be used for allocation, so that the memory occupation amount in the heap memory counted by the memory counting module of the virtual machine is reduced through a preset memory counting optimization strategy, so that the memory which can be used for allocation counted by the memory counting module can be increased, the memory is allocated to the target application object again, the number of times of actually throwing the OOM abnormity is reduced, and flash back of the target application due to the OOM abnormity is avoided; in addition, when the OOM is not intercepted, enough memory space is indicated to be allocated, and a preset memory statistics optimization strategy does not need to be executed, so that the minimum protection effect on intrusion to the system and maximum memory is achieved.
In a possible manner, the step of intercepting the OOM exception thrown when the memory allocation fails as shown in fig. 1 may include: determining the type of an identifier of a preset interface, wherein the preset interface is an interface used for throwing out OOM exception when being called, and the type of the identifier comprises an interception allowing type and an interception forbidding type; and intercepting the OOM exception thrown by the preset interface when monitoring that the preset interface is called under the condition that the type of the identification is the type allowing interception.
For example, the preset interface may be a threadoutofmemoryrer interface, and when the threadoutofmemoryrer interface is called, an OOM exception is thrown.
It should be noted that, when the type of the identifier of the preset interface is the type allowing interception, the representation may perform interception when the preset interface is called; and when the type of the identifier of the preset interface is the interception prohibition type, the representation prohibits interception execution when the preset interface is called, and normally throws out the OOM exception.
For example, the type of the identifier of the preset interface may be a symbolic representation of numbers, characters, and the like, and the embodiment is not limited herein.
By the mode, the OOM exception can be intercepted under the condition that the OOM exception is not intercepted under all conditions, so that whether the OOM exception can be intercepted or not when the preset interface is monitored to be called is determined by determining the type of the identifier of the preset interface, and therefore the intercepting accuracy can be guaranteed.
In a possible manner, the method further comprises: acquiring the removed actual memory occupation amount in the heap memory; and setting the type of the identifier of the preset interface according to the size relation between the preset threshold and the actual memory occupation amount.
The preset threshold is a maximum value of the allowed memory occupation amount reduced from the heap memory counted by the memory counting module of the virtual machine, and the preset threshold may be set according to an actual situation, which is not limited herein.
The actual memory occupancy amount represents the actual memory amount reduced from the memory statistics module of the virtual machine so far, that is, the actual memory amount which is not counted and used in the memory statistics module.
Specifically, the type of the identifier of the preset interface is set as an allowed interception type under the condition that the preset threshold is larger than the actual memory occupation amount; and setting the type of the identifier of the preset interface as a interception prohibition type under the condition that the preset threshold is less than or equal to the actual memory occupation amount.
Through the mode, the preset threshold is set, the release space of the virtual machine memory counting module is dynamically controlled through the preset threshold, the memory occupation of the Native Mem module side of the virtual machine is guaranteed to be maintained in a reasonable range, and the situation that the preset module occupies the memory of the Native Mem module without limitation is avoided.
In a possible manner, the step of obtaining the removed actual memory footprint in the heap memory may include: and when the memory is allocated for the target application object according to the memory allocation request for the first time, acquiring the removed actual memory occupation amount in the heap memory. Therefore, when the memory is allocated to the target application object according to the memory allocation request for the first time, the type of the identifier of the preset interface is determined according to the size relation between the actual memory occupation amount and the preset threshold value, and the memory of the Native Mem module can be maximally prevented from being occupied without limitation.
In a possible manner, the method further comprises: and when the memory is allocated to the object of the target application again according to the memory allocation request, setting the type of the identifier of the preset interface as the interception prohibition type. It can be understood that, after an OOM exception is intercepted once, a memory is allocated to an object of a target application according to a memory allocation request again, if an OOM exception still occurs in the memory application process this time, it is indicated that the expanded memory is insufficient to meet the application of the current memory, and if the OOM exception is intercepted again, a memory fault may be caused to affect the normal operation of subsequent services, so that it is still ensured that the OOM exception is normally thrown under this condition, and further, when a memory is allocated to an object of a target application according to a memory allocation request again, the type of the identifier of the preset interface needs to be set as an interception prohibition type.
For example, the memory amount removed from the memory amount counted by the memory counting module may be determined according to the current memory occupancy amount of the preset module. Specifically, the removal of the memory occupation amount belonging to the preset module in the virtual machine from the heap memory can be specifically realized by the following method: the method comprises the steps that the current memory occupation amount of a preset module in the virtual machine can be obtained, wherein the preset module is a module for storing a JAVA large object; determining the memory to-be-hidden amount according to the current memory occupation amount of the preset module; and updating the total amount of the current memory occupied counted by a memory counting module of the virtual machine according to the amount of the memory to be hidden, wherein the total amount of the current memory occupied counted by the memory counting module does not include the amount of the memory to be hidden, and memories not counted by the memory counting module can be used for distribution.
Through the mode, the memory counting module is used for counting used memories in the heap area of the virtual machine, and the memory counting module counts the memories which are not counted and can be used for distribution, so that the memory occupancy in the preset module is separated from the statistics of the memory counting module of the virtual machine, the memory counting module of the virtual machine cannot count the memory use condition in the preset module, the memories which can be used for distribution in the heap area of the virtual machine are indirectly improved, the phenomenon that Java OOM (Java object management) is abnormal due to the fact that the space of the distributable memories is insufficient and the memories cannot be distributed to the objects is avoided, and the reliability of the equipment is further improved. In a possible manner, the current memory occupancy of the preset module can be obtained by the following manner: acquiring a current memory occupation amount object of a preset module; performing decompiling on the current memory occupation amount object to obtain the relative memory address offset of the current memory occupation amount object; and acquiring the current memory occupation amount of the preset module according to the relative memory address offset of the current memory occupation amount object.
It should be noted that the current memory footprint object may be denoted by "num _ bytes _ allocated _".
For example, the current memory occupancy object of the preset module may be obtained through the proxy interface.
Illustratively, a high-level language source program is compiled into an executable file, and decompilation is the inverse process, i.e., the process of converting machine code (assembly language) into a high-level programming language. The related art can be referred to for the implementation method of decompilation, and this embodiment is not described herein again.
It should be noted that the relative memory address offset represents a physical address offset of the current memory occupancy object relative to the starting physical address of the disk where the current memory occupancy object is located, and according to the relative memory address offset, the current memory occupancy object can be directly located at the position to further acquire data of the current memory occupancy object, and it can be understood that the data includes the current memory occupancy of the preset module.
Because the virtual machine does not directly expose an interface for acquiring the memory occupation of the preset module to the outside, the relative memory address offset of the current memory occupation object can be determined by the method, and then the reading of the current memory occupation of the preset module is realized according to the relative memory address offset, so that the problem that the memory occupation of the preset module cannot be directly acquired in the related technology is solved.
In a possible manner, the method further comprises: respectively acquiring the object quantity objects of a preset module before and after the memory is allocated to the objects for the first time; before the current memory occupation amount of a preset module in the virtual machine is obtained, determining the difference value of the two obtained object quantity objects as a preset difference value, wherein the preset difference value is used for verifying whether the relative memory address offset of the current memory occupation amount object is accurate or not.
It should be noted that the number-of-objects object may be represented by "num _ objects _ allocated _".
The acquisition of the object quantity object can refer to the acquisition mode of the current memory occupation quantity object. Specifically, the object number object is decompiled to obtain a relative memory address offset of the object number object, and then data corresponding to the object number object is obtained according to the relative memory address offset, which can be understood that the data includes the number of the objects.
Illustratively, the preset difference is 1.
Specifically, it is required to respectively obtain the object number objects before and after allocating the memory for the object for the first time, determine whether to execute the step of obtaining the current memory occupancy amount of the preset module in the virtual machine according to whether the difference value between the two obtained object number objects is a preset difference value, and execute the step of obtaining the current memory occupancy amount of the preset module in the virtual machine again when it is determined that the difference value between the two obtained example number objects is the preset difference value.
By the method, the difference value of the object quantity objects is checked, if the difference value is equal to 1, the calculation of the relative memory address offset is normal, otherwise, the calculation of the relative memory address offset is wrong, and therefore the accuracy and the reliability of obtaining the memory occupation of the preset module are guaranteed.
In a possible mode, an interface associated with the correlation step can be proxied through Inlinehook (monitoring any function), and the correlation parameters can be changed in the execution process, so that different android system versions can be compatible.
In this embodiment, the implementation process of InlineHook may refer to related technologies, and this embodiment is not limited herein.
Based on the same inventive concept, an embodiment of the present disclosure provides a virtual machine memory application apparatus, and fig. 4 is a block diagram of a virtual machine memory application apparatus according to an exemplary embodiment of the present disclosure, and with reference to fig. 4, the virtual machine memory application apparatus includes:
a first obtaining module 401, configured to obtain a memory allocation request, where the memory allocation request is used to request to allocate a memory for an object of a target application;
an interception module 402, configured to intercept an OOM exception thrown when memory allocation fails;
an executing module 403, configured to execute a preset memory statistics optimization policy, where the memory statistics optimization policy is used to reduce the memory occupancy in the heap memory counted by the memory statistics module of the virtual machine;
the allocating module 404 is configured to reallocate the memory for the object of the target application according to the memory allocation request.
Optionally, the intercepting module 402 includes:
the identification type determining submodule is used for determining the type of an identification of a preset interface, the preset interface is an interface used for throwing the OOM exception when being called, and the type of the identification comprises an interception allowing type and an interception forbidding type;
and the interception submodule is used for intercepting the OOM exception thrown by the preset interface when monitoring that the preset interface is called under the condition that the type of the identification is the interception permission type.
Optionally, the apparatus 400 further comprises:
the second acquisition module is used for acquiring the removed actual memory occupation amount in the heap memory;
and the first setting module is used for setting the type of the identifier of the preset interface according to the size relationship between the preset threshold and the actual memory occupation amount.
Optionally, the first setting module includes:
the first setting submodule is used for setting the type of the identifier of the preset interface as an allowed interception type under the condition that the preset threshold is larger than the actual memory occupation amount;
and the second setting submodule is used for setting the type of the identifier of the preset interface as an interception prohibition type under the condition that the preset threshold is less than or equal to the actual memory occupation amount.
Optionally, the second obtaining module is specifically configured to obtain the removed actual memory occupation amount in the heap memory when the memory is allocated to the object of the target application according to the memory allocation request for the first time.
Optionally, the apparatus 400 further comprises:
and the second setting module is used for setting the type of the identifier of the preset interface as an interception prohibition type when the memory is allocated to the object of the target application again according to the memory allocation request.
Optionally, the executing module 403 is specifically configured to remove a memory occupied amount of a preset module in the virtual machine from the heap memory, where the virtual machine is an android virtual machine, and the preset module is a module for JAVA storage of a large object.
With regard to the apparatus in the above-described embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment related to the method, and will not be elaborated here.
Based on the same inventive concept, embodiments of the present disclosure further provide a computer-readable medium, on which a computer program is stored, where the computer program, when executed by a processing device, implements the steps of the method for applying for the memory of the virtual machine in the method embodiments.
Based on the same inventive concept, an embodiment of the present disclosure further provides an electronic device, including:
a storage device having a computer program stored thereon;
and the processing device is used for executing the computer program in the storage device so as to realize the steps of the virtual machine memory application method in the method embodiment.
Referring now to FIG. 5, a block diagram of an electronic device 500 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. 5 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. 5, electronic device 500 may include a processing means (e.g., central processing unit, graphics processor, etc.) 501 that may perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)502 or a program loaded from a storage means 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data necessary for the operation of the electronic apparatus 500 are also stored. The processing device 501, the ROM 502, and the RAM 503 are connected to each other through a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
Generally, the following devices may be connected to the I/O interface 505: input devices 506 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; output devices 507 including, for example, a Liquid Crystal Display (LCD), speakers, vibrators, and the like; storage devices 508 including, for example, magnetic tape, hard disk, etc.; and a communication device 509. The communication means 509 may allow the electronic device 500 to communicate with other devices wirelessly or by wire to exchange data. While fig. 5 illustrates an electronic device 500 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 carried on a non-transitory computer readable medium, the computer program containing program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication means 509, or installed from the storage means 508, or installed from the ROM 502. The computer program performs the above-described functions defined in the methods of the embodiments of the present disclosure when executed by the processing device 501.
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 comprise a propagated data signal with computer readable program code embodied therein, either 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 implementations, the electronic devices may communicate using any currently known or future developed network Protocol, such as HTTP (HyperText Transfer Protocol), and may be interconnected 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: acquiring a memory allocation request, wherein the memory allocation request is used for requesting memory allocation for an object of a target application; intercepting OOM exception thrown out when memory allocation fails; executing a preset memory statistics optimization strategy, wherein the memory statistics optimization strategy is used for reducing the memory occupation amount in the heap memory counted by a memory statistics module of the virtual machine; and allocating the memory for the object of the target application again according to the memory allocation request. .
Computer program code for carrying out operations for the present disclosure may be written in any combination of one or more programming languages, including but not limited to 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 modules described in the embodiments of the present disclosure may be implemented by software or hardware. The name of the module does not in some cases form a limitation on the module itself, for example, the first obtaining module may also be described as a "module that obtains a memory allocation request".
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.
Example 1 provides a virtual machine memory application method according to one or more embodiments of the present disclosure, including:
acquiring a memory allocation request, wherein the memory allocation request is used for requesting memory allocation for an object of a target application;
intercepting OOM exception thrown out when memory allocation fails;
executing a preset memory statistics optimization strategy, wherein the memory statistics optimization strategy is used for reducing the memory occupation amount in the heap memory counted by a memory statistics module of the virtual machine;
and allocating the memory for the object of the target application again according to the memory allocation request.
Example 2 provides the method of example 1, in accordance with one or more embodiments of the present disclosure, the intercepting an OOM exception thrown when memory allocation fails, comprising:
determining the type of an identifier of a preset interface, wherein the preset interface is an interface used for throwing out the OOM exception when being called, and the type of the identifier comprises an interception allowing type and an interception forbidding type;
and intercepting the OOM exception thrown by the preset interface when monitoring that the preset interface is called under the condition that the type of the identifier is an interception permission type.
Example 3 provides the method of example 2, further comprising, in accordance with one or more embodiments of the present disclosure:
acquiring the removed actual memory occupation amount in the heap memory;
and setting the type of the identifier of the preset interface according to the size relationship between a preset threshold and the actual memory occupation amount.
According to one or more embodiments of the present disclosure, example 4 provides the method of example 3, where setting the type of the identifier of the preset interface according to a size relationship between a preset threshold and the actual memory occupancy amount includes:
setting the type of the identifier of the preset interface as an allowed interception type under the condition that the preset threshold is larger than the actual memory occupation amount;
and setting the type of the identifier of the preset interface as an interception prohibition type under the condition that the preset threshold is less than or equal to the actual memory occupation amount.
Example 5 provides the method of example 3, wherein obtaining the removed actual memory footprint in the heap memory, according to one or more embodiments of the present disclosure, comprises:
and when the memory is allocated to the object of the target application according to the memory allocation request for the first time, acquiring the removed actual memory occupation amount in the heap memory.
Example 6 provides the method of example 5, further comprising, in accordance with one or more embodiments of the present disclosure:
and when the memory is allocated to the object of the target application again according to the memory allocation request, setting the type of the identifier of the preset interface as an interception prohibition type.
Example 7 provides the method of any one of examples 1-6, the performing a memory statistics optimization policy, in accordance with one or more embodiments of the present disclosure, including:
and removing the memory occupation amount of a preset module in the virtual machine from the heap memory, wherein the virtual machine is an android virtual machine, and the preset module is a module for storing JAVA large objects.
Example 8 provides, in accordance with one or more embodiments of the present disclosure, a virtual machine memory application apparatus, including:
the system comprises a first acquisition module, a first storage module and a second acquisition module, wherein the first acquisition module is used for acquiring a storage allocation request which is used for requesting the allocation of a storage for an object of a target application;
the interception module is used for intercepting the OOM exception thrown out when the memory allocation fails;
the execution module is used for executing a preset memory statistics optimization strategy, and the memory statistics optimization strategy is used for reducing the memory occupation amount in the heap memory counted by the memory statistics module of the virtual machine;
and the allocation module is used for reallocating the memory for the object of the target application according to the memory allocation request.
Example 9 provides a computer readable medium having stored thereon a computer program which, when executed by a processing apparatus, performs the steps of the method of any of examples 1-7.
Example 10 provides, in accordance with one or more embodiments of the present disclosure, an electronic device comprising:
a storage device having a computer program stored thereon;
processing means for executing the computer program in the storage means to carry out the steps of the method of any of examples 1-7.
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. With regard to the apparatus in the above-described embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment related to the method, and will not be elaborated here.

Claims (10)

1. A method for applying for a memory of a virtual machine is characterized by comprising the following steps:
acquiring a memory allocation request, wherein the memory allocation request is used for requesting memory allocation for an object of a target application;
intercepting OOM exception thrown out when memory allocation fails;
executing a preset memory statistics optimization strategy, wherein the memory statistics optimization strategy is used for reducing the memory occupation amount in the heap memory counted by a memory statistics module of the virtual machine;
and allocating the memory for the object of the target application again according to the memory allocation request.
2. The method of claim 1, wherein intercepting the OOM exception thrown when the memory allocation fails comprises:
determining the type of an identifier of a preset interface, wherein the preset interface is an interface used for throwing out the OOM exception when being called, and the type of the identifier comprises an interception allowing type and an interception forbidding type;
and intercepting the OOM exception thrown by the preset interface when monitoring that the preset interface is called under the condition that the type of the identifier is an interception permission type.
3. The method of claim 2, further comprising:
acquiring the removed actual memory occupation amount in the heap memory;
and setting the type of the identifier of the preset interface according to the size relationship between a preset threshold and the actual memory occupation amount.
4. The method according to claim 3, wherein the setting the type of the identifier of the preset interface according to the size relationship between the preset threshold and the actual memory footprint includes:
setting the type of the identifier of the preset interface as an allowed interception type under the condition that the preset threshold is larger than the actual memory occupation amount;
and setting the type of the identifier of the preset interface as an interception prohibition type under the condition that the preset threshold is less than or equal to the actual memory occupation amount.
5. The method of claim 3, wherein the obtaining the removed actual memory footprint in the heap memory comprises:
and when the memory is allocated to the object of the target application according to the memory allocation request for the first time, acquiring the removed actual memory occupation amount in the heap memory.
6. The method of claim 5, further comprising:
and when the memory is allocated to the object of the target application again according to the memory allocation request, setting the type of the identifier of the preset interface as an interception prohibition type.
7. The method according to any of claims 1-6, wherein said performing a memory statistics optimization policy comprises:
removing the memory occupation amount of a preset module in the virtual machine from the heap memory, wherein the virtual machine is an android virtual machine, and the preset module is a module for storing JAVA large objects.
8. A virtual machine memory application apparatus, comprising:
the system comprises a first acquisition module, a first storage module and a second acquisition module, wherein the first acquisition module is used for acquiring a storage allocation request which is used for requesting the allocation of a storage for an object of a target application;
the interception module is used for intercepting the OOM exception thrown out when the memory allocation fails;
the execution module is used for executing a preset memory statistics optimization strategy, and the memory statistics optimization strategy is used for reducing the memory occupation amount in the heap memory counted by the memory statistics module of the virtual machine;
and the allocation module is used for reallocating the memory for the object of the target application according to the memory allocation request.
9. A computer-readable medium, on which a computer program is stored, characterized in that the program, when being executed by processing means, carries out the steps of the method of any one of claims 1 to 7.
10. An electronic device, comprising:
a storage device having a computer program stored thereon;
processing means for executing the computer program in the storage means to carry out the steps of the method according to any one of claims 1 to 7.
CN202110719745.3A 2021-06-28 2021-06-28 Virtual machine memory application method and device, storage medium and electronic equipment Pending CN113407309A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110719745.3A CN113407309A (en) 2021-06-28 2021-06-28 Virtual machine memory application method and device, storage medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110719745.3A CN113407309A (en) 2021-06-28 2021-06-28 Virtual machine memory application method and device, storage medium and electronic equipment

Publications (1)

Publication Number Publication Date
CN113407309A true CN113407309A (en) 2021-09-17

Family

ID=77679765

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110719745.3A Pending CN113407309A (en) 2021-06-28 2021-06-28 Virtual machine memory application method and device, storage medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN113407309A (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103399822A (en) * 2013-08-14 2013-11-20 上海斐讯数据通信技术有限公司 Memory allocation method and system for solving problem of insufficient memory for applied pictures
US20140143516A1 (en) * 2012-11-20 2014-05-22 International Business Machines Corporation Out-of-memory avoidance in dynamic virtual machine memory adjustment
CN107357656A (en) * 2017-06-27 2017-11-17 努比亚技术有限公司 A kind of memory allocation method, mobile terminal and computer-readable recording medium
CN108062247A (en) * 2016-11-09 2018-05-22 腾讯科技(深圳)有限公司 A kind of EMS memory management process and system
CN111708638A (en) * 2020-06-18 2020-09-25 网易(杭州)网络有限公司 Memory allocation method, device, equipment and storage medium
CN112446032A (en) * 2020-11-20 2021-03-05 南方科技大学 Trusted execution environment construction method, system and storage medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140143516A1 (en) * 2012-11-20 2014-05-22 International Business Machines Corporation Out-of-memory avoidance in dynamic virtual machine memory adjustment
CN103399822A (en) * 2013-08-14 2013-11-20 上海斐讯数据通信技术有限公司 Memory allocation method and system for solving problem of insufficient memory for applied pictures
CN108062247A (en) * 2016-11-09 2018-05-22 腾讯科技(深圳)有限公司 A kind of EMS memory management process and system
CN107357656A (en) * 2017-06-27 2017-11-17 努比亚技术有限公司 A kind of memory allocation method, mobile terminal and computer-readable recording medium
CN111708638A (en) * 2020-06-18 2020-09-25 网易(杭州)网络有限公司 Memory allocation method, device, equipment and storage medium
CN112446032A (en) * 2020-11-20 2021-03-05 南方科技大学 Trusted execution environment construction method, system and storage medium

Similar Documents

Publication Publication Date Title
US11146502B2 (en) Method and apparatus for allocating resource
CN107807852B (en) Application program performance control method, device and computer readable storage medium
CN111221638B (en) Concurrent task scheduling processing method, device, equipment and medium
CN111432001B (en) Method, apparatus, electronic device and computer readable medium for jumping scenes
CN111625422B (en) Thread monitoring method, thread monitoring device, electronic equipment and computer readable storage medium
CN114625536B (en) Video memory allocation method, device, medium and electronic equipment
CN112416616A (en) Micro-service calling method and device, electronic equipment and storage medium
CN115237589A (en) SR-IOV-based virtualization method, device and equipment
CN112306685B (en) Task isolation method, device, electronic equipment and computer readable medium
CN113391882B (en) Virtual machine memory management method and device, storage medium and electronic equipment
CN113407309A (en) Virtual machine memory application method and device, storage medium and electronic equipment
CN111756833B (en) Node processing method, node processing device, electronic equipment and computer readable medium
CN111538717B (en) Data processing method, device, electronic equipment and computer readable medium
CN110502891B (en) Method, device, medium and electronic equipment for acquiring process memory leakage
CN113176937A (en) Task processing method and device and electronic equipment
CN113518183A (en) Camera calling method and device and electronic equipment
CN111949528A (en) Memory leak detection method and device, electronic equipment and storage medium
CN112817701A (en) Timer processing method and device, electronic equipment and computer readable medium
CN112767036A (en) Service processing method and device
CN110633141A (en) Memory management method and device of application program, terminal equipment and medium
CN113765692B (en) Current limiting method, device, electronic equipment and computer readable medium
CN111324888B (en) Verification method and device for application program starting, electronic equipment and storage medium
CN113395291B (en) Flow control method and device, electronic equipment and storage medium
CN117093149A (en) Memory management method, device, medium and electronic equipment
CN111240738B (en) File processing method, device, equipment and 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