CN117112073A - Exception handling method, device, equipment and medium - Google Patents
Exception handling method, device, equipment and medium Download PDFInfo
- Publication number
- CN117112073A CN117112073A CN202210536658.9A CN202210536658A CN117112073A CN 117112073 A CN117112073 A CN 117112073A CN 202210536658 A CN202210536658 A CN 202210536658A CN 117112073 A CN117112073 A CN 117112073A
- Authority
- CN
- China
- Prior art keywords
- function
- program
- abnormal
- language
- program context
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/448—Execution paradigms, e.g. implementations of programming paradigms
- G06F9/4488—Object-oriented
- G06F9/449—Object-oriented method invocation or resolution
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Devices For Executing Special Programs (AREA)
Abstract
The application discloses an exception handling method, an exception handling device, exception handling equipment and an exception handling medium, which generally relate to the technical field of computers, and particularly relate to the field of program exception handling. The method comprises the following steps: when executing a first function based on a first compiling language, calling a second function of a second compiling language to record the program context of the first function; the second compiling language is the same as the code data structure of the first compiling language, the program context is used for representing the current running state of the first function, and the first compiling language is a byte code supporting the running of a browser; and if the first function is abnormal, performing exception handling according to the program context. The exception handling can be realized based on the WebAssemble byte codes, and meanwhile, the running performance of the byte codes can be ensured.
Description
Technical Field
The present disclosure relates generally to the field of computer technology, and in particular, to the field of program exception handling, and in particular, to an exception handling method, apparatus, device, and medium.
Background
WebAssemblely is a new coding mode, can run in a web browser, and can improve the analysis and execution efficiency of programs. Typically, c++ code may be compiled into WebAssembly bytecode by a compilation tool (e.g., emscript).
In the process of compiling C++ codes into byte codes by using Emscripten, if the exception is captured by using try/catch statements in the C++ codes, the same flow is required to be executed after the exception is converted into byte codes. Since relevant standards of WebAssembly byte bytecodes do not give such exception handling flows, when the emscript converts c++ codes into WebAssembly byte bytecodes, an invoke function of JavaScript is usually called to realize the invocation of an actual function, and a try/catch statement calling JavaScript in the execution of the invoke function simulates an exception handling flow in c++ codes.
In the processing scheme, a large number of function calls between the WebAssemble and the JavaScript are involved, and the operation performance of the WebAssemble byte code is seriously affected.
Disclosure of Invention
In view of the foregoing drawbacks or shortcomings in the prior art, it is desirable to provide an exception handling method, apparatus, device, and medium that are capable of ensuring the running performance of bytecodes while implementing exception handling based on WebAssembly bytecodes.
In a first aspect, a method for processing code exception is provided, the method comprising:
when executing the first function based on the first compiling language, calling a second function of the second compiling language to record the program context of the first function; the second compiling language has the same code data structure as the first compiling language, the program context is used for representing the current running state of the first function, and the first compiling language is a byte code supporting the running of the browser;
And if the first function is abnormal, performing exception handling according to the program context.
In a second aspect, there is provided a code exception handling apparatus comprising:
a recording unit for calling a second function of a second compiling language to record a program context of the first function when the first function is executed based on the first compiling language; the second compiling language has the same code data structure as the first compiling language, the program context is used for representing the current running state of the first function, and the first compiling language is a byte code supporting the running of the browser;
and the processing unit is used for carrying out exception processing according to the program context when the first function is abnormal.
In a third aspect, a computer device is provided, comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the method according to the first aspect.
In a fourth aspect, there is provided a computer readable storage medium having stored thereon a computer program which when executed by a processor implements a method as described in the first aspect above.
In a fifth aspect, a computer program product is provided, comprising instructions which, when executed by a processor, implement a method as described in the first aspect above.
The exception handling method, the exception handling device, the exception handling equipment and the exception handling medium provided by the application can call sentences (or functions) of a second compiling language which is the same as a byte code data structure to realize exception handling of byte codes when executing functions which possibly have exceptions based on the first compiling language (for example, byte codes supporting browser operation). Specifically, a function of the second compiling language is called to save the program context of the first function, and when the first function is abnormal, the exception handling is performed based on the saved program context. Because the code data structure of the second compiling language is the same as that of the first compiling language, the function of the second compiling language is called without data structure conversion when the program in the byte code format is executed, the problem of high performance consumption caused by excessive data structure conversion processing introduced by function call is avoided, the abnormal processing of the byte code is realized, the performance consumption caused by function call can be avoided, and the running performance of the byte code is ensured to a great extent.
Additional aspects and advantages of the application will be set forth in part in the description which follows and, in part, will be obvious from the description, or may be learned by practice of the application.
Drawings
Other features, objects and advantages of the present application will become more apparent upon reading of the detailed description of non-limiting embodiments, made with reference to the accompanying drawings in which:
FIG. 1 is a schematic diagram of a system architecture according to an embodiment of the present application;
FIG. 2 is a schematic diagram of an exception call of a bytecode according to an embodiment of the present application;
FIG. 3 is a flowchart illustrating a method for processing code exceptions according to an embodiment of the present application;
FIG. 4 is another flow chart of a method for processing code exceptions according to an embodiment of the present application;
FIG. 5 is a schematic diagram of another byte code exception call provided in an embodiment of the present application;
FIG. 6 is a schematic diagram of code execution provided by an embodiment of the present application;
FIG. 7 is a block diagram of an exception handling apparatus according to an embodiment of the present application;
FIG. 8 is another block diagram of an exception handling apparatus according to an embodiment of the present application;
fig. 9 is a schematic structural diagram of a computer device according to an embodiment of the present application.
Detailed Description
The application is described in further detail below with reference to the drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the application and are not limiting of the application. It should be noted that, for convenience of description, only the portions related to the application are shown in the drawings.
It should be noted that, without conflict, the embodiments of the present application and features of the embodiments may be combined with each other. The application will be described in detail below with reference to the drawings in connection with embodiments.
First, terms related to the embodiments of the present application will be described:
(1) Compiled language
The compiled language, which may also be referred to as a programming language, is the language that a computer is able to recognize, and is also the underlying guarantee that a computer is able to run. For example, webAssembly bytecode, javaScript, c++, C, etc. related to the embodiment of the present application are all compiled languages that can be recognized by a computer, and the computer can execute codes written by means of the compiled languages to implement various functions.
(2) Exception handling
An Exception (Exception) in an embodiment of the present application may refer to an error that occurs when a code (or function) is executed. Further, exception handling (Exception handling) may also be performed to separate business logic from exception handling, avoiding the business logic from being affected by the exception handling.
Exception handling may employ a continuous running mode, i.e., when an exception occurs in function execution, the current operating environment is restored, and the code node where the error occurred is restored. In this way, exceptions can be avoided when the desired function is executed again, providing the possibility for correct execution of the program.
(3) try/catch statement
the try/catch statement is an exception handling statement used in JavaScript in its entirety. Where try is used to declare a function for which an exception may exist, e.g., a statement (or function) within a try statement is used to write the exception. The catch statement is used for filling out the captured exception types and the processing method of the exception. the basic syntax of the try/catch statement is as follows:
fig. 1 is a system architecture to which an embodiment of the present application is applicable. Referring to FIG. 1, the system includes hardware 10 and an operating system 20. The hardware 10 is an entity on which the system works, and includes a display, a keyboard, a mouse, a hard disk, a CPU, a motherboard, and the like; the operating system 20 is the first layer of software running on the hardware 10 and is the bridge for the hardware 10 to communicate with other software. In addition, virtual machines adapted to the respective compiled languages are run on the operating system 20. For example, the WebAssembly virtual machine 30 and JavaScript virtual machine 40 shown in fig. 1. Various programs compiled by the WebAssembly byte codes are run on the WebAssembly virtual machine 30, and various programs compiled by the JavaScript language are run on the JavaScript virtual machine 40.
The system shown in fig. 1 may be a computer device, which may be an independent physical computer, or may be a device cluster or a distributed system formed by a plurality of physical computers, or may be a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery network (content delivery network, CDN), and basic cloud computing services such as big data and artificial intelligence platforms.
Currently, in compiling the c++ code into the WebAssembly byte code, if the exception is captured in the c++ code by using try/catch statements, the WebAssembly virtual machine 30 typically calls JavaScript-associated invoke functions to implement the call to the actual functions, and calls the try/catch statements of the Java Script in the execution of the invoke functions to simulate the exception handling flow in the c++ code.
For example, when the original C++ code executes a try function, it is desirable to jump to a catch function. The specific codes are as follows:
when the WebAssembly virtual machine 30 converts the code into the byte code, a function which may be abnormal may be written into the invoke function, and then the invoke function is called to simulate the try/catch flow in the c++ code. A specific call flow is shown in fig. 2. Referring to fig. 2, when the WebAssembly virtual machine 30 calls an invoke function based on a bytecode, it is first switched to the JavaScript virtual machine 40, calls a glue function try of JavaScript based on JavaScript, and nests an actual bytecode function dynamics through the try function. After executing the try function, the JavaScript virtual machine 40 switches to the WebAssembly virtual machine 30 to execute the function dynamics. When the dynamic is abnormal, the jump to the JavaScript virtual machine 40 calls the glue function cxa _throw of JavaScript to throw out the anomaly identification (ptr). Further, the JavaScript virtual machine 40 jumps to the catch code block of the JavaScript invoke function, that is, calls the glue function catch of JavaScript to restore the current running environment, and returns to the code node (namely, dynamic) where the error occurs. It may also be followed by a jump to the WebAssembly virtual machine 30 to record exceptions based on the bytecode call setthread function (output "1").
In the exception handling scheme based on the byte code, a great amount of function calls are related between the WebAssemble virtual machine and the JavaScript virtual machine, and because the data structures supported by the WebAssemble virtual machine and the JavaScript virtual machine are different from each other, complex data structure conversion processing is required to realize the function calls between the WebAssemble virtual machine and the JavaScript virtual machine, so that the operation performance of the byte code is seriously influenced.
Based on the above, the application provides an exception handling method, an exception handling device, an exception handling equipment and an exception handling medium, which can ensure the running performance of byte codes while realizing the exception handling of the byte codes.
Fig. 3 is a schematic flow chart of an exception handling method according to an embodiment of the present application, where an execution body of the method may be a computer device as described above, or may be a WebAssembly virtual machine 30 running on the computer device. As shown in fig. 3, the method comprises the steps of:
301. when executing the first function based on the first compiling language, calling a second function of the second compiling language to record the program context of the first function; the second compiling language is the same as the code data structure of the first compiling language;
the first compiled language may be a bytecode supporting browser operation, for example, webAssembly bytecode. The first function may be a function in which an abnormality may occur.
It can be appreciated that when the bytecode involves exception handling, some statements (e.g., try/catch) of JavaScript may be generally called to perform exception handling, but this often causes a significant function call overhead, which seriously affects the running performance of the bytecode. In order to avoid the problem, the embodiment of the application selects proper exception handling statements when executing byte codes, and reduces the performance consumption caused by calling the exception handling statements. For example, when executing a function that may be abnormal based on the bytecode, the same statement as the bytecode data structure may be called for exception handling. For example, when a first function is executed based on a first compiled language (e.g., bytecode), statements of a second compiled language homologous to the first compiled language are called for exception handling. The code data structures of the second compiling language are identical (or close), and can run in the same compiling tool, and function call is performed without data structure conversion processing. Therefore, the exception processing statement of the second compiling language is called to realize the exception processing of the byte codes, and the performance consumption caused by the inter-calling among the statements in different compiling languages can be reduced.
In one possible implementation, exception handling may be in a manner that continues to run, i.e., when an exception occurs to function execution, the current operating environment is restored and the code node that has the error is returned. Therefore, when the related statement of the second compiling language is called to process the exception of the first function, the function of the second compiling language can be called to save the current running state of the first function so as to carry out the exception processing of the first function in a continuous running mode.
For example, a function for exception handling in the second compiled language may be selected to preserve the program context of the first function. For example, the second function may be a setjmp function, which belongs to a library of C-language functions, and may be considered as a function of C-language, capable of recording the context of the program in a cache.
In step 301, a second function is called to record the current program context, so that the running state of the program can be restored according to the saved program context when the first function is abnormal.
It should be noted that, the program context is used to characterize the current running state of the first function, and may also be referred to as a program context. In one possible implementation, the program context of the first function may be a set of external variables that are currently required to maintain the first function operating properly. For example, the program context may include a current value of a pointer (BP) register, a current value of a Stack Pointer (SP) register, and a current value of a Program Counter (PC) register.
302. And if the first function is abnormal, performing exception handling according to the program context.
The first function exception may be an exception of the execution result of the first function, for example, the first function execution result is an error (error).
In the embodiment of the application, when the first function is abnormal, the running state of the first function can be recovered according to the context stored by the second function, namely, the abnormality processing is carried out in a continuous mode.
In a specific implementation, when the first function is abnormal, the corresponding cache can be read, and the program context recorded in the cache can be obtained.
In one possible implementation, the program context includes a BP register value, a SP register value, and a PC register value when executing the first function based on the first compilation language. When performing exception handling, the running state of the program may be reset according to the register values, and the program running node may be restored to the state before the exception occurs, for example, the first function may be re-executed.
In the embodiment of the application, when executing the function which may be abnormal based on the byte code (namely the first compiling language), the statement (function) of the second compiling language which is the same as the byte code data structure can be called to realize the abnormal processing of the byte code. Specifically, a function of the second compiling language is called to save the program context of the first function, and when the first function is abnormal, the exception handling is performed based on the saved program context. Because the code data structure of the second compiling language is the same as that of the first compiling language, the function calling the second compiling language does not need to carry out data structure conversion when the byte code is executed, the problem of large performance consumption caused by excessive data structure conversion processing introduced by function calling is avoided, the abnormal processing of the byte code is realized, the performance consumption caused by function calling can be avoided, and the running performance of the byte code is ensured to a great extent.
In another embodiment of the present application, a specific implementation of invoking the second function to record the program context is also provided. Illustratively, the specific implementation of "calling the second function of the second compiled language to record the program context of the first function" referred to above includes: and calling a second function, and writing the program context of the first function into a cache region corresponding to the second function.
That is, the second function may be a nested function of the first function, and when the first function is executed based on the first compiled language, the next execution node of the program is the second function. The second function may be a function for saving the program context in the exception handling statement, the function being provided with a corresponding cache area. The current program context may be written to the corresponding cache region as the function executes.
In one possible implementation, the second function is a setjmp function, and when the setjmp function is executed, the current program context may be written into the cache jmp_buf corresponding to the setjmp function. Specifically, jmp_buf includes an object j, and when setjmp functions are executed, the program context of the first function may be written into the object j, so as to implement recording of the program context.
In the embodiment of the application, the program context of the function which is possibly abnormal can be written into the cache when the second function is executed, so that the abnormal processing can be carried out based on the program context in the cache when the function is actually abnormal, the program is prevented from being blocked, and the normal execution of the program after the abnormal occurrence is ensured.
In another embodiment of the present application, the first function may be used to declare a function that is likely to be abnormal, e.g., a function that is nested by the first function is a function that is likely to be abnormal. Specifically, nested under the first function is a second function, and nested under the second function is the function which may be abnormal. And judging whether the function which is possibly abnormal can be executed according to the return value of the second function. For example, if the return value of the second function is the first state value, then the function nested by the first function is executed.
That is, after a second function of the second compiled language is called to record the program context of the first function, a return value of the second function is obtained; and if the return value of the second function is the first state value, executing the function which is nested by the first function and is likely to be abnormal. Further, if the function which may be abnormal has an execution error, it is determined that the first function is abnormal.
In one possible implementation, the first state value is "0" or "false". The embodiment of the application does not limit the specific implementation of the first state value, and any parameter which can trigger the function which is nested by the first function and is possibly abnormal belongs to the first state value in the embodiment of the application.
In one possible implementation, the code that records the exception may also be nested in the first function. Specifically, the first tier execution logic is a first function, the second tier execution logic is a second function, and the second function is a third tier execution logic. The third layer of execution logic comprises two parallel execution logic, namely a function which can possibly generate an exception and a function which records the exception, and is executed alternatively according to the return value of the second function. Wherein, the logical relationship between the function in which the abnormality may occur and the function in which the abnormality is recorded may be if/else.
For example, when executing the first function based on the first compiling language, firstly calling the second function, and if the return value of the second function is the first state value, executing the function nested by the first function; if the return value of the second function is the second state value, jumping to the code recording the abnormality.
Taking the first function as an invoke function, the first function nested function as a dynamics function (i.e. a function in which an exception may occur), and the second function as a setjmp function as an example, the execution relationship between the three functions can be represented by the following code:
that is, the Invoke function is executed first, and then the Setjmp function nested by the Invoke function is executed. If the return value of the Setjmp function is 0, executing a dyncall function; conversely, if the return value of the Setjmp function is "1", the setThrew function is executed. Wherein setThiew is a function of the recording anomaly. If an abnormality occurs, returning to '1'; otherwise, return to "0".
In another embodiment of the present application, when an abnormality occurs in the program actually, a recorded program context may be acquired, so as to reset the running state of the program according to the program context, and restore to the running state before the abnormality occurs. Exemplary, the specific implementation of the foregoing "performing exception handling according to the program context when the first function is abnormal" includes: when the first function is abnormal, calling a third function of the second compiling language to jump to the second function; executing the second function again may obtain the previously recorded program context, and further, the running state of the first function may be reset according to the obtained program context, that is, the running state of the first function may be restored to before the occurrence of the abnormality.
That is, after the program is abnormal, the program node can be reset, so that the program execution flow jumps to the abnormal state again, the program is prevented from being blocked, and the possibility is provided for normal execution of the program.
In one possible implementation, the third function may be the same jump function as the first compiled language data structure. For example, it may be a longjmp function of the second compiled language. In a specific implementation, the function of longjmp is to jump the program node to the object j set by setjmp in the goto manner, that is, call longjmp to jump to setjmp, execute setjmp again to acquire the object j (i.e. the program context) recorded in the corresponding cache, and reset the program execution state according to the acquired content.
In an embodiment of the present application, the second function (e.g., setjmp) has two types of return values, namely the first state value and the second state value described above. When setjmp is executed to set object j, the second function logger context is executed, with setjmp returned to a value of "0" (i.e., the first state value described above); but when setjmp is invoked as the target of a long jump (longjmp), the return value of setjmp is "1" (i.e., the second state value described previously).
That is, invoking the third function jumps to the second function, and after executing the second function to obtain the previously recorded program context, the return value of the second function may also be obtained. At this time, the second function is targeted for long jumps of the longjmp function, and the value returned after the execution of the second function should be the second state value.
Further, a next running node of the program may be determined from the return value. For example, since the return value is the second state value, the function recording the abnormality is executed, and the abnormality identification of the first function is generated.
Referring to the foregoing, it can be known that the function that may be abnormal and the function that records the abnormality may be the same-level logic nested under the second function, and whether the function that may be abnormal is executed after the second function is executed or the function that records the abnormality is executed is determined according to the return value of the second function. Illustratively, when the return value of the second function is a second state value (e.g., 1), then the function that records the exception is performed.
It should be noted that, the function for recording an exception may be a setThrew function, and its return value is "0" or "1". Illustratively, if an exception occurs, a "1" is returned; otherwise, return to "0".
In the embodiment of the application, an implementation mode of exception handling is provided. Specifically, when the function is abnormal, the running state of the program can be reset by means of the previously recorded program context, and the program node before the abnormality occurs can be restored. In addition, the abnormal condition of the abnormal identification record function can be generated, so that the abnormal detection module is beneficial to monitoring the running state of the program, timely detecting the abnormality and ensuring the running performance of the whole program.
The embodiment of the application also provides a code exception handling method, which relates to the recovery of the program execution state and the recording of the program exception. Referring to fig. 4, the method includes the steps of:
401. executing a first function based on a first compiled language;
the first compiled language may be a bytecode supporting browser operation, for example, webAssembly bytecode. The first function is used to declare a function for which an exception is actually likely to occur. It will be appreciated that the first function is a first level of execution logic and the second function is a second level of execution logic nested under the first level of execution logic.
402. Executing a second function nested by the first function, and writing the current program context into a cache corresponding to the second function;
wherein the second function may be a function for exception handling in the second compiled language. The second compiled language may be a compiled language that is homologous to the first compiled language, i.e., the first compiled language has the same code data structure as the second compiled language. When executing the function based on the first compiling language, the function calling the second compiling language does not need to carry out data structure conversion, and performance consumption caused by function calling can be avoided.
Specifically, the second function may be a statement that saves the program context so that the running state of the program can be restored based on the saved program context when an abnormality occurs. For example, the second function may be a setjmp function, which belongs to a C function library, and may be considered a function in C language, capable of recording a program context in a cache (set_buf).
When the setjmp function is executed, the current program context may be written into the cache jmp_buf corresponding to the setjmp function. Specifically, jmp_buf includes an object j, and when setjmp functions are executed, the program context of the first function may be written into the object j, so as to implement recording of the program context.
403. Acquiring a first state value returned by the second function;
specifically, the first level execution logic of the program is a first function, the second level execution logic is a second function, and the second function is a third level execution logic. The third layer of execution logic comprises two parallel execution logic, namely a function which can possibly generate an exception and a function which records the exception, and is executed alternatively according to the return value of the second function. Wherein, the logical relationship between the function in which the abnormality may occur and the function in which the abnormality is recorded may be if/else.
In one possible implementation, the return values of the second function are of two types. When the second function logger context is executed, e.g., setjmp is executed to set object j, i.e., the return value of setjmp is "0" (i.e., the first state value described above).
404. And executing the function which is nested by the second function and is possibly abnormal.
It should be noted that, if the return value of the second function is the first state value, executing the function which is nested by the first function and may be abnormal; and if the return value of the second function is the second state value, executing the function which is nested by the second function and records the abnormality.
Taking the first function as an invoke function, the first function nested function as a dynamics function (i.e. a function in which an exception may occur), and the second function as a setjmp function as an example, the execution relationship between the three functions can be represented by the following code:
that is, the Invoke function is executed first, and then the Setjmp function nested by the Invoke function is executed. If the return value of the Setjmp function is 0, executing a dyncall function; conversely, if the return value of the Setjmp function is "1", the setThrew function is executed. Wherein setThiew is a function of the recording anomaly. If an abnormality occurs, returning to '1'; otherwise, return to "0".
405. When the function nested by the second function is abnormal, calling a third function to jump to the second function;
wherein the third function may be a jump function identical to the first compiled language data structure. For example, it may be a longjmp function of the second compiled language.
In a specific implementation, the function of longjmp is to jump the program node to the object j set by setjmp in the goto manner, that is, call longjmp to jump to setjmp, so as to execute setjmp again to acquire the object j (i.e. the program context) recorded in the corresponding cache, and reset the program execution state according to the acquired content.
406. Executing a second function, acquiring a program context in the cache, and resetting the running state of the program according to the program context;
it should be noted that, when the second function (e.g., setjmp) is called as a jump target of the third function (e.g., longjmp), executing the second function may obtain the previously recorded program context from the corresponding cache of the second function.
Further, the running state of the first function may be reset according to the acquired program context, i.e. before the running state of the first function is restored to the abnormal state. That is, after the program is abnormal, the program node can be reset, so that the program execution flow jumps to the abnormal state again, the program is prevented from being blocked, and the possibility is provided for normal execution of the program.
407. Acquiring a second state value returned by a second function;
it should be noted that the second function (e.g., setjmp) has two types of return values, namely the first state value and the second state value described above. When setjmp is executed to set object j, the second function logger context is executed, with setjmp returned to a value of "0" (i.e., the first state value described above); but when setjmp is invoked as the target of a long jump (longjmp), the return value of setjmp is "1" (i.e., the second state value described previously).
408. And executing the function recording the abnormality to generate an abnormality identification.
Referring to the description of step 404, if the return value of the second function is the second state value, the process jumps to the code recording the exception. The function for recording the exception may be a setThiew function, which returns a value of "0" or "1". Illustratively, if an exception occurs, a "1" is returned; otherwise, return to "0".
In the method shown in fig. 4, if the first compiled language is WebAssembly byte code, the execution subject of the method shown in fig. 4 may be a WebAssembly virtual machine of the computer device. Because the data structures of the second compiling language and the first compiling language are the same, the second compiling language and the first compiling language can run on the WebAssembly virtual machine, interaction between compiling virtual machines (for example, javaScript virtual machines) different from other data structures is not involved, data structure conversion caused by function call can be avoided as much as possible, performance consumption caused by the data structure conversion can be avoided, and the abnormal processing of WebAssembly byte codes can be realized while the running performance of a program can be ensured.
Fig. 5 is a call timing diagram of the WebAssembly virtual machine, referring to fig. 5, taking a first function as an invoke function, a function which may be abnormal as a dynamics function, a second function as a setjmp function, and a third function as a longjmp as an example, specifically, the WebAssembly virtual machine executes the invoke function first, and then calls the setjmp function of c++ to record the current program context.
Further, a dyncall function is executed, and cxa _throw is executed when an abnormality occurs in the dyncall function. The next step is to jump the longjmp function of c++ to setjmp function. Executing setThiew function after executing setjmp function again records exception identification.
In the flow shown in fig. 5, the WebAssembly virtual machine may call the statement of c++ to implement exception handling, and since the WebAssembly byte code and the data structure of the c++ statement are the same, both may run in the WebAssembly virtual machine, and interaction between compiling virtual machines (e.g., javaScript virtual machines) different from other data structures is not involved, so that performance consumption caused by data structure conversion can be avoided as much as possible.
Fig. 6 is a schematic diagram of code execution of an exception handling method according to an embodiment of the present application. Referring to fig. 6, the method comprises the steps of:
601. executing setjmp functions nested by invoke functions;
the invoke function is a first function in the embodiment of the present application, and is used for declaring a dyncall function that may be abnormal; setjmp function is the second function according to the embodiments of the present application. In step 601, executing the setjmp function can record the current program context in a cache.
602. Acquiring a false returned by the setjmp function;
It should be noted that, when the setjmp function performs an operation of recording the program context, the setjmp function returns "false".
603. Executing a dyncall function nested by setjmp functions;
it should be noted that, two parallel execution logics, namely a dyncall function and a setThiew function, are nested under the setjmp function, and the dyncall function and the setThiew function can be logic relations of if/else, and the dyncall function or the setThiew function is determined to be executed according to the value returned by the setjmp function.
Specifically, the setjmp function returns "false", and the dynamic function is executed.
604. Judging whether the dyncall function is abnormal or not;
specifically, it is determined whether an error (error) occurs in the dynall function.
605. If the dynamic function is abnormal, cxa _throw is called.
The cxa _throw function is mainly used for calling a longjmp function and realizing the jump of a program node.
606. When cxa _throw is executed, a longjmp function is called;
607. executing the longjmp function, jumping to the setjmp function, and repeatedly executing the setjmp function;
in step 607, repeatedly executing the setjmp function may obtain the program context in the set_buf cache and reset the program running state according to the obtained program context.
608. The "true" returned by the setjmp function is obtained.
It should be noted that, when the setjmp function performs an operation of acquiring a program context and resetting a program running state, the setjmp function returns a "true".
609. The setThiew function is executed.
With reference to the foregoing, two parallel execution logics, namely a dyacl function and a setThiew function, are nested under the setjmp function, and when the setjmp function returns to true, the setThiew function is executed, and the abnormal identifier of the function is recorded.
The embodiment of the application also provides a computer readable storage medium, on which a computer program is stored, which when being executed by a processor implements the training rule determining method as described in the embodiment of the application. For example, the steps of any of the methods shown in fig. 3, 4, 6 may be performed.
Specifically, the program, when executed by a processor, implements the method of:
when executing the first function based on the first compiling language, calling a second function of the second compiling language to record the program context of the first function; the second compiling language has the same code data structure as the first compiling language, the program context is used for representing the current running state of the first function, and the first compiling language is a byte code supporting the running of the browser;
And if the first function is abnormal, performing exception handling according to the program context.
Further, the program, when executed by the processor, may implement: and calling a second function, and writing the program context into a cache region corresponding to the second function.
The program, when executed by the processor, may implement: acquiring a return value of the second function;
if the return value is the first state value, executing the function nested by the first function;
if the function nested by the first function is abnormal, determining that the first function is abnormal.
The program, when executed by the processor, may implement: calling a third function of the second compiling language to jump to the second function;
executing the second function to obtain the program context, and resetting the running state of the first function according to the program context.
The program, when executed by the processor, may implement: after the second function is executed to acquire the program context, acquiring a return value of the second function;
if the return value is the second state value, an exception identification of the first function is generated.
The second function referred to above is setjmp function, and the third function is longjmp function.
Embodiments of the present application provide a computer program product comprising instructions which, when executed by a processor, implement the steps of the method of any of figures 3, 4, 6.
Specifically, the instructions, when executed by a processor, implement the method of:
when executing the first function based on the first compiling language, calling a second function of the second compiling language to record the program context of the first function; the second compiling language has the same code data structure as the first compiling language, the program context is used for representing the current running state of the first function, and the first compiling language is a byte code supporting the running of the browser;
and if the first function is abnormal, performing exception handling according to the program context.
Further, the instructions, when executed by the processor, may implement: and calling a second function, and writing the program context into a cache region corresponding to the second function.
The instructions, when executed by the processor, may implement: acquiring a return value of the second function;
if the return value is the first state value, executing the function nested by the first function;
if the function nested by the first function is abnormal, determining that the first function is abnormal.
The instructions, when executed by the processor, may implement: calling a third function of the second compiling language to jump to the second function;
executing the second function to obtain the program context, and resetting the running state of the first function according to the program context.
The instructions, when executed by the processor, may implement: after the second function is executed to acquire the program context, acquiring a return value of the second function;
if the return value is the second state value, an exception identification of the first function is generated.
The second function referred to above is setjmp function, and the third function is longjmp function.
It should be noted that although the operations of the method of the present application are depicted in the drawings in a particular order, this does not require or imply that the operations must be performed in that particular order or that all of the illustrated operations be performed in order to achieve desirable results.
FIG. 7 is a block diagram of a code exception handling apparatus according to an embodiment of the present application. Referring to fig. 7, the apparatus includes a recording unit 701 and a processing unit 702.
A recording unit 701, configured to call a second function in a second compiling language to record a program context of a first function when the first function is executed based on the first compiling language; the second compiling language is the same as the code data structure of the first compiling language, the program context is used for representing the current running state of the first function, and the first compiling language is a byte code supporting the running of a browser;
And the processing unit 702 performs exception processing according to the program context when the first function is abnormal.
In one embodiment, the recording unit 701 is specifically configured to: and calling the second function, and writing the program context into a cache region corresponding to the second function.
In one embodiment, the processing unit 702 is further configured to obtain a return value of the second function;
if the return value is a first state value, executing a function nested by the first function;
and if the function nested by the first function is abnormal, determining that the first function is abnormal.
In one embodiment, the processing unit 702 is specifically configured to: when the first function is abnormal, calling a third function of the second compiling language to jump to the second function;
executing the second function to acquire the program context, and resetting the running state of the first function according to the program context.
In one embodiment, referring to fig. 8, the above apparatus further includes a generating unit 703.
The generating unit 703 is configured to obtain a return value of the second function; and if the return value is determined to be the second state value, generating an abnormal identifier of the first function.
In one embodiment, the second function is a setjmp function and the third function is a longjmp function.
It will be understood that the units described in the abnormality processing apparatus correspond to the respective steps in the method described in the drawings. Thus, the operations and features described above for the method are equally applicable to the exception handling apparatus, and the units contained therein, and are not described in detail herein. The exception handling device may be implemented in advance in a browser or other security application of the computer device, or may be loaded into the browser or security application of the computer device by means of downloading or the like. The corresponding units in the exception handling means may cooperate with the units in the computer device to implement the solution of the embodiments of the present application.
The division of the modules or units mentioned in the above detailed description is not mandatory. Indeed, the features and functionality of two or more modules or units described above may be embodied in one module or unit in accordance with embodiments of the present disclosure. Conversely, the features and functions of one module or unit described above may be further divided into a plurality of modules or units to be embodied.
It should be noted that, for details not disclosed in the exception handling apparatus in the embodiment of the present application, please refer to details disclosed in the above embodiment of the present application, and details are not described herein.
Referring now to FIG. 8, FIG. 8 shows a schematic diagram of a computer device suitable for use in implementing embodiments of the present application. As shown in fig. 8, the computer system 900 includes a Central Processing Unit (CPU) 901, which can execute various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 902 or a program loaded from a storage section 908 into a Random Access Memory (RAM) 903. In the RAM903, various programs and data required for operation instructions of the system are also stored. The CPU901, ROM902, and RAM903 are connected to each other through a bus 904. An input/output (I/O) interface 905 is also connected to the bus 904.
The following components are connected to the I/O interface 905; an input section 906 including a keyboard, a mouse, and the like; an output portion 907 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and a speaker; a storage portion 908 including a hard disk or the like; and a communication section 909 including a network interface card such as a LAN card, a modem, or the like. The communication section 909 performs communication processing via a network such as the internet. The drive 910 is also connected to the I/O interface 905 as needed. A removable medium 911 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is installed as needed on the drive 910 so that a computer program read out therefrom is installed into the storage section 908 as needed.
In particular, the processes described above with reference to flowcharts fig. 3, 4 may be implemented as computer software programs according to embodiments of the present application. For example, embodiments of the present application include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the flowcharts. In such an embodiment, the computer program contains program code for performing the method shown in the flow chart. In such an embodiment, the computer program may be downloaded and installed from the network via the communication portion 909 and/or installed from the removable medium 911. The above-described functions defined in the system of the present application are performed when the computer program is executed by a Central Processing Unit (CPU) 801.
The computer readable medium shown in the present application may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present application, however, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation instructions of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, blocks shown in two separate connections may in fact be performed substantially in parallel, or they may sometimes be performed in the reverse order, depending on the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units or modules involved in the embodiments of the present application may be implemented in software or in hardware. The described units or modules may also be provided in a processor, for example, as: a processor includes a first collection module, a second collection module, and a transmission module. Wherein the names of the units or modules do not in some cases constitute a limitation of the units or modules themselves.
As another aspect, the present application also provides a computer-readable storage medium that may be included in the electronic device described in the above embodiment or may exist alone without being incorporated in the electronic device. The computer-readable storage medium stores one or more programs that when used by one or more processors perform the training rule determining method and the black industry identifying method described in the present application.
The above description is only illustrative of the preferred embodiments of the present application and of the principles of the technology employed. It will be appreciated by persons skilled in the art that the scope of the disclosure referred to in the present application is not limited to the specific combinations of technical features described above, but also covers other technical features which may be formed by any combination of the technical features described above or their equivalents without departing from the spirit of the disclosure. Such as the above-mentioned features and the technical features disclosed in the present application (but not limited to) having similar functions are replaced with each other.
Claims (15)
1. A method for processing code exceptions, comprising:
When executing a first function based on a first compiling language, calling a second function of a second compiling language to record the program context of the first function; the second compiling language is the same as the code data structure of the first compiling language, the program context is used for representing the current running state of the first function, and the first compiling language is a byte code supporting the running of a browser;
and if the first function is abnormal, performing exception handling according to the program context.
2. The method of claim 1, wherein the calling a second function of a second compiled language records a program context of the first function, comprising:
and calling the second function, and writing the program context into a cache region corresponding to the second function.
3. The method of claim 1 or 2, wherein after the calling a second function of a second compiled language records a program context of the first function, the method further comprises:
acquiring a return value of the second function;
if the return value is a first state value, executing a function nested by the first function;
and if the function nested by the first function is abnormal, determining that the first function is abnormal.
4. The method of claim 1, wherein the exception handling according to the program context comprises:
calling a third function of the second compiling language to jump to the second function;
executing the second function to acquire the program context, and resetting the running state of the first function according to the program context.
5. The method of claim 4, wherein after the executing the second function obtains the program context, the method further comprises:
acquiring a return value of the second function;
and if the return value is the second state value, generating an abnormal identifier of the first function.
6. The method of claim 4 or 5, wherein the second function is a setjmp function and the third function is a longjmp function.
7. A code exception handling apparatus, comprising:
a recording unit for calling a second function of a second compiling language to record a program context of a first function when the first function is executed based on the first compiling language; the second compiling language is the same as the code data structure of the first compiling language, the program context is used for representing the current running state of the first function, and the first compiling language is a byte code supporting the running of a browser;
And the processing unit is used for carrying out exception processing according to the program context if the first function is abnormal.
8. The apparatus according to claim 7, wherein the recording unit is specifically configured to:
and calling the second function, and writing the program context into a cache region corresponding to the second function.
9. The apparatus according to claim 7 or 8, wherein the processing unit is further configured to,
acquiring a return value of the second function;
if the return value is a first state value, executing a function nested by the first function;
and if the function nested by the first function is abnormal, determining that the first function is abnormal.
10. The apparatus according to claim 7, wherein the processing unit is specifically configured to:
when the first function is abnormal, calling a third function of the second compiling language to jump to the second function;
executing the second function to acquire the program context, and resetting the running state of the first function according to the program context.
11. The apparatus of claim 10, further comprising a generation unit,
The generating unit is further used for obtaining a return value of the second function; and if the return value is determined to be the second state value, generating an abnormal identifier of the first function.
12. The apparatus of claim 10 or 11, wherein the second function is a setjmp function and the third function is a longjmp function.
13. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the method of any of claims 1-6 when the program is executed by the processor.
14. A computer readable storage medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements the method according to any of claims 1-6.
15. A computer program product comprising instructions which, when executed by a processor, implement the method of any of claims 1-6.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202210536658.9A CN117112073A (en) | 2022-05-17 | 2022-05-17 | Exception handling method, device, equipment and medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202210536658.9A CN117112073A (en) | 2022-05-17 | 2022-05-17 | Exception handling method, device, equipment and medium |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN117112073A true CN117112073A (en) | 2023-11-24 |
Family
ID=88809771
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202210536658.9A Pending CN117112073A (en) | 2022-05-17 | 2022-05-17 | Exception handling method, device, equipment and medium |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN117112073A (en) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN118760438A (en) * | 2024-09-09 | 2024-10-11 | 粤港澳大湾区数字经济研究院(福田) | Compilation method, compiler, terminal and storage medium |
-
2022
- 2022-05-17 CN CN202210536658.9A patent/CN117112073A/en active Pending
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN118760438A (en) * | 2024-09-09 | 2024-10-11 | 粤港澳大湾区数字经济研究院(福田) | Compilation method, compiler, terminal and storage medium |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN110096338B (en) | Intelligent contract execution method, device, equipment and medium | |
| US9256517B1 (en) | Display of aggregated stack traces in a source code viewer | |
| US8347272B2 (en) | Call graph dependency extraction by static source code analysis | |
| CN108491207B (en) | Expression processing method, device, equipment and computer readable storage medium | |
| CN110673837B (en) | Code repairing method and device, electronic equipment and computer readable storage medium | |
| CN110489310B (en) | Method and device for recording user operation, storage medium and computer equipment | |
| WO2021175053A1 (en) | Method and apparatus for executing functional module in virtual machine | |
| CN111258802A (en) | Method for capturing application program crash information and related equipment | |
| CN110045952B (en) | Code calling method and device | |
| CN114115904A (en) | Information processing method, information processing apparatus, server, and storage medium | |
| CN114115884B (en) | Method and related device for managing programming service | |
| CN113296834A (en) | Reverse engineering-based android closed source service type information extraction method | |
| CN113127050A (en) | Application resource packaging process monitoring method, device, equipment and medium | |
| CN117112073A (en) | Exception handling method, device, equipment and medium | |
| CN114328073A (en) | Thread monitoring method, device, equipment and storage medium | |
| CN113901773B (en) | Data accounting method, device, electronic equipment and storage medium | |
| CN110297639B (en) | Method and apparatus for detecting code | |
| CN118860851A (en) | Embedded database compatibility testing method and device | |
| US10521206B2 (en) | Supporting compiler variable instrumentation for uninitialized memory references | |
| CN111176944A (en) | Block chain intelligent contract calling record analysis method, device, terminal and storage medium | |
| CN112650675A (en) | Code detection method and device of block chain and computer equipment | |
| CN114924947A (en) | Code testing method, device, electronic device and storage medium | |
| CN109634636B (en) | Application processing method, device, equipment and medium | |
| CN111338968A (en) | Project function module debugging method, device, medium and electronic equipment | |
| CN112860224B (en) | Function execution environment construction method and device, electronic equipment and storage medium |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination |