Compiling method of virtual machine and electronic device

CN120973482BActive Publication Date: 2026-08-28HONOR DEVICE CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202410600599.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-11
Publication Date
2026-08-28
Estimated Expiration
2044-05-11

AI Technical Summary

Technical Problem

[0003]然而,如果在编译优化过程中,用户执行的操作打破了系统所满足的条件,就会使当前的编译优化过程停止,导致没有完成完整的编译优化过程,这样就会使得部分应用未进行编译优化,出现编译功耗增加或应用卡顿的现象

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120973482B_ABST
    Figure CN120973482B_ABST
Patent Text Reader

Abstract

The embodiment of the application provides a kind of virtual machine's compiling method and electronic equipment, the method is applied on electronic equipment, comprising: when the time length that electronic equipment is in screen-off state reaches preset time length, and the battery power of electronic equipment is greater than the first electric quantity, the virtual machine in electronic equipment starts to execute compilation optimization;If electronic equipment is switched from screen-off state to screen-on state, then the virtual machine pauses compilation optimization;After the virtual machine pauses compilation optimization, if electronic equipment is not unlocked and is switched to screen-off state again, then the virtual machine continues to execute compilation optimization.Thereby it can make electronic equipment complete compilation optimization process as soon as possible, improve the efficiency of compilation optimization, reduce the phenomenon of compilation power consumption increase or application lag.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of electronic technology, specifically to a method for compiling a virtual machine and an electronic device. Background Technology

[0002] Typically, after a system upgrade or application upgrade of an electronic device, recompilation is required for it to function properly. To reduce compilation power consumption and application lag during the compilation process, electronic devices can perform compilation optimization. Common compilation optimization scenarios include optimization processes executed upon the first boot after an electronic device upgrade and optimization processes executed during daily idle periods. Both of these methods are essentially background compilation processes triggered after the system meets certain conditions.

[0003] However, if the user's actions during the compilation optimization process break the conditions met by the system, the current compilation optimization process will stop, resulting in the incomplete compilation optimization process. This will cause some applications to not be compiled and optimized, leading to increased compilation power consumption or application lag. Summary of the Invention

[0004] This application provides a method for compiling a virtual machine and an electronic device that can improve the efficiency of compilation optimization and reduce the increase in compilation power consumption or application lag.

[0005] In a first aspect, this application provides a method for compiling a virtual machine, which is applied to an electronic device, comprising: when the duration of the electronic device being in a screen-off state reaches a preset duration and the battery power of the electronic device is greater than a first power level, the virtual machine in the electronic device starts to perform compilation optimization; if the electronic device switches from a screen-off state to a screen-on state, the virtual machine pauses compilation optimization; after the virtual machine pauses compilation optimization, if the electronic device is not unlocked and switches to a screen-off state again, the virtual machine continues to perform compilation optimization.

[0006] In other words, when the electronic device meets the compilation execution conditions (i.e., the screen-off time reaches the preset duration and the battery level is greater than the initial charge level), the virtual machine begins to perform compilation optimization. If the screen lights up during the compilation optimization process, the virtual machine will pause the compilation optimization. Since the screen lighting event of the electronic device may be triggered by user operation or by notification messages subscribed to by the electronic device, if the electronic device only lights up but is not unlocked, it means that the probability of it being used by the user is relatively small, and continuing the compilation will have a smaller impact on the operation of the electronic device. Therefore, if the electronic device is not unlocked and the screen turns off again, the virtual machine can continue to perform the original compilation optimization, thereby enabling the electronic device to complete the compilation optimization process as quickly as possible, improving the efficiency of compilation optimization, and reducing the increase in compilation power consumption or application lag.

[0007] In one implementation, the preset duration can be half an hour.

[0008] In conjunction with the first aspect, in some implementations of the first aspect, after the virtual machine pauses compilation optimization, the above method also includes: terminating compilation optimization when the electronic device detects user input to unlock; if the electronic device switches to a screen-off state again, the virtual machine re-executes compilation optimization when the screen-off state duration reaches a preset duration.

[0009] During the compilation and optimization process described above, if the virtual machine pauses the compilation and optimization process and detects a user unlocking operation (i.e., detects the user's unlocking intention), it indicates a high probability that the user intends to use the electronic device. Continuing the compilation process would significantly impact the operation of the electronic device. Therefore, the compilation and optimization process can be terminated at this point, waiting for the electronic device to enter a screen-off state again and for the preset screen-off time to be reached before the virtual machine re-executes the compilation and optimization. This reduces the lag caused by the compilation and optimization process on the running applications on the electronic device.

[0010] In conjunction with the first aspect, in some implementations of the first aspect, the above method further includes: when the duration of the electronic device being in a screen-off state reaches a preset duration and the battery level of the electronic device is not greater than a first battery level, the virtual machine does not perform compilation optimization.

[0011] In other words, if the electronic device does not meet the compilation execution conditions (i.e., the screen-off time reaches the preset time and the battery level is greater than the first charge level), it should not perform compilation optimization. It should wait until the compilation execution conditions are met before starting to perform compilation optimization.

[0012] In conjunction with the first aspect, in some implementations of the first aspect, if the electronic device switches from a screen-off state to a screen-on state, the virtual machine pauses compilation and optimization, including: the electronic device sends a screen-on broadcast when it switches from a screen-off state to a screen-on state; the power-saving program in the electronic device receives the screen-on broadcast and freezes the corresponding compilation and optimization process; the power-saving program sends a notification instruction to the virtual machine, notifying the virtual machine to pause compilation and optimization.

[0013] In this application, the virtual machine's paused compilation optimization process can be controlled by a power-saving feature. Specifically, when the electronic device switches from a screen-off state to a screen-on state, a screen-on broadcast can be sent, for example, by the power manager (PMS). Upon receiving this broadcast, the power-saving feature can freeze the corresponding compilation optimization process (hereinafter referred to as the compilation process) and send a notification instruction to the virtual machine, informing it that the compilation process has been frozen and compilation optimization is paused. This implementation pauses compilation optimization through a process-freezing mechanism, allowing the process to be unfrozen promptly when compilation optimization needs to resume, thus improving compilation optimization efficiency.

[0014] In conjunction with the first aspect, in some implementations of the first aspect, if the electronic device is not unlocked and switches to a screen-off state again, the virtual machine continues to perform compilation optimization, including: the electronic device switches to a screen-off state and sends a screen-off broadcast; the power-saving wizard receives the screen-off broadcast and unfreezes the corresponding compilation optimization process; the power-saving wizard sends a notification instruction to the virtual machine, notifying the virtual machine to continue performing compilation optimization.

[0015] As described above, when the electronic device is not unlocked and the screen is turned off again, the virtual machine can continue to perform the original compilation optimization. However, if the compilation process is frozen, it needs to be unfrozen. Therefore, after the electronic device enters a screen-off state again, it can send a screen-off broadcast, for example, via the Power Management System (PMS). Upon receiving this broadcast, the power-saving utility can unfreeze the compilation process and send a notification to the virtual machine, informing it that the compilation process has been unfrozen and can continue compilation optimization. Thus, the electronic device no longer needs to wait half an hour after the screen is turned off before performing compilation optimization, improving compilation optimization efficiency.

[0016] In conjunction with the first aspect, in some implementations of the first aspect, the duration for which the aforementioned electronic device is in a screen-off state reaches a preset duration includes: when the electronic device enters a screen-off state, starting a timer to start timing; during the timing process, if the electronic device switches to a screen-on state, pausing the timer; if the electronic device detects an unlock operation input by the user, canceling the timer; when the electronic device switches to a screen-off state again, if the timer is in a paused state, continuing timing; if the timer is in a canceled state, restarting timing, until the timing duration reaches the preset duration.

[0017] The compilation execution conditions mentioned above include the electronic device being in a screen-off state for a preset duration and the battery level being greater than a certain threshold. However, in some scenarios, the screen may still light up even when the electronic device is in a screen-off state. Related technologies cancel the screen-off duration timing after the screen lights up and restart the timing when the screen lights up again. This delays the fulfillment of the compilation execution conditions, i.e., delays the start time of compilation optimization. Therefore, in this application, during the timing of the screen-off duration of the electronic device, if the electronic device switches to a screen-on state, the timer is paused. When a user input unlock operation is detected, indicating a higher probability of the user using the electronic device, the timer can be canceled. If no user unlock intention is detected, meaning the electronic device only lights up briefly and the probability of use is low, the timer can remain paused.

[0018] In this way, when the electronic device switches back to a screen-off state, the current state of the timer can be determined. If the timer is paused, it means the electronic device was only on and not used, so the timer can resume. If the timer is canceled, it means the electronic device was used and the timer needs to be reset. This reduces the need for the electronic device to reset the screen-off duration, allowing for faster compilation optimization and improving optimization efficiency.

[0019] In conjunction with the first aspect, in some implementations of the first aspect, when the duration of the electronic device being in a screen-off state reaches a preset duration and the battery level of the electronic device is greater than a first battery level, the virtual machine in the electronic device begins to perform compilation optimization, including: after the task scheduling service in the electronic device determines that the timer duration has reached the preset duration, it determines whether the battery level of the electronic device is greater than the first battery level; if the battery level of the electronic device is greater than the first battery level, the task scheduling service notifies the virtual machine to begin performing compilation optimization.

[0020] Whether the virtual machine starts compilation optimization can be controlled by the task scheduling service (JobService) in the electronic device. The timer mentioned above can also be started by the JobService. The JobService can know whether the timer has reached the preset duration. After the preset duration is reached, if the battery power of the electronic device is also greater than the first power level, that is, the JobService can determine that the compilation execution conditions are met, and then it can notify the virtual machine to start the compilation optimization.

[0021] It is understandable that if the aforementioned electronic device detects a user input unlock operation, the JobService can also notify the virtual machine to terminate the compilation and optimization.

[0022] In conjunction with the first aspect, in some implementations of the first aspect, after the virtual machine pauses compilation optimization, the above method also includes: determining whether user input unlocking operation is detected; and determining that the electronic device has not been unlocked if no user input unlocking operation is detected.

[0023] As described above, after the virtual machine pauses compilation and optimization, it will continue compiling and optimizing if the electronic device is not unlocked. Therefore, it is necessary to monitor whether the electronic device is unlocked, that is, to monitor whether the user has entered an unlock operation. If no user input is detected, it means that the electronic device is not unlocked, and compilation and optimization can continue after the screen is turned off, in order to improve the efficiency of compilation and optimization.

[0024] In conjunction with the first aspect, in some implementations of the first aspect, determining whether a user input unlock operation is detected includes: upon receiving a user unlock intent event, determining that a user input unlock operation has been detected, wherein the user unlock intent event includes at least one of the following events: an event generated when fingerprint information entered by the user in the fingerprint unlock area is obtained, an event generated when facial information captured by the camera of the electronic device is obtained, an event generated when the first touch event entered by the user in the password unlock area is obtained, and an event generated when the touch event of the user on the main screen of the electronic device is obtained; and upon not receiving a user unlock intent event, determining that no user input unlock operation has been detected.

[0025] Since there are currently multiple ways to unlock electronic devices, such as fingerprint unlocking, password unlocking, and facial recognition unlocking, this application can monitor multiple unlocking methods. Detecting any one of these methods indicates a user's unlocking intent. For fingerprint unlocking, acquiring the user's fingerprint information in the fingerprint unlocking area generates a user unlocking intent event and reports it to the JobService. For facial recognition unlocking, acquiring the facial information captured by the camera generates a user unlocking intent event and reports it to the JobService. For password unlocking, acquiring the first touch event in the password unlocking area generates a user unlocking intent event and reports it to the JobService, thus confirming that a user's unlocking operation has been detected. Alternatively, if no unlocking method is set, and the electronic device displays the home screen after the screen is turned on, any touch operation on the home screen by the user is also considered a user unlocking intent. Of course, if no user unlocking intent event is received, it can be determined that no user unlocking operation has been detected.

[0026] In conjunction with the first aspect, in some implementations of the first aspect, when the duration of the electronic device being in a screen-off state reaches a preset duration, the above method further includes: setting the value of the first flag bit to true.

[0027] In conjunction with the first aspect, in some implementations of the first aspect, when the electronic device terminates compilation optimization, the above method also includes: setting the value of the first flag bit to false.

[0028] The first flag bit indicates whether the electronic device has been off-screen for a preset duration. For example, a true first flag bit indicates that the electronic device has been off-screen for the preset duration, while a false first flag bit indicates that the electronic device has not been off-screen for the preset duration. By setting the value of the first flag bit, the electronic device can determine whether the condition is met and execute the corresponding process accordingly.

[0029] Secondly, this application provides an apparatus included in an electronic device, which has the function of implementing the behaviors of the electronic device in the first aspect and possible implementations thereof. The function can be implemented by hardware or by hardware executing corresponding software. The hardware or software includes one or more modules or units corresponding to the above-described functions. For example, a receiving module or unit, a processing module or unit, etc.

[0030] Thirdly, this application provides an electronic device, which includes: one or more processors, and a memory;

[0031] The memory is coupled to the one or more processors, and the memory is used to store computer program code, the computer program code including computer instructions, which the one or more processors call to cause the electronic device to perform any one of the methods of the first aspect of the technical solution.

[0032] Fourthly, this application provides a chip system applied to an electronic device, the chip system including one or more processors, the one or more processors being configured to invoke computer instructions to cause the electronic device to perform the methods in the first aspect and any possible implementation thereof.

[0033] Optionally, the chip system also includes a memory, which is connected to the processor via circuitry or wires.

[0034] Alternatively, the chip system may also include a communication interface.

[0035] Fifthly, this application provides a computer-readable storage medium including instructions that, when executed on an electronic device, cause the electronic device to perform any one of the methods in the first aspect of the technical solution.

[0036] Sixthly, this application provides a computer program product, which includes computer program code that, when executed on an electronic device, causes the electronic device to perform any one of the methods in the first aspect of the technical solution. Attached Figure Description

[0037] Figure 1 This is a schematic diagram of a compiler principle provided in an embodiment of this application;

[0038] Figure 2 This is a schematic diagram illustrating an example of AOT compilation principle provided in an embodiment of this application;

[0039] Figure 3 This is a schematic diagram illustrating an example of compiling an APK file according to an embodiment of this application;

[0040] Figure 4 This is a schematic diagram illustrating an example of a compilation optimization process provided by related technologies;

[0041] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application;

[0042] Figure 6 This is a software structure block diagram of an electronic device provided in an embodiment of this application;

[0043] Figure 7 This is a flowchart illustrating an example of a virtual machine compilation method provided in an embodiment of this application;

[0044] Figure 8 This is a flowchart illustrating an example of monitoring a user's unlocking intent provided in an embodiment of this application. Detailed Implementation

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

[0046] Hereinafter, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first," "second," or "third" may explicitly or implicitly include one or more of that feature.

[0047] To ensure clarity and conciseness in the description of the following embodiments, a brief introduction to the relevant concepts or technologies is given first:

[0048] Interpreted execution is a method of executing programming languages ​​that translates source code line by line into machine code and executes it immediately. Interpreted languages ​​require code translation at runtime, meaning that the interpreter needs to read the source code line by line and convert it into instructions that the electronic device can understand.

[0049] Just-in-time (JIT) compilation: A compilation method that translates bytecode into machine code on the fly before execution. During program runtime, hotspot code is calculated using algorithms and then compiled in real-time. This consumes runtime resources and can cause process lag.

[0050] Ahead-of-time (AOT) compilation: In contrast to JIT compilation, it is a compilation method that converts bytecode into machine code before the program runs, which can improve runtime efficiency.

[0051] dex2oat (dalvikxcutable file to optimized art file): is a program that compiles and optimizes dex files, used to convert Dalvik bytecode into native machine code. For example, in Android devices, the storage location is / system / bin / dex2oat, and after startup, it corresponds to the dex2oat process.

[0052] DEX files: Dalvik bytecode files are executable files that can be recognized by virtual machines in electronic devices.

[0053] odex file: The dex file is a compiled and optimized file that stores executable machine code.

[0054] Profile file: A configuration file that records the index information of hot functions during the compilation and optimization process of electronic devices, and can be continuously updated.

[0055] As electronic technology continues to improve, electronic devices undergo periodic system and application upgrades. Typically, after a system or application upgrade, recompilation is required for the device to function properly.

[0056] Compilation refers to the process of using a compiler to generate a target program from a source program written in a source language. It can be the process of translating a program written in one programming language into an equivalent language. Generally, Android application packages (APKs) and JAR (Java archives) downloaded to electronic devices (such as phones running the Android system) are written in Java. To run them on an electronic device, these packages need to be compiled into a language that the device can recognize. When Java code is compiled into an APK, it is simply translated into cross-platform bytecode. This bytecode can be stored in a dex file and can be recognized by the virtual machine (Android runtime, ART) on different platforms (or electronic devices). However, after the virtual machine recognizes the bytecode, it still needs to be compiled into platform-compatible machine code before it can be executed by the central processing unit (CPU).

[0057] For the early compilation process, such as Figure 1As shown, after Java code is translated into bytecode, the virtual machine compiles the bytecode using either JIT compilation or interpreted execution. This means that the bytecode is translated into machine code on runtime and then executed by the CPU. Furthermore, this bytecode-to-machine-code translation operation is performed every time the application runs, which undoubtedly increases compilation power consumption and causes application stuttering. To address this issue, researchers developed an AOT (Ahead-of-Time) compilation optimization method. This method pre-translates the bytecode of frequently used functions (or hot functions) in the APK into machine code and stores it, for example, as an odex file. During subsequent runtime, such as... Figure 2 As shown, the virtual machine first checks if there is a pre-compiled odex file. If there is an odex file, it will not compile this part of the function again, but will directly execute the machine code of the stored odex file. For functions without odex files, the virtual machine will compile them into platform-adapted machine code and can also save the machine code as an odex file for use in the next run. This can reduce the amount of compilation and compilation power consumption, and improve running efficiency.

[0058] In real-world scenarios, APK files contain multiple functions, some of which are hot functions and others are not. For AOT (Ahead-of-Time) compilation optimization, some hot functions may have already been compiled into odex files and stored, while other hot and non-hot functions still need to be JIT compiled or interpreted. During the compilation process, the virtual machine dynamically decides the compilation strategy for each function to optimize compilation performance as much as possible.

[0059] For example, such as Figure 3As shown, for an APK file, an electronic device can either install and decompress it, obtaining the dex file and handing it over to the virtual machine for subsequent compilation and execution, or it can start loading the APK, checking if an odex file exists. If an odex file exists, it is written to disk and stored, then handed over to the virtual machine for further execution. If no odex file exists, the dex file is verified based on a vdex file containing dex file verification information. If the verification passes, the subsequent compilation process is executed. During compilation and execution, the virtual machine first determines whether the current method function has already been compiled. If it has been compiled and it is a JIT compilation, the machine code in the code cache is executed. If it has been compiled but it is not a JIT compilation (i.e., it is an AOT compilation), the corresponding odex file is executed. If the current function has not yet been compiled, the virtual machine interprets and executes it, marking it as a hot function after multiple runs. If the current function is a hot function and there is sufficient memory, the virtual machine performs JIT compilation, storing the result in the code cache. If it is a hot function but there is insufficient memory, memory reclamation (e.g., garbage collection) is performed first. After reclamation, memory availability is checked again. If sufficient memory is available, JIT compilation is performed, storing the result in the code cache. If memory is still insufficient, JIT compilation is stopped. If the current function is not a hot function, interpretation continues. After a function is marked as a hot function, the virtual machine can also add the function index to the profile to update the number of hot functions. If the number of hot functions in the profile changes by more than a certain value (e.g., an increase of 2%), the virtual machine can also trigger daily idle background compilation.

[0060] For the aforementioned APK file, during daily operation, the virtual machine also performs daily idle background compilation optimization. This is used to compile all hot functions in the profile and store the compilation results (odex file) on disk for direct execution during subsequent compilations. The virtual machine can use the dex2oat mechanism for this background compilation. Furthermore, when the APK file is installed or updated, the electronic device will synchronize the new profile file from the cloud and delete the old profile file. Therefore, the new profile file will be used for subsequent daily idle background compilations.

[0061] The above describes the compilation and optimization process of the virtual machine based on AOT. So, in what scenarios is compilation optimization necessary? Research has revealed that in some scenarios, after electronic devices undergo updates such as HOTA upgrades and patch optimizations, the corresponding JAR packages or APK files change, and the indexes of the included functions also change. These require recompilation, and the electronic device can perform background compilation optimization, storing the compilation results on disk. In other scenarios, after applications in the electronic device are upgraded, recompilation is also required. Some applications may undergo just-in-time (JIT) compilation during foreground execution, but since JIT compilation results are not persisted to disk, the electronic device will perform compilation optimization again in the background, ensuring the compilation results are stored on disk. Therefore, the virtual machine compilation method provided in this application can be applied to any scenario requiring background compilation optimization.

[0062] Taking a scenario where an electronic device undergoes a hota upgrade as an example, the device downloads and installs the hota package, and typically restarts after installation. Upon the first boot after the upgrade, the device performs a compilation optimization, known as Fastiddle, which optimizes the top 15 apps. In addition, after Fastiddle, the device can perform daily idle compilation optimizations, meaning a compilation optimization is performed once a day during off-peak hours. Therefore, the optimization processes performed upon the first boot after an upgrade and the daily idle optimization processes represent the primary compilation optimization methods currently used.

[0063] The Fastiddle optimization is typically executed when the electronic device has been screen-off for half an hour and the battery level is above 40%. This allows for the early compilation of the top 15 apps with low power consumption. The Daily Idle Compilation optimization is typically executed when the electronic device is charging, screen-off for half an hour, and the battery level is above 95%. This allows for a full build with better performance. The execution conditions for both optimization methods are quite stringent, with specific requirements for charging status, screen-off time, and battery level. This is because the compilation load is high, and executing these optimizations while the user is using the device with the screen on can cause foreground app lag and increased device heat. The Daily Idle Compilation optimization, in particular, requires charging and a battery level above 95%. Executing it during the early stages of charging can lead to excessive heat generation and slow charging, significantly impacting the charging process.

[0064] Therefore, under the aforementioned execution conditions, electronic devices will enter the compilation optimization process if the conditions are met. However, due to the stringent nature of these conditions, they may not be easily met, or they may be broken during the compilation optimization process, leading to delayed execution or termination of the optimization process, i.e., incomplete compilation optimization. For example, the daily idle compilation optimization method requires meeting the conditions of charging status + screen off for half an hour + battery level greater than 95%. However, research in real-world scenarios has revealed that many electronic devices currently support fast charging, so charging may be completed in less than half an hour after the battery level reaches 95%. Alternatively, user operations may cause the screen to remain on continuously, all of which can break the execution conditions for compilation optimization, resulting in incomplete compilation optimization. This can lead to some applications not undergoing compilation optimization, resulting in increased power consumption or lag.

[0065] For example, the process by which some related technologies determine execution conditions and proceed to the compilation optimization step can be found in [reference needed]. Figure 4 As shown, the virtual machine (ART) first starts, setting up a scheduled compilation task (Job) and conditions, which are the execution conditions mentioned above. Then, when the electronic device screen is off, a timer starts, assuming a duration of half an hour. If the electronic device screen turns on before the duration is reached, the timer is canceled, and the device waits for the screen to turn off again. After the screen turns off, the timer restarts from 0, repeating this process until the duration is reached. In other words, during the screen-off timing process, if the electronic device screen turns on and off again, the timer restarts, undoubtedly increasing the latency to the subsequent compilation optimization step. When the timer reaches the duration (half an hour of screen-off), the virtual machine checks if the other execution conditions are met. If they are, compilation optimization begins. If the electronic device screen turns on again during compilation optimization, the virtual machine exits the compilation optimization process, stopping compilation. Any incomplete compilation results are discarded, waiting for the next compilation. Afterward, the virtual machine re-checks the execution conditions and the screen-off state of the electronic device. After the screen turns off, it restarts the process of starting the timer for another half hour, and so on. Therefore, before the complete compilation optimization is completed, some applications will perform interpretation or JIT compilation at runtime, which will result in increased compilation power consumption or application lag.

[0066] Based on the problems existing in related technologies, we found that these technologies require waiting for the screen-off time of the electronic device to exceed the timer before starting compilation. Once the screen is on, the timer restarts, and compilation stops if the screen is on during the optimization process. This is to avoid causing lag in applications running on the screen if compilation continues after the screen is on. However, in real-world scenarios, the screen-on event may not be due to user interaction or intention. For example, if the electronic device has notification-activated screen-on or raise-to-wake features enabled, the screen may light up upon receiving a notification, or raising the hand while holding the device may trigger screen-on, but no application is actually running. Similarly, pressing the power button to turn on the screen may simply be for checking the time, without any intention to operate the device or run an application. In these scenarios, screen-on does not affect the normal compilation optimization process and does not require stopping compilation. Therefore, this application optimizes these scenarios and proposes a virtual machine compilation method. After the electronic device screen is turned on, the method monitors the user's unlocking intention and does not stop compilation if there is no user unlocking intention. This can improve the efficiency of compilation optimization, complete the complete compilation optimization process as quickly as possible, and reduce the phenomenon of increased compilation power consumption or application lag.

[0067] It should be noted that the virtual machine compilation method provided in this application embodiment can be applied to electronic devices that require compilation optimization, such as mobile phones, tablets, wearable devices, in-vehicle devices, augmented reality (AR) / virtual reality (VR) devices, and smart home devices. This application embodiment does not impose any restrictions on the specific type of electronic device.

[0068] For example, Figure 5This is a schematic diagram of the structure of an electronic device 100 provided in an embodiment of this application. Taking a mobile phone as an example, 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, buttons 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identity module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an accelerometer sensor 180E, a distance sensor 180F, a proximity 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.

[0069] Processor 110 may include one or more processing units, such as: application processor (AP), modem processor, graphics processing unit (GPU), image signal processor (ISP), controller, memory, video codec, digital signal processor (DSP), baseband processor, and / or neural network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.

[0070] The charging management module 140 receives charging input from a charger. The charger can be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 receives charging input from the wired charger via the USB interface 130. In some wireless charging embodiments, the charging management module 140 receives wireless charging input via the wireless charging coil of the electronic device 100. While charging the battery 142, the charging management module 140 can also supply power to the electronic device via the power management module 141.

[0071] The power management module 141 connects the battery 142, the charging management module 140, and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140, providing power to the processor 110, internal memory 121, external memory, display screen 194, camera 193, and wireless communication module 160, etc. The power management module 141 can also monitor parameters such as battery capacity, battery cycle count, and battery health status (leakage current, impedance). In some other embodiments, the power management module 141 may also be located within the processor 110. In other embodiments, the power management module 141 and the charging management module 140 may be located in the same device.

[0072] The wireless communication function of electronic device 100 can be realized through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor, etc.

[0073] The wireless communication module 160 can provide solutions for wireless communication applications on the electronic device 100, including wireless local area networks (WLANs) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR) technologies. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via antenna 2, performs frequency modulation and filtering of the electromagnetic wave signals, and sends the processed signal to processor 110. The wireless communication module 160 can also receive signals to be transmitted from processor 110, perform frequency modulation and amplification, and convert them into electromagnetic waves for radiation via antenna 2.

[0074] Electronic device 100 implements display functions through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations and for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information.

[0075] Display screen 194 is used to display images, videos, etc. Display screen 194 includes a display panel. The display panel may be 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 miniature LED, a microLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, electronic device 100 may include one or N displays 194, where N is a positive integer greater than 1.

[0076] Camera 193 is used to capture still images or videos. An object is projected onto a photosensitive element by generating an optical image through the lens. The photosensitive element can be a charge-coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, which is then passed to an ISP for conversion into a digital image signal. The ISP outputs the digital image signal to a DSP for processing. The DSP converts the digital image signal into image signals in standard RGB, YUV, or other formats. In some embodiments, the electronic device 100 may include one or N cameras 193, where N is a positive integer greater than 1.

[0077] An NPU (Neural Processing Unit) is a computational processor for neural networks (NNs). By borrowing the structure of biological neural networks, such as the transmission patterns between neurons in the human brain, it can rapidly process input information and continuously learn on its own. NPUs enable intelligent cognitive applications in electronic devices, such as image recognition, facial recognition, speech recognition, and text understanding.

[0078] Internal memory 121 can be used to store computer executable program code, which includes instructions. Processor 110 executes various functional applications and data processing of electronic device 100 by running the instructions stored in internal memory 121. Internal memory 121 may include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback, image playback, etc.), etc. The data storage area may store data created during the use of electronic device 100 (such as audio data, phonebook, etc.). Furthermore, internal memory 121 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, universal flash storage (UFS), etc.

[0079] The fingerprint sensor 180H is used to collect fingerprints. The electronic device 100 can use the characteristics of the collected fingerprints to achieve fingerprint unlocking, accessing application locks, taking photos with fingerprints, answering calls with fingerprints, etc.

[0080] Touch sensor 180K, also known as a "touch panel," can be located on display screen 194. The touch sensor 180K and display screen 194 together form a touchscreen, also known as a "touch screen." Touch sensor 180K detects touch operations applied to or near it. The touch sensor can transmit the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through display screen 194. In other embodiments, touch sensor 180K may also be located on the surface of electronic device 100, in a different position than display screen 194.

[0081] Buttons 190 include a power button, volume buttons, etc. Buttons 190 can be mechanical buttons or touch-sensitive buttons. Electronic device 100 can receive button input and generate key signal inputs related to user settings and function control of electronic device 100.

[0082] Indicator 192 can be an indicator light, used to indicate charging status, power changes, or to indicate messages, missed calls, notifications, etc.

[0083] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0084] The software system of electronic device 100 can adopt a layered architecture, event-driven architecture, microkernel architecture, microservice architecture, or cloud architecture. This application embodiment uses the layered architecture Android system as an example to exemplify the software structure of electronic device 100.

[0085] Figure 6 This is a software structure block diagram of an electronic device 100 according to an embodiment of this application. The layered architecture divides the software into several layers, each with a clear role and function. 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 Android runtime and system libraries, and the kernel layer. The application layer may include a series of application packages.

[0086] like Figure 6 As shown, the application package may include applications such as camera, gallery, call, navigation, WLAN, video, and power saving, and may also include the system user interface (SystemUI). SystemUI is a system-level application and a key component of the Android operating system, primarily responsible for managing and providing core elements of the user interface, such as the status bar, navigation bar, and lock screen. In this embodiment, when SystemUI detects a user's unlocking intent, it can report the user's unlocking intent to the JobService.

[0087] The application framework layer provides application programming interfaces (APIs) and a programming framework for applications in the application layer. The application framework layer includes some predefined functions.

[0088] like Figure 6 As shown, the application framework layer may include a window manager, a view system, a phone manager, a resource manager, a notification manager, a task scheduler (JobScheduler), a power manager service (PMS), etc.

[0089] The Power Management System (PMS) is responsible for the power management of electronic devices, such as managing events like turning the screen on and off. In this embodiment, the PMS can send a screen-on broadcast when the electronic device's screen is on and a screen-off broadcast when the electronic device's screen is off. Specifically, the aforementioned power-saving utility can freeze the compilation process after receiving the screen-on broadcast from the PMS, and can unfreeze the compilation process after receiving the screen-off broadcast from the PMS.

[0090] JobScheduler is mainly used to trigger the execution of a task when certain conditions are met at a future time. The conditions involved may be network, battery power, time, etc. The task scheduling service (JobService) is a callback of JobScheduler, used to implement specific task logic. In the embodiments of this application, JobService can be used to notify ArtService to start or terminate the compilation process.

[0091] The window manager manages window programs. It can obtain screen size, determine the presence of a status bar, lock the screen, and capture the screen. The view system includes visual controls, such as controls for displaying text and controls for displaying images. The view system can be used to build applications. A display interface can consist of one or more views. For example, a display interface including a text notification icon can include views for displaying text and views for displaying images. The phone manager provides communication functionality for electronic devices 100. For example, it manages call status (including connection, hang-up, etc.). The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, etc. The notification manager allows applications to display notification information in the status bar. It can be used to convey informational messages and can disappear automatically after a short pause without user interaction. For example, the notification manager is used to notify of download completion, message alerts, etc. The notification manager can also display notifications as icons or scrollbar text in the system's top status bar, such as notifications from background applications, or as dialog windows on the screen. Examples include displaying text messages in the status bar, emitting alert sounds, vibrating electronic devices, and flashing indicator lights.

[0092] The Android runtime consists of core libraries and a virtual machine. The Android runtime is responsible for scheduling and managing the Android system.

[0093] The core library consists of two parts: one part is the functionalities that need to be called by the Java language, and the other part is the Android core library.

[0094] The application layer and application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and application framework layer into binary files, i.e., it performs compilation. The virtual machine is used to manage object lifecycles, stack management, thread management, security and exception management, and garbage collection. It can be understood that after the virtual machine starts running, its corresponding virtual machine service (ArtService) process also starts accordingly. ArtService can start or terminate the compilation process based on notifications from JobService.

[0095] System libraries can include multiple functional modules. For example: surface manager, media libraries, 3D graphics processing libraries (e.g., OpenGL ES), 2D graphics engines (e.g., SGL), etc.

[0096] The Surface Manager manages the display subsystem and provides fusion of 2D and 3D layers for multiple applications. The Media Library supports playback and recording of various common audio and video formats, as well as still image files. The Media Library supports multiple audio and video encoding formats, such as MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG. The 3D Graphics Processing Library implements 3D graphics drawing, image rendering, compositing, and layer processing. The 2D Graphics Engine is the drawing engine for 2D graphics.

[0097] The kernel layer is the layer between hardware and software. The kernel layer includes at least the display driver, camera driver, touch point (TP) driver, and fingerprint module driver.

[0098] The TP driver can receive touch signals generated when a user touches the screen of an electronic device, and can also acquire fingerprint information registered when the user unlocks the device. The fingerprint module driver is used to receive fingerprint information registered when the user touches the power button, such as in scenarios where fingerprint unlocking is performed via the side power button. The camera driver is used to detect images captured by the camera, such as detecting whether they contain facial information. In this embodiment, when the kernel layer driver detects a user's unlocking intention, it can report the user's unlocking intention to the JobService.

[0099] For ease of understanding, the following embodiments of this application will be described using the following methods: Figure 5 and Figure 6 Taking the electronic device with the structure shown as an example, and in conjunction with the accompanying drawings and application scenarios, the compilation method of the virtual machine provided in this application embodiment will be specifically described.

[0100] Figure 7 This is a flowchart illustrating a virtual machine compilation method provided in an embodiment of this application. The method includes:

[0101] S11, the virtual machine service (ArtService) starts.

[0102] ArtService (which can also be a virtual machine) can start when the electronic device is powered on, and after starting, it can perform subsequent compilation and optimization processes.

[0103] S12, ArtService registers a task (Job) in the task scheduling service (JobService).

[0104] The Job registered by ArtService is the task used for subsequent compilation optimization. When ArtService registers a Job in JobService, it can also register the conditions for the Job to start execution, that is, the corresponding task will start execution when the execution conditions are met.

[0105] S13, After the electronic device screen is turned off, the PMS sends a screen-off broadcast.

[0106] Since a Power Management System (PMS) is responsible for the power management of electronic devices, such as turning the screen on and off, it can send a screen-off broadcast after the screen is turned off. Correspondingly, services registered to receive broadcasts can receive the screen-off broadcast sent by the PMS.

[0107] S14, JobService receives the screen-off broadcast, checks if the first flag is true, otherwise executes S15, if it is true, executes S21.

[0108] The first flag indicates whether the electronic device has been off-screen for a preset duration. For example, a true first flag indicates that the electronic device has been off-screen for the preset duration, while a false first flag indicates that the electronic device has not been off-screen for the preset duration. For instance, the preset duration could be half an hour. It can be understood that when the first flag is true, it indicates that one execution condition for compiler optimization has been met, and other execution conditions can be further determined.

[0109] S15, JobService starts a timer, with a preset duration.

[0110] If the first flag is false, the electronic device has not yet reached the preset screen-off time. In this case, JobService can start a timer to count the screen-off time of the electronic device, so that subsequent steps can be performed when the electronic device reaches the preset screen-off time.

[0111] S16, During the timer's countdown, the electronic device's screen lights up, and the PMS sends a screen-light-up broadcast.

[0112] S17, JobService receives a screen-on broadcast and pauses the timer. If JobService detects the user's intention to unlock, it cancels the timer.

[0113] In other words, during the timer's timing phase, if the electronic device changes from a screen-off state to a screen-on state (e.g., a user triggers the screen to check the time or the electronic device receives a notification and triggers the screen to turn on), the PMS will also send a screen-on broadcast. Upon receiving this broadcast, the JobService will consider the electronic device potentially being used and will pause the timer. Simultaneously, the JobService will continue to monitor for user unlocking intentions. If a user unlocks the device, the probability of it being used is high, and the timer can be canceled directly, without performing any compilation optimizations during user interaction. However, if there is no user unlocking intention, meaning the electronic device is only briefly illuminated and the probability of it being used is low, the timer can remain paused.

[0114] Alternatively, if the JobService detects the user's intention to unlock while the timer is in progress, the timer can be canceled directly.

[0115] The process by which JobService monitors a user's unlocking intent can be found in the following: Figure 8 The described embodiments are as follows.

[0116] S18, the electronic device screen is off, and the PMS sends a screen off broadcast.

[0117] S19, JobService receives the screen-off broadcast sent by PMS again. If the timer is in a paused state, it continues to count down; if the timer is in a canceled state, it restarts the countdown.

[0118] Specifically, after a user unlocks and uses the electronic device and then turns the screen off again, or after the screen turns on and off again, the PMS will send a screen-off broadcast again. The JobService receives this broadcast and checks the current state of the timer. If the timer is paused, it means the electronic device was only turned on and not used, and the timer can resume counting. For example, if the timer was paused after 10 minutes in step S17, it will resume counting from 10 minutes. If the timer is canceled, it means the electronic device was used and the timer needs to be restarted, starting from 0.

[0119] For steps S16 to S19 above, in this embodiment of the application, the timer is canceled only when the user intends to unlock the electronic device. If the electronic device is only on but not unlocked, the timer is paused and can be resumed later. This allows the electronic device to perform compilation optimization as soon as possible, improves the efficiency of compilation optimization, and reduces the phenomenon of increased compilation power consumption or application lag.

[0120] S20, when the timer reaches the preset duration, JobService modifies the first flag to true.

[0121] That is, when the timer reaches the preset duration, it means that the electronic device has been off for the preset duration. At this time, JobService can change the first flag to true and then continue to determine whether other execution conditions are met.

[0122] S21, JobService determines the Job that depends on the condition that the first flag bit is true, and checks whether all execution conditions of the Job are met. If they are met, S22 is executed; otherwise, it waits for the conditions to be met.

[0123] When the first flag is true, meaning the condition is met, the JobService needs to determine which Jobs depend on this condition, and thus determine which Job to execute. Since the ArtService registers the Job and the conditions for the Job to start execution on the JobService, if the execution condition includes the first flag being true, the JobService can determine that the Job corresponding to the ArtService depends on the condition that the first flag is true, and can then further determine whether all execution conditions of the Job are met.

[0124] For example, if the Job corresponding to ArtService depends on the condition that the first flag is true, all execution conditions corresponding to the Job are queried, including: electronic device charging status + screen off for half an hour + battery level greater than M (e.g., M = 95%). If all these execution conditions are currently met, then the subsequent step S22 can be executed. Optionally, the electronic device can also set a flag to indicate whether all execution conditions of the Job are met. If all execution conditions of the Job are met, JobService modifies its corresponding flag to true. If the current battery level is not greater than M when the Job corresponding to ArtService depends on the condition that the first flag is true, then the execution conditions of the Job are not met, and the compilation process is temporarily suspended.

[0125] It is understood that there may be multiple Jobs that depend on the condition that the first flag bit is true. The JobService can perform corresponding operations on different Jobs. The embodiment of this application is to operate on the Job corresponding to the ArtService.

[0126] It is also understandable that ArtService can correspond to different Jobs in different scenarios, and the conditions of different Jobs are also different. For example, as described in the above scenario, the Fastiddle optimization method is executed under the condition that the electronic device screen is off for half an hour and the battery power is greater than 40%, while the daily idle compilation optimization method is executed under the condition that the electronic device is charging, the screen is off for half an hour and the battery power is greater than 95%. The execution conditions of the Jobs corresponding to these two optimization methods are different.

[0127] S22, JobService notifies ArtService to start the compilation process.

[0128] If the conditions are met as determined by S21, the compilation optimization process should begin, and JobService can then notify ArtService to start the compilation process. In one feasible approach, JobService can call the Start() function corresponding to the Job, using an Intent mechanism to inform ArtService to start the compilation process. Here, Intent is a runtime binding mechanism; once an Intent is issued, the system will accurately find the matching Service to respond.

[0129] S23, ArtService begins compilation optimization and sends the process ID of the compilation process to the power-saving wizard.

[0130] ArtService can use the dex2oat mechanism for compilation optimization, and the compilation process is the corresponding dex2oat process. ArtService also sends the process ID of the compilation process to the power-saving utility, allowing the utility to freeze the compilation process when needed, rather than stopping compilation altogether.

[0131] S24, during the compilation and optimization process, the electronic device screen turns on, and the PMS sends a screen-on broadcast.

[0132] In other words, during the ArtService compilation process, if a screen-on event occurs on the electronic device, it could be triggered by user operation or by a notification message subscribed to by the electronic device. In this case, PMS will send a screen-on broadcast again.

[0133] S25, the power-saving wizard receives the screen-on broadcast and freezes the compilation process based on the process ID of the compilation process.

[0134] S26, Power Saving Wizard sends a notification command to ArtService, informing ArtService that the compilation process has been frozen and compilation optimization has been paused.

[0135] If an electronic device changes from a screen-off state to a screen-on state, the Power Saving Wizard receives the screen-on broadcast and assumes that the electronic device may be in use. Therefore, the Power Saving Wizard can freeze the compilation process, i.e., pause the compilation, and notify ArtService of the frozen process.

[0136] S27, JobService receives the screen-on broadcast and monitors the user's intention to unlock.

[0137] S28, if the screen of the electronic device is off without detecting the user's intention to unlock, the PMS sends a screen off broadcast.

[0138] S29, JobService receives the screen-off broadcast, determines that the first flag is true, and then continues the process.

[0139] After receiving the screen-on broadcast, JobService will also monitor whether there is a user's intention to unlock. If no user's intention to unlock is detected, that is, the electronic device only lights up the screen briefly and the probability of it being used is small, then there is no need to terminate the compilation. The compilation process can be frozen.

[0140] In this case, if the electronic device changes to a screen-off state again (such as when the user turns off the power button or the screen turns off after a timeout), the PMS will send a screen-off broadcast again. After receiving the screen-off broadcast, the JobService will judge the first flag bit mentioned above (because the first flag bit has not changed since it was modified to true in S20 above), and if it is determined that the first flag bit is still true, the process will continue.

[0141] The process by which JobService monitors a user's unlocking intent can be found in the following: Figure 8 The described embodiments are as follows.

[0142] S30, the power-saving wizard receives the screen-off broadcast and unfreezes the compilation process according to the process ID of the compilation process.

[0143] S31, the power-saving wizard sends a notification command to ArtService, informing ArtService that the compilation process has been unfrozen and can continue compilation and optimization.

[0144] When PMS sends a screen-off broadcast, Power Saver will also receive the broadcast. Since JobService does not detect the user's intention to unlock the device at this time, meaning the electronic device is not in use, there will be no application lag. Therefore, the original compilation process can continue to execute. Thus, Power Saver can unfreeze the original compilation process and notify ArtService to continue compilation and optimization.

[0145] Regarding steps S24 to S31 above, in the compilation optimization process of this application embodiment, if the screen of the electronic device is turned on, the user's intention to unlock will be monitored. If the user does not intend to unlock the electronic device, that is, the electronic device is only turned on but not unlocked, the compilation process is frozen by the power saving tool, but the compilation process is not terminated. After the screen of the electronic device is turned off again, the original compilation process continues. This allows the electronic device to complete the compilation optimization process as soon as possible, improves the efficiency of compilation optimization, and reduces the phenomenon of increased compilation power consumption or application lag.

[0146] In some embodiments, the power consumption generated during the compilation and optimization process can cause the CPU temperature to rise. Excessive CPU temperature can also affect the performance of electronic devices. Therefore, this embodiment can also monitor the CPU temperature. If the CPU temperature exceeds a temperature threshold, a temperature sensor can send a high-temperature broadcast. Upon receiving the high-temperature broadcast, the power-saving utility freezes the compilation process based on its process ID and notifies ArtService that the compilation process has been frozen, pausing compilation and optimization. Once the CPU temperature drops below the temperature threshold, the temperature sensor can then send a low-temperature broadcast. Upon receiving the low-temperature broadcast, the power-saving utility unfreezes the compilation process based on its process ID and notifies ArtService that the compilation process has been unfrozen, allowing compilation and optimization to continue.

[0147] S32, upon detecting the user's intention to unlock, JobService notifies ArtService to terminate compilation.

[0148] S33, JobService modifies the first flag to false.

[0149] If JobService detects a user's intention to unlock the device, it determines that the electronic device is likely to be used. If continuing to compile would significantly impact the foreground application of the electronic device, then it can notify ArtService to terminate the compilation, i.e. cancel the current compilation optimization process, and at the same time modify the first flag to false for use in determining the execution conditions during the next recompilation.

[0150] S34, ArtService notifies the power-saving wizard that compilation has been terminated.

[0151] S35 is the process ID of the power-saving wizard that clears the compilation process.

[0152] After the compilation is terminated, the process ID in Power Saver no longer needs to be retained. Therefore, ArtService can notify Power Saver, and Power Saver can clear the corresponding process ID.

[0153] It's understandable that after the compilation process terminates, the results of any incomplete compilations of the application will be discarded, and the compilation will wait for the next iteration.

[0154] It is also understandable that after terminating the current compilation and optimization process, the electronic device will return to step S13, continue to wait for the next screen-off event and keep track of the preset duration, and iterate in this way until the complete compilation and optimization process is completed.

[0155] The process of JobService monitoring the user's unlocking intent in the above embodiments can be specifically described as follows: Figure 8 As shown, since there are currently multiple ways to unlock electronic devices, such as fingerprint unlocking, password unlocking, and facial recognition unlocking, this embodiment of the application can monitor multiple unlocking methods. When any unlocking method is detected, it will be reported to the JobService in a timely manner. This process includes the following steps:

[0156] S40, the kernel layer driver obtains the fingerprint information and reports the user's unlocking intent event to the JobService.

[0157] The fingerprint unlocking methods configured on electronic devices include, but are not limited to, side power button fingerprint unlocking and in-screen fingerprint unlocking. For in-screen fingerprint unlocking, the kernel-level TP driver can obtain fingerprint information when the user touches a designated location on the screen. For side power button fingerprint unlocking, the kernel-level fingerprint module driver can obtain fingerprint information when the user touches the side power button. Upon obtaining the fingerprint information, the kernel-level driver reports the user's unlocking intent event to the JobService. That is, as soon as the fingerprint information is obtained, before verifying whether the fingerprint belongs to a registered user, the user's unlocking intent event can be reported to the JobService. This allows the JobService to notify the ArtService to terminate the compilation process as quickly as possible, avoiding any lag or stuttering issues for the user.

[0158] S41, the kernel layer driver detects facial information and reports the user's unlocking intent event to the JobService.

[0159] In this embodiment, if the electronic device has its face unlock function enabled, the camera (such as a front-facing camera) will be in a state of real-time image acquisition. After the kernel-level camera driver (camera driver or hardware abstraction layer cameraHAL) detects the acquired image, it can determine whether it contains facial information. If it contains facial information, it will further identify whether it is the facial information of a registered user. In this embodiment, when the kernel-level driver detects facial information, it reports the user's unlocking intention to the JobService. That is, as soon as facial information is detected, before identifying whether the facial information belongs to a registered user, the user's unlocking intention event can be reported to the JobService, so that the JobService notifies the ArtService to terminate the compilation process as soon as possible.

[0160] S42, the System UI receives the first touch event and reports the user's unlock intent event to the JobService.

[0161] In this scenario, if a user has set a password for unlocking, they need to enter the corresponding password on the on-screen input panel to unlock the electronic device. This input panel can be presented through a System UI view. The user needs to enter several numbers sequentially (i.e., touch the corresponding touch points on the input panel) before successfully unlocking. Therefore, when the System UI receives the first touch event (touchdown event), i.e., the user touches the touch point corresponding to the first number, it reports the user's unlock intention event to the JobService, causing the JobService to notify the ArtService to terminate compilation as quickly as possible.

[0162] In some implementations, kernel-level drivers and the System UI can notify the JobService of a user unlock intent event by triggering a stub function.

[0163] S43, the System UI receives the home screen touch event and reports the user's unlock intent event to the JobService.

[0164] In some scenarios, electronic devices lack password, fingerprint, or facial recognition unlocking methods. When the screen is off, simply pressing the power button accesses the device's home screen; that is, the device enters the home screen as soon as the screen lights up. In such cases, if the user doesn't interact with the home screen after it lights up, it indicates the user isn't using the device, and compilation doesn't need to be terminated. However, if the System UI detects a touch event on the home screen, indicating a potential user interaction with the device, the System UI can report the user's unlocking intent to the JobService. This allows the JobService to notify the ArtService to terminate compilation as quickly as possible.

[0165] It is understood that steps S40 to S43 above are not sequential; they are merely descriptions of different ways to unlock electronic devices. Therefore, in any of the above situations, JobService will detect the user's unlocking intention and execute the process in S32 above. It is also understood that if none of the above situations occur, JobService will not detect the user's unlocking intention and will execute the process in S28 above to improve the efficiency of compilation optimization.

[0166] The foregoing has detailed examples of virtual machine optimization methods provided in the embodiments of this application. It is understood that, in order to achieve the above-mentioned functions, the electronic device includes hardware and / or software modules corresponding to the execution of each function. Those skilled in the art should readily recognize that, based on the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed by hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in conjunction with the embodiments, but such implementation should not be considered beyond the scope of this application.

[0167] This application embodiment can divide the electronic device into functional modules according to the above method example. For example, each function can be divided into a separate functional module, such as a detection unit, a processing unit, a display unit, etc., or two or more functions can be integrated into one module. The integrated module can be implemented in hardware or as a software functional module. It should be noted that the module division in this application embodiment is illustrative and only represents one logical functional division. In actual implementation, there may be other division methods.

[0168] It should be noted that all relevant content of each step involved in the above method embodiments can be referenced from the functional description of the corresponding functional module, and will not be repeated here.

[0169] The electronic device provided in this embodiment is used to execute the above-described virtual machine optimization method, and therefore can achieve the same effect as the above-described implementation method.

[0170] When using integrated units, the electronic device may further include a processing module, a storage module, and a communication module. The processing module is used to control and manage the operation of the electronic device. The storage module supports the execution of stored program code and data. The communication module supports communication between the electronic device and other devices.

[0171] The processing module can be a processor or a controller. It can implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. The processor can also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a digital signal processor and a microprocessor, etc. The storage module can be a memory. The communication module can specifically be a radio frequency circuit, a Bluetooth chip, a Wi-Fi chip, or other devices that interact with other electronic devices.

[0172] In one embodiment, when the processing module is a processor and the storage module is a memory, the electronic device involved in this embodiment can be a device having... Figure 5 The device shown has the following structure.

[0173] This application also provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it causes the processor to execute the optimized method of the virtual machine in any of the above embodiments. The storage medium may include various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0174] This application also provides a computer program product that, when run on a computer, causes the computer to perform the aforementioned steps to implement the virtual machine optimization method described in the above embodiments.

[0175] In addition, embodiments of this application also provide an apparatus, which may specifically be a chip, component, or module. The apparatus may include a connected processor and a memory. The memory is used to store computer execution instructions. When the apparatus is running, the processor can execute the computer execution instructions stored in the memory to cause the chip to execute the virtual machine optimization method in the above-described method embodiments.

[0176] In this embodiment, the electronic device, computer-readable storage medium, computer program product or chip are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can be referred to the beneficial effects of the corresponding methods provided above, and will not be repeated here.

[0177] Through the above description of the embodiments, those skilled in the art will understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0178] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0179] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A method for compiling a virtual machine, the method being applied to an electronic device, characterized in that, The method includes: When the electronic device is in a screen-off state, if the first flag is true and the execution conditions of the tasks that depend on the first flag being true are all met, then the virtual machine in the electronic device begins to perform compilation optimization. If the first flag is not true, then the timer is started and the timing duration is the preset duration; If the electronic device switches from a screen-off state to a screen-on state during the timing of the timer, the timing of the timer is paused. Monitor the user's unlocking intention. If the user's unlocking intention is detected, cancel the timer. If the user's unlocking intention is not detected, continue to pause the timer. When the electronic device switches to the screen-off state again, if the timer is in a paused state, it continues to count down; if the timer is in a canceled state, it restarts the countdown until the timer's duration reaches the preset duration, at which point the first flag is set to true. If the execution conditions of all tasks that depend on the first flag being true are met, then the virtual machine in the electronic device begins to perform compilation optimization. During the virtual machine compilation and optimization process, if the electronic device switches from a screen-off state to a screen-on state, the process corresponding to the compilation and optimization is frozen, and the virtual machine pauses the compilation and optimization. After the compilation optimization is paused in the virtual machine, the user's intention to unlock is monitored; If no user unlocking intent is detected and the electronic device switches to screen-off state again, the process corresponding to the compilation optimization is unfrozen, and the virtual machine continues to execute the compilation optimization; If a user's intent to unlock is detected, the process corresponding to the compilation optimization is cleared, and the compilation optimization is terminated.

2. The method according to claim 1, characterized in that, After terminating the compilation optimization, the method further includes: If the electronic device switches to a screen-off state again, the virtual machine will re-execute the compilation optimization when the first flag is true and the execution conditions of the tasks that depend on the first flag being true are met.

3. The method according to claim 2, characterized in that, The method further includes: If the first flag is true, but the execution conditions of the task that depends on the first flag being true are not met, the virtual machine will not perform compilation optimization.

4. The method according to any one of claims 1 to 3, characterized in that, If the electronic device switches from a screen-off state to a screen-on state, the process corresponding to the compilation optimization is frozen, and the virtual machine pauses the compilation optimization, including: The electronic device switches from a screen-off state to a screen-on state and sends a screen-on broadcast. Upon receiving the screen-on broadcast, the power-saving feature in the electronic device freezes the process corresponding to the compilation optimization. The power-saving wizard sends a notification command to the virtual machine, instructing the virtual machine to pause the compilation optimization.

5. The method according to claim 4, characterized in that, If no user unlocking intent is detected and the electronic device switches back to screen-off state, the process corresponding to the compilation optimization is unfrozen, and the virtual machine continues to execute the compilation optimization, including: The electronic device switches to screen-off mode and sends a screen-off broadcast. Upon receiving the screen-off broadcast, the power-saving wizard unfreezes the process corresponding to the compilation optimization. The power-saving wizard sends a notification command to the virtual machine, instructing the virtual machine to continue performing the compilation optimization.

6. The method according to any one of claims 1 to 3, characterized in that, If the execution conditions of tasks that depend on the first flag being true are all met, then the virtual machine in the electronic device begins to perform compilation optimization, including: After the task scheduling service in the electronic device determines that the timer's timing duration has reached the preset duration, it determines whether the battery power of the electronic device is greater than the first power level. If the battery level of the electronic device is greater than the first charge level, the task scheduling service notifies the virtual machine to start executing the compilation optimization.

7. The method according to any one of claims 1 to 3, characterized in that, The detection of a user's unlocking intent includes at least one of the following events: an event generated when the user inputs fingerprint information in the fingerprint unlocking area; an event generated when the user's face information is captured by the camera of the electronic device; an event generated when the user inputs the first touch event in the password unlocking area; and an event generated when the user touches the main screen of the electronic device.

8. The method according to any one of claims 1 to 3, characterized in that, In the event that the compilation optimization is terminated, the method further includes: Set the value of the first flag to false.

9. An electronic device, characterized in that, The electronic device includes: One or more processors, and memory; The memory is coupled to the one or more processors, the memory being used to store computer program code, the computer program code including computer instructions, the one or more processors invoking the computer instructions to cause the electronic device to perform the method as described in any one of claims 1 to 8.

10. A chip system, characterized in that, The chip system is applied to an electronic device, the chip system including one or more processors, the one or more processors being used to invoke computer instructions to cause the electronic device to perform the method as described in any one of claims 1 to 8.

11. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes instructions that, when executed on an electronic device, cause the electronic device to perform the method as described in any one of claims 1 to 8.

Citation Information

Patent Citations

  • Method and device for controlling hot update of application program, storage medium and mobile terminal

    CN108388431A

  • Compiling optimization method and device and electronic equipment

    CN111061483A

  • Application program optimization method and electronic equipment

    CN116643778A