Code compiling method and device, electronic equipment and computer readable storage medium

By acquiring and simulating historical compilation code and its optimization decisions, and selecting the optimal optimization decision as the compilation result, the problem of complex and time-consuming matching of available code in cached data is solved, thereby improving compilation efficiency and reducing overhead.

CN117008912BActive Publication Date: 2026-07-31TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
TENCENT TECHNOLOGY (SHENZHEN) CO LTD
Filing Date
2022-09-02
Publication Date
2026-07-31

AI Technical Summary

Technical Problem

During just-in-time compilation, the process of matching available code from cached data is complex and time-consuming, resulting in high compilation overhead and low efficiency.

Method used

By obtaining the historical compilation code and optimization decisions of the code to be compiled, the compilation is simulated and the historical compilation code with the best optimization decision is selected as the compilation result, saving the tedious process of matching available code from historical cache data.

Benefits of technology

It significantly improves code compilation efficiency, reduces compilation resource overhead, and alleviates data storage pressure.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117008912B_ABST
    Figure CN117008912B_ABST
Patent Text Reader

Abstract

This application discloses a code compilation method, apparatus, electronic device, and computer-readable storage medium, applicable to various scenarios such as computer technology, cloud technology, artificial intelligence, intelligent transportation, and assisted driving. The method includes: acquiring code to be compiled; acquiring historical compiled code corresponding to the code to be compiled, and optimization decisions used when compiling the code to be compiled into the historical compiled code; compiling the code to be compiled according to each optimization decision to obtain current compiled code corresponding to each optimization decision; determining the optimal optimization decision from the optimization decisions based on the current compiled code; and determining the historical compiled code corresponding to the optimal optimization decision as the compilation result of the code to be compiled. This application significantly improves code compilation efficiency and reduces compilation resource overhead.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and specifically to a code compilation method, apparatus, computer device, and readable storage medium. Background Technology

[0002] With the development of the Internet, during the just-in-time (JIT) compilation process, usable code can be determined from the cached data of historical compilation results, and the correct usable code can be identified as the compilation result.

[0003] However, the cached data contains a large number of functions, function values ​​and other cached information, which makes the process of matching available code from the cached data more complicated and time-consuming, resulting in high code compilation overhead and low efficiency. Summary of the Invention

[0004] This application provides a code compilation method, apparatus, electronic device, and computer-readable storage medium, which can significantly improve code compilation efficiency and reduce compilation resource overhead.

[0005] A first aspect of this application provides a code compilation method, the method comprising:

[0006] Obtain the code to be compiled;

[0007] Obtain the historical compiled code corresponding to the code to be compiled, and the optimization decisions made when compiling the code to be compiled into the historical compiled code;

[0008] Based on each optimization decision, the code to be compiled is compiled to obtain the current compiled code corresponding to each optimization decision;

[0009] Based on the currently compiled code, determine the optimal optimization decision from the optimization decisions;

[0010] The historical compiled code corresponding to the optimal optimization decision is determined as the compilation result of the code to be compiled.

[0011] Accordingly, a second aspect of the present application provides a code compilation apparatus, the apparatus comprising:

[0012] The module for obtaining code to be compiled is used to obtain the code to be compiled.

[0013] The historical data acquisition module is used to acquire the historical compilation code corresponding to the code to be compiled, as well as the optimization decisions made when compiling the code to be compiled into the historical compilation code;

[0014] The current compilation code determination module is used to compile the code to be compiled according to each optimization decision to obtain the current compilation code corresponding to each optimization decision;

[0015] The optimal optimization decision determination module is used to determine the optimal optimization decision from the optimization decisions based on the currently compiled code;

[0016] The compilation result determination module is used to determine the historical compilation code corresponding to the optimal optimization decision as the compilation result of the code to be compiled.

[0017] Optionally, the current compiled code determination module further includes:

[0018] The simulation compilation submodule is used to perform multiple rounds of simulation compilation on the code to be compiled, and to execute the optimization decision on the code to be compiled once in each round of simulation compilation;

[0019] The compilation result acquisition submodule is used to acquire the compilation results generated in each round of simulated compilation and use the compilation results as the current compiled code.

[0020] Optionally, the optimal optimization decision determination module further includes:

[0021] The scoring submodule is used to obtain a score for each of the currently compiled codes;

[0022] The optimal optimization decision acquisition submodule is used to determine the optimal optimization decision from the optimization decisions based on the score of the currently compiled code.

[0023] Optionally, the scoring submodule further includes:

[0024] The first score acquisition submodule is used to acquire the first score of the currently compiled code. The first score is used to characterize whether the optimization decision improves the performance of the compilation thread when the compilation thread compiles the code to be compiled using each optimization decision.

[0025] The second score acquisition submodule is used to accumulate multiple first scores to obtain a second score. If the second score is greater than a preset threshold, the first optimization decision corresponding to the multiple first scores is recorded.

[0026] Optionally, the optimal decision acquisition submodule is further specifically used for:

[0027] If the second score is greater than the preset threshold, then a third score is obtained for each of the first optimization decisions, and the third score is used to characterize the performance improvement of the first optimization decision on the compilation thread;

[0028] The first optimization decision with the highest third score is selected as the optimal optimization decision.

[0029] Optionally, the code compilation apparatus may further include:

[0030] The global score acquisition module is used to obtain the second score corresponding to all the currently compiled code.

[0031] The scoring and judgment module is used to skip the operation of obtaining the first optimization decision and directly compile the code to be compiled if all the second scores are less than or equal to the preset threshold.

[0032] Optionally, the compilation result determination module is specifically used for:

[0033] The first loading logic of the compilation process is obtained, wherein the compilation thread is a thread used to compile the code to be compiled;

[0034] A second loading logic is added to the first loading logic, and the second loading logic is used to load the historical edit code corresponding to the compilation result.

[0035] Optionally, the code compilation apparatus may further include:

[0036] The first historical compiled code acquisition module is used to acquire the first historical compiled code, which is provided with a storage space for storing the corresponding optimal optimization decision;

[0037] A mapping relationship acquisition module is used to acquire the mapping relationship between the first historical code and the code to be compiled;

[0038] A storage module is used to store the first historical code and the mapping relationship to the target location.

[0039] Optionally, the historical data acquisition module is specifically used for:

[0040] Search the target list to see if there is any historical compiled code corresponding to the code to be compiled.

[0041] If it exists, then the optimization decision corresponding to the historical compiled code is further obtained;

[0042] If it does not exist, skip the operation of obtaining the historical compiled code and the optimization decision, and directly compile the code to be compiled.

[0043] Optionally, the historical data acquisition module is specifically used for:

[0044] Obtain optimization information used when compiling the code to be compiled;

[0045] Based on the function type corresponding to the optimization information, optimization information of the same function type is organized into each optimization decision.

[0046] Optionally, the optimization information includes the optimization method of the optimized code, the relocation information of the optimized code, and the class information of the optimization method.

[0047] A third aspect of this application also provides an electronic device, including a memory storing a plurality of instructions; the processor loads the instructions from the memory to execute the steps in any of the code compilation methods provided in this application.

[0048] A fourth aspect of this application also provides a computer-readable storage medium storing a plurality of instructions adapted for loading by a processor to execute steps in any of the code compilation methods provided in this application.

[0049] A fifth aspect of this application also provides a computer program product, including a computer program or instructions, which, when executed by a processor, implement the steps in any of the code compilation methods provided in this application.

[0050] Therefore, it can be seen that when compiling code, the embodiments of this application can first obtain the historical compiled code and the optimization decisions corresponding to the historical compiled code. The compilation of the code to be compiled is simulated by the optimization decisions, and the most suitable historical compiled code is selected as the compilation result. This can save the tedious process of matching available code from historical cache data, thereby significantly improving the efficiency of code compilation and reducing compilation overhead. Furthermore, in the future, only the historical compiled code and the corresponding optimization decisions need to be stored as historical cache data, which reduces the data storage pressure. Attached Figure Description

[0051] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0052] Figure 1 This is a schematic diagram of a scenario illustrating the code compilation method provided in an embodiment of this application;

[0053] Figure 2 This is a flowchart illustrating the code compilation method provided in an embodiment of this application;

[0054] Figure 3 This is a flowchart illustrating another code compilation method provided in an embodiment of this application;

[0055] Figure 4 This is a schematic diagram illustrating the storage and loading of historical compiled code provided in an embodiment of this application;

[0056] Figure 5 This is a schematic diagram of the process for obtaining optimization decisions provided in an embodiment of this application;

[0057] Figure 6 This is a schematic diagram of the process of compiling the code to be compiled provided in the embodiments of this application;

[0058] Figure 7 This is a schematic diagram of the structure of the code compilation device provided in the embodiments of this application;

[0059] Figure 8 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation

[0060] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0061] Artificial intelligence (AI) is a technology that uses digital computers to simulate human perception of the environment, acquisition of knowledge, and use of that knowledge. This technology can enable machines to possess functions similar to human perception, reasoning, and decision-making. Fundamental AI technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies mainly include computer vision, speech processing, natural language processing, as well as machine learning / deep learning, autonomous driving, and intelligent transportation.

[0062] With the research and advancement of artificial intelligence (AI) technology, AI is being studied and applied in various fields, such as smart homes, smart wearable devices, virtual assistants, smart speakers, smart marketing, autonomous driving, drones, robots, smart healthcare, smart customer service, vehicle networking, and intelligent transportation. It is believed that with the development of technology, AI will be applied in more fields and play an increasingly important role.

[0063] This application provides a code compilation method, apparatus, electronic device, and storage medium.

[0064] Specifically, the code compilation device can be integrated into an electronic device, such as a terminal, server, or Java Virtual Machine. The terminal can be a mobile phone, tablet, smart Bluetooth device, laptop, desktop computer, smart TV, or in-vehicle device; the server can be a single server, a server cluster consisting of multiple servers, or a cloud server.

[0065] In some embodiments, the code compilation device may also be integrated into multiple electronic devices, such as multiple servers, with multiple servers implementing the code compilation method of this application.

[0066] For example, refer to Figure 1 The electronic device can be a server that applies the embodiments of this application, or it can be other terminals that can execute the embodiments of this application.

[0067] The following sections provide detailed descriptions of each example. It should be noted that the sequence numbers of the following embodiments are not intended to limit the preferred order of the embodiments.

[0068] like Figure 1 As shown, when compiling code via an electronic device, the server can obtain the code to be compiled; then obtain the historical compiled code corresponding to the code to be compiled, and the optimization decisions used when compiling the code to be compiled into the historical compiled code; then, according to each optimization decision, the code to be compiled is compiled to obtain the current compiled code corresponding to each optimization decision; then, according to the current compiled code, the optimal optimization decision is determined from the optimization decisions; finally, the historical compiled code corresponding to the optimal optimization decision is determined as the compilation result of the code to be compiled.

[0069] Furthermore, in the embodiments of this application, "multiple" refers to two or more. The terms "first" and "second," etc., in the embodiments of this application are used for distinguishing descriptions and should not be construed as implying relative importance.

[0070] The following sections provide detailed descriptions of each example. It should be noted that the order in which the embodiments are described is not intended to limit the preferred order of the embodiments.

[0071] The code compilation method can be executed by the terminal or the server alone, or by both the terminal and the server. In the embodiments of this application, the method is described by example when it is executed by the terminal.

[0072] In this embodiment, a code compilation method is provided, such as Figure 2 As shown, the specific process of compiling this code can be described as follows:

[0073] Step 201: Obtain the code to be compiled.

[0074] Compilation is the process of translating the code of a high-level computer language into a low-level computer language that can be executed by the computer, so that the computer can perform the function corresponding to the code. For example, Java code can be translated into machine code that can be executed by the computer through compilation.

[0075] It's understandable that a compilation device needs to receive the code to be compiled before performing the compilation operation. For example, the compilation device can be a Java Virtual Machine (JVM), which can receive the code to be compiled.

[0076] long add4(long num){

[0077] return num+4;

[0078] }

[0079] The above code to be compiled is compiled into the following by performing just-in-time (JIT) compilation:

[0080] 0x48,0x89,0xf8, / / mov%rdi,%rax

[0081] 0x48,0x83,0xc0,0x04, / / add$4,%rax

[0082] 0xc3

[0083] It should be noted that the compilation in this application uses just-in-time compilation as an example of various embodiments, but the code compilation method of this application is not limited to being applied to other types of compilation operations.

[0084] Step 202: Obtain the historical compilation code corresponding to the code to be compiled, and the optimization decisions used when compiling the code to be compiled into the historical compilation code.

[0085] Among them, historical compiled code refers to the historical code data generated during the compilation of the code to be compiled, that is, historical compiled code is the historical compilation result of the code to be compiled.

[0086] Among them, optimization decision refers to the relevant optimization processing performed on the code to be compiled during the compilation process. For example, optimization decision can be to process the code to be compiled through some optimization methods, code, or classes to speed up the compilation efficiency and improve the compilation accuracy.

[0087] Optionally, step 202 may also include:

[0088] Obtain optimization information used when compiling the code to be compiled;

[0089] Based on the function type corresponding to the optimization information, optimization information of the same function type is organized into each optimization decision.

[0090] Optionally, the optimization information may include the optimization method of the optimized code, the relocation information of the optimized code, and the class information of the optimization method.

[0091] Please see Figure 5 , Figure 5 This is a schematic diagram of the process for obtaining optimization decisions provided in an embodiment of this application. For example... Figure 5 As shown, when compiling the code to be compiled (501), to ensure the efficiency and accuracy of code compilation, a first round of optimized compilation (502), a second round of optimized compilation (503), ..., the Nth round of optimized compilation (504) will be executed until the just-in-time (JIT) code of the compilation result is obtained. The value of N can be set according to the optimization requirements.

[0092] It is understandable that during the above process of performing optimization compilation on the code to be compiled, the optimization decisions used in each round of optimization compilation can be obtained, and all optimization decisions and their corresponding historical compiled code can be organized and stored in a target location, such as a target database or target disk, so as to facilitate the subsequent retrieval of available historical compiled code and optimization decisions.

[0093] Furthermore, to facilitate efficient invocation of optimization decisions later, optimization decisions can be categorized and stored according to function type. For example, optimization decisions can be classified by function type into ProfiledUn stableIf branch compilation optimization, Profiled Receiver type analysis optimization, Inline analysis optimization, Devirtual virtual function optimization, and other types of optimization.

[0094] Class analysis optimization can be used to determine the class of an object during compile time. If the class is identified as specific, type analysis can then determine the object's class, making type analysis more accurate and allowing other optimizations to make better decisions. Therefore, when making this optimization decision, it is necessary to determine the method in which the optimized code resides, its position within that method, and the type information to be used.

[0095] Inlining analysis optimization can be used to eliminate method call overhead at compile time, compiling the called methods directly along with the code. This optimization determines which method is inlined, therefore it requires obtaining the optimized code's location within the optimized method, its position within that optimized method, and which optimized method was inlined.

[0096] Among these, virtual function optimization can be used to determine which or more virtual functions are being optimized. When a function contains a virtual function call, the compiler information collected during server runtime can be used to determine which subclass implements the method. Therefore, it is necessary to record the method in which the optimized code is located, its position within that method, how many subclasses implement the virtual function, which subclasses they are, and the actions taken if the actual execution does not involve one of these subclasses.

[0097] It should be noted that the content and number of optimization types in this application can be set according to compilation requirements, and this application embodiment does not impose any restrictions.

[0098] As an example, suppose the code to be compiled is conditional code. Conditional compilation is performed on this code. For instance, the code corresponds to a bytecode offset (bci) of 9 in the `Buffer.limit` method. The runtime sampling information of this code shows that its `if` branch follows the `true` branch and not the `false` branch. Therefore, subsequent optimization decisions can be introduced to ensure that only the `true` branch is compiled and the `false` branch is not. Specifically, this can be achieved through the following optimization information:

[0099] ProfiledUnstableIf at method=java / nio / Buffer.limit(I)Ljava / nio / Buffer; bci=9; uncommon trap:untaken edge

[0100] The function type of this optimization information can be ProfiledUnstableIf. The field "ProfiledUnstableIf at method=java / nio / Buffer.limit(I)Ljava / nio / Buffer" is the optimization method; the field "bci=9" is the relocation information of the optimized code, indicating that the bytecode is located at offset 9 in this optimization method; the field "uncommon trap:untaken edge" is the class information of this optimization method, indicating that the optimization decision sets a trap at the false branch, so that when the compilation thread executes the false branch, it triggers the trap and does not compile the false branch, but instead recompiles other branches of the code to be compiled.

[0101] Based on the above examples of optimization decisions, it can be understood that by introducing optimization decisions with optimization information to execute code compilation, the efficiency and accuracy of code compilation can be effectively improved. Therefore, this application embodiment acquires and stores all used optimization decisions during the code compilation process, so that subsequent simulated compilation of the code to be compiled can be performed based on these optimization decisions, selecting the most suitable historical compiled code as the compilation result, thereby improving the efficiency and accuracy of subsequent code compilation.

[0102] Optionally, step 202 may also include the following steps:

[0103] Search the target list to see if there is any historical compiled code corresponding to the code to be compiled.

[0104] If it exists, then the optimization decision corresponding to the historical compiled code is further obtained;

[0105] If it does not exist, skip the operation of obtaining the historical compiled code and the optimization decision, and directly compile the code to be compiled.

[0106] The target list can be a list of files storing historical compiled code. It can be understood that the historical compiled code in this application is equivalent to cached data. After determining the available historical compiled code based on the context of the code to be compiled, the historical compiled code can be loaded as a cache item for the target computer device in a manner similar to cache data loading, thereby improving code compilation efficiency.

[0107] Therefore, if there is no available historical compiled code in the target list or target storage space, the operation of obtaining historical compiled code and optimization decision can be skipped, and the code to be compiled can be compiled directly to avoid compilation interruption or termination due to the inability to obtain historical compiled code, thereby improving code compilation efficiency.

[0108] Step 203: Compile the code to be compiled according to each optimization decision to obtain the current compiled code corresponding to each optimization decision.

[0109] In conjunction with the context information of the code to be compiled, a single piece of code may correspond to multiple historical compiled codes under the same list. As an example, let's say we have a piece of code S to be compiled. To ensure the accuracy of compiling code S, we need to consider its context information during the compilation process. Let's assume that code S is:

[0110] int A = 10;

[0111] int B = 5;

[0112] if (A > B)

[0113] {

[0114] System.out.println(“A is greater than B”);

[0115] }

[0116] Accordingly, the complete code Q after obtaining the context information of the code segment to be compiled is:

[0117] int A = 10;

[0118] int B = 5;

[0119] if (A > B)

[0120] {

[0121] System.out.println(“A is greater than B”);

[0122] }

[0123] else

[0124] {

[0125] System.out.println(“A is less than B”);

[0126] }

[0127] It's understandable that, taking the conditional code example above, since the compiled code executable by computer devices is not limited to one implementation, to ensure the accuracy of compiling code S, it's necessary to consider not only the if statements in code S but also the else statements in the complete code Q to effectively guarantee the accuracy of the translation of code S. It's also understandable that, after obtaining historical compiled code and corresponding optimization decisions, the most suitable historical compiled code needs to be selected from multiple candidate historical compiled codes as the final compilation result, in order to balance code compilation efficiency and accuracy.

[0128] Optionally, step 203 may also include the following steps:

[0129] The code to be compiled is subjected to multiple rounds of simulated compilation, and the optimization decision is executed once for the code to be compiled in each round of simulated compilation;

[0130] Obtain the compilation results generated in each round of simulated compilation, and use the compilation results as the current compiled code.

[0131] It is understood that, in order to select the most suitable historical compilation code, the embodiments of this application provide a selection logic. The code to be compiled can first be simulated by performing optimization decisions, and then the results of the simulation compilation can be used to determine whether there is the most suitable historical compilation code. If there is, the most suitable historical compilation code can be selected from multiple historical compilation codes as the compilation result.

[0132] Step 204: Determine the optimal optimization decision from the optimization decisions based on the current compiled code.

[0133] Optionally, step 204 may also include the following steps:

[0134] Obtain a score for each of the currently compiled code snippets;

[0135] Based on the score of the currently compiled code, the optimal optimization decision is determined from the optimization decisions.

[0136] It is understandable that since the current compiled code is obtained after the optimization decisions are made on the code to be compiled, a comprehensive score of the efficiency and accuracy of the current compiled code is equivalent to a score of the merits of the optimization decisions.

[0137] Optionally, the step "obtain a score for each of the currently compiled codes" may include:

[0138] Obtain a first score for the currently compiled code. The first score is used to characterize whether the optimization decision improves the performance of the compilation thread when the compilation thread compiles the code to be compiled using each optimization decision.

[0139] The first scores are summed to obtain a second score. If the second score is greater than a preset threshold, the first optimization decision corresponding to the multiple first scores is recorded.

[0140] Optionally, a first-order score can be used to detect whether the optimization decision improves the compilation performance of the compilation thread. Continuing with the example of optimizing code execution branches, if the object of the branch optimization differs from the object to be compiled, it indicates that the optimization decision has not improved the current compilation performance, or is considered a performance regression. For example, if we want to compile the true branch in an if conditional function, but the current branch optimization target is the false branch, forcibly using this optimization decision for code compilation, or forcibly using the corresponding historical compiled code as the compilation result for the computer to execute, will inevitably lead to execution errors, requiring the uncompiled code to be recompiled, thus resulting in a performance regression that reduces compilation efficiency and accuracy.

[0141] As shown in the example above, during the simulated compilation of the code to be compiled, a first score can be set to detect whether the available optimization decisions are truly applicable to the current code to be compiled. Optionally, the first score for optimization decisions that bring performance improvements to the compilation thread can be set to 1, and the first score for optimization decisions that do not bring performance improvements to the compilation thread can be set to -1.

[0142] Furthermore, after performing multiple rounds of simulated compilation on the code to be compiled, a second score can be obtained by accumulating the first score. Whether the overall compilation performance has improved after multiple rounds of optimization can be detected by judging whether the second score is greater than a preset threshold. Specifically, if the first score is set to 1 or -1, the preset threshold can be set to 0, so that if the second score is greater than 0, it indicates that the overall compilation performance has improved; if the second score is less than 0, it indicates that the overall compilation performance has not improved; and if the second score is equal to 0, it indicates that the overall compilation performance has not changed. It can be understood that, to facilitate the subsequent selection of the optimal optimization decision and the most suitable historical compilation code, the first optimization decision after the second score is greater than the preset threshold can be recorded first. Optionally, during the recording process, optimization decisions with a first score of -1 can also be directly deleted to improve the flexibility and efficiency of recording.

[0143] It should be noted that this application does not limit the size of the first score and the preset threshold.

[0144] Optionally, the step "determining the optimal optimization decision from the optimization decisions based on the score of the current compiled code" may include:

[0145] If the second score is greater than the preset threshold, then a third score is obtained for each of the first optimization decisions, and the third score is used to characterize the performance improvement of the first optimization decision on the compilation thread;

[0146] The first optimization decision with the highest third score is selected as the optimal optimization decision.

[0147] It is understandable that since the first and second scores are only used to characterize optimization decisions, after obtaining at least one first optimization decision that brings performance improvement to the compilation thread, a third score can be set to evaluate the degree of improvement of the first optimization decision on compilation performance.

[0148] In some embodiments, the magnitude of the third score can be proportional to the degree of improvement in compilation performance. The third score can be represented numerically; for example, a first optimization decision with a third score of 100 is better than a first optimization decision with a third score of 80. Accordingly, after obtaining the third scores of all first optimization decisions, the first optimization decision with the highest third score can be selected as the optimal optimization decision, so that the most suitable historical compiled code for use as the compilation result can be determined subsequently through the optimal optimization decision.

[0149] Optionally, the method in this application embodiment may further include:

[0150] Obtain the second score corresponding to all the currently compiled code;

[0151] If all of the second scores are less than or equal to the preset threshold, then skip the operation of obtaining the first optimization decision and directly compile the code to be compiled.

[0152] It is understandable that the second score is used to characterize the cumulative sum generated by the simulated compilation of the code to be compiled through a series of optimization decisions. Different historical compiled code corresponds to different optimization decisions. If all second scores are less than a preset threshold, it means that all multi-round simulated compilation has degraded compilation performance, and it is not suitable to use the historical compiled code as the compilation result for execution on the computer device. Therefore, the operation of loading the historical compiled code as the compilation result can be skipped. For the specific process described above, please refer to [link to relevant documentation]. Figure 6 .

[0153] Please see Figure 6 , Figure 6 This is a schematic diagram illustrating the process of compiling code to be compiled, as provided in an embodiment of this application. Figure 6 As shown, compiling the code to be compiled in this embodiment may include the following steps:

[0154] Step 601: Compile the code to be compiled.

[0155] Step 602: Obtain historical compiled code. If historical compiled code exists, proceed to step 603; otherwise, proceed to step 610.

[0156] Step 603: Simulate and compile the code to be compiled based on the optimization decision.

[0157] Step 604: Does the compilation performance need to be rolled back? If yes, proceed to step 603; otherwise, proceed to step 605.

[0158] Step 605: Calculate the improvement in compilation performance.

[0159] Step 606: Traverse all optimization decisions.

[0160] Step 607: Are there any other optimization decisions? If yes, proceed to step 606; otherwise, proceed to step 608.

[0161] Step 608: Are there any other historical compiled codes? If yes, proceed to step 603; otherwise, proceed to step 609.

[0162] Step 609: Obtain the corresponding historical compiled code.

[0163] Step 610: Directly execute the operation of compiling the code to be compiled.

[0164] according to Figure 6 As can be seen from the flowchart and specific steps, during the simulated compilation process of the code to be compiled, all available optimization strategies are traversed and the corresponding simulated compilation scores are calculated before selecting the final suitable historical compilation code. Compared to the cumbersome operations of matching function lists and function values ​​with historical compilation code in existing technologies, compiling a piece of code using existing methods takes approximately 100 milliseconds, while the method of the present application can compile a piece of code of the same length in approximately 1 millisecond, thereby significantly improving the efficiency of code compilation.

[0165] Step 205: Determine the historical compiled code corresponding to the optimal optimization decision as the compilation result of the code to be compiled.

[0166] Optionally, step 205 may also include the following steps:

[0167] The first loading logic of the compilation process is obtained, wherein the compilation thread is a thread used to compile the code to be compiled;

[0168] A second loading logic is added to the first loading logic, and the second loading logic is used to load the historical edit code corresponding to the compilation result.

[0169] Optionally, after step 205, the embodiments of this application may further include the following steps:

[0170] Obtain the first historical compiled code, which contains a storage space for storing the corresponding optimal optimization decision;

[0171] Obtain the mapping relationship between the first historical code and the code to be compiled;

[0172] Store the first historical code and the mapping relationship to the target location.

[0173] Please see Figure 4 , Figure 4 This is a schematic diagram illustrating the storage and loading of historical compiled code as provided in an embodiment of this application. Figure 4As shown, this embodiment of the application can save the historical compilation code and optimization decisions of the last compilation operation of the computing device 401. During the saving process, the optimization decisions used in each round of compilation are recorded, and at the end of the compilation process, all historical compilation code and their corresponding optimization decisions are written together into a file and stored in the historical data storage terminal 403. When the computing device 402 performs compilation subsequently, the computing device 402 loads the generated file upon startup and retrieves the multiple historical compilation codes corresponding to that file from the historical data storage terminal 403. By simulating the compilation operation, the most suitable historical compilation code for the current execution is found and restored in the form of cached data, thereby reducing compilation overhead and improving the execution performance of the current compilation process.

[0174] As can be seen from the above, when compiling code, the embodiments of this application can first obtain the historical compiled code and the optimization decisions corresponding to the historical compiled code. The compilation of the code to be compiled is simulated by the optimization decisions, and the most suitable historical compiled code is selected as the compilation result. This can save the tedious process of matching available code from historical cache data, thereby significantly improving the efficiency of code compilation and reducing compilation overhead. Furthermore, in the future, only the historical compiled code and the corresponding optimization decisions need to be stored as historical cache data, which reduces the data storage pressure.

[0175] The method described in the above embodiments will be further described in detail below.

[0176] In this embodiment, data synchronization will be used as an example to describe the method of this application embodiment in detail.

[0177] like Figure 3 As shown, the specific process of a code compilation method is as follows:

[0178] Step 301: Obtain the code to be compiled.

[0179] Step 302: Obtain the optimization information used when compiling the code to be compiled.

[0180] Optionally, the optimization method of the optimized code, the relocation information of the optimized code, and the class information of the optimization method can be obtained.

[0181] Step 303: Based on the function type corresponding to the optimization information, organize the optimization information of the same function type into each optimization decision.

[0182] Optionally, optimization decisions can be categorized by function type into ProfiledUnstableIf branch compilation optimization, Profiled Receiver type analysis optimization, Inline analysis optimization, Devirtual function optimization, and other class optimizations.

[0183] Step 304: Perform multiple rounds of simulated compilation on the code to be compiled, and execute the optimization decision once on the code to be compiled in each round of simulated compilation.

[0184] Specifically, the merits of optimization decisions can be judged by simulating compilation, so that the optimal optimization decision and historical compiled code applicable to the code to be compiled can be determined in the future.

[0185] Step 305: Obtain the compilation results generated in each round of simulated compilation, and use the compilation results as the current compiled code.

[0186] Specifically, to facilitate comparison of the merits of each optimization decision, we can first obtain the current compiled code generated under the optimization decision, determine whether the current compiled code is suitable for the computer device to execute the compilation result accurately, and thus evaluate the merits of each optimization decision.

[0187] Step 306: Obtain the score for each of the currently compiled codes.

[0188] Specifically, a first score can be obtained to characterize when the compilation thread compiles the code to be compiled using each of the optimization decisions, a second score obtained by accumulating multiple first scores, and a third score to characterize the performance improvement of the compilation thread by the first optimization decision, so as to comprehensively evaluate the merits of the current compiled code and the corresponding optimization decision and select the optimal optimization decision.

[0189] Step 307: Determine the optimal optimization decision from the optimization decisions based on the score of the current compiled code.

[0190] Step 308: Determine the historical compiled code corresponding to the optimal optimization decision as the compilation result of the code to be compiled.

[0191] Therefore, it can be seen that when compiling code, the embodiments of this application can first obtain the historical compiled code and the optimization decisions corresponding to the historical compiled code. The compilation of the code to be compiled is simulated by the optimization decisions, and the most suitable historical compiled code is selected as the compilation result. This can save the tedious process of matching available code from historical cache data, thereby significantly improving the efficiency of code compilation and reducing compilation overhead. Furthermore, in the future, only the historical compiled code and the corresponding optimization decisions need to be stored as historical cache data, which reduces the data storage pressure.

[0192] To better implement the above methods, embodiments of this application also provide a code compilation device that can be integrated into a terminal or server.

[0193] For example, such as Figure 7The diagram shown is a structural schematic of a code compilation device provided in an embodiment of this application. The device may include a code acquisition module 701, a historical data acquisition module 702, a current code determination module 703, an optimal optimization decision determination module 704, and a compilation result determination module 705, as detailed below:

[0194] Module 701, which is used to acquire code to be compiled;

[0195] The historical data acquisition module 702 is used to acquire the historical compilation code corresponding to the code to be compiled, and the optimization decisions used when compiling the code to be compiled into the historical compilation code;

[0196] The current compilation code determination module 703 is used to compile the code to be compiled according to each optimization decision to obtain the current compilation code corresponding to each optimization decision;

[0197] The optimal optimization decision determination module 704 is used to determine the optimal optimization decision from the optimization decisions based on the currently compiled code;

[0198] The compilation result determination module 705 is used to determine the historical compilation code corresponding to the optimal optimization decision as the compilation result of the code to be compiled.

[0199] Optionally, the current compiled code determination module 703 further includes:

[0200] The simulation compilation submodule is used to perform multiple rounds of simulation compilation on the code to be compiled, and to execute the optimization decision on the code to be compiled once in each round of simulation compilation;

[0201] The compilation result acquisition submodule is used to acquire the compilation results generated in each round of simulated compilation and use the compilation results as the current compiled code.

[0202] Optionally, the optimal optimization decision determination module 704 further includes:

[0203] The scoring submodule is used to obtain a score for each of the currently compiled codes;

[0204] The optimal optimization decision acquisition submodule is used to determine the optimal optimization decision from the optimization decisions based on the score of the currently compiled code.

[0205] Optionally, the scoring submodule further includes:

[0206] The first score acquisition submodule is used to acquire the first score of the currently compiled code. The first score is used to characterize whether the optimization decision improves the performance of the compilation thread when the compilation thread compiles the code to be compiled using each optimization decision.

[0207] The second score acquisition submodule is used to accumulate multiple first scores to obtain a second score. If the second score is greater than a preset threshold, the first optimization decision corresponding to the multiple first scores is recorded.

[0208] Optionally, the optimal decision acquisition submodule is further specifically used for:

[0209] If the second score is greater than the preset threshold, then a third score is obtained for each of the first optimization decisions, and the third score is used to characterize the performance improvement of the first optimization decision on the compilation thread;

[0210] The first optimization decision with the highest third score is selected as the optimal optimization decision.

[0211] Optionally, the code compilation apparatus may further include:

[0212] The global score acquisition module is used to obtain the second score corresponding to all the currently compiled code.

[0213] The scoring and judgment module is used to skip the operation of obtaining the first optimization decision and directly compile the code to be compiled if all the second scores are less than or equal to the preset threshold.

[0214] Optionally, the compilation result determination module 705 is specifically used for:

[0215] The first loading logic of the compilation process is obtained, wherein the compilation thread is a thread used to compile the code to be compiled;

[0216] A second loading logic is added to the first loading logic, and the second loading logic is used to load the historical edit code corresponding to the compilation result.

[0217] Optionally, the code compilation apparatus may further include:

[0218] The first historical compiled code acquisition module is used to acquire the first historical compiled code, which is provided with a storage space for storing the corresponding optimal optimization decision;

[0219] A mapping relationship acquisition module is used to acquire the mapping relationship between the first historical code and the code to be compiled;

[0220] A storage module is used to store the first historical code and the mapping relationship to the target location.

[0221] Optionally, the historical data acquisition module 702 is specifically used for:

[0222] Search the target list to see if there is any historical compiled code corresponding to the code to be compiled.

[0223] If it exists, then the optimization decision corresponding to the historical compiled code is further obtained;

[0224] If it does not exist, skip the operation of obtaining the historical compiled code and the optimization decision, and directly compile the code to be compiled.

[0225] Optionally, the historical data acquisition module 702 is specifically used for:

[0226] Obtain optimization information used when compiling the code to be compiled;

[0227] Based on the function type corresponding to the optimization information, optimization information of the same function type is organized into each optimization decision.

[0228] Optionally, the optimization information includes the optimization method of the optimized code, the relocation information of the optimized code, and the class information of the optimization method.

[0229] In practice, the above modules can be implemented as independent entities or combined in any way to be implemented as the same or several entities. For the specific implementation of the above modules, please refer to the previous method implementation examples, which will not be repeated here.

[0230] As described above, the code compilation apparatus provided in this application embodiment acquires the code to be compiled through a code acquisition module 701; a historical data acquisition module 702 acquires the historical compilation code corresponding to the code to be compiled, and the optimization decisions used when compiling the code to be compiled into the historical compilation code; a current compilation code determination module 703 compiles the code to be compiled according to each optimization decision to obtain the current compilation code corresponding to each optimization decision; an optimal optimization decision determination module 704 determines the optimal optimization decision from the optimization decisions based on the current compilation code; and a compilation result determination module 705 determines the historical compilation code corresponding to the optimal optimization decision as the compilation result of the code to be compiled.

[0231] Therefore, in the embodiments of this application, when compiling code, the historical compiled code and the optimization decisions corresponding to the historical compiled code can be obtained first. The code to be compiled is simulated by the optimization decisions, and the most suitable historical compiled code is selected as the compilation result. This can save the tedious process of matching available code from historical cache data, thereby significantly improving the efficiency of code compilation and reducing compilation overhead. Furthermore, in the future, only the historical compiled code and the corresponding optimization decisions need to be stored as historical cache data, which reduces the data storage pressure.

[0232] This application also provides an electronic device, which can be a terminal, server, or other similar device. Figure 8 As shown, it illustrates a structural schematic diagram of the electronic device involved in the embodiments of this application, specifically:

[0233] The electronic device may include components such as a processor 801 with one or more processing cores, a memory 802 with one or more computer-readable storage media, a power supply 803, an input module 804, and a communication module 805. Those skilled in the art will understand that... Figure 8 The electronic device structure shown does not constitute a limitation on the electronic device and may include more or fewer components than shown, or combine certain components, or have different component arrangements. Wherein:

[0234] The processor 801 is the control center of the electronic device, connecting various parts of the device via various interfaces and lines. It performs various functions and processes data by running or executing software programs and / or modules stored in the memory 802, and by calling data stored in the memory 802. In some embodiments, the processor 801 may include one or more processing cores; in some embodiments, the processor 801 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may also not be integrated into the processor 801.

[0235] The memory 802 can be used to store software programs and modules. The processor 801 executes various functional applications and data processing by running the software programs and modules stored in the memory 802. The memory 802 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 802 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory 802 may also include a memory controller to provide the processor 801 with access to the memory 802.

[0236] The electronic device also includes a power supply 803 that supplies power to the various components. In some embodiments, the power supply 803 can be logically connected to the processor 801 through a power management system, thereby enabling functions such as managing charging, discharging, and power consumption through the power management system. The power supply 803 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.

[0237] The electronic device may also include an input module 804, which can be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.

[0238] The electronic device may also include a communication module 805. In some embodiments, the communication module 805 may include a wireless module, through which the electronic device can perform short-range wireless transmission, thereby providing users with wireless broadband internet access. For example, the communication module 805 can be used to help users send and receive emails, browse web pages, and access streaming media.

[0239] Although not shown, the electronic device may also include a display module, etc., which will not be described in detail here. Specifically, in this embodiment, the processor 801 in the electronic device loads the executable files corresponding to the processes of one or more application programs into the memory 802 according to the following instructions, and the processor 801 runs the application programs stored in the memory 802 to realize various functions, as follows:

[0240] Receive a data synchronization request from the server, the data synchronization request being used to request data to be synchronized;

[0241] According to the data synchronization request, obtain the configuration information of the data to be synchronized, the configuration information including the data type of the data to be synchronized;

[0242] Data synchronization is performed according to the synchronization process corresponding to the configuration information. The synchronization process is used to synchronize the data to be synchronized of different data types to the server and to manage the data to be synchronized of different data types.

[0243] In some embodiments, a computer program product is also provided, comprising a computer program or instructions that, when executed by a processor, implement the steps in any of the above-described code compilation methods.

[0244] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.

[0245] As can be seen from the above, when compiling code, the embodiments of this application can first obtain the historical compiled code and the optimization decisions corresponding to the historical compiled code. The compilation of the code to be compiled is simulated by the optimization decisions, and the most suitable historical compiled code is selected as the compilation result. This can save the tedious process of matching available code from historical cache data, thereby significantly improving the efficiency of code compilation and reducing compilation overhead. Furthermore, in the future, only the historical compiled code and the corresponding optimization decisions need to be stored as historical cache data, which reduces the data storage pressure.

[0246] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.

[0247] Therefore, embodiments of this application provide a computer-readable storage medium storing a plurality of instructions that can be loaded by a processor to execute steps in any of the code compilation methods provided in embodiments of this application. For example, the instructions can execute the following steps:

[0248] Receive a data synchronization request from the server, the data synchronization request being used to request data to be synchronized;

[0249] According to the data synchronization request, obtain the configuration information of the data to be synchronized, the configuration information including the data type of the data to be synchronized;

[0250] Data synchronization is performed according to the synchronization process corresponding to the configuration information. The synchronization process is used to synchronize the data to be synchronized of different data types to the server and to manage the data to be synchronized of different data types.

[0251] The storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.

[0252] According to one aspect of this application, a computer program product is provided, which includes a computer program or instructions that, when executed by a processor, implement the steps in the code compilation method described above.

[0253] Therefore, it can be seen that when compiling code, the embodiments of this application can first obtain the historical compiled code and the optimization decisions corresponding to the historical compiled code. The compilation of the code to be compiled is simulated by the optimization decisions, and the most suitable historical compiled code is selected as the compilation result. This can save the tedious process of matching available code from historical cache data, thereby significantly improving the efficiency of code compilation and reducing compilation overhead. Furthermore, in the future, only the historical compiled code and the corresponding optimization decisions need to be stored as historical cache data, which reduces the data storage pressure.

[0254] Since the instructions stored in the storage medium can execute the steps of any of the code compilation methods provided in the embodiments of this application, the beneficial effects that any of the code compilation methods provided in the embodiments of this application can achieve can be realized. For details, please refer to the previous embodiments, which will not be repeated here.

[0255] The foregoing has provided a detailed description of a code compilation method, apparatus, electronic device, and computer-readable storage medium provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A code compiling method characterized by, The method includes: Obtain the code to be compiled; Obtain the historical compiled code corresponding to the code to be compiled, and the optimization decisions made when compiling the code to be compiled into the historical compiled code; Based on each optimization decision, the code to be compiled is simulated to obtain the current compiled code corresponding to each optimization decision; Based on the current compiled code, determining the optimal optimization decision from the optimization decisions includes: obtaining a first score for the current compiled code, the first score being used to characterize whether the optimization decision improves the performance of the compilation thread when the compilation thread compiles the code to be compiled using each of the optimization decisions; accumulating multiple first scores to obtain a second score; if the second score is greater than a preset threshold, recording the first optimization decisions corresponding to multiple first scores; if the second score is greater than the preset threshold, obtaining a third score for each first optimization decision, the third score being used to characterize the degree of performance improvement of the compilation thread by the first optimization decision; and obtaining the first optimization decision with the highest third score as the optimal optimization decision. The historical compiled code corresponding to the optimal optimization decision is determined as the compilation result of the code to be compiled.

2. The code compiling method of claim 1, wherein, The step of simulating the compilation of the code to be compiled based on each optimization decision includes: The code to be compiled is subjected to multiple rounds of simulated compilation, and the optimization decision is executed once for the code to be compiled in each round of simulated compilation; Obtain the compilation results generated in each round of the simulated compilation, and use the compilation results as the current compiled code.

3. The code compiling method of claim 1, wherein, The method further includes: Obtain the second score corresponding to all the currently compiled code; If all of the second scores are less than or equal to the preset threshold, then skip the operation of obtaining the first optimization decision and directly compile the code to be compiled.

4. The code compiling method of claim 1, wherein, The step of obtaining the historical compilation code corresponding to the code to be compiled includes: Search the target list to see if there is any historical compiled code corresponding to the code to be compiled. If it exists, then the optimization decision corresponding to the historical compiled code is further obtained; If it does not exist, skip the operation of obtaining the historical compiled code and the optimization decision, and directly compile the code to be compiled.

5. The code compiling method of claim 1, wherein, The optimization decisions adopted when compiling the code to be compiled into the historical compiled code include: Obtain optimization information used when compiling the code to be compiled; Based on the function type corresponding to the optimization information, optimization information of the same function type is organized into each optimization decision.

6. The code compiling method of claim 5, wherein, The optimization information includes the optimization method of the optimized code, the relocation information of the optimized code, and the class information of the optimization method.

7. A code compiling apparatus characterized by comprising: The device includes: The module for obtaining code to be compiled is used to obtain the code to be compiled. The historical data acquisition module is used to acquire the historical compilation code corresponding to the code to be compiled, as well as the optimization decisions made when compiling the code to be compiled into the historical compilation code; The current compilation code determination module is used to simulate the compilation of the code to be compiled based on each optimization decision to obtain the current compilation code corresponding to each optimization decision; The optimal optimization decision determination module is used to determine the optimal optimization decision from the optimization decisions based on the current compiled code, including: obtaining a first score of the current compiled code, the first score being used to characterize whether the optimization decision improves the performance of the compilation thread when the compilation thread compiles the code to be compiled using each of the optimization decisions; accumulating multiple first scores to obtain a second score; if the second score is greater than a preset threshold, recording the first optimization decisions corresponding to the multiple first scores; if the second score is greater than the preset threshold, obtaining a third score for each first optimization decision, the third score being used to characterize the degree of performance improvement of the compilation thread by the first optimization decision; and obtaining the first optimization decision with the highest third score as the optimal optimization decision. The compilation result determination module is used to determine the historical compilation code corresponding to the optimal optimization decision as the compilation result of the code to be compiled.

8. The code compiling apparatus according to claim 7, wherein The current compiled code determination module also includes: The simulation compilation submodule is used to perform multiple rounds of simulation compilation on the code to be compiled, and to execute the optimization decision on the code to be compiled once in each round of simulation compilation; The compilation result acquisition submodule is used to acquire the compilation results generated in each round of the simulated compilation and use the compilation results as the current compiled code.

9. The code compilation apparatus according to claim 7, characterized in that, The code compilation device further includes: The global score acquisition module is used to obtain the second score corresponding to all the currently compiled code. The scoring and judgment module is used to skip the operation of obtaining the first optimization decision and directly compile the code to be compiled if all the second scores are less than or equal to the preset threshold.

10. The code compiling apparatus according to claim 7, wherein The historical data acquisition module is specifically used for: Search the target list to see if there is any historical compiled code corresponding to the code to be compiled. If it exists, then the optimization decision corresponding to the historical compiled code is further obtained; If it does not exist, skip the operation of obtaining the historical compiled code and the optimization decision, and directly compile the code to be compiled.

11. The code compiling apparatus according to claim 7, wherein The historical data acquisition module is specifically used for: Obtain optimization information used when compiling the code to be compiled; Based on the function type corresponding to the optimization information, optimization information of the same function type is organized into each optimization decision.

12. The code compiling apparatus according to claim 11, wherein The optimization information includes the optimization method of the optimized code, the relocation information of the optimized code, and the class information of the optimization method.

13. An electronic device, comprising: It includes a processor and a memory, the memory storing multiple instructions; the processor loads instructions from the memory to perform the steps in the code compilation method as described in any one of claims 1 to 6.

14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a plurality of instructions adapted for loading by a processor to perform the steps of the code compilation method according to any one of claims 1 to 6.

15. A computer program product comprising computer programs or instructions, characterized in that, The computer program or instructions, when executed by a processor, implement the steps of the code compiling method of any one of claims 1-6.