WO2016119605A1 - 终端中应用启动时的内存分配方法及其系统 - Google Patents

终端中应用启动时的内存分配方法及其系统 Download PDF

Info

Publication number
WO2016119605A1
WO2016119605A1 PCT/CN2016/071165 CN2016071165W WO2016119605A1 WO 2016119605 A1 WO2016119605 A1 WO 2016119605A1 CN 2016071165 W CN2016071165 W CN 2016071165W WO 2016119605 A1 WO2016119605 A1 WO 2016119605A1
Authority
WO
WIPO (PCT)
Prior art keywords
application
java heap
startup
prediction value
java
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.)
Ceased
Application number
PCT/CN2016/071165
Other languages
English (en)
French (fr)
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.)
Alibaba Group Holding Ltd
Original Assignee
Alibaba Group Holding 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 Alibaba Group Holding Ltd filed Critical Alibaba Group Holding Ltd
Publication of WO2016119605A1 publication Critical patent/WO2016119605A1/zh
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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/445Program loading or initiating

Definitions

  • the present invention relates to a terminal application technology, and in particular, to a memory allocation method and system thereof when an application is started in a terminal.
  • each application is allocated a Java heap memory space of size S 0 when it is started, which is used to store related data such as Java class objects dynamically generated by the program at startup and runtime.
  • the Java heap is managed by the garbage collector. Object data that is no longer needed is cleared by the garbage collector.
  • the cleaned heap space can be used to store other object data.
  • the existing android system cannot predict the size of the Java heap space required by each application. In order not to waste memory, the value of S 0 will be relatively small. If the application generates a large amount of object data during the startup process, after the garbage collection still fails to meet the distribution requirements, the system dynamically increases the heap space capacity of the application. In this way, during the application startup phase, the size of the heap space will increase as the startup progresses, and the overall appearance is an incremental sequence ⁇ S 0 , S 1 , S 2 , S 3 ... ⁇ .
  • the inventors of the present invention have found that for each start of all applications, the existing android system starts from a uniform smaller value S 0 and gradually increases the Java heap space size according to the application requirements.
  • the advantage of this is that it does not waste memory, but there is a drawback that reduces the user experience when the application starts.
  • this mechanism triggers garbage collection, which has a time-consuming cost, which causes an increase in startup time and a pause in the animation.
  • An object of the present invention is to provide a memory allocation method and a system thereof when an application is started in a terminal, which can effectively reduce the number of garbage collections during application startup without increasing the total amount of memory.
  • an embodiment of the present invention discloses a memory allocation method when an application starts in a terminal, and the method includes the following steps:
  • the Java heap is initially allocated for the application at the next startup of the application.
  • the embodiment of the invention also discloses a memory allocation system when the application starts in the terminal, the system comprising:
  • a recording module for recording the Java heap size actually allocated by the application after each startup
  • a calculation module configured to calculate a Java heap prediction value that is next started by the application according to an actual allocated Java heap size of the application recorded by the recording module
  • An allocation module for initially allocating a Java heap to the application at the next startup of the application based on the Java heap prediction value calculated by the computing module.
  • the Java heap prediction value of the next startup of the application is calculated according to the Java heap size actually allocated after each startup of the recorded application, and the application is initially started according to the Java heap prediction value when the application is next started. Allocating the Java heap effectively reduces the number of garbage collections during application startup without increasing the amount of memory, thereby reducing application startup time and improving startup animation smoothness.
  • selecting c is a value between 0.4 and 0.6, which can ensure that the predicted value of the Java heap that is started each time is continuously approaching the actual allocated Java heap size, and the fluctuation of the Java heap size initially allocated at each startup can be avoided. To cause unnecessary memory waste.
  • the Java heap prediction value for the next startup is more accurate.
  • FIG. 1 is a schematic flowchart of a memory allocation method when an application is started in a terminal according to the first embodiment of the present invention
  • Figure 2 is a schematic diagram of a typical application startup process on an android system.
  • Fig. 3 and Fig. 4 are graphs of predicted results and M values when c is 0.8 and 0.2, respectively.
  • FIG. 5 is a schematic structural diagram of a memory allocation system when an application is started in a terminal according to a second embodiment of the present invention.
  • FIG. 1 is a schematic flowchart of a memory allocation method when an application starts in the terminal. It can be understood that the above terminal can be a smart phone, a tablet computer, a television, a digital camera, a game machine, and the like.
  • the method includes the following steps:
  • step 101 the Java heap size actually allocated by the application after each startup is recorded.
  • the Java heap prediction value of the next startup of the application is calculated according to the actually allocated Java heap size of the recorded application.
  • the Java heap is initially allocated for the application at the next startup of the application.
  • the above method is applied to an Android system or an Android-like system.
  • the above method can also be applied to other operating systems using the Java language.
  • the Java heap prediction value that is next started by the application is calculated according to the Java heap size actually allocated after each startup of the recorded application, and the next time the application is started according to the Java heap prediction value.
  • the application initially allocates the Java heap, effectively reducing the number of garbage collections during application startup without increasing the amount of memory, thereby reducing application startup time and improving startup animation smoothness.
  • the Java heap prediction value that is started next time by the application may be calculated in various manners, specifically:
  • Sn -1 is the Java heap prediction value for the nth start of the application
  • Sn -2 is the Java heap prediction value for the n-1th startup of the application
  • Mn -2 is the n-1th time of the application.
  • the actual Java heap size allocated after startup, 0 ⁇ c ⁇ 1, 0 ⁇ c' ⁇ 1, and c+c' 1.
  • c can be a value between 0.4 and 0.6. Choosing c is a value between 0.4 and 0.6, which can ensure that the predicted value of the Java heap that is started each time is constantly approaching the actual allocated Java heap size, and Avoid fluctuations in the initial allocation of Java heap size each time you start, causing unnecessary memory waste.
  • Java heap prediction value S n-1 for n-th application-initiated M 0, M 1 ..., M n-2 , respectively for the application of the 1st, 2nd ..., n-1 times after the start
  • the actual allocated Java heap size, 0 ⁇ c 0 , c 1 ..., c n-2 ⁇ 1, and c 0 +c 1 +...+c n-2 1.
  • one or a combination of the above calculation methods may be selected as needed.
  • the former method is used several times before the application is started, and the latter method is used later to achieve better results.
  • the present invention proposes a new memory allocation method: predicting the maximum Java heap size M required for each application at the next startup, when the user The next time the application is launched, the system will directly allocate a heap of size M to the application. This reduces the number of garbage collections during application startup, which reduces application launch time and the ability to initiate animations.
  • the above prediction method is for each application. Since the maximum Java heap size required for each application at startup is different, the maximum heap size predicted by the present invention for each application is also different. Second, the above prediction method predicts the heap size required during application startup. Finally, the start-up time of each application varies, so you need to define the "start-up period.” As shown in FIG. 2, taking the typical application startup process on the android system as an example, the "starting period" used in the present invention includes four steps from "1 user clicks the application launch icon" to "4 application first frame display”. .
  • the first startup method of the application adopts the same heap allocation method as the existing android system, that is, the Java heap of size S 0 is first allocated, where S 0 is a uniform small value, and the application is dynamic during the startup process. Increase the heap space capacity.
  • the system will receive a "Displayed" message indicating that the first frame of the application has been displayed. At this point we write down the current Java heap size M 0 .
  • c 0 is taken directly, S n may be caused.
  • Mn -1 fluctuates.
  • c takes an intermediate value of 0.5 to 0, which can ensure that the prediction result is continuously approaching the true value, and unnecessary fluctuation of the prediction result can be avoided.
  • the present invention proposes a new memory allocation strategy, which can allocate memory more reasonably without increasing the total amount of memory, thereby reducing application startup time and improving startup animation smoothness.
  • the method embodiments of the present invention can all be implemented in software, hardware, firmware, and the like. Regardless of whether the invention is implemented in software, hardware, or firmware, the instruction code can be stored in any class.
  • Type of computer accessible memory eg, permanent or modifiable, volatile or non-volatile, solid or non-solid, fixed or replaceable media, etc.
  • the memory may be, for example, Programmable Array Logic ("PAL"), Random Access Memory (RAM), or Programmable Read Only Memory (PROM). "), Read-Only Memory (“ROM”), Electrically Erasable Programmable ROM (“EEPROM”), Disk, CD, Digital Versatile Disc , referred to as "DVD”) and so on.
  • PAL Programmable Array Logic
  • RAM Random Access Memory
  • PROM Programmable Read Only Memory
  • ROM Read-Only Memory
  • EEPROM Electrically Erasable Programmable ROM
  • Disk CD
  • DVD Digital Versatile Disc
  • FIG. 5 is a schematic structural diagram of a memory allocation system when an application is started in the terminal. As shown in Figure 5, the system includes:
  • a logging module that records the actual Java heap size allocated by the application after each launch.
  • the calculation module is configured to calculate a Java heap prediction value that is next started by the application according to the actual allocated Java heap size of the application recorded by the recording module. as well as
  • An allocation module for initially allocating a Java heap to the application at the next startup of the application based on the Java heap prediction value calculated by the computing module.
  • the above system is applied to an Android system or an Android-like system.
  • the above described system may also be applied to other operating systems using the Java language.
  • the calculation module calculates a Java heap prediction value that is next started by the application according to the Java heap size actually allocated after each startup of the recorded application, and the allocation module is next to the application according to the Java heap prediction value. Initially allocate the Java heap for the application at startup, effectively reducing the number of garbage collections during application startup without increasing the total amount of memory, thereby reducing application startup time and improving startup animation smoothness.
  • the above computing module can predict the Java heap that is started next time for the application in various ways.
  • the value is calculated, specifically:
  • S n-1 is the Java heap predicted value Application n-th start
  • S n-2 is the Java heap predicted value Application of n-1 current startup
  • M n-2 after application of the n-1 times start the actual
  • c is from 0.4 to 0.6. Choosing c is 0.4 ⁇ 0.6, which can ensure that the Java heap prediction value that is started each time is approaching the actual allocated Java heap size, and can avoid the fluctuation of the Java heap size allocated at the initial startup to avoid unnecessary memory waste. .
  • Sn -1 is the predicted value of the Java heap that is used for the nth start
  • Java heap size actually allocated after the first two times, the first three times, or the first m times can be considered as needed.
  • a Java heap prediction value that is started is calculated.
  • one or a combination of the above calculation methods may be selected as needed.
  • the former method is used several times before the application is started, and the latter method is used later to achieve better results.
  • the Java heap prediction value that is started next time by the application may not be calculated according to the historical data, and the memory usage of the application itself may be calculated at the same time that the application is installed. Apply the started Java heap prediction value.
  • the first embodiment is a method embodiment corresponding to the present embodiment, and the present embodiment can be implemented in cooperation with the first embodiment.
  • the related technical details mentioned in the first embodiment are still effective in the present embodiment, and are not described herein again in order to reduce repetition. Accordingly, the related art details mentioned in the present embodiment can also be applied to the first embodiment.
  • each module mentioned in each device implementation manner of the present invention is a logic module.
  • a logic module may be a physical module, a part of a physical module, or multiple physical entities.
  • the combined implementation of modules, the physical implementation of these logic modules themselves is not the most important, the combination of the functions implemented by these logic modules is the key to solving the technical problems raised by the present invention.
  • the above-mentioned various device embodiments of the present invention do not introduce a module that is not closely related to solving the technical problem proposed by the present invention, which does not indicate that the above device implementation does not have other Module.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

一种终端中应用启动时的内存分配方法及其系统,涉及终端应用技术。根据已记录的应用每次启动后实际分配的Java堆大小计算该应用下一次启动的Java堆预测值(102),并根据该Java堆预测值在该应用下一次启动时为该应用初始分配Java堆(103),在不增加内存总量的前提下,有效减少了应用启动期间的垃圾回收次数,从而减少应用启动时间,提高启动动画平滑度。

Description

终端中应用启动时的内存分配方法及其系统 技术领域
本发明涉及终端应用技术,特别涉及终端中应用启动时的内存分配方法及其系统。
背景技术
在android或者类android系统中,应用启动时的用户体验主要体现在应用启动时间的长短和应用启动动画的平滑程度上。这两个方面都跟应用启动时的内存的大小和分配方法有关。在内存有限的情况下,对内存需求较高的应用比如游戏等可能会面临启动时间长、启动动画卡顿等用户体验问题。
在android系统里,每个应用在启动时,系统会为其分配一块大小为S0的Java堆内存空间,用以存放程序在启动和运行时动态产生的Java类对象等相关数据。Java堆是由垃圾回收器管理的,不再需要的对象数据会被垃圾回收器清除,清理出来的堆空间可以用来存放其它对象数据。
现有android系统无法预知每个应用所需Java堆空间的大小,为了不浪费内存,S0的取值会相对较小。如果应用在启动过程中产生大量对象数据,经过垃圾回收后仍不能满足分配需求,系统会动态增加该应用的堆空间容量。这样一来,在应用启动阶段,堆空间的大小会随着启动的推进而不断增加,总体呈现为递增序列{S0,S1,S2,S3…}。
本发明的发明人发现,对所有应用的每次启动,现有android系统都是从一个统一的较小值S0开始,根据应用需求逐步增加Java堆空间大小。这样做的好处是不浪费内存,但是存在一个缺点,会降低应用启动时的用户体验。在应用启动阶段,这种机制会触发垃圾回收,垃圾回收是有时间代价的,它会造成启动时间的增加和启动动画的卡顿。
发明内容
本发明的目的在于提供一种终端中应用启动时的内存分配方法及其系统,在不增加内存总量的前提下,有效减少了应用启动期间的垃圾回收次数。
为解决上述技术问题,本发明的实施方式公开了一种终端中应用启动时的内存分配方法,该方法包括以下步骤:
记录应用每次启动后实际分配的Java堆大小;
根据已记录的应用的实际分配的Java堆大小计算该应用下一次启动的Java堆预测值;
根据Java堆预测值,在应用下一次启动时为该应用初始分配Java堆。
本发明的实施方式还公开了一种终端中应用启动时的内存分配系统,该系统包括:
记录模块,用于记录应用每次启动后实际分配的Java堆大小;
计算模块,用于根据记录模块已记录的应用的实际分配的Java堆大小计算该应用下一次启动的Java堆预测值;以及
分配模块,用于根据计算模块计算的Java堆预测值,在应用下一次启动时为该应用初始分配Java堆。
本发明实施方式与现有技术相比,主要区别及其效果在于:
在本发明中,根据已记录的应用每次启动后实际分配的Java堆大小计算该应用下一次启动的Java堆预测值,并根据该Java堆预测值在该应用下一次启动时为该应用初始分配Java堆,在不增加内存总量的前提下,有效减少了应用启动期间的垃圾回收次数,从而减少应用启动时间,提高启动动画平滑度。
进一步地,选取c为0.4~0.6之间的值,既可以保证每次启动的Java堆预测值不断逼近实际分配的Java堆大小,又可以避免每次启动时初始分配的Java堆大小的波动,以造成不必要的内存浪费。
进一步地,考虑更多次启动后实际分配的Java堆大小,使得下一次启动的Java堆预测值更准确。
附图说明
图1是本发明第一实施方式中一种终端中应用启动时的内存分配方法的流程示意图;
图2是android系统上典型的应用启动过程的示意图。
图3和图4分别是c取值为0.8和0.2时预测结果与M值的曲线图。
图5是本发明第二实施方式中一种终端中应用启动时的内存分配系统的结构示意图。
具体实施方式
在以下的叙述中,为了使读者更好地理解本申请而提出了许多技术细节。但是,本领域的普通技术人员可以理解,即使没有这些技术细节和基于以下各实施方式的种种变化和修改,也可以实现本申请各权利要求所要求保护的技术方案。
为使本发明的目的、技术方案和优点更加清楚,下面将结合附图对本发明的实施方式作进一步地详细描述。
本发明第一实施方式涉及一种终端中应用启动时的内存分配方法。图1是该终端中应用启动时的内存分配方法的流程示意图。可以理解,上述终端可以为智能手机、平板电脑、电视机、数码相机、游戏机等等。
如图1所示,该方法包括以下步骤:
在步骤101中,记录应用每次启动后实际分配的Java堆大小。
此后进入步骤102,根据已记录的应用的实际分配的Java堆大小计算该应用下一次启动的Java堆预测值。
此后进入步骤103,根据Java堆预测值,在应用下一次启动时为该应用初始分配Java堆。
此后结束本流程。
可选地,上述方法应用于安卓系统或类安卓系统。此外,可以理解,在本发明的其他实施方式中,上述方法也可以应用于使用Java语言的其他操作系统中。
在本实施方式的方法中,根据已记录的应用每次启动后实际分配的Java堆大小计算该应用下一次启动的Java堆预测值,并根据该Java堆预测值在该应用下一次启动时为该应用初始分配Java堆,在不增加内存总量的前提下,有效减少了应用启动期间的垃圾回收次数,从而减少应用启动时间,提高启动动画平滑度。
其中,在步骤102中可以以各种方式对该应用下一次启动的Java堆预测值进行计算,具体地说:
可以在步骤102中,根据Sn-1=c*Sn-2+c'*Mn-2计算该应用第n次启动的Java堆预测值,n为大于1的整数。
其中,Sn-1为该应用第n次启动的Java堆预测值,Sn-2为该应用第n-1次启动的Java堆预测值,Mn-2为该应用第n-1次启动后实际分配的Java堆大小,0<c<1,0<c'<1,且c+c'=1。
优选地,c可以为0.4~0.6之间的值。选取c为0.4~0.6之间的值,既可以保证每次启动的Java堆预测值不断逼近实际分配的Java堆大小,又可以 避免每次启动时初始分配的Java堆大小的波动,以造成不必要的内存浪费。
需注意的是,当直接取c=0时,Sn-1=Mn-2,…,S2=M1,S1=M0,相当于直接按照上一次启动完成时Java堆的大小来为下一次启动分配堆。这样做,虽然可能会产生波动,但优化效果通常比较显著。
也可以在步骤102中把以往历次启动的Java堆大小都考虑进来,即根据Sn-1=c0*Mn-2+c1*Mn-3+…+cn-2*M0计算该应用第n次启动的Java堆预测值,n为大于1的整数。
其中,Sn-1为该应用第n次启动的Java堆预测值,M0、M1…,Mn-2分别为该应用第1次、第2次…,第n-1次启动后实际分配的Java堆大小,0<c0,c1…,cn-2<1,且c0+c1+…+cn-2=1。
可以理解,在本发明的各个实施方式中,可以对M0、M1…,Mn-2进行算术平均以得到Sn-1,即c0=c1=…=cn-2=1/(n-1),也可以对M0、M1…,Mn-2进行加权平均,即可以为c0,c1…,cn-2选择不同的取值,在一优选实例中,选择c0>c1>…>cn-2,以使得最近几次启动后实际分配的Java堆大小的权重更大,或使用其他函数来进行计算。
此外,可以理解,在本发明的其他实施方式中,也可以根据需要仅考虑前两次、前三次或前m次(m为整数)启动后实际分配的Java堆大小以对下一次启动的Java堆预测值进行计算。
考虑更多次启动后实际分配的Java堆大小,可以使下一次启动的Java堆预测值更准确。
在实际操作时,可以根据需要选择上述计算方式中的一种或其组合。例如在启动该应用的前几次采用前一种方式,之后采用后一种方式,以达到更佳的效果。
此外,可以理解,在本发明的其他实施方式中,也可以不根据历史数据 来计算上述应用下一次启动的Java堆预测值,在安装应用的同时即通过分析应用本身的内存使用情况来计算该应用启动的Java堆预测值。
由上可以看到,为了减少垃圾回收次数,提升应用启动时的用户体验,本发明提出了一种新的内存分配方法:预测每一个应用在下次启动时所需最大Java堆大小M,当用户下次启动该应用时,系统将直接分配大小为M的堆给该应用。这样,应用启动期间发生垃圾回收的次数就会减少,从而减少了应用启动时间和启动动画的卡顿。
我们在此对该预测方法作几点说明。首先,上述预测方法针对的是每一个应用。因为每个应用在启动时所需最大Java堆大小都不相同,本发明针对每个应用预测出的最大堆大小也是不同的。其次,上述预测方法预测的是应用启动期间所需堆大小。最后,每个应用的启动时间长短不一,所以需要界定“启动期间”。如图2所示,以android系统上典型的应用启动过程为例,本发明所使用的“启动期间”包括从“1用户点击应用启动图标”到“4应用第一帧显示”共四个步骤。
以下将进一步以安卓系统和Sn-1=c*Sn-2+c'*Mn-2为例对上述方法进行详细描述。具体如下:
(1)应用第一次启动时采用与现有android系统相同的堆分配方法,即先分配大小为S0的Java堆,其中S0是一个统一的较小值,应用在启动过程中会动态增加堆空间容量。当启动过程完成时,系统会收到“Displayed”消息,表示应用第一帧已经显示。此时我们记下应用当前Java堆大小M0
(2)应用第二次启动时,直接分配大小为S1的Java堆,S1=c*S0+c’*M0(其中0<c<1,0<c’<1,且c+c’=1),通常情况下c取0~1中间值0.5,也可以根据实际需要选择0~1之间的其他取值。当启动过程完成时,记下当前Java堆大小M1
(3)依次类推,应用第n次启动时,直接分配大小为Sn-1的Java堆, Sn-1=c*Sn-2+c’*Mn-2(其中0<c<1,0<c’<1,且c+c’=1)。当启动过程完成时,记下当前Java堆大小Mn-1
下面将对c的取值稍作说明,以了解c的取值对预测的影响。如果c=1,则Sn-1=Sn-2=…=S1=S0,上述预测方法将退化成现有android系统所使用的堆分配方法;如果c=0,则Sn-1=Mn-2,…,S2=M1,S1=M0,上述预测方法相当于直接按照上一次启动完成时Java堆的大小来为下一次启动分配堆。因为应用每次启动完成时Java堆的大小可能并不相同,这跟S0的取值有关,也跟应用本身的实现有关(例如应用更新),如果直接取c=0,可能会造成Sn随着Mn-1波动。优选地,在本实施例中,c取0~1中间值0.5,这样既可以保证预测结果不断逼近真实值,也可以避免预测结果不必要的波动。
此外,也可以根据系统的设计倾向对c取0~1之间其它值。如图3和图4所示,当c越接近1时(例如c=0.8),预测结果逼近M值越慢;当c越接近0时(例如c=0.2),预测结果逼近M值越快,但是波动更大,即如图4所示,在第3次和第4次启动时预测结果大于M值,在第5次和第6次启动时预测结果小于M值,则在预测结果大于M值时会造成一定的内存浪费。因此,我们可以根据系统的设计倾向对c进行灵活取值。如果追求更快见效,可以使用接近0的取值;如果追求稳定性,可以使用接近1的取值。
因此,本发明提出了一种新的内存分配策略,可以在不增加内存总量的前提下,更加合理的分配内存,从而减少应用启动时间,提高启动动画平滑度。
可以理解,以上仅为一优选例,在本发明的其他实施例中,也可以根据需要使用其他计算方式或其组合,并应用于使用Java语言的其他操作系统中。
本发明的各方法实施方式均可以以软件、硬件、固件等方式实现。不管本发明是以软件、硬件、还是固件方式实现,指令代码都可以存储在任何类 型的计算机可访问的存储器中(例如永久的或者可修改的,易失性的或者非易失性的,固态的或者非固态的,固定的或者可更换的介质等等)。同样,存储器可以例如是可编程阵列逻辑(Programmable Array Logic,简称“PAL”)、随机存取存储器(Random Access Memory,简称“RAM”)、可编程只读存储器(Programmable Read Only Memory,简称“PROM”)、只读存储器(Read-Only Memory,简称“ROM”)、电可擦除可编程只读存储器(Electrically Erasable Programmable ROM,简称“EEPROM”)、磁盘、光盘、数字通用光盘(Digital Versatile Disc,简称“DVD”)等等。
本发明第二实施方式涉及一种终端中应用启动时的内存分配系统。图5是该终端中应用启动时的内存分配系统的结构示意图。如图5所示,该系统包括:
记录模块,用于记录应用每次启动后实际分配的Java堆大小。
计算模块,用于根据记录模块已记录的应用的实际分配的Java堆大小计算该应用下一次启动的Java堆预测值。以及
分配模块,用于根据计算模块计算的Java堆预测值,在应用下一次启动时为该应用初始分配Java堆。
可选地,上述系统应用于安卓系统或类安卓系统。此外,可以理解,在本发明的其他实施方式中,上述系统也可以应用于使用Java语言的其他操作系统中。
在本实施方式的系统中,计算模块根据已记录的应用每次启动后实际分配的Java堆大小计算该应用下一次启动的Java堆预测值,分配模块根据该Java堆预测值在该应用下一次启动时为该应用初始分配Java堆,在不增加内存总量的前提下,有效减少了应用启动期间的垃圾回收次数,从而减少应用启动时间,提高启动动画平滑度。
其中,上述计算模块可以以各种方式对该应用下一次启动的Java堆预测 值进行计算,具体地说:
上述计算模块可以用于根据Sn-1=c*Sn-2+c'*Mn-2来计算应用第n次启动的Java堆预测值,n为大于1的整数。
其中,Sn-1为应用第n次启动的Java堆预测值,Sn-2为应用第n-1次启动的Java堆预测值,Mn-2为应用第n-1次启动后实际分配的Java堆大小,0<c<1,0<c'<1,且c+c'=1。
优选地,c为0.4~0.6。选取c为0.4~0.6,既可以保证每次启动的Java堆预测值不断逼近实际分配的Java堆大小,又可以避免每次启动时初始分配的Java堆大小的波动,以造成不必要的内存浪费。
需注意的是,当直接取c=0时,Sn-1=Mn-2,…,S2=M1,S1=M0,相当于直接按照上一次启动完成时Java堆的大小来为下一次启动分配堆。这样做,虽然可能会产生波动,但优化效果通常比较显著。
上述计算模块也可以用于根据Sn-1=c0*Mn-2+c1*Mn-3+…+cn-2*M0来计算应用第n次启动的Java堆预测值。
其中,Sn-1为应用第n次启动的Java堆预测值,M0、M1…,Mn-2分别为应用第1次、第2次…,第n-1次启动后实际分配的Java堆大小,0<c0,c1…,cn-2<1,且c0+c1+…+cn-2=1。
可以理解,在本发明的各个实施方式中,可以对M0、M1…,Mn-2进行算术平均以得到Sn-1,即c0=c1=…=cn-2=1/(n-1),也可以对M0、M1…,Mn-2进行加权平均,即可以为c0,c1…,cn-2选择不同的取值,在一优选实例中,选择c0>c1>…>cn-2,以使得最近几次启动后实际分配的Java堆大小的权重更大,或使用其他函数来进行计算。
此外,可以理解,在本发明的其他实施方式中,也可以根据需要仅考虑前两次、前三次或前m次(m为整数)启动后实际分配的Java堆大小对下 一次启动的Java堆预测值进行计算。
考虑更多次启动后实际分配的Java堆大小,可以使下一次启动的Java堆预测值更准确。
在实际操作时,可以根据需要选择上述计算方式中的一种或其组合。例如在启动该应用的前几次采用前一种方式,之后采用后一种方式,以达到更佳的效果。
此外,可以理解,在本发明的其他实施方式中,也可以不根据历史数据来计算上述应用下一次启动的Java堆预测值,在安装应用的同时即通过分析应用本身的内存使用情况来计算该应用启动的Java堆预测值。
第一实施方式是与本实施方式相对应的方法实施方式,本实施方式可与第一实施方式互相配合实施。第一实施方式中提到的相关技术细节在本实施方式中依然有效,为了减少重复,这里不再赘述。相应地,本实施方式中提到的相关技术细节也可应用在第一实施方式中。
需要说明的是,本发明各设备实施方式中提到的各模块都是逻辑模块,在物理上,一个逻辑模块可以是一个物理模块,也可以是一个物理模块的一部分,还可以以多个物理模块的组合实现,这些逻辑模块本身的物理实现方式并不是最重要的,这些逻辑模块所实现的功能的组合才是解决本发明所提出的技术问题的关键。此外,为了突出本发明的创新部分,本发明上述各设备实施方式并没有将与解决本发明所提出的技术问题关系不太密切的模块引入,这并不表明上述设备实施方式并不存在其它的模块。
需要说明的是,在本专利的权利要求和说明书中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要 素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。
虽然通过参照本发明的某些优选实施方式,已经对本发明进行了图示和描述,但本领域的普通技术人员应该明白,可以在形式上和细节上对其作各种改变,而不偏离本发明的精神和范围。

Claims (10)

  1. 一种终端中应用启动时的内存分配方法,其特征在于,该方法包括以下步骤:
    记录应用每次启动后实际分配的Java堆大小;
    根据已记录的所述应用的实际分配的Java堆大小计算该应用下一次启动的Java堆预测值;
    根据所述Java堆预测值,在所述应用下一次启动时为该应用初始分配Java堆。
  2. 根据权利要求1所述的终端中应用启动时的内存分配方法,其特征在于,所述“根据已记录的所述应用的实际分配的Java堆大小计算该应用下一次启动的Java堆预测值”的步骤中,根据Sn-1=c*Sn-2+c'*Mn-2计算所述应用第n次启动的Java堆预测值,n为大于1的整数;
    其中,Sn-1为所述应用第n次启动的Java堆预测值,Sn-2为所述应用第n-1次启动的Java堆预测值,Mn-2为所述应用第n-1次启动后实际分配的Java堆大小,0<c<1,0<c'<1,且c+c'=1。
  3. 根据权利要求2所述的终端中应用启动时的内存分配方法,其特征在于,c为0.4~0.6之间的任一值。
  4. 根据权利要求1所述的终端中应用启动时的内存分配方法,其特征在于,所述“根据已记录的所述应用的实际分配的Java堆大小计算该应用下一次启动的Java堆预测值”的步骤中,根据Sn-1=c0*Mn-2+c1*Mn-3+…+cn -2*M0计算所述应用第n次启动的Java堆预测值,n为大于1的整数;
    其中,Sn-1为所述应用第n次启动的Java堆预测值,M0、M1…,Mn-2分别为所述应用第1次、第2次…,第n-1次启动后实际分配的Java堆大小, 0<c0,c1…,cn-2<1,且c0+c1+…+cn-2=1。
  5. 根据权利要求1至4中任一项所述的终端中应用启动时的内存分配方法,其特征在于,上述方法应用于安卓系统。
  6. 一种终端中应用启动时的内存分配系统,其特征在于,该系统包括:
    记录模块,用于记录应用每次启动后实际分配的Java堆大小;
    计算模块,用于根据所述记录模块已记录的所述应用的实际分配的Java堆大小计算该应用下一次启动的Java堆预测值;以及
    分配模块,用于根据所述计算模块计算的所述Java堆预测值,在所述应用下一次启动时为该应用初始分配Java堆。
  7. 根据权利要求6所述的终端中应用启动时的内存分配系统,其特征在于,所述计算模块用于根据Sn-1=c*Sn-2+c'*Mn-2来计算所述应用第n次启动的Java堆预测值,n为大于1的整数;
    其中,Sn-1为所述应用第n次启动的Java堆预测值,Sn-2为所述应用第n-1次启动的Java堆预测值,Mn-2为所述应用第n-1次启动后实际分配的Java堆大小,0<c<1,0<c'<1,且c+c'=1。
  8. 根据权利要求7所述的终端中应用启动时的内存分配系统,其特征在于,c为0.4~0.6之间的任一值。
  9. 根据权利要求6所述的终端中应用启动时的内存分配系统,其特征在于,所述计算模块用于根据Sn-1=c0*Mn-2+c1*Mn-3+…+cn-2*M0来计算所述应用第n次启动的Java堆预测值,n为大于1的整数;
    其中,Sn-1为所述应用第n次启动的Java堆预测值,M0、M1…,Mn-2分别为所述应用第1次、第2次…,第n-1次启动后实际分配的Java堆大小,0<c0,c1…,cn-2<1,且c0+c1+…+cn-2=1。
  10. 根据权利要求6至9中任一项所述的终端中应用启动时的内存分配 系统,其特征在于,上述系统应用于安卓系统。
PCT/CN2016/071165 2015-01-27 2016-01-18 终端中应用启动时的内存分配方法及其系统 Ceased WO2016119605A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201510042012.5A CN105988823B (zh) 2015-01-27 2015-01-27 终端中应用启动时的内存分配方法及其系统
CN201510042012.5 2015-01-27

Publications (1)

Publication Number Publication Date
WO2016119605A1 true WO2016119605A1 (zh) 2016-08-04

Family

ID=56542387

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/071165 Ceased WO2016119605A1 (zh) 2015-01-27 2016-01-18 终端中应用启动时的内存分配方法及其系统

Country Status (2)

Country Link
CN (1) CN105988823B (zh)
WO (1) WO2016119605A1 (zh)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110018902A (zh) * 2018-01-10 2019-07-16 广东欧珀移动通信有限公司 内存处理方法和装置、电子设备、计算机可读存储介质
CN110018900A (zh) * 2018-01-10 2019-07-16 广东欧珀移动通信有限公司 内存处理方法和装置、电子设备、计算机可读存储介质

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106980525A (zh) * 2017-04-25 2017-07-25 北京奇虎科技有限公司 应用启动方法、装置及移动终端
CN107357656B (zh) * 2017-06-27 2020-10-27 海南飞特同创科技有限公司 一种内存分配方法、移动终端以及计算机可读存储介质
US12217074B2 (en) * 2020-10-28 2025-02-04 International Business Machines Corporation Selective injection of GC safepoints for JNI invocations

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2012032896A (ja) * 2010-07-29 2012-02-16 Fujitsu Frontech Ltd 情報処理装置、メモリ容量制御方法及びメモリ容量制御プログラム
CN103544055A (zh) * 2013-10-22 2014-01-29 深圳Tcl新技术有限公司 资源需求数据的收集方法、应用程序的稳定运行方法及系统
CN103617060A (zh) * 2013-12-05 2014-03-05 积成电子股份有限公司 使用超级状态存储加快嵌入式软件启动过程的方法
CN103927264A (zh) * 2014-05-12 2014-07-16 中国航空无线电电子研究所 一种机载数字地图软件地图数据运行内存空间的分配方法

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101593152B (zh) * 2009-06-25 2011-07-27 青岛海信移动通信技术股份有限公司 一种移动终端内存泄漏检测方法及装置
US8799615B2 (en) * 2010-10-21 2014-08-05 International Business Machines Corporation Organization of a small object area and a large object area in a java heap
CN102760080B (zh) * 2011-04-26 2016-08-03 腾讯科技(深圳)有限公司 一种内存管理的方法和装置
CN103905450B (zh) * 2014-04-03 2017-05-31 国网河南省电力公司电力科学研究院 智能电网嵌入式设备网络检测评估系统与检测评估方法

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2012032896A (ja) * 2010-07-29 2012-02-16 Fujitsu Frontech Ltd 情報処理装置、メモリ容量制御方法及びメモリ容量制御プログラム
CN103544055A (zh) * 2013-10-22 2014-01-29 深圳Tcl新技术有限公司 资源需求数据的收集方法、应用程序的稳定运行方法及系统
CN103617060A (zh) * 2013-12-05 2014-03-05 积成电子股份有限公司 使用超级状态存储加快嵌入式软件启动过程的方法
CN103927264A (zh) * 2014-05-12 2014-07-16 中国航空无线电电子研究所 一种机载数字地图软件地图数据运行内存空间的分配方法

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110018902A (zh) * 2018-01-10 2019-07-16 广东欧珀移动通信有限公司 内存处理方法和装置、电子设备、计算机可读存储介质
CN110018900A (zh) * 2018-01-10 2019-07-16 广东欧珀移动通信有限公司 内存处理方法和装置、电子设备、计算机可读存储介质
CN110018900B (zh) * 2018-01-10 2023-01-24 Oppo广东移动通信有限公司 内存处理方法和装置、电子设备、计算机可读存储介质

Also Published As

Publication number Publication date
CN105988823B (zh) 2019-10-22
CN105988823A (zh) 2016-10-05

Similar Documents

Publication Publication Date Title
US10168917B2 (en) Hotness based data storage for facilitating garbage collection
JP6277827B2 (ja) 情報処理装置、スケール管理方法およびプログラム
US10037274B2 (en) Optimizing memory usage across multiple applications in the presence of garbage collection
WO2016119605A1 (zh) 终端中应用启动时的内存分配方法及其系统
US9652382B1 (en) Look-ahead garbage collection for NAND flash based storage
US7337201B1 (en) System and method to increase memory allocation efficiency
JP2014504768A (ja) 領域に基づくガベージ・コレクタを用いてクラスを漸進的にアンロードするための方法、コンピュータ・プログラム製品、および装置
CN111124304B (zh) 一种数据迁移方法、装置及电子设备和存储介质
US20260099444A1 (en) Data hierarchical storage
CN114063885A (zh) 用于管理存储空间的方法、设备和计算机程序产品
CN110325969A (zh) 多阶段垃圾收集器
CN110291508A (zh) 垃圾收集器
US8972629B2 (en) Low-contention update buffer queuing for large systems
US10324765B2 (en) Predicting capacity of shared virtual machine resources
US9870400B2 (en) Managed runtime cache analysis
US9696930B2 (en) Reducing new extent failures on target device during non-disruptive logical data set migration
US11294806B2 (en) Feedback-based selection of regions for abortable garbage collection
CN119166350A (zh) 一种显存管理方法、装置、设备及存储介质
HK1229483A (zh) 終端中應用啟動時的內存分配方法及其系統
HK1229483A1 (zh) 终端中应用启动时的内存分配方法及其系统
HK1229483B (zh) 终端中应用启动时的内存分配方法及其系统
KR100871185B1 (ko) 전용 캐시 메모리
CN115904616A (zh) 虚拟机热迁移方法、装置、设备及介质
CN107077420B (zh) 覆盖擦除块映射
CN112000471B (zh) 内存优化方法及装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 16742667

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 16742667

Country of ref document: EP

Kind code of ref document: A1