Binary file execution method, device and electronic device

By optimizing the binary file execution method, using one-pass parameter passing and synchronous native method checking, the performance difference problem of WebAssembly on embedded devices is solved, and the operating efficiency and performance are improved.

CN119536740BActive Publication Date: 2025-09-30GUANGDONG CHUTIAN DRAGON SMART CARD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411644878.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-18
Publication Date
2025-09-30
Estimated Expiration
2044-11-18

AI Technical Summary

Technical Problem

Existing WebAssembly applications suffer from poor performance when running on resource-constrained embedded devices and cannot be executed effectively, mainly because parameter passing requires two traversals, which leads to performance bottlenecks.

Method used

By optimizing the execution method of binary files, reducing the number of traversals for parameter passing, a single traversal process is adopted, combined with the synchronous parameter type checking and passing of native methods, to optimize method instantiation and stack frame structure, reducing the complexity of the instantiation process and stack space consumption.

Benefits of technology

It improves the application running performance and efficiency on embedded devices, reduces the processing process and space consumption, and is suitable for embedded devices with limited resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119536740B_ABST
    Figure CN119536740B_ABST
Patent Text Reader

Abstract

The present application provides a binary file execution method, device, and electronic device, which are applied to a bytecode interpreter; the method includes: reading the bytecode instruction currently to be executed from the binary file; when determining that the bytecode instruction is a method call instruction, reading the first index of the method to be called corresponding to the bytecode instruction, and determining the method instance corresponding to the method to be called; if the method to be called is an imported method, obtaining the signature parsing parameters of the method to be called and pushing them into the operand stack; setting the first stack frame structure corresponding to the method to be called, calling the native method and writing the return value of the native method to the stack frame, and restoring the calling function instance; in the native method, parameter type checking and parameter passing are performed synchronously; otherwise, execution is performed according to the processing flow of the non-imported method. This execution method can be applied to embedded devices with limited resources to improve the running performance of the application.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of software technology, and in particular to a method, device, and electronic device for executing a binary file. Background Art

[0002] WebAssembly (abbreviated as Wasm) is a binary instruction format for a stack-based virtual machine. It is a low-level assembly-like language with a compact binary format that can run at near-native performance and provides a compilation target for languages ​​such as C / C++.

[0003] The original wasm application was run on a computer web page. The existing execution process requires two traversals to process the passed parameters. Due to the relatively high computer operating speed, the impact on running performance when running on a web page is basically negligible. However, if the wasm application is run on a resource-constrained embedded device, there will be a significant difference in running performance, resulting in the wasm application being unable to run on the embedded device according to the existing execution process. Summary of the Invention

[0004] The purpose of this application is to provide a binary file execution method, device and electronic device, which can be applied to embedded devices with limited resources to improve the running performance of applications.

[0005] In the first aspect, the present application provides a method for executing a binary file, which is applied to a bytecode interpreter; the method includes: reading the bytecode instruction currently to be executed from the binary file; when determining that the bytecode instruction is a method call instruction, reading the first index of the method to be called corresponding to the bytecode instruction, and determining the method instance corresponding to the method to be called based on the first index; if the method to be called is an imported method, obtaining the signature parsing parameters of the method to be called and pushing them into the operand stack; setting a first stack frame structure corresponding to the method to be called, calling the native method and writing the return value of the native method into the stack frame, and restoring the calling function instance; wherein, in the native method, parameter type checking and parameter passing are performed synchronously; if the method to be called is not an imported method, pushing the method parameters of the method to be called into the operand stack; allocating stack space, setting a second stack frame structure corresponding to the method to be called, obtaining the calling method, and executing the method instance corresponding to the method to be called.

[0006] Furthermore, the above-mentioned step of determining the method instance corresponding to the method to be called based on the first index includes: obtaining the second index corresponding to the currently called method; judging whether the second index is consistent with the first index; if so, using the method instance corresponding to the currently called method as the method instance corresponding to the method to be called; if not, obtaining the corresponding instance data in the downloaded file according to the second index, and reconstructing the method instance required by the method to be called based on the instance data.

[0007] Furthermore, the above method also includes: determining whether the method to be called is an imported method, specifically including: obtaining the number of imported methods, and determining whether the first index is less than the number of imported methods; if so, determining that the method to be called is an imported method; if not, determining that the method to be called is not an imported method.

[0008] Furthermore, the above-mentioned step of obtaining the signature parsing parameters of the method to be called and pushing them into the operand stack includes: obtaining the function signature corresponding to the method to be called; performing address conversion calculation on the parameters corresponding to the specified characters according to the character string in the function signature, and placing the calculated value as the parameter to be passed into the specified position in the operand stack.

[0009] Furthermore, the above-mentioned steps of setting the first stack frame structure corresponding to the method to be called, calling the native method and writing the return value of the native method into the stack frame, and restoring the calling function instance include: setting the current stack frame pointer to point to the first stack frame structure corresponding to the method to be called; obtaining the native method corresponding to the method index in the first stack frame structure from the native method table according to the method index in the first stack frame structure, and executing the native method; after the execution of the native method is completed, storing the return value of the native method to a specified position on the operand stack according to the number and position information of the return values ​​in the first stack frame structure; and pointing the current stack frame pointer to the stack frame structure before calling the native method.

[0010] Furthermore, the above-mentioned steps of obtaining the native method corresponding to the method index in the first stack frame structure from the native method table and executing the native method include: obtaining a new method to be called by the method to be called, calculating the stack size required for the new method and allocating stack space, and setting a third stack frame structure for the new method; calling the new method, and when the new method is executed, updating the third stack frame structure based on the return value; copying the return value to the first stack frame structure of the method to be called according to the offset of the return value obtained from the third stack frame structure; and releasing the third stack frame structure.

[0011] Furthermore, the first stack frame structure includes: the frame address of the previous calling method, the index of the current method, the offset of the current method return value in the operand stack, the current method bytecode address, the local variable stack address, and the address of the operand stack.

[0012] In the second aspect, the present application also provides an execution device for a binary file, which is applied to a bytecode interpreter; the device includes: an instruction acquisition module, which is used to read the bytecode instruction to be executed currently from the binary file; an instance determination module, which is used to determine that the bytecode instruction is a method call instruction, read the first index of the method to be called corresponding to the bytecode instruction, and determine the method instance corresponding to the method to be called based on the first index; a first execution module, which is used to obtain the signature parsing parameters of the method to be called if the method to be called is an imported method, and push them into the operand stack; set the first stack frame structure corresponding to the method to be called, call the native method and write the return value of the native method into the stack frame, and restore the calling function instance; wherein, in the native method, parameter type checking and parameter passing are performed synchronously; a second execution module, which is used to push the method parameters of the method to be called into the operand stack if the method to be called is not an imported method; allocate stack space, set the second stack frame structure corresponding to the method to be called, obtain the calling method, and execute the method instance corresponding to the method to be called.

[0013] In a third aspect, the present application further provides an electronic device comprising a processor and a memory, wherein the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the method described in the first aspect above.

[0014] In a fourth aspect, the present application also provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the method described in the first aspect above.

[0015] The present application provides a binary file execution method, device, and electronic device, wherein the method is applied to a bytecode interpreter; the method comprises: reading a bytecode instruction currently to be executed from a binary file; when determining that the bytecode instruction is a method call instruction, reading a first index of a method to be called corresponding to the bytecode instruction, and determining a method instance corresponding to the method to be called based on the first index; if the method to be called is an imported method, obtaining signature parsing parameters of the method to be called and pushing them onto an operand stack; setting a first stack frame structure corresponding to the method to be called, calling a native method and writing the return value of the native method into the stack frame, and restoring the calling function instance; wherein, in the native method, parameter type checking and parameter passing are performed simultaneously; if the method to be called is not an imported method, pushing the method parameters of the method to be called onto the operand stack; allocating stack space, setting a second stack frame structure corresponding to the method to be called, obtaining a calling method, and executing the method instance corresponding to the method to be called. In this execution method, in the native method, parameter type checking and parameter passing are performed simultaneously, which can reduce processing and space consumption, and can be applied to embedded devices with limited resources to improve the running performance and efficiency of the application. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the specific implementation methods of the present application or the technical solutions in the prior art, the following is a brief introduction to the drawings required for use in the specific implementation methods or the description of the prior art. Obviously, the drawings described below are some implementation methods of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0017] Figure 1 A flowchart of a binary file execution method provided in an embodiment of the present application;

[0018] Figure 2 A flowchart of another binary file execution method provided in an embodiment of the present application;

[0019] Figure 3 A structural block diagram of an instruction execution device for a binary file provided in an embodiment of the present application;

[0020] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0021] The following will clearly and completely describe the technical solutions of this application in conjunction with the embodiments. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0022] The existing execution process requires two traversals to process parameter transfers. For example, if the called method has three parameters and one return value, the method call instruction specifies the parameter positions as 0, 1, and 3, respectively, and the return value position as 2. 0, 1, 2, and 3 are all indexes in the operand stack. First, based on the number of parameters, the parameters are traversed and the specified parameters (values ​​indexed at 0, 1, and 3 in the operand stack) are copied to the calling method's local variable stack (lp) at indexes 0, 1, and 2. Second, based on the method signature, the parameters copied to the local variable stack are traversed, the address types in the parameters are parsed and converted into actual addresses, and finally, the parameters from the local variable stack are copied to a temporary buffer for the method call. This two-pass process directly impacts application performance for embedded devices.

[0023] Based on this, the embodiments of the present application provide a binary file execution method, device, and electronic device, which can be applied to embedded devices with limited resources to improve the running performance of applications. To facilitate understanding of this embodiment, a binary file execution method disclosed in the embodiments of the present application is first described in detail.

[0024] Figure 1 This is a flowchart of a binary file execution method provided in an embodiment of the present application, which is applied to a bytecode interpreter; the method specifically includes the following steps:

[0025] Step S102, reading the bytecode instruction to be executed from the binary file;

[0026] The bytecode interpreter obtains the instructions to be executed from the card application binary file; the instructions to be executed are bytecode instructions defined by the wasm instruction set, which are used to represent the next instruction to be executed.

[0027] Step S104: when it is determined that the bytecode instruction is a method call instruction, a first index of the method to be called corresponding to the bytecode instruction is read, and based on the first index, a method instance corresponding to the method to be called is determined;

[0028] When it is determined that the bytecode instruction is not a method call instruction, the instruction can be directly executed according to the instruction function corresponding to the bytecode instruction. When it is determined that the bytecode instruction is a method call instruction, the method instance corresponding to the intended method to be called is determined based on the first index. Specifically, the judgment can be made based on the first index and the second index of the currently called method. If the two are consistent, the method instance of the currently called method is used as the method instance corresponding to the intended method to be called. If they are inconsistent, the corresponding instance data is obtained from the downloaded file according to the second index, and a new method instance is created for the intended method to be called based on the instance data.

[0029] The process of recreating a method instance is as follows: obtaining specified information from the downloaded file in the flash, filling the specified information into the preset method instance data structure, and obtaining a recreated method instance; the specified information includes: method index, number of parameters, size of stack space used, and return value position.

[0030] It can be seen that the method provided in the embodiment of the present application can effectively reduce the complexity of the instantiation process and the number of times the flash reads data by introducing a process of determining whether the method instance needs to be rebuilt based on an index, thereby improving the execution efficiency of the application.

[0031] Step S106: If the method to be called is an imported method, the signature parsing parameters of the method to be called are obtained and pushed into the operand stack; a first stack frame structure corresponding to the method to be called is set, the native method is called, and the return value of the native method is written into the stack frame, and the calling function instance is restored; wherein, in the native method, parameter type checking and parameter passing are performed simultaneously;

[0032] Before this step, the following steps may be performed: a stack space determination process and an imported method determination process, such as determining whether the stack space satisfies the space required by the method to be called to execute the method instance; if so, further determining whether the method to be called is an imported method;

[0033] Whether the stack space requirement is met can be determined by comparing the stack space size used by the running instance with the remaining stack space size. If the stack space size used by the running instance is less than the remaining stack space size, it can be determined that the stack space requirement is met; otherwise, it is not met.

[0034] When it is determined that the stack space does not meet the space required by the method to be called to execute the method instance, a stack overflow exception will be thrown and the current process will be exited; when the stack space meets the space required by the method to be called to execute the method instance, it can be further determined whether the method to be called is an imported method.

[0035] Imported methods refer to methods not defined in the current application module. They can be understood as methods other than those defined by the application itself. The number of imported methods is included in the downloaded file. If the method index is greater than or equal to the number of imported methods, it is an application-defined method; otherwise, it is an imported method.

[0036] After determining that the method to be called is an imported method, obtain the signature parsing parameters of the method to be called and push them into the operand stack; set the first stack frame structure corresponding to the method to be called, call the native method and write the return value of the native method into the stack frame, and restore the calling function instance.

[0037] The first stack frame structure includes the frame address of the previously called method, the index of the current method, the offset of the current method's return value in the operand stack, the current method's bytecode address, the address of the local variable stack, and the address of the operand stack. This stack frame structure can reduce stack space usage and minimize runtime stack space consumption.

[0038] In the native method, parameter type checking and parameter passing are performed simultaneously, which can avoid the two traversal processes in the prior art and convert the two traversal processes into one traversal process, thereby improving application operation efficiency.

[0039] Optionally, in this embodiment, steps 102 and 104 are designed for the import method. For the export method, the card operating system needs to call the corresponding application method to obtain the index of the export method and create a method instance for the export method, and then the bytecode interpreter will execute the export method.

[0040] Specifically, step 102 and step 104 are replaced accordingly as follows: the card operating system calls a preset application method to obtain the first index of the method to be called from the preset application method registration list, and creates a method instance corresponding to the method to be called based on the first index.

[0041] Step S108: If the method to be called is not an imported method, the method parameters of the method to be called are pushed into the operand stack; stack space is allocated, a second stack frame structure corresponding to the method to be called is set, and the calling method is obtained to execute the method instance corresponding to the method to be called.

[0042] In the binary file instruction execution method provided in the embodiment of the present application, since parameter type checking and parameter passing are performed simultaneously in the native method, the processing process and space consumption can be reduced, and it can be applied to embedded devices with limited resources to improve the application's operating performance and efficiency.

[0043] An embodiment of the present application also provides another method for executing a binary file, which is implemented on the basis of the above embodiment; this embodiment focuses on describing the instance determination process, the import method judgment process, and the execution process of the import method and the non-import method.

[0044] See also Figure 2 As shown, the instruction execution method of the binary file of this embodiment is applied to the bytecode interpreter, and specifically includes the following steps:

[0045] S1: Get the instruction to be executed from the card application binary file; the instruction to be executed refers to the next instruction to be executed, which is the instruction defined by the wasm instruction set.

[0046] S2: Determine whether the instruction to be executed is a method call instruction. If so, execute S3; if not, execute S4;

[0047] S3: Read the index of the instruction to be executed, and determine whether the method to be called is the same as the currently called method based on the index of the executed instruction. If so, execute S5; if not, execute S6;

[0048] S4: parse the instructions to be executed according to the corresponding instruction functions and execute them. After completion, execute S1;

[0049] S5: Use the instance of the currently called method as the instance of the method to be called and execute S7;

[0050] S6: Reconstruct the instance of the method to be called and execute S7;

[0051] A method instance is a data structure that stores the information a method relies on at runtime. When a method is called, this data structure is updated based on the method information in the downloaded file. This data structure is stored in RAM to improve access speed during execution, so it must be re-instantiated during method calls. For example, the method instance data structure consists of the method index, number of parameters, stack size, and return value location. Constructing a method instance involves retrieving this information from the downloaded file based on the information carried in the method call instruction and populating it into the method instance data structure. This information is then used to pass parameters, allocate stack space, and set return values.

[0052] S7: Check whether the stack space meets the space required for the method to be called. The information carried by the method call instruction can be used to obtain the stack space required for the called method to run, and compare it with the remaining available stack space. If it meets the requirements, execute S8; if not, execute S9.

[0053] S8: Determine whether the method to be called is an imported method; if so, execute S10; if not, execute S11;

[0054] Imported methods refer to methods not defined in the current application module. They can be understood as methods other than those defined by the application itself. The number of imported methods is included in the downloaded file. If the method index is greater than or equal to the number of imported methods, it is an application-defined method; otherwise, it is an imported method.

[0055] Determining whether the method to be called is an imported method includes: obtaining the number of imported methods and determining whether the first index is less than the number of imported methods; if so, determining that the method to be called is an imported method; if not, determining that the method to be called is not an imported method.

[0056] For example, the file downloaded from the flash (the executable file generated after the application is compiled by the compiler) contains 3 imported functions. When a method is called, the method index obtained from the method call instruction is 2, which is less than the number of imported functions 3. Therefore, it can be determined that the method with the method index 2 to be called is an imported method, and the calling process of the imported method is subsequently executed.

[0057] S9: Throws a stack overflow exception, exits the current process, and executes S1;

[0058] S10: Obtain the signature parsing parameters of the method to be called, push them into the stack, and execute S12;

[0059] Get the function signature corresponding to the method to be called; according to the string in the function signature, perform address conversion calculation on the parameter corresponding to the specified character, and place the calculated value as the parameter to be passed in the specified position in the operand stack.

[0060] In a Wasm application, the function signature indicates the type of the transmitted parameter, which is represented by a string. For example, i indicates that the parameter is an integer value type, and * indicates that the parameter is an address type. According to the string in the function signature, the parameter corresponding to the address type is converted and calculated, and the calculated value is placed in the specified position in the operand stack as the parameter to be passed.

[0061] S11: Transfer the method parameters of the method to be called to the stack and execute S13;

[0062] S12: Record the number and location information of the return values ​​of the method to be called; set up a first stack frame structure, call the native method of the cos layer, and write the return value of the native method into the stack frame according to the number and location information of the return values, restore the instance of the method to be called, complete the call of the method to be called, and execute S1;

[0063] The number and location information of the method return values ​​are saved in the stack frame Ret_offset field. After the method execution ends and before returning to the calling function, the return value needs to be placed in the specified location of the operand stack.

[0064] The process of writing the return value of the native method to the stack frame, restoring the instance of the method to be called, and completing the call of the method to be called is as follows:

[0065] (1) Setting the current stack frame pointer to point to the first stack frame structure corresponding to the method to be called; the above-mentioned first stack frame structure includes: the frame address of the previous calling method, the index of the current method, the offset of the current method return value in the operand stack, the current method bytecode address, the local variable stack address, and the address of the operand stack.

[0066] (2) According to the method index in the first stack frame structure, the native method in the native method table is called and the content of the native method is executed;

[0067] Taking the example in the aforementioned prior art as an example, according to the number of parameters (3), the parameters are traversed, and the parameters are resolved according to the method signature. The parameters with operand stack indexes of 0 and 1 are copied to positions 0 and 1 of the local variable stack (lp) of the calling method, and the parameter with operand stack index 3 is copied to position 2 of the local variable stack after address resolution.

[0068] During specific implementation, the new method to be called by the method to be called can be obtained, stack space can be allocated using the calculated stack size of the new method, and a third stack frame structure can be set for the new method; the new method can be called, and the third stack frame structure can be updated based on the return value after the new method is executed; the return value can be copied to the first stack frame structure of the method to be called according to the offset of the return value obtained from the third stack frame structure; and the third stack frame structure can be released.

[0069] (3) After the native method is executed, the method return value is stored in the specified location of the operand stack according to the number and position information of the return values ​​in the first stack frame structure;

[0070] (4) Set the current stack frame pointer to the stack frame structure before calling the native method.

[0071] S13: Record the number and location information of the return values ​​of the method to be called; allocate stack space, set the second stack frame structure, complete the call of the method to be called, and execute S1.

[0072] The second stack frame structure here may be the same as the aforementioned first stack frame structure.

[0073] The binary file execution method provided in the embodiments of the present application has the following advantages:

[0074] (1) By optimizing the method instance data structure, the data structure is made more compact and the method execution process is simplified.

[0075] (2) Increase the consistency judgment between the calling method and the current method. If it is the same method, there is no need to re-instantiate the method, thereby improving the execution efficiency during recursive calls; by optimizing the instantiation process during method calls, reducing the number of judgments during instantiation and the number of flash data reads, thereby improving execution efficiency.

[0076] (3) Optimize the parameter preparation process when calling native methods, combine parameter type checking with parameter passing, and reduce the number of loop operations that traverse parameters, thereby improving operational efficiency. Before the improvement, when calling native methods to pass parameters, the parameters were processed through two loop operations. The first loop transferred the parameters to a new buffer and added environment variables before the parameters. The second loop further processed the address type parameters according to the function signature. After the improvement, these two processes were combined into a single loop, and the environment variables were passed to the underlying function as separate parameters, thereby improving execution efficiency. At the same time, the use of local variables during the processing process was reduced, reducing native stack consumption.

[0077] (4) Optimization of the loaded file data structure. In this application, constant values ​​are placed in the flash, which does not require stack space and reduces the use of runtime stack space.

[0078] (5) Analyze the processing logic and optimize the processing flow to improve execution efficiency.

[0079] (6) Optimize the data composition of the frame structure to reduce the size of the frame space. For example, the stack frame data structure occupies 16 bytes before optimization, but occupies 8 bytes after optimization. This is achieved by deleting data that is not used during operation and compressing the bytes occupied by useful data.

[0080] Based on the above method embodiment, the embodiment of the present application also provides a binary file execution device, which is applied to the bytecode interpreter; see Figure 3As shown, the device includes: an instruction acquisition module 302, which is used to read the bytecode instruction to be executed currently from the binary file; an instance determination module 304, which is used to read the first index of the method to be called corresponding to the bytecode instruction when determining that the bytecode instruction is a method call instruction, and determine the method instance corresponding to the method to be called based on the first index; a first execution module 306, which is used to obtain the signature parsing parameters of the method to be called if the method to be called is an imported method, and push them into the operand stack; set the first stack frame structure corresponding to the method to be called, call the native method and write the return value of the native method into the stack frame, and restore the calling function instance; wherein, in the native method, parameter type checking and parameter passing are performed synchronously; a second execution module 308, which is used to push the method parameters of the method to be called into the operand stack if the method to be called is not an imported method; allocate stack space, set the second stack frame structure corresponding to the method to be called, obtain the calling method, and execute the method instance corresponding to the method to be called.

[0081] Furthermore, the above-mentioned instance determination module 304 is used to: obtain the second index corresponding to the currently called method; determine whether the second index is consistent with the first index; if so, use the method instance corresponding to the currently called method as the method instance corresponding to the method to be called; if not, obtain the corresponding instance data in the downloaded file according to the second index, and reconstruct the method instance required by the method to be called based on the instance data.

[0082] Furthermore, the above-mentioned device also includes: a judgment module for judging whether the method to be called is an imported method, including: obtaining the number of imported methods and judging whether the first index is less than the number of imported methods; if so, determining that the method to be called is an imported method; if not, determining that the method to be called is not an imported method.

[0083] Furthermore, the first execution module 306 is used to obtain the function signature corresponding to the method to be called; according to the character string in the function signature, the parameter corresponding to the specified character is converted into an address, and the calculated value is placed as the parameter to be passed into the specified position in the operand stack.

[0084] Furthermore, the first execution module 306 is configured to set the current stack frame pointer to point to the first stack frame structure corresponding to the method to be called; obtain the native method corresponding to the method index in the first stack frame structure from the native method table according to the method index in the first stack frame structure, and execute the native method; after the execution of the native method is completed, store the return value of the native method in a specified position on the operand stack according to the number and position information of the return values ​​in the first stack frame structure; and point the current stack frame pointer to the stack frame structure before calling the native method.

[0085] Furthermore, the first execution module 306 is used to obtain a new method to be called by the method to be called, calculate the stack size used by the new method and allocate stack space, and set a third stack frame structure for the new method; call the new method, and when the new method is executed, update the third stack frame structure based on the return value; copy the return value to the first stack frame structure of the method to be called according to the offset of the return value obtained from the third stack frame structure; and release the third stack frame structure.

[0086] Furthermore, the first stack frame structure includes: the frame address of the previous calling method, the index of the current method, the offset of the current method return value in the operand stack, the current method bytecode address, the local variable stack address, and the address of the operand stack.

[0087] The device provided in the embodiment of the present application has the same implementation principle and technical effects as those in the aforementioned method embodiment. For the sake of brief description, for matters not mentioned in the embodiment of the device, reference can be made to the corresponding content in the aforementioned method embodiment.

[0088] The present application also provides an electronic device, such as Figure 4 As shown, it is a structural diagram of the electronic device, wherein the electronic device includes a processor 41 and a memory 40, the memory 40 stores computer executable instructions that can be executed by the processor 41, and the processor 41 executes the computer executable instructions to implement the above method.

[0089] exist Figure 4 In the illustrated embodiment, the electronic device further includes a bus 42 and a communication interface 43 , wherein the processor 41 , the communication interface 43 and the memory 40 are connected via the bus 42 .

[0090] Among them, the memory 40 may include a high-speed random access memory (RAM), and may also include a non-volatile memory (non-volatile memory), such as at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 43 (which can be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. can be used. The bus 42 can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. The bus 42 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or one type of bus.

[0091] The processor 41 may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by hardware integrated logic circuits in the processor 41 or by software instructions. The above processor 41 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the embodiments of the present application can be directly implemented as being executed by a hardware decoding processor, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium mature in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. The storage medium is located in the memory, and the processor 41 reads the information in the memory and completes the steps of the method of the above embodiment in combination with its hardware.

[0092] An embodiment of the present application also provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are called and executed by the processor, the computer-executable instructions prompt the processor to implement the above-mentioned method. The specific implementation can be found in the above-mentioned method embodiment, which will not be repeated here.

[0093] The computer program products of the methods, devices, and electronic devices provided in the embodiments of the present application include a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the previous method embodiments. For specific implementation, please refer to the method embodiments and will not be repeated here.

[0094] Unless otherwise specifically stated, the relative steps, numerical expressions and values ​​of the components and steps set forth in these embodiments do not limit the scope of the present application.

[0095] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0096] In the description of this application, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicating orientations or positional relationships, are based on the orientations or positional relationships shown in the accompanying drawings and are intended solely to facilitate the description of this application and simplify the description. They do not indicate or imply that the devices or components referred to must have a specific orientation, be constructed, or operate in a specific orientation. Therefore, they should not be construed as limitations on this application. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.

[0097] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The scope of protection of the present application is not limited thereto. Although the present application has been described in detail with reference to the above-described embodiments, those skilled in the art should understand that any person skilled in the art can modify or easily conceive of changes to the technical solutions described in the above-described embodiments within the technical scope disclosed in the present application, or perform equivalent replacements for some of the technical features thereof. These modifications, changes, or replacements do not deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application shall be subject to the scope of protection of the claims.

Claims

1. A method for executing a binary file, characterized in that: The method is applied to a bytecode interpreter; the method comprises: Read the bytecode instruction to be executed from the binary file; When it is determined that the bytecode instruction is a method call instruction, a first index of the method to be called corresponding to the bytecode instruction is read, and based on the first index, a method instance corresponding to the method to be called is determined, including: obtaining a second index corresponding to the currently called method; determining whether the second index is consistent with the first index; if so, using the method instance corresponding to the currently called method as the method instance corresponding to the method to be called; if not, obtaining corresponding instance data from the downloaded file according to the second index, and reconstructing the method instance required by the method to be called based on the instance data; If the method to be called is an imported method, the signature parsing parameters of the method to be called are obtained and pushed into the operand stack; a first stack frame structure corresponding to the method to be called is set, the native method is called and the return value of the native method is written into the stack frame, and the calling function instance is restored; wherein, in the native method, parameter type checking and parameter passing are performed synchronously; the first stack frame structure includes: the frame address of the previous called method, the index of the current method, the offset of the return value of the current method in the operand stack, the bytecode address of the current method, the address of the local variable stack, and the address of the operand stack; If the method to be called is not an imported method, the method parameters of the method to be called are pushed into the operand stack; stack space is allocated, a second stack frame structure corresponding to the method to be called is set, and a calling method is obtained to execute the method instance corresponding to the method to be called.

2. The method according to claim 1, characterized in that The method further comprises: determining whether the method to be called is an imported method; The determining whether the method to be called is an imported method specifically includes: Obtain the number of import methods, and determine whether the first index is less than the number of import methods; If yes, determining that the method to be called is an import method; If not, it is determined that the method to be called is not an imported method.

3. The method according to claim 1, characterized in that The step of obtaining the signature parsing parameters of the method to be called and pushing them into the operand stack includes: Obtain the function signature corresponding to the method to be called; According to the character string in the function signature, the parameter corresponding to the specified character is converted into an address, and the calculated value is placed in the specified position in the operand stack as the parameter to be passed.

4. The method according to claim 1, wherein The steps of setting a first stack frame structure corresponding to the method to be called, calling the native method and writing the return value of the native method into the stack frame, and resuming the calling function instance include: Set the current stack frame pointer to point to the first stack frame structure corresponding to the method to be called; According to the method index in the first stack frame structure, obtaining a native method corresponding to the method index in the first stack frame structure from a native method table, and executing the native method; After the native method is executed, storing the return value of the native method in a specified position of the operand stack according to the number and position information of the return values ​​in the first stack frame structure; The current stack frame pointer points to the stack frame structure before calling the native method.

5. The method according to claim 4, characterized in that The step of obtaining a native method corresponding to the method index in the first stack frame structure from a native method table and executing the native method includes: Obtaining a new method to be called by the method to be called, calculating a stack size required for the new method and allocating stack space, and setting a third stack frame structure for the new method; Calling the new method, and when the new method is executed, updating the third stack frame structure based on the return value; Copying the return value to the first stack frame structure of the method to be called according to the offset of the return value obtained from the third stack frame structure; The third stack frame structure is released.

6. A binary file execution device, characterized in that: The device is applied to a bytecode interpreter; the device comprises: The instruction acquisition module is used to read the bytecode instructions to be executed from the binary file; an instance determination module, configured to, when determining that the bytecode instruction is a method call instruction, read a first index of a method to be called corresponding to the bytecode instruction, and determine, based on the first index, a method instance corresponding to the method to be called, including: obtaining a second index corresponding to a currently called method; determining whether the second index is consistent with the first index; if so, using the method instance corresponding to the currently called method as the method instance corresponding to the method to be called; if not, obtaining corresponding instance data from a downloaded file according to the second index, and reconstructing the method instance required by the method to be called based on the instance data; A first execution module is configured to obtain, if the method to be called is an imported method, signature parsing parameters of the method to be called and push them into an operand stack; set a first stack frame structure corresponding to the method to be called, call the native method and write the return value of the native method into the stack frame, and restore the calling function instance; wherein, in the native method, parameter type checking and parameter passing are performed synchronously; the first stack frame structure includes: a frame address of a previously called method, an index of a current method, an offset of a return value of the current method in the operand stack, a bytecode address of the current method, an address of a local variable stack, and an address of an operand stack; The second execution module is used to push the method parameters of the method to be called into the operand stack if the method to be called is not an imported method; allocate stack space, set the second stack frame structure corresponding to the method to be called, obtain the calling method, and execute the method instance corresponding to the method to be called.

7. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the method according to any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the method according to any one of claims 1 to 5.