Virtual machine compiling method and electronic equipment
By optimizing compilation while the electronic device is in a screen-off state, pausing compilation when the screen is on but not unlocked, and terminating compilation when the screen is on and unlocked, the problem of compilation interruption during user operation is solved, improving compilation efficiency and reducing power consumption and lag.
Patent Information
- Application Number
- CN202410600599.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-11
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2044-05-11
AI Technical Summary
During the compilation and optimization process of electronic devices, user operations may disrupt system conditions, causing the compilation and optimization process to be interrupted. Some applications may not complete the compilation and optimization, resulting in increased compilation power consumption or application lag.
The compilation and optimization process begins when the electronic device is in a screen-off state for a preset period of time and the battery has sufficient power. When the screen is on but not unlocked, the compilation is paused and resumed. When the screen is on and unlocked, the compilation is terminated. The compilation process is frozen and unfrozen through a power-saving tool to ensure that the compilation process continues at the appropriate time.
It improves the efficiency of compilation optimization, reduces the increase in compilation power consumption and application lag, and ensures that the compilation process is completed smoothly under appropriate conditions.
Smart Images

Figure CN120973482A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of electronics, in particular to a virtual machine compiling method and an electronic device. BACKGROUND
[0002] Generally, after system upgrade or application upgrade of an electronic device, recompilation is needed for normal operation. In order to reduce compiling power consumption and reduce application freezing phenomenon caused in the compiling process, the electronic device can perform compiling optimization on the application. The current common compiling optimization scenarios include: optimization process performed when the electronic device is started for the first time after upgrade, and optimization process performed when the electronic device is idle every day. Both of the two ways are basically background compiling processes triggered after the system meets certain conditions.
[0003] However, if the operation performed by the user breaks the condition met by the system in the compiling optimization process, the current compiling optimization process will be stopped, resulting in incomplete compiling optimization process, which will cause some applications not to be compiled, and increase in compiling power consumption or application freezing phenomenon. SUMMARY
[0004] The present application provides a virtual machine compiling method and an electronic device, which can improve the efficiency of compiling optimization, and reduce the increase in compiling power consumption or application freezing phenomenon.
[0005] In a first aspect, the present application provides a virtual machine compiling method, which is applied to an electronic device, and includes: starting, by a virtual machine in the electronic device, compiling optimization when the electronic device is in a screen-off state for a time length reaching a preset time length and the battery power of the electronic device is greater than a first power; pausing, by the virtual machine, the compiling optimization when the electronic device is switched from the screen-off state to a screen-on state; and continuing, by the virtual machine, the compiling optimization if the electronic device is not unlocked and is switched to the screen-off state again after the compiling optimization is paused.
[0006] That is to say, the electronic device starts the compiling optimization when the compiling execution condition is met (i.e. the time length in the screen-off state reaches the preset time length, and the battery power is greater than the first power), and the virtual machine pauses the compiling optimization if the electronic device has a screen-on event in the process of the compiling optimization. Since the screen-on event of the electronic device can be triggered by the screen-on of the user operation or the screen-on triggered by the notification message subscribed by the electronic device, if the electronic device is only screen-on but not unlocked, it means that the probability of being used by the user is small, and the subsequent compiling optimization has little effect on the operation of the electronic device. Therefore, the virtual machine can continue the original compiling optimization when the electronic device is not unlocked and is switched to the screen-off state again, so that the electronic device can complete the compiling optimization process as soon as possible, improve the efficiency of compiling optimization, and reduce the increase in compiling power consumption or application freezing phenomenon.
[0007] In an implementation manner, the preset time length can be half an hour.
[0008] With reference to the first aspect, in some implementation manners of the first aspect, after the virtual machine suspends the compiling optimization, the method further includes: in a case where the electronic device monitors a user input of an unlocking operation, terminating the compiling optimization; and in a case where the electronic device switches to the screen-off state again, when a time length in the screen-off state reaches a preset time length, the virtual machine re-executes the compiling optimization.
[0009] In the process of the compiling optimization, if the virtual machine suspends the compiling optimization and a user unlocking operation is monitored, that is, a user unlocking intention is monitored, it indicates that the probability of the user using the electronic device is relatively large, and the subsequent continuous compiling will have a relatively large impact on the running of the electronic device. Therefore, at this time, the compiling optimization process can be terminated, and the virtual machine can be caused to re-execute the compiling optimization when the electronic device enters the screen-off state again and the screen-off time length reaches the preset time length. In this way, the phenomenon of lag caused by the compiling optimization process to the running of the electronic device can be reduced.
[0010] With reference to the first aspect, in some implementation manners of the first aspect, the method further includes: in a case where the time length of the electronic device in the screen-off state reaches the preset time length and the battery power of the electronic device is not greater than a first power, the virtual machine does not execute the compiling optimization.
[0011] That is, in a case where the compiling execution condition (that is, the time length in the screen-off state reaches the preset time length and the battery power is greater than the first power) is not met, the electronic device should not execute the compiling optimization, and needs to wait until the compiling execution condition is met to start executing the compiling optimization.
[0012] With reference to the first aspect, in some implementation manners of the first aspect, in a case where the electronic device switches from the screen-off state to the screen-on state, the virtual machine suspends the compiling optimization, and the process includes: the electronic device switches from the screen-off state to the screen-on state, and sends a screen-on broadcast; the power saving daemon in the electronic device receives the screen-on broadcast, and freezes a process corresponding to the compiling optimization; and the power saving daemon sends a notification instruction to the virtual machine, and notifies the virtual machine to suspend the compiling optimization.
[0013] In the present application, the process of the virtual machine suspending the compiling optimization can be controlled by the power saving daemon, that is, in a case where the electronic device switches from the screen-off state to the screen-on state, a screen-on broadcast can be sent, for example, the screen-on broadcast can be sent by the power management module (PMS), the power saving daemon receives the broadcast, freezes a process (which can be referred to as a compiling process) corresponding to the compiling optimization, and sends a notification instruction to the virtual machine, and notifies the virtual machine that the compiling process has been frozen and the compiling optimization is suspended. The implementation manner suspends the compiling optimization by the mechanism of freezing the process, so that the process is unfrozen in time when the compiling optimization needs to be continued subsequently, and the compiling optimization efficiency is improved.
[0014] With reference to the first aspect, in some implementations of the first aspect, if the electronic device is not unlocked and switches to the screen-off state again, the virtual machine continues to perform the compilation optimization, including: the electronic device switches to the screen-off state and sends a screen-off broadcast; the power saving daemon receives the screen-off broadcast and unfreezes the compilation optimization process; and the power saving daemon sends a notification instruction to the virtual machine, notifying the virtual machine to continue the compilation optimization.
[0015] As can be seen from the above description, in the case where the electronic device is not unlocked and switches to the screen-off state again, the virtual machine can continue to perform the original compilation optimization, and in the case where the compilation process is frozen, it needs to be unfrozen. Then, after the electronic device enters the screen-off state again, a screen-off broadcast can be sent, for example, the PMS can send a screen-off broadcast, and after the power saving daemon receives the broadcast, the compilation process can be unfrozen, and a notification instruction can be sent to the virtual machine, notifying the virtual machine that the compilation process has been unfrozen and the compilation optimization continues. Thus, the electronic device does not need to wait for half an hour after the screen is turned off to perform the compilation optimization, and the compilation optimization efficiency is improved.
[0016] With reference to the first aspect, in some implementations of the first aspect, the duration of the electronic device in the screen-off state reaches the preset duration, including: starting a timer to time when the electronic device enters the screen-off state; if the electronic device switches to the screen-on state during the timing of the timer, pausing the timing of the timer, and if the electronic device monitors a user input unlock operation, canceling the timing of the timer; and if the electronic device switches to the screen-off state again, continuing the timing if the timer is in the paused state, or restarting the timing if the timer is in the canceled state, until the timing duration reaches the preset duration.
[0017] In some scenarios, the electronic device may be in the screen-on state when it is in the screen-off state, and the related art cancels the timing of the screen-off duration after the electronic device is in the screen-on state, and restarts the timing when the electronic device is in the screen-off state again, which may cause the compilation execution condition to be met later, i.e., the start time of the compilation optimization is delayed. Therefore, in the process of timing the screen-off duration of the electronic device, if the electronic device switches to the screen-on state, the timing of the timer is paused first, and when a user input unlock operation is monitored, i.e., a user unlock intention is monitored, it means that the probability of using the electronic device by the user is high, and the timing of the timer can be canceled at this time. In the case where no user unlock intention is monitored, i.e., the electronic device is only on for a short time, the probability of being used is small, and the paused state of the timer can be maintained.
[0018] In this way, when the electronic device switches to the screen-off state again, the current state of the timer can be determined. If the timer is in the pause state, it indicates that the electronic device was only screen-on and was not used, and the timer can continue to count. If the timer is in the cancel state, it indicates that the electronic device was used and needs to be re-timed. In this way, the electronic device can reduce the case of re-timing the screen-off duration, so that the electronic device can perform compilation optimization as soon as possible, and the efficiency of compilation optimization can be improved.
[0019] In combination with the first aspect, in some implementations of the first aspect, in the case that the duration that the electronic device is in the screen-off state reaches the preset duration and the battery level of the electronic device is greater than the first level, the virtual machine in the electronic device starts to perform the compilation optimization, including: the task scheduling service in the electronic device determines that the counting duration of the timer reaches the preset duration, and then determines whether the battery level of the electronic device is greater than the first level; in the case that the battery level of the electronic device is greater than the first level, the task scheduling service notifies the virtual machine to start to perform the compilation optimization.
[0020] In combination with the first aspect, in some implementations of the first aspect, in the case that the duration that the electronic device is in the screen-off state reaches the preset duration and the battery level of the electronic device is greater than the first level, the virtual machine in the electronic device starts to perform the compilation optimization, including: the task scheduling service in the electronic device determines that the counting duration of the timer reaches the preset duration, and then determines whether the battery level of the electronic device is greater than the first level; in the case that the battery level of the electronic device is greater than the first level, the task scheduling service notifies the virtual machine to start to perform the compilation optimization.
[0021] It can be understood that, in the case that the electronic device monitors the user input unlocking operation, the virtual machine can also be notified by the JobService to terminate the compilation optimization.
[0022] In combination with the first aspect, in some implementations of the first aspect, after the virtual machine pauses the compilation optimization, the method further includes: determining whether a user input unlocking operation is monitored; and in the case that the user input unlocking operation is not monitored, determining that the electronic device is not unlocked.
[0023] As can be seen from the above description, after the virtual machine pauses the compilation optimization, the electronic device is not unlocked, and the subsequent compilation optimization will continue. Therefore, it is necessary to monitor whether the electronic device is unlocked, that is, whether the user has an input unlocking operation. If the user input unlocking operation is not monitored, it indicates that the electronic device is not unlocked, and the compilation optimization can continue after the screen is turned off again, so that the efficiency of the compilation optimization can be improved.
[0024] In some implementations of the first aspect, in response to determining that the user input unlocking operation is monitored, the method further includes: in response to determining that the user input unlocking operation is monitored, setting a first flag to true, wherein the first flag is used to indicate whether the electronic device has been in the screen-off state for a preset time length.
[0025] Since there are various ways to unlock the electronic device, such as fingerprint unlocking, password unlocking, face unlocking, etc., the present application can monitor various unlocking methods, and when any unlocking method is monitored, it can be considered that there is a user unlocking intention. In the fingerprint unlocking method, as long as the fingerprint information input by the user in the fingerprint unlocking area is obtained, a user unlocking intention event can be generated and reported to the JobService; in the face unlocking method, as long as the face information collected by the camera is obtained, a user unlocking intention event can be generated and reported to the JobService; in the password unlocking method, as long as the first touch event input by the user in the password unlocking area is obtained, a user unlocking intention event can be generated and reported to the JobService, thereby determining that the user input unlocking operation is monitored. Alternatively, in the case where no unlocking method is set, the electronic device displays the home screen after the screen is turned on, and if the user has a touch operation on the home screen, it is also considered that there is a user unlocking intention. Of course, in the case where no user unlocking intention event is received, it can be determined that the user input unlocking operation is not monitored.
[0026] In some implementations of the first aspect, in response to determining that the electronic device has been in the screen-off state for the preset time length, the method further includes: setting the value of the first flag to true.
[0027] In some implementations of the first aspect, in response to the electronic device terminating the compilation optimization, the method further includes: setting the value of the first flag to false.
[0028] The first flag is used to indicate whether the electronic device has been in the screen-off state for a preset time length. For example, the first flag being true indicates that the electronic device has been in the screen-off state for a preset time length, and the first flag being false indicates that the electronic device has not been in the screen-off state for a preset time length. In response to setting the value of the first flag, the electronic device can determine whether the condition is met according to the value of the first flag in the future, so as to execute the corresponding process.
[0029] In a second aspect, the present application provides an apparatus, which is included in an electronic device, and the apparatus has a function of implementing the behaviors of the electronic device in the first aspect and possible implementation manners of the first aspect. The function can be implemented by hardware, or the function can be implemented by hardware executing corresponding software. The hardware or software includes one or more modules or units corresponding to the above functions. For example, a receiving module or unit, a processing module or unit, and the like.
[0030] In a third aspect, the present 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 configured to store computer program codes including computer instructions. The one or more processors invoke the computer instructions to cause the electronic device to perform any of the methods in the first aspect.
[0032] In a fourth aspect, the present application provides a chip system, which is applied to an electronic device, and the chip system includes one or more processors. The one or more processors are configured to invoke computer instructions to cause the electronic device to perform the methods in the first aspect and any possible implementation manners thereof.
[0033] Optionally, the chip system further includes a memory, and the memory is connected to the processor through a circuit or a wire.
[0034] Further optionally, the chip system further includes a communication interface.
[0035] In a fifth aspect, the present application provides a computer-readable storage medium, which includes instructions. When the instructions are run on an electronic device, the instructions cause the electronic device to perform any of the methods in the first aspect.
[0036] In a sixth aspect, the present application provides a computer program product, which includes computer program codes. When the computer program codes are run on an electronic device, the computer program codes cause the electronic device to perform any of the methods in the first aspect. BRIEF DESCRIPTION OF DRAWINGS
[0037] Figure 1 is an example of a compilation principle schematic diagram provided by an embodiment of the present application;
[0038] Figure 2 is an example of an AOT compilation principle schematic diagram provided by an embodiment of the present application;
[0039] Figure 3 is an example of a process schematic diagram for compiling an APK file provided by an embodiment of the present application;
[0040] Figure 4 is a schematic diagram of an example of a compilation optimization process provided by the related art;
[0041] Figure 5 is a structural schematic diagram of an example of an electronic device provided by an embodiment of the present application;
[0042] Figure 6 is a software structure block diagram of an example of an electronic device provided by an embodiment of the present application;
[0043] Figure 7 is a flowchart of an example of a compilation method of a virtual machine provided by an embodiment of the present application;
[0044] Figure 8 is a flowchart of an example of monitoring a user's unlocking intention provided by an embodiment of the present application. DETAILED DESCRIPTION
[0045] In the following description of embodiments of the present application, unless otherwise specified, " / " means "or", for example, A / B can mean A or B; "and / or" in this document is only a description of the association relationship of the associated objects, which means that there can be three relationships, for example, A and / or B, which means that there are three cases of A alone, A and B together, and B alone. In addition, in the description of embodiments of the present application, "multiple" means two or more than two.
[0046] Hereinafter, the terms "first", "second", "third" are only for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features. Therefore, the features defined with "first", "second", "third" can explicitly or implicitly include one or more features.
[0047] In order to describe each of the following embodiments clearly and concisely, first, a brief introduction of related concepts or technologies is given:
[0048] Interpretive execution: a programming language execution mode that translates source code line by line into machine code and executes immediately. The language of interpretive execution needs to be translated into code at runtime, which means that the interpreter needs to read the source code line by line and convert it into instructions that the electronic device can recognize at runtime.
[0049] Just-in-time (JIT): a compilation mode that translates bytecode into machine code and executes it at runtime. During program execution, hot code is calculated according to the algorithm, and then real-time compilation is performed, which requires runtime resources and will cause process lag.
[0050] AOT (ahead of time): opposite of JIT, is a compilation method that converts bytecode to machine code before the program runs, which can improve runtime efficiency.
[0051] dex2oat (dalvik executable file to optimized art file): a program that compiles and optimizes dex files, used to convert Dalvik bytecode to native machine code, for example, the storage location in Android devices is / system / bin / dex2oat, and after starting, it corresponds to the dex2oat process.
[0052] dex file: Dalvik bytecode file, executable file that can be recognized by the virtual machine in the electronic device.
[0053] odex file: optimized dex file, stores executable machine code.
[0054] profile file: configuration file, records the index information of hot functions in the electronic device compilation optimization process, and can be updated continuously.
[0055] With the continuous optimization of electronic technology, electronic devices will be upgraded from time to time, and the system and application will be upgraded. In general, after the system or application is upgraded, it needs to be recompiled to run normally.
[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 a certain programming language into an equivalent program in another language. Generally, the Android application package (APK) and JAR (Java archive) package downloaded in electronic devices (such as mobile phones running the Android system) are written based on the Java language. If you want to run it on an electronic device, you need to compile these program packages and convert them into a language that the electronic device can recognize. Among them, the Java language code will be simply translated into bytecode for cross-platform running when compiled into APK. This bytecode can be stored in a dex file and can be recognized by the virtual machine (Android runtime, ART) in different platforms (or electronic devices). However, after the virtual machine recognizes it, it still needs to be compiled into platform-adapted machine code according to the platform on which the virtual machine runs, so that it can be executed by the central processing unit (CPU).
[0057] For early compilation processes, such as Figure 1As shown, after the Java language code is translated into bytecode, the virtual machine compiles the bytecode using the JIT compilation method or the interpretation execution method, that is, the bytecode is translated into machine code in real time during running and then executed by the CPU, and the operation of translating the bytecode into machine code is required each time, which undoubtedly increases the compilation power consumption and the application running lag phenomenon caused by the compilation. To solve this problem, the developers developed the AOT compilation optimization method, that is, the bytecode of the commonly used functions (or hotspot functions) in the APK is translated into machine code in advance and stored, for example, stored as an odex file; in subsequent running, if the virtual machine finds that the odex file has been compiled, the virtual machine directly executes the machine code of the stored odex file without compiling the function again, and if there is no odex file, the virtual machine compiles the function into platform-adapted machine code, and the machine code can also be saved as an odex file for next running, thereby reducing the compilation amount and the compilation power consumption and improving the running efficiency. Figure 2 As shown, the virtual machine first checks whether the odex file has been compiled, if there is the odex file, the function is not compiled again, but the machine code of the stored odex file is directly executed, and for the function without the odex file, the virtual machine compiles the function into platform-adapted machine code, and the machine code can also be saved as an odex file for next running, thereby reducing the compilation amount and the compilation power consumption and improving the running efficiency.
[0058] In actual scenarios, the APK file includes multiple functions, some of which are hotspot functions and some of which are non-hotspot functions. For the AOT compilation optimization method, some hotspot functions can be compiled into odex files and stored, and some hotspot functions and non-hotspot functions need to be compiled using the JIT compilation method or the interpretation execution method. Then, the virtual machine dynamically decides the compilation strategy of each function during the compilation process, so that the compilation performance is optimized as much as possible.
[0059] Exemplarily, as shown in the following table, the virtual machine dynamically decides the compilation strategy of each function during the compilation process, so that the compilation performance is optimized as much as possible. Figure 3As shown, for an APK file, the electronic device can on one hand install and decompress it, obtain the dex file therein and hand it over to the virtual machine for subsequent compilation and running, and on the other hand start loading, judge whether there is an odex file, if there is an odex file, store the odex file on disk, and hand it over to the virtual machine for subsequent running, if there is no odex file, check the dex file based on the vdex file storing the dex file check information, and execute the subsequent compilation process after the check is passed. In the compilation and running, the virtual machine first judges whether the current method function has been compiled, if it has been compiled and is JIT compilation, runs the machine code of the code cache, if it has been compiled but is not JIT compilation, that is, AOT compilation, runs the corresponding odex file. If the current method function has not been compiled, the virtual machine performs interpretation execution, and records as a hot function after running multiple times, if the current function is a hot function and in the case of sufficient memory space, the virtual machine performs JIT compilation, and stores in the code cache after the compilation is completed; if it is a hot function but the memory space is not sufficient, first perform memory recycling (such as garbage collection (GC)), and then see whether the memory space is sufficient after the recycling is completed, if the memory space is sufficient, perform JIT compilation, and store in the code cache after the compilation is completed, if the memory space is still not sufficient, stop JIT compilation. If the current function is not a hot function, continue to perform interpretation execution. Among them, after a function is recorded as a hot function, the virtual machine can also record the function index in the profile file to update the number of hot functions; in the case that the number of hot functions in the profile file changes by more than a certain value (such as an increase of 2%), the virtual machine can also trigger daily idle background compilation.
[0060] For the above APK file, in the daily running process, the virtual machine can also perform the optimization operation of daily idle background compilation, for compiling all hot functions in the profile file, and storing the compilation result (odex file) on disk for subsequent compilation to be directly executed, here the virtual machine can use the dex2oat mechanism in the background compilation. And when the APK file is installed and updated, the electronic device also synchronizes a new profile file from the cloud, and deletes the old profile file, so that the new profile file is used in the subsequent daily idle background compilation.
[0061] The above is the AOT-based compilation optimization process of the virtual machine. In what scenarios is compilation optimization needed? Through research, it is found that in some scenarios, after the electronic device performs hota upgrade, patch optimization, etc., the corresponding JAR package or APK file will change, and the index of the functions contained will also change. Those need to be recompiled. The electronic device can perform background compilation optimization and store the compilation result. In other scenarios, after the application in the electronic device is upgraded, it also needs to be recompiled. Some applications may perform just-in-time compilation during foreground running, but the just-in-time compilation result is not stored, so the electronic device will perform compilation optimization again in the background to store the compilation result. Therefore, the compilation method of the virtual machine provided in the present application can be applied to any scenario that needs background compilation optimization.
[0062] Taking the scenario of hota upgrade of the electronic device as an example, the electronic device downloads and installs the hota package, and usually restarts after installation. The electronic device will perform compilation optimization for the first time after the upgrade, that is, Fastidle, which can optimize the TOP15 application. In addition, after Fastidle is completed, the electronic device can also perform daily idle compilation optimization, that is, perform compilation optimization once a day during the idle period. Therefore, the optimization process performed by the electronic device for the first time after the upgrade and the optimization process performed during the idle period every day are the current main compilation optimization approaches.
[0063] For the Fastidle optimization method, it is generally executed under the condition that the electronic device is turned off for half an hour + the battery power is greater than 40%, which can complete the compilation process of the TOP15 application in advance and has low power consumption. For the daily idle compilation optimization method, it is generally executed under the condition that the electronic device is in a charging state + turned off for half an hour + the battery power is greater than 95%, which can perform full-plate compilation and has good performance. From the execution conditions of the two optimization methods, it can be seen that the conditions set are relatively strict, and the charging state, turned-off time, and battery power all have specific requirements. This is because the load is large during compilation. If it is executed when the user uses the electronic device in the lighted screen state, it will cause the foreground application to run to be lagging, the device to heat up, etc. Especially for the daily idle compilation optimization method, it also needs to meet the condition that the battery power is greater than 95% in the charging state. This is because if it is executed in the early stage of charging, it will cause the charging to heat up too much and the charging to be too slow, which greatly affects the charging process.
[0064] Therefore, under the execution condition of the above setting, the electronic device will enter the compilation optimization process if the condition is met. However, due to the strictness of the setting condition, the condition may not be easily met, or the condition may be broken during the compilation optimization process, resulting in delayed execution of the compilation optimization or the optimization process being stopped, i.e., the complete compilation optimization process is not completed. For example, in the above daily idle compilation optimization mode, the condition of the charging state + screen-off for half an hour + battery power greater than 95% needs to be met. However, in actual scene investigation, it is found that the current electronic device supports fast charging mode, so when charging, the battery power may reach 95% and the charging may be completed in less than half an hour. Or the electronic device is constantly turned on due to user operation, which will break the execution condition of the compilation optimization, resulting in incomplete compilation optimization process, so that some applications are not compiled, resulting in increased power consumption or application lag.
[0065] Exemplarily, the flow of some related technologies for judging the execution condition and entering the compilation optimization step can be seen from Figure 4 As shown, first, the virtual machine (ART) is started, and a timing compilation task (Job) and a condition are set. The condition is the execution condition described above. Then, when the electronic device is screen-off, a timer is started to time. It is assumed that the timing duration is half an hour. If the electronic device is turned on before the timing duration is reached, the timer timing is cancelled, and the electronic device is waited to enter the screen-off state again. After the screen-off, the timer will start timing from 0 again, and so on until the timer reaches the timing duration. That is to say, during the screen-off timing process, once the electronic device is turned on and then turned off, the timer will start timing again, which undoubtedly increases the time delay of entering the compilation optimization step. If the timer reaches the timing duration, i.e., the screen-off for half an hour, the virtual machine judges whether the other conditions in the execution condition are met. If yes, the compilation optimization is started. If the electronic device is turned on during the compilation optimization process, the virtual machine will exit the compilation optimization process and stop the compilation. At this time, the compilation result of the application that is not compiled is discarded, and the next compilation is waited. Then, the virtual machine will re-judge whether the execution condition is met and detect the screen-off state of the electronic device. After the electronic device is screen-off, the step of starting the timer to time for half an hour is re-entered, and the cycle is repeated. Therefore, during the stage of not completing the complete compilation optimization, the partial application runtime will be interpreted or JIT compiled, resulting in increased compilation power consumption or application lag.
[0066] Based on the problems in the related art, we find that the related art needs to wait for the electronic device to be off-screen for more than the timing duration before starting compilation, and once the electronic device is on-screen, the timing is restarted, and once the electronic device is on-screen during the compilation optimization process, the compilation is stopped, which is to avoid the application running on the screen being stuck if the compilation continues after the electronic device is on-screen. However, in actual scenarios, the on-screen event of the electronic device may not be caused by user operation or the user may not have the intention to use the electronic device, that is, the electronic device does not run the application on the screen, for example, in the case that the electronic device has the functions of notification on-screen or hand-lifting on-screen, the electronic device will trigger on-screen when receiving a notification message or lifting the hand when holding the electronic device, but there is no actual application running. For another example, the user only checks the time after pressing the power button to turn on the screen, and does not have the intention to actually operate the electronic device to run the application. In these scenarios, the electronic device will not affect the normal compilation optimization process even if it is on-screen, and does not need to stop the compilation. Therefore, the embodiments of the present application optimize these scenarios and propose a compilation method of a virtual machine. After the electronic device is on-screen, the user's unlocking intention is monitored, and the compilation is not stopped in the case that there is no user's unlocking intention, so as to improve the efficiency of the compilation optimization, complete the complete compilation optimization process as soon as possible, and reduce the phenomenon of increased compilation power consumption or application sticking.
[0067] It should be noted that the compilation method of the virtual machine provided by the embodiments of the present application can be applied to electronic devices such as mobile phones, tablet computers, wearable devices, vehicle-mounted devices, augmented reality (AR) / virtual reality (VR) devices, and smart home devices, which may need to be compiled and optimized. The embodiments of the present application do not make any limitation on the specific type of electronic device.
[0068] Exemplarily, Figure 5Fig. 1 is a structural schematic diagram of an electronic device 100 provided by an embodiment of the present application. Taking the electronic device 100 as a mobile phone for example, the electronic device 100 can 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 loudspeaker 170A, a receiver 170B, a microphone 170C, a headset interface 170D, a sensor module 180, a key 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 can include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0069] The processor 110 can include one or more processing units, for example: the processor 110 can 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. Different processing units can be independent devices or integrated in one or more processors.
[0070] The charging management module 140 is configured to receive 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 can receive charging input from a wired charger through the USB interface 130. In some wireless charging embodiments, the charging management module 140 can receive wireless charging input through a wireless charging coil of the electronic device 100. The charging management module 140 can charge the battery 142 and supply power to the electronic device through the power management module 141.
[0071] The power management module 141 is configured to connect the battery 142 and the charging management module 140 to the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140 to power the processor 110, the internal memory 121, the external memory, the display 194, the camera 193, and the wireless communication module 160, etc. The power management module 141 can also be configured to monitor parameters such as the battery capacity, the number of battery cycles, the battery health status (leakage, impedance), etc. In some other embodiments, the power management module 141 can also be disposed in the processor 110. In some other embodiments, the power management module 141 and the charging management module 140 can also be disposed in the same device.
[0072] The wireless communication function of the electronic device 100 can be implemented by the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor, and the baseband processor, etc.
[0073] The wireless communication module 160 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) network), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR) technology, etc. applied to the electronic device 100. The wireless communication module 160 can be one or more devices integrated with at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, performs frequency modulation and filtering processing on the electromagnetic wave signals, and sends the processed signals to the processor 110. The wireless communication module 160 can also receive signals to be sent from the processor 110, perform frequency modulation, amplification, and convert them into electromagnetic wave radiation via the antenna 2.
[0074] The electronic device 100 implements the display function by the GPU, the display 194, and the application processor, etc. The GPU is a microprocessor for image processing, connected to the display 194 and the application processor. The GPU is configured to perform mathematical and geometric calculations for graphics rendering. The processor 110 can include one or more GPUs that execute program instructions to generate or change display information.
[0075] The display screen 194 is configured to display images, videos, and the like. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flex light-emitting diode (FLED), a Miniled, a MicroLed, a Micro-oLed, a quantum dot light emitting diodes (QLED), or the like. In some embodiments, the electronic device 100 can include one or N display screens 194, where N is a positive integer greater than 1.
[0076] The camera 193 is configured to capture still images or videos. An object generates an optical image through a lens and projects the optical image to a photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then transmits the electrical signal to an ISP to convert the electrical signal 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 an image signal in a standard format, such as RGB, YUV, or the like. In some embodiments, the electronic device 100 can include one or N cameras 193, where N is a positive integer greater than 1.
[0077] The NPU is a neural-network (NN) computing processor that is configured to quickly process input information by imitating the structure of a biological neural network, such as the transmission mode between neurons in the human brain, and is also configured to continuously self-learn. Through the NPU, the electronic device 100 can implement intelligent cognitive applications, such as image recognition, face recognition, voice recognition, text understanding, and the like.
[0078] The internal memory 121 can be used to store computer executable program codes, the executable program codes including instructions. The processor 110 performs various function applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. The internal memory 121 can include a program storage area and a data storage area. The program storage area can store an operating system, application programs required by at least one function (such as a sound playing function, an image playing function, etc.), and the like. The data storage area can store data (such as audio data, a phone book, etc.) created during use of the electronic device 100, and the like. In addition, the internal memory 121 can include a high-speed random access memory, and can further include a non-volatile memory such as at least one magnetic disk storage device, a flash memory device, a universal flash storage (UFS), and the like.
[0079] The fingerprint sensor 180H is used to collect a fingerprint. The electronic device 100 can implement fingerprint unlocking, access to an application lock, fingerprint photographing, fingerprint answering a call, and the like by using the collected fingerprint characteristics.
[0080] The touch sensor 180K, also referred to as a “touch panel”. The touch sensor 180K can be disposed on the display screen 194, and the touch sensor 180K and the display screen 194 form a touch screen, also referred to as a “touch panel”. The touch sensor 180K is used to detect a touch operation acting on or near the touch sensor 180K. The touch sensor 180K can transmit the detected touch operation to the application processor to determine a touch event type. Visual output related to the touch operation can be provided through the display screen 194. In other embodiments, the touch sensor 180K can also be disposed on the surface of the electronic device 100, which is different from the position of the display screen 194.
[0081] The keys 190 include a power-on key, a volume key, and the like. The keys 190 can be mechanical keys. They can also be touch keys. The electronic device 100 can receive key inputs and generate key signal inputs related to user settings and function control of the electronic device 100.
[0082] The indicator 192 can be an indicator light, which can be used to indicate a charging state, a power change, and can also be used to indicate a message, a missed call, a notification, and the like.
[0083] It can be understood that the structure illustrated in the embodiments of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 can include more or fewer components than illustrated, or combine certain components, or split certain components, or different component arrangements. The illustrated components can be implemented in hardware, software, or a combination of software and hardware.
[0084] The software system of the electronic device 100 can employ a layered architecture, an event-driven architecture, a microkernel architecture, a microservices architecture, or a cloud architecture. Embodiments of the present application take an Android system with a layered architecture as an example to illustrate the software structure of the electronic device 100.
[0085] Figure 6 is a software structure block diagram of the electronic device 100 according to an embodiment of the present application. The layered architecture divides the software into several layers, each of which has 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 Android runtime and system library, and the kernel layer. The application layer can include a series of application packages.
[0086] As shown in Figure 6 , the application packages can include camera, gallery, call, navigation, WLAN, video, power saving genie, and other applications, and can also include a system user interface (SystemUI). Among them, SystemUI is a system-level application and a key component of the Android operating system, mainly responsible for managing and providing core elements of the user interface, such as the status bar, the navigation bar, and the lock screen interface, etc. In embodiments of the present application, SystemUI can report the user unlock intention to JobService when detecting the user unlock intention.
[0087] The application framework layer provides application programming interfaces (APIs) and programming frameworks for the applications of the application layer. The application framework layer includes some pre-defined functions.
[0088] As shown in Figure 6 , the application framework layer can include a window manager, a view system, a phone manager, a resource manager, a notification manager, a task scheduler (JobScheduler), a power manager (PMS), and the like.
[0089] The PMS is used to manage the power of the electronic device, such as managing events such as turning on the screen and turning off the screen. In embodiments of the present application, the PMS can send a screen-on broadcast when the electronic device is turned on and a screen-off broadcast when the electronic device is turned off. Among them, the power saving genie described above 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 for triggering the execution of a task at a future time when certain conditions are met, which can be network, power, time, etc. JobService is the callback of JobScheduler, which is used to implement the specific task logic. In the embodiments of the present application, JobService can be used to notify ArtService to start or terminate the compilation process.
[0091] The window manager is used to manage window programs. The window manager can obtain the size of the display screen, determine whether there is a status bar, lock the screen, and intercept the screen, etc. The view system includes visual controls, such as controls for displaying text and controls for displaying pictures, etc. The view system can be used to build application programs. A display interface can be composed of one or more views. For example, a display interface including a short message notification icon can include a view for displaying text and a view for displaying pictures. The phone manager is used to provide the communication function of the electronic device 100. For example, the management of the call state (including connection, hang-up, etc.). The resource manager provides various resources for application programs, such as localized strings, icons, pictures, layout files, video files, etc. The notification manager enables application programs to display notification information in the status bar, which can be used to convey messages of the notification type, which can automatically disappear after a short stay without user interaction. For example, the notification manager is used to notify the completion of the download, message reminders, etc. The notification manager can also be a notification in the form of a chart or a scroll bar text appearing in the top status bar of the system, such as a notification of an application running in the background, and can also be a notification in the form of a dialog window appearing on the screen. For example, prompting text information in the status bar, issuing a prompt sound, vibrating the electronic device, and flashing the indicator light, etc.
[0092] The Android runtime includes the core library and the virtual machine. The Android runtime is responsible for the scheduling and management of the Android system.
[0093] The core library includes two parts: one part is the function function that the java language needs to call, and the other part is the core library of Android.
[0094] The application layer and the application framework layer run in the virtual machine. The virtual machine executes the java files of the application layer and the application framework layer into binary files, that is, performs compilation. The virtual machine is used to perform the management of the object life cycle, the management of the stack, the management of the thread, the management of the security and the exception, and the garbage collection, etc. It can be understood that after the virtual machine starts to run, the corresponding virtual machine service (ArtService) process is also started. ArtService can start or terminate the compilation process according to the notification of JobService.
[0095] The system library can include a plurality of functional modules. For example, a surface manager, media libraries, a three-dimensional graphics processing library (e.g., OpenGL ES), a 2D graphics engine (e.g., SGL), and the like.
[0096] The surface manager is used to manage a display subsystem and provides fusion of 2D and 3D layers for a plurality of applications. The media libraries support playback and recording of a plurality of commonly used audio, video formats, and still image files. The media libraries can support a plurality of audio and video encoding formats, such as MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, and the like. The three-dimensional graphics processing library is used to implement three-dimensional graphics drawing, image rendering, composition, and layer processing. The 2D graphics engine is a drawing engine for 2D drawing.
[0097] The kernel layer is a layer between hardware and software. The kernel layer at least includes a display driver, a camera driver, a touch point (TP) driver, and a fingerprint module driver.
[0098] The TP driver can receive a touch signal generated when a user touches a screen of the electronic device and can acquire fingerprint information input by the user when the user performs fingerprint unlocking. The fingerprint module driver is used to receive fingerprint information input by the user when the user touches a power key in a scenario of fingerprint unlocking of a side power key. The camera driver is used to detect an image captured by a camera, for example, whether the image contains face information. In the embodiments of the present application, the kernel layer driver can report a user unlocking intention to the JobService when detecting the user unlocking intention.
[0099] For ease of understanding, the following embodiments of the present application will take an electronic device having the structure shown in FIGS. 1 and 2 as an example, and the compiling method of the virtual machine provided by the embodiments of the present application will be described in detail in combination with the drawings and application scenarios. Figure 5 and Figure 6 The compiling method of the virtual machine provided by the embodiments of the present application will be described in detail in combination with the drawings and application scenarios.
[0100] Figure 7 is a flowchart of an example of the compiling method of the virtual machine provided by the embodiments of the present application, and the method includes the following steps.
[0101] S11, a virtual machine service (ArtService) is started.
[0102] The ArtService (which can also be a virtual machine) can be started along with the booting of the electronic device, and after being started, the subsequent compiling and optimizing process can be performed.
[0103] S12, the ArtService registers a task (Job) in a task scheduling service (JobService).
[0104] The Job registered by the ArtService is a task for subsequent execution of compilation optimization. When the ArtService registers the Job in the JobService, the ArtService can also register a condition for starting execution of the Job, i.e., the corresponding task is started when the execution condition is met.
[0105] S13, after the electronic device is turned off, the PMS sends a screen-off broadcast.
[0106] Since the PMS can be responsible for power management of the electronic device, such as turning on the screen and turning off the screen, the PMS can send a screen-off broadcast after the electronic device is turned off. Correspondingly, the service registered to receive the broadcast can receive the screen-off broadcast sent by the PMS.
[0107] S14, the JobService receives the screen-off broadcast and determines whether the first flag is true. If not, S15 is executed, and if yes, S21 is executed.
[0108] The first flag is used to indicate whether the electronic device has been turned off for a preset time length. For example, the first flag being true indicates that the electronic device has been turned off for a preset time length, and the first flag being false indicates that the electronic device has not been turned off for a preset time length. Illustratively, the preset time length can be half an hour. It can be understood that when the first flag is true, it indicates that one execution condition of the compilation optimization is met, and other execution conditions can be determined.
[0109] S15, the JobService starts a timer, and the timing duration is the preset time length.
[0110] That is, when the first flag is false, the electronic device has not reached the condition of being turned off for a preset time length. At this time, the JobService can start a timer to time the screen-off time length of the electronic device to perform subsequent steps when the electronic device reaches the condition of being turned off for a preset time length.
[0111] S16, during the timing of the timer, the electronic device is turned on, and the PMS sends an on-screen broadcast.
[0112] S17, the JobService receives the on-screen broadcast and suspends the timing of the timer. When the JobService detects a user unlocking intention, the timing of the timer is cancelled.
[0113] That is to say, if the electronic device changes from the screen-off state to the screen-on state (for example, the user triggers the screen-on to check the time or the electronic device receives a message notification to trigger the screen-on, etc.) during the timing of the timer, the PMS also sends a screen-on broadcast, and the JobService receives the screen-on broadcast and considers that the electronic device is likely to be used, and thus suspends the timing of the timer. Meanwhile, the JobService continues to monitor whether there is a user unlocking intention, and in the case of a user unlocking intention, it is determined that the electronic device is likely to be used, and thus the timing of the timer can be directly cancelled, and the compilation optimization operation is not performed during the use of the electronic device by the user; and in the case of no user unlocking intention, that is, the electronic device is only turned on for a moment, and the probability of being used is small, and thus the suspended state of the timer can be continued.
[0114] Alternatively, during the timing of the timer, the JobService first monitors the user unlocking intention, and at this time, the timing of the timer can also be directly cancelled.
[0115] The process in which the JobService monitors the user unlocking intention can be referred to the following Figure 8 Described embodiments.
[0116] S18, the electronic device is screen-off, and the PMS sends a screen-off broadcast.
[0117] S19, the JobService receives the screen-off broadcast sent by the PMS again, and if the timer is in the suspended state, the timing is continued, and if the timer is in the cancelled state, the timing is restarted.
[0118] Among them, after the user unlocks the electronic device after using the electronic device, or after the electronic device is turned on and then turned off, the PMS sends a screen-off broadcast again, and the JobService receives the screen-off broadcast and judges the current state of the timer. If the timer is in the suspended state, it indicates that the electronic device was just turned on and not used, and thus the timer can continue to time, for example, the timer is suspended at 10 minutes in the step S17, and at this time, the timing is continued from 10 minutes. If the timer is in the cancelled state, it indicates that the electronic device was just used, and thus the timer needs to be restarted, that is, the timer starts from 0.
[0119] For the above steps S16 to S19, the embodiments of the present application cancel the timer only in the case that the user has an unlocking intention for the electronic device, and if the electronic device is only turned on but not unlocked, the timer is suspended, and the subsequent timing can be continued, so that the electronic device can perform the compilation optimization as soon as possible, improve the efficiency of the compilation optimization, and reduce the increase of the compilation power consumption or the phenomenon of application lag.
[0120] S20, when the time length of the timer reaches the preset time length, the JobService modifies the first flag bit to true.
[0121] That is, when the time length of the timer reaches the preset time length, it indicates that the electronic device has been screen-off for the preset time length, at this time the JobService can modify the first flag bit to true, and then continue to determine whether other execution conditions are met.
[0122] S21, the JobService determines the Job depending on the condition that the first flag bit is true, and determines whether all execution conditions of the Job are met, if yes, S22 is executed, and if not, the conditions are waited for.
[0123] Wherein, in the case that the first flag bit is true, that is, the condition is met, the JobService needs to determine which Job depends on the condition, and then can determine which Job to execute. Since the ArtService registers the Job on the JobService and the execution condition of the Job is registered, in the case that the execution condition includes the condition that the first flag bit is true, the JobService can determine that the Job corresponding to the ArtService depends on the condition that the first flag bit is true, and then can determine whether all execution conditions of the Job are met.
[0124] Exemplarily, in the case that the Job corresponding to the ArtService depends on the condition that the first flag bit is true, it is queried that all execution conditions of the Job include: the electronic device charging state + screen-off for half an hour + battery power greater than M (such as M = 95%), if all these execution conditions are met, the subsequent step S22 can be executed. Alternatively, the electronic device can also set a flag bit for whether all execution conditions of the Job are met, in the case that all execution conditions of the Job are met, the JobService modifies the corresponding flag bit to true. In the case that the Job corresponding to the ArtService depends on the condition that the first flag bit is true, if it is queried that the current battery power is not greater than M, the execution condition of the Job is not met, and the compiling process is not executed temporarily.
[0125] It can be understood that there can be multiple Jobs depending on the condition that the first flag bit is true, and the JobService can perform corresponding operations on different Jobs respectively, and the embodiment of the application is to perform operations on the Job corresponding to the ArtService.
[0126] It can also be understood that ArtService can also correspond to different Jobs in different scenarios, and the conditions of different Jobs are also different. For example, in the scenarios described above, for the Fastidle optimization mode, the execution condition is that the electronic device is turned off for half an hour and the battery level is greater than 40%; for the daily idle compilation optimization mode, the execution condition is that the electronic device is charging, turned off for half an hour, and the battery level is greater than 95%; and the execution conditions of the Jobs corresponding to the two optimization modes are different.
[0127] S22, the JobService notifies the ArtService to start the compilation process.
[0128] That is, in the case where it is judged in S21 that the condition is met, the compilation optimization process is started, and the JobService can notify the ArtService to start the compilation process. In an implementable manner, the JobService can call the Start() function corresponding to the Job, and notify the ArtService to start the compilation process through the Intent mechanism. Here, Intent is a run-time binding mechanism, and once Intent is issued, the system will accurately find the matching Service to respond.
[0129] S23, the ArtService starts the compilation optimization and sends the process number of the compilation process to the power saving fairy.
[0130] Among them, the ArtService can use the dex2oat mechanism for compilation optimization, and the corresponding compilation process is the dex2oat process. At the same time, the ArtService also sends the process number of the compilation process to the power saving fairy, so that the power saving fairy can subsequently freeze the compilation process when needed, instead of stopping the compilation.
[0131] S24, during the compilation optimization process, the electronic device is turned on, and the PMS sends the on-screen broadcast.
[0132] That is, during the ArtService compilation process, the electronic device has a turn-on event, which can be triggered by user operation or notification message subscribed by the electronic device. At this time, the PMS will send the on-screen broadcast again.
[0133] S25, the power saving fairy receives the on-screen broadcast, freezes the compilation process according to the process number of the compilation process.
[0134] S26, the power saving fairy sends a notification instruction to the ArtService, notifying the ArtService that the compilation process has been frozen and the compilation optimization is suspended.
[0135] If the electronic device changes from the screen-off state to the screen-on state, the power saving genie receives the screen-on broadcast, considers that the electronic device is likely to be used, and thus can first freeze the compiling process, i.e., suspend the compiling, and notify the ArtService of the message of the frozen process.
[0136] S27, the JobService receives the screen-on broadcast and monitors the user unlocking intention.
[0137] S28, in the case where the user unlocking intention is not monitored, if the electronic device is screen-off, the PMS sends the screen-off broadcast.
[0138] S29, the JobService receives the screen-off broadcast, determines that the first flag is true, and continues the flow.
[0139] After receiving the screen-on broadcast, the JobService also monitors whether there is a user unlocking intention. In the case where the user unlocking intention is not detected, i.e., the electronic device is only screen-on for a short time and the probability of being used is small, the compiling does not need to be terminated and the compiling process can be continued to be frozen.
[0140] In this case, if the electronic device changes to the screen-off state again (e.g., the user turns off the power key or the screen is screen-off after the screen-on timeout), the PMS sends the screen-off broadcast again. After the JobService receives the screen-off broadcast, the first flag is determined to be true by judging the first flag (because the first flag is modified to true in S20 and has not been changed again), and the flow is continued.
[0141] The process in which the JobService monitors the user unlocking intention can be referred to the following Figure 8 described embodiments.
[0142] S30, the power saving genie receives the screen-off broadcast, unfreezes the compiling process according to the process number of the compiling process.
[0143] S31, the power saving genie sends a notification instruction to the ArtService, notifying the ArtService that the compiling process has been unfrozen and the compiling optimization is continued.
[0144] When the PMS sends the screen-off broadcast, the power saving genie also receives the screen-off broadcast. Because the JobService does not monitor the user unlocking intention at this time, i.e., the electronic device is not used and the application does not appear to be stuck, the original compiling process can be continued. Therefore, the power saving genie can unfreeze the original compiling process and notify the ArtService to continue the compiling optimization.
[0145] For the steps S24 to S31, in the process of compiling optimization, if the electronic device is brightened, the user's unlocking intention is monitored, and in the case that the user has no unlocking intention, the compiling process is frozen by the power saving wizard, and the compiling process is not terminated. After the electronic device is turned off again, the original compiling process is continued, so that the electronic device can complete the compiling optimization process as soon as possible, improve the efficiency of the compiling optimization, and reduce the phenomenon of increased compiling power consumption or application lag.
[0146] In some embodiments, the compiling optimization process generates power consumption, which can cause the CPU temperature to rise. If the CPU temperature is too high, it will also affect the performance of the electronic device. Therefore, the CPU temperature can also be monitored in this embodiment. If the CPU temperature exceeds the temperature threshold, the temperature sensor can send a high-temperature broadcast. After the power saving wizard receives the high-temperature broadcast, the compiling process is frozen according to the process number of the compiling process, and ArtService is notified that the compiling process has been frozen and the compiling optimization is suspended. After the CPU temperature is reduced to below the temperature threshold, the temperature sensor can send a low-temperature broadcast again. After the power saving wizard receives the low-temperature broadcast, the compiling process is unfrozen according to the process number of the compiling process, and ArtService is notified that the compiling process has been unfrozen and the compiling optimization is continued.
[0147] S32, in the case that the user's unlocking intention is monitored, JobService notifies ArtService to terminate the compiling.
[0148] S33, JobService modifies the first flag to false.
[0149] That is, if JobService monitors the user's unlocking intention, it is determined that the probability of using the electronic device is large, and if the compiling is continued, the front-end application of the electronic device will be greatly affected. At this time, ArtService can be notified to terminate the compiling, that is, to cancel the current compiling optimization process, and the first flag is modified to false for judging the execution condition when re-compiling next time.
[0150] S34, ArtService notifies the power saving wizard that the compiling has been terminated.
[0151] S35, the power saving wizard clears the process number of the compiling process.
[0152] After the compiling is terminated, the process number in the power saving wizard also does not have to be retained. Therefore, ArtService can notify the power saving wizard, and the power saving wizard can clear the corresponding process number.
[0153] It can be understood that after the compilation is terminated, the compilation result of the application which is not completed will be discarded, and the next compilation is waited.
[0154] It can also be understood that after the current compilation optimization process is terminated, the electronic device returns to the S13 step to continue to wait for the next screen-off event and count the preset time length, and iterates in this way until the complete compilation optimization process is completed.
[0155] For the process of monitoring the user unlocking intention by the JobService in the above embodiment, the process can be specifically as shown in the following Figure 8 Since there are various ways to unlock the electronic device at present, such as fingerprint unlocking, password unlocking, face unlocking, etc., the embodiments of the present application can monitor various unlocking methods, and will timely report to the JobService when any unlocking method is monitored. The process includes the following steps:
[0156] S40, the kernel layer driver obtains the fingerprint information and reports the user unlocking intention event to the JobService.
[0157] The fingerprint unlocking method set by the electronic device includes but is not limited to side power key fingerprint unlocking, screen fingerprint unlocking, etc. If it is a screen fingerprint unlocking method, the kernel layer TP driver can obtain the fingerprint information when the user touches the specified position of the screen with the finger. If it is a side power key fingerprint unlocking method, the kernel layer fingerprint module driver can obtain the fingerprint information when the user touches the side power key with the finger. When the kernel layer driver obtains the fingerprint information, the user unlocking intention event is reported to the JobService, that is, the user unlocking intention event can be reported to the JobService as long as the fingerprint information is obtained before the fingerprint information is identified whether it is a registered user, so that the JobService notifies the ArtService to terminate the compilation, so as to terminate the compilation process as soon as possible and avoid the impact of the user using the electronic device.
[0158] S41, the kernel layer driver detects the face information and reports the user unlocking intention event to the JobService.
[0159] If the electronic device has a face unlocking function enabled, the camera (e.g., a front camera) is in a state of real-time image acquisition. The camera driver (camera HAL) in the kernel layer detects the acquired image and determines whether the image contains face information. If the image contains face information, the face information is further identified as registered user face information. In the embodiment of the present application, when the kernel layer driver detects face information, the user unlocking intention is reported to the JobService. That is, when face information is detected, the user unlocking intention event is reported to the JobService before the face information is identified as registered user face information, so that the JobService notifies the ArtService to terminate the compilation to terminate the compilation process as soon as possible.
[0160] In S42, the System UI obtains the first touch event and reports the user unlocking intention event to the JobService.
[0161] In the case where the user sets a password to unlock the electronic device, if the user wants to unlock the electronic device, the corresponding password needs to be input on the input panel of the screen. The input panel can be presented by the view of the System UI. When the user inputs the password, the user needs to input several numbers (i.e., touch the touch points corresponding to the numbers on the input panel) one by one to successfully unlock the electronic device. Therefore, in the case where the System UI obtains the first touch event (touchdown event), i.e., the user touches the touch point corresponding to the first number, the user unlocking intention event is reported to the JobService, so that the JobService notifies the ArtService to terminate the compilation to terminate the compilation process as soon as possible.
[0162] In some implementations, the kernel layer driver and the System UI can notify the JobService of the user unlocking intention event by triggering a stake point function.
[0163] In S43, the System UI obtains the home screen touch event and reports the user unlocking intention event to the JobService.
[0164] In some scenarios, the electronic device does not set a password, a fingerprint, or a face, and the like as an unlocking method, and only needs to press the power key to enter the home screen of the electronic device when the screen is turned off, that is, the electronic device enters the home screen as soon as the screen is turned on. In this scenario, if the user does not operate the home screen after the screen of the electronic device is turned on, it indicates that the user does not use the electronic device, and the compiling process does not need to be terminated. However, if the System UI obtains a touch event of the user on the home screen, it indicates that the user is likely to use the electronic device, and the System UI can report a user unlocking intention event to the JobService, so that the JobService notifies the ArtService to terminate the compiling, to terminate the compiling process as soon as possible.
[0165] It can be understood that the steps S40 to S43 described above do not have a sequential relationship, and they are only descriptions of different unlocking methods of the electronic device. Therefore, in any of the above cases, the JobService monitors the user unlocking intention and performs the process of S32 described above. It can be understood that if none of the above cases occurs, the JobService does not monitor the user unlocking intention, and performs the process of S28 described above to improve the efficiency of the compiling optimization.
[0166] The above describes an example of the optimization method of the virtual machine provided by the embodiment of the application. It can be understood that the electronic device includes hardware and / or software modules corresponding to each function to implement the above functions. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a certain function is implemented in hardware or computer software driven 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 combination with the embodiments, but such implementation should not be considered beyond the scope of the application.
[0167] The embodiment of the application can divide the functional modules of the electronic device according to the above method examples. For example, each functional module such as a detection unit, a processing unit, and a display unit can be divided, or two or more functions can be integrated in one module. The integrated module can be implemented in the form of hardware or a software functional module. It should be noted that the division of the modules in the embodiment of the application is illustrative, and is only a logical functional division. Actual implementation can have another division manner.
[0168] It should be noted that all related contents of each step involved in the above method embodiments can be cited from the functional description of the corresponding functional module, which will not be described here.
[0169] The electronic device provided by the embodiment is used to execute the optimization method of the virtual machine, and thus the same effect as the implementation method can be achieved.
[0170] In the case of using the integrated unit, the electronic device can further include a processing module, a storage module and a communication module. The processing module can be used to control and manage the actions of the electronic device. The storage module can be used to support the electronic device to execute the storage of program codes and data, etc. The communication module can be used to support the communication between the electronic device and other devices.
[0171] The processing module can be a processor or a controller. It can realize or execute various exemplary logical blocks, modules and circuits described in combination with the disclosure. The processor can also be a combination of computing functions, such as a combination of one or more microprocessors, a combination of digital signal processors and microprocessors, etc. The storage module can be a memory. The communication module can be a device for interacting with other electronic devices, such as a radio frequency circuit, a Bluetooth chip, a Wi-Fi chip, etc.
[0172] In one embodiment, when the processing module is a processor and the storage module is a memory, the electronic device related to the embodiment can be a device with the structure as shown in the figure. Figure 5
[0173] The embodiment of the present application further provides a computer readable storage medium, and the computer readable storage medium stores a computer program. When the computer program is executed by a processor, the processor executes the optimization method of the virtual machine of any one of the above embodiments. The storage medium can include a U disk, a mobile hard disk, a read only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various storage medium that can store program codes.
[0174] The embodiment of the present application further provides a computer program product, which, when running on a computer, causes the computer to execute the related steps to realize the optimization method of the virtual machine in the above embodiment.
[0175] In addition, the embodiment of the present application further provides a device, which can be a chip, a component or a module. The device can include a processor and a memory connected to each other. The memory is used to store computer execution instructions. When the device is running, the processor can execute the computer execution instructions stored in the memory to make the chip execute the optimization method of the virtual machine in the above method embodiments.
[0176] The electronic device, the computer readable storage medium, the computer program product or the chip provided in the embodiment are used for executing the corresponding method provided above, and thus the beneficial effects achieved thereby can refer to the beneficial effects of the corresponding method provided above, which will not be described herein again.
[0177] Through the description of the above embodiments, those skilled in the art can understand that, for the convenience and brevity of description, only the division of the above functional modules is taken as an example, and in actual application, the above functions can be completed by 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.
[0178] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically independently, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0179] The above is only a specific embodiment of the present application, but the protection scope of the present application is not limited thereto, and any person skilled in the art can easily think of changes or replacements within the technical range disclosed in the present application, which should be covered in 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 compiling a virtual machine, the method being applied to an electronic device, characterized in that, The method includes: When the electronic device remains in a screen-off state for a preset duration and the battery level of the electronic device is greater than a first charge level, the virtual machine in the electronic device begins to perform compilation optimization. If the electronic device switches from a screen-off state to a screen-on state, the virtual machine pauses the compilation optimization. If the electronic device is not unlocked and is switched to a screen-off state again after the virtual machine pauses the compilation optimization, the virtual machine will continue to perform the compilation optimization.
2. The method according to claim 1, characterized in that, After the virtual machine pauses the compilation optimization, the method further includes: If the electronic device detects a user input unlock operation, the compilation optimization will be terminated. If the electronic device switches to a screen-off state again, the virtual machine will re-execute the compilation optimization when the screen-off state duration reaches the preset duration.
3. The method according to claim 1 or 2, characterized in that, The method further includes: If the electronic device remains in a screen-off state for a duration that reaches the preset duration and the battery level of the electronic device is not greater than the first battery level, 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 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 the electronic device is not unlocked and switches to a screen-off state again, the virtual machine continues to perform 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 5, characterized in that, The electronic device remains in a screen-off state for a preset duration, including: When the electronic device enters the screen-off state, a timer is started to keep track of the time. If the electronic device switches to a screen-on state during the timer's timing process, the timer is paused; if the electronic device detects an unlock operation input by the user, the timer is canceled. If the electronic device switches to screen-off state again, the timer will continue to count down if it is paused, and will restart if it is canceled, until the timer reaches the preset duration.
7. The method according to claim 6, characterized in that, When the electronic device remains in a screen-off state for a preset duration and the battery level of the electronic device is greater than a first charge 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's timing duration has reached the preset duration, it determines whether the battery power of the electronic device is greater than the first battery power. 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.
8. The method according to any one of claims 1 to 7, characterized in that, After the virtual machine pauses the compilation optimization, the method further includes: Determine whether a user input unlock operation was detected; If no user input is detected for the unlock operation, it is determined that the electronic device is not unlocked.
9. The method according to claim 8, characterized in that, The process of determining whether a user input unlock operation has been detected includes: Upon receiving a user unlock intent event, it is determined that the user has entered the unlock operation. The user unlock intent event includes at least one of the following events: an event generated when the fingerprint information entered by the user in the fingerprint unlock area is obtained; an event generated when the 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. If no user unlock intent event is received, it is determined that the user input of the unlock operation was not detected.
10. The method according to any one of claims 1 to 9, characterized in that, When the electronic device remains in a screen-off state for a preset duration, the method further includes: The first flag is set to true, and the first flag is used to indicate whether the electronic device has been off for a preset time.
11. The method according to claim 10, characterized in that, If the electronic device terminates the compilation optimization, the method further includes: Set the value of the first flag to false.
12. 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 11.
13. 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 11.
14. 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 11.
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
Terminal control method and device and terminal
CN111290561A
Application program optimization method and electronic equipment
CN116643778A
Optimizing branch condition expressions in a JIT compiler
US7421687B1