Binary translation method, device, electronic device and program product

By obtaining the system information and historical running files of the target program, and automatically selecting and configuring the optimization strategy of the binary translator, the problems of high operation threshold and low configuration efficiency in the existing technology are solved, and automated optimization strategy configuration is realized, reducing operation complexity.

CN119690455BActive Publication Date: 2025-06-06LOONGSON TECH CORP
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510192393.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-02-20
Publication Date
2025-06-06
Estimated Expiration
2045-02-20

AI Technical Summary

Technical Problem

When running client programs, existing binary translators have high operating thresholds and low configuration efficiency, and users need to manually select and configure optimization strategies.

Method used

By obtaining the target system information and/or historical running files of the target program, the appropriate optimization strategy is automatically selected from the optimization strategy to be selected, and the binary translator is configured to enable the optimization strategy.

Benefits of technology

It lowers the operation threshold and improves configuration efficiency. It automatically selects and configures optimization strategies for client programs without manual operation by users.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119690455B_ABST
    Figure CN119690455B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention provides a binary translation method, device, electronic device and program product, which relates to the field of computer technology. In the method, the target system information and / or historical operation file of the target program are obtained; the target program is the client program that the binary translator is running this time, the target system information is used to characterize the operating system adapted to the target program, and the historical operation file is used to record the historical operation results of the target program and the risk level information of the enabled historical optimization strategy. Based on the target system information and / or the historical operation file, the optimization strategy adapted to the target program is selected from the selected optimization strategies to obtain the target optimization strategy; the selected optimization strategy is the optimization strategy provided by the binary translator. The binary translator is configured to enable the target optimization strategy. In this way, the operation threshold can be lowered and the configuration efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a binary translation method, device, electronic equipment and program product. Background Art

[0002] The binary translator can enable a program compiled based on one instruction set architecture (ISA) to run on a hardware platform of another ISA, so as to achieve cross-ISA compatibility. For example, it can enable a program of the x86 architecture platform to run on the LoongArch platform. In binary translation technology, the host platform refers to the hardware platform of the ISA of the translated basic block (TB) in the actual running program, and the guest platform refers to the platform of the ISA simulated by the binary translator. Among them, the program run by the binary translator can be called a guest program.

[0003] In the prior art, when a binary translator is used to run a client program, that is, when binary translation is performed, the user manually selects the optimization strategies to be used and manually configures the binary translator to enable these optimization strategies for the client program. In this way, the operation threshold is high and the configuration efficiency is low. Summary of the invention

[0004] The embodiments of the present invention provide a binary translation method, device, electronic device and program product, which can solve the problems of high operation threshold and low configuration efficiency.

[0005] In order to solve the above problem, an embodiment of the present invention discloses a binary translation method, which includes:

[0006] Obtain target system information and / or historical operation files of a target program; the target program is a client program currently run by the binary translator, the target system information is used to characterize the operating system adapted by the target program, and the historical operation files are used to record historical operation results of the target program and risk level information of enabled historical optimization strategies;

[0007] Based on the target system information and / or the historical operation file, an optimization strategy adapted to the target program is selected from the selected optimization strategies to obtain a target optimization strategy; the selected optimization strategy is an optimization strategy provided by the binary translator;

[0008] The binary translator is configured to enable the target optimization strategy.

[0009] On the other hand, an embodiment of the present invention discloses a binary translation processing device, the device comprising:

[0010] An acquisition module, used to acquire target system information and / or historical operation files of a target program; the target program is a client program currently run by the binary translator, the target system information is used to characterize the operating system adapted by the target program, and the historical operation files are used to record historical operation results of the target program and risk level information of enabled historical optimization strategies;

[0011] A selection module is used to select an optimization strategy adapted to the target program from the selected optimization strategies based on the target system information and / or the historical operation file to obtain a target optimization strategy; the selected optimization strategy is an optimization strategy provided by the binary translator;

[0012] A configuration module is used to configure the binary translator to enable the target optimization strategy.

[0013] On the other hand, an embodiment of the present invention discloses an electronic device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other through the communication bus; the memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the aforementioned method.

[0014] The embodiment of the present invention further discloses a binary translation program product, which includes instructions. When the instructions are executed by one or more processors, the processors execute the method described above.

[0015] The embodiments of the present invention include the following advantages: In the binary translation method provided by the embodiments of the present invention, the target system information and / or historical operation files of the target program are obtained; the target program is the client program that the binary translator is running this time, the target system information is used to characterize the operating system that the target program is adapted to, and the historical operation files are used to record the historical operation results of the target program and the risk level information of the enabled historical optimization strategies. Based on the target system information and / or historical operation files, an optimization strategy that is adapted to the target program is selected from the selected optimization strategies to obtain a target optimization strategy; the selected optimization strategy is the optimization strategy provided by the binary translator. The binary translator is configured to enable the target optimization strategy. In this way, by automatically selecting the target optimization strategy for the client program that the binary translator is running this time, and configuring the binary translator to enable the selected target optimization strategy this time, no manual operation by the user is required, thereby lowering the operation threshold and improving the configuration efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.

[0017] Figure 1 is a flowchart of a binary translation method provided by an embodiment of the present invention;

[0018] Figure 2 It is a schematic diagram of a binary translation process in the prior art;

[0019] Figure 3 is a block diagram of a binary translation device provided by an embodiment of the present invention;

[0020] Figure 4 It is a structural schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0021] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0022] Figure 1 is a flowchart of a binary translation method provided by an embodiment of the present invention. Figure 1 As shown, the method may include the following steps:

[0023] Step 101, obtain the target system information and / or historical operation file of the target program; the target program is the client program run by the binary translator this time, the target system information is used to characterize the operating system adapted by the target program, and the historical operation file is used to record the historical operation results of the target program and the risk level information of the enabled historical optimization strategy.

[0024] Step 102: Based on the target system information and / or the historical operation file, select an optimization strategy adapted to the target program from the selected optimization strategies to obtain a target optimization strategy; the selected optimization strategy is an optimization strategy provided by the binary translator.

[0025] Step 103: Configure the binary translator to enable the target optimization strategy.

[0026] In the embodiment of the present invention, the client program processed by the binary translator this time is the target program. The target program can be any client program processed by the binary translator. When the compiled binary translator is running, it can translate and execute the target program this time to realize the operation of the client program. The optimization strategy is used to characterize the optimization method adopted when converting the binary program of the source architecture into the binary program of the target architecture. In order to improve the efficiency of the binary translator, various optimization methods are often introduced. When performing binary translation, the optimization strategy is turned on to achieve the effects of improving translation efficiency, optimizing the performance of the target program, and reducing resource consumption. An optimization strategy is implemented by at least one optimization function provided by the binary translator. The optimization strategy can also be called a code strategy. A code strategy can be regarded as an optimization function configuration. Specifically, the binary translator can provide multiple optimization functions, and an optimization strategy corresponds to the configuration method of each optimization function in an optimization function combination, wherein the configuration method of the optimization function refers to turning on the optimization function or disabling the optimization function.

[0027] The optimization function specifically provided by the binary translator is determined by the translator development link, and the optimization strategy provided by the binary translator can be pre-defined by the developer. The optimization strategy to be selected is specifically the optimization strategy provided by the binary translator that supports being controlled at runtime. Which optimization strategies support being controlled when the binary translator is running depends on the code design of the binary translator and is pre-defined by the developer. Exemplarily, assuming that the binary translator provides the optimization functions: function a, function b, function c, function d and function e, the optimization strategies provided by the binary translator include optimization strategy 1, optimization strategy 2 and optimization strategy 3. Among them, optimization strategy 1, optimization strategy 2 and optimization strategy 3 all support being controlled at runtime, then optimization strategy 1, optimization strategy 2 and optimization strategy 3 are the optimization strategies to be selected.

[0028] The target system information and historical operation files of the target program are used to characterize the strategy selection factors of the target program. The target system information and historical operation files of the target program are parameters that affect the selection of the optimization strategy. Among them, the operating system adapted by the target program can refer to the operating system to which the target program belongs, which is the operating system in which the target program is designed and compiled to run, that is, the operating system in which the target program can run normally. The target system information can be used to uniquely indicate the operating system adapted by the target program. Exemplarily, the target system information can be the identifier of the operating system adapted by the target program. Exemplarily, assuming that the operating system adapted by the target program is the Linux operating system, then the target program runs normally in the Linux operating system, and the target system information can be the string "Linux". Assuming that the operating system adapted by the target program is the Windows operating system, then the target program runs normally in the Windows operating system, and the target system information can be the string "Windows". Since some optimization strategies only have optimization effects for specific operating systems, therefore, obtaining the target system information can provide an effective reference for selecting which optimization strategies for the target program, and selecting the optimization strategy for the target program based on the target system information can ensure that the appropriate optimization strategy is selected for the target program to a certain extent.

[0029] The historical operation file can be a file created for the target program to record the historical operation information of the target program. Exemplarily, the historical operation file can be created when the binary translator runs the target program for the first time, and the historical operation file can be a log type file. For any historical operation of the target program, the historical operation result of the historical operation and the risk level information of the enabled historical optimization strategy can be recorded in the historical operation file. Among them, the enabled historical optimization strategy refers to the optimization strategy enabled during the historical operation, and the risk level information of the historical optimization strategy is information used to describe the risk level of the historical optimization strategy. In this way, through the historical operation file, the risk level of the optimization strategy used by the target program before can be conveniently determined, and whether the target program runs correctly when using these optimization strategies, thereby providing an effective reference for enabling the optimization strategy of which risk level for the target program, and selecting the optimization strategy for the target program based on the historical operation file can ensure that the appropriate optimization strategy is selected for the target program to a certain extent.

[0030] The optimization strategy selected for the target program to be run this time is the target optimization strategy. Further, the binary translator can be configured to enable the target optimization strategy, so that when the binary translator runs the target program this time, the binary translator uses the target optimization strategy for binary translation and optimization.

[0031] In summary, in the binary translation method provided by the embodiment of the present invention, the target system information and / or historical operation files of the target program are obtained; the target program is the client program that the binary translator is running this time, the target system information is used to characterize the operating system that the target program is adapted to, and the historical operation files are used to record the historical operation results of the target program and the risk level information of the enabled historical optimization strategies. Based on the target system information and / or historical operation files, an optimization strategy that is adapted to the target program is selected from the selected optimization strategies to obtain a target optimization strategy; the selected optimization strategy is the optimization strategy provided by the binary translator. The binary translator is configured to enable the target optimization strategy. In this way, by automatically selecting the target optimization strategy for the client program that the binary translator is running this time, and configuring the binary translator to enable the selected target optimization strategy this time, there is no need for manual operation by the user, so the operation threshold can be lowered and the configuration efficiency can be improved.

[0032] Since there are many differences in the instructions that can be supported by hardware designs of different ISAs, executable files compiled based on one ISA are incompatible with other platforms. Therefore, the application of binary translation technology is becoming more and more extensive. Binary translation technology can make executable files compatible across ISAs, which is of great significance for migrating the software ecology of mature central processing unit (CPU) architecture to new CPU architecture, promoting its software ecology construction, and promoting the development of new architecture. Figure 2 is a schematic diagram of a binary translation process in the prior art, such as Figure 2 As shown, the binary translator can use the "translate while running" method to translate the instructions in the client program into host architecture instructions and run them at runtime. Specifically, when the binary translator needs to execute the client platform executable program, it can read the target program in the target program reading stage. In the target program reading stage, it can increase the execution of the binary translation method provided by the embodiment of the present invention, and then process the basic blocks included in the target program in sequence according to the granularity of the basic blocks until the program execution ends. Among them, the basic block can include a header signal (Header), an instruction code (Code) and link information (Linker).

[0033] When processing a basic block, a basic block search is first performed, that is, whether the basic block that has been translated exists in the code cache. If it exists, it is confirmed that the basic block has been translated, and the basic block execution can be performed on the translated basic block in the code cache. If it does not exist, it is confirmed that the basic block has not been translated, and the basic block code translation can be performed, and then the translated basic block is placed in the code cache, and the translated basic block is executed. In the process of translating and executing the basic block, it can be processed according to the enabled target optimization strategy. Exemplarily, in the case where the target optimization strategy includes an instruction-level optimization strategy, multiple instructions in the basic block obtained after translation can be merged into a conforming instruction, and the no-operation instructions in the basic block obtained after translation can be deleted, etc. In the case where the target optimization strategy includes a basic block link type optimization strategy, the link type of the frequently jumped basic block (for example, the basic block with a jump number greater than the preset adjustment number threshold) can be set to a direct link, so that the processing overhead of the jump between basic blocks can be reduced. In the case where the target optimization strategy includes a self-modifying code simulation optimization strategy, code modification operations on basic blocks in the target program can be detected. If code modification operations on basic blocks are detected, the basic block that has been translated in the code cache is discarded, and then the basic block is re-translated, and the re-translated basic block is placed in the code cache, and then the re-translated basic block is executed.

[0034] Optionally, the step of configuring the binary translator to enable binary translation may specifically include:

[0035] Step 1031: For any of the target optimization strategies, determine the specified states corresponding to the optimization functions corresponding to the target optimization strategy according to the configuration method corresponding to the target optimization strategy.

[0036] Step 1032: Set the environment variables corresponding to each of the optimization functions to the specified states corresponding to each of the optimization functions, so as to control the binary translator to enable the target optimization strategy.

[0037] In an embodiment of the present invention, the specified state may be an on state or a disabled state (i.e., a closed state). The optimization function corresponding to the target optimization strategy is the optimization function included in the optimization function combination corresponding to the target optimization strategy. The configuration method corresponding to the target optimization strategy is specifically used to characterize the configuration method of each optimization function in the optimization function combination corresponding to the target optimization strategy. For any optimization function corresponding to the target optimization strategy, the environment variable corresponding to the optimization function is set to the specified state corresponding to the optimization function, thereby realizing the control of the binary translator to enable the target optimization strategy.

[0038] Specifically, when the configuration mode of the optimization function indicates that the optimization function is turned on, it is determined that the specified state corresponding to the optimization function is the turned-on state, and when the configuration mode of the optimization function indicates that the optimization function is disabled, it is determined that the specified state corresponding to the optimization function is the disabled state. By assigning the environment variable corresponding to the optimization function to a first preset value, the environment variable corresponding to the optimization function is set to the turned-on state, and by assigning the environment variable corresponding to the optimization function to a second preset value, the environment variable corresponding to the optimization function is set to the disabled state. Accordingly, in the case where the specified state corresponding to the optimization function is the turned-on state, setting the environment variable corresponding to the optimization function to the specified state corresponding to the optimization function may specifically include: generating a first command statement for indicating that the environment variable corresponding to the optimization function is set to the first preset value and executing it. In the case where the specified state corresponding to the optimization function is the disabled state, setting the environment variable corresponding to the optimization function to the specified state corresponding to the optimization function may specifically include: generating a second command statement for indicating that the environment variable corresponding to the optimization function is set to the second preset value and executing it.

[0039] Exemplarily, it is assumed that the binary translator provides the optimization functions: function a, function b, function c, function d and function e, and the optimization strategies provided by the binary translator include optimization strategy 1, optimization strategy 2 and optimization strategy 3. Among them, optimization strategy 1 is <function a; configuration mode: enable function a>, optimization strategy 2 is <function b and function d; configuration mode: enable function b and function d>, and optimization strategy 3 is <function c and function e; configuration mode: enable function c and disable function e>. Among them, optimization strategy 3 is selected as the target optimization strategy, then according to the configuration mode of the optimization function corresponding to the optimization strategy 3, the environment variable corresponding to function c is set to the enabled state and the environment variable corresponding to function e is set to the disabled state, so as to realize the control of the binary translator to enable optimization strategy 3. Assuming that the first preset value is 1 and the second preset value is 0, the environment variable corresponding to function c is TRANSLATOR_ENABLE_OPT_C, and the environment variable corresponding to function e is TRANSLATOR_ENABLE_OPT_E. Then, the first command statement may be generated and executed: set TRANSLATOR_ENABLE_OPT_C=1, and the second command statement may be generated and executed: set TRANSLATOR_ENABLE_OPT_E=0, so as to control the binary translator to enable optimization strategy 3.

[0040] It should be noted that the environment variables corresponding to the optimization strategy are in a closed state by default. After completing the current operation of the target program, the environment variables corresponding to the optimization functions corresponding to the target optimization strategies can be set to the default state. Among them, the default state can be a disabled state. In this way, it is ensured that when other client programs are processed subsequently, interference caused by the previously configured target optimization strategy is avoided. By re-executing the above-mentioned binary translation method, the binary translator is controlled to enable the target optimization strategy selected for other client programs for other client programs. Accordingly, in the case where the default state is a disabled state, if the environment variable corresponding to the optimization function whose state is a disabled state is not the second preset value, the operation of generating and executing a second command statement for instructing to set the environment variable corresponding to the optimization function to the second preset value is executed.

[0041] In an optional implementation, the selected target optimization strategy may also be output to the user, and the user may manually configure it, which is not limited in this embodiment of the present invention.

[0042] In the prior art, users are required to manually decide which optimization strategies to enable, and there are certain threshold requirements for users. And users are required to manually open the environment variables corresponding to the optimization functions corresponding to the optimization strategies, which is cumbersome to operate manually and has a high cost of use. In the embodiment of the present invention, the enabled target optimization strategy is automatically selected for the target program, which can save the cost of manually selecting the optimization strategy. Further, according to the configuration method corresponding to the target optimization strategy, the specified state corresponding to each optimization function corresponding to the target optimization strategy is automatically determined, and the environment variables corresponding to each optimization function are set to the specified state corresponding to each optimization function, thereby realizing the automatic configuration of the binary translator to enable the target optimization strategy when running the target program, that is, realizing the automatic control of the binary translator to use the target optimization strategy when processing the target program. In this way, manual operation can be further simplified, the operating cost of manual configuration can be saved, and the cost of use of the program can be reduced.

[0043] Optionally, the step of selecting an optimization strategy adapted to the target program from the candidate optimization strategies based on the target system information and / or the historical operation file may specifically include:

[0044] Step 1021: Select a first optimization strategy adapted to the target program based on the target system information and the specific operating system information of the selected optimization strategy; the specific operating system information is used to characterize the specific operating system adapted to the selected optimization strategy.

[0045] And / or, step 1022, based on the historical operation file and the risk level information of the selected optimization strategy, select a second optimization strategy adapted to the target program.

[0046] In an embodiment of the present invention, step 1021 represents a method for automatically selecting an optimization strategy, and step 1022 represents another method for automatically selecting an optimization strategy. In specific implementation, only one of the methods may be adopted, or both methods may be adopted at the same time. Accordingly, in the case of only obtaining the target system information, step 102 only includes step 1021, and the target optimization strategy only includes the first optimization strategy. In the case of only obtaining the historical operation files of the target program, step 102 only includes step 1022, and the target optimization strategy only includes the second optimization strategy. In the case of obtaining the target system information and the historical operation files of the target program, step 102 includes step 1021 and step 1022, and the target optimization strategy includes the first optimization strategy and the second optimization strategy.

[0047] Specifically, some optimization strategies have optimization effects on client programs of all operating systems, while some optimization strategies have optimization effects only on client programs of specific operating systems, that is, there may be optimization strategies for specific operating systems in the optimization strategies provided by the binary translator. Exemplarily, for Ahead-of-Time (AOT) type optimization strategies, since the organizational structure of its code cache file depends on the operating system type of the client program, the AOT type optimization strategies provided by the binary translator are often only effective for specific operating systems. The specific operating system information of the selected optimization strategy can be pre-set during the development stage. For the optimization strategy that has optimization effects only on client programs of specific operating systems, the specific operating system information will be pre-set for the optimization effect. Among them, the specific operating system information is used to uniquely indicate the specific operating system targeted by the selected optimization strategy. Exemplarily, the specific operating system information can be the identifier of the specific operating system targeted by the selected optimization strategy. In this way, based on the target system information of the target program and the specific operating system information of the selected optimization strategy, the first optimization strategy adapted for the target program can be selected. Exemplarily, assuming that the specific operating system targeted by the selected optimization strategy is the Linux operating system, then the specific operating system information can be the string "Linux". Assuming that the specific operating system targeted by the selected optimization strategy is the Windows operating system, then the specific operating system information can be the string "Windows". The risk level information of the selected optimization strategy can also be pre-set during the development phase. The risk level information of the selected optimization strategy is information used to describe the risk level of the selected optimization strategy. In this way, based on the historical running files and the risk level information of the selected optimization strategy, an adaptive second optimization strategy can be selected for the target program.

[0048] Because different client programs have different sensitivity and correctness to different optimization strategies, and the optimization effect is usually closely related to the characteristics of the program. For example, when the same optimization strategy is adopted for different client programs, there are differences in the improvement effect on processing performance, and there are differences in the error conditions of the program operation. Some optimization strategies are only applicable to client programs of specific operating systems, and can only guarantee the correctness of client programs for specific operating systems. Therefore, there is a demand for different client programs to adopt different code strategies. In the embodiment of the present invention, through the above two automatic selection optimization strategy methods, a code strategy is selected for each client program, which satisfies the demand of the binary translator to adopt different code strategies for different client programs to a certain extent. In specific implementation, the above two automatic selection optimization strategy methods can be adopted at the same time to determine the first optimization strategy and the second optimization strategy as the target optimization strategy, so that the optimization effect of the binary translator can be maximized and the translation efficiency of the binary translator can be improved. It should be noted that the target optimization strategy may include repeated optimization strategies. Therefore, before configuring the binary translator to enable the target optimization strategy, the target optimization strategy can also be deduplicated.

[0049] Optionally, the selecting the first optimization strategy adapted to the target program based on the target system information and the specific operating system information of the selected optimization strategy includes:

[0050] Step 1021a, determine from the predefined first policy groups, a first policy group whose corresponding operating system information is consistent with the target system information as the target group; one of the first policy groups corresponds to one operating system information, and one of the first policy groups includes a candidate optimization policy whose specific operating system information is consistent with the operating system information corresponding to the first policy group.

[0051] Step 1021b: determine the candidate optimization strategy included in the target group as the first optimization strategy.

[0052] In an embodiment of the present invention, the first policy group is obtained by dividing the selected optimization policies in advance according to the specific operating system information of the selected optimization policies. Exemplarily, the first policy group can be predefined by the following process: determining the specific operating system information of each selected optimization policy. Among them, the specific operating system information of the selected optimization policy can be preset, and can be pre-set by the developer. The selected optimization policy that has an optimization effect on the client programs of all operating systems does not have the specific operating system information. For the selected optimization policy that does not have the specific operating system information, it is not divided into the first policy group. Then, a first policy group is set corresponding to different operating system information. Among them, the first policy group is empty in the initial state, and the number of the first policy groups is determined by the number of operating system types. For any first policy group, the selected optimization policy whose specific operating system information is the operating system information corresponding to the first policy group is added to the first policy group. After completing the division operation of all the selected optimization policies, the empty first policy group can be deleted. Exemplarily, the first policy group corresponding to "Linux": Linux group, and the first policy group corresponding to "Windows": Windows group can be set. All the selected optimization strategies with specific operating system information of "Linux" are added to the Linux group, and all the selected optimization strategies with specific operating system information of "Windows" are added to the Windows group. The data structure of the first strategy group can be an array, and adding the selected optimization strategy to the first strategy group means writing the identifier of the selected optimization strategy as an array member into the array representing the first strategy group.

[0053] Furthermore, the binary translator can directly run the client program of the same operating system as the binary translator, or it can indirectly run the client program of a cross-operating system through other simulation programs (such as Wine programs). For example, a binary translator in a Linux operating system can directly run the client program of the Linux operating system, or it can run the client program of the Windows operating system through a simulation program. That is, the operating system to which the client program run by the binary translator belongs may be the same as the operating system simulated in the binary translator, or it may be different. The operating system adapted to the target program run by the binary translator each time is not fixed. In the embodiment of the present invention, for the target program run this time, the operating system to which the target program belongs can be dynamically identified by obtaining the target system information of the target program.

[0054] Specifically, the file flags of executable files of different operating systems are different. Among them, the file flag refers to the magic number at the beginning of the file. The magic number of the executable file of the target program can be compared with the preset operating system information and magic number correspondence. Exemplarily, for any operating system, the operating system information of the operating system and the magic number of the executable file of the operating system can be stored in the form of a key-value pair, and finally the correspondence is obtained. Then, the operating system information that matches the magic number corresponding to the corresponding relationship with the magic number of the target program is used as the target system information. Exemplarily, it is assumed that in the preset operating system information and magic number correspondence, the magic number corresponding to the operating system information "Linux" is \x7FELF, and the magic number corresponding to the operating system information "Windows" is \0x4D5A. Then, when the magic number of the target program is \x7FELF, "Linux" is determined as the target system information.

[0055] Furthermore, the target system information can be compared with the operating system information corresponding to each first policy grouping. If the operating system information corresponding to the first policy grouping is the same as the target system information, the first policy grouping is determined as the target grouping. All the selected optimization policies included in the target grouping are used as the first optimization policies. In this way, different first optimization policies can be automatically enabled for client programs of different operating systems, thereby improving the matching degree between the enabled first optimization policies and the client programs and ensuring the execution effect on the client programs. Of course, if there is no corresponding first policy grouping whose operating system information is the same as the target system information, the first optimization policy is determined to be empty, which triggers the operating system identification exception processing: no optimization policy in the first policy grouping is enabled this time.

[0056] In the embodiment of the present invention, a first policy group whose corresponding operating system information is consistent with the target system information is determined from the predefined first policy group as the target group. The selected optimization policy included in the target group is determined as the first optimization policy, so that the first optimization policy can be selected for the target program, and the selection efficiency is high. It can also ensure that the specific operating system targeted by the selected first optimization policy is consistent with the operating system to which the target program belongs, and then when the target optimization policy is used to optimize the target program later, the target program runs correctly.

[0057] It should be noted that in actual application scenarios, the default optimization strategy can also be enabled before or during the compilation of the binary translator. Among them, the optimization function corresponding to the default optimization strategy is an optimization function applicable to different client programs, and the default optimization strategy can be pre-defined in the development stage. Exemplarily, it is assumed that the developed binary translator provides 10 optimization functions, of which 3 optimization functions are optimization functions applicable to different client programs, and the optimization strategy composed of the other 7 optimization functions is only applicable to the client program of a specific operating system, that is, it only has an optimization effect on the client program of a specific operating system. Then the default optimization strategy composed of these 3 optimization functions can be configured in the compilation stage of the binary translator so that the default optimization strategy is enabled for all client programs, and the optimization strategy composed of the other 7 optimization functions can be used as a candidate optimization strategy. When the binary translator is running, according to the operating system adapted to the target program of this operation, the second optimization strategy is selected from these candidate optimization strategies. Exemplarily, the binary translator provided in an embodiment of the present invention can be a user-level binary translator, and the user-level binary translator refers to a binary translator running in user space. Exemplarily, the binary translator can be QEMU. Among them, QEMU supports configuring the optimization strategy at compile time and configuring the optimization strategy at run time. QEMU can also be used as a system-level binary translator, which is not limited in the embodiment of the present invention.

[0058] Optionally, the step of selecting the second optimization strategy adapted to the target program based on the historical operation file and the risk level information of the selected optimization strategy includes:

[0059] Step 1022a: when the historical operation file is not empty, use the risk level information of the historical optimization strategy recorded in the historical operation file as the candidate level information, and determine the number of historical operation failures corresponding to the candidate level information based on the historical operation results corresponding to the candidate level information.

[0060] Step 1022b: based on the number of historical operation failures, select target level information from the to-be-selected level information and the next risk level information of the to-be-selected level information; the risk level represented by the next risk level information is lower than the risk level represented by the to-be-selected level information.

[0061] Step 1022c: determine the candidate optimization strategy with risk level information being the target level information as the second optimization strategy.

[0062] In the embodiment of the present invention, when the binary translator runs the client program for the first time, a history operation file can be generated for the client program first, so that each client program run by the binary translator has its own history operation file. In the initial state, the history operation file of the client program is empty. After the binary translator runs the client program at least once, the history operation file of the client program is not empty.

[0063] When the historical operation file is not empty, the historical operation file may include at least one historical operation record information, one historical operation record information corresponds to one historical operation, and one historical operation record information may include the operation time of the historical operation, the historical operation result, and the risk level information of the enabled historical optimization strategy. Specifically, the risk level information of the historical optimization strategy is used as the historical risk level information. The historical risk level information included in each historical operation record information in the historical operation file can be first identified, and the historical risk level information with the lowest risk level represented can be used as the candidate level information. In the embodiment of the present invention, the candidate optimization strategy can be selected in order of risk level from high to low. Accordingly, the historical risk level information included in the most recently recorded historical operation record information in the historical operation file can be determined as the candidate level information.

[0064] In an embodiment of the present invention, multiple risk level information can be pre-set. If there are multiple risk level information that represent a risk level lower than the risk level represented by the level information to be selected, the risk level information with the highest risk level represented therein is used as the next risk level information of the level information to be selected. For example, assuming that risk level information 1, risk level information 2, and risk level information 3 are set in order from high to low in terms of the risk levels represented, and the current level information to be selected is risk level information 1, then risk level information 2 can be used as the next risk level information of the level information to be selected.

[0065] Further, the historical operation result may indicate a successful operation or a failed operation, and the historical operation result is determined by the exit status of the historical operation of the target program. For any historical operation, if the exit status when the target program exits is a normal exit, the historical operation result recorded for this historical operation indicates a successful operation. If the exit status when the target program exits is an abnormal exit, the historical operation result recorded for this historical operation indicates a failed operation. Accordingly, based on the historical operation result corresponding to the to-be-selected level information, the number of historical operation failures corresponding to the to-be-selected level information may be determined. Among them, the number of historical operation failures indicates the number of operation failures that occurred in at least one historical operation in which the historical optimization strategy for the to-be-selected level information was enabled.

[0066] Based on the number of historical run failures, the degree of adaptability between the historical optimization strategy of the candidate level information that has been historically enabled and the target program can be measured. The greater the number of historical run failures, the lower the degree of adaptability. Conversely, the lower the number of historical run failures, the higher the degree of adaptability. Therefore, based on the number of historical run failures, it can be decided whether to continue using the historical optimization strategy or enable an optimization strategy with a lower risk level to ensure the correctness of the target program operation.

[0067] In an embodiment of the present invention, when the historical operation file is not empty, the risk level information of the historical optimization strategy recorded in the historical operation file is used as the candidate level information, and based on the historical operation results corresponding to the candidate level information, the number of historical operation failures corresponding to the candidate level information is determined. Based on the number of historical operation failures, the target level information is selected from the candidate level information and the next risk level information of the candidate level information; the risk level represented by the next risk level information is lower than the risk level represented by the candidate level information. The candidate optimization strategy with the risk level information as the target level information is determined as the second optimization strategy. In this way, combined with the number of historical operation failures corresponding to the risk level information of the historical optimization strategy, it is determined which risk level information candidate optimization strategy to enable this time, which can ensure the correctness of the operation of the target program when the selected candidate optimization strategy is enabled for optimization to a certain extent.

[0068] Optionally, in an embodiment of the present invention, the risk level information of the selected optimization strategy is an identifier of the second strategy group to which the selected optimization strategy belongs, and one of the second strategy groups includes a selected optimization strategy whose corresponding risk level matches the risk level represented by the second strategy group. The above step of determining the selected optimization strategy whose risk level information is the target level information as the second optimization strategy may specifically include: determining the selected optimization strategy included in the second strategy group represented by the target level information as the second optimization strategy.

[0069] In an embodiment of the present invention, the risk level information may be an identifier of the second policy group, and the risk level represented by the risk level information is the risk level represented by the second policy group. The risk level information of the historical optimization strategy is the identifier of the second policy group to which the historical optimization strategy belongs, and the target level information is the identifier of a selected second policy group. The second policy group is obtained by pre-dividing the selected optimization strategy according to the risk level of the selected optimization strategy. Exemplarily, the second policy group can be pre-defined by the following process: determining the risk level corresponding to each selected optimization strategy. Among them, the risk level can also be called the correctness risk level, and the specific risk level corresponding to the selected optimization strategy can be preset, and can be set in advance for each selected optimization strategy by the developer. Then, at least two second policy groups are set. Among them, the second policy group is empty in the initial state, and the specific number of the second policy groups can be set according to actual needs. For any second policy group, the selected optimization strategy with a risk level represented by the second policy group is added to the second policy group, so as to realize the classification of the selected optimization strategy, and one second policy group is regarded as one classification. The data structure of the second strategy group can be an array, and adding the selected optimization strategy to the second strategy group means writing the identifier of the selected optimization strategy as an array member into the array representing the second strategy group. The risk level information can be specifically an array identifier, such as an array name, an array number, and the like.

[0070] Exemplarily, the risk level represented by the second policy grouping may include one risk level, or may also include a risk level interval. Assume that three risk levels are defined in order from high to low: risk level I, risk level II, and risk level III. Two second policy groups are created: second policy grouping 1 and second policy grouping 2. Among them, the risk level represented by the second policy grouping 1 includes risk level III, and the risk level represented by the second policy grouping 2 includes [risk level I, risk level II]. Of course, three second policy groups may also be set, and the risk levels represented by these three second policy groups are defined as risk level III, risk level II, and risk level I, respectively, and the embodiments of the present invention are not limited to this. In the case where the risk level represented by the second policy grouping includes a risk level interval, the risk level represented by the second policy grouping is higher than the risk levels represented by other second policy groups, which means that the lowest risk level in the risk level interval represented by the second policy grouping is higher than the highest risk level in the risk levels represented by other second policy groups. The risk level represented by the second policy grouping is lower than the risk levels represented by other second policy groupings, which means that the highest risk level in the risk level range represented by the second policy grouping is lower than the lowest risk level in the risk levels represented by other second policy groupings.

[0071] Further, the second policy group 1 includes all the selected optimization policies corresponding to the risk level III, and the second policy group 2 includes all the selected optimization policies corresponding to the risk level I and all the selected optimization policies corresponding to the risk level II. The second policy group 1 can be called the basic configuration group, and the second policy group 2 can be called the risk configuration group. Risk level III can be set for the selected optimization policies that cause the client program to have correctness errors (running errors) less than the preset error number threshold, that is, the selected optimization policies that have never or rarely caused the client program to have correctness errors in the past are set to risk level III, ensuring that only low-risk optimization policies are included in the basic configuration group. Risk level I or risk level II is set for the selected optimization policies that cause the client program to have correctness errors no less than the preset error number threshold and have been repaired, or for the selected optimization policies that can only make the client program run correctly in a specific scenario. Assuming that the target level information is the identifier of the second policy group 2, all the selected optimization policies included in the second policy group 2 can be determined as the second optimization policies. In this way, the second policy group is defined in advance according to the risk level, so that the second optimization policy can be conveniently selected based on the dimension of the second policy group.

[0072] Optionally, in an embodiment of the present invention, when the historical operation file is empty, the selected optimization strategy included in the second strategy group with the highest risk level is determined as the second optimization strategy. Since the selected optimization strategy with a higher risk level tends to have a better optimization effect, it can be ensured that the second strategy group with the highest risk level is enabled at the beginning, and then the second strategy group enabled by the target program is switched in the order of the risk level from high to low according to the number of historical operation failures, so that the second strategy group with a higher risk level is used as much as possible for the target program.

[0073] It should be noted that, when the second strategy group represented by the selected level information corresponds to the lowest risk level, the selected optimization strategy included in the second strategy group represented by the selected level information can be directly used as the second optimization strategy. Alternatively, the second optimization strategy can be determined to be empty, that is, no second optimization strategy is enabled for the target program in this operation.

[0074] Optionally, the step of determining the number of historical operation failures corresponding to the candidate level information based on the historical operation results corresponding to the candidate level information includes:

[0075] Step 1022a1, determine the number of results indicating operation failure in the most recent N historical operation results corresponding to the selected level information, and obtain the number of historical operation failures; N is a positive integer.

[0076] The step of selecting target level information from the to-be-selected level information and the next risk level information of the to-be-selected level information based on the historical number of operation failures comprises:

[0077] Step 1022b1: When the number of historical operation failures is greater than a preset number threshold, the next risk level information is used as the target level information.

[0078] Step 1022b2: When the number of historical operation failures is not greater than the preset number threshold, use the candidate level information as the target level information.

[0079] In the embodiment of the present invention, N is a positive integer, and the specific value of N can be set according to actual needs. For example, N can be 2, or N can be 1, and so on. The historical operation record information including the historical risk level information of the selected level information can be used as the target record information. The historical operation results included in the N target record information with the latest operation time are used as the latest N historical operation results corresponding to the selected level information. Specifically, the target record information can be sorted in the order of the included operation time from early to late. The historical operation results included in the last N target record information are obtained to obtain the latest N historical operation results corresponding to the selected level information. Taking N equal to 1 as an example, the historical operation results included in the target record information with the latest operation time (i.e., the historical operation record information of the latest record) can be used as the latest N historical operation results. Assume that the historical operation result is TRUE, indicating a successful operation, and the historical operation result is FALSE, indicating a failed operation. Then the number of FALSE in the latest N historical operation results can be counted as the number of historical operation failures.

[0080] Further, the preset number threshold can be predefined, and illustratively, the preset number threshold can be 0. If the selected optimization strategy in the second strategy group represented by the selected level information has not caused an error exit in the past N historical runs of the target program, it can meet the situation that the number of historical run failures is not greater than the preset number threshold, and accordingly, the current run can continue to use the selected optimization strategy in the second strategy group represented by the selected level information. On the contrary, if an error exit has occurred, the next risk level information of the selected level information is used as the target level information, that is, the next second strategy group of the second strategy group represented by the selected level information is enabled in this run, and the optimization strategy with lower risk is enabled to reduce the probability of error exit of the target program to ensure the correctness of the target program.

[0081] In the embodiment of the present invention, the target level information used in the current operation is dynamically adjusted according to the magnitude relationship between the number of historical operation failures and the preset number threshold, so as to ensure that the target program runs correctly when the second optimization strategy is enabled.

[0082] Optionally, the embodiment of the present invention may further include the following steps:

[0083] Step S21: after the current operation is completed, the operation result of the current operation is determined as a new historical operation result, and the risk level information of the second optimization strategy is determined as the risk level information of the new historical optimization strategy.

[0084] Step S22: write the new historical operation results and the risk level information of the new historical optimization strategy into the historical operation file accordingly.

[0085] Specifically, after the end of this operation, this operation becomes the most recent historical operation, and the start time of this operation is used as the running time of this historical operation. Based on the exit status of the target program at the end of this operation, a historical operation result is generated. For example, when the exit status is a normal exit, a historical operation result indicating a successful operation is generated, and when the exit status is an abnormal exit, a historical operation result indicating a failed operation is generated. The identifier of the second strategy group to which the second optimization strategy belongs is used as the risk level information of the new historical optimization strategy. Finally, the running time, the generated historical operation result, and the identifier of the second strategy group to which the second optimization strategy belongs are added to the historical operation file of the target program as a new historical operation record information. In this way, by updating the historical operation file, it can be ensured that the historical operation file can accurately characterize the historical operation of the target program. Among them, the historical operation file of the target program is stored in a non-volatile storage area to avoid the loss of the historical operation file.

[0086] The binary translation method provided by the embodiment of the present invention can be implemented by code, and the implementation code of the method can be integrated with a binary translator. The above processing method is executed by the binary translator. Alternatively, it can be implemented in the form of a plug-in, and the binary translator can call the plug-in in the link of reading the target program to implement the above processing method, which is not limited by the embodiment of the present invention. In this way, it is as convenient as possible for users to plug and play, reducing the learning cost and operation threshold of users.

[0087] Reference Figure 3 , shows a block diagram of a binary translation device provided by an embodiment of the present invention, such as Figure 3 As shown, the device may specifically include:

[0088] The acquisition module 201 is used to acquire the target system information and / or historical operation files of the target program; the target program is the client program currently run by the binary translator, the target system information is used to characterize the operating system adapted by the target program, and the historical operation files are used to record the historical operation results of the target program and the risk level information of the enabled historical optimization strategies;

[0089] A selection module 202 is used to select an optimization strategy adapted to the target program from the selected optimization strategies based on the target system information and / or the historical operation file to obtain a target optimization strategy; the selected optimization strategy is an optimization strategy provided by the binary translator;

[0090] The configuration module 203 is used to configure the binary translator to enable the target optimization strategy.

[0091] Optionally, the selection module 202 is specifically configured to:

[0092] Based on the target system information and the specific operating system information of the selected optimization strategy, selecting a first optimization strategy adapted to the target program; the specific operating system information is used to characterize the specific operating system adapted to the selected optimization strategy;

[0093] And / or, based on the historical operation file and the risk level information of the selected optimization strategy, a second optimization strategy adapted to the target program is selected.

[0094] Optionally, the selection module 202 is further configured to:

[0095] From the predefined first policy groups, determine a first policy group whose corresponding operating system information is consistent with the target system information as the target group; one of the first policy groups corresponds to a type of operating system information, and one of the first policy groups includes a candidate optimization policy whose specific operating system information is consistent with the operating system information corresponding to the first policy group;

[0096] The candidate optimization strategy included in the target group is determined as the first optimization strategy.

[0097] Optionally, the selection module 202 is further configured to:

[0098] In the case that the historical operation file is not empty, the risk level information of the historical optimization strategy recorded in the historical operation file is used as the level information to be selected, and based on the historical operation results corresponding to the level information to be selected, the number of historical operation failures corresponding to the level information to be selected is determined;

[0099] Based on the number of historical operation failures, target level information is selected from the to-be-selected level information and the next risk level information of the to-be-selected level information; the risk level indicated by the next risk level information is lower than the risk level indicated by the to-be-selected level information;

[0100] The candidate optimization strategy whose risk level information is the target level information is determined as the second optimization strategy.

[0101] Optionally, the selection module 202 is further configured to:

[0102] Determine the number of results indicating operation failure in the most recent N historical operation results corresponding to the selected level information, and obtain the number of historical operation failures; N is a positive integer;

[0103] When the number of historical operation failures is greater than a preset number threshold, the next risk level information is used as the target level information;

[0104] When the number of historical operation failures is not greater than the preset number threshold, the to-be-selected level information is used as the target level information.

[0105] Optionally, the risk level information of the optimization strategy to be selected is an identifier of a second strategy group to which the optimization strategy to be selected belongs, and one of the second strategy groups includes the optimization strategies to be selected whose corresponding risk levels are compatible with the risk level represented by the second strategy group;

[0106] The selection module 202 is further specifically used for:

[0107] The candidate optimization strategy included in the second strategy group represented by the target level information is determined as the second optimization strategy.

[0108] Optionally, the device further comprises:

[0109] A processing module, configured to determine, after the current operation is completed, the operation result of the current operation as a new historical operation result, and determine the risk level information of the second optimization strategy as the risk level information of the new historical optimization strategy;

[0110] The writing module is used to write the new historical operation results and the risk level information of the new historical optimization strategy into the historical operation file accordingly.

[0111] Optionally, the configuration module 203 is specifically configured to:

[0112] For any of the target optimization strategies, determining the designated states corresponding to the optimization functions corresponding to the target optimization strategy according to the configuration mode corresponding to the target optimization strategy;

[0113] The environment variables corresponding to the optimization functions are set to the specified states corresponding to the optimization functions, so as to control the binary translator to enable the target optimization strategy.

[0114] In summary, in the binary translation processing device provided by the embodiment of the present invention, the target system information and / or historical operation files of the target program are obtained; the target program is the client program that the binary translator is running this time, the target system information is used to characterize the operating system that the target program is adapted to, and the historical operation files are used to record the historical operation results of the target program and the risk level information of the enabled historical optimization strategies. Based on the target system information and / or historical operation files, an optimization strategy that is adapted to the target program is selected from the selected optimization strategies to obtain a target optimization strategy; the selected optimization strategy is the optimization strategy provided by the binary translator. The binary translator is configured to enable the target optimization strategy. In this way, by automatically selecting the target optimization strategy for the client program that the binary translator is running this time, and configuring the binary translator to enable the selected target optimization strategy this time, there is no need for manual operation by the user, so the operation threshold can be lowered and the configuration efficiency can be improved.

[0115] Reference Figure 4 , is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. Figure 4 As shown, the electronic device includes: a processor, a memory, a communication interface and a communication bus.

[0116] The processor, the memory and the communication interface communicate with each other through the communication bus; the memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the binary translation method of the above embodiment. The executable instruction can form a program.

[0117] An embodiment of the present invention provides a machine-readable medium having instructions stored thereon, which, when executed by one or more processors, enables the processors to execute the binary translation method of the aforementioned embodiment.

[0118] An embodiment of the present invention provides a binary translation program product, on which instructions are stored. When executed by one or more processors, the processors are enabled to execute the binary translation method of the above-mentioned embodiment.

[0119] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0120] It will be appreciated by those skilled in the art that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product 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 codes.

[0121] It should be noted that all actions of acquiring signals, information or data in this application are carried out in compliance with the relevant data protection laws and policies of the country where they are located and with the authorization given by the owner of the corresponding device.

[0122] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0123] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing terminal device to operate in a predictable manner, so that the instructions stored in the computer readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0124] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0125] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.

[0126] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are merely used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations.

[0127] Moreover, the terms "include", "comprises" or any other variation thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device that includes a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of more restrictions, an element defined by the sentence "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or terminal device that includes the element.

[0128] The above is a detailed introduction to a binary translation method, a device, an electronic device and one or more readable media provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for a person skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A binary translation method, characterized in that: The method comprises: Obtaining target system information and / or historical operation files of a target program; the target program is a client program currently run by the binary translator, the target system information is used to characterize the operating system adapted by the target program, and the historical operation files are used to record historical operation results of the target program and risk level information of enabled historical optimization strategies; Based on the target system information and / or the historical operation file, an optimization strategy adapted to the target program is selected from the candidate optimization strategies to obtain a target optimization strategy; the candidate optimization strategy is the optimization strategy provided by the binary translator; the target optimization strategy is the optimization strategy used in the process of translating instructions in the target program into host architecture instructions; the target optimization strategy includes: instruction-level optimization strategy, basic block link type optimization strategy and self-modifying code simulation optimization strategy; the instruction-level optimization strategy includes merging multiple instructions in the basic block obtained after translation into a composite instruction and deleting the no-operation instructions in the basic block obtained after translation; the basic block link type optimization strategy includes setting the link type of the basic block whose jump number is greater than a preset adjustment number threshold to a direct link; the self-modifying code simulation optimization strategy includes discarding the basic block that has been translated in the code cache when a code modification operation on the basic block is detected, then re-translating the basic block, putting the re-translated basic block into the code cache, and then executing the re-translated basic block; Before translating the target program, configuring the binary translator to enable the target optimization strategy; Switching between the target optimization strategies during binary translation of the target program.

2. The method according to claim 1, characterized in that The step of selecting an optimization strategy adapted to the target program from among the selected optimization strategies based on the target system information and / or the historical operation file includes: Based on the target system information and the specific operating system information of the selected optimization strategy, selecting a first optimization strategy adapted to the target program; the specific operating system information is used to characterize the specific operating system adapted to the selected optimization strategy; And / or, based on the historical operation file and the risk level information of the selected optimization strategy, a second optimization strategy adapted to the target program is selected.

3. The method according to claim 2, characterized in that The selecting, based on the target system information and the specific operating system information of the selected optimization strategy, a first optimization strategy adapted to the target program includes: From the predefined first policy groups, determine a first policy group whose corresponding operating system information is consistent with the target system information as the target group; one of the first policy groups corresponds to a type of operating system information, and one of the first policy groups includes a candidate optimization policy whose specific operating system information is consistent with the operating system information corresponding to the first policy group; The candidate optimization strategy included in the target group is determined as the first optimization strategy.

4. The method according to claim 2, characterized in that: The selecting, based on the historical operation file and the risk level information of the selected optimization strategy, a second optimization strategy adapted to the target program includes: In the case that the historical operation file is not empty, the risk level information of the historical optimization strategy recorded in the historical operation file is used as the level information to be selected, and based on the historical operation results corresponding to the level information to be selected, the number of historical operation failures corresponding to the level information to be selected is determined; Based on the number of historical operation failures, target level information is selected from the to-be-selected level information and the next risk level information of the to-be-selected level information; the risk level indicated by the next risk level information is lower than the risk level indicated by the to-be-selected level information; The candidate optimization strategy whose risk level information is the target level information is determined as the second optimization strategy.

5. The method according to claim 4, characterized in that The determining, based on the historical operation results corresponding to the to-be-selected level information, the number of historical operation failures corresponding to the to-be-selected level information includes: Determine the number of results indicating operation failure in the most recent N historical operation results corresponding to the selected level information, and obtain the number of historical operation failures; N is a positive integer; The selecting target level information from the to-be-selected level information and the next risk level information of the to-be-selected level information based on the historical number of operation failures includes: When the number of historical operation failures is greater than a preset number threshold, the next risk level information is used as the target level information; When the number of historical operation failures is not greater than the preset number threshold, the to-be-selected level information is used as the target level information.

6. The method according to claim 4, characterized in that The risk level information of the selected optimization strategy is an identifier of the second strategy group to which the selected optimization strategy belongs, and one of the second strategy groups includes the selected optimization strategies whose corresponding risk levels are compatible with the risk level represented by the second strategy group; The step of determining the candidate optimization strategy with the risk level information being the target level information as the second optimization strategy includes: The candidate optimization strategy included in the second strategy group represented by the target level information is determined as the second optimization strategy.

7. The method according to any one of claims 2 to 6, characterized in that: The method further comprises: After the current operation is completed, the operation result of the current operation is determined as a new historical operation result, and the risk level information of the second optimization strategy is determined as the risk level information of the new historical optimization strategy; The new historical operation results and the risk level information of the new historical optimization strategy are correspondingly written into the historical operation file.

8. The method according to any one of claims 1 to 6, characterized in that: The configuring the binary translator to enable the target optimization strategy includes: For any of the target optimization strategies, determining the designated states corresponding to the optimization functions corresponding to the target optimization strategy according to the configuration mode corresponding to the target optimization strategy; The environment variables corresponding to the optimization functions are set to the specified states corresponding to the optimization functions, so as to control the binary translator to enable the target optimization strategy.

9. A binary translation device, characterized in that: The device comprises: An acquisition module, used to acquire target system information and / or historical operation files of a target program; the target program is a client program currently run by the binary translator, the target system information is used to characterize the operating system adapted by the target program, and the historical operation files are used to record historical operation results of the target program and risk level information of enabled historical optimization strategies; A selection module is used to select an optimization strategy adapted to the target program from the candidate optimization strategies based on the target system information and / or the historical operation file to obtain a target optimization strategy; the candidate optimization strategy is the optimization strategy provided by the binary translator; the target optimization strategy is the optimization strategy used in the process of translating instructions in the target program into host architecture instructions; the target optimization strategy includes: instruction-level optimization strategy, basic block link type optimization strategy and self-modifying code simulation optimization strategy; the instruction-level optimization strategy includes merging multiple instructions in the basic block obtained after translation into a composite instruction and deleting the no-operation instructions in the basic block obtained after translation; the basic block link type optimization strategy includes setting the link type of the basic block whose jump number is greater than a preset adjustment number threshold to a direct link; the self-modifying code simulation optimization strategy includes discarding the basic block that has been translated in the code cache when a code modification operation on the basic block is detected, then re-translating the basic block, putting the re-translated basic block into the code cache, and then executing the re-translated basic block; A configuration module is used to configure the binary translator to enable the target optimization strategy before translating the target program; wherein, the target optimization strategies are switched during the binary translation of the target program.

10. An electronic device, characterized in that: include: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store executable instructions, and when the executable instructions are executed by the processor, the processor executes the method according to any one of claims 1 to 8.

11. A binary translation program product, characterized in that: The method comprises instructions which, when executed by one or more processors, cause the processors to perform the method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • RISCV instruction set binary translation and dynamic optimization method

    CN116795376A

  • Display device, server and OTA upgrading method

    CN117544810A