Compiling method and device
By compiling the dex files of applications or plug-ins in specific scenarios, the problem of interruption of compilation and optimization tasks of electronic devices under complex conditions is solved, and the operation efficiency and user experience of applications or plug-ins are improved.
Patent Information
- Application Number
- CN202311872062.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-29
- Publication Date
- 2025-07-08
AI Technical Summary
In the prior art, electronic devices need to meet complex conditions when batch triggering compilation optimization tasks, and will interrupt the compilation optimization tasks when the screen is turned on or the charger is removed, resulting in the application being unable to compile and optimize, affecting the user experience.
Provides a compilation method, by compiling the dex file based on the first compilation mode in the main process startup, child process startup or plug-in loading scenarios of the application or plug-in, improving the running efficiency of the application or plug-in, including determining whether the compilation mode is lower than the first compilation mode, and compiling processing when the conditions are met.
Improves the startup and loading performance of applications or plug-ins, avoids compilation failures and stability issues, and provides a better user experience.
Smart Images

Figure CN120276735A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of terminals, and in particular, to a compilation method and device. Background Art
[0002] An application (APP) can run in a virtual machine. The execution of application code by the virtual machine includes two parts. The first part is to compile the source code into bytecode, also known as front-end compilation. At this time, the main work is to analyze the lexicon, syntax, and semantics. The second part is to compile the bytecode into machine code for interpretation and execution. However, due to the low efficiency of interpretation and execution, it has a serious impact on the user experience. To solve this problem, dex2oat (dalvik excutable file to optimized art file) came into being. Dex2oat can compile the bytecode of the application into machine code in advance, so that the machine code can be directly executed during actual operation, thus greatly improving the running efficiency of the application.
[0003] Dex2oat includes multiple different compilation modes. Sorted according to the performance of the executed application from high to low, the currently common compilation modes include: the speed compilation mode, the speed-profile compilation mode, the verify compilation mode, etc. Among them, the speed compilation mode compiles and optimizes all the application code, and the resulting product has good performance, but the generated file is large, the time consumption is long, and the mobile phone storage space is consumed more. 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 relatively poor in compilation performance compared with the speed-profile compilation mode.
[0004] Currently, an electronic device (such as an Android mobile phone) can trigger a compilation optimization task in batches (that is, compile and optimize applications in batches). However, triggering a compilation optimization task in batches often requires meeting complex conditions, such as the electronic device entering the idle state, the remaining battery power being greater than or equal to the preset power, and the electronic device being charged, etc. Moreover, the compilation optimization task will be interrupted when the electronic device is lit or the charger is removed, resulting in some applications being unable to be compiled and optimized for a long time, affecting the user experience. Summary of the Invention
[0005] The embodiments of the present application provide a compilation method and device, which can compile the dex file of an application or a plugin, and improve the running efficiency of the application or the plugin when it runs next time.
[0006] To achieve the above object, the embodiments of the present application adopt the following technical solutions:
[0007] In a first aspect, a compilation method is provided, which is applied to an electronic device. The method includes: in response to the electronic device being in a first scenario, determining whether the compilation mode corresponding to a first application or a first plugin is lower than a first compilation mode; if the compilation mode corresponding to the first application or the first plugin is lower than the first compilation mode, performing compilation processing on the dex file of the first application or the first plugin based on the first compilation mode.
[0008] Based on the method provided in the embodiments of the present application, when the electronic device is in the first scenario, the dex file of the first application or the first plugin can be compiled based on the first compilation mode, improving the performance of the application when it runs next time (for example, startup performance, sliding performance, etc.), or improving the performance of the plugin when it is loaded next time.
[0009] In a possible implementation manner, the first scenario includes a scenario where the main process or a child process of the first application is started, or a scenario where the first plugin is loaded. Based on the method provided in the embodiments of the present application, it is possible to compile the dex file of the application or the like in the scenario of starting the application process (starting the main process or a child process), improving the performance of the application when it runs next time (for example, startup performance, sliding performance, etc.). Or, compile the dex file of the plugin in the scenario of loading the plugin, improving the performance of the plugin when it is loaded next time (for example, loading performance).
[0010] In a possible implementation manner, before performing compilation processing on the dex file of the first application or the first plugin based on the first compilation mode, the method further includes: determining whether the first application or the first plugin belongs to a blacklist; if the first application or the first plugin does not belong to the blacklist, performing compilation processing on the first application or the first plugin based on the first compilation mode; where the blacklist includes applications or plugins that do not need to be compiled and / or compilation fails. In this way, it is possible to avoid repeated compilation failures of an application or the first plugin, or to avoid stability problems of the first application or the first plugin.
[0011] In a possible implementation manner, performing compilation processing on the dex file of the first application or the first plugin based on the first compilation mode includes: if the electronic device is in a second scenario, adding the first application or the first plugin to a list of applications to be compiled, the list of applications to be compiled including one or more applications or plugins to be compiled, and performing compilation processing on the first application or the first plugin based on the order of the applications or plugins to be compiled in the list of applications to be compiled. In this way, when the electronic device is in the second scenario, the first application or the first plugin can be added to the list of applications to be compiled, and the first application or the first plugin is triggered to be compiled based on the order of the applications or plugins in the list of applications to be compiled, avoiding affecting the user experience.
[0012] In a possible implementation, the second scenario includes at least one of a sliding scenario, an animation display scenario, a startup scenario, an over-the-air (OTA) upgrade scenario, and a user switching scenario.
[0013] In a possible implementation, compiling the dex file of the first application or the first plugin based on the first compilation mode includes: if the status parameter of the electronic device meets the first condition, adjusting the profile file of the first application or the first plugin according to the call order of the hot functions; wherein, the status parameter of the electronic device includes at least one of the current load of the processor of the electronic device, the current temperature of the electronic device, and the remaining battery level of the electronic device. In this way, when the status parameter of the electronic device meets the first condition, the profile file of the first application or the first plugin can be adjusted according to the call order of the hot functions to optimize the execution performance of the first application or the first plugin.
[0014] In a possible implementation, determining whether the compilation mode corresponding to the first application or the first plugin is lower than the first compilation mode includes: determining whether there is an art file corresponding to the first application or the first plugin; the art file is the compilation product corresponding to the first compilation mode; if there is no art file corresponding to the first application or the first plugin, it is determined that the compilation mode corresponding to the first application or the first plugin is lower than the first compilation mode.
[0015] In a possible implementation, before determining whether the compilation mode corresponding to the first application is lower than the first compilation mode, the method further includes: determining whether there is an odex file corresponding to the first application or the first plugin; if there is an odex file corresponding to the first application or the first plugin, reading the header file of the odex file to obtain the compilation mode corresponding to the first application or the first plugin.
[0016] In a possible implementation, the method further includes: determining whether the number of times the electronic device triggers compilation on the current day exceeds a preset number of times. In this way, the problem of excessive power consumption caused by too many compilation executions of the electronic device can be avoided.
[0017] In a possible implementation, the electronic device includes a condition judgment module, a compilation task control module, and a system thread. Responding to the electronic device being in the first scenario and determining whether the compilation mode corresponding to the first application is lower than the first compilation mode includes: the condition judgment module determines whether the electronic device is in the first scenario. If the electronic device is in the first scenario, it determines whether the compilation mode corresponding to the first application is lower than the first compilation mode; performing compilation processing on the dex file of the first application or the first plugin based on the first compilation mode includes: the condition judgment module sends the package name of the first application or the storage path of the first plugin to the compilation task control module; the compilation task control module sends the first compilation parameter to the system thread; wherein, the first compilation parameter includes the package name of the first application and the identifier of the first compilation mode; or, the first compilation parameter includes the package name of the application corresponding to the first plugin, the information indicating the compilation of the plugin, and the identifier of the first compilation mode; the system thread has the permission to trigger the compilation of the first application or the first plugin. In this way, the system thread can trigger the compilation of the first application or the first plugin, solving the problem that the first application or the first plugin itself has no right to trigger compilation.
[0018] In a possible implementation, before the compilation task control module sends the first compilation parameter to the system thread, the method further includes: the compilation task control module adds the first compilation parameter to the to-be-compiled list and triggers the compilation of the first application or the first plugin based on the order of the to-be-compiled list.
[0019] In a possible implementation, the electronic device further includes a first compilation processing module, a second compilation processing module, a third compilation processing module, and a compilation module. The method further includes: the system thread sends the first compilation parameter to the first compilation processing module; the first compilation processing module sends the second compilation parameter to the second compilation processing module; wherein, the second compilation parameter includes the package name of the first application, the identifier of the first compilation mode, the compilation priority, and the storage path of the profile file (benchmark configuration file); the second compilation processing module sends the third compilation parameter to the third compilation processing module; wherein, the third compilation parameter includes the package name of the first application, the identifier of the first compilation mode, the file descriptor, the timeout time, the number of threads supported by the compilation, and the number of processor cores supported by the compilation; the third compilation processing module sends the compilation command to the compilation module; wherein, the compilation command includes the package name of the first application, the identifier of the first compilation mode, the timeout time, the number of threads supported by the compilation, and the number of processor cores supported by the compilation; the compilation module parses the compilation command and performs compilation processing on the dex file of the first application or the first plugin.
[0020] Second aspect, the present application provides a chip system, which includes one or more interface circuits and one or more processors. The interface circuits and the processors are interconnected by lines. The above chip system can be applied to an electronic device including a communication module and a memory. The interface circuit is configured to receive a signal from the memory of the electronic device and send the received signal to the processor, and the signal includes computer instructions stored in the memory. When the processor executes the computer instructions, the electronic device can execute the method described in the first aspect and any possible design manner thereof.
[0021] Third aspect, the present application provides a computer-readable storage medium, which includes computer instructions. When the computer instructions run on an electronic device (such as a mobile phone), the electronic device is caused to execute the method described in the first aspect and any possible design manner thereof.
[0022] Fourth aspect, the present application provides a computer program product, which when running on a computer, causes the computer to execute the method described in the first aspect and any possible design manner thereof.
[0023] Fifth aspect, an embodiment of the present application provides a compiling device, which includes a processor. The processor is coupled to a memory, and the memory stores program instructions. When the program instructions stored in the memory are executed by the processor, the device implements the method described in the first aspect and any possible design manner thereof. The device can be an electronic device or a server device; or can be a component of an electronic device or a server device, such as a chip.
[0024] Sixth aspect, an embodiment of the present application provides a compiling device. The device can be divided into different logical units or modules according to functions, and each unit or module performs different functions, so that the device executes the method described in the first aspect and any possible design manner thereof.
[0025] It can be understood that the beneficial effects that can be achieved by the chip system described in the second aspect, the computer-readable storage medium described in the third aspect, the computer program product described in the fourth aspect, and the devices described in the fifth and sixth aspects can refer to the beneficial effects in the first aspect and any possible design manner thereof, which will not be elaborated here. Description of the Drawings
[0026] Figure 1 It is a schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present application;
[0027] Figure 2 It is a schematic diagram of the software architecture of an electronic device provided by an embodiment of the present application;
[0028] Figure 3 Schematic diagram of the software architecture of another electronic device provided by an embodiment of the present application;
[0029] Figure 4 Schematic diagram of module interaction provided by an embodiment of the present application;
[0030] Figure 5 Schematic diagram of display provided by an embodiment of the present application;
[0031] Figure 6 Another schematic diagram of display provided by an embodiment of the present application;
[0032] Figure 7 Schematic diagram of a process provided by an embodiment of the present application;
[0033] Figure 8 Schematic diagram of the structure of a chip system provided by an embodiment of the present application. Detailed implementation manners
[0034] For the sake of clear and concise description of the following embodiments, a brief introduction to relevant concepts or technologies is given first:
[0035] In order to make the applications installed in the electronic device run more smoothly during the running stage, dex2oat can be used to compile the dex files of the applications into machine codes that the electronic device can directly run. Thus, the electronic device can directly load these machine codes during the running process of the applications, making the applications run more smoothly. Among them, the dex files of the applications exist in the Android installation packages (APKs) of the applications and contain all the operation instructions and runtime data of the applications, that is, the dex files contain all the codes of the applications.
[0036] Dex2oat includes multiple different compilation optimization modes. Sorted according to the performance of the executed applications from high to low, the currently common compilation optimization modes include: the compilation mode of speed, the compilation mode of speed-profile, the compilation mode of verify, etc. The comparison of these several typical compilation optimization modes is shown in Table 1.
[0037] Table 1
[0038]
[0039] In the above scenarios, when dex2oat compiles the dex files, one of the multiple compilation modes shown in Table 1 can be adopted.
[0040] Compilation mode of speed: In this compilation mode, dex2oat can perform AOT compilation on all function codes in the dex file to obtain the corresponding compilation products: odex and vdex. The compilation mode of speed compiles and optimizes all program codes, and the obtained products have good performance, but the generated files are large, the compilation time is long, and the mobile phone storage space is consumed more.
[0041] Compilation mode of speed-profile (have profile): In this compilation mode, in addition to performing verification on the dex file to obtain the corresponding odex file, dex2oat will also perform AOT compilation on the function codes specified in the profile file in the dex file of the application according to the information of the specified functions in the profile file to obtain the corresponding compilation product: art file. Among them, the profile file (benchmark configuration file) refers to a file containing information about hot functions (which can also be called hot codes). The art file contains the addresses of these specified function codes, which is convenient for addressing these specified functions. And these specified function codes are the codes of the functions commonly used during the operation of the application. Therefore, during the operation of the application, after the electronic device loads the art file into the memory, it can quickly address and run the found code, thereby making the application run more smoothly.
[0042] Compilation mode of speed-profile (no profile): In this compilation mode, dex2oat verifies the dex file and optimizes the dex instructions in the dex file, thereby obtaining the corresponding odex file, and the optimized dex instructions have higher interpretation performance and can be efficiently recognized by the electronic device.
[0043] Among them, since the compilation mode of speed-profile (no profile) only verifies the dex file and optimizes the dex instructions and does not involve AOT compilation. Therefore, the compilation mode of speed-profile (no profile) has a shorter compilation time compared to the compilation mode of speed-profile (have profile). However, the compilation performance of the speed-profile (no profile) compilation mode is relatively poor compared to the speed-profile (have profile) compilation mode.
[0044] It should be noted that since the compilation mode of speed-profile (no profile) does not require a profile file to be provided, in scenarios where a profile file cannot be provided, dex2oat can choose to use the speed-profile (no profile) compilation mode to compile the dex file of the application, achieving the compilation of the dex file with relatively lower compilation performance compared to the speed-profile (have profile) compilation mode, but shortening the compilation duration compared to the speed-profile (have profile) compilation mode. Scenarios where a profile file cannot be provided include the scenario of the electronic device booting up for the first time, the scenario of the electronic device cloning an application in another device, the scenario of the electronic device being idle and triggering compilation, and the scenario of using an application installation tool that cannot provide a profile file, and so on.
[0045] Among them, in the scenario of the electronic device booting up for the first time, there is no profile file corresponding to the application in the electronic device. Based on this, the electronic device can trigger dex2oat to use the speed-profile (no profile) compilation mode to compile the dex file extracted from the installation package. In the scenario of the electronic device cloning an application in another device, since there is no profile file of the application in the electronic device, the electronic device can trigger dex2oat to use the speed-profile (no profile) compilation mode to compile the dex file extracted from the installation package. In the scenario of the electronic device being idle and triggering compilation, the application may not have collected the corresponding profile file during the historical running process. Thus, the electronic device can trigger dex2oat to use the speed-profile (no profile) compilation mode to compile the dex file of the application. In the scenario of installing an application using an application installation tool, the application installation tool cannot provide the profile file of the application. Thus, the electronic device can trigger dex2oat to use the speed-profile (no profile) compilation mode to compile the dex file of the application.
[0046] Compilation mode of verify: In this compilation mode, dex2oat verifies the dex file to obtain the corresponding odex file. Among them, since only the dex file is verified in the verify compilation mode and it does not involve AOT compilation and dex instruction optimization, therefore, the verify compilation mode has a shorter compilation duration compared to the speed-profile (have profile) compilation mode and the speed-profile (no profile) compilation mode. However, the verify compilation mode has relatively poor compilation performance compared to the speed-profile (have profile) compilation mode and the speed-profile (no profile) compilation mode.
[0047] In the related art, before the Android system is upgraded to the Android 10+ system, an application can actively trigger dex2oat compilation. In the scenario where the application itself triggers compilation, when the self-triggering condition of the application is met, the application triggers dex2oat to compile the dex file of the application through an instruction to obtain the odex file. Based on this, during the operation of the application, the electronic device can directly load and execute the odex file, making the application run more smoothly. However, as the security of the Android system continues to increase, the Android system has removed the entry to trigger dex2oat from the application process and no longer allows the application to actively trigger its own compilation. Only the system itself is allowed to trigger dex2oat compilation (that is, the system batch-compiles the applications for dex2oat).
[0048] Currently, an electronic device (for example, an Android mobile phone) can batch-trigger a compilation optimization task (that is, batch-compile applications for dex2oat). However, batch-triggering a compilation optimization task often requires meeting complex conditions, such as the electronic device entering the idle state, the remaining battery power being greater than or equal to a preset battery power (for example, the remaining battery power reaches 90%), etc. Moreover, the compilation optimization task will be interrupted when the electronic device is turned on or the charger is removed, resulting in some applications being unable to be compiled and optimized for a long time, reducing the smoothness of the application and affecting the user experience.
[0049] This application provides a compilation method and device that can trigger dex2oat compilation of the dex file of an application or a plugin in the application main process startup scenario, sub-process startup scenario, or plugin loading scenario. In this way, the performance (such as startup performance, loading performance, and sliding performance) of the application or plugin during the next startup or loading will be improved, which can bring a better experience to the user.
[0050] Exemplarily, in the following situations, in response to the electronic device being in an application main process startup scenario, a subprocess startup scenario, or a plugin loading scenario, the dex2oat compilation of the application's dex file can be triggered.
[0051] Situation 1: The compilation mode is verify after the application is installed. In the scenario where the electronic device installs an application, the electronic device can download the installation package of the application to be installed from the application market. During the process of executing the installation package to install the application, dex2oat can be triggered to compile the dex file extracted from the installation package of the application (for example, compile in the verify compilation mode) to obtain an odex file.
[0052] Situation 2: The compilation mode is verify after the application is cloned when changing devices. In the scenario where the electronic device clones an application from another device, the electronic device installs the corresponding application locally according to the application installed on the other device. During the process of the electronic device installing these applications, dex2oat can be triggered to compile the dex file of the application cloned to the local electronic device (for example, compile in the verify compilation mode) to obtain an odex file.
[0053] Situation 3: The compilation mode is verify after the electronic device is upgraded. For example, in the scenario where the electronic device performs an over-the-air (OTA) upgrade, during the first restart process of the electronic device after the system upgrade is completed, the dex files of each application in the electronic device are recompiled (for example, compile in the verify compilation mode) to obtain an odex file.
[0054] Situation 4: The odex file of the application is deleted or invalidated under certain circumstances.
[0055] Figure 1 This is a schematic structural diagram of an electronic device 100 provided by an embodiment of the present application.
[0056] As Figure 1As shown in the figure, 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, a headphone jack 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.
[0057] Among them, the sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric 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.
[0058] It can be understood that the structure illustrated in this embodiment does not constitute a specific limitation on the electronic device 100. In other embodiments, the electronic device 100 may include more or fewer components than shown in the figure, or combine certain components, or split certain components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0059] The processor 110 may include one or more processing units. For example, the processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Among them, different processing units may be independent devices or integrated in one or more processors.
[0060] The controller may be the nerve center and command center of the electronic device 100. The controller may generate operation control signals according to the instruction operation code and timing signals to complete the control of fetching instructions and executing instructions.
[0061] A memory may also be provided in the processor 110 for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory may hold instructions or data that the processor 110 has just used or recycled. If the processor 110 needs to use the instruction or data again, it can be directly called from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0062] In some embodiments, the processor 110 may include one or more interfaces. The interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0063] It can be understood that the interface connection relationships between the modules illustrated in this embodiment are only illustrative descriptions and do not constitute a structural limitation on the electronic device 100. In other embodiments, the electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
[0064] The charging management module 140 is configured to receive a charging input from a charger. While charging the battery 142, the charging management module 140 can also power the electronic device through the power management module 141.
[0065] The power management module 141 is used to connect the battery 142, the charging management module 140, and the processor 110. The power management module 141 receives inputs from the battery 142 and / or the charging management module 140 and supplies power to the processor 110, the internal memory 121, the external memory, the display screen 194, the camera 193, the wireless communication module 160, etc. In some other embodiments, the power management module 141 may also be disposed in the processor 110. In some other embodiments, the power management module 141 and the charging management module 140 may also be disposed in the same device.
[0066] The wireless communication function of the electronic device 100 can be implemented by the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modulation and demodulation processor, and the baseband processor, etc.
[0067] The antenna 1 and the antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in the electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be multiplexed to improve the utilization rate of the antennas. For example, the antenna 1 can be multiplexed as the diversity antenna of the wireless local area network.
[0068] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc. applied to the electronic device 100. The mobile communication module 150 may include at least one filter, switch, power amplifier, low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves through the antenna 1, filter, amplify, etc. the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor and convert it into electromagnetic waves through the antenna 1 for radiation.
[0069] The modulation and demodulation processor may include a modulator and a demodulator. Among them, the modulator is used to modulate the low-frequency baseband signal to be transmitted into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. Subsequently, the demodulator transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After being processed by the baseband processor, the low-frequency baseband signal is transmitted to the application processor. The application processor outputs sound signals through an audio device (not limited to the speaker 170A, the receiver 170B, etc.), or displays images or videos through the display screen 194.
[0070] The wireless communication module 160 may provide solutions for wireless communications applied to the electronic device 100, including wireless local area networks (WLANs) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite systems (GNSSs), frequency modulation (FM), near field communication (NFC), infrared (IR), and so on. The wireless communication module 160 may be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, performs frequency modulation and filtering processing on the electromagnetic wave signals, and sends the processed signals to the processor 110. The wireless communication module 160 may also receive signals to be sent from the processor 110, perform frequency modulation and amplification on them, and convert them into electromagnetic waves through the antenna 2 for radiation.
[0071] In some embodiments, antenna 1 of electronic device 100 is coupled to mobile communication module 150, and antenna 2 is coupled to wireless communication module 160, such that electronic device 100 can communicate with a network and other devices through wireless communication technologies. The wireless communication technologies may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technology, etc. The GNSS may include global positioning system (GPS), global navigation satellite system (GLONASS), beidou navigation satellite system (BDS), quasi-zenith satellite system (QZSS), and / or satellite based augmentation systems (SBAS).
[0072] Electronic device 100 implements a display function through a GPU, display screen 194, and an application processor, etc. The GPU is a microprocessor for image processing, connected to display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or change display information.
[0073] 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), a light-emitting diode (LED), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a Miniled, a MicroLed, a Micro-oLed, a quantum dot light-emitting diode (QLED), etc.
[0074] The electronic device 100 can implement the shooting function through the ISP, the camera 193, the video codec, the GPU, the display screen 194, and the application processor, etc. The ISP is used to process the data fed back by the camera 193. The camera 193 is used to capture static images or videos. The digital signal processor is used to process digital signals. In addition to processing digital image signals, it can also process other digital signals. The video codec is used to compress or decompress digital videos. The electronic device 100 can support one or more video codecs. In this way, the electronic device 100 can play or record videos in multiple coding formats, such as: Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.
[0075] The camera 193 can include 1 to N. For example, the electronic device can include 2 front cameras and 4 rear cameras.
[0076] The NPU is a neural-network (NN) computing processor. By learning from the biological neural network structure, such as learning from the transmission mode between human brain neurons, it can quickly process the input information and can also continuously self-learn. Through the NPU, applications such as the intelligent cognition of the electronic device 100 can be realized, such as: image recognition, face recognition, speech recognition, text understanding, etc.
[0077] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to implement the storage capacity expansion of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement the data storage function. For example, files such as music and videos are saved in the external memory card. The internal memory 121 can be used to store computer-executable program codes, and the executable program codes include instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. For example, in the embodiment of the present application, the processor 110 can execute the instructions stored in the internal memory 121. The internal memory 121 can include a program storage area and a data storage area. Among them, the program storage area can store an operating system, applications required for at least one function (such as a sound playback function, an image playback function, etc.). The data storage area can store data created during the use of the electronic device 100 (such as audio data, a phone book, etc.). In addition, the internal memory 121 can include a high-speed random access memory and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.
[0078] The electronic device 100 can implement audio functions through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone interface 170D, and the application processor, etc. For example, music playback, recording, etc.
[0079] The audio module 170 is used to convert digital audio information into an analog audio signal for output, and is also used to convert an analog audio input into a digital audio signal. The audio module 170 can also be used for encoding and decoding audio signals. The speaker 170A, also known as the "loudspeaker", is used to convert an audio electrical signal into a sound signal. The receiver 170B, also known as the "earpiece", is used to convert an audio electrical signal into a sound signal. The microphone 170C, also known as the "microphone", "transmitter", is used to convert a sound signal into an electrical signal. The headphone interface 170D is used to connect a wired headphone.
[0080] The button 190 includes a power-on button, volume buttons, etc. The button 190 can be a mechanical button or a touch button. The electronic device 100 can receive button inputs and generate key signal inputs related to the user settings and function controls of the electronic device 100. The motor 191 can generate vibration prompts. The motor 191 can be used for incoming call vibration prompts and also for touch vibration feedback. The indicator 192 can be an indicator light and can be used to indicate the charging status, power change, and can also be used to indicate messages, missed calls, notifications, etc. The SIM card interface 195 is used to connect the SIM card. The SIM card can be in contact with and separated from the electronic device 100 by inserting or removing it from the SIM card interface 195. The electronic device 100 can support 1 or N SIM card interfaces, where N is a positive integer greater than 1. The SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, etc.
[0081] The methods in the following embodiments can all be implemented in the electronic device 100 with the above hardware structure.
[0082] The software system of the above electronic device 100 can adopt a layered architecture, event-driven architecture, microkernel architecture, microservices architecture, or cloud architecture. In the embodiments of the present invention, taking the Android system with a layered architecture as an example, the software structure of the electronic device 100 is exemplarily described.
[0083] The layered architecture divides the software into several layers, and each layer has a clear role and division of labor. The layers communicate with each other through interfaces. In some embodiments, the Android system can include an application layer, an application framework layer, Android runtime, system libraries, a hardware abstraction layer (HAL), and a kernel layer. It should be noted that the embodiments of the present application take the Android system as an example for illustration. In other operating systems (such as HarmonyOS, IOS system, etc.), as long as the functions implemented by each functional module are similar to those of the embodiments of the present application, the solutions of the present application can also be implemented.
[0084] Among them, the application layer can include a series of application packages.
[0085] As Figure 2 shown, the application packages can include applications such as a camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, lock screen application, settings application, etc. Of course, the application layer can also include other application packages, such as an application market (such as ) etc., which are not limited in this application.
[0086] The application framework layer provides application programming interfaces (APIs) and programming frameworks for applications in the application layer. The application framework layer includes some predefined functions. For example, it may include an activity manager, a window manager, a content provider, a view system, a resource manager, a notification manager, etc. The embodiments of this application do not impose any restrictions on this.
[0087] In the embodiments of this application, the application framework layer may provide a package management service (PMS), which at least includes: a condition judgment module, a compilation task control module, and a system thread (e.g., android.bg).
[0088] Among them, the condition judgment module is used to judge whether the current is in the first scenario. The first scenario may be an application startup scenario (i.e., the main process startup scenario of the application), a subprocess startup scenario, etc. If the current is in the first scenario, the condition judgment module determines whether the compilation mode of the first application is lower than the first compilation mode. If the compilation mode of the first application is lower than the first compilation mode (e.g., the compilation mode of speed-profile(have profile)), the condition judgment module sends the package name of the first application to the compilation task control module.
[0089] The compilation task control module is used to determine the compilation type and compilation timing corresponding to the first application. Among them, the compilation type is used to indicate whether to perform compilation rearrangement. The compilation task control module may also send the first compilation parameter to the system thread. Among them, the first compilation parameter may include the package name of the first application, the compilation type, the identifier of the first compilation mode, etc.
[0090] The compilation task control module may also add the first compilation parameter to the list of applications to be compiled, and trigger the first application to be compiled based on the order of the applications or plugins to be compiled in the list of applications to be compiled.
[0091] The compilation task control module may also send the first compilation parameter to the system thread.
[0092] The system thread has the permission to trigger an application (the first application) or a plugin (the first plugin) to be compiled. The system thread may trigger the first application or the first plugin to be compiled according to the first compilation parameter received from the compilation task control module.
[0093] The system library may include multiple functional modules. For example: surface manager, Media Libraries, 3D graphics processing library (e.g., OpenGL ES), 2D graphics engine (e.g., SGL), etc.
[0094] The Surface Manager is used to manage the display subsystem and provides the fusion of 2D and 3D layers for multiple applications.
[0095] The media library supports the playback and recording of multiple common audio and video formats, as well as static image files, etc. The media library can support multiple audio and video coding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0096] OpenGL ES is used to implement three-dimensional graphics drawing, image rendering, synthesis, and layer processing, etc.
[0097] The system library may also include the Android Runtime (ART). ART includes the core library and the virtual machine. The core library consists of two parts: one part is the functional functions that need to be called by the Java language, and the other part is the core library of Android. The application layer and the application framework layer run in the 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. The Android runtime is responsible for the scheduling and management of the Android system.
[0098] In the embodiment of the present application, the system library may also include a first compilation processing module (art Service), a second compilation processing module (artd), a third compilation processing module (art_exec), and a compilation module (dex2oat process).
[0099] The first compilation processing module (art Service): is used to parse the parameters (the first compilation parameters) passed in by the system thread, perform pre-compilation checks, supplement other parameters required for compilation (such as compilation priority, storage path of the profile file, etc.), and then pass the parameters to the second compilation processing module (artd).
[0100] The second compilation processing module (artd): can package information such as the timeout time, the number of threads supported for compilation, the CUP cores supported for compilation, and file descriptors, together with information such as the package name of the first application, the compilation type, and the identifier of the first compilation mode included in the second compilation parameters, and send them as the third compilation parameters to the third compilation processing module (art_exec).
[0101] The third compilation processing module (art_exec): can parse the third compilation parameters to obtain the art_exec parameters and the compilation command. The third compilation processing module can create a dex2oat process according to the art_exec parameters and send the compilation command to the dex2oat process.
[0102] Compilation module (dex2oat process): It can be used to parse compilation commands and compile the dex files of the first application.
[0103] The HAL layer is a wrapper for the Linux kernel driver, providing interfaces upward and shielding the implementation details of the underlying hardware.
[0104] The HAL layer may include Wi-Fi HAL, audio HAL, Camera HAL, etc.
[0105] The kernel layer is the layer between hardware and software. The kernel layer at least includes a display driver, a camera driver, an audio driver, and a sensor driver.
[0106] The hardware layer includes a display, a camera, sensors, etc.
[0107] Next, the technical solutions in the embodiments of the present application will be described in conjunction with the accompanying drawings in the embodiments of the present application. Among them, in the description of the present application, unless otherwise specified, "at least one" means one or more, and "multiple" means two or more than two. In addition, in order to clearly describe the technical solutions in the embodiments of the present application, in the embodiments of the present application, terms such as "first" and "second" are used to distinguish the same items or similar items with basically the same functions and effects. Those skilled in the art can understand that the terms "first", "second", etc. do not limit the quantity and execution order, and the terms "first", "second", etc. do not necessarily limit to be different.
[0108] For ease of understanding, the compilation method provided in the embodiments of the present application will be specifically introduced below in conjunction with the accompanying drawings.
[0109] Next, the software modules involved in the application compilation method provided in the embodiments of the present application and the interactions between the modules will be described.
[0110] As Figure 3As shown in the figure, the condition judgment module can judge whether the current state is the first scenario. The first scenario may include the first application startup scenario (i.e., the main process startup scenario of the first application), the subprocess startup scenario of the first application, and the first plugin loading scenario, etc. If the current state is the first scenario, the condition judgment module determines whether the compilation mode of the first application or the first plugin is lower than the first compilation mode. If the compilation mode of the first application or the first plugin is lower than the first compilation mode (for example, the compilation mode of speed-profile(have profile)), the condition judgment module sends the package name of the first application or the storage path of the first plugin to the compilation task control module. The compilation task control module can determine the compilation type corresponding to the first application or the first plugin. Among them, the compilation type can indicate whether to perform compilation rearrangement. The compilation task control module can also send the first compilation parameter to the system thread. Among them, the first compilation parameter can include the package name of the first application (or the storage path of the first plugin), the compilation type, the identifier of the first compilation mode, etc. The system thread can send the first compilation parameter to the first compilation processing module (art service). The first compilation processing module (art service) can parse the parameter passed by the system thread (the first compilation parameter), perform pre-compilation checks, and supplement other parameters required for compilation (such as compilation priority, storage path of the profile file, etc.) to obtain the second compilation parameter, and then pass the second compilation parameter to the second compilation processing module (artd). The second compilation processing module (artd) can package information such as the timeout time, the number of threads supported by compilation, the CPU cores supported by compilation, and file descriptors together with information such as the package name of the first application, the compilation type, and the identifier of the first compilation mode included in the second compilation parameter into the third compilation parameter, and send it to the third compilation processing module (art_exec). The third compilation processing module (art_exec) can parse the third compilation parameter to obtain the artexec parameter and the compilation command. The third compilation processing module can create a dex2oat process according to the artexec parameter and send the compilation command to the dex2oat process. The compilation module (dex2oat process) can parse the compilation command and perform compilation processing on the dex file of the first application.
[0111] As Figure 4 shown in the figure, an embodiment of the present application provides a compilation method, including:
[0112] 401. The condition judgment module judges whether the current state is the first scenario.
[0113] Among them, the first scenario may be the main process startup scenario (i.e., the cold startup scenario of the first application) or the subprocess startup scenario of an application (for example, the first application). Alternatively, the first scenario may be the plugin loading scenario (for example, the first plugin).
[0114] For example, taking the first application as the gallery application, as shown in (a) of Figure 5 , in response to the user's operation on the icon 402 corresponding to the gallery application on the desktop 401, the gallery application is launched, that is, the current is in the application launch scenario. After the gallery application is launched, as shown in (b) of Figure 5 , the mobile phone can display the interface 450. The interface 450 may include thumbnails of photos or videos.
[0115] Again, for example, as shown in (a) of Figure 6 , in response to the user's operation (such as a click operation) on the plugin option 602 in the settings interface 601 of the chat application, as shown in (b) of Figure 6 , the mobile phone can display the interface 603. The interface 603 may include several plugins, such as plugin 1 and plugin 2. Each plugin corresponds to a usage control. In response to the user's operation on the usage control 604 of plugin 1 (the first plugin), the mobile phone can load the plugin, that is, the current is in the plugin loading scenario.
[0116] In a possible design, the condition judgment module can judge whether the current is in the first scenario by the way of "instrumentation".
[0117] Exemplarily, the condition judgment module can "instrument" in the startup function of the application, that is, insert an instrumentation function into the insertion point of the startup function of the application in advance. When the execution reaches the insertion point of the startup function of the application, the instrumentation function is executed, and thus it can be recognized in real time that the scenario of the application is the application launch scenario.
[0118] 402. The condition judgment module determines whether the compilation mode of the first application or the first plugin is lower than the first compilation mode.
[0119] That the compilation mode of the first application or the first plugin is lower than the first compilation mode means that the performance of the compilation mode of the first application or the first plugin is lower than the performance of the first compilation mode. For example, if the compilation mode of the first application or the first plugin is the compilation mode of verify or speed-profile(no profile), and the first compilation mode is the compilation mode of speed-profile(have profile), then the compilation mode of the first application or the first plugin is lower than the first compilation mode. In a possible design, the condition judgment module can determine whether there is an art file corresponding to the first application or the first plugin; the art file is the compilation product corresponding to the first compilation mode; if there is no art file corresponding to the first application or the first plugin, it is determined that the compilation mode corresponding to the first application or the first plugin is lower than the first compilation mode.
[0120] In a possible design, the condition judgment module can determine whether there is an odex file corresponding to the first application or the first plugin; if there is an odex file corresponding to the first application or the first plugin, read the header file of the odex file to obtain the compilation mode corresponding to the first application or the first plugin. Compare the compilation mode corresponding to the first application or the first plugin with the first compilation mode to determine whether the compilation mode corresponding to the first application or the first plugin is lower than the first compilation mode.
[0121] In some embodiments, the condition judgment module can query whether the first application or the first plugin belongs to the blacklist. If the first application or the first plugin belongs to the blacklist, there is no need to compile the first application or the first plugin to avoid stability problems of the first application or the first plugin. Among them, the blacklist can include the package names of applications that do not need to be compiled or the storage paths of plugins. Exemplarily, the applications that do not need to be compiled can include government affairs applications and financial applications (such as bank applications).
[0122] In some embodiments, when the electronic device performs a system upgrade, the blacklist can be updated, or the cloud server can push a new blacklist to the electronic device.
[0123] If the compilation mode of the first application or the first plugin is lower than the first compilation mode, or the compilation mode of the first application or the first plugin is lower than the first compilation mode and the first application or the first plugin does not belong to the blacklist, step 403 can be executed; otherwise, the process ends.
[0124] 403. The condition judgment module sends the package name of the first application or the storage path of the first plugin to the compilation task control module.
[0125] If the first scenario is the main process startup scenario or the subprocess startup scenario of the first application, the condition judgment module can send the package name of the first application to the compilation task control module. Exemplarily, the package name of the first application can be com.*****.mm.
[0126] If the first scenario is the scenario of loading the first plugin, the condition judgment module can send the storage path of the dex file of the first plugin to the compilation task control module.
[0127] 404. The compilation task control module determines the compilation type corresponding to the first application or the first plugin.
[0128] In some embodiments, the compilation task control module can determine the compilation type corresponding to the first application or the first plugin according to the status parameters of the electronic device.
[0129] Among them, the status parameters of the electronic device may include at least one of temperature, battery power, and CPU load. The compilation types include a first type and a second type. When the compilation type of the first application is the first type, hot functions of the first application or the first plugin can be compiled and rearranged; when the compilation type of the first application is the second type, hot functions of the first application or the first plugin are not compiled and rearranged.
[0130] Among them, compilation rearrangement refers to adjusting the profile according to the call order of hot functions (that is, adjusting the arrangement order of hot functions in the profile) to optimize the execution performance of the first application or the first plugin.
[0131] In some optional ways, when the temperature is lower than the first temperature threshold and the processor load is lower than the first load threshold, it is determined that the compilation type corresponding to the first application is the first type (that is, compilation rearrangement is performed). That is, when the first condition is met (for example, the temperature is lower than the first temperature threshold and the processor load is lower than the first load threshold), the profile file of the first application or the first plugin can be adjusted according to the call order of hot functions.
[0132] When the temperature is higher than or equal to the first temperature threshold and the processor load is higher than or equal to the first load threshold, it is determined that the compilation type corresponding to the first application is the second type (that is, no compilation rearrangement is performed).
[0133] In some embodiments, the compilation task control module can determine the compilation type corresponding to the first application according to the type of the first application. Exemplarily, if the application belongs to a government application or a bank application, it is determined that the compilation type corresponding to the first application is the second type. This is because compilation rearrangement may cause stability problems of the application. Therefore, applications with high stability requirements such as government applications or bank applications may not be compiled and rearranged.
[0134] The compilation task control module can also control the compilation timing. In the case where the electronic device is in a second scenario (such as at least one of an animation display scenario, a boot scenario, an over-the-air (OTA) upgrade scenario, and a user switching scenario), in order to avoid affecting the user experience, a trigger delay can be added to the compilation task. The compilation task control module can add the first compilation parameter to the to-be-compiled list. The to-be-compiled list may include compilation parameters corresponding to multiple applications or plugins. In this way, the first application or the first plugin can be triggered to be compiled based on the order of the applications or plugins in the to-be-compiled list.
[0135] Optionally, in the scenario of starting the main process or a subprocess of the first application, the compilation task control module may determine whether there are plugins to be compiled in the first application. If there are plugins to be compiled in the first application, these plugins to be compiled can be compiled together, without waiting for the plugin loading scenario to trigger plugin compilation, which can reduce the time consumption when the first application loads plugins next time and speed up the application plugin loading speed.
[0136] Optionally, the compilation task control module may also determine whether the number of times of triggering compilation on the electronic device on the current day exceeds a preset number of times. If it does not exceed the preset number of times, step 405 may be executed to trigger the compilation of the first application or the first plugin, otherwise the process ends. In this way, the problem of excessive power consumption caused by the electronic device executing too many compilation times can be avoided.
[0137] 405. The compilation task control module sends the first compilation parameter to the system thread.
[0138] If the first scenario is the scenario of starting the main process or a subprocess of the first application, the first compilation parameter may include the package name of the first application, the compilation type (indicating whether to perform compilation rearrangement), the identifier of the first compilation mode (for example, the compilation mode of speed-profile (have profile)), etc.
[0139] If the first scenario is the scenario of plugin loading, the first compilation parameter may include the package name of the application corresponding to the first plugin, the information indicating the compilation of the plugin, the compilation type (indicating whether to perform compilation rearrangement), the identifier of the first compilation mode (for example, the compilation mode of speed-profile (have profile) or the compilation mode of verify), etc.
[0140] Optionally, the first compilation parameter may further include the status parameter of the electronic device. The status parameter of the electronic device may include at least one of the current load of the processor of the electronic device, the current temperature of the electronic device, and the remaining battery amount of the electronic device.
[0141] 406. The system thread sends the first compilation parameter to the first compilation processing module.
[0142] It should be noted that the system thread has the permission to trigger the compilation of the application (the first application) or the plugin.
[0143] In this way, the system thread can trigger the compilation of the first application or the first plugin, solving the problem that the first application or the first plugin itself has no right to trigger compilation.
[0144] 407. The first compilation processing module sends the second compilation parameter to the second compilation processing module.
[0145] The first compilation processing module can obtain the profile file required for the first compilation mode according to the identifier of the compilation mode (for example, the first compilation mode) carried in the compilation parameters. The first compilation processing module can determine the compilation priority according to the compilation parameters, and the compilation priority is used to indicate the order in which compilations are executed by the CPU.
[0146] The first compilation processing module can package the compilation priority and the storage path of the profile file together with information such as the package name of the first application, the compilation type, and the identifier of the first compilation mode included in the first compilation parameters into second compilation parameters and send them to the second compilation processing module. That is, the second compilation parameters can include the package name of the first application, the compilation type, the identifier of the first compilation mode, the compilation priority, and the storage path of the profile file.
[0147] 408. The second compilation processing module sends third compilation parameters to the third compilation processing module.
[0148] The second compilation processing module can set a timeout for the first application or the first plugin, and the timeout is used to limit the time for dex2oat to compile the first application or the first plugin.
[0149] The second compilation processing module can also determine information such as the number of threads supported for compilation and the CUP cores supported for compilation according to the status parameters of the electronic device. It should be understood that the processor can include multiple types, for example, a large-core processor (large-core CPU), a medium-core processor (medium-core CPU), and a small-core processor (small-core CPU). The processing power of a large-core processor is stronger than that of a medium-core processor, and the processing power of a medium-core processor is stronger than that of a small-core processor. It can be understood that the higher the operating frequency of a processor with stronger processing power, the faster the processing speed. Exemplarily, the operating frequency of a small-core processor can be, for example, 1.8 GHz. The operating frequency of a medium-core processor can be, for example, 2.0 GHz. The operating frequency of a large-core processor can be, for example, 2.6 GHz.
[0150] The second compilation processing module can also generate a file descriptor. Among them, the file descriptor is used to indicate the files on which the compilation depends, and the files on which the compilation depends can include the profile file. Optionally, the files on which the compilation depends can also include some temporary files.
[0151] The second compilation processing module can package information such as the timeout, the number of threads supported for compilation, the CUP cores supported for compilation, and the file descriptor together with information such as the package name of the first application, the compilation type, and the identifier of the first compilation mode included in the second compilation parameters into third compilation parameters and send them to the third compilation processing module. Among them, the third compilation parameters can include the package name of the first application, the compilation type, the identifier of the first compilation mode, the file descriptor, the timeout, the number of threads supported for compilation, the CUP cores supported for compilation, etc.
[0152] In addition, the third compilation parameter may further include an art_exec parameter, and the art_exec parameter is used to create a dex2oat process.
[0153] 409. The third compilation processing module sends a compilation command to the dex2oat process.
[0154] The third compilation processing module may parse the third compilation parameter to obtain the art_exec parameter and the compilation command. The third compilation processing module may create a dex2oat process according to the art_exec parameter and send the compilation command to the dex2oat process.
[0155] Among them, the compilation command may include information such as the package name of the first application, the compilation type, the identifier of the first compilation mode, the timeout, the number of threads supported by the compilation, the CUP cores supported by the compilation, etc.
[0156] 410. The dex2oat process performs compilation processing.
[0157] After receiving the compilation command, the dex2oat process may parse the compilation command and perform compilation processing on the dex file of the first application or the first plugin according to the compilation command. In addition to performing verification processing on the dex file to obtain the corresponding odex file, the dex2oat process will also perform AOT compilation on the code of the hot functions in the dex file of the first application or the first plugin according to the information of the hot functions indicated by the profile file to obtain the corresponding compilation product: the art file. The art file contains the addresses of the codes of these hot functions, which is convenient for addressing these hot functions. And the codes of these hot functions are the codes of the functions commonly used by the first application or the first plugin to run. Thus, during the startup of the first application or the loading of the first plugin, after the electronic device loads the art file into the memory, it can quickly address and run the found code, thereby making the application startup or plugin loading smoother.
[0158] Next, taking the scenario where the main process of the first application is started in the first scenario as an example, the complete process of the method provided in the embodiments of the present application will be described.
[0159] As Figure 7As shown, when the electronic device recognizes the scenario where the main process of the first application starts, it can determine whether the compilation mode of the first application is lower than the first compilation mode. If the compilation mode of the first application is not lower than the first compilation mode, it can return (ending the process). If the compilation mode of the first application is lower than the first compilation mode, it determines whether the main process of the first application is a foreground process (to avoid the first application exiting immediately after being launched due to accidental user touches). If the main process of the first application is not a foreground process, it can return. If the main process of the first application is a foreground process, it can wait for a preset duration (e.g., 5s) to allow the main thread of the first application to perform processing such as loading hot functions. To avoid the main thread of the first application having been compiled during the waiting period, after waiting for the preset duration, it can check whether the main thread of the first application has been compiled. If the main thread of the first application has not been compiled, it can detect whether the first application has a profile file (benchmark configuration file). If the profile file is not detected, it can increment the detection count (i.e., the number of times of detecting whether there is a profile file) by 1 and determine whether the detection count is greater than the preset count (e.g., 25 times). If the detection count is less than 25 times, it can detect again whether the first application has a profile file at intervals of a preset time (e.g., 2s). If the profile file of the first application is detected, it can send the package name of the first application to the compilation task control module. Additionally, if the detection count is greater than 25 times, it can return. The compilation task control module can determine whether the number of compilations triggered on the current day exceeds the preset count. If it exceeds the preset count, it can return. If it does not exceed the preset count, it can determine whether the first application has triggered a compilation failure before (i.e., whether the first application belongs to the blacklist). If the first application has triggered a compilation failure before, it can return. If the first application has not triggered a compilation failure before, it determines whether the current scenario is a scenario that requires waiting (the second scenario). Scenarios that require waiting include a sliding scenario, an animation display scenario, a power-on scenario, an OTA upgrade scenario, a user switching scenario, etc. If the current scenario is a scenario that requires waiting, it can add the compilation parameters corresponding to the first application (the first compilation parameters) to the list of applications to be compiled. If the current scenario is not a scenario that requires waiting, it can send the first compilation parameters to the system thread, and the system thread can send a compilation command to the dex2oat process. For example, the system thread can send a compilation command to the dex2oat process through the first compilation processing module, the second compilation processing module, and the third compilation processing module. So that the dex2oat process can perform compilation processing on the dex file of the first application according to the compilation command. After the dex2oat process finishes compilation, it can determine whether there are still remaining applications to be compiled in the list of applications to be compiled. If not, it can return. If there are, it can send the compilation parameters of the remaining applications to be compiled to the system thread. The system thread sends a compilation command for the remaining applications to be compiled to the dex2oat process.The dex2oat process compiles the dex files of the remaining applications to be compiled according to the compilation commands of the remaining applications to be compiled.
[0160] After the first application is compiled based on the compilation method provided by this application, the startup performance of the first application is significantly improved. As shown in Table 2, when the first application is different applications, the cold startup time after the first application is compiled is significantly lower than the cold startup time before compilation, and the performance improvement is obvious.
[0161] Table 2
[0162]
[0163]
[0164] Based on the method provided by the embodiments of this application, it is possible to compile the dex files of an application or in the scenario of an application startup process (starting the main process or a subprocess), and improve the performance of the application during the next run (for example, startup performance, sliding performance, etc.). Or, compile the dex files of a plugin in the plugin loading scenario, and improve the performance of the plugin during the next loading (for example, loading performance). And, since this application triggers the compilation of the plugin when loading the plugin, it is possible to avoid compiling useless plugins.
[0165] Some embodiments of this application provide an electronic device, which may include: a touch screen, a memory, and one or more processors. The touch screen, the memory, and the processor are coupled. The memory is used to store computer program code, and the computer program code includes computer instructions. When the processor executes the computer instructions, the electronic device can execute each function or step executed by the electronic device in the above method embodiments. The structure of the electronic device can refer to Figure 2 the structure of the electronic device 100 shown.
[0166] Embodiments of this application also provide a chip system (for example, a system on a chip (SoC)), as Figure 8 shown, the chip system includes at least one processor 801 and at least one interface circuit 802. The processor 801 and the interface circuit 802 can be interconnected by lines. For example, the interface circuit 802 can be used to receive signals from other devices (for example, the memory of an electronic device). Also for example, the interface circuit 802 can be used to send signals to other devices (for example, the processor 801 or the touch screen of an electronic device). Exemplarily, the interface circuit 802 can read the instructions stored in the memory and send the instructions to the processor 801. When the instructions are executed by the processor 801, the electronic device (for example, a mobile phone) can execute each step in the above embodiments. Of course, the chip system can also include other discrete devices, and the embodiments of this application do not make specific limitations on this.
[0167] The embodiments of the present application also provide a computer-readable storage medium, which includes computer instructions. When the computer instructions run on the above-mentioned electronic device, the electronic device is enabled to execute each function or step that the electronic device (such as a mobile phone) executes in the above-mentioned method embodiments.
[0168] The embodiments of the present application also provide a computer program product. When the computer program product runs on an electronic device, the electronic device (such as a mobile phone) is enabled to execute each function or step that the electronic device executes in the above-mentioned method embodiments.
[0169] Through the description of the above embodiments, those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above function modules is used as an example. In actual applications, the above functions can be allocated to different function modules according to needs, that is, the internal structure of the device is divided into different function modules to complete all or part of the functions described above.
[0170] In several embodiments provided by the present application, it should be understood that the disclosed device and method can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the modules or units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection can be through some interfaces. The indirect coupling or communication connection of the device or unit can be in an electrical, mechanical or other form.
[0171] The unit described as a separated component may or may not be physically separated. The component displayed as a unit may be a physical unit or multiple physical units, that is, it may be located in one place, or may be distributed to multiple different places. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0172] In addition, each functional unit in the various embodiments of the present application can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above integrated unit can be implemented in the form of hardware or in the form of a software functional unit.
[0173] When the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiments of the present application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. The software product is stored in a storage medium and includes several instructions for causing a device (which can be a single-chip microcomputer, a chip, etc.) or a processor to execute all or part of the steps of the methods described in the embodiments of the present application. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard disks, read-only memories (ROM), random access memories (RAM), magnetic disks, or optical discs.
[0174] The above content is only the specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application should be covered by the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A compilation method, characterized in that Applied to an electronic device, the method includes: In response to the electronic device being in a first scenario, determining whether the compilation mode corresponding to a first application or a first plugin is lower than a first compilation mode; If the compilation mode corresponding to the first application or the first plugin is lower than the first compilation mode, performing a compilation process on the dex file of the first application or the first plugin based on the first compilation mode.
2. The method according to claim 1, wherein: Among them, The first scenario includes a scenario where the main process or a subprocess of the first application is started, or a scenario where the first plugin is loaded.
3. The method according to claim 1 or 2, characterized in that, Before performing the compilation process on the dex file of the first application or the first plugin based on the first compilation mode, the method further includes: Determining whether the first application or the first plugin belongs to a blacklist; If the first application or the first plugin does not belong to the blacklist, performing a compilation process on the first application or the first plugin based on the first compilation mode; wherein, the blacklist includes applications or plugins that do not require compilation and / or have compilation failures.
4. The method according to any one of claims 1-3, characterized in that, The performing a compilation process on the dex file of the first application or the first plugin based on the first compilation mode includes: If the electronic device is in a second scenario, adding the first application or the first plugin to a list of applications to be compiled, the list of applications to be compiled including one or more applications or plugins to be compiled, and performing a compilation process on the first application or the first plugin based on the order of the applications or plugins to be compiled in the list of applications to be compiled.
5. The method according to claim 4, wherein: The second scenario includes at least one of a sliding scenario, an animation display scenario, a power-on scenario, an over-the-air (OTA) upgrade scenario, and a user switching scenario.
6. The method according to any one of claims 1-5, characterized in that The performing a compilation process on the dex file of the first application or the first plugin based on the first compilation mode includes: If the status parameter of the electronic device meets a first condition, adjusting the profile file of the first application or the first plugin according to the call order of hot functions; Wherein, the status parameter of the electronic device includes at least one of the current load of the processor of the electronic device, the current temperature of the electronic device, and the remaining battery level of the electronic device.
7. The method according to any one of claims 1-6, characterized in that, The determining whether the compilation mode corresponding to a first application or a first plugin is lower than a first compilation mode includes: Determining whether there is an art file corresponding to the first application or the first plugin; the art file is a compilation product corresponding to the first compilation mode; If there is no art file corresponding to the first application or the first plugin, determining that the compilation mode corresponding to the first application or the first plugin is lower than the first compilation mode.
8. The method according to any one of claims 1 to 6, characterized in that, Before determining whether the compilation mode corresponding to the first application is lower than the first compilation mode, the method further includes: Determining whether there is an odex file corresponding to the first application or the first plugin; If there is an odex file corresponding to the first application or the first plugin, reading the header file of the odex file to obtain the compilation mode corresponding to the first application or the first plugin.
9. The method according to any one of claims 1 - 8, characterized in that, The method further includes: Determine whether the number of times the electronic device triggers compilation on the same day exceeds a preset number of times.
10. The method according to any one of claims 1-9, characterized in that, The electronic device includes a condition judgment module, a compilation task control module, and a system thread. Determining whether the compilation mode corresponding to the first application is lower than the first compilation mode in response to the electronic device being in the first scenario includes: The condition judgment module determines whether the electronic device is in the first scenario. If the electronic device is in the first scenario, it determines whether the compilation mode corresponding to the first application is lower than the first compilation mode. Compiling the dex file of the first application or the first plugin based on the first compilation mode includes: The condition judgment module sends the package name of the first application or the storage path of the first plugin to the compilation task control module. The compilation task control module sends first compilation parameters to the system thread; wherein, the first compilation parameters include the package name of the first application and the identifier of the first compilation mode; or, the first compilation parameters include the package name of the application corresponding to the first plugin, information indicating the compilation of the plugin, and the identifier of the first compilation mode; the system thread has the permission to trigger the compilation of the first application or the first plugin.
11. The method according to claim 10, wherein Before the compilation task control module sends the first compilation parameters to the system thread, the method further includes: The compilation task control module adds the first compilation parameters to the list of applications to be compiled, and triggers the compilation of the first application or the first plugin based on the order of the list of applications to be compiled.
12. The method according to claim 10 or 11, characterized in that The electronic device further includes a first compilation processing module, a second compilation processing module, a third compilation processing module, and a compilation module. The method further includes: The system thread sends the first compilation parameters to the first compilation processing module. The first compilation processing module sends second compilation parameters to the second compilation processing module; wherein, the second compilation parameters include the package name of the first application, the identifier of the first compilation mode, the compilation priority, and the storage path of the profile file. The second compilation processing module sends third compilation parameters to the third compilation processing module; wherein, the third compilation parameters include the package name of the first application, the identifier of the first compilation mode, the file descriptor, the timeout, the number of threads supported for compilation, and the number of processor cores supported for compilation. The third compilation processing module sends a compilation command to the compilation module; wherein, the compilation command includes the package name of the first application, the identifier of the first compilation mode, the timeout, the number of threads supported for compilation, and the number of processor cores supported for compilation. The compilation module parses the compilation command and compiles the dex file of the first application or the first plugin.
13. An electronic device, characterized in that, The electronic device includes a display screen, a processor, and a memory; the memory stores program instructions; the processor is used to run the program instructions stored in the memory, so that the electronic device executes the method according to any one of claims 1-12.
14. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes program instructions that, when run on an electronic device, cause the electronic device to execute the method according to any one of claims 1-12.