Method compiling method and device and storage medium
By compiling methods post-startup and optimizing resource allocation during software startup, the method compilation method addresses long startup times, enhancing user experience through faster software initialization.
Patent Information
- Application Number
- CN202310797728.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-30
- Publication Date
- 2024-12-31
AI Technical Summary
The long software startup times due to resource-intensive method compilation during the software startup process negatively impact user experience.
Compile methods after software startup by stopping the target thread during the startup state and resuming it post-startup, utilizing a compilation queue and resource checks to optimize resource allocation.
This approach reduces software startup time by conserving resources for immediate software operation, ensuring faster startup and efficient method execution without recompilation.
Smart Images

Figure CN119225837A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method compilation method, device, system and storage medium. Background Art
[0002] With the development of computer technology, various software are often installed on terminal devices. The process from software shutdown to running state can be called the software startup process. The performance of software during the startup process often has a great impact on the user experience. For example, if the software takes a long time to start, it will significantly reduce the user experience.
[0003] Therefore, there is a need to reduce the time spent in the software startup process. Summary of the invention
[0004] In order to solve the problems of the prior art, the present application provides a method and device for compiling a method.
[0005] In a first aspect, the present application provides a method for compiling a method, the method comprising:
[0006] In response to the target software being in a startup state, stopping execution of a target thread, the target thread being used to compile a target method in the target software;
[0007] In response to the target software being started up, the target thread is started to be executed to compile the target method.
[0008] In some possible implementations, before stopping execution of the target thread, the method further includes:
[0009] Construct a target object according to the target method;
[0010] The target object is added to a compilation queue, and the target thread is used to take out the target object from the compilation queue and compile it.
[0011] In some possible implementations, after stopping execution of the target thread, the method further includes:
[0012] Loading an adding method into a memory, the adding method being used to write the identification of the object in the compile queue into a preset file;
[0013] Erasing the adding method loaded in the memory.
[0014] In some possible implementations, after compiling the target method, the method further includes:
[0015] Erasing the deletion method loaded in the memory, the deletion method is used to delete the identifier of the object from the preset file after the object in the compilation queue is compiled.
[0016] In some possible implementations, the target software runs on the first device, and before starting to execute the target thread, the method further includes:
[0017] In response to completion of the target software startup, obtaining a remaining amount of resources, where the remaining amount of resources indicates an amount of resources that can be called by the target thread;
[0018] It is determined that the remaining resource amount is greater than a preset resource amount.
[0019] In some possible implementations, the target software runs on the first device, and after starting to execute the target thread, the method further includes:
[0020] Acquire a first operation triggered by a user, and stop executing the target thread;
[0021] In response to the first operation being processed, the target thread continues to be executed.
[0022] In some possible implementations, the target software includes a first method, and the method further includes:
[0023] Get the number of times the first method is called;
[0024] In response to the first method being called a number of times greater than a preset threshold, the first method is determined as the target method.
[0025] In a second aspect, the present application provides a method compilation device, the device comprising: a stop unit, for stopping the execution of a target thread in response to the target software being in a startup state, the target thread being used to compile a target method in the target software; a start unit, for starting the execution of the target thread in response to the completion of the startup of the target software to compile the target method.
[0026] In some possible implementations, the stopping unit specifically constructs a target object according to the target method, adds the target object to a compilation queue, and the target thread is used to take out the target object from the compilation queue and compile it.
[0027] In some possible implementations, the device further includes a method erasing unit. The method erasing unit is configured to load an adding method into a memory, wherein the adding method is configured to write an identifier of an object in the compilation queue into a preset file, and to erase the adding method loaded into the memory.
[0028] In some possible implementations, the method erasing unit is further used to erase the deletion method loaded in the memory, and the deletion method is used to delete the identifier of the object from the preset file after the object in the compilation queue is compiled.
[0029] In some possible implementations, the target software runs on the first device. The startup unit is specifically configured to obtain a remaining resource amount in response to completion of startup of the target software, the remaining resource amount indicating the amount of resources that the target thread can call, and determine that the remaining resource amount is greater than a preset resource amount.
[0030] In some possible implementations, the target software runs on a first device. The stopping unit is further configured to obtain a first operation triggered by a user and stop executing the target thread. The starting unit is further configured to continue executing the target thread in response to the first operation being processed.
[0031] In some possible implementations, the target software includes a first method. The device further includes a determination unit. The determination unit is configured to obtain the number of times the first method is called; in response to the number of times the first method is called being greater than a preset threshold, determine the first method as the target method.
[0032] In a third aspect, the present application provides an electronic device, including:
[0033] one or more processors;
[0034] a storage device having one or more programs stored thereon,
[0035] When the one or more programs are executed by the one or more processors, the one or more processors implement any method described in the first aspect.
[0036] In a fourth aspect, the present application provides a computer-readable medium having a computer program stored thereon, wherein when the program is executed by a processor, any method described in the first aspect is implemented.
[0037] In a fifth aspect, the present application provides a computer program product, which, when executed on a device, enables the device to execute the method described in the first aspect.
[0038] It can be seen that this application has the following beneficial effects:
[0039] In the technical solution provided by the present application, for the target method that needs to be compiled into machine code in the target software, it can be compiled after the target software is started. Specifically, if the compilation of the target method is executed by the target thread, the target thread can be stopped when the target software is in the startup state. In this way, since the execution of the target thread is stopped, the compilation of the target method will also be stopped accordingly. After the target software is started, the target thread can be started to compile the target method. In this way, during the process of starting the target software, since the compilation of the target method is stopped, the resources of the device will not be occupied. Accordingly, the device can use more resources to start the target software, complete the data processing tasks in the process of starting the target software faster, thereby reducing the time consumed when the target software is started. In addition, after the target software is started, the target thread can compile the target method. In this way, when the target method needs to be run, the compiled target method can be executed without recompiling the target method, which also ensures the response speed during the software operation. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0041] Figure 1 A flowchart of a method compilation method provided in an embodiment of the present application;
[0042] Figure 2 A schematic diagram of a method compilation device provided in an embodiment of the present application;
[0043] Figure 3 A schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0044] The embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be construed as being limited to the embodiments described herein. Instead, these embodiments are provided to provide a more thorough and complete understanding of the present application. It should be understood that the drawings and embodiments of the present application are only for exemplary purposes and are not intended to limit the scope of protection of the present application.
[0045] It should be understood that the various steps described in the method implementation of the present application can be performed in different orders and / or performed in parallel. In addition, the method implementation may include additional steps and / or omit the steps shown. The scope of the present application is not limited in this respect.
[0046] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.
[0047] It should be noted that the concepts such as "first" and "second" mentioned in this application are only used to distinguish different objects, devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0048] It should be noted that the modifications of "one" and "plurality" mentioned in the present application are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0049] The methods in the software installed on the device may not be directly executed by the device's processor. Therefore, in order to implement the functions corresponding to the methods, the methods in the software can be converted into a format that the device can execute. The converted methods are loaded into the device's memory so that the processor can retrieve and execute them. This process can be called the compilation process of the method.
[0050] For example, in software written in JAVA language, the methods in the software are stored in the storage module of the device in the form of method bytecode. However, the method bytecode cannot be directly executed by the processor. Therefore, the method is compiled, the method bytecode is converted into machine code that can be executed by the processor, and the machine code is loaded into the memory. Specifically, the machine code can be loaded into a profile file in the memory. In this way, the processor can read the machine code from the memory (such as the profile file in the memory) and execute it to implement the function corresponding to the method.
[0051] Taking into account that methods may be called during software operation to implement corresponding functions, methods can currently be compiled during software startup. That is to say, during the software startup process, the methods in the software can be converted into a format that can be executed by the processor and loaded into the memory. In this way, during the running of the software, the processor can directly execute the compiled method. Accordingly, when the corresponding method needs to be executed, there is no need to recompile the method. In particular, if there are a large number of methods in the software, the hot method can be compiled when the software is started, and the non-hot method can be compiled when it is called. Among them, hot methods refer to methods that are frequently called in the software.
[0052] In this way, pre-compiling the method during the software startup process can save the time of compiling the method during the software running process, increase the speed of software running, and enhance the user experience.
[0053] However, the computing resources of the device are limited, or the computing resources allocated by the device to the software are limited. During the software startup process, the computing resources required by the software are relatively large, for example, more than the computing resources required during the software operation. Therefore, if the method is compiled during the software startup process, part of the computing resources will be allocated to compile the method in the software, and the computing resources that can be called by the software startup will be reduced accordingly. Since enough computing resources cannot be called, the software startup speed will slow down, and the time taken to start the software will increase accordingly. In this way, the excessively long software startup time will have a greater impact on the user experience.
[0054] In order to solve the problems of the prior art, an embodiment of the present application provides a method compilation method, which is described in detail below in conjunction with the drawings in the specification.
[0055] The above briefly introduces the application scenarios of the method compilation method provided in the embodiment of the present application. Figure 1 Further introduction to the method compilation method.
[0056] See also Figure 1 , Figure 1 An information interaction diagram of a method compilation method provided in an embodiment of the present application, the embodiment of the present application can be applied to an application scenario of opening a target software. Among them, the target software is software pre-installed on a device and can be run on the device. The device can be a terminal device, for example, a mobile terminal device such as a mobile phone, or a terminal device such as a personal computer. Optionally, the target software can be software that needs to be compiled before it can be executed by a processor. For example, the target software can be software written in a language such as Java or Python. Before the target software is compiled, the target software is stored in a storage device of the device in a bytecode or other format that cannot be directly executed by the processor.
[0057] In the embodiment of the present application, the method compilation method may be executed by a method compilation device, which may be implemented by software. Optionally, the method compilation device may be software running on a device, for example, an operating system of the device, for compiling the method in the software running on the device. Figure 1 As shown, the method specifically comprises the following steps:
[0058] S101: Obtain a startup instruction for the target software.
[0059] In the embodiment of the present application, the startup process of the target software can be optimized. The target software is software installed on the device and can be run, and the startup process of the target software refers to the process of the target software entering the running state from the non-running state. The non-running state refers to the state in which there are compiled methods in the target software. That is to say, in the non-running state, at least one method in the target software is not compiled.
[0060] In some possible implementations, the non-operating state may include a closed state. In the closed state, the main process of the target software is not loaded into the memory, and any process of the target software is not in a working state.
[0061] In some possible implementations, the non-running state may include a background running state. The background running state corresponds to the foreground running state. The target software in the foreground running state is executed by the device, and the user can see the target software on the display device corresponding to the device. The target software in the background running state runs in the background of the operating system, and the user cannot see the target software on the display device corresponding to the device.
[0062] If the target software has at least one uncompiled method in the background running state, the background running state can be regarded as the aforementioned non-running state. For example, if all or part of the methods of the target software are cleared from the memory in the background running state, then after switching to the foreground running state, the methods of the target software need to be compiled and loaded into the memory. Accordingly, in the above implementation, the background running state of the target software can be regarded as the non-starting state.
[0063] In the embodiment of the present application, the switching of the target software from the non-operating state to the operating state may be triggered by a startup instruction, wherein the startup instruction may be an operation instruction triggered by a user, which is used to control the switching of the target software from the non-operating state to the operating state.
[0064] For example, if the non-operating state includes a closed state, then the above-mentioned startup instruction may be an instruction for starting the target software. Specifically, the user may trigger an operation for starting the target software. After obtaining the user's operation, the operating system of the device may start the target software according to the operation triggered by the user, and the method compilation device may obtain the startup instruction for the target software. Among them, the above-mentioned user-triggered operation for starting the target software may include a single-click operation of the user on the icon corresponding to the target software, or may include a double-click operation of the user on the icon corresponding to the target software, and may also include other operations of the user on the icon corresponding to the target software.
[0065] For another example, if the non-running state includes a background running state, then the above-mentioned startup instruction may be an instruction for switching the foreground running software. Specifically, the user may trigger an operation to switch the target software to the foreground running. After obtaining the user's operation, the operating system of the device may start the target software according to the operation triggered by the user, and the method compilation device may obtain the startup instruction for the target software. Among them, the above-mentioned user-triggered operation for starting the target software may include a user's click operation corresponding to the target software (for example, including a single-click operation or a double-click operation), or may include a user's switching operation on the operating system of the device (for example, may include an operation to evoke a background menu and an operation to click on the area corresponding to the target software in the background menu).
[0066] After obtaining the startup instruction for the target software, the target software can be switched from a non-running state to a running state. During the startup process, the target software can be said to be in a startup state. After the target software enters the running state, it can be said that the startup of the target software is completed, or the target software enters a startup completion state. Depending on the state of the target software, the method compilation device can execute the following step S102 or step S103. It can be understood that, without considering the startup failure, there is a clear time relationship between step S102 and step S103. That is, after the startup process, the target software can enter a startup completion state from the startup state.
[0067] S102: In response to the target software being in the startup state, stop executing the target thread.
[0068] As described above, the target software in the startup state requires more computing resources. Accordingly, to increase the startup speed of the target software, the compilation of the methods in the target software can be stopped, thereby saving computing resources for the startup of the target software.
[0069] Therefore, in the embodiment of the present application, if the target software is in the startup state, the target thread can be stopped. The target thread package is a thread used to compile the target method. The target method is a method in the target software, and when the target software is in the non-running state, the target method is not compiled and loaded into the memory.
[0070] The target method is first introduced below.
[0071] In the embodiment of the present application, the target method is a method that is not compiled and loaded into the memory. In an actual application scenario, the target software in a non-running state may include multiple uncompiled methods. Optionally, these uncompiled methods can all be regarded as target methods and compiled by the target thread. Alternatively, the target method can be a specific method among the above-mentioned target uncompiled methods. Two possible implementations are described below.
[0072] In a first possible implementation, the target method may be a method with a large amount of data in the target software. Since the target method has a large amount of data, compiling the target method may require more computing resources. Thus, during the process of starting the target software, pausing the compilation of the target method can save more computing resources, so as to increase the startup speed of the target software.
[0073] In a second possible implementation, the target method may be a method in the target software that is not compiled and is called frequently. In other words, the target method may be a hotspot method that is not compiled. In other words, for the hotspot method, compilation may be suspended during the startup of the target software, and compiled after the startup of the target software is completed. For the non-hotspot method, compilation may not be performed after the startup of the target software is completed, but compiled when the non-hotspot method is executed or about to be executed.
[0074] Accordingly, during the operation of the target software, the number of times (or frequency) each method in the target software is called can be recorded, and the method whose number of calls (or frequency) is greater than a preset threshold is determined as the target method. The operation of the above-mentioned target software can be run on the device or on other devices. For example, the target method can be determined based on the situation of the target software running on the test device. The test device is a device used to test the target software before the target software is released. Alternatively, the hot method can also be set by the technician who develops the target software. For example, the technician can determine the more frequently called methods in the target software based on the structure and function of the target software.
[0075] The target method is introduced above, and the target thread is introduced below.
[0076] In an embodiment of the present application, the target thread is a thread used to compile a target method in the target software. The target thread may be a thread of an operating system of a device. That is, the compilation of the target method in the target software may be performed by the operating system of the device. For example, in some possible implementations, the target thread may be a just-in-time (Jit) thread. The JIT thread is used to compile a method in the software during the software startup process.
[0077] Optionally, considering that there may be multiple methods to be compiled in the target software, during the process of starting the target software, an object can be constructed according to the method to be compiled in the target software, and the object can be added to the compilation queue so that the target thread compiles the object in the compilation queue. For example, if the target software is software written in Java language, an object can be constructed according to the method bytecode of the method in the target software. Each object includes a class object and an instance object. For the target object constructed according to the target method, the instance object in the target object includes the method bytecode of the target method, and the class object in the target object can be regarded as the identifier of the target method. Optionally, the compilation of the target method can also be referred to as the compilation of the target object.
[0078] After the target object is constructed, the target object can be added to the compilation queue. The compilation queue is used to hold one or more objects constructed according to the method to be compiled. If the target thread is not stopped, the target thread can take the object from the head of the compilation queue and compile the method bytecode included in the object.
[0079] Optionally, when adding the target object to the compilation queue, the target object may be added to the compilation queue from the tail of the compilation queue.
[0080] Optionally, when adding the target object to the compilation queue, the position of the target object in the compilation queue can also be determined according to the priority of the target method. For example, if the priority of the target method is higher than the priority of the methods included in other objects in the compilation queue, the target object can be added to the head of the compilation queue. For another example, if the priority of the target method is lower than the priority of the methods included in other objects in the compilation queue, the target object can be added to the tail of the compilation queue. Among them, the priority of the target method is used to indicate the priority of the target method to be compiled, for example, it can be determined according to the number of times or frequency that the target method is called.
[0081] According to the above introduction, the target thread can be a jit thread. Then the above object can be a Jit compilation task (JitCompileTask) object, and the above compilation queue can be a JitCompileTask queue. When the jit thread compiles the method, it can first take out the JitCompileTask object from the JitCompileTask queue, and then execute the run method to compile the method bytecode included in the JitCompileTask object.
[0082] Accordingly, when the execution of the target thread is stopped, the target thread is intercepted (hooked) after the jit thread takes out the target object from the JitCompileTask queue. Specifically, the run method in the virtual function table of the JitCompileTask object can be intercepted by an inline function. After the jit suppression switch is turned on, the sleep instruction can be executed on the hooked run method. In this way, after the sleep instruction is obtained, the run method is intercepted and the compilation of the target method is terminated. Among them, the jit suppression switch is a logical switch in the software for controlling the compilation of the target method. In step S102, the jit suppression switch can be turned on. In step S103, the jit suppression switch can be turned off.
[0083] In some possible implementations, uncompiled objects can be recorded. For example, the identifiers of uncompiled objects can be recorded in a preset file. During the startup of the target software, in order to provide more computing resources for the startup of the target software, the compilation of one or more methods in the target software may be stopped. Accordingly, more object identifiers will be recorded in the preset file. In actual application scenarios, preset files are often files in memory or cache, which limits the size of the preset files. Therefore, if the identifiers of multiple objects are written to the preset file, the capacity of the preset file is insufficient to accommodate the identifiers of the objects that need to be written, and an overflow failure occurs.
[0084] In order to avoid this fault, the identification of the object can be prevented from being written into the preset file. Specifically, if the identification of the object is written into the preset file by the adding method, the adding method can be erased in the memory. In this way, since the adding method does not exist in the memory, the processor of the device will not execute the adding method, and the identification of the object will not be written into the preset file.
[0085] For example, in some possible implementations, the identifier of a JitCompileTask object that is taken out of the JitCompileTask queue and not compiled by a jit thread can be written into a global table in memory. The identifier of the JitCompileTask object can be a class object of the JitCompileTask object. If the compilation of multiple objects is intercepted during the startup of the target software, the class objects of multiple JitCompileTask objects need to be written into the global table, and the capacity of the global table is limited, so an overflow failure may occur.
[0086] To this end, the add method in the memory can be erased. For example, in some implementations, the class object of the JitCompileTask object is written to the global table by the addGlobalRef method. Accordingly, in order to avoid overflow failures, the addGlobalRef method can be erased from the memory after the addGlobalRef method is loaded into the memory. In this way, since the addGlobalRef method is erased from the memory, the class object of the JitCompileTask object will not be written to the global table, thereby avoiding overflow failures.
[0087] It is understandable that the startup process of the target software may correspond to a period of time. During this period of time, the target thread may be in a suppressed state.
[0088] S103: In response to the target software being started, the target thread is started to be executed.
[0089] After the target software is started, the target software enters the running state. The computing resources required by the target software in the running state are less than the computing resources required by the target software in the starting state. Therefore, after the target software is started, the target thread can be executed to compile the target method.
[0090] For example, if the target thread is stopped by executing a sleep instruction on the run method of the hook, then after determining that the target software has been started, the sleep instruction can be canceled. After the sleep instruction is canceled, the target thread continues to execute, and the target method can be compiled.
[0091] If the method to be compiled is constructed as an object and added to the compilation queue, then after the target software is started, the target thread can take the object from the head of the compilation queue, and compile the method bytecode included in the instance object of the object into machine code and load it into the memory. Optionally, the bytecode compiled by the target method can be loaded into a profile file in the memory.
[0092] In some possible implementations, after the method corresponding to the identifier in the preset file is compiled, the identifier in the preset file can be deleted. However, in the embodiment of the present application, since the adding method is deleted from the memory, the identifier of the target object is not included in the preset file. Therefore, after the target method is compiled, since the identifier of the target object is not included in the preset file, the identifier of the target object cannot be deleted from the preset file. This may cause the program to report an error.
[0093] To solve this problem, in an embodiment of the present application, after the deletion method is loaded into the memory, the deletion method in the memory can be erased. The deletion method is an identifier for deleting the target object from the preset file.
[0094] For example, in some possible implementations, after the compilation of the JitCompileTask object is completed, the class object of the JitCompileTask object recorded in the global table can be deleted by executing the deleteGlobalRef method. In the embodiment of the present application, since the addGlobalRef method is erased from the memory, for the JitCompileTask object corresponding to the target method, the class object of the JitCompileTask object is not recorded in the global table. Therefore, in order to avoid errors in the deleteGlobalRef method or other methods, the deleteGlobalRef method can be erased from the memory after the deleteGlobalRef method is loaded into the memory. In this way, since the deleteGlobalRef method is erased from the memory, the deleteGlobalRef method will not run and will not generate an error.
[0095] In some possible implementations, the target software may still have a large demand for computing resources after being started. Thus, if the target method is compiled immediately after the target software is started, the computing resources required by the target software will be squeezed out, affecting the normal operation of the target software, for example, it may prolong the user's interaction time and affect the user experience.
[0096] To solve this problem, in some possible implementations, it can be determined whether to start executing the target thread based on the amount of available computing resources. Specifically, after the target software is started, the remaining amount of resources can be obtained.
[0097] The remaining amount of resources refers to the amount of resources that the target thread can call without occupying the amount of resources occupied by the target software. For example, it can be the amount of resources remaining in the device, or it can be the difference between the amount of resources allocated by the device to the target software and the amount of resources occupied by the target software. Optionally, the above-mentioned amount of resources refers to the amount of resources related to data processing, for example, it can include the amount of computing resources remaining in the central processing unit (CPU), and it can also include the size of the remaining storage space in the memory, etc.
[0098] After obtaining the remaining resource amount, it can be determined whether the remaining resource amount is greater than the preset resource amount. If the remaining resource amount is not greater than the preset resource amount, it means that the resource amount that can be currently allocated to the target thread is small. In this way, if the target thread is executed, due to insufficient resource amount, the target thread may occupy the resource amount occupied by the target software, thereby affecting the running speed of the target software. For this reason, the target thread can be temporarily discontinued.
[0099] If the remaining resources are greater than the preset resources, it means that the resources currently available to the target thread are sufficient. In this way, even if the target thread is executed, the target thread will not occupy the resources occupied by the target software because the target thread can call sufficient resources. In this way, the target thread can continue to be executed, thereby compiling the target method.
[0100] In the technical solution provided by the embodiment of the present application, for the target method that needs to be compiled into machine code in the target software, the target method can be compiled after the target software is started. Specifically, if the compilation of the target method is executed by the target thread, the target thread can be stopped when the target software is in the startup state. In this way, since the execution of the target thread is stopped, the compilation of the target method will also be stopped accordingly. After the target software is started, the target thread can be started to compile the target method. In this way, in the process of starting the target software, since the compilation of the target method is stopped, the resources of the device will not be occupied. Accordingly, the device can use more resources to start the target software, complete the data processing tasks in the process of starting the target software faster, thereby reducing the time consumed when the target software is started. In addition, after the target software is started, the target thread can compile the target method. In this way, when the target method needs to be run, the compiled target method can be executed without recompiling the target method, which also ensures the response speed during the software operation.
[0101] In the implementation method given above, the compilation of the methods in the software can be suspended during the software startup process, thereby saving computing resources to increase the speed of the software. In actual scenarios, the computing resources required during the operation of the software may fluctuate. For example, after the user triggers certain instructions, the software may require more computing resources to process the instructions. In this process, if the methods in the software are also compiled at the same time, there is also a probability of reducing the computing resources that the software can use.
[0102] For example, for video playback software, users can change the currently playing video or adjust the progress of video playback by sliding. Taking switching the played video as an example, after obtaining the user's operation, the software needs to obtain the video to be played and decode it, render the corresponding visual interface, and create controls for interaction on the interface. In this process, the software may have a high demand for computing resources. Therefore, if the method in the software is compiled after the user triggers the sliding operation, it may occupy the software's computing resources and affect the software's processing speed. At the user level, after triggering the sliding operation, the user may need to wait for a long time before being able to see the new video. In this way, the impact on the user experience is more serious.
[0103] To this end, in some possible implementations, the compilation of methods in the target software can be suspended after certain preset operations are obtained. In this way, since the compilation of the method is suspended, no additional computing resources will be consumed, and the target software can use more computing resources to process the obtained operations, thereby improving the user experience. Among them, the above-mentioned preset operations are pre-set operations, and the processing of the preset operations by the target software requires more computing resources.
[0104] Specifically, after entering the running state, the target software can detect the operation triggered by the user. If it is determined that the user has triggered the preset first operation, the target software can stop executing the target thread and terminate the compilation of the target method to save computing resources. After the first operation is processed, the target software can continue to execute the target thread, thereby compiling the target method. The first operation is processed, which means that the target software has completed its response to the first operation.
[0105] Optionally, if different methods are compiled by different threads, and when the user triggers the first operation, the compilation of the target method has been completed, but the compilation of other methods (or multiple methods) in the target software has not been completed, then in order to save computing resources, the compilation of these methods can be stopped. Specifically, the thread for compiling the above-mentioned uncompleted compiled method can be stopped.
[0106] Taking the target software as a video player as an example, the preset first operation may include a sliding operation for switching the video played by the target software. Optionally, the sliding operation may include an upward sliding operation and / or a downward sliding operation.
[0107] If the user wants to switch the video played by the target software, the user can trigger a sliding operation. After obtaining the sliding operation triggered by the user, on the one hand, the target software can process the sliding operation triggered by the user to play a new video to the user according to the sliding operation. On the other hand, it can also be determined whether the target software currently has a method that is about to be compiled or is already in a compiling state. If the target software has method A that is about to be compiled, the thread used to compile method A can be intercepted to stop the compilation of method A. If the target software has method B that is in a compiling state, the operation of the thread used to compile method B can also be suspended. In this way, during the process of the target software processing the sliding operation, the method of the target software stops compiling to save computing resources for processing the sliding operation.
[0108] After the target software completes the processing of the sliding operation, the target software can play the switched video to the user. Accordingly, the thread for compiling the method can also continue to be executed.
[0109] Based on the method compilation method provided in the above method embodiment, the embodiment of the present application further provides a method compilation device, which will be described below in conjunction with the accompanying drawings.
[0110] See also Figure 2 As shown in FIG. 1 , this figure is a schematic diagram of a method compilation device provided in an embodiment of the present application. Figure 2 As shown, the method compilation device includes:
[0111] The stopping unit 210 is used to stop executing a target thread in response to the target software being in a startup state, wherein the target thread is used to compile a target method in the target software.
[0112] The startup unit 220 is used to start executing the target thread in response to the completion of the startup of the target software to compile the target method.
[0113] In some possible implementations, the stopping unit 210 specifically constructs a target object according to the target method, adds the target object to a compilation queue, and the target thread is used to take out the target object from the compilation queue and compile it.
[0114] In some possible implementations, the device further includes a method erasing unit. The method erasing unit is configured to load an adding method into a memory, wherein the adding method is configured to write an identifier of an object in the compilation queue into a preset file, and to erase the adding method loaded into the memory.
[0115] In some possible implementations, the method erasing unit is further used to erase the deletion method loaded in the memory, wherein the deletion method is used to delete the identifier of the object from the preset file after the object in the compilation queue is compiled.
[0116] In some possible implementations, the target software runs on the first device. The startup unit 220 is specifically configured to obtain a remaining resource amount in response to completion of startup of the target software, the remaining resource amount indicating the amount of resources that the target thread can call, and determine that the remaining resource amount is greater than a preset resource amount.
[0117] In some possible implementations, the target software runs on a first device. The stopping unit 210 is further configured to obtain a first operation triggered by a user and stop executing the target thread. The starting unit 220 is further configured to continue executing the target thread in response to the first operation being processed.
[0118] In some possible implementations, the target software includes a first method. The device further includes a determining unit. The determining unit is configured to obtain the number of times the first method is called; in response to the number of times the first method is called being greater than a preset threshold, determine the first method as the target method.
[0119] Based on a method compilation method provided in the above method embodiments, the present application also provides an electronic device, including: one or more processors; a storage device, on which one or more programs are stored, and when the one or more programs are executed by the one or more processors, the one or more processors implement the method compilation method described in any of the above embodiments.
[0120] Reference below Figure 3, which shows a schematic diagram of the structure of an electronic device 300 suitable for implementing an embodiment of the present application. The terminal device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (portable android devices), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs (televisions), desktop computers, etc. The electronic device shown in the figure is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0121] like Figure 3 As shown, the electronic device 300 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 301, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 302 or a program loaded from a storage device 308 into a random access memory (RAM) 303. In the RAM 303, various programs and data required for the operation of the electronic device 300 are also stored. The processing device 301, the ROM 302, and the RAM 303 are connected to each other via a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.
[0122] Typically, the following devices may be connected to the I / O interface 305: input devices 308 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; output devices 307 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 308 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 309. The communication devices 309 may allow the electronic device 300 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 3 The electronic device 300 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0123] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 309, or installed from the storage device 308, or installed from the ROM 302. When the computer program is executed by the processing device 301, the above-mentioned functions defined in the method of the embodiment of the present application are executed.
[0124] The electronic device provided in the embodiment of the present application and the method compilation method provided in the above embodiment belong to the same inventive concept. The technical details not fully described in this embodiment can be referred to the above embodiment, and this embodiment has the same beneficial effects as the above embodiment.
[0125] Based on the method compilation method provided in the above method embodiments, an embodiment of the present application provides a computer storage medium on which a computer program is stored, wherein when the program is executed by a processor, a method compilation method as described in any of the above embodiments is implemented.
[0126] It should be noted that the computer-readable medium mentioned above in the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0127] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (Hyper Text Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.
[0128] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.
[0129] The computer-readable medium carries one or more programs, and when the one or more programs are executed by the electronic device, the electronic device executes the method compilation method.
[0130] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including, but not limited to, object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0131] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0132] The units involved in the embodiments described in this application may be implemented by software or hardware. The name of a unit / module does not limit the unit itself in some cases. For example, a voice data acquisition module may also be described as a "data acquisition module".
[0133] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0134] In the context of the present application, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0135] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the various embodiments can be referred to each other. For the system or device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description.
[0136] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0137] It should also be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0138] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for compiling a method, characterized in that, The method comprises: In response to the target software being in a startup state, stopping execution of a target thread, the target thread being used to compile a target method in the target software; In response to the target software being started up, the target thread is started to be executed to compile the target method.
2. The method according to claim 1, characterized in that Before stopping execution of the target thread, the method further includes: Construct a target object according to the target method; The target object is added to a compilation queue, and the target thread is used to take out the target object from the compilation queue and compile it.
3. The method according to claim 2, characterized in that After stopping execution of the target thread, the method further includes: Loading an adding method into a memory, the adding method being used to write the identification of the object in the compile queue into a preset file; Erasing the adding method loaded in the memory.
4. The method according to claim 3, characterized in that After compiling the target method, the method further includes: Erasing the deletion method loaded in the memory, the deletion method is used to delete the identifier of the object from the preset file after the object in the compilation queue is compiled.
5. The method according to claim 1, characterized in that: The target software is run on the first device, and before starting to execute the target thread, the method further includes: In response to completion of the target software startup, obtaining a remaining amount of resources, where the remaining amount of resources indicates an amount of resources that can be called by the target thread; It is determined that the remaining resource amount is greater than a preset resource amount.
6. The method according to claim 1, characterized in that The target software is run on the first device, and after starting to execute the target thread, the method further includes: Acquire a first operation triggered by a user, and stop executing the target thread; In response to the first operation being processed, the target thread continues to be executed.
7. The method according to claim 1, characterized in that The target software includes a first method, and the method further includes: Get the number of times the first method is called; In response to the first method being called a number of times greater than a preset threshold, the first method is determined as the target method.
8. A method compilation device, characterized in that The device comprises: a stop unit, configured to stop executing a target thread in response to the target software being in a startup state, the target thread being used to compile a target method in the target software; The startup unit is used to start executing the target thread in response to completion of startup of the target software to compile the target method.
9. An electronic device, characterized in that: include: one or more processors; a storage device having one or more programs stored thereon, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7.
10. A computer-readable medium, characterized in that A computer program is stored thereon, wherein when the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.