Execution method and device of virtual machine exception handling instruction, equipment and medium
By establishing exception processing stack frames in the virtual machine and writing instruction addresses, the problem of low efficiency in the virtual machine's exception handling is solved, and the abnormal location is quickly positioned and system performance is improved.
Patent Information
- Application Number
- CN202411196808.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-29
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2044-08-29
AI Technical Summary
Existing virtual machines are less efficient when handling exceptions, making it difficult to quickly locate the command locations where exceptions occur, affecting system performance.
During the execution of the program by the virtual machine, an exception processing stack frame is established when an exception monitoring instruction is detected and the instruction address is written into it, so that the exception location is quickly positioned through the pre-constructed stack frame when the exception occurs.
It improves the efficiency of virtual machine exception handling, can quickly locate the command location where exceptions occur, and improves the system's exception handling capabilities.
Smart Images

Figure CN119088506A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, device, equipment and medium for executing a virtual machine exception handling instruction. Background Art
[0002] WebAssembly (Wasm for short) is a virtual instruction set architecture. Programs written in languages such as C / C++ can be compiled and run safely and quickly on the Web (World Wide Web) platform. When the C-based WebAssembly virtual machine technology is applied to computer devices such as smart cards, the virtual machine needs to support exception handling mechanisms and maximize the efficiency of virtual machine exception handling. Summary of the invention
[0003] The present invention provides a method, device, equipment and medium for executing a virtual machine exception handling instruction, which can effectively improve the efficiency of virtual machine exception handling.
[0004] According to one aspect of the present invention, a method for executing a virtual machine exception handling instruction is provided, the method comprising:
[0005] During the process of executing the program in the virtual machine, when it is detected that the current function executes the exception monitoring instruction normally, an exception handling stack frame corresponding to the exception monitoring instruction is established;
[0006] The instruction address of the exception monitoring instruction is written into the established exception handling stack frame.
[0007] According to another aspect of the present invention, a device for executing a virtual machine exception handling instruction is provided, the device comprising:
[0008] The exception stack frame establishment module is used to establish an exception handling stack frame corresponding to the exception monitoring instruction when it is detected that the current function executes the exception monitoring instruction normally during the process of executing the program in the virtual machine;
[0009] The instruction address writing module is used to write the instruction address of the exception monitoring instruction into the established exception handling stack frame.
[0010] According to another aspect of the present invention, a computer device is provided, characterized in that the computer device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the execution method of the virtual machine exception handling instruction described in any embodiment of the present invention.
[0011] According to another aspect of the present invention, a computer-readable storage medium is provided, characterized in that the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the execution method of the virtual machine exception handling instruction described in any embodiment of the present invention when executing.
[0012] The technical solution provided by the embodiment of the present invention provides a C language-based WebAssembly virtual machine exception handling method, which can quickly locate the instruction position of the exception through a pre-built exception handling stack frame when the virtual machine runs an exception and detects that the current function executes the exception monitoring instruction normally during the process of executing the program in the virtual machine, thereby improving the efficiency of the virtual machine exception handling.
[0013] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0015] Figure 1 It is a flowchart of a method for executing a virtual machine exception handling instruction provided according to an embodiment of the present invention;
[0016] Figure 2a is a flowchart of another method for executing a virtual machine exception handling instruction provided according to an embodiment of the present invention;
[0017] Figure 2b It is a flow chart of a method for handling an exception of a virtual machine when the virtual machine runs abnormally according to an embodiment of the present invention;
[0018] Figure 2c It is a flow chart of a method for handling an exception of a virtual machine when the virtual machine runs abnormally according to an embodiment of the present invention;
[0019] Figure 3 It is a structural schematic diagram of a device for executing a virtual machine exception handling instruction provided by an embodiment of the present invention;
[0020] Figure 4It is a structural schematic diagram of a computer device provided according to an embodiment of the present invention. DETAILED DESCRIPTION
[0021] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only 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 should fall within the scope of protection of the present invention.
[0022] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0023] Figure 1 The present invention provides a flowchart of a method for executing a virtual machine exception handling instruction. The present invention can be applied to the case of controlling a virtual machine to execute an exception handling instruction. The method can be executed by an execution device for a virtual machine exception handling instruction. The execution device for the virtual machine exception handling instruction can be configured in a virtual machine. Figure 1 As shown, the method includes:
[0024] Step 110: During the process of executing the program in the virtual machine, when it is detected that the current function executes the exception monitoring instruction normally, an exception handling stack frame corresponding to the exception monitoring instruction is established.
[0025] In this embodiment, during the process of executing a program by the virtual machine, the currently executed function may include an exception handling instruction, and the exception handling instruction may include an exception monitoring instruction try and a paired exception catching instruction catch.
[0026] During the normal execution of the current function, when a certain exception monitoring instruction is executed, an exception handling stack frame corresponding to the exception monitoring instruction may be established.
[0027] Step 120: Write the instruction address of the exception monitoring instruction into the established exception handling stack frame.
[0028] In this embodiment, specifically, after the exception handling stack frame corresponding to the exception monitoring instruction is established, the address (Program Counter, PC) of the exception monitoring instruction in the memory may be written into the exception handling stack frame.
[0029] In a specific embodiment, it is assumed that the program pseudo code is as follows:
[0030]
[0031] When the current function funcA is executed normally to the try1 instruction, an exception handling stack frame corresponding to the try1 instruction may be established, and the instruction address of the try1 instruction may be written into the established exception handling stack frame.
[0032] The advantage of such a setting is that when a virtual machine runs abnormally, the pre-built exception handling stack frame can be used to quickly locate the instruction position where the exception occurs, thereby improving the efficiency of virtual machine exception handling.
[0033] The technical solution provided by the embodiment of the present invention provides a C language-based WebAssembly virtual machine exception handling method, which can quickly locate the instruction position of the exception through a pre-built exception handling stack frame when the virtual machine runs an exception and detects that the current function executes the exception monitoring instruction normally during the process of executing the program in the virtual machine, thereby improving the efficiency of the virtual machine exception handling.
[0034] Figure 2a A flowchart of another method for executing a virtual machine exception handling instruction provided by an embodiment of the present invention is shown in FIG. Figure 2a As shown, the method includes:
[0035] Step 210: During the process of executing the program in the virtual machine, when it is detected that the current function executes the exception monitoring instruction normally, an exception handling stack frame corresponding to the exception monitoring instruction is established.
[0036] Step 220: Write the instruction address of the exception monitoring instruction into the established exception handling stack frame.
[0037] Step 230: Push the normal operation state corresponding to the exception monitoring instruction into the virtual machine operand stack, so that the virtual machine continues to execute the code in the exception monitoring instruction block corresponding to the exception monitoring instruction.
[0038] Specifically, when the current function executes the exception monitoring instruction normally, a zero value may be pushed into the virtual machine operand stack as a normal running state identifier corresponding to the exception monitoring instruction.
[0039] In a specific embodiment, it is assumed that the program pseudo code is as follows:
[0040]
[0041]
[0042] When the current function funcA is executed normally to the try1 instruction, an exception handling stack frame corresponding to the try1 instruction can be established, the instruction address of the try1 instruction can be written into the established exception handling stack frame, and the zero value can be pushed into the virtual machine operand stack as the normal running status identifier corresponding to the try1 instruction, so that the virtual machine continues to execute the code in the exception monitoring instruction block corresponding to try1.
[0043] Step 240: When the current function executes the exception capture instruction normally, the normal running state corresponding to the exception capture instruction is pushed into the virtual machine operand stack, so that the virtual machine skips the exception capture instruction block corresponding to the exception capture instruction during execution and continues to execute the code after the exception capture instruction block.
[0044] In this step, specifically, when the current function executes the exception capture instruction normally, a non-zero value may be pushed into the virtual machine operand stack as a normal running state identifier corresponding to the exception capture instruction.
[0045] In a specific embodiment, taking the above program code as an example, when the current function funcA is executed normally to the catch1 instruction, a non-zero value (such as 1) can be pushed into the virtual machine operand stack as the normal operating status identifier corresponding to the catch1 instruction, and then the virtual machine is made to skip the exception capture instruction block corresponding to catch1 during execution, and continue to execute the code after the exception capture instruction block, such as callB()...
[0046] In one implementation of this embodiment, in the current function, the exception monitoring instruction or the exception catching instruction is nested with at least one level of other exception monitoring instructions and exception catching instructions; or, in the current function, the exception monitoring instruction or the exception catching instruction is not nested with other exception monitoring instructions and exception catching instructions. Specifically, it is assumed that the program pseudo code is as follows:
[0047]
[0048]
[0049] In a function, the try-catch level information of the exception monitoring instruction blocks and exception catching instruction blocks in other exception monitoring instruction blocks is non-first level; the try-catch level information of the exception monitoring instruction blocks and exception catching instruction blocks not in other exception monitoring instruction blocks is first level. The try1 instruction in function funcA is not in other exception monitoring instruction blocks of this function, so the try-catch level information of try1 instruction in function funcA is first level. The try21 instruction in function funcA is not in other exception monitoring instruction blocks of this function, so the try-catch level information of try21 instruction in function funcA is first level; the try22 instruction in function funcA is in the try21 exception monitoring instruction block of this function, so the try-catch level information of try22 instruction in function funcA is non-first level.
[0050] In this embodiment, after establishing the exception handling stack frame corresponding to the exception monitoring instruction, it also includes: writing the level information of the exception monitoring instruction in the current function into the exception handling stack frame; wherein the level information includes the first level or non-first level.
[0051] The level information to which the exception monitoring instruction belongs in the current function can be determined by a running status flag in an exception monitoring instruction block in a virtual machine stack frame corresponding to the function.
[0052] Specifically, before starting to execute the current function, a virtual machine stack frame corresponding to the current function can be established, and in the virtual machine stack frame, the running status flag in the exception monitoring instruction block in the current function is maintained in real time. Before writing the level information of the exception monitoring instruction in the current function into the exception handling stack frame, it also includes: querying the virtual machine stack frame; if the running status flag in the exception monitoring instruction block in the current function is no, then determining that the level information of the exception monitoring instruction in the current function is the first level; if the running status flag in the exception monitoring instruction block in the current function is yes, then determining that the level information of the exception monitoring instruction in the current function is non-first level.
[0053] Among them, when the running status flag in the exception monitoring instruction block in the current function is no, it is used to indicate that the current execution code is not being monitored for exceptions in the current function; when the running status flag in the exception monitoring instruction block in the current function is yes, it is used to indicate that the current execution code is being monitored for exceptions in the current function.
[0054] In a specific embodiment, taking the above program pseudo code as an example, before starting to execute the funcA function, a virtual machine stack frame corresponding to the funcA function can be established, and in the virtual machine stack frame, the running status flag in the exception monitoring instruction block in the funcA function is maintained in real time.
[0055] When the funcA function executes normally to the try1 instruction, an exception handling stack frame corresponding to the try1 instruction can be established, and then the running status flag in the exception monitoring instruction block in the virtual machine stack frame corresponding to the funcA function is queried. Since the try1 instruction is not in other exception monitoring instruction blocks of this function, the running status flag in the exception monitoring instruction block in the virtual machine stack frame is no. Therefore, it can be determined that the try-catch level information to which the try1 instruction belongs in the funcA function is the first level, and this try-catch level information is written into the exception handling stack frame corresponding to the try1 instruction.
[0056] When the funcA() function executes to the catch1 instruction, the exception handling stack frame of the try1 instruction can be popped up. After determining that the try-catch level information of the try1 instruction is the first level through the exception handling stack frame, the running status flag in the exception monitoring instruction block recorded in the virtual machine stack frame of the funcA function can be set to no.
[0057] When the funcA function executes normally to the try21 instruction, an exception handling stack frame corresponding to the try21 instruction can be established, and then the running status flag in the exception monitoring instruction block in the virtual machine stack frame corresponding to the funcA function is queried. Since the try21 instruction is not in other exception monitoring instruction blocks of this function, the running status flag in the exception monitoring instruction block in the virtual machine stack frame is no. Therefore, it can be determined that the try-catch level information to which the try21 instruction belongs in the funcA function is the first level, and this try-catch level information is written into the exception handling stack frame corresponding to the try21 instruction.
[0058] When the funcA function executes normally to the try22 instruction, an exception handling stack frame corresponding to the try22 instruction can be established, and then the running status flag in the exception monitoring instruction block in the virtual machine stack frame corresponding to the funcA function is queried. Since the try22 instruction is in the try21 exception monitoring instruction block of this function, the running status flag in the exception monitoring instruction block in the virtual machine stack frame is yes, it can be determined that the try-catch level information to which the try22 instruction belongs in the funcA function is non-first level, and this try-catch level information is written into the exception handling stack frame corresponding to the try22 instruction.
[0059] In this embodiment, in the virtual machine stack frame, the running status flag in the exception monitoring instruction block in the current function is maintained in real time, including: when the current function executes the exception monitoring instruction normally, the running status flag in the current exception monitoring instruction block in the virtual machine stack frame is set to yes; when the current function executes the exception capture instruction, an exception handling stack frame is popped up; if the level information recorded in the popped exception handling stack frame is the first level, the running status flag in the current exception monitoring instruction block in the virtual machine stack frame is set to no.
[0060] In a specific embodiment, taking the above program pseudocode as an example, when the funcA function is executed normally to the try1 instruction, the running status flag in the exception monitoring instruction block recorded in the virtual machine stack frame corresponding to the funcA function is no. When the bytecode of the try1 instruction is executed, the running status flag in the exception monitoring instruction block in this virtual machine stack frame can be set to yes.
[0061] When the funcA() function executes to the catch1 instruction, the exception handling stack frame of the try1 instruction can be popped up. After determining that the try-catch level information of the try1 instruction is the first level through the exception handling stack frame, the running status flag in the exception monitoring instruction block recorded in the virtual machine stack frame of the funcA function can be set to no.
[0062] When the funcA function is executed normally to the try21 instruction, the running status flag in the exception monitoring instruction block recorded in the virtual machine stack frame corresponding to the funcA function is no. When the bytecode of the try21 instruction is executed, the try-catch level information of the try21 instruction in the funcA function can be written as the first layer into the exception handling stack frame corresponding to the try21 instruction, and the running status flag in the exception monitoring instruction block in this virtual machine stack frame can be set to yes.
[0063] When the funcA function is executed normally to the try22 instruction, the running status flag in the exception monitoring instruction block recorded in the virtual machine stack frame corresponding to the funcA function is yes. When the bytecode of the try22 instruction is executed, the try-catch level information of the try22 instruction in the funcA function as a non-first level can be written into the exception handling stack frame corresponding to the try22 instruction, and there is no need to repeatedly set the running status flag in the exception monitoring instruction block in this virtual machine stack frame to yes.
[0064] When the funcA() function executes to the catch22 instruction, the exception handling stack frame information of the try22 instruction can be popped up. The exception handling stack frame information records the try-catch level information of the try22 instruction, which is not the first level. Therefore, there is no need to clear and set the running status flag in the exception monitoring instruction block recorded in the virtual machine stack frame of the funcA function, that is, keep the running status flag in the exception monitoring instruction block recorded in the virtual machine stack frame of the funcA function as yes.
[0065] When the funcA() function executes to the catch21 instruction, the exception handling stack frame information of the try21 instruction can be popped up. The exception handling stack frame information records that the try-catch level information of the try21 instruction is the first level. Therefore, the running status flag in the exception monitoring instruction block recorded in the virtual machine stack frame of the funcA function needs to be set to no.
[0066] The technical solution provided by the embodiment of the present invention is to establish an exception handling stack frame corresponding to the exception monitoring instruction when it is detected that the current function is executing the exception monitoring instruction normally during the process of executing the program in the virtual machine, and write the instruction address of the exception monitoring instruction into the established exception handling stack frame; the normal operating state corresponding to the exception monitoring instruction is pushed into the virtual machine operand stack, so that the virtual machine continues to execute the code in the exception monitoring instruction block corresponding to the exception monitoring instruction; when the current function is executing the exception capture instruction normally, the normal operating state corresponding to the exception capture instruction is pushed into the virtual machine operand stack, so that the virtual machine skips the exception capture instruction block corresponding to the exception capture instruction during execution, and continues to execute the code after the exception capture instruction block. This technical means can improve the efficiency of virtual machine exception handling.
[0067] Based on the above embodiments, the method also includes: when a virtual machine exception is detected, locating the target virtual machine stack frame, and using the top frame of the exception handling stack frame as the target exception handling stack frame; in the target exception handling stack frame information, obtaining the target instruction address of the target exception monitoring instruction; through the target instruction address, jumping to execute the target exception capture instruction paired with the target exception monitoring instruction, and the code in the exception capture instruction block corresponding to the target exception capture instruction, so as to implement exception handling for the virtual machine.
[0068] Specifically, Figure 2b A flowchart of a method for handling an exception of a virtual machine when the virtual machine runs abnormally in this embodiment may be provided. The method includes:
[0069] Step 211, when a virtual machine exception is detected, trace back the virtual machine stack frame information from the top of the virtual machine stack to the bottom of the stack, obtain the virtual machine stack frame with the running status flag of yes in the first exception monitoring instruction block in the virtual machine stack frame information, and use the virtual machine stack frame as the target virtual machine stack frame.
[0070] In this embodiment, when an exception occurs during the operation of a virtual machine, the virtual machine stack frame information can be traced back from the top of the virtual machine stack to the bottom of the stack to find the virtual machine stack frame with a running status flag of yes in the first exception monitoring instruction block. If it exists, this virtual machine stack frame is used as the target virtual machine stack frame.
[0071] Step 212: Use the top frame of the exception handling stack frame as the target exception handling stack frame.
[0072] Step 213: Obtain the target instruction address of the target exception monitoring instruction in the target exception processing stack frame information.
[0073] Step 214: Use the target instruction address as the current execution address to restore the virtual machine operating environment to the target instruction address.
[0074] Step 215: Push the non-zero value as the abnormal operation state identifier corresponding to the target abnormal monitoring instruction into the virtual machine operand stack.
[0075] In this step, specifically, when the target exception monitoring instruction is executed after the program has an exception, a non-zero value (such as 1) can be pushed into the virtual machine operand stack as an abnormal running state identifier corresponding to the target exception monitoring instruction.
[0076] Step 216: After determining through a conditional jump instruction that the abnormal operation status flag of the target abnormal monitoring instruction pushed into the virtual machine operand stack is a non-zero value, skip the abnormal monitoring instruction block corresponding to the target abnormal monitoring instruction and execute the target abnormal capture instruction paired with the target abnormal monitoring instruction.
[0077] Step 217: When executing the target exception capture instruction, a zero value is pushed into the virtual machine operand stack as the abnormal operation status identifier corresponding to the target exception capture instruction. Through a conditional jump instruction, it is determined that the abnormal operation status identifier pushed into the virtual machine operand stack by the target exception capture instruction is a zero value, and then the code in the exception capture instruction block corresponding to the target exception capture instruction continues to be executed.
[0078] In this embodiment, when executing the target exception capture instruction, it also includes: obtaining the level information of the target exception monitoring instruction in the target function in the target exception handling stack frame information; determining whether the level information of the target exception monitoring instruction in the target function is the first level; if so, setting the running status flag in the target exception monitoring instruction block in the target virtual machine stack frame to no.
[0079] In this embodiment, the conditional jump virtual machine instruction includes two virtual machine instructions, br_if_u16 and br_if_fw_u8.
[0080] In a specific embodiment, it is assumed that the program pseudo code is as follows:
[0081]
[0082] If an exception occurs when the program executes the callA() function in the exception monitoring instruction block corresponding to try1, and the running status in the exception monitoring instruction block is not set in the virtual machine stack frame information of the callA() function, find out that the running status flag in the exception monitoring instruction block in the stack frame information of the previous virtual machine stack frame funcA() function is yes, read the top frame information of the exception handling stack frame, use the instruction address recorded in the above-read exception handling stack frame information as the current execution address, restore the virtual machine running environment to the try1 instruction position to start execution, push the exception running status identifier 1 corresponding to the try1 instruction into the operand stack, skip the exception monitoring instruction block corresponding to the try1 instruction through the conditional jump instruction br_if_u16 or br_if_fw_u8, and execute the catch1 instruction. When executing the catch1 instruction, the top frame of the exception handling stack frame is popped out as the target exception handling stack frame. After determining that the try-catch level information in the target exception handling stack frame information is the first level, the running status flag in the exception monitoring instruction block recorded in the virtual machine stack frame of the funcA() function can be set to no, and the exception running status flag 0 corresponding to the catch1 instruction is pushed into the operand stack, and the conditional jump instruction br_if_u16 or br_if_fw_u8 is used to jump into the exception capture instruction block corresponding to catch1, and the code in the exception capture instruction block continues to be executed.
[0083] By recording the running flag in the exception monitoring instruction block in the virtual machine stack frame information, combined with the exception monitoring instruction address and try-catch level status recorded in the exception handling stack frame, when an exception occurs during the running of the virtual machine program, the function where the exception monitoring instruction is located can be quickly retrieved, thereby improving the exception handling efficiency.
[0084] Based on the above embodiment, when a virtual machine exception is detected, if there is no virtual machine stack frame with a running status flag of yes in the exception monitoring instruction block in the virtual machine stack frame information, the operation of the virtual machine is terminated.
[0085] Figure 2c is another flow chart of a method for handling an exception of a virtual machine when the virtual machine runs abnormally in this embodiment, such as Figure 2c As shown, the method may include:
[0086] After detecting a virtual machine exception, start looking for an exception handling point;
[0087] Determine whether the running status flag in the exception monitoring instruction block in the current virtual machine stack frame is yes;
[0088] If yes, use the top frame of the exception handling stack frame as the target exception handling stack frame; read the instruction address recorded in the target exception handling stack frame information as the target exception monitoring instruction address, and restore the virtual machine operating environment to the target exception monitoring instruction address to start execution;
[0089] If not, determine whether the current virtual machine stack frame is at the bottom of the stack. If so, terminate the virtual machine operation; if not, trace back the virtual machine stack frame information from the top of the virtual machine stack to the bottom of the stack, obtain the previous virtual machine stack frame, and return to execute the operation to determine whether the running status flag in the exception monitoring instruction block in the current virtual machine stack frame is yes.
[0090] Figure 3 A schematic diagram of the structure of a device for executing a virtual machine exception handling instruction provided by an embodiment of the present invention includes: an exception stack frame establishing module 310 and an instruction address writing module 320.
[0091] The exception stack frame establishment module 310 is used to establish an exception handling stack frame corresponding to the exception monitoring instruction when it is detected that the current function executes the exception monitoring instruction normally during the process of executing the program in the virtual machine;
[0092] The instruction address writing module 320 is used to write the instruction address of the exception monitoring instruction into the established exception handling stack frame.
[0093] The technical solution provided by the embodiment of the present invention provides a C language-based WebAssembly virtual machine exception handling method, which can quickly locate the instruction position of the exception through a pre-built exception handling stack frame when the virtual machine runs an exception and detects that the current function executes the exception monitoring instruction normally during the process of executing the program in the virtual machine, thereby improving the efficiency of the virtual machine exception handling.
[0094] Based on the above embodiments, in the current function, at least one level of other exception monitoring instructions and exception capture instructions are nested in the exception monitoring instruction or the exception capture instruction; or, in the current function, other exception monitoring instructions and exception capture instructions are not nested in the exception monitoring instruction or the exception capture instruction.
[0095] The abnormal stack frame building module 310 includes:
[0096] A level information writing unit is used to write the level information to which the exception monitoring instruction belongs in the current function into the exception handling stack frame; wherein the level information includes the first level or the non-first level.
[0097] The device also includes:
[0098] A normal state recording module is used to, when the current function executes the abnormal monitoring instruction normally, push the normal operating state corresponding to the abnormal monitoring instruction into the virtual machine operand stack; enable the virtual machine to continue to execute the code in the abnormal monitoring instruction block corresponding to the abnormal monitoring instruction; when the current function executes the abnormal capture instruction normally, push the normal operating state corresponding to the abnormal capture instruction into the virtual machine operand stack; enable the virtual machine to skip the abnormal capture instruction block corresponding to the abnormal capture instruction during execution, and continue to execute the code after the abnormal capture instruction block;
[0099] A virtual machine stack frame establishment module, used to establish a virtual machine stack frame corresponding to the current function before starting to execute the current function; and in the virtual machine stack frame, to maintain in real time the running status flag in the abnormal monitoring instruction block in the current function;
[0100] A layer determination module, used for querying the virtual machine stack frame when executing the abnormal monitoring instruction normally; if the running status flag in the abnormal monitoring instruction block in the current function is no, then determining that the layer information to which the abnormal monitoring instruction belongs in the current function is the first layer; if the running status flag in the abnormal monitoring instruction block in the current function is yes, then determining that the layer information to which the abnormal monitoring instruction belongs in the current function is non-first layer;
[0101] Wherein, when the running status flag in the abnormal monitoring instruction block in the current function is no, it is used to identify that the current execution code is not being abnormally monitored in the current function; when the running status flag in the abnormal monitoring instruction block in the current function is yes, it is used to identify that the current execution code is being abnormally monitored in the current function;
[0102] The state maintenance module is used to set the running state flag in the current exception monitoring instruction block in the virtual machine stack frame to yes when the current function executes the exception monitoring instruction normally; pop up an exception handling stack frame when the current function executes the exception capture instruction; if the level information recorded in the popped exception handling stack frame is the first level, set the running state flag in the current exception monitoring instruction block in the virtual machine stack frame to no;
[0103] The exception handling module is used to locate the target virtual machine stack frame when a virtual machine exception is detected, and use the top frame of the exception handling stack frame as the target exception handling stack frame; obtain the target instruction address of the target exception monitoring instruction in the target exception handling stack frame information; through the target instruction address, jump to execute the target exception capture instruction paired with the target exception monitoring instruction, and the code in the exception capture instruction block corresponding to the target exception capture instruction, so as to realize the exception handling of the virtual machine.
[0104] The normal state recording module comprises:
[0105] A zero value recording unit, used for pushing a zero value as a normal operating state identifier corresponding to the abnormal monitoring instruction into a virtual machine operand stack when the current function executes the abnormal monitoring instruction normally;
[0106] The non-zero value recording unit is used to push the non-zero value into the virtual machine operand stack as a normal running state identifier corresponding to the exception capture instruction when the current function executes the exception capture instruction normally.
[0107] The exception handling module includes:
[0108] a target virtual machine stack frame determination unit, configured to trace back virtual machine stack frame information from the top of the virtual machine stack to the bottom of the stack, obtain a virtual machine stack frame whose running status flag is yes in the first abnormal monitoring instruction block in the virtual machine stack frame information, and use the virtual machine stack frame as the target virtual machine stack frame;
[0109] An exception capture instruction block execution unit is used to use the target instruction address as the current execution address to restore the virtual machine operating environment to the target instruction address; when executing the target exception monitoring instruction, a non-zero value is pushed into the virtual machine operand stack as the abnormal operation status identifier corresponding to the target exception monitoring instruction; through a conditional jump instruction, after judging that the abnormal operation status identifier pushed into the virtual machine operand stack by the target exception monitoring instruction is a non-zero value, the exception monitoring instruction block corresponding to the target exception monitoring instruction is skipped, and the target exception capture instruction paired with the target exception monitoring instruction is executed; when executing the target exception capture instruction, a zero value is pushed into the virtual machine operand stack as the abnormal operation status identifier corresponding to the target exception capture instruction; through a conditional jump instruction, after judging that the abnormal operation status identifier pushed into the virtual machine operand stack by the target exception capture instruction is a zero value, the code in the exception capture instruction block corresponding to the target exception capture instruction is continued to be executed;
[0110] A running status flag setting unit is used to obtain the layer information of the target exception monitoring instruction in the target function in the target exception handling stack frame information; determine whether the layer information of the target exception monitoring instruction in the target function is the first layer; if so, set the running status flag in the target exception monitoring instruction block in the target virtual machine stack frame to no;
[0111] The virtual machine termination unit is used to terminate the operation of the virtual machine if there is no virtual machine stack frame with a running status flag of yes in the abnormal monitoring instruction block in the virtual machine stack frame information.
[0112] The above device can execute the methods provided by all the above embodiments of the present invention, and has the corresponding functional modules and beneficial effects of executing the above methods. For technical details not fully described in the embodiments of the present invention, please refer to the methods provided by all the above embodiments of the present invention.
[0113] Figure 4 A schematic diagram of a computer device structure that can be used to implement an embodiment of the present invention is shown. The virtual machine can be loaded into various forms of digital computers in the form of a computer program, such as a laptop computer, a desktop computer, a workbench, a personal digital assistant, a server, a blade server, a mainframe computer, and other suitable computers. The virtual machine program can also be loaded into a mobile device, such as a personal digital processing, a cellular phone, a smart phone, a wearable device (such as a helmet, glasses, a watch, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0114] like Figure 4 As shown, the computer device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a non-volatile memory (NVM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the non-volatile memory (NVM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the computer device 10 can also be stored. The processor 11, the NVM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0115] A number of components in the computer device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the computer device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0116] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The processor 11 executes the various methods and processes described above, such as the execution method of the virtual machine exception handling instruction.
[0117] In some embodiments, the execution method of the virtual machine exception handling instruction may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the computer device 10 via the NVM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the execution method of the virtual machine exception handling instruction described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the execution method of the virtual machine exception handling instruction by any other appropriate means (e.g., by means of firmware).
[0118] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0119] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0120] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0121] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer device. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0122] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0123] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0124] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0125] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for executing a virtual machine exception handling instruction, characterized in that: include: During the process of executing the program in the virtual machine, when it is detected that the current function executes the exception monitoring instruction normally, an exception handling stack frame corresponding to the exception monitoring instruction is established; Writing the instruction address of the exception monitoring instruction into the established exception handling stack frame; The current function includes exception handling instructions, and the exception handling instructions include exception monitoring instructions and paired exception capturing instructions.
2. The method according to claim 1, characterized in that Also includes: In the current function, the exception monitoring instruction or the exception catching instruction is nested with at least one level of other exception monitoring instructions and exception catching instructions; Alternatively, in the current function, no other exception monitoring instructions or exception catching instructions are nested in the exception monitoring instruction or the exception catching instruction.
3. The method according to claim 2, characterized in that After establishing the exception handling stack frame corresponding to the exception monitoring instruction, it also includes: The level information to which the exception monitoring instruction belongs in the current function is written into the exception handling stack frame; wherein the level information includes the first level or the non-first level.
4. The method according to claim 3, characterized in that Also includes: Before starting to execute the current function, establishing a virtual machine stack frame corresponding to the current function; as well as In the virtual machine stack frame, the running status flag in the exception monitoring instruction block in the current function is maintained in real time.
5. The method according to any one of claims 1 to 4, characterized in that: Also includes: When a virtual machine exception is detected, the target virtual machine stack frame is located, and the top frame of the exception handling stack frame is used as the target exception handling stack frame; In the target exception handling stack frame information, obtaining a target instruction address of a target exception monitoring instruction; Through the target instruction address, the target exception capture instruction paired with the target exception monitoring instruction and the code in the exception capture instruction block corresponding to the target exception capture instruction are jumped to execute, so as to realize the exception handling of the virtual machine.
6. The method according to claim 5, characterized in that When a virtual machine exception is detected, the target virtual machine stack frame is located, including: The virtual machine stack frame information is traced back from the top of the virtual machine stack to the bottom of the stack, and a virtual machine stack frame with a running status flag of yes in the first abnormal monitoring instruction block is obtained from the virtual machine stack frame information, and the virtual machine stack frame is used as the target virtual machine stack frame.
7. The method according to claim 5, characterized in that By using the target instruction address, jumping to execute the target exception capture instruction paired with the target exception monitoring instruction, and the code in the exception capture instruction block corresponding to the target exception capture instruction, including: Using the target instruction address as the current execution address, restoring the virtual machine running environment to the target instruction address; Pushing a non-zero value as an abnormal operation state identifier corresponding to the target abnormal monitoring instruction into the virtual machine operand stack; After judging that the abnormal operation state flag of the target abnormal monitoring instruction pushed into the virtual machine operand stack is a non-zero value through the conditional jump instruction, the abnormal monitoring instruction block corresponding to the target abnormal monitoring instruction is skipped, and the target abnormal capture instruction paired with the target abnormal monitoring instruction is executed; When executing the target exception capture instruction, a zero value is pushed into the virtual machine operand stack as the abnormal operation state identifier corresponding to the target exception capture instruction; Through the conditional jump instruction, after determining that the abnormal operation state identifier of the target abnormal capture instruction pushed into the virtual machine operand stack is zero, continue to execute the code in the abnormal capture instruction block corresponding to the target abnormal capture instruction.
8. A device for executing a virtual machine exception handling instruction, characterized in that: The device comprises: The exception stack frame establishment module is used to establish an exception handling stack frame corresponding to the exception monitoring instruction when it is detected that the current function executes the exception monitoring instruction normally during the process of executing the program in the virtual machine; An instruction address writing module is used to write the instruction address of the exception monitoring instruction into the established exception handling stack frame; The current function includes exception handling instructions, and the exception handling instructions include exception monitoring instructions and paired exception capturing instructions.
9. A computer device, characterized in that: The computer device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the method for executing a virtual machine exception handling instruction according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the execution method of the virtual machine exception handling instruction according to any one of claims 1 to 7 when executing the computer instructions.
Citation Information
Patent Citations
User mode process exception processing method and device, equipment and medium
CN114003470A
Code exception processing method and device
CN117033064A
WebAssessment module exception handling method and device and electronic equipment
CN117667738A
Updating encrypted security context in stack pointers for exception handling and tight bounding of on-stack arguments
US20230018585A1
