A memory expansion method and related equipment

By requesting a larger virtual address during zygote virtual machine creation and expanding the application's Java memory after startup, the memory leak and lag issues caused by Java memory limitations in the Android system are resolved. Memory expansion under specific conditions is achieved, ensuring system stability.

CN122309143APending Publication Date: 2026-06-30HONOR DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HONOR DEVICE CO LTD
Filing Date
2023-04-23
Publication Date
2026-06-30

AI Technical Summary

Technical Problem

In Android systems, Java memory for applications is limited, leading to memory leaks and delayed object release. This results in high application memory usage, insufficient available memory, triggering garbage collection, and causing severe lag and performance issues.

Method used

When creating the zygote virtual machine, a larger virtual address for memory is requested, and some memory is released before startup. After a cold start, the Java memory of the application is expanded according to the conditions, and memory expansion is achieved through spare virtual addresses.

Benefits of technology

Under certain conditions, the Java memory of the application can be expanded to avoid lag caused by insufficient memory, limit the number of applications that can be expanded, and ensure system stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122309143A_ABST
    Figure CN122309143A_ABST
Patent Text Reader

Abstract

This application discloses a memory expansion method and related device. According to this method, when creating a zygote virtual machine, the electronic device can allocate virtual addresses corresponding to larger memory in the Java memory space and reserve a portion of the virtual addresses unused. After a cold start of the application, the electronic device can monitor the memory of the Java memory space in the virtual machine corresponding to the application. Under certain conditions, the Java memory space in the virtual machine corresponding to the application can not only continue to use the original virtual addresses but also use the reserved virtual addresses, thereby expanding the Java memory of the application. Through this method, the electronic device can expand the Java memory space for specific applications and scenarios (e.g., excessive memory usage) while ensuring system stability, thus avoiding stuttering and other problems caused by garbage collection (GC) when memory usage is too high.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] This application is a divisional application. The original application was filed with the State Intellectual Property Office on April 23, 2023, with application number 202310462338.8 and application title "A Memory Expansion Method and Related Devices". The entire contents of the original application are incorporated herein by reference. Technical Field

[0002] This application relates to the field of terminal technology, and in particular to a memory expansion method and related equipment. Background Technology

[0003] Because excessive memory usage by applications can lead to system crashes or instability, and one application consuming a large amount of memory can cause other applications to malfunction, and because electronic devices have relatively limited hardware resources, operating systems limit application memory usage to ensure system stability, fair resource allocation, and to mitigate the limitations imposed by device hardware resources. For example, in the Android system, the maximum available Java memory for an application is 512 megabytes (MB). With this memory limitation, issues with the usage of interfaces or controls by different modules within the application, complex application business logic, and tight development cycles can lead to memory leaks. Furthermore, if the application uses a multi-threaded asynchronous framework, it may cause delayed release of certain objects. Both memory leaks and delayed object release can result in high application memory usage and insufficient available memory. Once the application's available Java memory is insufficient, it will trigger garbage collection (GC) for block types. In this situation, the application will pause other tasks, causing severe lag and serious performance issues.

[0004] Therefore, how to expand the available Java memory for applications while ensuring system stability is a problem that urgently needs to be solved. Summary of the Invention

[0005] This application provides a memory expansion method and related apparatus. According to this memory expansion method, an electronic device can request a spare virtual address during the creation of the Java memory space in the zygote virtual machine, so that other virtual machines subsequently hatched from the zygote virtual machine can expand their memory based on this spare virtual address.

[0006] Firstly, this application provides a memory expansion method. This memory expansion method can be applied to electronic devices. According to this method, the electronic device can receive a first instruction from a user to start the electronic device, and in response to the first instruction, the electronic device can create a zygote virtual machine. It is understood that the Java memory space in the zygote virtual machine created by the electronic device is a first Java memory space. The memory size of the first Java memory space is the first memory. The virtual addresses corresponding to the first Java memory space are a first virtual address segment and a second virtual address segment. The memory size corresponding to the first virtual address segment is the first memory, and the memory corresponding to the second virtual address segment is the spare virtual memory allocated by the zygote virtual machine. The sum of the memory size corresponding to the first virtual address segment and the memory size corresponding to the second virtual address segment is greater than the default memory of the first Java memory space. According to this method, the electronic device can receive a second instruction from a user to cold start a first application, and in response to the second instruction, the electronic device copies the zygote virtual machine to obtain a first application virtual machine. The Java memory space in the first application virtual machine is the second Java memory space. According to this method, under the condition of satisfying a first preset condition, the electronic device can adjust the memory size of the second Java memory space from the first memory to the second memory based on the second virtual address segment. The second memory is the memory size corresponding to the third virtual address segment. The third virtual address segment includes the first virtual address segment, and some or all of the addresses in the second virtual address segment. The second memory is larger than the first memory.

[0007] According to the solution provided in this application, an electronic device can request spare virtual addresses during the creation of the Java memory space in the zygote virtual machine. This allows the virtual machine corresponding to the application to expand its memory based on these spare virtual addresses after the zygote virtual machine has been incubated. Specifically, during the creation of the zygote virtual machine, the memory size corresponding to the virtual addresses requested in the Java memory space of the zygote virtual machine is larger than the default memory of that Java memory space. Furthermore, the virtual addresses actually used in the created zygote virtual machine's Java memory space are only a portion of the requested virtual addresses, while the remaining portion is unused. This unused portion of virtual addresses can be used as spare virtual addresses. The Java memory space in the zygote virtual machine can record this unused portion of virtual addresses. After the application in the electronic device (e.g., the first application) undergoes a cold boot, the electronic device can copy the zygote virtual machine to obtain the virtual machine corresponding to the application (e.g., the first application virtual machine). The initial memory layout of the application's virtual machine is completely identical to that of the zygote virtual machine. Therefore, the virtual addresses actually used by the Java memory space in the application's virtual machine are only a portion of the requested virtual addresses, and the Java memory space in the application's virtual machine records another portion of the requested virtual addresses that are not used. Thus, under certain conditions (e.g., when the first preset condition is met), the Java memory space in the application's virtual machine can use the requested unused virtual addresses, increasing its size. Furthermore, since the memory size corresponding to the requested virtual addresses is larger than the default memory of the zygote virtual machine's Java memory space, using the requested unused virtual addresses allows the Java memory space in the application's virtual machine to be larger than the default memory of the zygote virtual machine's Java memory space.

[0008] Understandably, during the creation of the zygote virtual machine by the electronic device, the device can request a first virtual address segment and a second virtual address segment for the first Java memory space. After the electronic device completes the creation of the zygote virtual machine, the virtual address segment actually used by the first Java memory space is the first virtual address segment, while the second virtual address segment is not used. That is, the memory size of the first Java memory space in the created zygote virtual machine is the memory size corresponding to the first virtual address segment. The second virtual address segment can serve as a spare virtual address segment within the zygote virtual machine. Subsequently, the Java memory space in other virtual machines spawned by the zygote virtual machine can use the second virtual address segment. This means that the maximum expandable memory size of this Java memory space is the memory size corresponding to the second virtual address segment.

[0009] As described above, electronic devices can adjust the size of the second Java memory space from the first memory to the second memory. Specifically, when using the first virtual address segment, the second Java memory space can use all or part of the addresses in the second virtual address segment (i.e., the second Java memory space can switch from using the first virtual address segment to using the third virtual address segment). This means that after using all or part of the addresses in the second virtual address segment, the size of the second Java memory space can be expanded from the first memory to the second memory.

[0010] It can be understood that the zygote virtual machine is the virtual machine instance corresponding to the zygote process. The first application virtual machine is the virtual machine instance corresponding to the process of the first application. It can be understood that the process of an electronic device copying the zygote virtual machine to obtain the first application virtual machine is the process of the zygote virtual machine forking to obtain the first application virtual machine. It can be understood that the size of the Java memory space is the Java memory size.

[0011] In some embodiments of this application, the first instruction may be the instruction in step 101 (such as...). Figure 6 As shown), it can be the instruction in step 1010 (such as...). Figure 7 As shown), it can also be an instruction in S1 (such as...). Figure 8A (As shown).

[0012] In some embodiments of this application, the second instruction may be the instruction in step 103 (such as...). Figure 6 As shown), it can be the instruction in step 1040 (such as...). Figure 7 As shown), it can also be an instruction in S4 (such as... Figure 8B (As shown).

[0013] In some embodiments of this application, the first Java memory space can be RegionSpace_1. The first memory can be memory_2. The default memory of the first Java memory space can be the default memory corresponding to RegionSpace_1. In this case, the memory size of RegionSpace_1 in the created zygote virtual machine is memory_2.

[0014] In some embodiments of this application, the first application can be application_1. The first application virtual machine can be application_1 virtual machine. The second Java memory space can be RegionSpace_2. The second memory can be memory_3.

[0015] In some embodiments of this application, the first virtual address range is 75d80000-b5d80000 (inclusive of b5d80000), and the second virtual address range is b5d80000-d5d80000 (excluding b5d80000).

[0016] In some embodiments of this application, the virtual address corresponding to the Java memory space can be understood as a virtual address segment corresponding to the Java memory space, and the memory size corresponding to this virtual address segment is related to the memory size of the Java memory space. In this application, the virtual address segment corresponding to the Java memory space can be understood as a virtual address segment that the Java memory space can use. When the virtual address segment corresponding to the Java memory space is the virtual address currently used by the Java memory space, the memory size corresponding to this virtual address segment is the current memory size of the Java memory space. Only when the virtual address segment corresponding to the Java memory space is not entirely composed of the virtual addresses currently used by the Java memory space does the memory size corresponding to the currently used virtual address segment equal the current memory size of the Java memory space.

[0017] In conjunction with the first aspect, in one possible implementation, after the electronic device obtains the first application virtual machine, the method may further include: if the first preset condition is not met, the memory size corresponding to the second Java memory space is the first memory.

[0018] According to the solution provided in this application, after an electronic device cold-starts an application (e.g., the first application) and obtains the virtual machine corresponding to the application, under certain conditions (e.g., when the first preset condition is met), the Java memory space in the virtual machine corresponding to the application can use the previously allocated spare virtual address, thereby expanding the Java memory of the application. However, if the above conditions are not met, the virtual machine corresponding to the application may not use the previously allocated spare virtual address, thus keeping the memory size of the Java memory space in the virtual machine unchanged. Through this method, the electronic device can only expand the Java memory of an application under specific circumstances. This means that not every application's Java memory can be expanded. This avoids the situation where the conditions for expanding Java memory are easily met, leading to an excessive number of applications expanding Java memory, and thus avoids excessive system memory usage caused by an excessive number of applications expanding Java memory, thereby preventing poor system stability due to excessive system memory usage.

[0019] It should be noted that in some embodiments of this application, if the first preset condition is not met, the electronic device can adjust the application's memory for specific situations, and may not necessarily maintain the memory size corresponding to the second Java memory space as the first memory. It is understood that this specific situation may be related to the application_1, the occupied memory of the Java memory space in the application_1 virtual machine, and the unoccupied memory of the electronic device's operating system. For details, please refer to the descriptions of the first and second preset conditions below, which will not be elaborated here. For example, if the first preset condition is not met, and application_1 is a type A application, the electronic device can adjust the memory size of the Java memory space in the application_1 virtual machine from memory_1 to memory_A; if application_1 is a type B application, the electronic device can adjust the memory size of the Java memory space in the application_1 virtual machine from memory_1 to memory_B; if application_1 is a type C application, the electronic device can keep the memory size of the Java memory space in the application_1 virtual machine unchanged. Memory_A and memory_B may be different.

[0020] In conjunction with the first aspect, in one possible implementation, the sum of the memory size corresponding to the first virtual address segment and the memory size corresponding to the second virtual address segment constitutes the third memory. During the creation of the zygote virtual machine, the electronic device can create a first Java memory space, the initial memory size of which is the third memory. Furthermore, once the memory space layout within the zygote virtual machine is complete, the electronic device can release a portion of the memory in the first Java memory space. The memory in the released first Java memory space is then called the first memory.

[0021] According to the scheme provided in this application, during the initial creation of the zygote virtual machine, the electronic device can request a larger virtual address space, thereby creating a larger Java memory space. It is understood that "larger" here refers to a size relative to the default Java memory space. After creating the larger Java memory space, the electronic device can release a portion of the memory, retaining only the virtual address space corresponding to this released memory. For other virtual machines hatched from the zygote virtual machine, their initial Java memory size is the size of the Java memory space after memory release, but a spare virtual address space is reserved for memory expansion. This approach makes it difficult for most applications to implement Java memory expansion, but it allows for Java memory expansion for specific applications while ensuring system stability.

[0022] In some embodiments of this application, the third memory may be memory_1.

[0023] In conjunction with the first aspect, in one possible implementation, satisfying the first preset condition may specifically include: the second Java memory space in the electronic device satisfies the first memory condition, and the first application in the electronic device is the first preset application. Specifically, satisfying the first memory condition in the second Java memory space includes: the occupied memory in the second Java memory space reaching a first threshold, and / or the growth rate of the occupied memory in the second Java memory space exceeding a second threshold.

[0024] According to the solution provided in this application, electronic devices can only expand the Java memory of an application when the application's Java memory space meets certain conditions, and the application itself meets certain conditions. This method ensures that Java memory expansion can only be implemented for specific applications in specific scenarios. This satisfies the application's memory expansion needs, thus avoiding stuttering and other problems caused by garbage collection (GC) due to insufficient memory, while also limiting the number of applications that can expand their memory, thereby ensuring system stability to a certain extent.

[0025] In some embodiments of this application, "the second Java memory space satisfies the first memory condition" has the same meaning as "RegionSpace_2 memory satisfies condition_1" in the following text.

[0026] In some embodiments of this application, the first threshold can be threshold_1. The first threshold can also be threshold_2. The second threshold can be e%.

[0027] In some embodiments of this application, the first preset application may be preset application_1.

[0028] Understandably, in another possible implementation, the second Java memory space satisfies the first memory condition, specifically including: the occupied memory in the second Java memory space exceeds the first threshold within a certain period of time, and / or the growth rate of the occupied memory in the second Java memory space is greater than the second threshold.

[0029] In conjunction with the first aspect, in one possible implementation, after the electronic device obtains the first application virtual machine, the method may further include: the electronic device monitoring the second Java memory space and determining whether the second Java memory space meets the first memory condition.

[0030] In conjunction with the first aspect, in one possible implementation, satisfying the first preset condition can specifically include: the second Java memory space in the electronic device satisfies the first memory condition, the first application in the electronic device is the first preset application, and the unused memory of the operating system of the electronic device is greater than a third threshold. Specifically, satisfying the first memory condition in the second Java memory space can include: the occupied memory in the second Java memory space reaching the first threshold, and / or the growth rate of the occupied memory in the second Java memory space being greater than the second threshold.

[0031] According to the solution provided in this application, an electronic device can only expand the Java memory of an application when the application's Java memory space meets certain conditions, the application meets certain conditions, and the electronic device's system memory meets certain conditions. This method allows for the expansion of Java memory only for specific applications in specific scenarios, thus fulfilling the application's memory expansion needs and avoiding issues like stuttering caused by garbage collection (GC) due to insufficient memory. It also limits the number of applications that can expand their memory, thereby ensuring system stability to a certain extent.

[0032] In some embodiments of this application, the third threshold may be threshold_3.

[0033] It is understood that the first threshold, the second threshold, and the third threshold can be set according to actual needs, and this application does not impose any restrictions on this.

[0034] In conjunction with the first aspect, in one possible implementation, the electronic device creates a first Java memory space, which specifically includes: the electronic device determining the initial memory size of the first Java memory space to be a third memory; for the first Java memory space, the electronic device may request a first virtual address segment and a second virtual address segment, and map the first virtual address segment and the second virtual address segment to physical addresses. The electronic device releases a portion of the memory in the first Java memory space, which specifically includes: the electronic device may unmap the second virtual address segment to a physical address. Based on the second virtual address segment, the electronic device adjusts the memory size of the second Java memory space from the first memory to the second memory, which specifically includes: the electronic device maintaining the mapping from the first virtual address segment to the physical address, and mapping some or all of the addresses in the second virtual address segment to physical addresses.

[0035] According to the scheme provided in this application, Java memory space uses virtual addresses, specifically meaning that Java memory space maps virtual addresses to physical addresses. That is, Java memory space establishes a mapping relationship between virtual addresses and physical addresses. Conversely, Java memory space does not use virtual addresses, specifically meaning that Java memory space does not map virtual addresses to physical addresses. That is, Java memory space does not establish a mapping relationship between virtual addresses and physical addresses.

[0036] In conjunction with the first aspect, in one possible implementation, the electronic device requests a first virtual address segment and a second virtual address segment, and maps the first and second virtual address segments to physical addresses. Specifically, this may include: the electronic device requesting an anonymous page corresponding to third memory. The anonymous page corresponding to the third memory includes the first and second virtual address segments. The anonymous page is used to represent a segment of virtual addresses in the process's virtual address space that has a mapping relationship with physical addresses.

[0037] In some embodiments of this application, for electronic devices operating on the Android system, when the electronic device creates the zygote virtual machine, it can request corresponding anonymous pages, thereby realizing the creation of Java memory space of the corresponding memory size.

[0038] In conjunction with the first aspect, in one possible implementation, the first memory is the default memory of the first Java memory space.

[0039] In some embodiments of this application, during the creation of the zygote virtual machine, after the Java memory space in the zygote virtual machine is released, the memory size of the Java memory space in the zygote virtual machine becomes the default memory.

[0040] In conjunction with the first aspect, in one possible implementation, the second memory is greater than the default memory of the first Java memory space.

[0041] It is understandable that if the Java memory space in the zygote virtual machine is created with the default memory size, the application virtual machine cannot subsequently expand the Java memory and can only use the default memory. In some embodiments of this application, the memory size of the application virtual machine after expanding the memory based on alternative virtual addresses can be larger than the default memory of the zygote virtual machine's Java memory space. This means that, compared to the default memory, the application virtual machine has achieved an expansion of Java memory.

[0042] In conjunction with the first aspect, in one possible implementation, after the electronic device adjusts the size of the second Java memory space from the first memory to the second memory, the method may further include: under a second preset condition, the electronic device may adjust the size of the second Java memory space from the second memory to the fourth memory. The sum of the memory size corresponding to the first virtual address segment and the memory size corresponding to the second virtual address segment is greater than the fourth memory.

[0043] According to the solution provided in this application, in one possible implementation, the second memory is smaller than the third memory. This means that the Java memory in the application virtual machine can still be expanded, from the second memory to the fourth memory. In another possible implementation, regardless of whether the second memory is smaller than or equal to the third memory, the Java memory in the application virtual machine can be reduced. In summary, when the second virtual address space is not fully utilized, if the application virtual machine needs more memory, it can continue to expand; if the application virtual machine no longer needs such a large amount of memory, it can reduce its memory size. In this way, electronic devices can flexibly adjust the Java memory of applications for different scenarios.

[0044] It should be noted that, provided that the Java memory space used in other virtual machines incubated by the zygote virtual machine does not exceed the third memory, this application does not impose any restrictions on the number of times the memory of these other virtual machines can be expanded / shrunken, nor on the size of each expansion / shrunken memory.

[0045] In some embodiments of this application, the fourth memory is larger than the second memory. That is, the second Java memory space expands again. In still other embodiments of this application, the fourth memory is smaller than the second memory. That is, the second Java memory space shrinks.

[0046] In some embodiments of this application, the fourth memory is greater than the first memory. In some embodiments of this application, the fourth memory is equal to the first memory. In some embodiments of this application, the fourth memory is less than the first memory.

[0047] In conjunction with the first aspect, in one possible implementation, the second preset condition is satisfied, which may specifically include: the occupied memory of the second Java memory space is less than the fourth threshold, and the growth rate of the occupied memory of the second Java memory space is less than the fifth threshold.

[0048] According to the solution provided in this application, the second Java memory space can be reduced under certain conditions. In this way, electronic devices can flexibly adjust the Java memory allocated to applications for different scenarios.

[0049] In some embodiments of this application, the fourth threshold can be threshold _8. The fifth threshold can be s%.

[0050] In conjunction with the first aspect, in one possible implementation, satisfying the second preset condition may further include: the unused memory of the electronic device's operating system is less than the sixth threshold.

[0051] In some embodiments of this application, the sixth threshold can be threshold_9.

[0052] It is understood that the fourth, fifth, and sixth thresholds can be set according to actual needs, and this application does not impose any restrictions on them.

[0053] In a second aspect, this application provides an electronic device comprising: one or more memories and one or more processors; the one or more memories being coupled to the one or more processors, the memories being used to store computer program code including computer instructions, the one or more processors calling the computer instructions to cause the electronic device to perform the method as described in the first aspect or any implementation thereof.

[0054] Thirdly, this application provides a computer storage medium. The computer storage medium includes computer instructions that, when executed on an electronic device, cause the electronic device to perform the method described in the first aspect or any implementation thereof.

[0055] Fourthly, embodiments of this application provide a chip. This chip can be applied to an electronic device, and the chip includes one or more processors. The processors are used to invoke computer instructions to cause the electronic device to perform the methods described in the first aspect or any implementation thereof.

[0056] Fifthly, embodiments of this application provide a computer program product containing instructions. When the computer program product is run on an electronic device, it causes the electronic device to perform the method described in the first aspect or any implementation thereof.

[0057] It is understood that the electronic device provided in the second aspect, the computer storage medium provided in the third aspect, the chip provided in the fourth aspect, and the computer program product provided in the fifth aspect are all used to execute the method described in the first aspect or any implementation thereof. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects of any possible implementation of the first aspect, which will not be repeated here. Attached Figure Description

[0058] Figure 1 A schematic diagram of the software structure of an electronic device provided in an embodiment of this application; Figure 2A and Figure 2B A schematic diagram of a virtual machine provided in an embodiment of this application; Figure 3 A schematic diagram of a runtime data area provided in an embodiment of this application; Figure 4 A schematic diagram of a zygote virtual machine provided in an embodiment of this application; Figure 5 A schematic diagram illustrating the principle of a zygote virtual machine incubating other application process virtual machines, provided in an embodiment of this application; Figure 6 A flowchart illustrating a memory expansion method provided in an embodiment of this application; Figure 7 A flowchart illustrating yet another memory expansion method provided in this application embodiment; Figure 8A and Figure 8B A flowchart illustrating yet another set of memory expansion methods provided in the embodiments of this application; Figure 9 A schematic diagram illustrating the changes in RegionSpace memory provided in an embodiment of this application; Figure 10 Another schematic diagram of RegionSpace memory changes provided in the embodiments of this application; Figure 11 This application provides a schematic diagram illustrating the change of the virtual address corresponding to the RegionSpace memory in an embodiment of the present application. Figure 12 This is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0059] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. In the description of the embodiments of this application, unless otherwise stated, " / " means "or," for example, A / B can mean A or B; "and / or" in the text is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Furthermore, in the description of the embodiments of this application, "multiple" refers to two or more than two.

[0060] It should be understood that the terms "first," "second," etc., in the specification, claims, and drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or apparatuses.

[0061] In this application, the reference to "embodiment" means that a specific feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a mutually exclusive, independent, or alternative embodiment. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described in this application can be combined with other embodiments.

[0062] During the use of electronic devices such as mobile phones and computers, the Java memory available to applications on these devices is limited. For example, for electronic devices using the Android system, the maximum available Java memory for applications is limited (for example, the default value for this maximum Java memory is 512MB). Java memory refers to the memory allocated to Java objects. The reason why the Java memory available to applications is limited is that excessive memory usage by applications can cause system crashes or instability. The system needs to limit the memory usage of applications to ensure system stability. Furthermore, by limiting the memory available to each application, the system can prevent some applications from consuming excessive memory and causing other applications to malfunction. Additionally, electronic devices have relatively limited hardware resources, necessitating the system to limit application memory to ensure that all applications can run normally on the device.

[0063] However, when an application's memory is limited, it may frequently experience insufficient available memory. For example, issues with the usage of APIs or controls by different modules, or complex application logic and tight development cycles, can lead to memory leaks. A memory leak refers to dynamically allocated heap memory that is not released or cannot be released for some reason. In memory-constrained situations, memory leaks can further lead to high memory usage and insufficient available memory. Another example is the use of multithreaded asynchronous frameworks in some applications, which may cause delayed release of certain objects. In memory-constrained situations, delayed release of certain objects can also lead to high memory usage and insufficient available memory. Once the application's available memory is insufficient, it will trigger a Block-type garbage collection (GC), resulting in severe stuttering and serious performance issues.

[0064] As you can understand, a Block-type GC refers to the following: when an application is short of memory but needs to allocate memory, the threads in the application that need to allocate memory will pause running and wait for the GC to finish before they can continue running.

[0065] This application provides a memory expansion method and related device. According to this method, when creating a zygote virtual machine, the electronic device can request a larger virtual address corresponding to the Java memory space, thereby expanding the Java memory space. Before the zygote virtual machine starts, a portion of the requested Java memory space is released. After a cold start of the application, the electronic device can monitor the memory of the Java memory space in the virtual machine corresponding to the application and, under certain conditions, adjust the memory of that Java memory space to a larger amount based on the previously requested virtual address corresponding to the larger memory. It is understood that Java memory space refers to the memory space provided for Java objects. Through this method, the electronic device can expand the Java memory space for specific applications and scenarios (e.g., high memory usage) while ensuring system stability, thereby avoiding problems such as stuttering caused by garbage collection (GC) when memory usage is too high.

[0066] The software structure of the electronic device involved in this application will be introduced first below.

[0067] Please see Figure 1 , Figure 1 This is a schematic diagram of the software structure of an electronic device provided in an embodiment of this application.

[0068] like Figure 1As shown, the software framework of the electronic device involved in this application may include an application layer, an application framework layer (FWK), a system library, a runtime, a hardware abstraction layer (HAL), and a kernel layer.

[0069] The application layer can include a series of application packages. For example, applications such as Application_1, Calendar, Gallery, Call, Bluetooth, Video, Music, SMS, and WLAN (which can also be simply referred to as applications). Application_1 can be a system application or a third-party application; this application does not limit this. For example, Application_1 can be a short video application, a live streaming application, or a news application.

[0070] The application framework layer provides an Application Programming Interface (API) and programming framework for applications within the application layer. The application framework layer includes predefined functions. It may also include a series of system services. System services are modular components focused on specific functionalities. The functionality provided by the application framework API allows communication with system services to access the underlying hardware. The application framework layer may include window managers, content providers, view systems, phone managers, resource managers, and notification managers, among others. For a detailed explanation of their specific meanings, please refer to relevant technical documentation; further details are omitted here.

[0071] The application framework layer may further include a kill module and a task stack recovery module. The kill module can be used to release memory already occupied by the application. In some embodiments of this application, the kill module can register application background exit events. This allows the kill module to monitor whether the application has exited to the background. Once the kill module detects that the application has exited to the background, it can release the memory already occupied by the application. It is understood that the kill module can also monitor other imperceptible scenarios besides the application exiting to the background, and this application does not limit this. For example, these other imperceptible scenarios may include: the electronic device not sensing any user operation on the application for a period of time (e.g., 5 minutes). The task stack recovery module can be used to restore the interface displayed by the application before it was killed. It is understood that the task stack recovery module can restore the interface displayed by the application before it was killed to the background. That is, the process of restoring the corresponding interface of the application can be imperceptible to the user. In some embodiments of this application, the task stack recovery module can determine whether to restart and restore the corresponding interface of the killed application based on priority decisions. It is understood that this priority refers to the priority of the killed application. In some embodiments of this application, if the detected application has a high priority, the task stack recovery module can restart and restore the corresponding interface of that application. It is understood that the rules for setting priority can be found in relevant technical documents and will not be elaborated upon here.

[0072] The runtime is responsible for system scheduling and management. The runtime includes the core libraries and the virtual machine. The core libraries consist of two parts: one part contains the functionalities that the programming language (e.g., Java) needs to call, and the other part is the system's core libraries. The application layer and application framework layer run in the virtual machine. The virtual machine executes the programming files (e.g., Java files) of the application layer and application framework layer as binary files. The virtual machine is used to perform functions such as object lifecycle management, stack management, thread management, security and exception management, and garbage collection.

[0073] It is understood that applications run in a virtual machine (e.g., the Dalvik / ART virtual machine). Each application can correspond to one virtual machine instance. For example, the virtual machine instance corresponding to application_1 is the application_1 virtual machine. It is understood that the Dalvik virtual machine is the Android virtual machine used in Android versions prior to 5.0, while the ART virtual machine is the Android virtual machine fully used in Android version 5.0.

[0074] In some embodiments of this application, each process may correspond to one virtual machine instance. For example, the zygote process corresponds to the zygote virtual machine. zygote (the incubator) is a very important daemon service in Android. All other virtual machine processes are forked from zygote. Android applications are written in Java and run in their own independent virtual machines. If each application needed to run and initialize a virtual machine separately at startup, it would significantly reduce system performance. Therefore, Android first creates a zygote virtual machine, and then uses it to fork other virtual machine processes, thereby sharing virtual machine memory and framework layer resources, which greatly improves the startup and running speed of applications.

[0075] As you can understand, the specific descriptions of the _1 virtual machine and the zygote virtual machine can be found below, and will not be elaborated here.

[0076] The runtime can also include a process management module. This module can be used to manage processes. For example, it can create virtual machine instances corresponding to the zygote process (i.e., the zygote virtual machine) and virtual machine instances corresponding to applications (e.g., application_1 virtual machine).

[0077] System libraries can include multiple functional modules. Examples include a Surface Manager, Media Libraries, 3D graphics processing libraries (e.g., OpenGL ES), and 2D graphics engines (e.g., SGL). The specific meanings and functions of these modules can be found in relevant technical documentation and will not be elaborated upon here.

[0078] The Hardware Abstraction Layer (HAL) is an interface layer located between the operating system kernel and upper-level software, its purpose being to abstract hardware. The HAL is an abstract interface for device kernel drivers, providing application programming interfaces (APIs) for accessing the underlying device to higher-level Java API frameworks. The HAL can provide a standard interface to display device hardware functionality to higher-level Java API frameworks. The HAL contains multiple library modules, such as the Camera HAL and Audio HAL. Each library module implements an interface for a specific type of hardware component. When the system framework layer API requires access to the portable device's hardware, the operating system loads the library module for that hardware component.

[0079] The kernel layer is the foundation of the Android operating system. It is responsible for hardware drivers, networking, power, system security, and memory management. The kernel layer acts as an intermediary between hardware and software, relaying application requests to the hardware. It can include camera drivers, display drivers, webcam drivers, audio drivers, and sensor drivers.

[0080] It should be noted that the application provides Figure 1 The illustrated software architecture diagram of the electronic device is merely an example and does not limit the specific module divisions within different layers of the Android operating system. For details, please refer to the descriptions of the Android operating system software architecture in conventional technologies. Furthermore, the memory expansion method provided in this application can also be implemented based on other operating systems, which will not be listed here.

[0081] The following section provides a detailed introduction to virtual machines and their corresponding memory spaces.

[0082] Please see Figure 2A , Figure 2A This is a schematic diagram of a virtual machine provided in an embodiment of this application.

[0083] like Figure 2A As shown, a virtual machine can include a Runtime module, an address management module, and a runtime data area. The Runtime module manages the memory space within the virtual machine (e.g., the runtime data area). The address management module calls interfaces and / or functions to establish communication with the kernel layer, thereby creating virtual addresses and mapping them to physical addresses. In other words, the address management module implements a one-to-one mapping between physical addresses and a segment of virtual addresses in the process's virtual address space (i.e., virtual memory). The runtime data area stores class file metadata, objects and arrays, as well as method parameters and local variables. The runtime data area can include several spaces, each with a different function. For example, ... Figure 2A As shown, the runtime data area can include Java memory space. Java memory space refers to the memory space provided for use by Java objects. The memory corresponding to Java memory space is Java memory. This can be understood as... Figure 2BAs shown, for the Android operating system, the Java memory space can be a RegionSpace. Of course, for other operating systems, the Java memory space can be other modules, and this application does not limit this. RegionSpace manages memory by allocating 256 kilobytes (KB) regions (which can also be understood as memory blocks) on an average basis. That is, RegionSpace divides memory resources into fixed-size regions and then allocates memory from these regions. Furthermore, the size of a region is 256KB. It can be understood that the address management module can be used to implement the mapping relationship between the virtual addresses and physical addresses corresponding to the memory in the Java memory space (e.g., RegionSpace). It should be noted that the virtual address involved in this application can be understood as a virtual memory address, and the physical address can be understood as a physical memory address (i.e., RAM memory address). Virtual memory refers to a block of logical memory virtualized using disk space. Physical memory refers to the address space range that real physical memory (i.e., RAM memory) can represent.

[0084] As you can understand, RAM stands for Random Access Memory. Also known as main memory, RAM is internal storage that directly exchanges data with the Central Processing Unit (CPU). It can be read and written at any time (except during refresh) and is very fast, typically serving as temporary data storage for the operating system or other running programs. When RAM is working, information can be written to (stored) or read from (retrieved) at any specified address at any time.

[0085] It should be noted that the runtime data area can include not only Java memory space (e.g., RegionSpace), but also other spaces. For example, ... Figure 3 As shown, the runtime data area may include RegionSpace, LargeObjectSpace, ZygoteSpace, ImageSpace, and JIT code cache. The specific meanings and functions of these memory spaces can be found in relevant technical documentation and will not be elaborated upon here.

[0086] Understandably, the runtime data area can also manage other modules such as the stack and method area. The stack is a memory instruction area used to store basic data types, instruction code, and constants. The method area, similar to the runtime data area, is a shared memory area for all threads, used to store type information loaded by the virtual machine, constants, static variables, and cached code compiled by the just-in-time compiler.

[0087] It is understandable that memory allocated in the runtime data area is managed through the virtual machine's garbage collection (GC) mechanism. It is also understandable that a description of GC can be found above and in relevant technical documents, and will not be repeated here.

[0088] It is understood that the Runtime module may also include an execution engine, native library interfaces, native method libraries, and Java threads, and this application does not impose any restrictions on the specific structure of the Runtime module.

[0089] It is understood that the virtual machine mentioned in this application may be the Java Virtual Machine (JVM).

[0090] The following describes the zygote virtual machine and its incubation process.

[0091] Understandable, such as Figure 4 As shown, in this application, the Runtime module in the zygote virtual machine is denoted as Runtime module_1, the runtime data area in the zygote virtual machine is denoted as runtime data area_1, and the Java memory space in the zygote virtual machine is denoted as RegionSpace_1.

[0092] As is understandable, the zygote process can create application processes and System Server (system service) processes using fork. These application and System Server processes can then obtain a copy of a virtual machine instance from the zygote process. In other words, application and System Server processes can obtain virtual machine instances copied from the zygote process's virtual machine instance (i.e., the zygote virtual machine). In other words, electronic devices can obtain virtual machine instances corresponding to other processes by copying the zygote virtual machine.

[0093] For example, such as Figure 5As shown, the electronic device can fork the process corresponding to application_1 (referred to as application_1 process) through the zygote process. The virtual machine instance corresponding to application_1 process (i.e., application_1 virtual machine) can be copied / copied from the virtual machine instance corresponding to the zygote process (i.e., zygote virtual machine). That is to say, the application_1 virtual machine in the initial state (i.e., the newly created application_1 virtual machine) is the same as the zygote virtual machine. For ease of description, this application refers to the Runtime module in application_1 virtual machine as Runtime module_2, the runtime data area in application_1 virtual machine as runtime data area_2, and the Java memory space in application_1 virtual machine as RegionSpace_2. It can be understood that for the application_1 virtual machine in the initial state, Runtime module_2 and Runtime module_1 are the same, runtime data area_2 and runtime data area_1 are the same, and RegionSpace_2 and RegionSpace_1 are the same. In some embodiments of this application, after the application_1 virtual machine is created, application_1 can configure the application_1 virtual machine according to actual needs (e.g., change the memory space layout in application_1 virtual machine), and this application does not limit this. Understandably, the zygote process can also fork other application processes (e.g., the SMS process). The virtual machine instance corresponding to SMS (i.e., the SMS virtual machine) can be copied from the zygote virtual machine. Similarly, in the initial state, Runtime module_3 and Runtime module_1 in the SMS virtual machine are the same, runtime data area_3 and runtime data area_1 are the same, RegionSpace_3 and RegionSpace_1 are the same, and address management module_3 and address management module_1 in the SMS virtual machine are the same.

[0094] It is understandable that the zygote process can also fork other application processes and the System Server process, which will not be listed here.

[0095] It is understandable that in the Android operating system, the Java memory space in the zygote virtual machine can be a RegionSpace. However, in other operating systems, the Java memory space in the zygote virtual machine may not be a RegionSpace, but other modules. This application does not impose any restrictions on this.

[0096] The following describes a memory expansion method provided by an embodiment of this application.

[0097] Please see Figure 6 , Figure 6This is a flowchart illustrating a memory expansion method provided in an embodiment of this application. The method may include, but is not limited to, the following steps: 101: The electronic device receives a command to start the electronic device. In response to this command, the electronic device begins creating the zygote virtual machine. During the creation of the zygote virtual machine, the electronic device creates a Java memory space based on memory_1. Here, memory_1 is greater than the default memory of the Java memory space.

[0098] Users can start the electronic device by pressing and holding the power button, etc. Correspondingly, the electronic device receives the command to start and, in response, begins creating the zygote virtual machine. During the creation of the zygote virtual machine, the electronic device can allocate its memory space. In this process, the electronic device can create the Java memory space for the zygote virtual machine. Furthermore, the initial memory of the Java memory space within the zygote virtual machine created by the electronic device is memory_1. That is, when creating the Java memory space within the zygote virtual machine, the virtual address allocated by the electronic device corresponds to memory_1, and the electronic device establishes a mapping relationship between this virtual address and the physical address. It can be understood that memory_1 is greater than the default memory of the Java memory space (i.e., the default memory corresponding to the Java memory space).

[0099] 102: After the memory space layout in the zygote virtual machine is completed, the electronic device releases a portion of the Java memory space. The size of the Java memory space after the memory release is memory_2, which is less than memory_1.

[0100] During the creation of the zygote virtual machine, once the memory space (e.g., the runtime data area) within the zygote virtual machine is laid out, the electronic device can release a portion of the Java memory space within the created zygote virtual machine. The size of the released Java memory space within the zygote virtual machine is memory_2. It can be understood that memory_2 is less than memory_1. Specifically, the electronic device can unmap the virtual addresses allocated during the creation of the Java memory space from their physical addresses. Thus, since the memory space within the zygote virtual machine has been laid out, this portion of virtual addresses will not be occupied by other memory spaces, and the electronic device can subsequently expand the Java memory based on the previously allocated virtual addresses.

[0101] It is understandable that after the zygote virtual machine is created, the electronic device can start the zygote virtual machine. In some embodiments of this application, the electronic device can determine that the zygote virtual machine has been created after releasing the memory of the Java memory space in the zygote virtual machine. It should be noted that, since the electronic device releases the memory of the Java memory space in the zygote virtual machine, after the zygote virtual machine is created, the size of the Java memory space in the zygote virtual machine is memory_2, instead of the initial memory (i.e., memory_1) when the Java memory space was originally created.

[0102] In some embodiments of this application, memory_2 can be the default memory of the Java memory space in the zygote virtual machine. Of course, memory_2 can also be other values, and this application does not impose specific limitations on this.

[0103] 103: The electronic device receives the instruction to cold start application_1. In response to this instruction, the electronic device hatches the application_1 virtual machine based on the zygote virtual machine. The application_1 virtual machine is the virtual machine instance corresponding to the application_1 process, and the initial memory of the Java memory space in the application_1 virtual machine is memory_2.

[0104] Users can cold-start application_1 via touch, voice, or other methods. Correspondingly, the electronic device can receive the command to cold-start application_1, and in response, the electronic device can create a virtual machine for application_1 based on the zygote virtual machine. The virtual machine for application_1 refers to the virtual machine instance corresponding to the application_1 process. It can be understood that the initial memory space layout of the virtual machine for application_1 is consistent with the memory space layout in the created zygote virtual machine. That is, the initial memory of the Java memory space in the virtual machine for application_1 is memory_2.

[0105] As is understandable, when an application starts, there is no process for that application in the background of the electronic device. At this time, the system will create a new process and assign it to the application. This startup method is called a cold start (the application process does not exist in the background).

[0106] 104: Under the condition that the first preset condition is met, the electronic device will expand the memory of the Java memory space in the virtual machine _1 from memory _2 to memory _3. Among them, memory _3 is greater than memory _2, and memory _3 is not greater than memory _1.

[0107] Under the condition that the first preset condition is met, the electronic device can expand the Java memory space in the virtual machine of application_1. Specifically, the electronic device can expand the Java memory space in the virtual machine of application_1 from memory_2 to memory_3. It can be understood that memory_3 is no greater than memory_1, and memory_3 is greater than memory_2.

[0108] In some embodiments of this application, satisfying a first preset condition may specifically include: the occupied memory of the Java memory space in the application_1 virtual machine meets the corresponding condition.

[0109] In some embodiments of this application, the first preset condition is satisfied, which may specifically include: application_1 is a preset application_1.

[0110] In some embodiments of this application, the first preset condition is met, which may specifically include: the unused memory of the operating system of the electronic device meets the corresponding condition.

[0111] As described above, the first preset condition can be related to the memory already occupied in the Java memory space of the application_1 virtual machine. In this case, after the electronic device obtains the application_1 virtual machine based on the zygote virtual machine, it can monitor the memory usage of the Java memory space in the application_1 virtual machine and determine whether the first preset condition is met based on the monitored memory usage. It is understood that the memory usage can refer to the size of the occupied memory or the growth rate of the occupied memory; this application does not limit this.

[0112] In some embodiments of this application, the electronic device may check the occupied memory of the Java memory space in the application_1 virtual machine at regular intervals (e.g., 1 minute).

[0113] In some embodiments of this application, the electronic device can check the occupied memory of the Java memory space in the application_1 virtual machine once after each GC.

[0114] In some embodiments of this application, memory_3 may be equal to memory_1.

[0115] It should be noted that, in some embodiments of this application, after the electronic device executes step S8, the electronic device can expand / shrink the memory of the Java memory space in the application_1 virtual machine. Specifically, the electronic device can adjust the memory size of the Java memory space in the application_1 virtual machine from memory_3 to memory_4.

[0116] In some embodiments of this application, memory_3 is less than memory_1, and memory_3 is less than memory_4, and memory_4 is not greater than memory_1. In still other embodiments of this application, memory_3 is greater than memory_4.

[0117] In some embodiments of this application, the second preset condition is satisfied, which may specifically include: application_1 is a preset application_2.

[0118] In some embodiments of this application, the second preset condition is satisfied, which may specifically include: the occupied memory of the Java memory space in the application_1 virtual machine meets the corresponding condition.

[0119] In some embodiments of this application, the second preset condition is satisfied, which may specifically include: the unused memory of the operating system of the electronic device meets the corresponding condition.

[0120] It is understood that the relevant descriptions of the first and second preset conditions can be found in the following text, and will not be elaborated here.

[0121] The following example, using the Java memory space RegionSpace, memory_2 as the default memory of RegionSpace, and memory_3 equal to memory_1, further illustrates the memory expansion method provided in this application (e.g., Figure 7 , Figures 8A-8B (As shown).

[0122] Please see Figure 7 , Figure 7 A flowchart illustrating yet another memory expansion method provided in this application embodiment. This method may include, but is not limited to, the following steps: 1010: The electronic device has received a command to start the electronic device.

[0123] Understandably, users can trigger the startup of electronic devices by pressing and holding the power button, etc. Correspondingly, the electronic device can receive a startup command. This command is used to trigger the creation of the zygote virtual machine by the electronic device.

[0124] 1020: In response to the instruction received by the electronic device to start the electronic device, the electronic device begins to create the zygote virtual machine.

[0125] In response to the instruction to start the electronic device, the electronic device can begin creating the zygote virtual machine, and the zygote virtual machine can lay out its memory space, as detailed in the context below, which will not be elaborated here.

[0126] 1030: After the memory space layout in the zygote virtual machine is completed, the zygote virtual machine adjusts the memory size of RegionSpace_1 from the originally created memory_1 to the default memory of RegionSpace_1. Memory_1 is greater than the default memory of RegionSpace_1.

[0127] It is understandable that after the electronic device starts creating the zygote virtual machine, once the memory space layout within the zygote virtual machine is complete, the zygote virtual machine can adjust the memory size of RegionSpace_1 from the originally created memory_1 to the default memory of RegionSpace_1 (i.e., the default memory corresponding to RegionSpace_1).

[0128] It's understandable that the initial memory of RegionSpace_1 within the zygote virtual machine was memory_1, and anonymous pages corresponding to memory_1 were allocated. In other words, the initial memory of RegionSpace_1 was memory_1. Memory_1 is greater than the default memory of RegionSpace_1. Anonymous pages are used to represent a segment of virtual addresses in the process's virtual address space that has a mapping relationship with physical addresses.

[0129] Understandably, after the zygote virtual machine is created, the electronic device can start the zygote virtual machine. In some embodiments of this application, the zygote virtual machine completes its creation after adjusting the memory of RegionSpace_1 from the originally created memory to the default memory of RegionSpace_1. In this case, the electronic device can start the zygote virtual machine.

[0130] 1040: The electronic device has received the instruction from the cold start application_1.

[0131] Users can cold-start application_1 via touch, voice, or other means. Correspondingly, the electronic device can receive a command to cold-start application_1. This command is used to trigger the launch of application_1.

[0132] 1050: In response to the instruction received by the electronic device to cold start application_1, the electronic device hatches the application_1 virtual machine based on the zygote virtual machine. The application_1 virtual machine is the virtual machine instance corresponding to the application_1 process.

[0133] In response to the instruction to cold start application_1, the electronic device can begin launching application_1. Specifically, the electronic device can incubate the application_1 virtual machine based on the zygote virtual machine. The application_1 virtual machine is the virtual machine instance corresponding to the application_1 process.

[0134] It is understandable that since the application_1 virtual machine is incubated by the zygote virtual machine, the initial memory of RegionSpace_2 in the application_1 virtual machine is the adjusted memory of RegionSpace_1 in the zygote virtual machine, that is, the default memory of RegionSpace_1.

[0135] 1060: Application _1 virtual machine monitors the memory of RegionSpace_2.

[0136] Understandably, once the application_1 virtual machine is incubated, the memory of RegionSpace_2 can be monitored. For details, please refer to the context; further explanation is not provided here.

[0137] 1070: Under the condition that the first preset condition is met, the application _1 virtual machine expands the memory size of RegionSpace_2 from the default memory of RegionSpace_1 to memory_1.

[0138] Understandably, under the first preset condition, application_1 virtual machine can expand the memory of RegionSpace_2. Specifically, application_1 virtual machine can expand the memory size of RegionSpace_2 from the default memory of RegionSpace_1 to memory_1. Understandably, the specific implementation method of satisfying the first preset condition can be referred to the context and will not be explained in detail here.

[0139] It is understandable that the memory adjustment methods for RegionSpace_1 and RegionSpace_2 mentioned in steps 1030 and 1070 can be referred to the context and will not be explained in detail here.

[0140] It should be noted that if the first preset condition does not involve the memory of RegionSpace_2, the electronic device may not need to execute step 1060.

[0141] The following is combined with Figure 8A and Figure 8B The specific implementation of the above embodiments is explained.

[0142] 1. Start the electronic device, create and start the zygote virtual machine (e.g. Figure 8A (As shown) S1: The process management module receives the instruction to start the electronic device.

[0143] Understandably, electronic devices can detect user actions that initiate the device (e.g., pressing and holding the power button). Specifically, when a user presses and holds the power button, the process management module within the electronic device receives the instruction to start the device.

[0144] S2: The process management module creates the zygote virtual machine. The zygote virtual machine is the virtual machine instance corresponding to the zygote process. The zygote virtual machine includes the Runtime module_1, the address management module_1, and the runtime data area_1. The runtime data area_1 includes RegionSpace_1.

[0145] After receiving a command to start the electronic device, the process management module within the electronic device can create a zygote virtual machine in response to this command. Specifically, after receiving the command to start the electronic device, the process management module can create a zygote virtual machine. It can be understood that the zygote virtual machine is the virtual machine instance corresponding to the zygote process. The zygote virtual machine includes a Runtime module_1, an address management module_1, and a runtime data area_1. The runtime data area_1 includes RegionSpace_1. A detailed description of the zygote virtual machine can be found above and will not be elaborated upon here.

[0146] S3: The process management module starts the zygote virtual machine.

[0147] After an electronic device creates a zygote virtual machine, it can be started. Specifically, once the zygote virtual machine is created, the process management module can start it.

[0148] Specifically, when the electronic device performs step S2, it may perform the following steps: S201: Process Management Module Creates Runtime Module_1.

[0149] After receiving the instruction to start the electronic device, the process management module can begin creating the zygote virtual machine in response to that instruction. Specifically, the process management module can first create the Runtime module_1. A description of the Runtime module_1 can be found above and will not be elaborated upon here.

[0150] S202: Runtime module_1 Create runtime data area_1.

[0151] After the process management module creates the Runtime module_1, the Runtime module_1 can then create the runtime data area_1. A description of the runtime data area_1 can be found above and will not be elaborated upon here.

[0152] It is understandable that after the Runtime module_1 creates the runtime data area_1, the runtime data area_1 can be laid out in memory. That is, the electronic device can lay out the runtime data area_1. The specific implementation of the layout of the runtime data area_1 may include steps S203-S208.

[0153] S203: Runtime Data Area 1 determines that the memory size corresponding to RegionSpace 1 in Runtime Data Area 1 is Memory 1. Memory 1 is greater than the default memory corresponding to RegionSpace 1.

[0154] After the Runtime module_1 creates the Runtime Data Area_1, the Runtime Data Area_1 can determine the memory size corresponding to each Space within it. Specifically, the Runtime Data Area_1 can determine that the memory size corresponding to RegionSpace_1 is Memory_1. This can also be understood as the Runtime Data Area_1 determining that the initial memory size corresponding to RegionSpace_1 is Memory_1. Memory_1 is greater than the default memory corresponding to RegionSpace_1. RegionSpace_1 can be understood as a memory space within the Runtime Data Area_1; its detailed description can be found above.

[0155] Of course, runtime data area _1 can also determine the memory size of other Spaces (e.g., ImageSpace) in runtime data area _1. For specific implementation details, please refer to the relevant technical documents, which will not be elaborated here.

[0156] In some embodiments of this application, the runtime data area_1 can determine the memory size corresponding to each Space in the runtime data area_1 by reading a relevant configuration file. It is understood that the configuration file records the memory corresponding to each Space in the runtime data area_1. Thus, the runtime data area_1 can be laid out according to the memory corresponding to each Space recorded in the configuration file.

[0157] It is understandable that the configuration file can record the initial memory size of RegionSpace_1 as memory_1, and the default memory size of RegionSpace_1.

[0158] For example, memory_1 can be 768MB, and the default memory corresponding to RegionSpace_1 can be 512MB.

[0159] Of course, memory_1 can also be set to other values ​​greater than the default memory corresponding to RegionSpace_1, and this application does not impose any restrictions on this. In some embodiments of this application, memory_1 is not greater than a preset memory threshold. It is understood that the preset memory threshold can be set according to actual needs, and this application does not impose any restrictions on this. For example, the preset memory threshold can be 768MB.

[0160] S204: Runtime data area_1 creates RegionSpace_1 based on memory_1.

[0161] After the runtime data area_1 determines that the memory size corresponding to RegionSpace_1 is memory_1, it can allocate a memory space within the runtime data area_1 as RegionSpace_1. At this stage, RegionSpace_1 has not yet been created. In subsequent processes, the runtime data area_1 can control RegionSpace_1 to call the address management module_1 to request the virtual address corresponding to memory_1, establish the mapping between the virtual address and the physical address, and divide the region, thereby realizing the creation of RegionSpace_1.

[0162] S205: RegionSpace_1 calls address management module_1 to request the anonymous page corresponding to memory_1. An anonymous page is used to represent a segment of virtual addresses in the process's virtual address space that has a mapping relationship with physical addresses.

[0163] After the runtime data area_1 is divided into RegionSpace_1, RegionSpace_1 can call the address management module_1 to request the anonymous page corresponding to memory_1. In other words, RegionSpace_1 can use the address management module_1 to call relevant interfaces and / or relevant functions to request the virtual address corresponding to memory_1 and establish the mapping relationship between the virtual address and physical address of memory_1.

[0164] Understandably, the heap, stack, and data segment in a process's virtual address space are generally referred to as anonymous pages. Anonymous pages are pages without a file background; they do not exist as files and therefore cannot be exchanged with disk files.

[0165] In some embodiments of this application, RegionSpace_1 calls address management module_1 to request the anonymous page corresponding to memory_1. Specifically, RegionSpace_1 calls the mmap interface (or mmap function) in address management module_1 to request the anonymous page corresponding to memory_1. That is, RegionSpace_1 can use address management module_1 to call mmap to request the virtual address corresponding to memory_1 and establish a mapping relationship between the virtual address and physical address of memory_1. It can be understood that mmap refers to Memory Mapped. mmap can be used to map a file or other object into memory. In other words, mmap can specifically implement the mapping from virtual address to physical address (e.g., the mapping between the virtual address and physical address corresponding to memory_1).

[0166] S206: Address management module _1 returns information about the anonymous page corresponding to memory _1 to RegionSpace _1. The information about the anonymous page is the information about the virtual address corresponding to memory _1.

[0167] After RegionSpace_1 successfully requests the anonymous page corresponding to memory_1 from address management module_1, address management module_1 can return the relevant information of the anonymous page corresponding to memory_1 to RegionSpace_1. This information can include the starting address of the anonymous page (i.e., the starting address of the virtual address corresponding to memory_1) and the address range of the anonymous page (i.e., the virtual address corresponding to memory_1). In other words, after RegionSpace_1 requests the virtual address corresponding to memory_1 from address management module_1 and successfully establishes the mapping relationship between the virtual address and physical address of memory_1, address management module_1 can return the relevant information of the virtual address corresponding to memory_1 to RegionSpace_1. This virtual address can be understood as the virtual address corresponding to RegionSpace_1.

[0168] For example, the starting address of the anonymous page (i.e., the starting address of the virtual address corresponding to memory_1) can be 75d80000, and the address range of the anonymous page (i.e., the virtual address corresponding to memory_1) can be 75d80000-d5d80000.

[0169] S207: RegionSpace_1 divides the regions in RegionSpace_1 based on the relevant information of the anonymous page corresponding to memory_1.

[0170] After receiving the information about the anonymous page corresponding to memory_1 returned by address management module_1, RegionSpace_1 can divide the region into regions based on this information and determine the relevant region information. If the anonymous page information includes the starting address of the anonymous page, RegionSpace_1 can determine the virtual address corresponding to memory_1 based on the starting address of the anonymous page and memory_1, and divide the virtual address corresponding to memory_1 into address segments of 256KB each. Each 256KB address segment represents a region. Similarly, if the anonymous page information includes the address segment of the anonymous page, RegionSpace_1 can divide the anonymous page address segment into 256KB address segments. Again, each 256KB address segment represents a region.

[0171] S208: Runtime data area_1 obtains and records relevant information about the regions in RegionSpace_1 from RegionSpace_1.

[0172] After RegionSpace_1 divides the region, runtime data area_1 can obtain and record relevant information about the regions divided by RegionSpace_1. It is understood that the relevant information about a region may include the address range corresponding to the region, as well as the region's status and type. Of course, the relevant information about a region may also include other content (e.g., the type of stored objects within the region), and this application does not impose any restrictions on this.

[0173] S209: Runtime module_1 Determine runtime data area_1 Layout complete.

[0174] After the runtime data area_1 obtains and records the relevant information of the region in RegionSpace_1, the runtime module_1 can determine that the layout of the runtime data area_1 is complete.

[0175] S210: Runtime module_1 can release memory in memory_1 other than the default memory corresponding to RegionSpace_1.

[0176] Specifically, after the Runtime module_1 completes the layout of the runtime data area_1, for the memory_1 allocated by RegionSpace_1, the Runtime module_1 can retain only a portion of the memory and release the rest. The size of this portion of memory can be the same as the default memory size corresponding to RegionSpace_1. That is to say, as... Figure 9 As shown, after RegionSpace_1 allocates the virtual address corresponding to memory_1, the memory size of RegionSpace_1 is memory_1. After Runtime module_1 releases the memory in memory_1 excluding the default memory corresponding to RegionSpace_1, the memory size of RegionSpace_1 is the default memory corresponding to RegionSpace_1. It can be understood that after the memory in memory_1 excluding the default memory corresponding to RegionSpace_1 is released, RegionSpace_1 can no longer use the released memory.

[0177] It is worth noting that, because the virtual address corresponding to the freed memory has already been allocated during the layout process of the runtime data area (i.e., runtime data area_1) in the zygote virtual machine, other modules (except for RegionSpace_1) cannot allocate this virtual address. This means that other modules cannot use the memory corresponding to this virtual address.

[0178] It is understood that the memory release involved in this application specifically refers to breaking the mapping relationship between the virtual address and the physical address of the memory.

[0179] In other words, Runtime module_1 releases the memory in Memory_1 excluding the default memory corresponding to RegionSpace_1. Specifically, for the memory in Memory_1 excluding the default memory corresponding to RegionSpace_1, Runtime module_1 can unmap the virtual address to the physical address. It can be understood that after Runtime module_1 releases the memory in Memory_1 excluding the default memory corresponding to RegionSpace_1, the actual usable memory in RegionSpace_1 becomes the default memory corresponding to RegionSpace_1, not Memory_1 itself.

[0180] In some embodiments of this application, the Runtime module_1 can read relevant configuration files to determine the default memory corresponding to RegionSpace_1, and then release the memory in Memory_1 other than the default memory corresponding to RegionSpace_1. Specifically, the Runtime module_1 can call the runtime data area_1 to implement the above memory release. Furthermore, the runtime data area_1 can call RegionSpace_1 to implement the above memory release. Furthermore, RegionSpace_1 can call relevant interfaces and / or relevant functions (e.g., the munmap interface, or munmap function) in the address management module_1 to specifically implement the above memory release. It can be understood that munmap can be used to cancel the previously allocated mapped memory start address (i.e., the mapped memory start address pointed to by the parameter start).

[0181] For example, the virtual address range corresponding to memory_1 is 75d80000-d5d80000. Runtime module_1 can unmap the virtual addresses and physical addresses of a portion of the memory in memory_1, retaining only the memory in memory_1 with virtual addresses from 75d80000 to 5d80000 (inclusive). That is, Runtime module_1 can release the memory corresponding to b5d80000-d5d80000 (excluding b5d80000). It can be understood that the size of the memory with virtual addresses from 75d80000 to 5d80000 (inclusive) is the same as the default memory size corresponding to RegionSpace_1.

[0182] 2. Perform a cold start on application_1 and monitor the memory usage of application_1 (e.g., ...). Figure 8B (As shown) S4: The process management module received the instruction to start application_1.

[0183] Users can trigger a cold start for application_1. For example, a user can trigger a cold start for application_1 by clicking its application icon. Correspondingly, the process management module can receive the instruction to cold start application_1. For a clearer understanding of the meaning of cold start, please refer to the above text and related technical documents; further explanation is not provided here.

[0184] S5: The process management module incubates the Application_1 virtual machine based on the zygote virtual machine. The Application_1 virtual machine is the virtual machine instance corresponding to the Application_1 process. The Application_1 virtual machine inherits the space layout of the zygote virtual machine. The Application_1 virtual machine includes the Runtime module_2, the address management module_2, and the runtime data area_2. The runtime data area_2 includes RegionSpace_2.

[0185] Understandably, the process management module can fork the application_1 process through the zygote process. Specifically, the process management module can copy (i.e., duplicate) the virtual machine instance corresponding to the zygote process (i.e., the zygote virtual machine) as the virtual machine instance corresponding to the application_1 process (i.e., the application_1 virtual machine). Accordingly, the Runtime module_2, the address management module_2, and the runtime data area_2 in the application_1 virtual machine are created. Among them, the runtime data area_2 includes RegionSpace_2.

[0186] It is understandable that the application_1 virtual machine inherits the spatial layout of the zygote virtual machine. Specifically, this means that the spatial layout of the application_1 virtual machine, which is incubated based on the zygote virtual machine, is the same as the spatial layout of the zygote virtual machine. In other words, the application_1 virtual machine and the zygote virtual machine are the same in their initial state. The relevant description can be found above, and will not be elaborated here.

[0187] S6: Runtime module_2 notifies runtime data area_2 to start monitoring of RegionSpace_2 memory.

[0188] After the virtual machine fork in Application_1 is complete, the Runtime module_2 in Application_1 can notify the runtime data area_2 to start monitoring the memory of RegionSpace_2.

[0189] S7: Runtime data area_2 monitors the memory of RegionSpace_2.

[0190] After Runtime module_2 notifies runtime data area_2 to start monitoring RegionSpace_2's memory, runtime data area_2 can monitor the memory of RegionSpace_2. Specifically, runtime data area_2 can monitor the memory already occupied by RegionSpace_2.

[0191] In some embodiments of this application, the runtime data area_2 can check the occupied memory of RegionSpace_2 every certain period of time (e.g., 1 minute).

[0192] In some embodiments of this application, the runtime data area_2 can check the memory already occupied in RegionSpace_2 after each GC.

[0193] S8: Under the condition that the first preset condition is met, the runtime data area_2 controls the RegionSpace_2 to call the address management module to adjust the memory size of RegionSpace_2 from the default memory corresponding to RegionSpace_1 to memory_1.

[0194] Runtime data area_2 can monitor the memory of RegionSpace_2, and, under the first preset condition, runtime data area_2 controls RegionSpace_2 to call the address management module to adjust the memory size of RegionSpace_2 from the default memory corresponding to RegionSpace_1 to memory_1. In other words, runtime data area_2 can control RegionSpace_2 to call the address management module to re-establish the mapping relationship between the virtual address and physical address of the previously released memory (i.e., the memory in memory_1 excluding the default memory corresponding to RegionSpace_1). In this way, RegionSpace_2 can use the previously released memory, and the memory size of RegionSpace_2 can be changed from the default memory corresponding to RegionSpace_1 to memory_1 (e.g.,...). Figure 10 (As shown).

[0195] In some embodiments of this application, runtime data area_2 controls RegionSpace_2 to call the address management module to adjust the memory size of RegionSpace_2 from the default memory corresponding to RegionSpace_1 to memory_1. Specifically, RegionSpace_2 can call relevant interfaces and / or functions (e.g., the mremap interface, or mremap function) in the address management module to re-establish the mapping relationship between virtual addresses and physical addresses for the memory in memory_1 other than the default memory corresponding to RegionSpace_1, thereby adjusting the memory size of RegionSpace_2 from the default memory corresponding to RegionSpace_1 to memory_1. It can be understood that mremap can be used to expand existing memory mappings. The parameters involved in mremap can include the virtual addresses in the process virtual address space that were previously mapped to physical addresses, and the size of the remapped memory space.

[0196] For example, such as Figure 11As shown, the virtual address range for memory_1 is 75d80000-d5d80000. Runtime module_1 can de-map the virtual addresses and physical addresses of some memory locations in memory_1, retaining only the memory locations with virtual addresses between 75d80000-b5d80000 (inclusive). Thus, the virtual address range for RegionSpace_2 changes from 75d80000-d5d80000 to 75d80000-b5d80000 (inclusive). Meanwhile, runtime data area_2 can control RegionSpace_2 to call the address management module to change the virtual address range for RegionSpace_2 from 75d80000-b5d80000 (inclusive) to 75d80000-d5d80000. The memory allocated to RegionSpace_2 will be adjusted from the default memory allocated to RegionSpace_1 to memory_1. This means the size of the memory at virtual addresses 75d80000-b5d80000 (inclusive) will be the same as the default memory allocated to RegionSpace_1.

[0197] In some implementations of this application, the above-mentioned first preset condition is satisfied, which may specifically include any one or more of the following: the memory of RegionSpace_2 satisfies condition_1, and the application_1 satisfies condition_2, and the unused memory of the operating system of the electronic device satisfies condition_3.

[0198] In some embodiments of this application, the memory of RegionSpace_2 satisfies condition_1, which may specifically include: the occupied memory in RegionSpace_2 exceeds threshold_1.

[0199] In some embodiments of this application, the memory of RegionSpace_2 satisfies condition_1, which may specifically include: the occupied memory in RegionSpace_2 exceeds threshold_1 within a certain period of time. It is understood that this period of time can be set according to actual needs, and this application does not impose any restrictions on it. For example, this period of time can be 10 seconds.

[0200] In some embodiments of this application, the memory of RegionSpace_2 satisfies condition_1, which may specifically include: the occupied memory in RegionSpace_2 after m consecutive GC cycles all exceed the threshold_1.

[0201] It is understood that the threshold_1 can be set according to actual needs, and this application does not impose any restrictions on it. For example, the threshold_1 can be 460MB. In some embodiments of this application, the threshold_1 can be less than or equal to a preset memory threshold. In some embodiments of this application, the threshold_1 can be f% of the preset memory threshold. It is understood that f can be set according to actual needs, and this application does not impose any restrictions on it. For example, f can be 80.

[0202] It is understood that m is a positive integer, and the specific value of m can be set according to actual needs; this application does not impose any restrictions on it. For example, m can be 3. Another example is that m can be 5.

[0203] In some embodiments of this application, the memory of RegionSpace_2 satisfies condition_1, which may specifically include: the growth rate of the occupied memory in RegionSpace_2 exceeds e%. It is understood that e can be set according to actual needs, and this application does not impose any restrictions on it. For example, e can be 60.

[0204] In some embodiments of this application, the memory of RegionSpace_2 satisfies condition_1, which may specifically include: the growth rate of the occupied memory in RegionSpace_2 exceeds e%, and the occupied memory in RegionSpace_2 exceeds threshold_2. It is understood that threshold_2 can be set according to actual needs, and this application does not impose any restrictions on it. In some embodiments of this application, threshold_2 may be less than threshold_1.

[0205] In some embodiments of this application, application_1 satisfies condition_2, specifically including: application_1 is a preset application_1. In one possible implementation, application_1 being a preset application_1 specifically includes: application_1 being an application in the preset application list_1. In yet another possible implementation, application_1 being a preset application_1 specifically includes: application_1 being an application of preset category_1.

[0206] It is understood that the preset application list / preset category can be set according to actual needs, and this application does not impose any restrictions on it. In some embodiments of this application, the preset application list / preset category can be set based on the historical memory usage of each application. For example, the preset application list_1 may include: applications whose memory usage exceeds b% for a cold starts, and whose memory usage reaches c%*a times. It is understood that a, b, and c can be set according to actual needs, and this application does not impose any restrictions on them. For example, a can be 5, b can be 90, and c can be 80.

[0207] In some embodiments of this application, the unused memory of the operating system of the electronic device satisfies condition_3, which may specifically include: the unused memory of the operating system of the electronic device is greater than threshold_3. It is understood that threshold_3 can be set according to actual needs, and this application does not impose any restrictions on it.

[0208] In some embodiments of this application, the unused memory of the electronic device's operating system satisfies condition_3, which specifically may include: the ratio of the unused memory of the electronic device's operating system to the total memory of the operating system is greater than threshold_4. It is understood that threshold_4 can be set according to actual needs, and this application does not impose any restrictions on it. For example, threshold_4 can be 0.2.

[0209] It is understood that conditions 1, 2 and 3 above may include other contents, and this application does not limit them.

[0210] It should be noted that, in some embodiments of this application, when the electronic device executes step S210, the electronic device may release the memory in memory_1 other than memory_2 (e.g., Figure 6 (As shown). It can be understood that memory_2 is less than memory_1. In one possible implementation, such as... Figure 8A As shown, memory_2 can be the default memory corresponding to RegionSpace_1. In another possible implementation, memory_2 can be larger than the default memory corresponding to RegionSpace_1. This allows the Java memory space of all application processes forked via the zygote process to be expanded. In yet another possible implementation, memory_2 can be smaller than the default memory corresponding to RegionSpace_1. This shrinks the Java memory space of application processes forked via the zygote process, facilitating subsequent expansion of Java memory space for specific applications.

[0211] It is understandable that if the electronic device releases the memory in memory_1 excluding memory_2 when executing step S210, then when the electronic device executes step S8, the memory size of RegionSpace_2 can be adjusted from memory_2 to memory_3. It is also understandable that memory_3 is greater than memory_2, and memory_3 is less than or equal to memory_1.

[0212] In some embodiments of this application, when the electronic device performs step S8, the electronic device can adjust the memory size of RegionSpace_2 from the default memory corresponding to RegionSpace_1 to memory_3.

[0213] In some embodiments of this application, after the electronic device executes step S8, the electronic device can expand / shrink the memory of RegionSpace_2. Specifically, the runtime data area_2 can adjust the memory size of RegionSpace_2 from memory_3 to memory_4 by controlling RegionSpace_2 to call the address management module.

[0214] Specifically, under the condition that the second preset condition is met, the runtime data area_2 can control the address management module to adjust the memory size of RegionSpace_2 from memory_3 to memory_4.

[0215] In some embodiments of this application, a second preset condition is satisfied, which may specifically include any one or more of the following: RegionSpace_2 memory satisfies condition_4, application_1 satisfies condition_5, and the unused memory of the electronic device's operating system satisfies condition_6. In this case, memory_4 is greater than memory_3, and memory_4 is not greater than memory_1.

[0216] In some embodiments of this application, the memory of RegionSpace_2 satisfies condition_4, which may specifically include any one or more of the following: the memory occupied in RegionSpace_2 exceeds threshold_5, the memory occupied in RegionSpace_2 exceeds threshold_5 within a certain period of time, the memory occupied in RegionSpace_2 exceeds threshold_5 after n consecutive GC cycles, and the growth rate of the memory occupied in RegionSpace_2 exceeds r.

[0217] It is understood that the threshold_5, r, and n can be set according to actual needs, and this application does not impose any restrictions on them. For example, the threshold_5 can be 480MB. In some embodiments of this application, the threshold_5 can be less than or equal to a preset memory threshold. In some embodiments of this application, the threshold_5 can be greater than the threshold_1. The relevant description of the threshold_5 can be referred to the relevant description of the threshold_1 above, and will not be repeated here. In some embodiments of this application, r can be greater than, equal to, or less than e. In some embodiments of this application, r can be 30. n can be a positive integer. For example, n can be 5.

[0218] In some embodiments of this application, application_1 satisfies condition_5, specifically including: application_1 is a preset application_2. In one possible implementation, application_1 being a preset application_2 specifically includes: application_1 being an application in the preset application list_2. In yet another possible implementation, application_1 being a preset application_2 specifically includes: application_1 being an application of preset category_2.

[0219] It should be noted that the preset application list_2 and the preset application list_1 can be completely or partially the same, and similarly, the preset category_2 and the preset category_1 can also be completely or partially the same. In some embodiments of this application, application_1 can correspond to multiple categories. In this case, the preset category_1 and the preset category_2 can be completely different. It is understood that the relevant descriptions of the preset application lists and preset categories can be referred to above, and will not be repeated here.

[0220] In some embodiments of this application, the unused memory of the operating system of the electronic device satisfies condition _6, which may specifically include any one or more of the following: the unused memory of the operating system of the electronic device is greater than threshold _6, and the ratio of the unused memory of the operating system of the electronic device to the total memory of the operating system is greater than threshold _7. It is understood that threshold _6 and threshold _7 can be set according to actual needs, and this application does not impose any restrictions on them.

[0221] It is understood that conditions 4, 5 and 6 above may also include other contents, and this application does not limit them.

[0222] In some embodiments of this application, a second preset condition is satisfied, which may specifically include any one or more of the following: RegionSpace_2 memory satisfies condition_7, application_1 satisfies condition_8, and the unused memory of the electronic device's operating system satisfies condition_9. In this case, memory_4 is less than memory_3.

[0223] In some embodiments of this application, the memory of RegionSpace_2 satisfies condition_7, which may specifically include any one or more of the following: the memory occupied in RegionSpace_2 is less than threshold_8, the memory occupied in RegionSpace_2 is less than threshold_8 within a certain period of time, the memory occupied in RegionSpace_2 after n consecutive GCs is less than threshold_8, and the growth rate of the memory occupied in RegionSpace_2 is less than s.

[0224] It is understood that threshold_8 and s can be set according to actual needs, and this application does not impose any restrictions on them. For example, threshold_5 can be 400MB. In some embodiments of this application, threshold_8 can be less than or equal to a preset memory threshold. In some embodiments of this application, threshold_8 can be less than threshold_1, and threshold_8 can be less than threshold_5. In some embodiments of this application, s can be less than e, and s can be less than r. In some embodiments of this application, s can be 5.

[0225] In some embodiments of this application, application_1 satisfies condition_8, specifically including: application_1 is a preset application_3. In one possible implementation, application_1 being a preset application_3 specifically includes: application_1 being an application in the preset application list_3. In yet another possible implementation, application_1 being a preset application_3 specifically includes: application_1 being an application of preset category_3.

[0226] It should be noted that the preset application list_3 and the preset application list_1 can be completely or partially the same, and similarly, the preset category_3 and the preset category_1 can also be completely or partially the same. In some embodiments of this application, application_1 can correspond to multiple categories. In this case, the preset category_1 and the preset category_3 can be completely different. It is understood that the relevant descriptions of the preset application lists and preset categories can be referred to above, and will not be repeated here.

[0227] In some embodiments of this application, the unused memory of the operating system of the electronic device satisfies condition_9, which may specifically include any one or more of the following: the unused memory of the operating system of the electronic device is less than threshold_9, and the ratio of the unused memory of the operating system of the electronic device to the total memory of the operating system is less than threshold_10. It is understood that threshold_9 and threshold_10 can be set according to actual needs, and this application does not impose any restrictions on them.

[0228] It is understood that conditions 7, 8 and 9 above may also include other contents, and this application does not impose any restrictions on them.

[0229] It is understood that the above method is not only applicable to electronic devices using the Android operating system, but also to electronic devices using other operating systems. In this case, the Java memory space in the electronic device may not be the RegionSpace mentioned above.

[0230] The hardware structure of the electronic device involved in this application is described below.

[0231] Please see Figure 12 , Figure 12 This is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application.

[0232] The electronic device may include a processor 110, an external memory interface 120, an internal memory 121, an audio module 130, a speaker 130A, a receiver 130B, a microphone 130C, a headphone jack 130D, a display screen 140, a camera 150, and a touch sensor 160.

[0233] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device. It is understood that the illustrated components can be implemented in hardware, software, or a combination of both. In some embodiments of this application, the electronic device may include more components than illustrated. For example, the electronic device may include other types of sensors such as accelerometers, gyroscopes, and temperature sensors. In still other embodiments of this application, the electronic device may include fewer components than illustrated, or combine some components, split some components, or arrange different components. The interface connection relationships between the modules illustrated in the embodiments of this application are merely illustrative and do not constitute a structural limitation on the electronic device.

[0234] Processor 110 may include one or more processing units, such as: application processor (AP), modem processor, graphics processing unit (GPU), image signal processor (ISP), controller, video codec, digital signal processor (DSP), baseband processor, and / or neural network processing unit (NPU), etc. Processor 110 may also include memory for storing instructions and data.

[0235] Electronic devices achieve display functions through GPUs, displays 140, and application processors.

[0236] A GPU is a microprocessor for image processing, connected to display screen 140 and application processor. The GPU performs mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information. Display screen 140 is used to display images, videos, etc. In some embodiments, an electronic device may include one or more display screens 140.

[0237] Camera 150 is used to capture still images or videos. The ISP (Image Signal Processor) is used to process the data fed back by camera 150. Light is transmitted through the lens to the camera's photosensitive element, where the light signal is converted into an electrical signal. The camera's photosensitive element then transmits the electrical signal to the ISP for processing, transforming it into an image visible to the naked eye. Electronic devices may include one or more cameras 150.

[0238] Internal memory 121 may include one or more RAMs and one or more non-volatile memory (NVMs). The RAMs can be directly read and written by the processor 110 and can be used to store executable programs (e.g., machine instructions) of the operating system or other running programs, as well as user and application data. The NVMs can also store executable programs and user and application data, and can be pre-loaded into the RAMs for direct read and write operations by the processor 110.

[0239] In this embodiment, the code implementing the memory expansion method described in this embodiment can be stored in non-volatile memory. When running a camera application, the electronic device can load the executable code stored in the non-volatile memory into random access memory.

[0240] The external memory interface 120 can be used to connect to external non-volatile memory, thereby expanding the storage capacity of electronic devices.

[0241] Electronic devices can implement audio functions through audio modules 130, speakers 130A, receivers 130B, microphones 130C, headphone jacks 130D, and application processors.

[0242] Audio module 130 is used to convert digital audio information into analog audio signal output, and also to convert analog audio input into digital audio signal. Speaker 130A, also called a "loudspeaker," is used to convert audio electrical signals into sound signals. Receiver 130B, also called a "handpiece," is used to convert audio electrical signals into sound signals. Microphone 130C, also called a "microphone" or "voice transducer," is used to convert sound signals into electrical signals. Headphone jack 130D is used to connect wired headphones.

[0243] In this embodiment of the application, when the electronic device has the voice-to-text function enabled, it can enable the microphone 130C to collect sound signals and convert the sound signals into corresponding text.

[0244] Touch sensor 160, also known as a "touch device," can be disposed on display screen 140. The touch sensor 160 and display screen 140 together form a touchscreen, also known as a "touchscreen." Touch sensor 160 is used to detect touch operations applied to or near it. The touch sensor can transmit the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through display screen 140. In other embodiments, touch sensor 160 may also be disposed on the surface of the electronic device, in a different location than display screen 140.

[0245] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.

Claims

1. A memory expansion method, characterized in that, The method is performed by an electronic device, and the method includes: Start the electronic device; After the electronic device is started, a zygote virtual machine is created; Wherein, the Java memory space in the zygote virtual machine is the first Java memory space, the virtual address segment corresponding to the first Java memory space is the first virtual address segment and the second virtual address segment, the memory size of the first Java memory space is the third memory, the memory size corresponding to the first virtual address segment is the first memory, and the third memory is greater than the preset memory; If the first application does not exist in the background of the electronic device, the first application is launched; After the first application is launched, a first application virtual machine is obtained, wherein the first application virtual machine is incubated by the zygote virtual machine, and the Java memory space in the first application virtual machine is the second Java memory space; Wherein, under the condition of satisfying the first preset condition, the memory size of the second Java memory space is adjusted from the first memory to the second memory, and the memory size corresponding to the third virtual address segment is the second memory. The third virtual address segment includes the first virtual address segment and some or all of the address segments in the second virtual address segment.

2. The method as described in claim 1, characterized in that, The method further includes: If the first preset condition is not met, the size of the second Java memory space is the same as the first memory.

3. The method as described in claim 1 or 2, characterized in that, The method further includes the following steps during the creation of the zygote virtual machine: Create the first Java memory space; Once the memory space layout in the zygote virtual machine is complete, release the memory of the second virtual address segment; After releasing the memory of the second virtual address segment, the size of the first Java memory space is the first memory.

4. The method according to any one of claims 1-3, characterized in that, The condition of satisfying the first preset condition specifically includes: the first application is a first preset application.

5. The method according to any one of claims 1-4, characterized in that, The virtual address segment actually used by the first Java memory space is the first virtual address segment, and the second virtual address segment is not actually used.

6. The method according to any one of claims 1-5, characterized in that, The Java memory space in the zygote virtual machine is the memory space corresponding to the RegionSpace of the zygote virtual machine.

7. The method as described in claim 3, characterized in that, The creation of the first Java memory space specifically includes: The initial memory size of the first Java memory space is determined to be the third memory. For the first Java memory space, allocate the first virtual address segment and the second virtual address segment, and map the first virtual address segment and the second virtual address segment to physical addresses; The release of the memory of the second virtual address segment specifically includes: unmapping the mapping between the second virtual address segment and the physical address; The size of the second Java memory space is adjusted from the first memory space to the second memory space, specifically including: Maintain the mapping from the first virtual address segment to the physical address, and map some or all of the addresses in the second virtual address segment to the physical address.

8. The method as described in claim 7, characterized in that, The step of applying for the first virtual address segment and the second virtual address segment, and mapping the first virtual address segment and the second virtual address segment to physical addresses, specifically includes: The anonymous page corresponding to the third memory is requested; the anonymous page corresponding to the third memory includes the first virtual address segment and the second virtual address segment; the anonymous page is used to represent a segment of virtual address in the process virtual address space that has a mapping relationship with the physical address.

9. The method according to any one of claims 1-8, characterized in that, The first memory is the preset memory.

10. The method according to any one of claims 1-9, characterized in that, The second memory is greater than the preset memory.

11. The method according to any one of claims 1-10, characterized in that, The preset memory size is 512MB.

12. An electronic device comprising one or more memories and one or more processors, characterized in that, The memory is used to store a computer program; the processor is used to invoke the computer program to cause the electronic device to perform the method of any one of claims 1-11.

13. A computer storage medium, characterized in that, include: Computer instructions; when the computer instructions are executed on an electronic device, causing the electronic device to perform the method of any one of claims 1-11.