Application program compiling method and electronic device

By selecting the compilation mode in electronic devices based on whether the application is a long-lasting application and system load status, the problem of low execution efficiency of DEX file interpretation in Android virtual machines is solved, and the effect of rapid installation and efficient operation is achieved.

CN118733054BActive Publication Date: 2025-02-07HONOR DEVICE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411217703.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-02
Publication Date
2025-02-07
Estimated Expiration
2044-09-02

AI Technical Summary

Technical Problem

In electronic devices, the Android virtual machine recognizes the DEX file and loads it for memory interpretation and execution, resulting in low operation efficiency and affects the user experience.

Method used

An application compilation method is adopted to determine whether the application is a long-lasting application and system load state in response to the installation operation of the target application, and select the appropriate compilation mode for installation and compilation optimization. Use the first compilation mode to quickly install it when high load, and use the second compilation mode to perform compilation optimization when low load.

Benefits of technology

Quickly install applications under high load conditions to reduce system load and lag, and improve user experience; improve application operation efficiency through compilation and optimization under low load conditions to avoid excessive system load.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118733054B_ABST
    Figure CN118733054B_ABST
Patent Text Reader

Abstract

An application compilation method and an electronic device, comprising: in response to a first installation operation on a first target application, when the first target application is not a long-keep-alive application and the load state is high load, the electronic device installs the first target application through a first compilation mode; the first compilation mode does not perform compilation optimization; after the first target application is installed, if the load state changes from high load to low load, the electronic device compiles and optimizes the first target application through a second compilation mode. The embodiment of the present application can be used to avoid overload operation of the device and ensure the operation efficiency of the first application.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of terminal devices, and in particular to an application compilation method and an electronic device. Background Art

[0002] After installing the application on the electronic device, the Android virtual machine can recognize the DEX file, and load the DEX file into memory during the use of the application, interpret and execute the bytecode, and the operation efficiency is very low, affecting the user's experience of using the device. To address the above problems, dex2oat compilation optimization can be used to convert the dex file bytecode into machine code that can be executed on the virtual machine before the Android system runs. The machine code can be directly executed during the application, thereby improving the application's operating efficiency. However, the installation time required for the dex2oat compilation optimization method is long, and it occupies more device processing resources. Summary of the invention

[0003] The embodiments of the present application provide an application compilation method and an electronic device, which can be used to avoid device overload and ensure the operating efficiency of a first application.

[0004] In a first aspect, an embodiment of the present application provides an application compilation method, which is applied to an electronic device, and the method includes: in response to a first installation operation on a first target application, when the first target application is not a long-keep-alive application and the load state is high load, the electronic device installs the first target application through a first compilation mode; the first compilation mode does not perform compilation optimization; after the first target application is installed, if the load state changes from high load to low load, the electronic device compiles and optimizes the first target application through a second compilation mode.

[0005] In an implementation manner of the present application, when an electronic device installs an application that is not long-lived when the system load is high, it can first be installed according to the first compilation mode that does not perform compilation optimization. While the installation speed is fast, it reduces the system load, reduces freezes, and improves user experience. When the system load changes from high load to low load, it can be compiled and optimized according to the second compilation mode, which ensures that the first target application runs more efficiently while avoiding excessive system load.

[0006] In a possible implementation, after the first target application is installed through the first compilation mode, and before the first target application is compiled and optimized through the second compilation mode, the electronic device converts the bytecode of the first target application into machine code during the operation of the first target application; after the first target application is compiled and optimized through the second compilation mode, the electronic device directly executes the machine code of the first target application during the operation of the first target application. In this way, after the compilation and optimization according to the second compilation mode, the electronic device can directly execute the machine code of the first target application, thereby improving the operation efficiency of the first target application.

[0007] In a possible implementation, the method further includes: when the first target application is the long keep-alive application, the electronic device installs the first target application through the second compilation mode. In this way, when the long keep-alive application is installed, the system load is ignored and the application is directly installed according to the second compilation mode, giving priority to the operation efficiency after installation, avoiding the problem of low operation efficiency for a long time due to the long-term inability to restart the long keep-alive application, and processing resource occupation, thereby improving the system execution efficiency and alleviating the system load pressure in the long run.

[0008] In a possible implementation, the method further includes: when the first target application is not the long keep-alive application and the load state is low load, the electronic device installs the first target application through the second compilation mode. In this way, when the system load is low load, it can be directly installed according to the second compilation mode, which reduces the number of installations and avoids the situation of high system load, thereby ensuring smooth operation of the device and user experience.

[0009] In a possible implementation, the method further includes: in response to a first installation operation on the first target application, the electronic device determines whether the first target application is the long keep-alive application; the long keep-alive application is an application that can maintain an active life cycle in response to a user exit operation; when the first target application is not the long keep-alive application, the electronic device determines whether the load state is a high load. In this way, the electronic device can ensure that the long keep-alive application is directly installed according to the second compilation mode, and if it is not a long keep-alive application, the compilation mode can be selected according to the load state, and it can be installed through the second compilation mode when the system load is low, ensuring that the system load is small, reducing system freezes, and ensuring smooth system operation.

[0010] In a possible implementation, the electronic device determines whether the load state is a high load, including: the electronic device determines whether a first condition is satisfied; the first condition includes at least one of a kernel state condition, a memory usage condition, and a temperature condition; the kernel state condition is a condition that a first kernel busy state rate is less than or equal to a threshold kernel busy state rate, and the first kernel busy state rate is a probability that the kernel state of the electronic device is a busy state within a first time period; the memory usage condition is a condition that a first memory usage is less than or equal to a threshold memory usage; the temperature condition is a condition that a processor temperature is less than or equal to a threshold temperature; the electronic device determines that the load state is a high load when the first condition is not satisfied; and determines that the load state is a low load when the first condition is satisfied. In this way, the electronic device can determine the current load according to the characteristic information of the memory load, thereby ensuring the accuracy of the load judgment and the accuracy of the compilation mode selection.

[0011] In a possible implementation, in response to the first installation operation of the first target application, the method further includes: the electronic device starts to obtain load parameters, the load parameters include one or more of the kernel state of the electronic device, the first memory usage, and the processor temperature; after the electronic device installs the first target application through the first compilation mode, the method further includes: the electronic device obtains load information based on the load parameters; the load information includes the first kernel busy state rate, the first memory usage, and the processor temperature. In this way, the electronic device can first obtain the load parameters to ensure the accuracy of the load information, and then ensure the accuracy of the compilation mode selection and timing.

[0012] The load information is used to measure the load status.

[0013] In a possible implementation, the electronic device determines whether the first target application is a long keep-alive application, including: the electronic device determines whether the long keep-alive application list includes the application package name of the first target application, and when the long keep-alive application list includes the application package name of the first target application, the first target application is a long keep-alive application; when the long keep-alive application list does not include the application package name of the first target application, the first target application is not a long keep-alive application. In this way, the electronic device can determine whether the currently installed application is a long keep-alive application according to the preset long keep-alive application list, and the accuracy of the judgment can further ensure the accuracy of the compilation mode selection and timing.

[0014] The electronic device may be preset with a long keep-alive application list, and the long keep-alive application list includes at least one application package name.

[0015] In a possible implementation, after the first target application is installed, the method further includes: the electronic device determines whether the load state is low load; the load information is used to indicate the load level of the electronic device memory; when the load state is not low load, the electronic device continues to execute the process of determining whether the load state is low load. In this way, after the installation is completed according to the first compilation mode, the operation efficiency of the first target application is low, so the load state of the system is monitored, and the monitoring is maintained when the load is high, and the compilation and optimization is performed according to the second compilation mode when the load is low, to ensure efficient operation after compilation, and to take into account the overall low system load and improve the application operation efficiency.

[0016] In a possible implementation, the electronic device includes a first target application, a package management service PMS, a real-time service module and a bytecode optimization module; in response to a first installation operation on the first target application, when the first target application is not a long keep-alive application and the load state is a high load, the electronic device installs the first target application through a first compilation mode, including: the first target application responds to the first installation operation on the first target application, sending a target application installation request to the PMS, the target application installation request including the application package name of the first target application; the PMS sends installation request information to the real-time service module, the installation request information is used to request the installation of the first target application; the real-time service module determines whether the first target application belongs to a long keep-alive application based on the installation request information; when the first target application does not belong to the long keep-alive application, the real-time service module obtains load information, and determines whether the load state is a high load based on the load information; when the load state is a high load, the real-time service module sends target compilation mode information to the PMS; the target compilation mode information is used to request the first target application to be installed according to the first compilation mode; the PMS determines whether the first target application belongs to a long keep-alive application based on the installation request information; The electronic device obtains and determines whether the load state is low load after the installation of the first target application is completed, including: after the installation of the first target application is completed, the real-time service module determines whether the load state is low load; if the load state changes from high load to low load, the electronic device compiles and optimizes the first target application through the second compilation mode, including: when the load state is low load, the real-time service module sends the second compilation mode information to the PMS; the second compilation mode information is used to request to compile and optimize the first target information according to the second compilation mode; the PMS compiles the first target application according to the second compilation mode; the PMS sends compilation request information to the bytecode optimization module; the bytecode optimization module compiles the first file based on the compilation request information to obtain the second file, and the bytecode optimization module sends the compilation completion notification to the PMS. In this way, for a long-keep-alive application, the installation package can be directly interpreted and executed to obtain a second file for fast execution, thereby avoiding the inefficiency of being unable to use the second file to run due to a low possibility of starting after installation.In the case of non-long keep-alive applications and high load status, the electronic device can be installed according to the first compilation mode to increase the installation speed, reduce the processing load, and ensure smooth device processing. When the target compilation mode is the first compilation mode, the electronic device needs to continue to detect the load status, and perform compilation optimization according to the second compilation mode when the load status is low load. For non-long keep-alive applications, the second compilation mode can avoid high load periods and compile in low load periods, reasonably control the degree of processing resource usage, reduce system freezes, and improve user experience.

[0017] Among them, the first file is a DEX file, and the second file is an OAT file.

[0018] In a second aspect, an embodiment of the present application provides an electronic device, comprising one or more processors and one or more memories; the one or more processors are coupled to the one or more memories, the one or more memories are used to store computer program code, the computer program code comprises computer instructions, and when the one or more processors execute the computer instructions, the electronic device executes an application compilation method described in the first aspect or any possible implementation method of the first aspect.

[0019] In a third aspect, an embodiment of the present application provides a computer program product comprising instructions, which, when executed on an electronic device, enables the electronic device to execute an application compilation method as described in the first aspect or any possible implementation of the first aspect.

[0020] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, comprising instructions, which, when executed on an electronic device, enable the electronic device to execute an application compilation method as described in the first aspect or any possible implementation of the first aspect.

[0021] In a fifth aspect, an embodiment of the present application provides a chip system, which is applied to an electronic device, and the chip system includes one or more processors, which are used to call computer instructions so that the electronic device executes an application compilation method as described in the first aspect or any possible implementation method of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Figure 1 It is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application;

[0023] Figure 2 It is a schematic diagram of the software structure of an electronic device proposed in an embodiment of the present application;

[0024] Figure 3A to Figure 3Eis a set of user interface schematic diagrams proposed in the embodiments of the present application;

[0025] Figure 4A and Figure 4B This is a schematic diagram of the process of application compilation and operation in different compilation modes proposed in an embodiment of the present application;

[0026] Figure 5 It is a schematic diagram of an application compilation method process proposed in an embodiment of the present application;

[0027] Figure 6 This is a schematic diagram of an application installation and compilation process proposed in an embodiment of the present application;

[0028] Figure 7 It is a schematic diagram of an application compilation method process proposed in an embodiment of the present application;

[0029] Figure 8 It is a flowchart of a method for obtaining a target compilation mode proposed in an embodiment of the present application;

[0030] Fig. 9 It is a schematic diagram of an application installation and compilation process proposed in an embodiment of the present application. DETAILED DESCRIPTION

[0031] The terms used in the following embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to be used as limitations to the present application. As used in the specification and appended claims of the present application, the singular expressions "one", "a kind of", "said", "above", "the" and "this" are intended to also include plural expressions, unless there is a clear indication to the contrary in the context. It should also be understood that the term "and / or" used in the present application refers to and includes any or all possible combinations of one or more listed items.

[0032] The following first introduces the terms involved in the embodiments of the present application.

[0033] 1. Compilation of the application:

[0034] The application (APP) runs in a virtual machine (the virtual machine of the Android system is the Android runtime library ART). The virtual machine's execution of the application code includes two parts. The first part is to compile the source code into bytecode, also known as front-end compilation. The work performed at this time is mainly to analyze the lexical, grammatical, and semantic aspects. The second part is to compile the bytecode into machine code for interpretation and execution.

[0035] In the Just-in-time (JIT) technology, JIT is the compilation of bytecode to local machine code at runtime. When the interpreter performs just-in-time compilation, the interpreter needs to compile the local machine code, which takes a long time. The execution efficiency of the above interpreter is low, which has a serious impact on the user experience. AOT technology is used to solve the above problem. In AOT technology, when the application package (Android application package, Android APK) is installed, the system will compile the DEX (DalvikExecutable) file in the APK into an OAT (Optimized ART) file containing local machine code through the dex2oat (dalvik excutable file to optimized art file) tool for storage. Among them, in the Android system, there are two runtime executable file formats, one is the DEX file and the other is the OAT file. The DEX file is a standard executable file format running on the Dalvik virtual machine, while the OAT file is an optimized executable file format running on the ART virtual machine. That is, dex2oat can compile the bytecode of the application into machine code in advance, so the machine code can be directly executed during actual operation, thereby greatly improving the operation efficiency of the application. When the application is running, it needs to load the DEX file. If the OAT file is included, ART uses the OAT file directly; if the OAT file is not included, ART executes the DEX file through JIT and the interpreter.

[0036] 2. Different compilation modes:

[0037] dex2oat includes multiple different compilation modes, which are sorted according to the performance of the application after execution. The common compilation modes include: speed compilation mode, speed-profile compilation mode, verify compilation mode, etc. Among them, the speed compilation mode compiles and optimizes all application codes, and the resulting product has good performance, but the generated file is large, time-consuming, and consumes a lot of mobile phone storage space. The speed-profile compilation mode depends on the profile file and can compile and optimize the hot functions of the application. The verify compilation mode only verifies the dex file of the application. The verify compilation mode is inferior to the speed-profile compilation mode in terms of compilation performance.

[0038] The electronic device in the embodiments of the present application can be a mobile phone, a tablet computer, a desktop, a laptop computer, a handheld computer, a smart bracelet, a super mobile personal computer, a netbook, a personal phone, a personal data assistant, an augmented reality (AR) / virtual reality (VR) and other touch screen devices. The present application does not limit the specific form of the electronic device.

[0039] The following is an introduction to the device involved in the embodiments of the present application.

[0040] Figure 1 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application.

[0041] The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.

[0042] It is to be understood that the structure illustrated in the embodiments of the present application does not constitute a specific limitation on the electronic device. In other embodiments of the present application, the electronic device may include more or fewer components than shown in the figure, or combine certain components, or split certain components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0043] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processor (graphics processing unit, GPU), an image signal processor (image signal processor, ISP), a controller, a memory, a video codec, a digital signal processor (digital signal processor, DSP), a baseband processor, and / or a neural network processor (neural-network processing unit, NPU), etc. Among them, different processing units may be independent devices or integrated in one or more processors.

[0044] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0045] It is understandable that the interface connection relationship between the modules illustrated in the embodiments of the present application is only a schematic illustration and does not constitute a structural limitation on the electronic device. In other embodiments of the present application, the electronic device may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.

[0046] The wireless communication function of the electronic device can be implemented through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor.

[0047] The electronic device implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.

[0048] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.

[0049] The touch sensor 180K is also called a "touch panel". The touch sensor 180K can be set on the display screen 194. The touch sensor 180K and the display screen 194 form a touch screen, also called a "touch screen". The touch sensor 180K is used to detect touch operations acting on or near it.

[0050] In the embodiment of the present application, the electronic device 100 can detect user operations through the touch sensor 180K. The user operation may include a touch event from the user touching the display screen 194, for example, the user clicks on an object in the shooting preview screen to focus.

[0051] Optionally, the user operation may also be an air operation, a voice operation instruction, etc. For example, a gesture sensing sensor is installed in the electronic device, and the gesture sensing sensor can detect the user's air operation.

[0052] Figure 2 A schematic diagram of the software structure of an electronic device provided in an embodiment of the present application.

[0053] like Figure 2 As shown, the software framework of the electronic device involved in the present application may include an application layer, an application framework layer (framework, FWK), an Android runtime (Android runtime, ART) and a system library.

[0054] The application layer may include a series of application packages, such as calendar, map, music, gallery, SMS, call, social software, browser, application store and other applications (also referred to as applications, some of the above applications are not shown). In the embodiment of the present application, the electronic device can install the application through the first application, for example, the first application is an application such as an application store or a browser, and the application store can obtain the user's operation of installing each application and request the electronic device to install the application.

[0055] The application framework layer provides application programming interface (API) and programming framework for the applications in the application layer. The application framework layer includes some predefined functions. Figure 2 As shown, the application framework layer may include a window manager, a content manager, an activity manager service (AMS), a resource manager, and the like.

[0056] Among them, AMS is a service in the Android system responsible for managing and scheduling the life cycle and task stack of application activities. AMS manages the activity life cycle by using system resources and data structures (such as processes, task battles, and recording the status of the activity life cycle). For example, it manages the creation, operation, and destruction of the application life cycle.

[0057] In an embodiment of the present application, the application framework layer can also provide system services (system server), which may include package management services (PMS) and Android runtime services (Art server) and real-time service modules (for example, IAware real-time services).

[0058] Among them, the PMS can perform application installation and compilation optimization processing, mainly loading installation, management and uninstallation of applications on Android devices. The PMS receives an installation request for a target application from a first application, and performs installation processing based on a corresponding target compilation mode of the target application.

[0059] As the communication interface with the Android runtime, the Art service enables PMS to interact with the modules of the Android runtime and participate in the compilation and optimization processing.

[0060] The real-time service module determines the target compilation mode for installation based on the current target application and the current load situation when the PMS obtains the installation request.

[0061] The Android runtime is responsible for scheduling and management of the Android system. In the embodiment of the present application, ART provides a bytecode optimization module (dex2oat) for application startup.

[0062] The bytecode optimization module can compile and process the DEX file of the application. After the bytecode optimization module receives the compilation instruction, the bytecode optimization module can compile and process the DEX file according to the instructions of the compilation instruction, wherein the mode identifier of the target compilation mode in the compilation instruction is used to instruct the bytecode optimization module to compile and process the DEX file of the application in the corresponding compilation mode, and the core identifier of the target running core in the compilation instruction is used to instruct the bytecode optimization module to run on the corresponding core and then compile and process the DEX file of the application.

[0063] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.

[0064] The system library may include multiple functional modules, such as surface manager, media library, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.

[0065] It should be noted that the application provides Figure 2 The software structure diagram of the electronic device shown is only an example and does not limit the specific module division in different layers of the Android operating system. For details, please refer to the introduction of the Android operating system software structure in conventional technology.

[0066] Combination Figure 2 The software structure in this application is Figure 3A to Figure 3E A user scenario that illustrates the installation process for an application.

[0067] Figure 3A to Figure 3E It is a set of user interface schematic diagrams exemplarily disclosed in the embodiments of the present application. Figure 3A to Figure 3E The electronic device displays the installation process when the user performs the operation of installing the target application in the interface of the application store.

[0068] like Figure 3A As shown, the user turns on the electronic device, and the desktop interface 310 can be displayed on the electronic device. Figure 3A is a schematic diagram of the desktop interface of a user of an electronic device. Figure 3AAs shown, the electronic device can display application icons such as clock, calendar, gallery, memo, file management, email, music, calculator, browser and application store 311. The user can click on the application icon of application store 311, and in response to the operation of clicking the icon of application store, as shown in FIG. Figure 3B As shown, the electronic device can display the user interface 320 of the application store. Here, the first application is described by taking the application store as an example.

[0069] like Figure 3B As shown, the user interface 320 of the application store displays a selected application list 321, and the application list 321 includes multiple recommended applications. The user clicks the installation control corresponding to application A in the application list 321. In response to the above user operation, the electronic device installs application A and displays the user interface 330 of the application store, as shown in FIG. Figure 3C As shown, the user interface 330 of the application store displays an icon 331 of application A being installed. After the installation is complete, the electronic device displays the user interface 340 of the application store, such as Figure 3D As shown, an opening control 341 of application A is displayed in the user interface 340 of the application store.

[0070] When the electronic device displays the user interface 340 of the application store, the user can click the open control 341 of application A. Figure 3E As shown, in response to the above opening operation, the electronic device starts to run application A and displays a startup interface 350 of application A. The startup interfaces of different applications after installation are different, and this application does not limit this.

[0071] The above-mentioned installation of application A is based on the selected recommendation installation in the application store. The user can also search for a certain application to install or install or upgrade a new version of an existing application, etc. The above situation is only an example and is not limiting.

[0072] It should be noted that the above-mentioned application installation process is only an installation method and interface of the application store. Users can also perform installation operations through a browser or other applications with application installation permissions, and the electronic device performs corresponding installation processing, etc. This application does not limit this.

[0073] exist Figure 3A to Figure 3E During the application installation process, the electronic device should install it according to the corresponding compilation mode. The following describes two different compilation modes: verify compilation mode and speed-profile compilation mode.

[0074] Figure 4A and Figure 4B A schematic diagram of the process of application compilation and running in different compilation modes provided in an embodiment of the present application.

[0075] like Figure 4A As shown, in the verify compilation mode, after the electronic device obtains the installation request of the target application, it starts to install using the verify compilation mode. Since no compilation processing is required, only verification is performed, the installation time is short and the speed is fast. After the target application is installed, if the electronic device obtains the running request of the target application, the target application runs according to the first mode. During the running process, the virtual machine is required to interpret and execute the bytecode (that is, interpret and execute the DEX file). After the interpretation and execution, the machine code can be processed. Therefore, the running efficiency of the target application running according to the first mode is low.

[0076] like Figure 4B As shown, in the compilation mode of speed-profile, after the electronic device obtains the installation request of the target application, it compiles and optimizes through the profile file, and converts the bytecode in the application installation package into machine code (the installation package of the target application may include the profile file). The above-mentioned profile file has a large amount of data and the compilation process takes a long time. Therefore, compared with the installation time of the compilation mode of verify, the installation time of the target application in the compilation mode of speed-profile is longer. After the installation of the target application is completed, when the electronic device obtains the operation request of the target application, the target application runs in the second mode. During the operation of the target application, the machine code can be directly executed on the hardware platform (that is, executed on the OAT file). Therefore, after the compilation mode of speed-profile, the operation efficiency of the target application is high. Among them, the machine code is a binary instruction directly executed by the computer hardware, has a lower level of abstraction, and is a code that the hardware can directly understand and execute.

[0077] After comparison, when using the verify compilation mode for installation, only verification processing is performed, and the bytecode conversion to machine code is not performed. The installation time is short and the speed is fast, but after the installation is completed, the virtual machine needs to interpret and execute the bytecode during the operation, and the operation efficiency is low. When using the speed-profile compilation mode for installation, the bytecode of the installation package needs to be converted into machine code. The installation time is long and the speed is slow, but after the installation is completed, the virtual machine does not need to interpret and execute the bytecode during the operation, and the hardware can directly execute the machine code, which has fast operation efficiency and smooth processing.

[0078] Based on the above situation, in order to make the application run more smoothly, you can use des2oat to compile the DEX file of the application during the installation of the application, that is, compile the application through the speed-profile compilation mode and compile it into machine code that can be directly run by electronic devices. Electronic devices can directly load these machine codes during the running of the application, and the application runs more smoothly.

[0079] It should be noted that the electronic device can also be compiled through the speed compilation mode, or compiled in other ways, which is not limited in this application.

[0080] Combination Figure 4A and Figure 4B In the application installation process, in order to ensure that the installation application runs more smoothly, the following describes an application compilation method.

[0081] Figure 5 1 is a flow chart of a method for compiling an application program disclosed in an exemplary embodiment of the present application. The electronic device may include a first application, a PMS, an ART service, and a bytecode optimization module. The above four modules can be referred to Figure 2 The relevant description in is not repeated here.

[0082] like Figure 5 As shown, the application compilation method may include but is not limited to the following steps:

[0083] S501: A first application obtains a first operation of a target application.

[0084] The first operation is to install the target application. The first operation can be Figure 3B The click-to-install operation in the example may also be a user voice control operation or a gesture control installation operation, or an installation operation in other applications, etc. This application does not limit the specific operation method of the first operation. Among them, the first application may be an application with application installation permission such as a browser or an application store, which is not limited in this application. The target application is the application that needs to be installed.

[0085] In addition, after the electronic device obtains the first operation of the target application, it can start downloading the installation package (APK file) of the target application. The installation package can include a DEX file, and the DEX file is used for compilation optimization during the installation process.

[0086] S502: The first application sends a target application installation request to the PMS in response to the first operation.

[0087] After the first application can obtain the first operation of installing the target application, in response to the above operation, the first application can send a target application installation request to the PMS. The target application installation request includes the installation package name of the target application. The target application installation request is used to request the installation of the target application.

[0088] S503: The PMS performs installation processing on the installation package of the target application.

[0089] Specifically, PMS creates an installation directory for the application in the electronic device and writes the installation files in the installation package into the installation directory of the electronic device. For example, PWS creates an installation directory for "application A" in the mobile phone, such as the directory data / app / ... / applicationA, and writes the installation files in the APK installation package of the target application, such as DEX files, into the installation directory.

[0090] After receiving the target application installation request, PMS can call the process waiting for installation ProcessPendingInstall() function and the process installation request ProcessInstallResquests() function, as well as call the APK installation task ProcessApkInstallResquests() function and the installation application package InstallPackages() function to request to start installing the target application.

[0091] S504: The PMS sends a compilation request message to the ART service.

[0092] The installation request information can be used to request the installation package to be compiled. The installation request information includes parameters such as the installation package name and installation directory of the target application.

[0093] Specifically, the PMS may call the ExecutePostCommitStepsLIF() function to send installation request information to the bytecode optimization module.

[0094] S505: The ART service determines the compilation mode.

[0095] After receiving the installation request information, the ART service can determine the compilation mode. The ART service can determine the compilation mode by executing functions including deoptPackage() and dexopt() to determine the compilation mode used when installing the current target application.

[0096] S506: The ART service sends a compilation task request information to the bytecode optimization module.

[0097] The compilation task request information can be used to request the installation package to be compiled. The installation request information includes the compilation mode information of the target application, the name of the installation package, the installation directory and other parameters.

[0098] S507: The bytecode optimization module compiles the first file based on the requested compilation task information.

[0099] The first file is a DEX file in the APK installation package of the target application. The bytecode optimization module can compile the first file based on the requested compilation task information.

[0100] The bytecode optimization module calls the Dexopt() function to perform dex2opt compilation optimization. Specifically, the bytecode optimization module can compile the installation package of the target application according to the speed-profile compilation mode, that is, interpret and execute the DEX file (i.e., the first file) in the installation package to obtain the OAT file (the second file), and store the OAT file.

[0101] S508: The bytecode optimization module sends a compilation completion notification to the PMS through the ART service.

[0102] After the bytecode optimization module completes compiling the first file based on the installation request information, a compilation completion notification can be sent to the PMS through the ART service. Correspondingly, the PMS can receive a compilation completion notification from the bytecode optimization module through the ART service. The compilation completion notification is used to indicate that the target application has been compiled.

[0103] S509: The PMS sends an installation completion notification to the first application.

[0104] After the PMS receives the compilation completion notification, the PMS sends an installation completion notification to the first application. Correspondingly, the first application receives the installation completion notification from the PMS. The installation completion notification is used to indicate that the target application has been installed.

[0105] S510: The first application displays installation completion information.

[0106] After the first application receives the installation completion notification, the installation completion information may be displayed. Figure 3D As shown, after the target application (eg, application A) is installed, an open control 341 may be displayed, indicating that the current application A has been installed.

[0107] Optionally, when the electronic device currently displays the desktop main interface, the desktop main interface of the electronic device can start to display the icon application icon without displaying the icon of the target application. At this time, the electronic device also includes a desktop application, and the desktop application can start to display the installation completion information, that is, start to display the icon of the target application.

[0108] Figure 5 During the application compilation process, only the speed-profile compilation mode is used for installation. After the installation is completed, the machine code in the OAT file can be directly executed by the hardware, and the application runs efficiently. However, this takes a long time to install, and the user has to wait a long time during the installation, which leads to a poor user installation experience.

[0109] In view of the above situation, an application compilation method is proposed, which can be installed using the verify compilation mode first. After the installation is completed, the target application can start running when the user starts using it. After the installation is installed using the verify compilation mode, the electronic device can compile the installation package based on the speed-profile compilation mode. After the installation is completed, when the thread of the application is started, it can run according to the machine code compiled in the speed-profile compilation mode. After that, the target application has a higher running efficiency.

[0110] Figure 6 This is a schematic diagram of the application installation and compilation process provided by this application. Figure 6 As shown, after the electronic device obtains the target application installation request, it first verifies the installation package through the verify compilation mode and installs the target application. After the target application is installed, the target application operation request is obtained (the user clicks to open the target application, and the target application can be used quickly), and the electronic device runs the target application according to the first mode. During the operation of the first mode, the virtual machine needs to interpret and execute the bytecode. At the same time, after a period of time after the target application is installed, the installation package can also be compiled and optimized through the speed-profile compilation mode. After the compilation and optimization are completed, if the target application is started (the conditions for starting need to be met after compilation), the target application can be run in the second mode after compilation optimization, that is, the machine code can be directly executed.

[0111] Usually after compiling and installing in the verify compilation mode, the user will click to open the target application. During the process of running the target application in the first mode, the electronic device will also compile and optimize the installation package of the target application in the speed-profile compilation mode. After the target application running thread is terminated, it will be rebuilt before the target application can be run in the second mode. However, due to the existence of some application threads that remain active for a long time. For example, for some applications that users use frequently for a long time, in order to reduce the processing process each time the user opens it, the electronic device background will not terminate the threads of these application activities, which can reduce the response time and improve the user experience. The installation of the above-mentioned application will cause the electronic device to be unable to wait for the creation of the application thread and continue to run in the first mode even if it has been compiled in the speed-profile compilation mode. It will be in a long-term low operating efficiency and serious processing resource occupation.

[0112] In addition, the speed-profile compilation mode occupies more processing resources for the installation package. If the current memory load is high, continuing to use the speed-profile compilation mode will further occupy processing resources. When the memory is overloaded, the power consumption is high, the processing efficiency of the whole machine is low, the response time is long, and the user experience of using the device is poor.

[0113] In view of the above problems, the present application proposes an application compilation method and an electronic device. In the process of installing the target application, the electronic device can determine the target compilation mode based on whether the target application is a long keep-alive application and the current load state, and the electronic device can install the target application according to the target compilation mode. For long keep-alive applications, or non-long keep-alive applications but the load state is low load, the electronic device can be installed according to the second compilation mode, and the second file is generated after compilation to improve the operation efficiency. In this way, for long keep-alive applications, the installation package can be directly interpreted and executed to obtain the second file for fast execution, avoiding the low possibility of starting after installation, resulting in the inefficient operation that cannot be used to run the second file. In the case of non-long keep-alive applications and the load state is high load, the electronic device can be installed according to the first compilation mode to increase the installation speed, reduce the processing load, and ensure smooth device processing. In the case of the target compilation mode is the first compilation mode, the electronic device needs to continue to detect the load state, and compile and optimize according to the second compilation mode when the load state is low load. For non-long keep-alive applications, the second compilation mode can avoid high load periods, compile in low load periods, and reasonably control the degree of processing resource usage, which can reduce system jams and improve user experience.

[0114] Figure 7 This is an application compilation method exemplarily proposed in the embodiment of the present application, such as Figure 7As shown, the electronic device may include a first application, a PMS, a real-time service module, an ART service, and a bytecode optimization module. The above modules can refer to Figure 2 The relevant description in is not repeated here. The application compilation method may include but is not limited to executing the following methods:

[0115] S701: A first application obtains a first operation of a target application.

[0116] The processing process of S701 may refer to the relevant content of S501 and will not be described in detail.

[0117] S702: In response to the first operation, the first application sends a load parameter acquisition request to the real-time service module.

[0118] After the real-time service module obtains the load detection request, the real-time service module may start to obtain load information.

[0119] S703: The real-time service module starts to obtain load parameters.

[0120] The load parameters can reflect the current system performance and processing resource scheduling. The load information can include the kernel status.

[0121] It should be noted that, when the load information may include the busy state rate of the first core, the electronic device may start to obtain the core states of all processor cores of the electronic device according to the first frequency, and the core states may include a busy state and an idle state. The busy state indicates that a task is being executed or a request is being processed; the idle state indicates that there is no task to be processed or waited for at present.

[0122] Among them, S702 and S703 are optional steps. When the load parameters do not include the kernel state, the electronic device may not execute steps S702 and S703, which is not limited in this application.

[0123] S704: In response to the first operation, the first application sends a target application installation request to the PMS.

[0124] Among them, S704 can refer to the relevant steps of S502 and will not be described in detail.

[0125] S705: The PMS sends a first installation request message to the real-time service module.

[0126] After the PMS receives the target application installation request, it may send a first installation request message to the real-time service module. Correspondingly, the real-time service module receives the installation request message from the PMS. The installation request message may include the application package name of the target application.

[0127] S706: The PMS sends a second installation request message to the ART service.

[0128] After the PMS receives the target application installation request, the PMS may send a second installation request message to the ART service. The second installation request message may be used to request the installation of the target application, and the ART service needs to process the installation task based on the second installation request message. The second installation request message may include the application package name of the target application.

[0129] There is no restriction on the execution order of S705 and S706 , and both S705 and S706 can be executed after S704 .

[0130] S707: The real-time service module determines a target compilation mode based on the first installation request information and the system load status.

[0131] After the real-time service module receives the installation request information from the PMS, the real-time service module needs to determine the target compilation mode based on the installation request information and the system load status. Figure 8 The method of obtaining the target compilation mode is explained in:

[0132] Figure 8 1 is a flow chart of a method for obtaining a target compilation mode proposed in an embodiment of the present application. Figure 8 As shown, the method for obtaining the target compilation mode may include but is not limited to the following steps:

[0133] S801: The real-time service module obtains the package name of the target application based on the installation request information.

[0134] The installation request information includes the package name of the target application, and the real-time service module can obtain the package name of the target application based on the installation request information.

[0135] S802: The real-time service module determines whether the target application is a long keep-alive application. If the target application is a long keep-alive application, S806 is executed; if the target application is not a long keep-alive application, S803 is executed.

[0136] The electronic device is stored in the long keep-alive application list. The real-time service module can determine whether the target application is a long keep-alive application by determining whether the package name of the target application is included in the long keep-alive application list. In the case that the package name of the target application is included in the long keep-alive application list, it can be determined that the target application is a long keep-alive application; in the case that the package name of the target application is not included in the long keep-alive application list, it can be determined that the target application is not a long keep-alive application.

[0137] Exemplarily, the long-keep-alive application list includes social software A, information reminder B, etc. Among them, when the target application is social software A, it is determined that the target application is a long-keep-alive application; when the target application is sports and health C, the long-keep-alive application list does not include sports and health C, and it is determined that the target application is not a long-keep-alive application. The above description is only an exemplary description and does not constitute a limitation.

[0138] Among them, long-keep-alive applications are applications whose life cycle is still in an active state after the user terminates the application; non-long-keep-alive applications are applications whose life cycle is in a terminated state (from an active state to a terminated state) after the user terminates the application. The following explains the difference between long-keep-alive applications and non-long-keep-alive applications in combination with the interface display and the application life cycle (activity).

[0139] In the case where application A is a long-keep-alive application, when the electronic device displays the user interface of application A (the life cycle of application A is in an active state), the user swipes up to enter the multitasking desktop, which includes the interface card of application A. The user swipes up the interface card of application A in the multitasking desktop to end the execution thread of the current application A (that is, the user ends the operation of running the application). In response to the above-mentioned user operation of ending the running of application A, the electronic device does not end the life cycle of application A, the life cycle of application A is still in an active state in the background, and the activity of application A is not destroyed, that is, the user's processing operation of ending the running of application A does not terminate the life cycle of application A (active state) (long-keep-alive application).

[0140] In the case where application B is not a long-keep-alive application, when the electronic device displays the multitasking desktop interface, including the card interface of application B (the life cycle of application B is in an active state), the user swipes up the card interface of application B in the multitasking desktop to end the current execution thread of application B. In response to the above operation, the electronic device ends the life cycle of application B, the life cycle of application B changes to a terminated state (killed), and the activity of application A is destroyed, that is, the user's processing operation of ending the operation of application B will terminate the life cycle of application B (non-long-keep-alive application).

[0141] It should be noted that the long keep-alive application list can be fixed or change with the user's usage habits, which is not limited in this application. The long keep-alive application list is generally related to the thread management of each application by the device, and the long keep-alive application should include at least one application program, which is not specifically limited.

[0142] S803: The real-time service module obtains the load information of the current system.

[0143] The load information may indicate the current system load level, and may reflect the current system performance and processing resource scheduling. The load information may include one or more of the first core busy rate, the first memory usage, and the processor temperature. The first core busy rate, the first memory usage, and the processor temperature are described in detail below:

[0144] The first core busy state rate is the probability that the core state of the electronic device is busy in the first time period. The core state is the core state of the electronic device processor. The core state can include a busy state and an idle state. The busy state indicates that the corresponding processor core is occupied and is processing tasks; the idle state indicates that the corresponding processor core is not occupied and is idle. The electronic device can obtain the core state of each core according to the first frequency in the first time period, and then calculate the first core busy state rate. The first core busy state rate is the ratio of the number of busy states to the total number of core states. Among them, the first time period can be 30s~5min.

[0145] For example, for an electronic device with 8 cores, the kernel status of the 8 cores is obtained 5 times in 2 minutes, and the total number of kernel status is 40; if 24 kernels are busy, the busy rate of the first kernel is 24 / 40=60%. If 32 kernels are busy, the busy rate of the first kernel is 32 / 40=80%. The above calculation process of the number of memory cores of the electronic device and the busy rate of the first kernel are all examples and are not limited.

[0146] The first memory usage is the ratio of the memory occupied by the electronic device to the total memory. The first memory usage may be the most recently acquired memory usage, or may be the average of the memory usage acquired in the most recent second period.

[0147] The processor temperature may be a temperature value of a processor in the electronic device. The first processor temperature may be the most recently acquired processor temperature, or may be an average value of the processor temperatures acquired in the most recent third period.

[0148] S804: The real-time service module determines whether the load state is high load. If the load state is high load, the electronic device executes S805; if the load state is low load (not high load), the electronic device executes S806.

[0149] The load state includes two states: high load and low load. The electronic device can determine whether the current load level is high load based on the load information.

[0150] The electronic device determines whether the current load state is a high load by judging whether the load information satisfies the first condition. If the first condition is met, the load state is a high load; otherwise, it is a low load. The first condition may include at least one of the following three conditions. If all conditions included in the first condition are met, the electronic device may determine that the first condition is met; if one or more conditions (at least one condition) are not met, it may be determined that the first condition is not met. The following is a description of the three conditions that may be included in the first condition:

[0151] Condition 1: The first core busy state rate is less than or equal to (smaller than) a threshold core busy state rate.

[0152] The electronic device is provided with a threshold kernel busy state rate, and the electronic device determines whether the first kernel busy state rate is less than or equal to (less than) the threshold kernel busy state rate. When the first kernel busy state rate is less than or equal to (less than) the threshold kernel busy state rate, the electronic device determines that condition 1 is satisfied; when the first kernel busy state rate is greater than (greater than or equal to) the threshold kernel busy state rate, the electronic device determines that condition 1 is not satisfied, and the first condition is not satisfied. The threshold kernel busy state rate can be set to 50% to 95%.

[0153] Electronic devices can collect the kernel status in the recent period of time and count the probability of the busy state, so as to accurately determine the level of system load and ensure the accuracy and effectiveness of load status measurement.

[0154] Condition 2: The first memory usage is less than or equal to (smaller than) a threshold memory usage.

[0155] The electronic device may be provided with a threshold memory usage. The electronic device determines whether the first memory usage is less than or equal to (less than) the threshold memory usage. When the first memory usage is less than or equal to (less than) the threshold memory usage, it may be determined that condition 2 is satisfied. When the first memory usage is greater than (greater than or equal to) the threshold memory usage, it may be determined that condition 2 is not satisfied and the first condition is not satisfied.

[0156] The threshold memory usage can be set to 50% to 90%. For example, if the threshold memory usage is 70%, if the first memory usage is 80%, condition 2 is not met; if the first memory usage is 60%, condition 2 is met.

[0157] Memory usage is a direct reflection of system load conditions. Electronic devices can determine the load status by the amount of memory usage, thus ensuring the accuracy and effectiveness of load status measurement.

[0158] Condition 3: The processor temperature is less than or equal to (smaller than) the threshold temperature.

[0159] The electronic device may be set with a threshold temperature. The electronic device determines whether the processor temperature is less than or equal to (less than) the threshold temperature. When the processor temperature is less than or equal to (less than) the threshold temperature, it may be determined that condition 2 is satisfied. When the processor temperature is greater than (greater than or equal to) the threshold temperature, it may be determined that condition 3 is not satisfied and the first condition is not satisfied. The threshold temperature may range from 30 degrees Celsius to 50 degrees Celsius.

[0160] Among them, the higher the processing load, the higher the processor temperature, so the temperature can indirectly reflect the operating status of the processor, and the load status can be effectively judged by the temperature.

[0161] S805: The real-time service module determines that the target compilation mode is the first compilation mode.

[0162] The process of interpreting and executing the first file by the interpreter is not performed during the compilation process of the first compilation mode. For example, the first compilation mode is the verify compilation mode.

[0163] Specifically, when the target application is not a long keep-alive application and the load state is high load, the target compilation mode is determined to be the first compilation mode.

[0164] S806: The real-time service module determines that the target compilation mode is the second compilation mode.

[0165] The compilation process of the second compilation mode includes the process of interpreting and executing the first file by the interpreter. For example, the second compilation mode is the speed-profile compilation mode or the speed compilation mode.

[0166] Specifically, when the target application is a long keep-alive application; or when the target application is not a long keep-alive application and the load state is low load, the target compilation mode is determined to be the second compilation mode.

[0167] The target compilation mode includes one of a first compilation mode and a second compilation mode. During the installation process of the first compilation mode, verification processing is performed, and compilation optimization processing is not performed. During the installation process of the second compilation mode, compilation optimization processing needs to be performed.

[0168] After the above processing steps S801 to S806 , the electronic device may determine the target compilation mode, and then continue to execute based on the target compilation mode.

[0169] In the embodiment of the present application, the target compilation mode includes a first compilation mode and a second compilation mode. The first compilation mode does not require the bytecode of the installation package to be converted into machine code during installation; the second compilation mode requires the bytecode of the installation package to be converted into machine code during installation.

[0170] S708: The real-time service module sends the target compilation mode information to the ART service.

[0171] After the real-time service module determines the target compilation mode, the target compilation mode information may be sent to the ART service. Correspondingly, the ART service may receive the target compilation mode information from the real-time service module.

[0172] S709: The ART service determines the installation compilation mode based on the second installation request information and the target compilation mode information.

[0173] After receiving the target compilation mode information, the ART service can use the compilation mode of the target application during installation as the target compilation mode, that is, the installation compilation mode as the target compilation mode. The ART service can then perform installation processing on the target application according to the target compilation mode.

[0174] S710: The ART service sends a compilation task request information to the bytecode optimization module.

[0175] After determining the installation compilation mode based on the second installation request information and the target compilation mode information, the ART service may send compilation task request information to the bytecode optimization module.

[0176] The requested compilation task information includes a target compilation mode, which is used to request processing of the target application according to the target compilation mode.

[0177] S711: The bytecode optimization module processes the first file based on the requested compilation task information.

[0178] After the bytecode optimization module receives the compilation task request information, it may process the first file according to the target compilation mode in the compilation task request information.

[0179] When the target compilation mode is the first compilation mode, the first file can be verified, that is, the installation package of the target application can be verified. When the target compilation mode is the second compilation mode, the first file can be compiled and optimized, that is, the first file (DEX file) of the installation package of the target application is interpreted and executed in advance to obtain the second file OAT file (i.e., compilation optimization). In addition, verification processing can also be performed before interpretation and execution.

[0180] S712: The bytecode optimization module sends a first compilation completion notification to the PMS through the ART service.

[0181] After the bytecode optimization module processes the first file based on the installation request information, a first compilation completion notification may be sent to the PMS through the ART service.

[0182] S713: The PMS sends an installation completion notification to the first application.

[0183] After receiving the compilation completion notification, the PMS may send an installation completion notification to the first application. The installation completion notification is used to indicate that the installation of the current target application is complete.

[0184] In addition, after receiving the compilation completion notification, the PMS may also send another installation completion notification to the desktop application to trigger the desktop application to draw and display the icon of the target application.

[0185] S714: The first application displays installation completion information.

[0186] Among them, the processing process of S711~S714 can refer to the relevant content of S507~S510, which will not be repeated here.

[0187] S715: When the target compilation mode is the first compilation mode, the real-time service module obtains load information.

[0188] After executing S707, the electronic device continues to obtain load information (if load parameters are required, the load parameters can also be collected) when the target compilation mode is the first compilation mode. The process of obtaining load information can refer to the relevant contents of S703 and S803, which will not be repeated. When the target compilation mode is not the first compilation mode, the processing of S715~S721 can be omitted, that is, the compilation optimization has been completed.

[0189] It should be noted that, in S715, when the target compilation mode is the first compilation mode, the electronic device will not temporarily delete the compilation optimization related files in the installation package of the target application, and will delete the compilation optimization related files after executing S720. In addition, when the target compilation mode is the second compilation mode, the electronic device can directly delete the compilation optimization related files in the installation package of the target application.

[0190] S716: The real-time service module determines whether the load state is high load. If the load state is high load, S715 can be executed, that is, continue to obtain load information; if the load state is low load, S717 can be executed.

[0191] The processing process of S716 may refer to the relevant content of S804 and will not be described in detail.

[0192] S717: The real-time service module sends the second compilation mode information to the PMS.

[0193] When the load state is low load, the real-time service module sends the second compilation mode information to the PMS. Correspondingly, the PMS receives the second compilation mode information from the real-time service module. The second compilation mode information may include a second compilation mode for requesting to compile the first file of the installation package according to the second compilation mode, that is, to convert the bytecode of the installation package of the target application into machine code.

[0194] S718: The PMS compiles the target application according to the second compilation mode.

[0195] After the PMS receives the second compilation mode information from the real-time service module, it may compile the target application according to the second compilation mode.

[0196] Among them, in the above S715~S718, the electronic device can continue to monitor the load state (loop execution of S715 and S716) when the bytecode of the installation package is not converted into machine code during installation. When the load is low, the compilation process of the second compilation mode is executed to convert the bytecode of the installation package into machine code, which ensures that the target application runs more efficiently after installation, avoids the installation process of the system with a large amount of data processing when the load is high, ensures the smoothness and stability of the system, and improves the user installation experience.

[0197] S719: The PMS sends compilation request information to the bytecode optimization module through the ART service.

[0198] The compilation request information may include a second compilation mode, which is used to request that the installation package of the target file be compiled and optimized according to the second compilation mode.

[0199] S720: The bytecode optimization module compiles the first file based on the compilation request information to obtain a second file.

[0200] After the bytecode optimization module receives the compilation request information, it can compile the first file based on the installation request information to obtain the second file, that is, it can compile and optimize the DEX file (first file) in the target application installation package according to the second compilation mode, that is, interpret and execute it to obtain the OAT file (second file), and store the OAT file. The OAT file is used for subsequent operation.

[0201] S721: The bytecode optimization module sends a second compilation completion notification to the ART service.

[0202] The second compilation completion notification is used to indicate that the compilation process of the installation package of the target application has been completed according to the second compilation mode.

[0203] Optionally, after executing S721, the user clicks the icon of the target application, and in response to the user's operation of starting the target application, the activity manager AMS starts to create a process of the target application. In the case of recreating the life cycle of the target application, the target application can be run according to the generated second file.

[0204] After executing S713, the electronic device can run the target application. When the application is compiled only according to the first compilation mode and has not yet been compiled according to the second compilation mode, the electronic device needs to interpret and execute the bytecode during operation; if the application has been compiled according to the second compilation mode, the electronic device does not need to interpret and execute the bytecode during operation, but can directly execute the machine code.

[0205] Figure 7 In this way, the electronic device can determine whether to select the first compilation mode that is faster during installation or the second compilation mode that is more efficient during operation based on the long-life state of the installed application and the system load. Since long-life applications rarely end and are rebuilt after their life cycle is in an active state, directly selecting the second compilation mode to install the long-life application can avoid the situation where after installation according to the first compilation mode, even if the second compilation mode is used again, it cannot be run according to the result compiled according to the second compilation mode, which will cause the problem of low long-term operation efficiency of the target application. In addition, for long-life applications, the electronic device needs to detect the system load during the installation process. When the load state is high, it is installed according to the first compilation mode. After installation, continue to wait for the load state to be low before installing according to the second compilation mode. This can reduce the pressure of high load in the memory and improve the smoothness and stability of device operation.

[0206] Combination Figure 7 implementation method, Fig. 9 illustrate Figure 7 In the timing process of compiling and running the processing according to the target application. Fig. 9 It is a schematic diagram of a process of compiling and running an application program exemplarily provided in an embodiment of the present application.

[0207] like Fig. 9As shown, the installation process when the target application is not a long-keep-alive application and the load state of the electronic device is in a high-load state during the installation process. After the electronic device obtains the target application installation request, it determines that the target application is not a long-keep-alive application and the load state is in a high-load state. It uses the verify compilation mode (first compilation mode) to install and can continue to monitor the load state. Optionally, after the target application is installed, if the target application operation request 1 is received, the target application runs in the first mode, and the operation efficiency is low. After a period of operation, the target application end request is obtained, then the life cycle of the target application is ended, and the operation thread of the target application is closed. When the monitored load state changes from high load to low load, the electronic device can compile and optimize according to the speed-profile compilation mode (second compilation mode). After the compilation optimization is completed, the target application operation start request is monitored, that is, the target application runs in the second mode, and the operation efficiency is higher.

[0208] It should be noted that if the target application is a long keep-alive application; or if the target application is not a long keep-alive application and the load state is low, the installation process of the electronic device can refer to Figure 4B The processing process is not described in detail. When the load state is high, the second compilation mode is directly used for installation, and the installation is done in one step, reducing the processing of multiple installation and compilation, and improving the installation efficiency and the execution efficiency after installation. In the above process, the screening of long-keep-alive applications eliminates the situation where the second compilation result cannot be used for a long time after two compilations, ensuring the timeliness of execution after the subsequent two compilations.

[0209] As used in the above embodiments, the term "when..." may be interpreted to mean "if..." or "after..." or "in response to determining..." or "in response to detecting...", depending on the context. Similarly, the phrases "upon determining..." or "if (the stated condition or event) is detected" may be interpreted to mean "if determining..." or "in response to determining..." or "upon detecting (the stated condition or event)" or "in response to detecting (the stated condition or event)", depending on the context.

[0210] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk), etc.

[0211] Those skilled in the art can understand that to implement all or part of the processes in the above-mentioned embodiments, the processes can be completed by computer programs to instruct related hardware, and the programs can be stored in computer-readable storage media. When the programs are executed, they can include the processes of the above-mentioned method embodiments. The aforementioned storage media include: ROM or random access memory RAM, magnetic disk or optical disk and other media that can store program codes.

Claims

1. A method for compiling an application, characterized in that: The method is applied to an electronic device, and the method comprises: In response to a first installation operation on a first target application, when the first target application is not a long-keep-alive application and the load state is a high load, the electronic device installs the first target application through a first compilation mode; the first compilation mode does not perform compilation optimization; the long-keep-alive application is an application that can keep its life cycle in an active state in response to a user's operation of exiting the operation; after the first target application is installed through the first compilation mode, the electronic device determines whether the load state is a low load; the load state is used to indicate the load level of the electronic device's memory; when the load state is not a low load, the electronic device continues to execute the process of determining whether the load state is a low load; when the load state is a low load, the electronic device compiles and optimizes the first target application through a second compilation mode; After the installation of the first target application is completed through the first compilation mode, and before the compilation and optimization of the first target application through the second compilation mode is completed, in response to a first operation of the user starting the first target application, running the first target application according to the installation result of the first compilation mode; after the electronic device compiles and optimizes the first target application through the second compilation mode, if the life cycle of the first target application is in an ended state, in response to a second operation of the user starting the first target application, running the first target application according to the compilation and optimization result of the second compilation mode; When the first target application is the long keep-alive application, the electronic device installs the first target application through the second compilation mode; When the first target application is not the long keep-alive application and the load state is low load, the electronic device installs the first target application through the second compilation mode.

2. The method according to claim 1, characterized in that After the installation of the first target application is completed by the first compilation mode, and before the compilation and optimization of the first target application is completed by the second compilation mode, the electronic device converts the bytecode of the first target application into machine code during the running of the first target application; After the compilation optimization of the first target application is completed by using the second compilation mode, the electronic device directly executes the machine code of the first target application during the running of the first target application.

3. The method according to claim 1 or 2, characterized in that: The method further comprises: In response to a first installation operation on the first target application, the electronic device determines whether the first target application is the long keep-alive application; When the first target application is not the long keep-alive application, the electronic device determines whether the load state is a high load.

4. The method according to claim 3, characterized in that The electronic device determines whether the load state is a high load, including: The electronic device determines whether a first condition is satisfied; the first condition includes at least one of a kernel state condition, a memory usage condition, and a temperature condition; The kernel state condition is a condition that a first kernel busy state rate is less than or equal to a threshold kernel busy state rate, and the first kernel busy state rate is a probability that the kernel state of the electronic device is busy in a first time period; the memory usage condition is a condition that a first memory usage is less than or equal to a threshold memory usage; the temperature condition is a condition that a processor temperature is less than or equal to a threshold temperature; When the first condition is not satisfied, the electronic device determines that the load state is a high load; when the first condition is satisfied, the electronic device determines that the load state is a low load.

5. The method according to claim 4, characterized in that In response to a first installation operation of the first target application, the method further includes: the electronic device starts acquiring a load parameter, the load parameter including one or more of a kernel state of the electronic device, the first memory usage, and the processor temperature; After the electronic device installs the first target application through the first compilation mode, the method further includes: The electronic device obtains load information based on the load parameter; the load information includes a first core busy state rate, a first memory usage, and a processor temperature.

6. The method according to claim 3, characterized in that The electronic device determines whether the first target application is a long keep-alive application, including: The electronic device determines whether the long keep-alive application list includes the application package name of the first target application. If the long keep-alive application list includes the application package name of the first target application, the first target application is a long keep-alive application; if the long keep-alive application list does not include the application package name of the first target application, the first target application is not a long keep-alive application.

7. The method according to claim 1, characterized in that The electronic device comprises a first target application, a package management service PMS, a real-time service module and a bytecode optimization module; In response to a first installation operation on a first target application, when the first target application is not a long keep-alive application and the load state is a high load, the electronic device installs the first target application in a first compilation mode, including: In response to the first installation operation on the first target application, the first target application sends a target application installation request to the PMS, where the target application installation request includes an application package name of the first target application; The PMS sends installation request information to the real-time service module, where the installation request information is used to request installation of the first target application; The real-time service module determines whether the first target application is a long keep-alive application based on the installation request information; if the first target application is not a long keep-alive application, the real-time service module obtains load information, and determines whether the load state is a high load based on the load information; When the load state is high load, the real-time service module sends target compilation mode information to the PMS; the target compilation mode information is used to request installation of the first target application according to the first compilation mode; The PMS installs the first target application according to the first compilation mode based on the target compilation mode information; the PMS sends installation request information to the bytecode optimization module; the bytecode optimization module verifies the first file based on the installation request information, and the bytecode optimization module sends an installation completion notification to the PMS; After the first target application is installed, the electronic device determines whether the load state is low load, including: After the first target application is installed, the real-time service module determines whether the load state is low load; If the load state changes from high load to low load, the electronic device compiles and optimizes the first target application through a second compilation mode, including: When the load state is low load, the real-time service module sends second compilation mode information to the PMS; the second compilation mode information is used to request compilation optimization of the first target application according to the second compilation mode; The PMS compiles the first target application according to the second compilation mode; the PMS sends compilation request information to the bytecode optimization module; the bytecode optimization module compiles the first file based on the compilation request information to obtain a second file, and the bytecode optimization module sends a compilation completion notification to the PMS.

8. An electronic device, characterized in that: include: One or more processors and one or more memories; the one or more processors are coupled to the one or more memories, the one or more memories are used to store computer program codes, the computer program codes include computer instructions, and when the one or more processors execute the computer instructions, the electronic device executes the method as described in any one of claims 1 to 7.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Application program updating method and related device

    CN116088888A

  • Effect taking method and device for compiling optimization file and electronic equipment

    CN117311723A