Bytecode compiling method, device and equipment and readable storage medium

By identifying hot functions that have not been inline optimized, recompiling and adjusting compilation constraints, the performance bottleneck caused by the fixed filtering strategy during the compilation process is solved, and the execution efficiency of the bytecode in the virtual machine is improved.

CN118733053APending Publication Date: 2024-10-01LOONGSON TECH CORP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410870207.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-28
Publication Date
2024-10-01

AI Technical Summary

Technical Problem

The existing technology uses a fixed filtering strategy to identify hot functions for inline optimization during the compilation process, which is easily affected by the operating environment, resulting in reduced bytecode execution efficiency in the virtual machine and a performance bottleneck.

Method used

By identifying hot functions that have not been inline optimized, recompile for inline optimization, adjust compilation restrictions to relax restrictions, and optimize the called subfunctions in hot functions to the greatest extent to obtain better compilation optimization effects.

Benefits of technology

Through multiple compilations and optimizations, performance bottlenecks are broken through, the execution efficiency of bytecodes in the virtual machine is improved, and more efficient compilation and optimization effects are achieved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118733053A_ABST
    Figure CN118733053A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a byte code compiling method and device, equipment and a readable storage medium. Relates to the technical field of computers. The method comprises the steps of obtaining a first compiling result for byte codes in an application program; identifying a thermal function from all functions included in the first compiling result; the thermal function comprises a target sub-function which is not inline; the thermal function is compiled again to conduct inline optimization on the target sub-function, and a second compiling result of the application program is obtained; and obtaining a performance parameter of the second compiling result, and keeping the second compiling result for use under the condition that the performance parameter meets a preset condition. According to the method, the called sub-functions included in the thermal function are compiled and optimized as much as possible through multiple times of compiling, so that the compiling and optimizing effect is further broken through, and the optimization bottleneck is relieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of computer technology, and specifically relates to a bytecode compilation method, device, electronic device and readable storage medium. Background Art

[0002] Compilation optimization can be performed during bytecode compilation to improve subsequent execution efficiency. One of the compilation optimization operations is inline optimization of hot functions. The basic idea of ​​inline optimization is to insert the called sub-function directly into the place where the function is called, so as to reduce the overhead caused by the function call during subsequent execution.

[0003] Currently, when inline optimization of functions is performed during the compilation process, hot functions that can be optimized inline are identified based on a fixed screening strategy, and optimization is abandoned for functions that do not meet the screening strategy.

[0004] However, the current solution, which is based on a fixed screening strategy to identify hot functions and optimize them, is easily affected by the operating environment and falls into a bottleneck, reducing the execution efficiency of the bytecode in the virtual machine. Summary of the invention

[0005] The present invention aims to provide a bytecode compilation method, device, electronic device and readable storage medium, which at least solve the problems in the prior art.

[0006] In order to solve the above-mentioned technical problems, the present invention is achieved as follows:

[0007] In a first aspect, an embodiment of the present invention provides a bytecode compilation method, the method comprising:

[0008] Obtain a first compilation result for bytecodes in the application program;

[0009] Identify hot functions from all functions included in the first compilation result; the hot functions include target sub-functions that are not inline optimized;

[0010] Compile the hot function again to perform inline optimization on the target sub-function to obtain a second compilation result of the application program;

[0011] Acquire performance parameters of the second compilation result, and if the performance parameters meet a preset condition, retain the second compilation result for use.

[0012] In a second aspect, an embodiment of the present invention further provides a bytecode compiling device, the device comprising:

[0013] An acquisition module, used for acquiring a first compilation result of the bytecode in the application program;

[0014] An identification module, configured to identify hot functions from all functions included in the first compilation result; the hot functions include target sub-functions that are not inline optimized;

[0015] A compiling module, used for compiling the hot function again to perform inline optimization on the target sub-function and obtain a second compilation result of the application program;

[0016] The testing module is used to obtain performance parameters of the second compilation result, and when the performance parameters meet preset conditions, retain the second compilation result for use.

[0017] In a third aspect, an embodiment of the present invention further provides an electronic device, comprising a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps of the method described in the first aspect.

[0018] In a fourth aspect, an embodiment of the present invention further provides a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the steps of the method described in the first aspect are implemented.

[0019] In an embodiment of the present invention, hot functions including target sub-functions that have not been inlined are identified in the first compilation result, and the hot functions are compiled again to inline optimize at least part of the target sub-functions in the hot functions, thereby obtaining a second compilation result of the application. The embodiment of the present invention compiles and optimizes the called sub-functions included in the hot functions as much as possible through multiple compilations, thereby further optimizing the compilation optimization effect and improving the execution efficiency of the bytecode in the virtual machine. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] Figure 1 is a flowchart of the steps of a bytecode compilation method provided by an embodiment of the present invention;

[0021] Figure 2 is a flowchart of another bytecode compilation method provided by an embodiment of the present invention;

[0022] Figure 3 It is an overall flow chart of a bytecode compilation method provided by an embodiment of the present invention;

[0023] Figure 4 is a block diagram of a bytecode compiling device provided by an embodiment of the present invention;

[0024] Figure 5 It is a schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0025] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the accompanying drawings in the embodiments of the present invention.

[0026] Figure 1 is a flowchart of a bytecode compilation method provided by an embodiment of the present invention. Figure 1 As shown, the method may include:

[0027] Step 101: Obtain a first compilation result for an application.

[0028] In an embodiment of the present invention, the bytecode compilation method can be applied to a virtual machine environment. When an application starts to execute, the virtual machine can usually interpret the execution first (i.e., execute it in a manner of directly translating the bytecode). When it is found that a certain function or a code block in a function is executed particularly frequently within a period of time, the function or code block will be marked as a hot function, and the hot function will be compiled and optimized using a just-in-time compiler to improve the operating efficiency of the virtual machine. One of the optimization methods is inline optimization. Inline function is a programming language optimization structure for implementing inline expansion of hot functions (functions that are executed more frequently per unit time). Specifically, the function body of the hot function is embedded in each call location during compilation, that is, the called sub-function is directly inserted into the place where the function is called, so as to reduce the function call overhead in the subsequent execution process.

[0029] First, when the application is executed, the virtual machine can first execute the application by directly translating the bytecode of the application, and when a hot function in the bytecode is identified in the process, the just-in-time compiler is used to perform compilation optimization on the hot function, that is, inline optimization is performed on the hot function. When the compilation is completed, the first compilation result corresponding to the bytecode is obtained.

[0030] Specifically, in order to consider the performance balance, the just-in-time compiler can set compilation restrictions to screen functions that can be optimized inline. For example, the compilation restrictions do not allow unloaded functions to be optimized inline, do not allow functions with too many bytecodes to be optimized inline, do not allow the inlined code to include too many instructions, etc. The purpose of setting compilation restrictions is to avoid the side effects of inline optimization (that is, inline optimization does not produce positive effects, but instead produces negative problems).

[0031] Step 102: identifying hot functions from all functions included in the first compilation result; the hot functions include target sub-functions that have not been inline optimized.

[0032] In an embodiment of the present invention, after the last compilation, the calling function may include multiple sub-functions, and these sub-functions can be divided into: sub-functions that have been inlined, sub-functions that have not been inlined, and other sub-functions. Among them, if the calling function is called at a high frequency per unit time, the calling function can be identified as a hot function; the sub-function that has not been inlined is the target sub-function. The embodiment of the present invention aims to recompile the hot function, in order to complete the inline optimization of the target sub-function of the hot function during the re-compilation process. It should be noted that during the re-compilation process, the sub-functions that have been inlined and other sub-functions in the hot function will not be affected, because the process of converting bytecode to executable machine code has been completed during the initial compilation.

[0033] Under the influence of the compilation restrictions in the just-in-time compiler, there may be a large number of called sub-functions (target sub-functions) in the hot functions of the first compilation result that cannot be inline optimized because they do not meet the compilation restrictions. This is why performance bottlenecks occur in related technologies. That is, due to fixed compilation restrictions, there are called sub-functions that cannot be inline optimized each time inline optimization is performed because they do not meet the compilation restrictions. This phenomenon cannot be changed, making it difficult to break through the performance bottleneck.

[0034] The embodiment of the present invention aims to identify the called sub-function (target sub-function) in the first compilation result that cannot be inline optimized because it does not meet the compilation restriction conditions, and after identifying the target sub-function, inline optimize the target sub-function again, thereby breaking through the performance bottleneck in the related technology and achieving a better optimization effect.

[0035] First, an embodiment of the present invention can identify hot functions from all functions included in the first compilation result, and use the hot functions as calling functions. The hot functions contain many called sub-functions. The specific implementation of inline optimization is to directly insert the calling function (hot function) into the position of the function call. Due to the existence of compilation restrictions, some called sub-functions that do not meet the compilation restrictions are not inlined. Therefore, an embodiment of the present invention can identify the target sub-functions that are not inlined in the hot functions included in the first compilation result (that is, the called sub-functions that meet the compilation restrictions).

[0036] Step 103, compile the hot function again to perform inline optimization on the target sub-function to obtain a second compilation result of the application.

[0037] In an embodiment of the present invention, for the called sub-functions in the first compilation result that cannot be inline optimized due to not meeting the compilation restriction conditions, some of the called sub-functions still have value to be inline optimized again, for example, the unloaded called sub-functions can be inline optimized after being loaded, and some called sub-functions whose number of code lines exceeds the limit of the compilation restriction conditions but whose number of code lines is not too large can be optimized, etc.

[0038] In an embodiment of the present invention, for the first compilation result that has been inline optimized, the just-in-time compiler can continue to perform inline optimization again on at least part of the target sub-functions in the hot function that have not been inline optimized to obtain a second compilation result.

[0039] Optionally, step 103 may specifically include:

[0040] Sub-step 1031: If it is detected that the target sub-function is not inlined in the first compilation result because it is not loaded, then when compiling again, the loading status of the target sub-function is identified.

[0041] Sub-step 1032: When the loading status is loaded, inline optimization is performed on the target sub-function.

[0042] During the re-compilation process, the target sub-function that was not inline optimized during the last compilation because it was not loaded may have been loaded at this time, thereby satisfying the compilation restriction conditions, and completing the inline optimization of the target sub-function by re-compilation, so as to achieve the purpose of inline optimization of the called sub-function as much as possible. Among them, during the operation of the just-in-time compiler, each function can distinguish its loading / unloading status by setting the corresponding mark, such as, if the recognition module of the just-in-time compiler recognizes that a target sub-function has a loading mark, it is determined that the target sub-function is currently loaded; if it is recognized that a target sub-function has an unloaded mark, it is determined that the target sub-function is currently not loaded. In addition, during the compilation life cycle of the just-in-time compiler, a data table will be maintained to record the information of each function in real time, such as whether the function has been inlined, the loading status of the function, etc., so a convenient way is to determine the loading status of the target sub-function by querying the data table.

[0043] In addition, in one implementation, during the recompile process, the compilation restriction conditions may be released to achieve the maximum optimization effect. In another implementation, during the recompile process, the compilation restriction conditions may be adjusted to relax the compilation restriction conditions to achieve further optimization effect.

[0044] Step 104: Obtain performance parameters of the second compilation result, and if the performance parameters meet preset conditions, retain the second compilation result for use.

[0045] In the embodiment of the present invention, after undergoing re-compilation optimization, the performance parameters of the second compilation result can also be collected and the performance evaluation of the re-compilation can be performed to determine whether the result after the re-compilation optimization produces a positive effect (such as improvement of running speed and execution efficiency). If a positive effect is produced, it is considered that the performance parameters meet the preset conditions, and the second compilation result can be retained for use. If no positive effect is produced but a negative effect is produced, it is considered that the performance parameters corresponding to the second compilation result do not meet the preset conditions, the second compilation result is discarded, the first compilation result is used, or re-compilation is performed again.

[0046] In summary, in an embodiment of the present invention, by identifying hot functions that include target sub-functions that have not been inlined in the first compilation result, the hot functions are compiled again to inline optimize at least part of the target sub-functions in the hot functions, thereby obtaining a second compilation result of the application. The embodiment of the present invention compiles and optimizes the called sub-functions included in the hot functions as much as possible through multiple compilations, thereby achieving a further breakthrough in the compilation optimization effect and removing the optimization bottleneck.

[0047] Figure 2 It is a flowchart of the steps of another bytecode compilation method provided by an embodiment of the present invention. Figure 2 include:

[0048] Step 201: Obtain a first compilation result for the bytecode in the application.

[0049] This step may specifically refer to the above step 101, which will not be described in detail here.

[0050] Step 202: Select a calling function including the target sub-function from the first compilation result.

[0051] Step 203: Count the number of times each of the calling functions is called within a unit time.

[0052] Step 204: Determine the calling function whose calling times are greater than or equal to a preset number threshold as the hot function.

[0053] In the embodiment of the present invention, for steps 202-204, the first compilation result is the result obtained by the just-in-time compiler after inline compilation optimization of the hot functions of the bytecode in the application according to the compilation restriction conditions. Among them, the hot function refers to the function that is executed more frequently per unit time. Therefore, the embodiment of the present invention can count the number of calls of the calling function of the target sub-function that is not inlined in the first compilation result per unit time. If the number of calls of the calling function is greater than or equal to the preset number threshold (which can be set according to actual needs), then the calling function can be determined as a hot function.

[0054] Optionally, in the process of selecting a calling function including a target sub-function that is not inlined, a function in the calling function that is associated with a calling instruction is determined as the target sub-function.

[0055] In an example of obtaining the first compilation result, it is assumed that before the virtual machine is compiled, there are functions A, B, C, D, E, BA, CA, and CB in the bytecode of the application, and their calling relationship is as follows:

[0056] function A{

[0057] call B;

[0058] call C;

[0059] call D;

[0060] call E;

[0061] }

[0062] function B{

[0063] call BA;

[0064] }

[0065] function C{

[0066] call CA;

[0067] call CB;

[0068] }

[0069] Among them, call is a calling instruction, and hot function A is the calling function, which calls the called sub-functions B, C, D, and E respectively; in addition, function B further calls function BA, and function C further calls functions CA and CB.

[0070] After the application is run, the just-in-time compiler performs inline optimization on the hot function A according to the compilation restriction conditions, and the first compilation result obtained is:

[0071]

[0072] Among them, inline is the inline mark. Hot function A successfully inlines functions B and BA, but does not inline functions C, D, and E. The reason why function C is not inlined is that the number of its bytecodes is too large, exceeding the bytecode number threshold in the compilation restriction conditions; the reason why function D is not inlined is that it has not been loaded by the virtual machine at present; the reason why function E is not inlined is that the total number of functions inlined by hot function A has reached the function number threshold in the compilation restriction conditions.

[0073] Therefore, after an inline optimization compilation, the functions C, D, and E that are still associated with the call instruction call can be regarded as the target sub-functions in the embodiment of the present invention, that is, the functions that are not inline optimized.

[0074] Step 205: Obtain compilation restriction conditions of the just-in-time compiler corresponding to the bytecode.

[0075] In an embodiment of the present invention, the compilation restriction condition is used to screen the called sub-functions that can be inline optimized when inline optimization is performed on hot functions. For example, the compilation restriction condition does not allow unloaded functions to be inline optimized, does not allow functions with too many bytecodes to be inline optimized, does not allow the inlined code to include too many instructions, and so on.

[0076] Step 206, during the process of recompiling the hot function through the just-in-time compiler, the compilation restriction condition is released or adjusted to inline optimize at least part of the target sub-functions in the hot function that have not been inlined, so as to obtain a second compilation result of the application.

[0077] The embodiment of the present invention aims to re-inline optimize the called sub-functions in the first compilation result that cannot be inline optimized because they do not meet the compilation restriction conditions, thereby breaking through the performance bottleneck in the related technology and achieving a better optimization effect.

[0078] In an embodiment of the present invention, in one way, since a calling function has been inserted into an inlined sub-function, the inlined sub-function can be found by checking whether a calling function has been inserted into the sub-function; and since a call instruction still exists in a non-inlined sub-function, the non-inlined sub-function can be found by checking whether there is a call instruction in the sub-function, so the non-inlined sub-function and the inlined sub-function can be distinguished according to this rule.

[0079] In another way, during the compilation life cycle of the just-in-time compiler, a data table is maintained to record the information of each function in real time, such as whether the function has been inlined, the loading status of the function, etc., so that by querying the data table, the sub-functions that have not been inlined and the sub-functions that have been inlined can be determined.

[0080] Specifically, in the process of re-inline optimization, the embodiment of the present invention can remove the restrictions of the compilation restrictions so that the target sub-functions that have not been inlined can be successfully inline optimized to achieve the maximum inline optimization effect, or the embodiment of the present invention can reduce the compilation restrictions so that the restrictions brought by the compilation restrictions are weakened, thereby successfully inline optimizing at least part of the target sub-functions that have not been inlined in the hot function.

[0081] Optionally, the compilation restriction condition includes: when it is detected that the bytecode quantity of the target sub-function is less than a preset bytecode quantity threshold, inline optimization is performed on the target sub-function; step 206 may specifically include:

[0082] Sub-step 2061: Increase the preset bytecode quantity threshold so that the bytecode quantity of the target sub-function is less than the increased preset bytecode quantity threshold.

[0083] In one implementation of an embodiment of the present invention, the compilation restriction condition may include: when it is detected that the bytecode number of the target sub-function is less than a preset bytecode number threshold, the target sub-function is inlined; when it is detected that the bytecode number of the target sub-function is greater than or equal to the preset bytecode number threshold, the target sub-function is not inlined; that is, the compilation restriction condition does not allow the target sub-function with too large a bytecode number to be inlined by setting the preset bytecode number threshold. The embodiment of the present invention can relax the restriction on the bytecode number of functions to be inlined under the compilation restriction condition by increasing the preset bytecode number threshold, so that some target sub-functions that originally had a bytecode number exceeding the threshold but did not have a very large bytecode number can be inlined when compiled again.

[0084] Among them, during the compilation life cycle of the just-in-time compiler, a data table will be maintained to record the information of each function in real time. The function information includes the number of bytecodes of the function, that is, there is a functional function in the just-in-time compiler for real-time identification of the number of function bytecodes, and this functional function identifies the number of function bytecodes and records it in the data table, so that by querying the data table, the number of bytecodes of the target sub-function can be determined. The preset bytecode number threshold can be set by the user according to actual needs (such as the size of hardware resources). For example, if the current hardware resources are sufficient, the preset bytecode number threshold can be set larger. After that, the size of the bytecode number of the target sub-function and the preset bytecode number threshold can be compared through a comparison operation.

[0085] For example, as described above, by querying the query data table maintained by the just-in-time compiler, it can be obtained that the number of bytecode lines of the target sub-function H is 9. Assuming that the preset bytecode number threshold in the compilation restriction condition is 8 during a compilation, the target sub-function H cannot be inlined during the first compilation. During the re-compilation process, the embodiment of the present invention can adjust the preset bytecode number threshold to 10. After the adjustment, the re-compilation process can perform inline optimization on the target sub-function H. Inline optimization of the target sub-function H means first finding the call location of the target sub-function H, and then directly inserting the target sub-function H into the call location. After the target sub-function H is inline optimized, the number of components occupied by calling the target sub-function H is reduced, and the memory access overhead of the call is reduced, so the call to the target sub-function H is faster.

[0086] In addition, in one way, after all target sub-functions that can be inline optimized are identified, all target sub-functions can be inline optimized uniformly. In another way, each time a target sub-function that can be inline optimized is identified, one target sub-function can be inline optimized.

[0087] Optionally, the compilation restriction condition includes: when it is detected that the total instruction number of the hot function after the target sub-function is inlined is less than a preset instruction number threshold, inlining the target sub-function; step 206 may specifically include:

[0088] Sub-step 2062: Increase the preset instruction quantity threshold so that the total instruction quantity of the hot function after inlining the target sub-function is less than the increased preset instruction quantity threshold.

[0089] In another implementation of the embodiment of the present invention, the compilation restriction condition may include: when it is detected that the total number of instructions of the hot function after the target sub-function is inlined is less than a preset instruction number threshold, the target sub-function is inlined; when it is detected that the total number of instructions of the hot function after the target sub-function is inlined is greater than or equal to the preset instruction number threshold, the target sub-function is not inlined; that is, the compilation restriction condition does not allow the total number of instructions included in the inlined hot function to be too large through the setting of the preset instruction number threshold. The embodiment of the present invention can relax the restriction on the number of instructions included in the inlined hot function by increasing the preset instruction number threshold, so that some target sub-functions can be inlined when compiled again.

[0090] For example, for the target sub-function F, assuming that during the first compilation, the preset instruction number threshold in the compilation restriction condition is 50, then during the first compilation, the target sub-function F is inlined, so that the total number of instructions included in the hot function becomes 55, and thus the target sub-function F cannot be inlined. During the re-compilation process, the embodiment of the present invention can adjust the preset instruction number threshold to 60. After the adjustment, the target sub-function F can be inlined during the re-compilation process.

[0091] During the compilation life cycle of the just-in-time compiler, a data table is maintained to record the information of each function in real time. The function information may include the total number of instructions of the function, that is, there is a function function in the just-in-time compiler for real-time identification of the total number of instructions of the function, and the total number of instructions of the function is identified by the function function and recorded in the data table, so that the total number of instructions of the target sub-function F can be determined by querying the data table. The preset instruction number threshold can be set by the user according to actual needs (such as the size of hardware resources). For example, if the current hardware resources are sufficient, the preset instruction number threshold can be set larger. After that, the total number of instructions of the hot function after the target sub-function is inlined and the size of the preset instruction number threshold can be compared through a comparison operation. Inline optimization of the target sub-function F means first finding the call location of the target sub-function F, and then directly inserting the target sub-function F into the call location. After inline optimization of the target sub-function F, the number of components occupied by calling the target sub-function F is reduced, and the memory access overhead of the call is reduced, so the call of the target sub-function F is faster.

[0092] Optionally, the compilation restriction condition includes: when it is detected that the total number of functions that have been inlined in the hot function is less than a preset function quantity threshold, inlining the target sub-function; step 206 may specifically include:

[0093] Sub-step 2063: Increase the preset function quantity threshold so that the total number of functions inlined in the hot function after the target sub-function is inlined is less than the increased preset function quantity threshold.

[0094] In another implementation of the embodiment of the present invention, the compilation restriction condition may include: when it is detected that the total number of functions that have been inlined for the hot function is less than a preset function number threshold, inlining the target sub-function; when it is detected that the total number of functions that have been inlined for the hot function is greater than or equal to the preset function number threshold, not inlining the target sub-function; that is, the compilation restriction condition does not allow hot inlining optimization of too many functions by setting the preset function number threshold. The embodiment of the present invention can relax the restriction on the number of functions for hot inlining optimization under the compilation restriction condition by increasing the preset function number threshold, so that some target sub-functions can be inlined when compiled again.

[0095] For example, for the target sub-function G, assuming that the preset function number threshold in the compilation restriction condition is 5, then in one compilation, the hot function has inlined 5 functions, and the target sub-function G cannot be inlined because the total number of functions inlined by the hot function reaches the upper limit. In the process of re-compilation, the embodiment of the present invention can adjust the preset instruction number threshold to 6. After the adjustment, the process of re-compilation can inline the target sub-function G. In the compilation life cycle of the just-in-time compiler, a data table will be maintained to record the information of each function in real time. The function information can include the number of inlined functions of the function, that is, there is a function function in the just-in-time compiler for real-time identification of the number of inlined functions of the function, and the function identifies the number of inlined functions of the function and records it in the data table, so that by querying the data table, the number of inlined functions of the hot function can be determined. The preset function number threshold can be set by the user according to actual needs (such as the size of hardware resources). For example, if the current hardware resources are sufficient, the preset function number threshold can be set larger. After that, the size of the inlined function number of the hot function and the preset function number threshold can be compared by comparison operation. The inline optimization of the target sub-function G refers to first finding the calling location of the target sub-function G, and then directly inserting the target sub-function G into the calling location.

[0096] It should be noted that, for the above three methods, the threshold value is increased to relax the compilation restriction conditions. Specifically, one method of increasing the threshold value may be to directly adjust the threshold value to a larger value, and another method of increasing the threshold value may be to increase the threshold value multiple times according to a fixed step size (the step size is a smaller value), thereby gradually increasing the threshold value. For example, in one compilation operation, the threshold value is adjusted by increasing the step size n each time and performing k increase operations respectively; in addition, the step size n may be increased in one compilation operation, and the step size n may be increased again in the next compilation operation... thereby continuing to increase the threshold value in k compilations, and these threshold increase operations may cause some target sub-functions to be successfully inlined.

[0097] With respect to the example proposed in steps 202-204, with respect to the first compilation result obtained after an inline optimization compilation, functions C, D, and E in the hot functions can be regarded as target sub-functions in an embodiment of the present invention, that is, functions that are not inlined.

[0098] In one implementation, the second compilation result obtained by adjusting the compilation restriction condition and performing the recompilation includes:

[0099]

[0100] Among them, after re-compilation, the bytecode quantity of the target sub-function C meets the limit of the bytecode quantity threshold in the adjusted compilation restriction condition, and can thus be successfully inlined.

[0101] In another implementation, the compilation is performed again by adjusting the compilation restriction condition, and the second compilation result obtained includes:

[0102]

[0103] After recompiling, the bytecode quantity of the target sub-function C meets the bytecode quantity threshold in the adjusted compilation restriction condition, and can be successfully inlined. The target sub-function D has been loaded by the virtual machine at this time, and can be successfully inlined.

[0104] Step 207: Acquire performance parameters of the second compilation result, and retain the second compilation result for use if the performance parameters meet preset conditions.

[0105] This step may be specifically referred to as the above step 104, which will not be described in detail here.

[0106] Optionally, step 207 may specifically include:

[0107] Sub-step 2071, obtaining the performance parameter and a first total number of static instructions in the first compilation result; the performance parameter includes a second total number of static instructions in the second compilation result.

[0108] Sub-step 2072: When the second total number is less than the first total number, retain the second compilation result for use.

[0109] After the re-compilation optimization, the performance parameters of the second compilation result can be collected and the re-compilation performance evaluation can be performed to determine whether the result after the re-compilation optimization produces a positive effect. If a positive effect is produced, it is considered that the performance parameters meet the preset conditions and the second compilation result can be retained for use; if no positive effect is produced but a negative effect is produced instead, it is considered that the performance parameters do not meet the preset conditions and the second compilation result is not used.

[0110] In one implementation of the embodiment of the present invention, a first total number of static instructions in the first compilation result and a second total number of static instructions in the second compilation result can be obtained. If the second total number is less than the first total number, it is considered that the process of re-inline compilation has a positive effect. At this time, using the second compilation result can improve the operating efficiency of subsequent applications. If the second total number is greater than or equal to the first total number, it is considered that the process of re-inline compilation has no effect, or has a negative effect. At this time, the second compilation result can be used. Among them, the second total number is less than the first total number, indicating that the number of static instructions of the result after inline optimization is smaller than that before inline optimization. Generally speaking, the execution speed of the code with a smaller number of static instructions is faster than the execution speed of the code with a larger number of static instructions. For example, the execution speed of a code with 5 static instructions is generally faster than the execution speed of a code with 10 static instructions.

[0111] It should be noted that if the second compilation result is used, the pointer of the pointer area of ​​the hot function can be adjusted to point to the instruction address of the function corresponding to the second compilation result, and the original instruction area of ​​the hot function can be invalidated.

[0112] Optionally, step 207 may specifically include:

[0113] Sub-step 2073: Count the number of first instructions corresponding to each clock cycle in the process of running the application using the first compilation result, and the number of second instructions corresponding to each clock cycle in the process of running the application using the second compilation result.

[0114] Sub-step 2074: When the first number of instructions is greater than the second number of instructions, retain the second compilation result for use.

[0115] In another implementation method of the embodiment of the present invention, the application can be first run using the second compilation result, that is, the pointer of the pointer area of ​​the hot function is adjusted to point to the instruction address of the function corresponding to the second compilation result, and then the application is run. Then, the first number of instructions per clock cycle in the process of running the application using the first compilation result and the second number of instructions per clock cycle in the process of running the application using the second compilation result are obtained. If the second number of instructions is greater than the first number of instructions, it is considered that the process of inline compilation again has a positive effect. At this time, using the second compilation result can improve the running efficiency of subsequent applications; if the second number of instructions is less than or equal to the first number of instructions, it is considered that the process of inline compilation again has no effect, or has a negative effect. At this time, the second compilation result can be not used, that is, the operation of adjusting the pointer of the pointer area of ​​the hot function to point to the instruction address of the function corresponding to the second compilation result is eliminated, and the original instruction area of ​​the hot function is restored. Among them, the second instruction number is greater than the first instruction number, which means that the number of instructions executed per clock cycle after inline optimization is greater than that before inline optimization. Generally speaking, the more instructions executed per clock cycle, the better the performance. For example, the performance of code that executes 10 instructions per clock cycle is better than the performance of code that executes 5 instructions per clock cycle.

[0116] Optionally, after step 204, the method further includes:

[0117] Step 208: When it is determined that there is an idle position in the compilation queue, the hot function is added to the compilation queue for recompilation.

[0118] Step 209: When it is determined that there is no free position in the compilation queue, wait for the free position to be generated in the queue to be compiled.

[0119] In an embodiment of the present invention, a compilation queue is provided in the just-in-time compiler, and the just-in-time compiler maintains the execution of compilation tasks through the compilation queue. In the embodiment of the present invention, when it is determined that there is an idle position in the compilation queue, the hot function can be added to the compilation queue for re-compilation; and when it is determined that there is no idle position in the compilation queue, the just-in-time compiler waits for the idle position to be generated in the queue to be compiled.

[0120] The purpose of the above operation is to treat the inline optimization in the compilation process as an independent process, and make the execution priority of the inline optimization lower than the execution priority of the normal compilation operation, that is, when there is a normal compilation operation in the compilation queue, the normal compilation operation is executed first, and the hot inline optimization task is executed when the compilation queue is idle or the compilation queue is empty, so as to avoid the inline optimization operation from interfering with the normal compilation operation of the just-in-time compiler.

[0121] Before step 206, the following steps may also be included:

[0122] Step 210: Identify the function state of the hot function.

[0123] Step 211: When the function state is still a hot function, enter the above-mentioned step of recompiling the hot function.

[0124] In an embodiment of the present invention, after a hot function is placed in a compilation queue, it may wait for a certain period of time in the compilation queue before being inline optimized (it needs to wait for the execution of the first task in the queue first), and during the waiting process, the frequency of the hot function being called may change, and even make the function no longer a hot function. Therefore, when the compilation queue executes inline optimization of the hot function, it is necessary to first identify the function state of the hot function, and only recompile the hot function when the function state is still a hot function. Recompiling means trying to inline optimize the target sub-function that has not been inlined in the hot function, and the sub-functions that have been inlined in the hot function and other sub-functions will not be affected.

[0125] Reference Figure 3 , which shows an overall flow chart of a bytecode compilation method, including:

[0126] S1. Identify hot functions that need to be inlined again.

[0127] S2. Determine whether the compilation queue is idle; if not, end the process; if so, execute S3.

[0128] S3. Perform inline optimization on the target sub-functions that are not inlined in the hot functions.

[0129] S4: Determine whether the performance of the result after inline optimization is improved. If not, end; if so, execute S5.

[0130] S5. Apply the result after inline optimization and end the process.

[0131] In summary, in an embodiment of the present invention, by identifying hot functions that include target sub-functions that have not been inlined in the first compilation result, the hot functions are compiled again to inline optimize at least part of the target sub-functions in the hot functions, thereby obtaining a second compilation result of the application. The embodiment of the present invention compiles and optimizes the called sub-functions included in the hot functions as much as possible through multiple compilations, thereby achieving a further breakthrough in the compilation optimization effect and removing the optimization bottleneck.

[0132] Figure 4 is a block diagram of a bytecode compiling device provided by an embodiment of the present invention, such as Figure 4 As shown, the device comprises:

[0133] An acquisition module 301 is used to acquire a first compilation result of a bytecode in an application program;

[0134] An identification module 302 is used to identify hot functions from all functions included in the first compilation result; the hot functions include target sub-functions that are not inline optimized;

[0135] A compiling module 303 is used to compile the hot function again to perform inline optimization on the target sub-function to obtain a second compilation result of the application program;

[0136] The testing module 304 is used to obtain performance parameters of the second compilation result, and when the performance parameters meet preset conditions, retain the second compilation result for use.

[0137] Optionally, the identification module 302 includes:

[0138] A selection submodule, used for selecting a calling function of the target subfunction from the first compilation result;

[0139] A statistics submodule, used to count the number of times each of the calling functions is called within a unit time;

[0140] The first determination submodule is used to determine the calling function whose calling times is greater than or equal to a preset number threshold as the hot function.

[0141] Optionally, the device further comprises:

[0142] The determination module is used to determine the related function associated with the calling instruction in the calling function as the target sub-function.

[0143] Optionally, the compiling module 303 includes:

[0144] A condition acquisition submodule, used to obtain the compilation restriction conditions of the just-in-time compiler corresponding to the bytecode;

[0145] The condition adjustment submodule is used to release or adjust the compilation restriction condition to perform inline optimization on at least part of the target sub-functions in the hot function that have not been inlined, so as to obtain a second compilation result of the application.

[0146] Optionally, the compilation restriction condition includes: when it is detected that the number of bytecodes of the target sub-function is less than a preset bytecode number threshold, inlining the target sub-function; the condition adjustment sub-module includes:

[0147] The first adjustment unit is used to increase the preset bytecode quantity threshold so that the bytecode quantity of the target sub-function is less than the increased preset bytecode quantity threshold.

[0148] Optionally, the compilation restriction condition includes: when it is detected that the total number of instructions of the hot function after the target sub-function is inlined is less than a preset instruction number threshold, inlining the target sub-function; the condition adjustment sub-module includes:

[0149] The second adjustment unit is used to increase the preset instruction quantity threshold so that the total instruction quantity of the hot function after the target sub-function is inlined is less than the increased preset instruction quantity threshold.

[0150] Optionally, the compiling module 303 includes:

[0151] a state acquisition submodule, for identifying the loading state of the target subfunction during recompiling if it is detected that the target subfunction is not inlined in the first compilation result because it is not loaded;

[0152] The judgment submodule is used to perform inline optimization on the target subfunction when the loading status is loaded.

[0153] Optionally, the device further comprises:

[0154] An adding module, used for adding the hot function to the compilation queue for re-compilation when it is determined that there is an idle position in the compilation queue;

[0155] A waiting module, configured to wait for the idle position to be generated in the queue to be compiled if it is determined that there is no idle position in the compilation queue;

[0156] The device also includes:

[0157] A state module, used for identifying the function state of the hot function;

[0158] The loop module is used to enter the above-mentioned step of recompiling the hot function when the function state is still a hot function.

[0159] Optionally, the testing module 304 includes:

[0160] A first acquisition submodule, configured to acquire the performance parameter and a first total number of static instructions in the first compilation result; the performance parameter includes a second total number of static instructions in the second compilation result;

[0161] The first retaining submodule is configured to retain the second compilation result for use when the second total number is less than the first total number.

[0162] Optionally, the testing module 304 includes:

[0163] A second acquisition submodule is used to count the number of first instructions corresponding to each clock cycle in the process of running the application using the first compilation result, and the number of second instructions corresponding to each clock cycle in the process of running the application using the second compilation result;

[0164] The second reservation submodule is used to reserve the second compilation result for use when the second instruction number is greater than the first instruction number.

[0165] In summary, in an embodiment of the present invention, by identifying hot functions that include target sub-functions that have not been inlined in the first compilation result, the hot functions are compiled again to inline optimize at least part of the target sub-functions in the hot functions, thereby obtaining a second compilation result of the application. The embodiment of the present invention compiles and optimizes the called sub-functions included in the hot functions as much as possible through multiple compilations, thereby achieving a further breakthrough in the compilation optimization effect and removing the optimization bottleneck.

[0166] The bytecode compiling device in the embodiment of the present invention may be a device, or a component, an integrated circuit, or a chip in a terminal. The device may be a mobile electronic device or a non-mobile electronic device. Exemplarily, the mobile electronic device may be a mobile phone, a tablet computer, a laptop computer, a PDA, an in-vehicle electronic device, a wearable device, an ultra-mobile personal computer (UMPC), a netbook, or a personal digital assistant (PDA), etc. The non-mobile electronic device may be a server, a network attached storage (NAS), a personal computer (PC), a television (TV), a teller machine, or a self-service machine, etc., which is not specifically limited in the embodiment of the present invention.

[0167] The bytecode compiling device in the embodiment of the present invention may be a device having an operating system. The operating system may be an Android operating system, an iOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present invention.

[0168] The bytecode compiling device provided in the embodiment of the present invention can implement each process implemented by the bytecode compiling device in the method embodiment, and will not be described again here to avoid repetition.

[0169] Optionally, an embodiment of the present invention further provides an electronic device, including a processor, a memory, and a program or instruction stored in the memory and executable on the processor. When the program or instruction is executed by the processor, each process of the above-mentioned bytecode compilation method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.

[0170] It should be noted that the electronic devices in the embodiments of the present invention include the mobile electronic devices and non-mobile electronic devices mentioned above.

[0171] Figure 5 The present invention is a schematic diagram of the hardware structure of an electronic device.

[0172] The electronic device 1300 includes but is not limited to: a radio frequency unit 1301, a network module 1302, an audio output unit 1303, an input unit 1304, a sensor 1305, a display unit 1306, a user input unit 1307, an interface unit 1308, a memory 1309, and a processor 1310 and other components.

[0173] Those skilled in the art will appreciate that the electronic device 1300 may also include a power source (such as a battery) for supplying power to each component, and the power source may be logically connected to the processor 1310 through a power management system, thereby implementing functions such as managing charging, discharging, and power consumption management through the power management system. Figure 5 The electronic device structure shown in the figure does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently, which will not be described in detail here.

[0174] It should be understood that in an embodiment of the present invention, the input unit 1304 may include a graphics processor (GPU) 13041 and a microphone 13042, and the graphics processor 13041 processes the image data of a static picture or video obtained by an image capture device (such as a camera) in a video capture mode or an image capture mode. The display unit 1306 may include a display panel 13061, and the display panel 13061 may be configured in the form of a liquid crystal display, an organic light emitting diode, etc. The user input unit 1307 includes a touch panel 13071 and at least one of other input devices 13072. The touch panel 13071 is also called a touch screen. The touch panel 13071 may include two parts: a touch detection device and a touch controller. Other input devices 13072 may include, but are not limited to, a physical keyboard, function keys (such as a volume control button, a switch button, etc.), a trackball, a mouse, and a joystick, which will not be repeated here.

[0175] The memory 1309 can be used to store software programs and various data. The memory 1309 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, an application program or instructions required for at least one function (such as a sound playback function, an image playback function, etc.), etc. In addition, the memory 1309 may include a volatile memory or a non-volatile memory, or the memory 1309 may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDRSDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synchronous link dynamic random access memory (SLDRAM) and a direct memory bus random access memory (DRRAM). The memory 1309 in the embodiment of the present invention includes but is not limited to these and any other suitable types of memory.

[0176] The processor 1310 may include one or more processing units; optionally, the processor 1310 integrates an application processor and a modem processor, wherein the application processor mainly processes operations related to an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communication signals, such as a baseband processor. It is understandable that the modem processor may not be integrated into the processor 1310.

[0177] An embodiment of the present invention also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the various processes of the above-mentioned bytecode compilation method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0178] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation modes, which are merely illustrative rather than restrictive. Under the guidance of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the present invention and the claims, all of which are within the protection of the present invention.

Claims

1. A bytecode compilation method, Characterized in that the method include: Obtain a first compilation result for bytecodes in the application program; Identify hot functions from all functions included in the first compilation result; The hot function includes a target sub-function that is not inline optimized; Compiling the hot function again to perform inline optimization on the target sub-function, and obtaining a second compilation result of the application; Acquire performance parameters of the second compilation result, and if the performance parameters meet a preset condition, retain the second compilation result for use.

2. The method according to claim 1, It is characterized in that The step of identifying hot functions from all functions included in the first compilation result comprises: Selecting a calling function including the target sub-function from the first compilation result; Counting the number of times each of the calling functions is called within a unit time; The calling function whose calling times is greater than or equal to the preset times threshold is determined as the hot function.

3. The method according to claim 2, It is characterized in that The method further comprises: A related function associated with a calling instruction in the calling function is determined as the target sub-function.

4. The method according to claim 1, It is characterized in that When the hot function is compiled again, Obtaining compilation restriction conditions of the just-in-time compiler corresponding to the bytecode; The compilation restriction condition is released or adjusted to perform inline optimization on at least a portion of the target sub-functions in the hot function that have not been inlined, so as to obtain a second compilation result of the application.

5. The method according to claim 4, It is characterized in that The compilation restriction condition includes: the number of bytecodes of the target sub-function is less than a preset bytecode number threshold; and adjusting the compilation restriction condition includes: The preset bytecode quantity threshold is increased so that the bytecode quantity of the target sub-function is less than the increased preset bytecode quantity threshold.

6. The method according to claim 4, It is characterized in that The compilation restriction condition includes: the total instruction quantity of the hot function after the target sub-function is inlined is less than a preset instruction quantity threshold; and adjusting the compilation restriction condition includes: The preset instruction quantity threshold is increased so that the total instruction quantity of the hot function after the target sub-function is inlined is less than the increased preset instruction quantity threshold.

7. The method according to claim 1, It is characterized in that The method further comprises: If it is detected that the target sub-function is not inlined in the first compilation result because it is not loaded, then when compiling again, identifying the loading status of the target sub-function; When the loading status is loaded, the target sub-function is inline optimized.

8. The method according to claim 1, It is characterized in that The method further comprises: When it is determined that there is an idle position in the compilation queue, adding the hot function to the compilation queue for recompilation; When it is determined that there is no free position in the compilation queue, the process waits for the free position to be generated in the queue to be compiled.

9. The method according to claim 1, It is characterized in that When obtaining the performance parameter of the second compilation result, Obtaining a first total number of static instructions in the first compilation result; the performance parameter includes a second total number of static instructions in the second compilation result; When the second total number is less than the first total number, the second compilation result is retained for use.

10. The method according to claim 1, It is characterized in that When obtaining the performance parameter of the second compilation result, Counting the number of first instructions corresponding to each clock cycle in a process of running the application using the first compilation result, and the number of second instructions corresponding to each clock cycle in a process of running the application using the second compilation result; When the second number of instructions is greater than the first number of instructions, the second compilation result is retained for use.

11. A bytecode compiling device, It is characterized in that include: An acquisition module, used for acquiring a first compilation result of the bytecode in the application program; An identification module, configured to identify hot functions from all functions included in the first compilation result; the hot functions include target sub-functions that are not inline optimized; A compiling module, used for compiling the hot function again to perform inline optimization on the target sub-function and obtain a second compilation result of the application program; The testing module is used to obtain performance parameters of the second compilation result, and when the performance parameters meet preset conditions, retain the second compilation result for use.

12. An electronic device, It is characterized in that The method comprises a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps of the bytecode compilation method as claimed in any one of claims 1 to 10.

13. A readable storage medium, It is characterized in that The readable storage medium stores a program or instruction, and when the program or instruction is executed by a processor, the steps of the bytecode compilation method according to any one of claims 1 to 10 are implemented.