Application startup method, electronic device and chip system
By skipping the verification operation, the bytecode is directly compiled and generated machine code, which solves the problem of low application cold start efficiency caused by changes in the operating system version and realizes a faster application startup process.
Patent Information
- Application Number
- CN202510070888.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-16
- Publication Date
- 2025-07-01
- Estimated Expiration
- 2045-01-16
AI Technical Summary
In the prior art, after the operating system version changes, the machine code generated by Dex2oat technology fails, resulting in the application cold start efficiency being reduced and cannot be loaded and executed directly.
After the operating system version changes, the electronic device skips the bytecode operation of the verification application, directly compiles the bytecode, generates a machine code that matches the current operating system version, and loads the machine code for cold start.
It improves the cold start efficiency of the application, reduces the cold start time, and saves the computing power and resources of electronic devices.
Smart Images

Figure CN119473438B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present application relate to the technical field of terminals, and in particular, to an application startup method, an electronic device, and a chip system. Background Art
[0002] For any application, the source code written by a developer is compiled to generate bytecode, which contains the logic and instructions of the application. After the application is installed on the electronic device, the electronic device needs to compile the bytecode to obtain machine code and execute the machine code in order to cold start the application.
[0003] Currently, through the Dex2oat technology, the electronic device pre-compiles the bytecode to obtain machine code and stores the machine code in the.odex file in advance. In this way, when the application needs to be cold started, the electronic device can directly load and execute the machine code in the.odex file, without spending time compiling the bytecode, simplifying the execution steps, saving the execution duration, and being beneficial to improving the cold start efficiency of the application.
[0004] However, the electronic device may encounter a situation where it cannot directly load and execute the machine code in the.odex file, resulting in a decrease in the cold start efficiency of the application. Summary of the Invention
[0005] Embodiments of the present application provide an application startup method, an electronic device, and a chip system, which can improve the cold start efficiency of the application.
[0006] To achieve the above object, the embodiments of the present application adopt the following technical solutions:
[0007] In a first aspect, an application startup method is provided, which is applied to an electronic device. The electronic device includes a first file and a second file of a first application. The first file stores machine code for starting an application program, and the second file stores bytecode of the application program. The method includes: the electronic device receives a first request for starting the first application. In response to the first request, when the first file of the first application fails, the electronic device determines that the version of the operating system of the electronic device has changed. The electronic device skips the operation of verifying the bytecode in the second file of the first application, compiles the bytecode of the first application to obtain the machine code of the first application, and executes the machine code of the first application to start the first application.
[0008] In the above solution, the electronic device skips the operation of verifying the bytecode of the application, so that the electronic device can directly compile the bytecode to obtain the machine code that the electronic device can run, and cold start the application by loading the machine code, saving the application cold start time and improving the application cold start efficiency.
[0009] In a possible implementation of the first aspect, when the power of the electronic device is greater than the first threshold and / or the electronic device is in a charging state, the electronic device may pre-compile the bytecode of the first application in the second file of the first application to obtain the machine code of the first application, and update and store it in the first file of the first application. The electronic device may also pre-compile the bytecode of the second application in the second file of the second application to obtain the machine code of the second application, and update and store it in the first file of the second application.
[0010] In the above solution, when the power of the electronic device is greater than the first threshold and / or the electronic device is in a charging state, the electronic device may batch pre-compile the bytecodes corresponding to multiple applications, so that when the electronic device cold-starts an application subsequently, the electronic device can directly load the machine code corresponding to the application, improving the cold-start efficiency of the application.
[0011] In another possible implementation of the first aspect, in response to a first request, when the first file fails, the electronic device determines that the version of the operating system of the electronic device has not changed. The electronic device verifies the bytecode of the first application in the second file. When the bytecode of the first application passes the verification, the electronic device compiles the bytecode of the first application to obtain the machine code of the first application, and executes the machine code of the first application to start the first application.
[0012] In the above solution, except for the failure of the first file caused by a change in the operating system version, for the failure of the first file caused by other reasons, the electronic device cannot skip the verification operation of the bytecode in the second file, which can ensure the accuracy of the bytecode in the second file, effectively avoid errors in the subsequent bytecode compilation process of the electronic device, and save the computing power of the electronic device.
[0013] In another possible implementation of the first aspect, the process of the electronic device verifying the bytecode is a process of verifying the classes in the bytecode. Specifically, the operations of the electronic device verifying the bytecode of the first application in the second file include at least one of the following: The electronic device verifies whether the bytecode in the second file is legal. The electronic device verifies whether all type conversions and method calls in the second file are legal. The electronic device verifies whether all data structures and code segments in the second file are aligned and whether there are memory access errors. The electronic device verifies the entry points of the methods in the second file, the initialization order of the classes, and the constraints during the operation of the electronic device.
[0014] In the above solution, the electronic device verifying the bytecode of the first application in the second file can ensure the accuracy of the bytecode, effectively avoid errors in the subsequent bytecode compilation process of the electronic device, and save the computing power of the electronic device.
[0015] In another possible implementation of the first aspect, when the identifier of the operating system of the electronic device changes, the operating system is upgraded, or the operating system is restored to the default version.
[0016] In the above solution, by determining whether the identifier of the operating system changes, the electronic device can determine whether the operating system version changes, which is convenient for the subsequent determination of whether the reason for the failure of the first file is caused by the operating system change, and further convenient for the electronic device to determine whether to skip the operation of verifying the bytecode.
[0017] In another possible implementation of the first aspect, the operating system of the electronic device includes an application layer and a runtime layer. The first application is located in the application layer, and the first file management module, the second file management module, and the verification module of the electronic device are located in the runtime layer. The first application responds to the first request and sends a second request to the second file management module. The second request is used to load the second file. The second file management module responds to the second request, loads the second file, and sends a third request to the first file management module. The third request is used to load the first file. In response to the third request, when the first file fails, the second file management module determines whether the version of the operating system of the electronic device has changed. When the version of the operating system of the electronic device has changed, the verification module skips the operation of verifying the bytecode of the first application in the second file. The second file management module compiles the bytecode of the first application to obtain the machine code of the first application and executes the machine code of the first application to start the first application.
[0018] In the above solution, the verification module skips the operation of verifying the bytecode of the application, enabling the electronic device to directly compile the bytecode to obtain the machine code that the electronic device can run, and loading the machine code to cold start the application, saving the application cold start time and improving the application cold start efficiency.
[0019] In a second aspect, the present application provides an electronic device, which includes: a memory and one or more processors. When the processor executes one or more computer programs stored in the memory, the electronic device executes the method in the first aspect and any of its possible implementations.
[0020] In a third aspect, the present application provides an electronic device, which includes: a memory and one or more processors, and the memory is coupled to the processor. Among them, computer program code is stored in the memory, and the computer program code includes computer instructions. When the computer instructions are executed by the processor, the electronic device executes the method in the first aspect and any of its possible implementations.
[0021] Fourthly, the present application provides a chip system, which is applied to an electronic device including a memory and a display screen. The chip system includes: a processor, when the processor executes computer instructions stored in the memory, the chip system is caused to execute the method in the first aspect and any one of its possible implementation manners.
[0022] Fifthly, an embodiment of the present application provides a computer-readable storage medium, which includes computer instructions. When the computer instructions run on an electronic device, the electronic device is caused to execute the method in the first aspect and any one of its possible implementation manners.
[0023] Sixthly, an embodiment of the present application provides a computer program product. When the computer program product runs on a computer, the computer is caused to execute the method in the first aspect and any one of its possible implementation manners. Wherein, the computer may be the electronic device in the second aspect and any one of its possible implementation manners, the electronic device in the third aspect and any one of its possible implementation manners, and the chip system in the fourth aspect and any one of its possible implementation manners.
[0024] It can be understood that for the beneficial effects that can be achieved by the electronic device in the second aspect, the electronic device in the third aspect, the chip system in the fourth aspect, the computer-readable storage medium in the fifth aspect, and the computer program product in the sixth aspect provided above, reference may be made to the beneficial effects in the method in the first aspect and any one of its possible implementation manners, which will not be elaborated herein. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 It is a schematic diagram of the operating state of an electronic device provided by an embodiment of the present application;
[0026] Figure 2 It is a schematic diagram of the principle of an application cold start method provided by an embodiment of the present application;
[0027] Figure 3 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present application;
[0028] Figure 4 It is a schematic diagram of the software system architecture of an electronic device provided by an embodiment of the present application;
[0029] Figure 5 It is a schematic diagram of the flow of an application cold start method provided by an embodiment of the present application;
[0030] Figure 6 It is a schematic diagram of the principle of another application cold start method provided by an embodiment of the present application;
[0031] Figure 7A timing schematic diagram of an application cold start method provided by an embodiment of the present application;
[0032] Figure 8 Another timing schematic diagram of an application cold start method provided by an embodiment of the present application;
[0033] Figure 9 Another schematic diagram of the operating state of an electronic device provided by an embodiment of the present application. Detailed implementation manners
[0034] Hereinafter, the terms "first" and "second" are only used for descriptive purposes, and cannot be construed as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include one or more of such features. In the description of this embodiment, unless otherwise specified, the meaning of "a plurality" is two or more.
[0035] Before introducing the embodiments of the present application, for the convenience of understanding, the following explanations are made for the relevant terms in the embodiments of the present application.
[0036] Machine code is the code that can be understood and run by the operating system on an electronic device.
[0037] Bytecode is an intermediate code. After the source code is compiled by an electronic device, bytecode can be obtained, and then the electronic device compiles the bytecode to obtain machine code.
[0038] The Dex2oat technology is a pre-compilation technology that enables an electronic device to pre-compile bytecode into machine code. Among them, the bytecode is stored in a.dex file, and the pre-compiled machine code is stored in an.odex file. The machine code can be called native code, or native code, and pre-compilation can also be called Ahead-of-Time (AOT) compilation.
[0039] Application cold start refers to the process in which an application program (App) starts from a completely non-running state to start and initialize on a device. Simply put, it is the startup process when a user first opens an application, or the process when the operating system of an electronic device restarts the application for some reason (such as after memory cleaning).
[0040] The following further specifically introduces the embodiments of the present application.
[0041] In some embodiments, the electronic device can precompile bytecode into machine code through the Dex2oat technology, enabling the electronic device to directly load the machine code during operation. For example, during the cold start of an application on the electronic device, through the Dex2oat technology, the electronic device can directly load the machine code to achieve the cold start of the application, and the electronic device no longer needs to compile the bytecode corresponding to the application. Before precompiling the bytecode, the electronic device also needs to verify the bytecode to obtain a verification result, and the electronic device stores the verification result in a.vdex file. Only when the verification passes can the electronic device compile the bytecode to obtain machine code.
[0042] However, the machine code generated by the electronic device through the Dex2oat technology is matched with the current operating system version of the electronic device. For example, when the operating system version of the electronic device is upgraded, or when the operating system of the electronic device is restored to the factory settings and becomes a lower version, the machine code will become invalid, and the electronic device cannot directly load the machine code. In this case, the electronic device will re-verify the bytecode. When the verification passes, the electronic device recompiles the bytecode to obtain machine code that the electronic device can directly run, which results in a decrease in the efficiency during the first cold start of the application.
[0043] Specifically, before the operating system version changes, when the machine code obtained by the electronic device through the Dex2oat technology is matched with the current operating system version, during the cold start of an application on the electronic device, there is no need to perform a verification operation on the class of the bytecode. The electronic device can directly determine that the verification result is correct, and the time for the electronic device to determine the verification result is short. For example, the electronic device only needs 1 ms to determine the verification result.
[0044] Figure 1 This is a schematic diagram of the operating state of an electronic device provided by an embodiment of the present application. As Figure 1 shown in (b) therein, at time t1, after the electronic device receives the operation of the user clicking on the application icon, the electronic device executes the function corresponding to the cold start of the application. During the process of executing the function corresponding to the cold start of the application, the electronic device first initializes the class corresponding to the function. During the process of initializing the class, the electronic device needs to determine the verification result of the class. When the machine code is matched with the current operating system version, that is, when the machine code is valid, the electronic device can directly determine that the verification result of the class is correct, and the time for the electronic device to determine the verification result is short. Subsequently, at time t2, the electronic device completes the cold start of the application. The time interval between t1 and t2 may be 800 ms.
[0045] However, after the operating system version changes, when the machine code obtained by the electronic device through the Dex2oat technology does not match the current operating system version, during the cold start of an application on the electronic device, the electronic device needs to perform a class verification operation and calculate the verification result, and the verification time is relatively long. For example, the electronic device needs 30 ms to complete the verification.
[0046] As Figure 1 shown in (a) of , at time t3, after the electronic device receives the operation of the user clicking on the application icon, the electronic device executes the function corresponding to the cold start of the application. During the execution of the function corresponding to the cold start of the application, the electronic device first initializes the class corresponding to the function. During the initialization of the class by the electronic device, the electronic device needs to perform a class verification operation to obtain the verification result, and the time spent in the verification process is relatively long. Subsequently, at time t4, the electronic device completes the cold start of the application. Among them, the interval between t3 and t4 may be 1000 ms.
[0047] From Figure 1 the (a) and (b) of , it can be seen that after the operating system version of the electronic device changes, the cold start time of the application becomes longer, thereby resulting in a lower cold start efficiency of the application.
[0048] In some embodiments, Figure 2 is a schematic diagram of the principle of an application cold start method provided by an embodiment of the present application. In Figure 2 the (a) of , in order to solve the problem of the reduced cold start efficiency of the application, after the operating system version of the electronic device is updated, the updated operating system version is installed, and after the electronic device is restarted, and before the first cold start of the application, that is, after time t5 and before time t6, the electronic device can batch pre-compile the bytecodes corresponding to each application in the electronic device through the Dex2oat technology, so that after the first cold start of the application, that is, after time t6, the electronic device can directly load the pre-compiled machine code, and the machine code matches the current operating system version of the electronic device.
[0049] However, in this embodiment, before the electronic device batch pre-compiles the bytecodes corresponding to each application, in the case of the first cold start of the application, the electronic device still cannot directly load the machine code, and the cold start efficiency of the application still cannot be improved.
[0050] In other embodiments, in Figure 2In (b) of the above, after the operating system version of the electronic device is updated, the updated operating system version is installed, and the electronic device is restarted, that is, after time t7, when the electronic device performs the first cold start of the application at time t8, the electronic device verifies the bytecode of the application. And in the case where the verification passes, the electronic device compiles the bytecode through the Dex2oat technology to obtain machine code that matches the current operating system version.
[0051] However, in this embodiment, during the first cold start of the application on the electronic device, the electronic device not only needs to re-verify the machine code, but also needs to obtain the machine code through the Dex2oat technology and cold start the application by loading the machine code, and the efficiency of the first cold start of the application has not been improved yet.
[0052] Therefore, the present application provides a method for cold starting an application. When the machine code corresponding to the application on the electronic device becomes invalid due to a change in the operating system version, the bytecode of the application is still valid in this case. Therefore, the electronic device can skip the operation of verifying the bytecode of the application, so that the electronic device can directly compile the bytecode to achieve the cold start of the application and improve the efficiency of the cold start of the application.
[0053] Exemplarily, the above electronic device may be a mobile phone, a tablet computer, a smart remote control, a wearable device (such as a smart bracelet, a smart watch or smart glasses, etc.), a handheld computer, an augmented reality (AR) / virtual reality (VR) device. Or, the mobile phone 500 may also be other types of electronic devices such as a Portable Multimedia Player (PMP), a media player, etc. The specific type of the electronic device in the embodiments of the present application is not limited in any way.
[0054] Figure 3 It is a schematic structural diagram of an electronic device provided by an embodiment of the present application.
[0055] The electronic device 300 may include a processor 310, an external memory interface 320, an internal memory 321, a universal serial bus (USB) interface 330, a charging management module 340, a power management module 341, a battery 342, antenna 1, antenna 2, a mobile communication module 350, a wireless communication module 360, an audio module 370, a sensor module 380, cameras 1 to N 393, and displays 1 to N 394.
[0056] It can be understood that the structure illustrated in the embodiments of the present invention does not constitute a specific limitation on the electronic device 300. In other embodiments of the present application, the electronic device 300 may include more or fewer components than those illustrated, 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.
[0057] The processor 310 may include one or more processing units. For example, the processor 310 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.
[0058] Among them, the controller may be the nerve center and command center of the electronic device 300. The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of fetching and executing instructions.
[0059] A memory may also be provided in the processor 310 for storing instructions and data. In some embodiments, the memory in the processor 310 is a cache memory. This memory can save the instructions or data that the processor 310 has just used or recycled. If the processor 310 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 310, and thus improves the efficiency of the system.
[0060] In some embodiments, the processor 310 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.
[0061] The wireless communication function of the electronic device 300 may be implemented by the antenna 1, the antenna 2, the mobile communication module 350, the wireless communication module 360, the modulation and demodulation processor, and the baseband processor, etc.
[0062] The antenna 1 and the antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in the electronic device 300 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. In some other embodiments, the antenna can be used in combination with a tuning switch.
[0063] The display screen 394 is used to display images, videos, etc. The display screen 394 includes a display panel. The display panel can adopt a liquid crystal display (LCD), 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. In some embodiments, the electronic device 300 may include 1 or N display screens 394, where N is a positive integer greater than 1.
[0064] A video codec is used to compress or decompress digital video. The electronic device 300 can support one or more video codecs. In this way, the electronic device 300 can play or record videos in multiple coding formats, such as: Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.
[0065] The NPU is a neural-network (NN) computing processor. By learning from the structure of biological neural networks, such as learning from the transmission pattern between human brain neurons, it can quickly process input information and can also continuously self-learn. Through the NPU, applications such as intelligent cognition of the electronic device 300 can be realized, such as: image recognition, face recognition, voice recognition, text understanding, etc.
[0066] The external memory interface 320 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 300. The external memory card communicates with the processor 310 through the external memory interface 320 to achieve the data storage function. For example, files such as music and videos are saved in the external memory card.
[0067] The internal memory 321 can be used to store computer-executable program code, and the executable program code includes instructions. The processor 310 executes various functional applications and data processing of the electronic device 300 by running the instructions stored in the internal memory 321. The internal memory 321 can include a program storage area and a data storage area. Among them, the program storage area can store the operating system, application programs required for at least one function (such as the sound playback function, the image playback function, etc.). The data storage area can store the data created during the use of the electronic device 300 (such as audio data, phone book, etc.). In addition, the internal memory 321 can include high-speed random access memory and can also include non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.
[0068] Figure 4 This is a schematic diagram of the software system architecture of an electronic device provided by an embodiment of this application.
[0069] The software system of the electronic device can adopt a layered architecture, an event-driven architecture, a microkernel architecture, a microservices architecture, or a cloud architecture. In this embodiment of the present invention, the Android system with a layered architecture is taken as an example to exemplarily illustrate the software structure of the electronic device.
[0070] The layered architecture divides software into several layers, each layer having a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom: the application layer, the application framework layer, the runtime library layer, and the kernel layer.
[0071] The application layer may include a series of application packages.
[0072] As Figure 4 shown, the application layer may include: system applications and third-party applications. System applications may include: camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message and other applications. Third-party applications may include: shopping applications, dating applications, etc., which are not shown one by one in the figure.
[0073] The application framework layer provides application programming interfaces (APIs) and programming frameworks for the applications in the application layer. The application framework layer includes some predefined functions.
[0074] As Figure 4 shown, the application framework layer may include: window manager, content provider, view system, phone manager, resource manager, notification manager, etc., which are not shown one by one in the figure.
[0075] The runtime library layer may include: a first file management module, a second file management module, and a verification module.
[0076] Among them, the first file management module is used to determine whether the machine code in the first file is invalid.
[0077] The second file management module is used to obtain the bytecode in the second file.
[0078] The verification module is used to verify the bytecode and obtain a verification result.
[0079] The kernel layer is the layer between hardware and software. The kernel layer includes a memory driver, etc. Among them, the memory driver is responsible for managing operations related to the memory (such as hard disk, SSD, etc.). The memory driver enables the electronic device to access the data on the memory by providing a series of interfaces. These interfaces include reading and writing of data, initialization of the device, control of the device, etc.
[0080] As Figure 4As shown in the figure, the hardware on the electronic device may include a memory, and the memory may include a first file and a second file. The electronic device may drive the memory to read the first file and the second file in the memory. Among them, the first file stores the machine code for starting the application program, and the second file stores the bytecode of the application program. When the electronic device uses the Dex2oat technology, the electronic device may pre-compile the bytecode in the second file to obtain the machine code and store it in the first file. Among them, the first file may be an.odex file, and the second file may be a.dex file.
[0081] The cold start method of the application of the present application will be described in detail below with specific drawings.
[0082] Figure 5 It is a schematic flowchart of a cold start method for an application provided by an embodiment of the present application. As Figure 5 shown, the cold start method for the application includes the following steps:
[0083] Step 501: The electronic device receives a first request for starting a first application.
[0084] In this embodiment, the first request may be generated based on a touch operation received by the electronic device or based on a voice operation received by the electronic device. In the embodiments of the present application, the generation method of the first request is not limited.
[0085] For example, after the electronic device receives a touch operation on the icon of the first application, the electronic device obtains the first request based on the touch operation to start the first application.
[0086] Among them, the first application may be a system application on the electronic device or a third-party application. The system application may be system applications such as a camera and a video recorder, and the third-party application may be video applications, shopping applications, etc.
[0087] Step 502: In response to the first request, when the first file of the first application fails, the electronic device determines that the version of the operating system of the electronic device has changed.
[0088] After receiving the first request, the electronic device determines that it is necessary to start the first application. The electronic device may determine whether the first file of the first application fails. When the first file of the first application fails, the electronic device may determine the reason for the failure of the first file. When the reason for the failure is that the version of the operating system of the electronic device has changed, the electronic device executes the following step 503.
[0089] Among them, the electronic device can represent the reason for the failure of the first file through a preset status or a preset value. For example, the electronic device can set the kOatBootImageOutOfDate status to indicate that the failure of the first file is caused by a change in the operating system version.
[0090] Step 503: The electronic device skips the operation of verifying the bytecode in the second file of the first application, compiles the bytecode of the first application to obtain the machine code of the first application, and executes the machine code of the first application to start the first application.
[0091] The electronic device verifying the bytecode means that the electronic device verifies the classes in the bytecode to ensure that the design and implementation of the classes meet the expected requirements, satisfy specific standards or specifications.
[0092] In the case where the operating system version changes, although the machine code fails, the bytecode is still valid, and the verification result of the bytecode does not change. Therefore, in the case where the first file fails due to a change in the operating system version, the electronic device can skip the operation of verifying the bytecode of the first application, directly compile the bytecode to obtain the machine code matching the current operating system version, and start the first application by loading the machine code of the first application to improve the startup efficiency of the first application.
[0093] Among them, the solution of this application can be applied to the first cold start after the application is installed after the operating system version of the electronic device changes. Or, the solution of this application can also be applied to the re-cold start of the application after the first cold start and shutdown of the application after the operating system version of the electronic device changes. Or, the solution of this application can also be applied to the first cold start of the application after the operating system version of the electronic device changes and the electronic device is restarted.
[0094] In the method provided by the embodiments of this application, the electronic device skips the operation of verifying the bytecode of the application, so that the electronic device can directly compile the bytecode to obtain the machine code that the electronic device can run, and cold start the application by loading the machine code, saving the cold start time of the application and improving the cold start efficiency of the application.
[0095] Based on the above description, it can be known that the electronic device skips the verification operation of the bytecode when the operating system version changes and causes the machine code to fail. The following specifically describes how the electronic device determines that the operating system version has changed.
[0096] In some embodiments, when the identifier of the operating system of the electronic device changes, the operating system version is upgraded, or the operating system is restored to the default version.
[0097] Among them, the identifier of the operating system is used to identify the current version of the operating system. The identifier of the operating system may include at least one of the name of the operating system, the id of the operating system, etc. When the operating system version changes, the identifier of the operating system also changes.
[0098] In this embodiment, by determining whether the identifier of the operating system changes, the electronic device can determine whether the operating system version changes, which is convenient for the subsequent determination by the electronic device whether the reason for the failure of the first file is caused by the change of the operating system, and further convenient for the electronic device to determine whether to skip the operation of verifying the bytecode.
[0099] In some embodiments, the electronic device may also include multiple applications. After the operating system version changes, the electronic device may also batch re-precompile the bytecodes corresponding to the multiple applications on the electronic device to obtain the machine codes corresponding to each application.
[0100] Specifically, in some embodiments, when the power of the electronic device is greater than the first threshold and / or the electronic device is in a charging state, the electronic device may precompile the bytecode of the first application in the second file of the first application to obtain the machine code of the first application, and update and store it in the first file of the first application. The electronic device may also precompile the bytecode of the second application in the second file of the second application to obtain the machine code of the second application, and update and store it in the first file of the second application.
[0101] Figure 6 This is a schematic diagram of the principle of another application cold start method provided by the embodiments of the present application. In Figure 6 After the first cold start of the application, that is, after time t9, the electronic device may batch recompile the bytecodes corresponding to multiple applications in the background to obtain the machine codes corresponding to each application that match the current operating system version. After the electronic device generates the machine codes corresponding to each application that match the current operating system version, when the application is cold started again, that is, at time t10, the electronic device may directly load the newly generated machine codes to improve the efficiency of the application cold start.
[0102] Among them, the electronic device may compile the bytecode of the first application and the bytecode of the second application at the same time. The electronic device may also compile the bytecode of the first application first according to the compilation order, then compile the bytecode of the second application, or compile the bytecode of the second application first and then compile the bytecode of the first application. In the embodiments of the present application, no restrictions are imposed on the compilation execution order of the applications in the electronic device.
[0103] When the power consumption of the electronic device is low, for example, when the power consumption is less than 2% of the total power, or when the power of the electronic device is greater than the first threshold, for example, when the power is greater than 60% of the total power, or when the electronic device is in a charging state, the electronic device can recompile the bytecodes corresponding to multiple applications.
[0104] It can be understood that in this embodiment, when the power of the electronic device is greater than the first threshold and / or the electronic device is in a charging state, the electronic device can batch precompile the bytecodes corresponding to multiple applications, so that when the electronic device cold-starts an application subsequently, the electronic device can directly load the machine code corresponding to the application, improving the cold-start efficiency of the application.
[0105] Based on the above description, in some embodiments, in addition to the first file becoming invalid due to a change in the operating system version, the invalidation of the first file can also include various reasons, such as: the first file becomes invalid due to file corruption, the first file becomes invalid due to machine code storage failure, the first file becomes invalid due to the update of the second file, etc. The reasons for the invalidation of the first file are not limited in this application.
[0106] Among them, the invalidation of the first file due to the update of the second file can specifically refer to: after the second file is updated, if the corresponding second file is not updated synchronously, the verification of the first file and the second file does not match, and in this case, the first file becomes invalid. The invalidation of the first file due to file corruption can specifically refer to: file corruption causes the first file or the second file to be unable to be opened.
[0107] The electronic device can represent the reason for the invalidation of the first file through different preset states or different preset values. For example, the electronic device can use the kOatCannotOpen state to indicate that the first file becomes invalid due to file corruption, the electronic device can also use the kOatContextOutOfDate state to indicate that the first file becomes invalid due to storage failure, and the electronic device can also use the kOatDexOutOfDate state to indicate that the first file becomes invalid due to the update of the second file.
[0108] When the first file becomes invalid for reasons other than a change in the operating system version, during the cold start of the application, the electronic device needs to perform an operation of re-verifying the bytecode.
[0109] Specifically, in some embodiments, in response to a first request, when a first file fails, the electronic device determines that the version of the operating system of the electronic device has not changed. The electronic device verifies the bytecode of a first application in a second file. When the bytecode of the first application passes the verification, the electronic device compiles the bytecode of the first application to obtain the machine code of the first application and executes the machine code of the first application to start the first application.
[0110] It can be understood that except for the failure of the first file caused by a change in the operating system version, for the failure of the first file caused by other reasons, the electronic device cannot skip the verification operation of the bytecode in the second file, which can ensure the accuracy of the bytecode in the second file, effectively avoid errors in the subsequent bytecode compilation process of the electronic device, and save the computing power of the electronic device.
[0111] The following will further elaborate on the process of how the electronic device verifies the bytecode.
[0112] In some embodiments, the process of the electronic device verifying the bytecode is a process of verifying the classes in the bytecode. Specifically, the operations of the electronic device for verifying the bytecode of the first application in the second file include at least one of the following: The electronic device verifies whether the bytecode in the second file is legal. The electronic device verifies whether all type conversions and method calls in the second file are legal. The electronic device verifies whether all data structures and code segments in the second file are aligned and whether there are memory access errors. The electronic device verifies the entry points of the methods, the initialization order of the classes, and the constraints during the operation of the electronic device.
[0113] Among them, the types in the second file are used to define the types of data such as variables, function return values, and data structures that can be stored or processed. The types can include basic data types, composite data types, reference types, etc. Type conversion refers to the process of converting the value of one data type to the value of another data type.
[0114] The electronic device verifying whether all type conversions in the second file are legal means that: The electronic device verifies whether the data type conversion process in the second file is compliant. For example, when the electronic device converts an integer type in the basic data type to a floating-point type in the basic data type, this type conversion is not compliant.
[0115] Method call refers to the process of executing a predefined method (function). The electronic device verifying whether method calls in the second file are legal means that: The electronic device verifies whether the process of executing the method (function) is compliant.
[0116] The data structure in the second file refers to the arrangement of data in the second file. The electronic device verifying whether all data structures in the second file are aligned means that the electronic device verifies whether the arrangement of data in the second file is aligned.
[0117] The electronic device can also verify whether all code segments in the second file are aligned.
[0118] The electronic device can also verify whether there are errors during the process of accessing the second file.
[0119] The entry point of a method refers to the starting point of program execution when the method is called. The initialization order of a class is used to determine the initialization timing of elements such as static members, non-static members, properties, code blocks, and constructors in the class. The constraints during the operation of the electronic device mean that the electronic device is subject to various constraints during operation, and these constraints are used to ensure the normal operation of the electronic device and extend the service life of the electronic device, etc.
[0120] The electronic device verifying the entry point of the method, the initialization order of the class, and the constraints during the operation of the electronic device in the second file means that the electronic device verifies whether the entry point of the method in the second file is correct, and verifies whether the initialization order of the class is correct, and verifies whether the electronic device complies with the constraints during the operation process.
[0121] In this embodiment, when the bytecode in the second file is legal, and all type conversions and method calls in the second file are legal, and all data structures and code segments in the second file are aligned, and no memory access errors occur, and the entry point of the method in the second file is correct, and the initialization order of the class is correct, and the operation of the electronic device complies with the constraints, the electronic device passes the verification of the bytecode of the first application in the second file. Conversely, the electronic device fails to pass the verification of the bytecode of the first application in the second file.
[0122] It can be understood that the electronic device verifying the bytecode of the first application in the second file can ensure the accuracy of the bytecode, effectively avoid errors during the subsequent bytecode compilation process of the electronic device, and save the computing power of the electronic device.
[0123] Next, in combination with the above Figure 4 software modules and sequence diagrams, the embodiments of the present application will be described in more detail.
[0124] Next, the process of the electronic device skipping the bytecode verification operation will be specifically described first.
[0125] In some embodiments, in response to a first request, a first application sends a second request to a second file management module, where the second request is used to load a second file. The second file management module responds to the second request, loads the second file, and sends a third request to the first file management module, where the third request is used to load a first file. In response to the third request, when the first file fails, the second file management module determines whether the version of the operating system of the electronic device has changed. When the version of the operating system of the electronic device has changed, the verification module skips the operation of verifying the bytecode of the first application in the second file. The second file management module compiles the bytecode of the first application to obtain machine code of the first application, and executes the machine code of the first application to start the first application.
[0126] Specifically, Figure 7 is a timing diagram of a cold start method for an application provided by an embodiment of the present application. As Figure 7 shown,
[0127] Step 701: The first application sends a request to start the first application to the second file management module.
[0128] Step 702: The second file management module responds to the request to start the first application and opens the second file.
[0129] In some embodiments, regardless of whether the electronic device can directly load the machine code in the first file, when the electronic device starts the first application, it will open the second file. For example, the electronic device can open the second file through the openDexFileNative() function.
[0130] Step 703: The second file management module sends a request to obtain the first file to the first file management module.
[0131] In some embodiments, after the electronic device opens the second file, the second file management module sends a request to obtain the first file to the first file management module to obtain and load the machine code in the first file. For example, the electronic device can obtain the first file through the openDexFileFromOat() function.
[0132] Step 704: The second file management module responds to the request to obtain the first file and sends a request to initialize a class to the verification module.
[0133] In some embodiments, the electronic device can initialize a class through the InitializeClass() function, where the class is the class of the bytecode in the second file.
[0134] Step 705: The verification module responds to the request to initialize the class and verifies the class.
[0135] In some embodiments, when the electronic device initializes a class, it needs to verify the correctness of the class. For example, the electronic device can verify the class through the VerifyClass() function.
[0136] Step 706: The verification module verifies the class through the first file management module.
[0137] For example, the verification module verifies the class through the first file management module by using the VerifyClassUsingOatFile() function.
[0138] Step 707: The first file management module determines whether the first file is invalid.
[0139] In some embodiments, the electronic device can determine whether the first file is invalid through the GetOatClassStatus() function. When the first file is valid, or when the first file becomes invalid due to a change in the operating system version, the verification module does not need to verify the class.
[0140] Step 708: When the first file is invalid, the first file management module determines the reason for the invalidity of the first file.
[0141] For example, the electronic device can determine the reason for the invalidity of the first file through the IsDexChanged() function. When the result returned by the IsDexChanged() function is kOatBootImageOutOfDate and the second file has not been modified, the electronic device performs the following step 709.
[0142] Step 709: When the first file becomes invalid due to a change in the operating system version, return a verification passed result to the verification module.
[0143] Among them, the verification passed result can be represented by the KVerifed status.
[0144] Step 710: The verification module determines the verification result of the class.
[0145] Next, the process of the electronic device not skipping the bytecode verification operation will be specifically described.
[0146] Specifically, Figure 8 This is a timing diagram of another application cold start method provided by the embodiments of the present application. As Figure 8 shown.
[0147] Step 801: The first application sends a request to start the first application to the second file management module.
[0148] Step 802: The second file management module responds to the request to start the first application and opens the second file.
[0149] Step 803: The second file management module sends a request to the first file management module to obtain the first file.
[0150] Step 804: In response to the request to obtain the first file, the second file management module sends a request to the verification module to initialize the class.
[0151] Step 805: In response to the request to initialize the class, the verification module verifies the class.
[0152] Step 806: The verification module verifies the class through the first file management module.
[0153] Step 807: The first file management module determines whether the first file is invalid.
[0154] Step 808: When the first file is invalid and the reason for the invalidation of the first file is not due to a change in the operating system version, the verification module verifies the class.
[0155] For example, when the first file is invalid and the reason for the invalidation of the first file is not due to a change in the operating system version, the first file management module returns kVerifiedNeedsAccessChecks to the verification module, and the verification module verifies the class through the ComputeClassStatus() function.
[0156] Step 809: The verification module determines the verification result of the class.
[0157] It can be understood that Figure 9 is another schematic diagram of the operating state of the electronic device provided by the embodiment of the present application. In Figure 9 , after the operating system version of the electronic device changes and before the electronic device obtains the machine code matching the current operating system version through the Dex2oat technology, when the electronic device receives an operation of the user clicking on the application icon at time t11 and during the process of the electronic device executing the application cold start function, after the electronic device initializes the class, the electronic device skips the operation of verifying the class of the bytecode, and the electronic device directly compiles the bytecode to implement the cold start of the application, then the solution of the present application is used.
[0158] Alternatively, when the electronic device cannot directly load the machine code matching the current operating system version, the electronic device skips the operation of verifying the class of the bytecode, and the electronic device directly compiles the bytecode to implement the cold start of the application, then the solution of the present application is used.
[0159] In summary, in the solution of the present application, during the cold start of the application, the electronic device improves the efficiency of the cold start of the application by skipping the process of verifying the bytecode.
[0160] Some other embodiments of the present application provide an electronic device, which may include: a memory and one or more processors. When the processor executes one or more computer programs stored in the memory, the electronic device is caused to execute each function or step in the above method embodiments. The structure of the electronic device may refer to Figure 3 and Figure 4 the structure of the electronic device 300 shown.
[0161] Some other embodiments of the present application provide an electronic device, which may include: a memory and one or more processors, and the memory is coupled to the one or more processors. The memory is used to store computer program code, and the computer program code includes computer instructions. When the computer instructions are executed by the processor, the electronic device is caused to execute each function or step in the above method embodiments. The structure of the electronic device may refer to Figure 3 and Figure 4 the structure of the electronic device 300 shown.
[0162] Some other embodiments of the present application provide a chip system, which is applied to an electronic device including a memory and a display screen. The chip system includes: a processor. When the processor executes computer instructions stored in the memory, the chip system is caused to execute each function or step in the above method embodiments. The structure of the electronic device may refer to Figure 3 and Figure 4 the structure of the electronic device 300 shown.
[0163] Embodiments of the present application further provide a computer storage medium, which includes computer instructions. When the computer instructions run on the above electronic device, the electronic device is caused to execute each function or step that the electronic device executes in the above method embodiments.
[0164] Embodiments of the present application further provide a computer program product. When the computer program product runs on a computer, the computer is caused to execute each function or step that the electronic device executes in the above method embodiments.
[0165] Through the description of the above embodiments, those skilled in the art can clearly understand that, for the convenience and conciseness of description, only the above division of each functional module is used as an example. In practical applications, the above functions can be allocated to different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above.
[0166] In several embodiments provided by the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of 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 couplings or direct couplings or communication connections to each other can be through some interfaces. The indirect couplings or communication connections of devices or units can be in electrical, mechanical or other forms.
[0167] The units described as separate components may or may not be physically separated. The components displayed as units may be one physical unit or multiple physical units, that is, they can be located in one place, or they can 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.
[0168] In addition, each functional unit in 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-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units.
[0169] If 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 such an 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 this technical solution, can be embodied in the form of a software product. This 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 in various embodiments of the present application. The aforementioned storage medium includes: USB flash drives, mobile hard disks, read only memory (ROM), random access memory (RAM), magnetic disks or optical discs and other various media that can store program codes.
[0170] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions according to the embodiments of the present application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from a website, computer, server, or data center to another website, computer, server, or data center in a wired manner (such as coaxial cable, optical fiber, digital subscriber line) or a wireless manner (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that the computer can access or a data storage device such as a server or data center that includes one or more integrated available media. The available medium can be a magnetic medium (such as a floppy disk, hard disk, magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid-state drive), etc.
[0171] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by relevant hardware instructed by a computer program. The program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the above method embodiments. The aforementioned storage medium includes various media that can store program codes, such as ROM or random access memory RAM, magnetic disks, or optical discs.
[0172] 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 method for starting an application, characterized in that: Applied to an electronic device, the electronic device includes a first file and a second file of a first application, the first file stores a machine code for starting the application, and the second file stores a bytecode of the application; the method includes: receiving a first request, where the first request is used to start the first application; In response to the first request, when the first file is invalid, determining that a version of the operating system of the electronic device has changed; The operation of verifying the bytecode of the first application in the second file is skipped, the bytecode of the first application is compiled to obtain the machine code of the first application, and the machine code of the first application is executed to start the first application.
2. The method according to claim 1, characterized in that The electronic device further includes a first file and a second file of a second application, and the method further includes: When the power level of the electronic device is greater than a first threshold and / or the electronic device is in a charging state, the bytecode of the first application in the second file of the first application is precompiled to obtain the machine code of the first application, and the first file stored in the first application is updated; the bytecode of the second application in the second file of the second application is precompiled to obtain the machine code of the second application, and the first file stored in the second application is updated.
3. The method according to claim 1 or 2, characterized in that: The method further comprises: In response to the first request, when the first file is invalid, determining that a version of the operating system of the electronic device has not changed; verifying the bytecode of the first application in the second file; When the bytecode of the first application passes verification, the bytecode of the first application is compiled to obtain the machine code of the first application, and the machine code of the first application is executed to start the first application.
4. The method according to claim 1, characterized in that: The operation of verifying the bytecode of the first application in the second file includes at least one of the following: Verifying whether the bytecode in the second file is legal; Verify whether all type conversions and method calls in the second file are legal; Verify whether all data structures and code segments in the second file are aligned and whether memory access errors occur; Verify the entry point of the method in the second file, the initialization order of the class, and the constraints of the electronic device when it is running.
5. The method according to claim 1, characterized in that Determining that the version of the operating system of the electronic device has changed includes: When the identification of the operating system of the electronic device changes, the operating system version is upgraded, or the operating system is restored to a default version.
6. The method according to claim 1, characterized in that The operating system of the electronic device includes an application layer and a runtime layer, the first application is located in the application layer, and the first file management module, the second file management module and the verification module of the electronic device are located in the runtime layer; In response to the first request, the first application sends a second request to the second file management module, where the second request is used to load the second file; The second file management module responds to the second request, loads the second file, and sends a third request to the first file management module, where the third request is used to load the first file; The second file management module determines, in response to the third request, whether a version of the operating system of the electronic device has changed when the first file is invalid; In the case where the version of the operating system of the electronic device is changed, the verification module skips the operation of verifying the bytecode of the first application in the second file; The second file management module compiles the bytecode of the first application to obtain the machine code of the first application, and executes the machine code of the first application to start the first application.
7. An electronic device, characterized in that: The electronic device comprises: one or more processors; when the processor executes one or more computer programs stored in a memory, the electronic device executes the method according to any one of claims 1 to 6.
8. An electronic device, characterized in that: The electronic device comprises: one or more processors; a memory; wherein the memory is coupled to the one or more processors, the memory is used to store computer program code, the computer program code comprises computer instructions, and the one or more processors call the computer instructions so that the electronic device executes the method as described in any one of claims 1-6.
9. A chip system, characterized in that: The chip system is applied to an electronic device including a memory and a display screen; the chip system includes: a processor; when the processor executes computer instructions stored in the memory, the electronic device executes the method as described in any one of claims 1-6.
10. A computer-readable storage medium comprising instructions, characterized in that: When the instructions are executed on an electronic device, the electronic device is caused to execute the method as claimed in any one of claims 1 to 6.
11. A computer program product comprising instructions, characterized in that When the computer program product is executed on an electronic device, the electronic device is enabled to execute the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Application program processing method and device, electronic equipment and readable storage medium
CN114895948A
Method and device for optimizing first-time cold start of plug-in
CN116932078A