Method, system, electronic device and storage medium for generating exception handling table

The stack structure is used to mark, compile and parse the statement blocks to be parsed, filter exception handling instructions, and generate exception handling tables. This solves the problem of too many exception handling table entries on resource-limited devices and achieves optimization and effectiveness of exception handling.

CN116010147BActive Publication Date: 2024-10-01EASTCOMPEACE TECH
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202211693341.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-28
Publication Date
2024-10-01
Estimated Expiration
2042-12-28

AI Technical Summary

Technical Problem

On resource-constrained devices, traditional high-level languages ​​have too many exception handling table entries, making it difficult to perform effective exception handling.

Method used

Mark and compile and parse the statement blocks to be parsed through the stack structure, screen and eliminate exception handling instructions, generate exception handling tables, reduce exception handling table entries, and optimize the exception handling mechanism.

Benefits of technology

It implements the exception handling mechanism on resource-constrained devices, reduces the entries in the exception handling table, improves resource utilization, and ensures the effectiveness of exception handling.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116010147B_ABST
    Figure CN116010147B_ABST
Patent Text Reader

Abstract

The present application provides a method, system, electronic device and storage medium for generating an exception handling table, the method comprising: obtaining a statement block to be parsed, the statement block to be parsed comprising an execution statement and an exception handling statement; based on a stack structure, respectively performing corresponding push marks on the execution statement and the exception handling statement to obtain a marked statement block containing marking information; according to the stack order of the stack structure, sequentially compiling and parsing the marked statement blocks to obtain an intermediate code containing marking information, the intermediate code comprising an execution code and an exception handling code; through the marking information and the stack order, filtering and removing the exception handling instructions from the execution code, generating an exception handling table, the exception handling instructions comprising the exception handling code. The embodiment of the present application aims to reduce the entries of the exception handling table and realize the operation of the exception handling mechanism on a resource-constrained device.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of compiler programs, and in particular to a method, system, electronic device and storage medium for generating an exception handling table. Background Art

[0002] At present, traditional high-level languages, such as C++, Java, Python, Ruby, Scala and Swift, need to support exception handling (Exception Handling) mechanism. The exception handling mechanism is a program operation fault recovery mechanism that can better handle the situation where the program cannot run normally. Usually, a statement block with the function of capturing and processing exceptions is set in traditional high-level languages. After the exception capture process, the compiler in the related technology will form a large number of exception table entries for handling exceptions, but a large number of exception table entries cannot be stored on a resource-constrained device, resulting in difficulty in exception handling on a resource-constrained device. Therefore, how to generate an exception handling table on a resource-constrained device has become a technical problem that needs to be solved urgently. Summary of the invention

[0003] The following is a summary of the subject matter described in detail herein. This summary is not intended to limit the scope of the claims.

[0004] The main purpose of the embodiments of the present application is to propose a method, system, electronic device and storage medium for generating an exception handling table, aiming to reduce the entries in the exception handling table and implement an exception handling mechanism on a resource-constrained device.

[0005] To achieve the above object, a first aspect of an embodiment of the present application proposes a method for generating an exception handling table, the method comprising:

[0006] Obtaining a statement block to be parsed, wherein the statement block to be parsed includes an execution statement and an exception handling statement;

[0007] Based on the stack structure, the execution statement and the exception handling statement are respectively pushed into the stack to obtain a marked statement block containing marking information;

[0008] According to the stack order of the stack structure, the marked statement blocks are sequentially compiled and parsed to obtain intermediate codes containing the marked information, wherein the intermediate codes include execution codes and exception handling codes;

[0009] Exception handling instructions are screened out from the execution code through the tag information and the stack sequence to generate an exception handling table, wherein the exception handling instructions include the exception handling code.

[0010] In some embodiments, compiling and parsing the marked statement blocks in sequence according to the stack order of the stack structure to obtain the intermediate code containing the marked information includes:

[0011] According to the stack order of the stack structure, the marked statement blocks are parsed in sequence to obtain intermediate execution codes and exception handling codes;

[0012] When a return instruction exists in the execution statement, the exception handling code is copied to a position before the return instruction in the intermediate execution code to obtain an execution code;

[0013] In the case where there is no return instruction in the execution statement, inserting a jump instruction for jumping to the exception handling code from the intermediate execution code to obtain an execution code;

[0014] According to the stack structure, the execution code and the exception handling code are comprehensively sorted to obtain an intermediate code containing the tag information.

[0015] In some embodiments, filtering out exception handling instructions from the execution code by using the tag information and the stack sequence to generate an exception handling table includes:

[0016] Determining a first range of the execution code and a second range of the exception handling code by using the tag information and the stack sequence;

[0017] In a case where the execution code includes the exception handling code, removing the second range from the first range to generate a plurality of exception intervals;

[0018] A plurality of the abnormal intervals are merged to generate an abnormality processing table.

[0019] In some embodiments, the tag information includes an execution tag for marking the execution statement, and an exception handling tag for marking the exception handling statement;

[0020] Determining the first range of the execution code and the second range of the exception handling code by using the tag information and the stack sequence includes:

[0021] Determine an execution start position and an execution end position by using the execution mark and the stack sequence, and determine a first range of the execution code according to the execution start position and the execution end position;

[0022] Determine an exception start position and an exception end position by using the exception handling mark and the stack sequence, and determine a second range of the exception handling code according to the exception start position and the exception end position;

[0023] The first range includes the execution start position and the execution end position, and the second range includes the abnormal start position and the abnormal end position.

[0024] In some embodiments, the execution code includes an exception capture code, and the exception capture code includes multiple exception types;

[0025] The step of determining an execution start position and an execution end position by using the execution mark and the stack sequence, and determining a first range of the execution code according to the execution start position and the execution end position, comprises:

[0026] Determining, from the execution code, an exception capture tag corresponding to the exception capture code according to the exception type and the stack sequence;

[0027] Determine a plurality of execution start positions and a plurality of execution end positions by using the execution mark, the exception capture mark and the stack sequence, wherein each of the execution start positions corresponds to each of the execution end positions;

[0028] A plurality of first ranges are determined according to the plurality of execution start positions and the plurality of execution end positions, wherein the first ranges include the execution flag and the exception capture flag.

[0029] In some embodiments, the abnormal interval includes the abnormal capture mark;

[0030] The step of merging the plurality of abnormal intervals to generate an abnormality processing table includes:

[0031] The abnormal intervals having the same abnormal capture mark and continuous intervals are merged to generate an abnormal processing table.

[0032] In some embodiments, when the execution code includes the exception handling code, the second range is removed from the first range to generate multiple exception intervals;

[0033] When the abnormal start position and the abnormal end position are both between the execution start position and the execution end position, a first abnormal interval is determined using the execution start position and the abnormal start position, and a second abnormal interval is determined using the abnormal end position and the execution end position.

[0034] To achieve the above-mentioned purpose, a second aspect of an embodiment of the present application proposes a system for generating an exception handling table, the system comprising:

[0035] A statement acquisition module, used to acquire a statement block to be parsed, wherein the statement block to be parsed includes an execution statement and an exception handling statement;

[0036] A statement marking module, used for respectively pushing the execution statement and the exception handling statement into the stack based on the stack structure to obtain a marked statement block containing marking information;

[0037] A compiling and parsing module, used for compiling and parsing the marked statement blocks in sequence according to the stack order of the stack structure, to obtain an intermediate code containing the marked information, wherein the intermediate code includes an execution code and an exception handling code;

[0038] The exception table generation module is used to filter out exception handling instructions from the execution code through the tag information and the stack sequence, and generate an exception handling table, wherein the exception handling instructions include the exception handling code.

[0039] To achieve the above-mentioned purpose, the third aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, the memory stores a computer program, and the processor implements the method for generating an exception handling table described in the first aspect when executing the computer program.

[0040] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application proposes a storage medium, which is a computer-readable storage medium, and the storage medium stores a computer program. When the computer program is executed by a processor, it implements the method for generating an exception handling table described in the first aspect above.

[0041] The present application provides a method, system, electronic device and storage medium for generating an exception handling table, the method comprising: obtaining a statement block to be parsed, the statement block to be parsed comprising an execution statement and an exception handling statement; based on a stack structure, respectively performing corresponding stacking marks on the execution statement and the exception handling statement to obtain a marked statement block containing marking information; according to the stack order of the stack structure, sequentially compiling and parsing the marked statement blocks to obtain an intermediate code containing marking information, the intermediate code comprising an execution code and an exception handling code; through the marking information and the stack order, filtering and removing the exception handling instructions from the execution code to generate an exception handling table, the exception handling instructions comprising the exception handling code. According to the technical solution of the present application, the statement block to be parsed is split and marked by a stack structure to form a marked statement block, and the marked statement block is sequentially compiled according to the order of stacking, because the traditional high-level language will automatically generate the content of the exception handling statement redundantly after the possible branch path in each execution statement during the compilation process to realize the exception handling mechanism, thereby generating a large number of exception handling table entries with the exception handling statement as the starting index and the ending index. However, exception handling statements are not exception information. Therefore, the present application determines the location and range of the exception handling code through the corresponding marking information and stack order of the compiled execution code and the exception handling code, removes the exception handling instructions containing the exception handling code from the execution code, and splits a large number of continuous exception capture ranges in the execution code into multiple exception capture intervals, thereby realizing small-grained exception handling table information and reducing the number of exception handling table entries, thereby optimizing the traditional exception handling table and enabling the exception handling mechanism to run on resource-constrained devices. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 It is a flowchart of the steps of a method for generating an exception handling table provided by an embodiment of the present application;

[0043] Figure 2 is a specific step flow chart of step S130 provided in one embodiment of the present application;

[0044] Figure 3 is a specific step flow chart of step S140 provided in another embodiment of the present application;

[0045] Figure 4 is a specific step flow chart of step S310 provided in another embodiment of the present application;

[0046] Figure 5 is a specific step flow chart of step S410 provided in another embodiment of the present application;

[0047] Figure 6 is a specific step flow chart of step S330 provided in another embodiment of the present application;

[0048] Figure 7 is a specific step flow chart of step S320 provided in another embodiment of the present application;

[0049] Figure 8 It is a module schematic diagram of a system for generating an exception handling table provided in an embodiment of the present application;

[0050] Fig. 9 It is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION

[0051] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0052] It should be noted that, although the functional modules are divided in the system schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the system or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.

[0053] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0054] The method for generating the exception handling table provided in the embodiment of the present application can be applied to the terminal, can also be applied to the server side, and can also be software running in the terminal or the server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or a server cluster or distributed system composed of multiple physical servers, and can also be configured as a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN) and big data and artificial intelligence platforms; the software can be an application that implements the method for generating the exception handling table, etc., but is not limited to the above forms.

[0055] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.

[0056] The embodiments of the present application are introduced below with reference to the accompanying drawings.

[0057] First, Figure 1 is an optional flowchart of the method for generating an exception handling table provided in an embodiment of the present application, Figure 1 The method for generating the exception handling table may include but is not limited to steps S110 to S140.

[0058] Step S110, obtaining a statement block to be parsed, the statement block to be parsed includes an execution statement and an exception handling statement;

[0059] Step S120, based on the stack structure, the execution statements and the exception handling statements are marked accordingly, and a marked statement block containing marking information is obtained;

[0060] Step S130, compiling and parsing the marked statement blocks in sequence according to the stack order of the stack structure to obtain an intermediate code containing the marked information;

[0061] Step S140 , filtering out exception handling instructions from the execution code through the tag information and the stack sequence, and generating an exception handling table.

[0062] It is understandable that the statement block to be parsed can be obtained through the observer pattern for parsing, that is, the statement in the abstract syntax tree is obtained using the observer design pattern. The statement block to be parsed can be a try-catch-finally statement block, and the execution statement can be a try statement. In the try-catch-finally statement block, the try statement can be used to execute a section of code. When an exception occurs in the code block, the execution of subsequent code will be stopped, and then jump to the catch statement. If no exception occurs, the catch statement will not be executed, but the finally statement will be executed. The try statement can include one or more exception capture statements, namely catch statements, and the exception type can be determined from the exception capture statement. The exception handling statement can be a finally statement, and the exception handling statement is executed after the try statement or catch statement block is executed.

[0063] The statement block to be parsed usually appears in a multi-layer nested format, that is, multiple layers of try statements are nested and used, and can be processed through the stack structure, with the principle that the outer try statement is pushed into the stack first and the inner try statement is pushed into the stack later. Therefore, the execution statements and exception handling statements in the statement block to be parsed are respectively pushed into the stack in the order of being pushed into the stack using the stack structure to obtain a marked statement block containing marking information, and the marked statement block contains the execution statement and the exception handling statement, that is, the execution statement and the exception handling statement both have marking information, and the marking information represents the order in which each statement is pushed into the stack structure, and the marking information can distinguish the execution statement from the exception handling statement.

[0064] Since the marked statement block is located in the stack structure, the marked statement block can be compiled and parsed in turn using the custom intermediate code through the stack order of the stack structure, so that the execution code is generated by compiling and parsing the execution statement, and the exception handling code is generated by compiling and parsing the exception handling statement, that is, the intermediate code containing the marking information is obtained. However, since the traditional high-level language will automatically generate the content of the exception handling statement redundantly after each possible branch path in each execution statement during the compilation process to implement the exception handling mechanism, a large number of exception handling table entries with the exception handling statement as the starting index and the ending index are generated, which is equivalent to the existence of the exception handling code in the compiled part of the execution code, but the exception handling statement and the exception handling code are not exception information. Therefore, the location of the exception handling code is determined by the marking information and the stack order, and it is judged whether the exception handling code is located in the execution code. If the exception handling code is in the execution code, that is, the finally statement is within the scope of the try statement or the catch statement, then the exception handling instructions containing the exception handling statements are removed from the execution code, which is equivalent to removing the scope of the exception handling instructions from the scope of the execution code when calculating the exception capture range of the statement block to be parsed, and splitting a redundant and continuous exception capture interval of the execution code into multiple streamlined and accurate small intervals, so that a fine-grained exception handling table can be constructed using multiple small intervals, reducing the entries of the exception handling table, and optimizing the traditional exception handling table, so that the exception handling mechanism can be run on resource-constrained devices.

[0065] In addition, in addition to exception handling statements for exceptions that should not be caught, exception handling instructions also include some special instructions for traversing each exception capture interval in the execution code, such as jump instructions and return instructions. Jump instructions and return instructions can be considered as impossible to throw exceptions. Therefore, special instructions can be removed from the execution code, which is equivalent to deleting corresponding redundant table entries from the traditional exception handling table, reducing the entries in the exception handling table, and helping to run on resource-constrained devices.

[0066] See also Figure 2 , in some embodiments, Figure 1 Step S130 may include but is not limited to steps S210 to S240:

[0067] Step S210, according to the stack order of the stack structure, the marked statement blocks are parsed in sequence to obtain the intermediate execution code and the exception handling code;

[0068] Step S220, when there is a return instruction in the execution statement, copy the exception handling code to the position before the return instruction in the intermediate execution code to obtain the execution code;

[0069] Step S230, when there is no return instruction in the execution statement, insert a jump instruction for jumping to the exception handling code from the intermediate execution code to obtain the execution code;

[0070] Step S240, comprehensively sorting the execution code and the exception handling code according to the stack structure to obtain the intermediate code containing the tag information.

[0071] It can be understood that by marking the stack order of each statement in the stack structure of the statement block, each statement in the marked statement block is parsed in turn, that is, the execution statement is parsed to obtain the intermediate execution code, and the exception handling statement is parsed to obtain the exception handling code, and both the execution statement and the exception handling statement carry marking information. After compilation and parsing, the corresponding generated execution code and exception handling code also retain the marking information.

[0072] When there is a return instruction in the execution statement, which is equivalent to a possible branch path of the program, the exception handling code is copied to the position before the return instruction in the intermediate execution code to implement the exception handling mechanism and obtain the execution code. When there are multiple return instructions in the execution statement, that is, there are multiple return instructions in the intermediate execution code, the exception handling code can be copied before each return instruction, or before one or more of the return instructions. However, the exception handling code is only used for execution processing and will not throw an exception. Therefore, after generating the exception capture range for the execution code, the exception handling code copied to the execution code can be deleted to reduce redundant table entries in the exception handling table.

[0073] When there is no return instruction in the execution statement, in order to ensure that the exception handling statement can still be executed after an exception occurs in the execution statement, the jump instruction used to jump to the exception handling code is inserted into the intermediate execution code. The exception handling mechanism is implemented by inserting jump instructions, which can effectively reduce the number of bytecodes in the execution code and save space.

[0074] Therefore, after inserting the copied exception handling code or inserting the jump instruction into the intermediate execution code, the execution code is obtained, and the execution code and the exception handling code are reordered using the stack structure. At the same time, the execution code and the exception handling code are respectively readjusted using the tag information, including the exception handling code located in the execution code, to obtain the intermediate code containing the tag information.

[0075] See also Figure 3 , in some embodiments, Figure 1 Step S140 may include but is not limited to steps S310 to S330:

[0076] Step S310, determining a first range of execution code and a second range of exception handling code through tag information and stack sequence;

[0077] Step S320, when the execution code includes an exception handling code, remove the second range from the first range to generate multiple exception intervals;

[0078] Step S330: merge multiple abnormal intervals to generate an abnormality processing table.

[0079] It is understandable that, since each statement is marked and marking information is generated during the process of pushing the marked statement block into the stack, the execution code and the exception handling code, especially the exception handling code copied into the execution code, can be determined by the marking information. Thus, by using the marking information and the stack order at the same time, the first range of the execution code can be determined, and the second range of the exception handling code can be determined at the same time.

[0080] In the case where the execution code includes the exception handling code, that is, the first range will overlap with the second range, therefore, the second range in the first range is removed, the first range is split into multiple exception intervals, and the entries in the exception handling table are reduced. Multiple exception intervals are merged, and the exception intervals with the same or continuous intervals are merged to further optimize the exception handling table.

[0081] For example, the range of the try code in the execution code is [3,15], the range of the catch code is [15,21], the range of the any code is [22,28], and the range of the finally code in the exception handling code is [29,33]. In addition, the try code includes the copied and inserted finally code, and the copied and inserted code range is [8,12]. This is equivalent to the first range being [3,28], the second range being [8,12] and [29,33]. The second range [8,12] existing in the first range is removed, and [3,8] and [13,28] are obtained. Therefore, the two exception intervals after removing the second range are used to generate an exception handling table, wherein the specific table entries are as follows: [3,8,15], [13,15,15], [3,8,22], [13,15,22] and [15,21,22]. The first element of the table entry represents the starting position, the second element represents the ending position, and the third element represents the processing execution position. If the code in the range [13,15] is an exception handling instruction, namely a jump instruction, a return instruction and an exception type, then after removing the exception handling instruction, only [3,8,15], [3,8,22] and [15,21,22] are retained, which can reduce the table entry of the exception handling table.

[0082] See also Figure 4 , in some embodiments, Figure 3 Step S310 may include but is not limited to steps S410 to S420:

[0083] Step S410, determining the execution start position and the execution end position by using the execution mark and the stack order, and determining the first range of the execution code according to the execution start position and the execution end position;

[0084] Step S420, using the exception handling mark and the stack sequence, determine the exception start position and the exception end position, and determine the second range of the exception handling code according to the exception start position and the exception end position.

[0085] It can be understood that the marking information may include an execution tag for marking an execution statement and an exception handling tag for marking an exception handling statement. Therefore, during the stacking process, each statement in the statement block to be parsed is marked separately according to the statement type, so that the execution statement and the exception handling statement can be determined through the marking information.

[0086] Through the execution mark and stack position, the start line and end line of the execution code, that is, the execution start position and the execution end position, can be determined, so that the code range from the execution start position to the execution end position is considered to be the first range of the execution code, that is, the first range can be determined by the execution start position and the execution end position, and includes the execution start position and the execution end position.

[0087] Accordingly, the start line and the end line of the exception handling code, i.e., the exception start position and the exception end position, can be determined by executing the mark and the stack position. The second range of the exception handling code is determined by the code range between the exception start position and the exception end position, i.e., the second range can be determined by the exception start position and the exception end position and includes the exception start position and the exception end position.

[0088] Since the exception handling code can be copied into the execution code, there can be multiple exception start positions and exception end positions, and each exception start position corresponds to each exception end position one by one, so multiple second ranges can be determined, and the second range can exist in the first range.

[0089] See also Figure 5 , in some embodiments, Figure 4 Step S410 may include but is not limited to steps S510 to S530:

[0090] Step S510, determining the exception capture mark corresponding to the exception capture code from the execution code according to the exception type and the stack sequence;

[0091] Step S520, using the execution mark, the exception capture mark and the stack order, determining multiple execution start positions and multiple execution end positions;

[0092] Step S530: determining a plurality of first ranges according to a plurality of execution start positions and a plurality of execution end positions.

[0093] It is understandable that the execution code also includes an exception catching code, which is compiled from the exception catching statement in the execution statement, that is, obtained from the catch statement. The exception catching code can determine the exception type within the current statement range. There are many types of exception catching codes, and different types of exception catching codes correspond to different exception types, which is equivalent to the exception catching code having multiple exception types.

[0094] See also Figure 6 , in some embodiments, Figure 3 Step S330 may include but is not limited to step S610:

[0095] Step S610: merging the abnormal intervals with the same abnormal capture mark and continuous intervals to generate an abnormal processing table.

[0096] It can be understood that each exception interval is represented by a corresponding exception capture mark, and the exception capture mark is characterized as a mark of the exception type determined by the exception capture statement. The exception type of the current exception interval can be determined by the exception capture mark. Different exception types have different exception processing, and when the exception types are the same, the exception processing performed is the same. Therefore, the exception intervals with the same exception capture mark and continuous intervals can be merged, and the merged exception intervals and the exception intervals that cannot be merged can be used to generate an exception processing table. Multiple exception intervals with the same exception capture mark and continuous intervals can be merged. For example, if [1,3] and [4,10] have the same exception capture mark, they can be merged to form a new exception interval [1,10]. By merging exception intervals with the same exception type and continuous intervals, redundant table entries in the exception processing table can be effectively reduced, which helps to run the exception handling mechanism on resource-constrained devices.

[0097] See also Figure 7 , in some embodiments, Figure 3 Step S320 may include but is not limited to step S710:

[0098] Step S710: When both the abnormal start position and the abnormal end position are between the execution start position and the execution end position, a first abnormal interval is determined using the execution start position and the abnormal start position, and a second abnormal interval is determined using the abnormal end position and the execution end position.

[0099] It can be understood that when the abnormal start position and the abnormal end position are both between the execution start position and the execution end position, the second range can be considered to be within the first range, so that the first abnormal interval is determined by the execution start position and the abnormal start position, and the second abnormal interval is determined by the abnormal end position and the execution end position, which is equivalent to eliminating the second range determined by the abnormal start position and the abnormal end position.

[0100] Second, see Figure 8 , Figure 8 is a module diagram of a system for generating an exception handling table provided in an embodiment of the present application. The embodiment of the present application also provides a system 800 for generating an exception handling table, which can implement the above-mentioned method for generating an exception handling table. The system includes:

[0101] A statement acquisition module 810 is used to acquire a statement block to be parsed, where the statement block to be parsed includes an execution statement and an exception handling statement;

[0102] A statement marking module 820 is used to push corresponding marks on the execution statements and exception handling statements based on the stack structure to obtain a marked statement block containing marking information;

[0103] A compiling and parsing module 830 is used to compile and parse the marked statement blocks in sequence according to the stack order of the stack structure to obtain an intermediate code containing the marking information, wherein the intermediate code includes an execution code and an exception handling code;

[0104] The exception table generation module 840 is used to filter out exception handling instructions from the execution code through tag information and stack sequence, and generate an exception handling table. The exception handling instructions include exception handling codes.

[0105] It should be noted that the specific implementation of the system 800 for generating the exception handling table is substantially the same as the specific implementation of the method for generating the exception handling table described above, and will not be described in detail herein.

[0106] In a third aspect, an embodiment of the present application further provides an electronic device, the electronic device comprising a memory and a processor, the memory storing a computer program, and the processor implementing the above-mentioned method for generating an exception handling table when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a vehicle-mounted computer, etc.

[0107] See also Fig. 9 , Fig. 9 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:

[0108] The processor 910 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;

[0109] The memory 920 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 920 can store an operating system and other applications. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 920, and the processor 910 calls and executes the method for generating the exception handling table of the embodiment of the present application, for example, executing the above-described Figure 1 Steps S110 to S140 of the method, Figure 2 Steps S210 to S240 of the method, Figure 3 Steps S310 to S330 of the method, Figure 4 Steps S410 to S420 of the method, Figure 5 Steps S510 to S520 of the method, Figure 6 Method step S610 and Figure 7 Method step S710;

[0110] Input / output interface 930, used to implement information input and output;

[0111] Communication interface 940, used to realize communication interaction between the device and other devices, which can be realized through wired mode (such as USB, network cable, etc.) or wireless mode (such as mobile network, WIFI, Bluetooth, etc.);

[0112] bus 950 , which transmits information between the various components of the device (e.g., processor 910 , memory 920 , input / output interface 930 , and communication interface 940 );

[0113] The processor 910 , the memory 920 , the input / output interface 930 , and the communication interface 940 are connected to each other in communication within the device via a bus 950 .

[0114] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, which stores a computer program, and when the computer program is executed by a processor, the method for generating the above-mentioned exception handling table is implemented.

[0115] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0116] The non-transient software program and instructions required to implement the method for generating the exception handling table in the above embodiment are stored in the memory. When executed by one or more processors, the method for generating the exception handling table in the above embodiment is executed, for example, the above described method is executed. Figure 1 Steps S110 to S140 of the method, Figure 2 Steps S210 to S240 of the method, Figure 3 Steps S310 to S330 of the method, Figure 4 Steps S410 to S420 of the method, Figure 5 Steps S510 to S520 of the method, Figure 6 Method step S610 and Figure 7 Method step S710 in .

[0117] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0118] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.

[0119] The system embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment.

[0120] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.

[0121] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application 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 interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0122] It should be understood that in this application, "plurality" refers to two or more than two. The character " / " generally indicates that the objects associated with each other are in an "or" relationship.

[0123] In the several embodiments provided in the present application, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of systems or units, which can be electrical, mechanical or other forms.

[0124] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0125] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0126] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.

[0127] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.

Claims

1. A method for generating an exception handling table, characterized in that: The generation method comprises: Obtaining a statement block to be parsed, wherein the statement block to be parsed includes an execution statement and an exception handling statement; Based on the stack structure, the execution statement and the exception handling statement are respectively pushed into the stack to obtain a marked statement block containing marking information; According to the stack order of the stack structure, the marked statement blocks are sequentially compiled and parsed to obtain intermediate codes containing the marked information, wherein the intermediate codes include execution codes and exception handling codes; Exception handling instructions are screened out from the execution code through the tag information and the stack sequence to generate an exception handling table, wherein the exception handling instructions include the exception handling code.

2. The generation method according to claim 1, characterized in that: The method of compiling and parsing the marked statement blocks in sequence according to the stack order of the stack structure to obtain the intermediate code containing the marked information includes: According to the stack order of the stack structure, the marked statement blocks are parsed in sequence to obtain intermediate execution codes and exception handling codes; When a return instruction exists in the execution statement, the exception handling code is copied to a position before the return instruction in the intermediate execution code to obtain an execution code; In the case where there is no return instruction in the execution statement, inserting a jump instruction for jumping to the exception handling code from the intermediate execution code to obtain an execution code; According to the stack structure, the execution code and the exception handling code are comprehensively sorted to obtain an intermediate code containing the tag information.

3. The generation method according to claim 1, characterized in that: The step of filtering out exception handling instructions from the execution code by using the tag information and the stack sequence to generate an exception handling table includes: Determining a first range of the execution code and a second range of the exception handling code by using the tag information and the stack sequence; In a case where the execution code includes the exception handling code, removing the second range from the first range to generate a plurality of exception intervals; A plurality of the abnormal intervals are merged to generate an abnormality processing table.

4. The generation method according to claim 3, characterized in that: The tag information includes an execution tag for marking the execution statement, and an exception handling tag for marking the exception handling statement; Determining the first range of the execution code and the second range of the exception handling code by using the tag information and the stack sequence includes: Determine an execution start position and an execution end position by using the execution mark and the stack sequence, and determine a first range of the execution code according to the execution start position and the execution end position; Determine an exception start position and an exception end position by using the exception handling mark and the stack sequence, and determine a second range of the exception handling code according to the exception start position and the exception end position; The first range includes the execution start position and the execution end position, and the second range includes the abnormal start position and the abnormal end position.

5. The generation method according to claim 4, characterized in that: The execution code includes an exception capture code, and the exception capture code includes multiple exception types; The step of determining an execution start position and an execution end position by using the execution mark and the stack sequence, and determining a first range of the execution code according to the execution start position and the execution end position, comprises: Determining, from the execution code, an exception capture tag corresponding to the exception capture code according to the exception type and the stack sequence; Determine a plurality of execution start positions and a plurality of execution end positions by using the execution mark, the exception capture mark and the stack sequence, wherein each of the execution start positions corresponds to each of the execution end positions; A plurality of first ranges are determined according to the plurality of execution start positions and the plurality of execution end positions, wherein the first ranges include the execution flag and the exception capture flag.

6. The generation method according to claim 5, characterized in that: The exception interval includes the exception capture mark; The step of merging the plurality of abnormal intervals to generate an abnormality processing table includes: The abnormal intervals having the same abnormal capture mark and continuous intervals are merged to generate an abnormal processing table.

7. The generation method according to claim 4, characterized in that: In the case where the execution code includes the exception handling code, the second range is removed from the first range to generate multiple exception intervals, including: When the abnormal start position and the abnormal end position are both between the execution start position and the execution end position, a first abnormal interval is determined using the execution start position and the abnormal start position, and a second abnormal interval is determined using the abnormal end position and the execution end position.

8. A system for generating an exception handling table, characterized in that: The system comprises: A statement acquisition module, used to acquire a statement block to be parsed, wherein the statement block to be parsed includes an execution statement and an exception handling statement; A statement marking module, used for respectively pushing the execution statement and the exception handling statement into the stack based on the stack structure to obtain a marked statement block containing marking information; A compiling and parsing module, used for compiling and parsing the marked statement blocks in sequence according to the stack order of the stack structure, to obtain an intermediate code containing the marked information, wherein the intermediate code includes an execution code and an exception handling code; The exception table generation module is used to filter out exception handling instructions from the execution code through the tag information and the stack sequence, and generate an exception handling table, wherein the exception handling instructions include the exception handling code.

9. An electronic device, characterized in that: The electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the method for generating an exception handling table according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method for generating an exception handling table according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Dynamic and static combined Java program exception handling and optimization method

    CN102117228A

  • Exception handling method, device and system of advanced language

    CN110275792A

  • Program monitoring method and device, computing equipment and storage medium

    CN110321275A

  • Application program running information acquisition method and device

    CN110806968A

  • Abnormality processing method and device for intelligent wearable device, equipment and storage medium

    CN114296982A