Compiling method, compiler, electronic equipment, storage medium and program product

By obtaining the estimated runtime of the loop and the average execution time of other business threads, the safepoint insertion position is adjusted, which solves the efficiency problem caused by inserting safepoints at fixed positions in the loop and enables the compiler to run efficiently.

CN121523652APending Publication Date: 2026-02-13LOONGSON TECH CORP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511458599.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-10-13
Publication Date
2026-02-13

AI Technical Summary

Technical Problem

Existing compilers insert safety points at fixed positions in loops, leading to differences in execution speed between different loops. This affects the execution efficiency of other business threads and reduces the overall efficiency of the compiler.

Method used

By obtaining the estimated runtime of the compiled machine instructions of the loop and the average time taken for other business threads to enter the nearest safe point, the insertion position of the safe point is adjusted to ensure that the business thread containing the loop executes to the safe point as soon as possible, while reducing the impact on other business threads.

Benefits of technology

It improves the compiler's execution efficiency, ensuring that the business thread containing the loop quickly enters the safe point without affecting the operation of other business threads, thus improving the overall compilation efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121523652A_ABST
    Figure CN121523652A_ABST
Patent Text Reader

Abstract

The invention discloses a compiling method, a compiler, electronic equipment, a storage medium and a program product, and relates to the technical field of compilers. The method comprises the following steps of: obtaining an estimated running time length of a machine instruction which is cyclically compiled; obtaining the average time consumption of other business threads in the compiler for respectively entering the nearby security points; and based on the estimated operation duration and the average time consumption, the safety points are circularly adjusted. In the application, the pre-estimated running duration of the machine instruction compiled by one cycle fully reflects the execution efficiency of the instruction sequence in the cycle and the average time consumption of other service threads in the compiler respectively entering the nearby security points, and can fully reflect the speed of other service threads running approximately at the same time with the cycle entering the nearby security points; the security point is set for the loop, so that the service thread where the loop is located is executed to the security point as soon as possible, and other service threads are basically not affected.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of compiler technology, and in particular to a compilation method and compiler, an electronic device, a storage medium, and a computer program product. Background Technology

[0002] The compiler needs to perform specific operations during the STW (Stop-The-World) phase, such as garbage collection (Clean Dead Objects), deoptimization, or wake-up biased locking. The compiler only begins execution when all business threads have reached their nearest safepoint and entered a sleep state. However, since each business thread uses a different method, the speed at which it reaches a safepoint varies.

[0003] To ensure that each business thread reaches its nearest safe point in the shortest possible time without affecting the execution efficiency of other business threads, safe points are often inserted at fixed positions in the loop during the compilation process.

[0004] However, the execution speed of different instruction sequences within a loop varies. Currently, inserting safepoints at fixed positions within a loop often results in longer execution times for some slower business threads within the loop to enter the safepoint. Other business threads need to wait for these slower threads, affecting their execution and thus reducing the compiler's execution efficiency. Summary of the Invention

[0005] In view of the above problems, embodiments of this application are proposed to provide a compilation method that overcomes or at least partially solves the above problems, thereby facilitating the operation of other business threads.

[0006] Firstly, this application provides a compilation method, the method comprising: Get the estimated runtime of the loop after the compiled machine instructions; Obtain the average time taken for other business threads in the compiler to enter the nearest safe point; the other business threads are business threads running on the compiler at the current moment other than the business thread in which the loop is located; at least one of the other business threads has entered a safe point before the current moment; Based on the estimated runtime and the average time consumed, the safety points are adjusted cyclically.

[0007] Secondly, this application provides a compiler, including: The estimated runtime acquisition module is used to obtain the estimated runtime of the compiled machine instructions for loops; The average time consumption acquisition module is used to acquire the average time consumed by other business threads in the compiler to enter the nearest safe point; the other business threads are business threads running on the compiler at the current moment other than the business thread in which the loop is located; at least one of the other business threads has entered a safe point before the current moment; The safety point setting module is used to adjust the safety points of the loop based on the estimated runtime and the average time consumption, thereby compiling the safety points of the loop.

[0008] Thirdly, this application provides an electronic device, including: a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-described compilation method when executing the program.

[0009] Fourthly, this application provides a readable storage medium that, when the instructions in the storage medium are executed by the processor of an electronic device, enables the electronic device to execute the above-described compilation method.

[0010] Fifthly, this application provides a computer program product, comprising: a computer program, which, when executed by a processor, implements the steps of the above-described compilation method.

[0011] This application has the following advantages.

[0012] In this application, the estimated runtime of the compiled machine instructions for the loop reflects, to some extent, the actual runtime of the compiled machine instructions for the loop, and also fully reflects the execution efficiency of the instruction sequence within the loop. Correspondingly, the average time taken for other business threads in the compiler to enter the nearest safe point fully reflects how quickly other business threads running roughly simultaneously with the loop enter the nearest safe point. Based on this estimated runtime and the average time taken for other business threads in the compiler to enter the nearest safe point, the safe points are adjusted accordingly. This considers not only the execution efficiency of the loop itself, but also the speed at which other business threads running roughly simultaneously with the loop enter the nearest safe point. The resulting safe points are relatively accurate, ensuring that the business thread containing the loop executes to the safe point as quickly as possible, with minimal impact on other business threads, thereby improving the compiler's execution efficiency.

[0013] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description

[0014] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which: Figure 1 A flowchart illustrating the steps of one embodiment of the compilation method of this application is shown; Figure 2 This shows the time taken for the business thread of this application to most recently enter the nearest safe point; Figure 3 A flowchart illustrating the steps of another embodiment of the compilation method of this application is shown; Figure 4 A structural block diagram of one embodiment of the compiler of this application is shown; Figure 5 This is a structural diagram of an electronic device provided in an embodiment of this application. Detailed Implementation

[0015] The embodiments of this application will now be described in detail. Examples of these embodiments are illustrated in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain this application, and should not be construed as limiting this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.

[0016] The terms "first" and "second" in the specification and claims of this application may explicitly or implicitly include one or more of the features. In the description of this application, unless otherwise stated, "multiple" means two or more. Furthermore, "and / or" in the specification and claims indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.

[0017] In the description of this application, it should be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "upper", "lower", "front", "rear", "left", "right", "vertical", "horizontal", "top", "bottom", "inner", "outer", "clockwise", "counterclockwise", "axial", "radial", "circumferential", etc., indicating the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings, are only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of this application.

[0018] In the description of this application, it should be noted that, unless otherwise expressly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection between two components. Those skilled in the art can understand the specific meaning of the above terms in this application based on the specific circumstances.

[0019] One of the functions of a compiler is to translate a programming language into executable object code. The programming language here can refer to source code, and the specific type of compiler is not limited; for example, a compiler can be a dynamic compiler or a virtual machine. A dynamic compiler enables just-in-time (JIT) compilation, meaning it dynamically compiles the source code into executable object code at runtime. A virtual machine is a complete computer system simulated by software, possessing full hardware system functionality and running in a completely isolated environment; any task that can be performed on a physical computer can also be performed in the compiler. A safe point is a specific location during the execution of source code or object code where the state of the business thread is known and consistent, and can be safely manipulated by the virtual machine or compiler.

[0020] In related technologies, the compiler often generates safepoints at fixed positions within loops. Specifically, this involves directly splitting the loop into an inner loop and an outer loop, setting the iteration count of the inner loop to the same fixed number for each loop, and inserting a safepoint at the end of each inner loop iteration. However, the execution efficiency of the instruction sequence within different loops directly affects the time taken to enter the safepoint. These technologies may result in longer loop entry times, impacting the execution of other business threads in the compiler and thus reducing compiler efficiency. Other business threads refer to at least one business thread running on the compiler other than the business thread containing the loop at the current moment when the compiler needs to adjust the loop's safepoint. At the current moment when the compiler needs to adjust the loop's safepoint, the number of other business threads is less than or equal to the total number of all other business threads running on the compiler besides the business thread containing the loop. These other business threads may or may not include loops, both falling within the scope of this application.

[0021] For example, the following is an example of a loop counting.

[0022] for (i = 0; i<10000; i++) { / / do something; } Safepoint instruction; In this example, the loop iterates a total of 10,000 times. After each iteration, it enters a safepoint instruction and performs specific operations such as garbage collection at the safepoint.

[0023] In this example, in related technologies, if it is stipulated that the iteration count of the split inner loop is set to 1000 for different loops, and a safety point is adjusted or inserted at the end of each inner loop, then the above loop count is converted into the following loop.

[0024] for (i = 0; i<10; i++) { for (j = 0; j<1000; j++) { / / do something; } Safepoint instruction; } The safepoint instruction in the transformed loop above sets or inserts a safepoint, which controls specific operations such as garbage collection within the inner loop. In the transformed loop, the inner loop iterates 1000 times, and the outer loop iterates 10 times. A safepoint is inserted at the end of each inner loop iteration, so the loop enters the safepoint after each iteration. However, entering a safepoint in the transformed loop may take a long time, potentially affecting other business threads.

[0025] To address the aforementioned technical issues, a core concept of this application is that, during the insertion of a safe point within a loop, not only is the execution efficiency of the loop itself considered, but also the speed at which other business threads running roughly simultaneously with the loop enter the nearest safe point. This ensures that the safe point of the loop corresponds to the minimum STW (Stop-The-World) time for each business process, allowing the business thread containing the loop to reach the safe point as quickly as possible without significantly impacting other business threads. This reduces the time other business threads spend entering STW due to the slow execution of the business thread containing the loop to the safe point, thereby improving the compiler's compilation efficiency.

[0026] Figure 1A flowchart illustrating an embodiment of the compilation method of this application is shown. This compilation method is applied to a compiler. The specific definition of the compiler, etc., is described in the foregoing relevant records, and will not be repeated here to avoid repetition. This compiler can run on various system architectures, for example, it can run on the Android system architecture, or it can run on the Linux system architecture; no specific limitation is made. (Refer to...) Figure 1 The compilation method specifically includes the following steps.

[0027] Step 101: Obtain the estimated runtime of the compiled machine instructions for the loop.

[0028] In this application, a loop is a control structure or program structure that allows a block of code to be executed repeatedly until a specific condition is met. There is no specific limitation on the type of loop. For example, a loop can be a for loop, etc. This machine instruction is used to cause the central processing unit of the server where the compiler resides to run the loop.

[0029] This step involves first compiling the loop to obtain the compiled machine instructions, and then estimating the runtime of those machine instructions, T-sum, which is the estimated runtime of the machine instructions. It should be noted that the estimated runtime of the compiled machine instructions for the same loop may differ or be the same in different architectures; no specific limitation is made.

[0030] Optionally, prior to step 101, the method further includes: assigning estimated runtime values ​​to each sub-machine instruction executed by the compiler. Step 101 includes: summing the estimated runtime values ​​corresponding to each of the sub-machine instructions included in the loop-compiled machine instructions to obtain the estimated runtime of the loop-compiled machine instructions.

[0031] The submachine instructions here refer to those that constitute the machine instructions in the compiled loop. The execution time or runtime of the same submachine instruction may differ across different architectures, and the execution time or runtime of submachine instructions of different instruction types may also differ within the same architecture. Therefore, this assignment needs to be determined in conjunction with the architecture and instruction type of the compiler, primarily relying on the hardware parameters of the server hosting the compiler, as well as the instruction type. The assignment here is based on the clock cycle. The hardware parameters of the server hosting the compiler can be performance parameters that affect running speed, such as the server's CPU performance parameters and memory performance parameters, but are not specifically limited to these.

[0032] For example, for the Loongson architecture, the estimated execution time of the integer arithmetic submachine instruction is set to 1 (i.e., 1 clock cycle), the estimated execution time of the integer multiplication submachine instruction is set to 2 (i.e., 2 clock cycles), the estimated execution time of the floating-point multiplication submachine instruction is set to 3 (i.e., 3 clock cycles), the estimated execution time of the floating-point division submachine instruction is set to 4 (i.e., 4 clock cycles), the estimated execution time of the load submachine instruction is set to 6 (i.e., 6 clock cycles), the estimated execution time of the control transfer submachine instruction is set to 3 (i.e., 3 clock cycles), and so on.

[0033] Here, the machine instruction compiled from the aforementioned loop is broken down into individual sub-machine instructions using the compiler's existing instruction splitting module. Then, arithmetic functions are used to sum the estimated runtime of each sub-machine instruction, resulting in a relatively accurate estimated runtime for the machine instruction compiled from the loop. The execution process of the machine instruction compiled from the loop is the execution process of all the sub-machine instructions it includes; therefore, the estimated runtime obtained in this way is quite accurate.

[0034] Step 102: Obtain the average time taken for other business threads in the compiler to enter the nearest safe point; the other business threads are the business threads running on the compiler at the current moment other than the business thread in which the loop is located; at least one of the other business threads has entered a safe point before the current moment.

[0035] Other business threads refer to at least one business thread running on the compiler at the current moment when the compiler needs to adjust the loop's safepoint, excluding the business thread containing the loop body. The number of other business threads is not specifically limited; it can be two, three, four, or all business threads except the loop's business thread. When each business thread enters a safepoint, the compiler stores that moment as a historical record. The specific storage location is not limited. For example, it can be stored in the compiler's global data area. Here, the compiler's historical record retrieves the historical time taken by each of the other business threads to enter the nearest safepoint, and then calculates the average time using arithmetic functions. Only if at least one of the aforementioned other business threads has entered a safepoint before the current moment will the compiler's historical record contain a record of the time taken by that thread to enter the safepoint before the current moment. This time record can then serve as a reference for optimizing and adjusting the loop's safepoint. Therefore, in this application, at least one of the aforementioned other business threads has entered a safepoint before the current moment. Specifically, there is no limit to the number of business threads that have entered the safe point among the aforementioned other business threads before the current moment. For example, the number of business threads that have entered the safe point among the aforementioned other business threads before the current moment could be 1, 2, etc.

[0036] Optionally, step 102 includes the following sub-step 1021: Sub-step 1021: Obtain the average time taken for each of the other business threads that have entered a safe point before the current time to enter the nearest safe point.

[0037] The "current moment" here can refer to the moment when the safepoint needs to be adjusted for the loop. Specifically, as mentioned earlier, when each business thread enters a safepoint, the compiler stores that moment as a historical record. Then, from the runtime log, it searches for the most recent historical record of each of the aforementioned other business threads that had entered a safepoint before the current moment, and records the moment when that thread entered the safepoint. Then, it sums the times taken for each of these most recent safepoint entries and takes the arithmetic mean to obtain the average time. The average time taken for the most recent safepoint entries of the other business threads that had entered safepoints before the current moment is closer to the current moment in time. Therefore, the compiler's state when entering a safepoint during the loop execution is more similar, and the times taken are likely to be similar, making the average time more accurate.

[0038] Optionally, in sub-step 1021, the average time taken by each of the business threads that have entered a safe point before the current time to enter the nearest safe point is obtained. Specifically, this involves obtaining the average time taken by each of the business threads that have entered a safe point before the current time to enter the nearest safe point. That is, after determining all the business threads running on the compiler at the current time except for the business thread containing the loop, based on the aforementioned historical records, the sum of the times taken by each of the business threads that have entered a safe point before the current time to enter the nearest safe point is calculated. Then, this sum is divided by the number of business threads that have entered a safe point before the current time to obtain the average time taken. All business threads other than the business thread containing the loop at the current time are considered, because the accuracy of the safe point inserted in the loop will affect the execution efficiency of other business threads other than the business thread containing the loop at the current time, thus further improving the accuracy of the average time taken.

[0039] For example, at the current moment, the other business threads running on the compiler besides the business thread where the loop is located are business thread 1, business thread 2, business thread 3, and business thread 4. Business thread 1, business thread 2, business thread 3, and business thread 4 are the other business threads. Figure 2 This is a schematic diagram illustrating the historical average time taken by other business threads to enter the nearest safe point most recently, stored in the compiler of this application. (Refer to...) Figure 2 According to the compiler's stored history, it is determined that business thread 1, business thread 2, business thread 3, and business thread 4 have all entered a safe point before the current moment. From the above history, the time taken for each of the other business threads to enter the nearest safe point before the current moment is determined to be: 1ms for business thread 1, 3ms for business thread 2, 6ms for business thread 3, and 2ms for business thread 4. Therefore, the average time taken by the arithmetic function is (1ms + 3ms + 6ms + 2ms) / 4 = 3ms.

[0040] Optionally, before step 102, the method further includes: if, before the current time, there is a business thread among the other business threads that has not entered a safe point, setting the time spent by that business thread on its most recent entry into the nearest safe point to 0. That is, if before the current time, there is a business thread among the other business threads that has not entered a safe point, therefore, there is no historical record of the time spent on its most recent entry into the nearest safe point. Therefore, setting the time spent on its most recent entry into the nearest safe point to 0 avoids affecting the operation of the arithmetic function because the business thread among the other business threads that has not entered a safe point before the current time lacks a historical record of its most recent entry into the nearest safe point.

[0041] It should be noted that, for this loop, if any other business thread has not yet entered a safepoint before the current time, the compiler records the moment when that thread enters the safepoint, as a reference for subsequent optimization and adjustment of the safepoint. If, for this loop, none of the other business threads have entered a safepoint before the current time, then no optimization or adjustment will be made to the safepoint of this loop.

[0042] It should be noted that the order of steps 101 and 102 is not specifically limited here. For example, it can be that step 101 is executed first and then step 102, or step 102 is executed first and then step 101.

[0043] Step 103: Based on the estimated runtime and the average time consumption, adjust the safety points of the loop to compile the safety points of the loop.

[0044] In this application, the estimated runtime of the compiled machine instructions of a loop can roughly reflect the actual runtime of the compiled machine instructions of the loop, and also fully reflect the execution efficiency of the instruction sequence within the loop. Before the compiler adjusts the safe point for the loop, the average time taken for other business threads to enter the nearest safe point can fully reflect the speed at which other business threads running roughly at the same time as the loop enter the nearest safe point. Based on the estimated runtime and the average time taken for other business threads to enter the nearest safe point in the compiler, the safe point of the loop is adjusted. That is to say, the setting of the safe point of the loop not only considers the execution efficiency of the loop itself, but also the speed at which other business threads running roughly at the same time as the loop enter the nearest safe point. The safe point of the loop determined in this way is relatively accurate, so that the business thread containing the loop can execute to the safe point as quickly as possible, and will not have much impact on other business threads running at the same time as the loop.

[0045] Figure 3 A flowchart illustrating another embodiment of the compilation method of this application is shown, which is also applied to the aforementioned compiler. (Refer to...) Figure 3 The method specifically includes the following steps.

[0046] Step 201: Obtain the estimated runtime of the compiled machine instructions for the loop.

[0047] Step 202: Obtain the average time taken for other business threads in the compiler to enter the nearest safe point; the other business threads are the business threads running on the compiler at the current moment other than the business thread in which the loop is located; at least one of the other business threads has entered a safe point before the current moment.

[0048] Steps 201 and 202 refer to the relevant records in steps 101 and 102 above, and will not be repeated here to avoid repetition.

[0049] Step 203: If the estimated runtime is greater than the average runtime, obtain the total number of iterations of the loop.

[0050] If the estimated runtime T-sum is greater than the aforementioned average runtime T-stw-avg, it indicates that the loop may take a long time to complete. If a safe point is not inserted in the loop, when STW is required, excessive garbage generated by the loop may cause memory overflow, data loss, etc., which may lead to the loop failing to run correctly.

[0051] The total number of iterations (Count-sum) of a loop refers to the total number of times the code block within the loop is executed. For example, for the loop in the previous example, the total number of iterations (Count-sum) is 10000.

[0052] Step 204: Based on the estimated runtime, the average time consumption, and the total number of iterations, adjust the safety point for each loop body in the loop.

[0053] In this step, if the estimated runtime T-sum is greater than the aforementioned average execution time T-stw-avg, it indicates that completing the loop completely may take a long time. Therefore, a safepoint needs to be inserted within the loop to pause user threads and perform specific operations such as garbage collection. The estimated runtime, the aforementioned average execution time, and the total number of iterations of the loop are closely related to the setting of the safepoint. Setting the safepoint in this way ensures greater accuracy, allowing the business thread containing the loop to reach the safepoint as quickly as possible, minimizing the impact on other business threads and reducing the time other business threads spend entering STW (Stop-The-World) mode due to the slow execution of the business thread containing the loop to the safepoint.

[0054] Optionally, step 204 includes sub-steps 2041 and 2042. Sub-step 2041 involves splitting the loop into an inner loop and an outer loop; wherein the number of iterations in the inner loop is equal to the total number of iterations divided by a proportional value, where the proportional value is the estimated runtime divided by the average time consumption; and the number of iterations in the outer loop is equal to the total number of iterations divided by the number of iterations in the inner loop. Sub-step 2042 involves inserting a safety point at the target position where the loop body of each round of the inner loop has been executed.

[0055] Specifically, after the compiler's existing splitting module splits the loop into an inner loop and an outer loop, each iteration of the outer loop triggers the execution of the inner loop. The number of iterations of the outer loop, Count-out, determines how many rounds the inner loop will be executed. The number of iterations of the inner loop is denoted as Count-inner, and the total number of iterations of the loop, Count-sum = Count-inner × Count-out. The aforementioned ratio is T-sum / T-stw-avg. Count-inner = Count-sum / (T-sum / T-stw-avg). A safepoint is inserted at the target position after each inner loop completes its execution. This means splitting a time-consuming loop into multiple inner loops, with each inner loop having its own safepoint. The time taken for each inner loop to enter STW (Stop-The-World) mode cannot exceed T-stw-avg. As a result, each inner loop, acting as a small loop, has minimal impact on other business threads. Furthermore, while minimizing the impact on other business threads, the number of iterations for each inner loop is set as large as possible to minimize the number of safepoints required, thereby improving the loop's execution efficiency.

[0056] In summary, in this application, for any loop, when the estimated runtime T-sum is greater than the aforementioned average execution time T-stw-avg, not only can the execution efficiency of the loop be improved, but it will also have virtually no impact on other business threads, reducing the time that other business threads enter STW due to the slow execution of the business thread containing the loop to the safe point.

[0057] For example, in the aforementioned loop example, if the estimated runtime T-sum is greater than the aforementioned average runtime T-stw-avg, the loop is split into the following loop.

[0058] for (i = 0; i <Count-out; i++) { for (j = 0; j <Count-inner; j++) { / / do something; } Safepoint instruction; } The inner loop iteration count is: Count-inner = Count-sum / (T-sum / T-stw-avg), Count-inner × Count-out = Count-sum, and Count-out is the outer loop iteration count.

[0059] Optionally, if the quotient of the total number of iterations divided by the aforementioned ratio is a decimal, the quotient is rounded up to obtain the number of iterations of the inner loop. That is, if the quotient of Count-sum / (T-sum / T-stw-avg) is a decimal, the quotient is rounded up using the rounding instruction to obtain Count-inner, thus avoiding data loss and ensuring the correct execution of the loop.

[0060] It should be noted that in determining the number of iterations, Count-out, of the outer loop, Count-out = Count-sum / Count-inner is used. If the quotient of Count-sum / Count-inner is a decimal, it can be rounded up to get Count-out, or it can be rounded down; there is no specific limitation on this.

[0061] Step 205: If the estimated runtime is less than or equal to the average runtime, insert a safety point at the target position where the loop has been completed.

[0062] If the estimated runtime T-sum is less than or equal to the aforementioned average execution time T-stw-avg, it indicates that the loop will take a short time to complete. During its entire execution, there is no need to insert a safepoint, and it will have minimal impact on other business threads. Therefore, to improve the loop's execution efficiency, a safepoint is inserted only at the target position after the loop's execution, using existing safepoint insertion instructions in the compiler. In summary, when the estimated runtime of the loop is less than or equal to the aforementioned average execution time, inserting a safepoint at the target position after the loop's execution further improves the loop's execution efficiency, has minimal impact on other business threads, and reduces the time other business threads spend entering STW (Stop-The-World) mode due to the slow execution of the business thread containing the loop to the safepoint.

[0063] For example, in the aforementioned loop example, if the estimated runtime T-sum is less than or equal to the aforementioned average execution time T-stw-avg, safety points are inserted at the target positions after the loop is completed using existing safety point insertion instructions in the compiler, as follows.

[0064] for (i = 0; i <Count-sum; i++) { / / do something; } Safepoint instruction; It should be noted that, for the sake of simplicity, the method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments of this application are not limited to the described order of actions, because according to the embodiments of this application, some steps may be performed in a different order or simultaneously. Secondly, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required for the embodiments of this application.

[0065] Figure 4 A structural block diagram of one embodiment of the compiler of this application is shown, with reference to Figure 4 The compiler specifically includes the following modules.

[0066] The estimated runtime acquisition module 301 is used to acquire the estimated runtime of the compiled machine instructions of the loop; the average time acquisition module 302 is used to acquire the average time taken for other business threads in the compiler to enter the nearest safe point; the other business threads are business threads running on the compiler at the current moment other than the business thread in which the loop is located; at least one of the other business threads has entered a safe point before the current moment; The safety point setting module 303 is used to adjust the safety point of the loop based on the estimated runtime and the average time consumption, thereby realizing the compilation of the safety point of the loop.

[0067] Optionally, the safety point setting module 303 includes: The total iteration count acquisition submodule is used to acquire the total number of iterations of the loop when the estimated runtime is greater than the average time. The first safety point setting submodule is used to adjust the safety point of each loop body in the loop based on the estimated runtime, the average time consumption, and the total number of iterations.

[0068] Optionally, the first security point setting submodule includes: A splitting unit is used to split the loop into an inner loop and an outer loop; wherein the number of iterations of the inner loop is equal to the total number of iterations divided by a proportion value, the proportion value being the estimated runtime divided by the average time consumption; and the number of iterations of the outer loop is equal to the total number of iterations divided by the number of iterations of the inner loop. The safety point setting unit is used to insert a safety point at the target position after each round of inner loop execution.

[0069] Optionally, the splitting unit is further configured to round up to obtain the number of iterations of the inner loop when the total number of iterations divided by the ratio value is a decimal.

[0070] Optionally, the safety point setting module 303 includes: The second safety point setting submodule is used to insert a safety point at the target position after the loop is completed when the estimated runtime is less than or equal to the average runtime.

[0071] Optionally, the average time acquisition module 302 includes: The average time consumption acquisition submodule is used to acquire the average time consumption of the business threads that have entered the safe point most recently among the other business threads that have entered the safe point before the current time. Optionally, the compiler further includes a time consumption setting module, used to set the time consumption of the business thread's most recent entry into the nearest safe point to 0 if there is a business thread among the other business threads that has not entered the safe point before the current time.

[0072] Optionally, the compiler further includes: The assignment module is used to assign estimated execution time to each sub-machine instruction executed by the compiler; the estimated execution time is determined by the compiler's hardware parameters and instruction type. The estimated runtime acquisition module 301 includes: The estimated runtime acquisition submodule is used to sum the estimated runtime of each of the sub-machine instructions included in the loop-compiled machine instructions.

[0073] As the compiler implementation is basically similar to the method implementation, it is described in a simpler way. For relevant details, please refer to the description of the method implementation.

[0074] Figure 5 This is a structural diagram of an electronic device provided in an embodiment of this application. (Refer to...) Figure 5 This application also provides an electronic device, see [link to relevant documentation]. Figure 5 It includes: a processor 401, a memory 402, and a computer program 4021 stored in the memory and executable on the processor. When the processor executes the program, it implements the steps of the above-described embodiments of the compilation method.

[0075] This application also provides a readable storage medium, wherein when the instructions in the storage medium are executed by the processor of an electronic device, the electronic device is able to perform the steps of the various embodiments of the above-described compilation method.

[0076] This application also provides a computer program product, including: a computer program that, when executed by a processor, implements the steps of the above-described compilation method embodiments.

[0077] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.

[0078] Those skilled in the art will understand that embodiments of this application can be provided as methods, apparatus, electronic devices, readable storage media, or computer program products. Therefore, embodiments of this application can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, embodiments of this application can take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0079] This application describes embodiments with reference to flowchart illustrations and / or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0080] These computer program instructions may also be stored in a computer-readable storage medium capable of directing a computer or other programmable data processing terminal device to operate in a predictive manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0081] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0082] Although preferred embodiments of the present application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present application.

[0083] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.

[0084] The foregoing has provided a detailed description of a compilation method and compiler, an electronic device, a storage medium, and a computer program product provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments 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 variations 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 compilation method, characterized in that, Applied to a compiler, the method includes: Get the estimated runtime of the loop after the compiled machine instructions; Obtain the average time taken for other business threads in the compiler to enter the nearest safe point; the other business threads are business threads running on the compiler at the current moment other than the business thread in which the loop is located; at least one of the other business threads has entered a safe point before the current moment; Based on the estimated runtime and the average time consumption, the safety points of the loop are adjusted accordingly, thereby enabling the compilation of the safety points of the loop.

2. The method according to claim 1, characterized in that, The step of cyclically adjusting the safety point based on the estimated runtime and the average time consumption includes: If the estimated runtime is greater than the average runtime, obtain the total number of iterations of the loop; Based on the estimated runtime, the average time consumed, and the total number of iterations, the safety point is adjusted for each loop body in the loop.

3. The method according to claim 2, characterized in that, The step of adjusting the safety point for each loop body in the loop includes: The loop is divided into an inner loop and an outer loop; wherein the number of iterations of the inner loop is equal to the total number of iterations divided by a proportion value, the proportion value being the estimated runtime divided by the average time consumption; the number of iterations of the outer loop is equal to the total number of iterations divided by the number of iterations of the inner loop; Insert a safety point at the target position after the loop body of each inner loop is executed.

4. The method according to claim 3, characterized in that, If the total number of iterations divided by the ratio is a decimal, the number of iterations of the inner loop is rounded up.

5. The method according to claim 1, characterized in that, The aforementioned cyclic adjustment of safety points includes: If the estimated runtime is less than or equal to the average runtime, a safety point is inserted at the target position where the loop has been completed.

6. The method according to any one of claims 1 to 5, characterized in that, The step of obtaining the average time taken for other business threads in the compiler to enter the nearest safe point includes: Get the average time taken for each of the other business threads that have entered a safe point before the current time to enter the nearest safe point.

7. The method according to claim 6, characterized in that, The method further includes: If, at the current moment, there is a business thread among the other business threads that has not entered a safe point, the time taken for that business thread to enter the nearest safe point most recently is set to 0.

8. The method according to any one of claims 1 to 5, characterized in that, Before obtaining the estimated runtime of the compiled machine instructions for the loop, the method further includes: The compiler is assigned an estimated execution time for each sub-machine instruction; the estimated execution time is determined by the compiler's hardware parameters and instruction type. The process of obtaining the estimated runtime of the compiled machine instructions for the loop includes: The estimated runtime is obtained by summing the estimated runtimes corresponding to the sub-machine instructions included in the machine instructions.

9. A compiler, characterized in that, The compiler includes: The estimated runtime acquisition module is used to acquire the estimated runtime of the compiled machine instructions of the loop; the average time acquisition module is used to acquire the average time taken for other business threads in the compiler to enter the nearest safe point; the other business threads are business threads running on the compiler at the current moment other than the business thread in which the loop is located; at least one of the other business threads has entered a safe point before the current moment; The safety point setting module is used to adjust the safety points of the loop based on the estimated runtime and the average time consumption, thereby compiling the safety points of the loop.

10. An electronic device, characterized in that, include: A processor, a memory, and a computer program stored in the memory and executable on the processor, characterized in that the processor, when executing the program, implements the steps of the compilation method as described in any one of claims 1 to 8.

11. A readable storage medium, characterized in that, When the instructions in the storage medium are executed by the processor of the electronic device, the electronic device is able to perform the steps of the compilation method according to any one of claims 1 to 8.

12. A computer program product, characterized in that, include: A computer program that, when executed by a processor, implements the steps of the compilation method according to any one of claims 1 to 8.