Data processing method and device, electronic equipment and storage medium
By introducing common functions in the WASM virtual machine, using function index information to determine the objective function signature and call the target native function, the problem of cumbersome calling steps and excessive memory resource usage is solved, and the operation performance and user experience are improved.
Patent Information
- Application Number
- CN202311533126.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-16
- Publication Date
- 2025-05-16
AI Technical Summary
In WASM virtual machines, the calling steps of native functions are cumbersome, the running performance is poor, and each native function has a lot of registration information and takes up more memory resources.
By introducing common functions in the WASM virtual machine, using function index information to determine the objective function signature, and calling the target native function based on the signature and parameter information, the calling process of the native function is simplified and the complexity of registration information is reduced.
It improves the calling efficiency and performance of native functions, reduces the use of memory resources, reduces the cumbersomeness of function calls, and improves the user's operation experience.
Smart Images

Figure CN120010957A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of information technology, and in particular to a data processing method and device, an electronic device, and a storage medium. Background Art
[0002] WASM (WebAssembly) is a new bytecode format whose compiled code instructions are small, portable, fast to load, and compatible with web pages (Web). With the continuous development of computer technology, the application field of WASM has evolved from web applications to loading and running in the virtual machine (VM Virtual Machine) corresponding to WASM. The virtual machine is used to indicate a complete computer system simulated by software, with complete hardware system functions and running in an isolated environment; virtual machines include system virtual machines (VMwave) and program virtual machines (JVM virtual machines).
[0003] When calling a native function through a wasm program in a WASM virtual machine, the native function needs to be compiled and registered with the WASM virtual machine. Usually, different native functions depend on different wasm programs, and each native function needs to be compiled and registered separately, which results in cumbersome function calling steps and relatively poor program performance. In addition, each called native function needs to be registered separately, which requires more registration information and occupies more memory resources. Summary of the invention
[0004] The embodiments of the present disclosure disclose a data processing method and device, an electronic device, and a storage medium.
[0005] According to a first aspect of an embodiment of the present disclosure, a data processing method is provided, which is applied to a wasm virtual machine, and the method includes:
[0006] During the running of the wasm program, function call information of the native function is obtained; wherein the function call information includes function index information and function parameter information;
[0007] In response to detecting a call instruction to a general function during the running of the wasm program, using the general function to determine a target function signature corresponding to the function index information; wherein the target function signature includes a function pointer of a target naitve function to be called;
[0008] The target naitve function pointed to by the function pointer is called by using the universal function according to the target function signature and the first function parameter information.
[0009] In some embodiments, the method further comprises:
[0010] During the compilation of the wasm program, a function signature corresponding to the function is generated according to the function information of each native function to be called by the wasm program, and function index information is allocated to the function signature;
[0011] During the registration process of the wasm program, the general function, each function signature, and function index information corresponding to the function signature are registered in association;
[0012] In response to detecting a call instruction to a universal function during the running of the wasm program, determining the target function signature corresponding to the function index information using the universal function, including:
[0013] In response to detecting the calling instruction of the universal function during the running of the wasm program, the universal function is used to determine the target function signature corresponding to the function index information in the function calling information according to the associated registered information.
[0014] In some embodiments, the generating a function signature corresponding to a function according to the function information of each native function to be called by the wasm program includes:
[0015] Storing function information of each native function to be called by the wasm program in a preset data structure;
[0016] Based on the function information corresponding to the native function in the preset data structure, a function signature corresponding to the native function is generated.
[0017] In some embodiments, the function parameter information includes parameter values of associated parameter types, and the target function signature also includes input parameter types and input parameter order of the target native function to be called;
[0018] The using the universal function to call the target native function pointed to by the function pointer according to the target function signature and the function parameter information includes:
[0019] The parameter value is assigned to the target native function pointed to by the function pointer by using the general function according to the input parameter type and the input parameter order.
[0020] In some embodiments, the using the universal function to call the target native function pointed to by the function pointer according to the target function signature and the function parameter information includes:
[0021] Using the universal function to convert the target function signature and the function parameter information respectively, to obtain a function signature in an encoding format suitable for running the native function, and function parameter information in an encoding format suitable for running the native function;
[0022] The target native function pointed to by the function pointer is called by using the universal function according to the function signature and function parameter information after format conversion.
[0023] In some embodiments, the method further comprises:
[0024] The general function is used to convert the format of the running result obtained by calling the target naitve function to obtain the running result suitable for the wasm program.
[0025] In some embodiments, storing the function information of each native function to be called by the wasm program in a preset data structure includes:
[0026] storing the function information of each native function in a data substructure in the preset data structure; wherein one piece of function information of the native function corresponds to one data substructure;
[0027] The generating a function signature corresponding to the native function based on the function information corresponding to the native function in the preset data structure includes:
[0028] Encode the function information in each data substructure respectively and generate the function signature corresponding to the native function.
[0029] According to a second aspect of an embodiment of the present disclosure, a data processing device is provided, the device comprising:
[0030] An acquisition module, used to acquire function call information of a native function during the running of a wasm program; wherein the function call information includes function index information and function parameter information;
[0031] A determination module, configured to, in response to detecting a call instruction to a general function during the running of the wasm program, determine a target function signature corresponding to the function index information using the general function; wherein the target function signature includes a function pointer of a target naitve function to be called;
[0032] A calling module is used to use the general function to call the target naitve function pointed to by the function pointer according to the target function signature and the function parameter information.
[0033] In some embodiments, the apparatus further comprises:
[0034] A generation module, used for generating a function signature corresponding to a function according to the function information of each native function to be called by the wasm program during the compilation process of the wasm program, and allocating function index information to the function signature;
[0035] A registration module, used for associating and registering the general function, each function signature, and function index information corresponding to the function signature during the registration process of the wasm program;
[0036] The determination module is used to, in response to detecting the calling instruction of the universal function during the running of the wasm program, determine the target function signature corresponding to the function index information in the function calling information according to the associated registered information using the universal function.
[0037] In some embodiments, the generation module is used to store the function information of each native function to be called by the wasm program in a preset data structure; and generate a function signature corresponding to the native function based on the function information corresponding to the native function in the preset data structure.
[0038] In some embodiments, the function parameter information includes parameter values of associated parameter types, and the target function signature also includes input parameter types and input parameter order of the target native function to be called;
[0039] The calling module is used to use the general function to assign the parameter value to the target native function pointed to by the function pointer according to the input parameter type and the input parameter order.
[0040] In some embodiments, the calling module is used to use the universal function to convert the format of the target function signature and the function parameter information respectively, to obtain a function signature in an encoding format suitable for the operation of the native function, and function parameter information in an encoding format suitable for the operation of the native function; and use the universal function to call the target native function pointed to by the function pointer according to the function signature and function parameter information after format conversion.
[0041] In some embodiments, the apparatus further comprises:
[0042] The calling module is also used to use the general function to convert the format of the running result obtained by calling the target naitve function to obtain the running result suitable for the wasm program.
[0043] In some embodiments, the generating module is used to store the function information of each native function in a data substructure in the preset data structure; wherein one piece of function information of the native function corresponds to one data substructure;
[0044] The generation module is used to encode the function information in each data substructure respectively and generate a function signature corresponding to the native function.
[0045] According to a third aspect of an embodiment of the present disclosure, there is provided an electronic device, including:
[0046] processor;
[0047] a memory for storing processor-executable instructions;
[0048] Wherein, the processor is configured to: implement the data processing method described in any embodiment of the present disclosure when running the executable instructions.
[0049] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores an executable program, wherein the executable program, when executed by a processor, implements the data processing method described in any embodiment of the present disclosure.
[0050] The technical solution provided by the embodiments of the present disclosure may have the following beneficial effects:
[0051] In the disclosed embodiment, the wasm virtual machine can determine the target function signature based on the function index information of the called target native function by using the general function, so as to call the target native function pointed to by the function pointer included in the target function signature by using the general function according to the target function signature and function parameter information. It can be understood that, on the one hand, the general function in the wasm virtual machine can be called according to the function index information. When there are multiple target native functions to be called, the wasm virtual machine can obtain the function index information corresponding to the multiple target native functions, without the need to compile and register each target native function separately, so the call to each target native function to be called is simple, convenient and fast, and the performance of the program running is better. On the other hand, by setting the general function to associate the called target native function according to the function index information, since the function index information is simple and convenient to set, the wasm virtual machine does not need to implement the call based on the complex registration information of each target native function, which saves the memory resources occupied by the registration target native function, and can further reduce the cumbersomeness of calling the target native function; thereby reducing the running jam caused by excessive memory resource occupation and improving the user's operating experience.
[0052] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0054] Figure 1 is a flowchart of a data processing method according to an exemplary embodiment;
[0055] Figure 2 is a flowchart of a data processing method according to an exemplary embodiment;
[0056] Figure 3 is a flowchart of a data processing method according to an exemplary embodiment;
[0057] Figure 4 is a flowchart of a data processing method according to an exemplary embodiment;
[0058] Figure 5 is a flowchart of a data processing method according to an exemplary embodiment;
[0059] Figure 6 is a flowchart of a data processing method according to an exemplary embodiment;
[0060] Figure 7 is a structural schematic diagram of a data processing device according to an exemplary embodiment;
[0061] Figure 8 The diagram is a schematic structural diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0062] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices consistent with some aspects of the present disclosure as detailed in the appended claims.
[0063] In the related art, the wasm virtual machine is a virtual computer that can execute wasm bytecode. wasm is designed to run in a web browser or other wasm-supported environment to provide high-performance, secure and cross-platform computing capabilities. The wasm virtual machine can run various types of programs, including native functions written in various programming languages. It should be noted that the wasm virtual machine itself does not directly support the running of native functions. Instead, it mainly supports the running of programs compiled into wasm bytecode. To run a native function in a wasm virtual machine, the function needs to be compiled into wasm bytecode. This can usually be done by using a compiler such as Emscripten, which can convert code in languages such as C / C++ into wasm bytecode. Therefore, wasm applications can provide portability and flexibility for the operation of native functions on different platforms and devices. As shown below, an exemplary application scenario of wasm applications is provided:
[0064] 1) Video, audio, and image encoding / decoding on the Web platform, AI deep learning-machine learning training and computing processes, and at least part of the computing and rendering processes that require multi-terminal unification.
[0065] 2) Existing code bases are migrated to wasm bytecode and run on multiple platforms and environments simultaneously.
[0066] 3) Big data processing process.
[0067] Figure 1 is a flowchart of a data processing method according to an exemplary embodiment; Figure 1 As shown, the data processing method includes:
[0068] S11: during the running of the wasm program, obtaining function call information of the native function; wherein the function call information includes function index information and function parameter information;
[0069] S12: In response to detecting a call instruction to a general function during the running of the wasm program, using the general function to determine a target function signature corresponding to the function index information; wherein the target function signature includes a function pointer of a target naitve function to be called;
[0070] S13: Using the general function, according to the target function signature and the function parameter information, calling the target naitve function pointed to by the function pointer.
[0071] The method described in the embodiments of the present disclosure is applied to a wasm virtual machine. The wasm virtual machine may be located in an electronic device. The electronic device may be a terminal or a server.
[0072] In the embodiments of the present disclosure, the terminal may be any mobile terminal or fixed terminal. The terminal may be a device that provides voice and / or data connectivity to a user. Exemplarily, the terminal may be an IoT terminal, such as a sensor device, a mobile phone (or a "cellular" phone), and a computer with an IoT terminal, for example, a fixed, portable, pocket-sized, handheld, computer-built-in, or vehicle-mounted device. Alternatively, the terminal may also be a device of an unmanned aerial vehicle. Alternatively, the terminal may also be a vehicle-mounted device, for example, a driving computer with wireless communication capabilities, or a wireless terminal external to the driving computer.
[0073] In the embodiments of the present disclosure, the server may be any device used to store data, process data, forward data, and provide network services.
[0074] In the disclosed embodiment, the wasm program is a binary file composed of a series of instructions. The wasm program can be compiled and generated according to a variety of programming languages. The wasm program can be compiled into a binary format and loaded and executed in a web browser or a corresponding virtual machine. The general function is part of the wasm program.
[0075] In the embodiments of the present disclosure, programming languages include C, C++, Rust, Go, etc. Before a programming language is compiled into a wasm program, it needs to be translated into a wasm instruction set; its instructions comply with the wasm specification.
[0076] In the disclosed embodiment, the wasm program runs in the operating environment corresponding to the wasm virtual machine.
[0077] In the embodiment of the present disclosure, the wasm program is composed of wasm modules. Each wasm module includes a linear memory and a set of functions; wherein the functions can be imported or exported, and the functions can be called inside or outside the wasm module.
[0078] In the embodiments of the present disclosure, a native function is used to indicate a function written in a predetermined programming language. A native function can be run in an operating environment corresponding to an operating system or hardware without being interpreted and / or compiled.
[0079] Exemplarily, when the wasm program and the called target native function are in different operating environments, the wasm program belongs to the code developed in the virtual machine environment, and the target native function belongs to the code developed in other environments to be called.
[0080] In the embodiments of the present disclosure, the running process of the wasm program is used to indicate the process of loading the executable file of the wasm program into the memory and executing it by the web browser or the wasm virtual machine. The running process includes but is not limited to the following steps: loading the executable file into the memory, setting registers and / or executing instructions.
[0081] In the embodiment of the present disclosure, the function call information may include function index information and function parameter information; the function call information may also include function name information, function body information, return type information and / or error handling information.
[0082] In the disclosed embodiment, the function index information is used for the program to find and determine the target native function to be called. The function index information may be identification information of the target function signature. Exemplarily, the identification information may be name information, number information and / or address information of the target function signature corresponding to the target native function. For example, the identification information may be a string used to identify the target function signature corresponding to the target native function.
[0083] In the disclosed embodiments, function parameter information is used to indicate information related to parameters when a function is called. Function parameter information may include: parameter name information, parameter type information, parameter value information, variable parameter quantity information, parameter passing method information and / or parameter passing order information. Exemplarily, parameter type information may include: integer (int), floating point number (float), double-precision floating point number (double), string type and / or Boolean type. It should be noted that function parameter information is mainly used to provide input parameter information for the target native function to be called, so that the wasm program can implement function calls by passing parameters.
[0084] In the disclosed embodiment, the function name information is used to indicate the function definition location and the function calling method.
[0085] In the disclosed embodiment, the function body information is used to indicate the functions that can be implemented by the function; the function body information may be the specific code corresponding to the function.
[0086] In the embodiment of the present disclosure, the return type information is used to indicate the parameter type of the execution result returned after the function call is completed.
[0087] In the disclosed embodiment, the error handling information is used to indicate the function's handling mechanism information for code exceptions and / or errors.
[0088] In step S12, the wasm virtual machine responds to detecting a call instruction to a universal function during the running of the wasm program, and uses the universal function to determine the target function signature corresponding to the function index information. Here, in response to detecting a trigger event, it can be determined that a call instruction to a universal function is detected during the running of the wasm program. The trigger event can be used to trigger the call to the universal function. Exemplarily, the trigger event can be an event in which a predetermined operation of a user is detected; or, the trigger event can be an event triggered by the automatic execution of the wasm program. It should be noted that in the embodiment of the present disclosure, the universal function is a calling function used to call different target native functions. After being compiled, each target native function is associated with the universal function, so that the wasm virtual machine can implement the call to each target native function through the universal function.
[0089] In the disclosed embodiment, the wasm virtual machine uses a general function to determine the target function signature corresponding to the function index information, wherein the function signature is used to identify the function to implement function overloading, function identification and function calling. The function signature may include function name information, parameter type information, parameter number information and parameter order information, as well as function class information and namespace information. The target function signature may be the function signature of the target native function.
[0090] In some embodiments, a function pointer is used to indicate a pointer variable and / or address pointing to a function, and a program can call a function through the function pointer.
[0091] In step S13, the wasm virtual machine uses a universal function to call the target native function pointed to by the function pointer according to the target function signature and function parameter information. As mentioned above, the target function signature provides a function pointer of the target native function to be called, the function parameter information provides the input parameter value of the target native function to be called, and the function pointer can point to the target native function to be called. Therefore, in the embodiment of the present disclosure, the wasm virtual machine can use a universal function to call the target native function through the target function signature and function parameter information.
[0092] It should be noted that in the embodiment of the present disclosure, the target native function that needs to be called during the operation of the wasm program may be one or more. In the case of multiple target native functions, the function call information obtained by the wasm virtual machine may include function index information for multiple target native functions, and function parameter information for each target native function. In step S12, the wasm virtual machine uses a general function to determine multiple target function signatures corresponding to multiple function index information; wherein one function index information corresponds to one target function signature, one target function signature corresponds to one target native function, and each target function signature includes a function pointer to the target native function to be called. In step S13, the wasm virtual machine uses a general function to call the target native function pointed to by the function pointer in parallel according to the target function signature and function parameter information; or, calls the target native function pointed to by the function pointer in serial according to a predetermined order.
[0093] As mentioned above, in the related art, the wasm virtual machine needs to implement the call based on the registration information of each target native function to be called; wherein the registration information includes but is not limited to: function name, function parameters, function return value and function body. In this way, the wasm virtual machine needs to call the above complex registration information of each target native function to be called, which occupies more memory resources.
[0094] In contrast, in the disclosed embodiment, the wasm virtual machine can determine the target function signature based on the function index information of the called target native function by using the general function, and thus call the target native function pointed to by the function pointer included in the target function signature by using the general function according to the target function signature and function parameter information. It can be understood that, on the one hand, the wasm virtual machine general function can be called according to the function index information. When there are multiple target native functions to be called, the wasm virtual machine can obtain the function index information corresponding to the multiple target native functions, without the need to compile and register each target native function separately, so the call to each target native function to be called is simple, convenient and fast, and the program runs with good performance. On the other hand, by setting the general function to associate the called target native function according to the function index information, since the function index information is simple and convenient to set, the wasm virtual machine does not need to implement the call based on the complex registration information of each target native function, which saves the memory resources occupied by registering the target native function, and can further reduce the cumbersomeness of calling the target native function; thereby reducing the running jam caused by excessive memory resource occupation, and improving the user's operating experience.
[0095] In some embodiments, Figure 2 As shown, the method also includes:
[0096] S21: during the compilation process of the wasm program, generating a function signature corresponding to the function according to the function information of each native function to be called by the wasm program, and assigning function index information to the function signature;
[0097] S22: During the registration process of the wasm program, the general function, each function signature, and function index information corresponding to the function signature are registered in association;
[0098] The aforementioned S12 includes:
[0099] S121: In response to detecting the calling instruction of the universal function during the running of the wasm program, using the universal function to determine the target function signature corresponding to the function index information in the function calling information according to the associated registered information.
[0100] In the disclosed embodiment, the compilation process of the wasm program is used to indicate the process of converting the source code of each native function to be called and the text file associated with the function into an executable file.
[0101] In the disclosed embodiment, the registration process of the wasm program refers to the registration process of the function associated with the wasm program; function registration is a process of associating a function with a specific event or signal. When an event or signal occurs, the registered function will be called to perform the corresponding operation. In the disclosed embodiment, the function signatures of the general function and each native function and the index information corresponding to the function signature are associated and registered, so that when a call instruction to the general function is detected, the registered target native function can be called.
[0102] In the embodiment of the present disclosure, the registration process of the wasm program is used to indicate the process of loading the wasm module into the wasm virtual machine and making it available.
[0103] In the embodiments of the present disclosure, the registration method of the wasm program includes but is not limited to at least one of the following:
[0104] Register using JavaScript API: Use the methods provided by the WebAssembly JavaScript API for loading and executing wasm modules to load the wasm module into the wasm virtual machine and register it as a JavaScript object or function.
[0105] Register using packaging tools such as Webpack: Package the wasm module as a static resource into the application through front-end packaging tools such as Webpack, and automatically register it as a JavaScript object or function.
[0106] Register with server-side rendering: In server-side rendering, the wasm module can be loaded to the server and registered as an object or function available on the server; the corresponding JavaScript code is included in the HyperText Markup Language (HTML) generated on the server to load and use the registered wasm module on the client.
[0107] It should be noted that in the embodiment of the present disclosure, the wasm virtual machine needs to ensure that the path, name and type of the wasm module are correct so that the wasm virtual machine can correctly load and execute the wasm module. In addition, the wasm virtual machine also needs to ensure that the input and output formats of the wasm module are consistent with the requirements of the application program in order to achieve correct data interaction.
[0108] As mentioned above, in the related art, when there are many native functions to be called, the wasm virtual machine compiles and registers each native function separately, the function call steps are cumbersome, and the performance of the program running is relatively poor; moreover, the wasm virtual machine requires more time to register the native function, the function call power consumption is relatively high, and the timeliness of the function call is relatively poor.
[0109] In contrast, in the disclosed embodiment of the present invention, the wasm virtual machine assigns function index information to the function signature, and registers the general function, each function signature, and the function index information corresponding to the function signature. On the one hand, the wasm virtual machine does not need to separately compile and register each target native function to be called, reducing the time used to compile and register the target native function, thereby ensuring the timeliness of calling the target native function; and, it also reduces the cumbersome procedures for calling the target native function and improves the user's operating experience. On the other hand, there is no need to traverse the above-mentioned complex registration information of each target native function to be called, and the corresponding function signature and its associated function information can be quickly determined based on the associated registered function index information; in this way, while improving the query efficiency, it also shortens the function call time and improves the program's running performance.
[0110] In some embodiments, Figure 3 As shown, the aforementioned S21 includes:
[0111] S211: storing function information of each native function to be called by the wasm program in a preset data structure;
[0112] S212: Generate a function signature corresponding to the native function based on the function information corresponding to the native function in the preset data structure.
[0113] In some embodiments, the preset data structure may include, but is not limited to: an array, a list and / or a linked list.
[0114] In some embodiments, the aforementioned S211 includes: storing the function information of each native function in a data substructure in the preset data structure; wherein one piece of the function information of the native function corresponds to one of the data substructures;
[0115] The aforementioned S212 includes: encoding the function information in each data substructure respectively, and generating a function signature corresponding to the native function.
[0116] Exemplarily, the preset data structure is a list, and the data substructure in the list includes the list in the 1st row to the list in the nth row; wherein n is a positive integer, and n is greater than 1. The function information of the 1st function is stored in the list in the 1st row of the list; the function information of the 2nd function is stored in the list in the 2nd row of the list; and so on, the function information of the nth function is stored in the list in the nth row of the list.
[0117] Exemplarily, the function information of the first function is "int add(int a, int b)", indicating that the function name corresponding to the function information is "add", the input parameters are "a" and "b", the parameter types of the two input parameters are both integer types, and the parameter type of the return value is an integer type; the function name, input parameters and parameter types, and return value parameter type included in the function information are encoded respectively to obtain the first function signature "(s1x s1as1b)" corresponding to the first function.
[0118] In the disclosed embodiment, the wasm virtual machine can store the function information of each native function in a preset data structure in a predetermined order and / or a predetermined format, so as to facilitate the subsequent generation and search of the function signature corresponding to each native function and improve the query efficiency. In addition, the wasm virtual machine can accurately know how to call the function based on the information provided by the function signature, including the parameters to be passed and the running results of the function call; thereby reducing the difficulty of function calling and reducing the problems caused by parameter errors and / or running results errors.
[0119] In some embodiments, Figure 4As shown, the function parameter information includes the parameter value of the associated parameter type, and the target function signature also includes the input parameter type and the input parameter order of the target function to be called;
[0120] The aforementioned S13 includes:
[0121] S131: Using the general function, assigning the parameter value to the target native function pointed to by the function pointer according to the input parameter type and the input parameter order.
[0122] In the embodiment of the present disclosure, the parameter value of the associated parameter type is used to indicate the parameter value of the parameter passed to the target native function as an input parameter when the function is called.
[0123] In the embodiment of the present disclosure, the input parameter type is used to indicate the parameter type of the parameter passed to the target native function when the function is called.
[0124] Exemplarily, the parameter type of the parameter passed to the target native function can be a constant, a variable and / or an expression.
[0125] Exemplarily, the parameter type of the parameter passed to the target native function may be an integer type, a floating point type and / or a string type.
[0126] In the embodiment of the present disclosure, the input parameter order is used to indicate the order in which the parameters are passed to the target native function when the function is called.
[0127] In the disclosed embodiment, the wasm virtual machine can assign parameter values to the target native function pointed to by the function pointer according to the order and type of input parameters, thereby ensuring the accuracy of the passed parameter order and parameter type, reducing syntax errors and runtime errors; and ensuring the subsequent correct calling of the target native function.
[0128] In some embodiments, Figure 5 As shown, the aforementioned S13 includes:
[0129] S132: using the universal function to perform format conversion on the target function signature and the function parameter information respectively, to obtain a function signature in a coding format suitable for running the native function, and function parameter information in a coding format suitable for running the native function;
[0130] S133: Using the general function according to the function signature and function parameter information after format conversion, call the target naitve function pointed to by the function pointer.
[0131] In the embodiment of the present disclosure, the operating environment suitable for the running of the native function is the first operating environment.
[0132] In the embodiment of the present disclosure, the operating environment may be a process, a platform and / or an operating system. Exemplarily, the first operating environment may be a first operating system.
[0133] In the embodiments of the present disclosure, the operating environment includes, but is not limited to: an execution environment, a closed environment and / or a calling environment.
[0134] In the embodiment of the present disclosure, the encoding format applicable to the operation of the native function is used to indicate a specific encoding format of the text file in the first operating environment. Exemplarily, if the first operating environment is a Windows system, the encoding format applicable to the operation of the native function may be GBK.
[0135] In some embodiments, the aforementioned S132 includes:
[0136] According to a predetermined programming language, the universal function is used to convert the function signature in a coding format suitable for the operation of the native function and the function parameter information in a coding format suitable for the operation of the native function, respectively, to obtain the function signature in a format suitable for the predetermined programming language and the function information in a format suitable for the predetermined programming language.
[0137] In the embodiment of the present disclosure, the predetermined programming language format includes but is not limited to: C language format, C++ language format, Java language format and / or Python language format.
[0138] In the disclosed embodiment, the wasm virtual machine converts the target function signature and function parameter information into a function signature in an encoding format suitable for the operation of the native function, and function parameter information in an encoding format suitable for the operation of the native function, which can ensure reading and writing in the correct encoding format, thereby improving the fluency of subsequent function calls and reducing the occurrence of garbled characters or other errors.
[0139] In some embodiments, the method further comprises:
[0140] The general function is used to convert the format of the running result obtained by calling the target naitve function to obtain the running result suitable for the wasm program.
[0141] In the embodiment of the present disclosure, the operating environment suitable for running the wasm program is the second operating environment.
[0142] In the embodiment of the present disclosure, the encoding format applicable to the running of the wasm program is used to indicate the specific encoding format of the text file in the second operating environment. Exemplarily, if the second operating environment is a Linux system in the wasm virtual machine, the encoding format applicable to the running of the wasm program may be UTF-8.
[0143] In the embodiment of the present disclosure, the operation result may be a return result, which includes a return value and a parameter type of the return value.
[0144] In some embodiments, the using of the general function to convert the format of the running result obtained by calling the target naitve function to obtain the running result applicable to the wasm program includes:
[0145] If a universal function is used to call the target naitve function pointed to by the function pointer in parallel according to the target function signature and function parameter information, the universal function is used to convert the format of the running results obtained by calling the target naitve function in parallel;
[0146] Send the running results of each target naitve function to the wasm program in parallel.
[0147] In some embodiments, the using of the general function to convert the format of the running result obtained by calling the target naitve function to obtain the running result applicable to the wasm program includes:
[0148] If the target naitve function pointed to by the function pointer is serially called in a predetermined order according to the target function signature and function parameter information by using a universal function, the format of the operation result obtained by calling the target naitve function is serially converted in a predetermined order by using the universal function;
[0149] The running results of each target naitve function are sent serially to the wasm program in a predetermined order.
[0150] In the disclosed embodiment, the wasm virtual machine will perform format conversion based on the running result obtained by calling the target native function to obtain the running result in the encoding format suitable for the wasm program, which can ensure that the running result is returned in the correct encoding format, thereby ensuring the subsequent correct reading and writing of the running result, and further reducing the occurrence of garbled characters or other errors.
[0151] The following provides specific examples in combination with any of the above embodiments:
[0152] Specific example 1, such as Figure 6 As shown, a data processing method is executed by a wasm virtual machine, and the method includes:
[0153] S61: The program is a wasm program; during the compilation process of the program, function information such as pointers, parameters and return values of all native functions that the program depends on are organized into a data structure list (array) form, and the list is provided to the general registration function.
[0154] In some embodiments, the data structure list may be a preset data structure in the above embodiments; the universal registration function may be a universal function in the above embodiments.
[0155] S62: During the registration process of the program, the universal registration function generates a corresponding function signature from the function information of the native function in each data structure of the list, binds the function signature and the universal registration function, and registers them to the wasm virtual machine.
[0156] In some embodiments, each data structure corresponds to a data substructure in the above embodiments.
[0157] S63: When the target native function registered to the wasm virtual machine is called in the wasm code of the program, the general registration function is called first, and the function call information is passed to the general registration function.
[0158] In some embodiments, the function call information includes function index information and function parameter information; the function parameter information is associated with a parameter value of a parameter type.
[0159] S64: In the general registration function, according to the function index information, the function pointer and parameter information corresponding to the target native function are found from the above data structure list.
[0160] S65: Convert the parameter form of the function parameter information passed by the wasm virtual machine into the parameter form that the native function can receive, and call the corresponding function pointer to complete the call of the target native function; and convert the return value of calling the target native function into the format required by the wasm virtual machine and then return it to the wasm code in the wasm program.
[0161] In some embodiments, the parameter format that the native function can receive can be the encoding format applicable to the operation of the native function in the above embodiment; the format required by the wasm virtual machine can be the encoding format applicable to the operation of the wasm program in the above embodiment.
[0162] In the disclosed embodiment, the wasm virtual machine can determine the target function signature based on the function index information of the called target native function by using the general function, so as to call the target native function pointed to by the function pointer included in the target function signature by using the general function according to the target function signature and function parameter information. It can be understood that, on the one hand, the wasm virtual machine general function can be called according to the function index information. When there are multiple target native functions to be called, the wasm virtual machine can obtain the function index information corresponding to the multiple target native functions, without the need to compile and register each target native function separately, so the call to each target native function to be called is simple, convenient and fast, and the performance of the program running is better. On the other hand, by setting the general function to associate the called target native function according to the function index information, since the function index information is simple and convenient to set, the wasm virtual machine does not need to implement the call based on the complex registration information of each target native function, which saves the memory resources occupied by the registration target native function, and can further reduce the cumbersomeness of calling the target native function; thereby reducing the running jam caused by excessive memory resource occupation and improving the user's operating experience.
[0163] like Figure 7 As shown, an embodiment of the present disclosure provides a data processing device, the device comprising:
[0164] The acquisition module 701 is used to acquire function call information of a native function during the running of the wasm program; wherein the function call information includes function index information and function parameter information;
[0165] A determination module 702 is used for, in response to detecting a call instruction to a general function during the running of the wasm program, determining a target function signature corresponding to the function index information using the general function; wherein the target function signature includes a function pointer of a target naitve function to be called;
[0166] The calling module 703 is used to use the general function to call the target naitve function pointed to by the function pointer according to the target function signature and the function parameter information.
[0167] In some embodiments, the apparatus further comprises:
[0168] A generation module, used for generating a function signature corresponding to a function according to the function information of each native function to be called by the wasm program during the compilation process of the wasm program, and allocating function index information to the function signature;
[0169] A registration module, used for associating and registering the general function, each function signature, and function index information corresponding to the function signature during the registration process of the wasm program;
[0170] The determination module 702 is used to determine the target function signature corresponding to the function index information in the function call information using the general function according to the associated registered information in response to detecting the call instruction to the general function during the running of the wasm program.
[0171] In some embodiments, the generation module is used to store the function information of each native function to be called by the wasm program in a preset data structure; and generate a function signature corresponding to the native function based on the function information corresponding to the native function in the preset data structure.
[0172] In some embodiments, the function parameter information includes parameter values of associated parameter types, and the target function signature also includes input parameter types and input parameter order of the target function to be called;
[0173] The calling module 703 is used to use the general function to assign the parameter value to the target native function pointed to by the function pointer according to the input parameter type and the input parameter order.
[0174] In some embodiments, the calling module 703 is used to use the universal function to convert the format of the target function signature and the function parameter information respectively, to obtain a function signature in an encoding format suitable for the operation of the native function, and function parameter information in an encoding format suitable for the operation of the native function; and use the universal function to call the target native function pointed to by the function pointer according to the function signature and function parameter information after format conversion.
[0175] In some embodiments, the apparatus further comprises:
[0176] The calling module 703 is also used to use the general function to convert the format of the running result obtained by calling the target naitve function to obtain the running result suitable for the wasm program.
[0177] In some embodiments, the generating module is used to store the function information of each native function in a data substructure in the preset data structure; wherein one piece of function information of the native function corresponds to one data substructure;
[0178] The generation module is used to encode the function information in each data substructure respectively and generate a function signature corresponding to the native function.
[0179] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0180] An embodiment of the present disclosure provides an electronic device, including:
[0181] processor;
[0182] a memory for storing processor-executable instructions;
[0183] Wherein, the processor is configured to: implement the data processing method described in any embodiment of the present disclosure when running the executable instructions.
[0184] The memory may be various types of memory, such as random access memory, read-only memory, flash memory, etc. The memory may be used for information storage, for example, storing computer executable instructions, etc. The computer executable instructions may be various program instructions, for example, target program instructions and / or source program instructions, etc.
[0185] The processor may be any type of processor, for example, a central processing unit, a microprocessor, a digital signal processor, a programmable array, a digital signal processor, an application specific integrated circuit or an image processor, etc. The processor may be connected to the memory via a bus, which may be an integrated circuit bus, etc.
[0186] like Figure 8 As shown, an embodiment of the present disclosure shows a structure of an electronic device. Figure 8 The electronic device 900 includes a processing component 922, which further includes one or more processors, and a memory resource represented by a memory 932 for storing instructions executable by the processing component 922, such as an application. The application stored in the memory 932 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 922 is configured to execute instructions to perform the aforementioned data processing method.
[0187] The electronic device 900 may further include a power supply component 926 configured to perform power management of the terminal 900, a wired or wireless network interface 950 configured to connect the terminal 900 to a network, and an input / output (I / O) interface 958. The terminal 900 may operate based on an operating system stored in the memory 932, such as Windows Server TM, Mac OSX TM, Unix TM, Linux TM, FreeBSD TM or the like.
[0188] An embodiment of the present disclosure provides a computer-readable storage medium, wherein the computer-readable storage medium stores an executable program, wherein the executable program, when executed by a processor, implements the data processing method described in any embodiment of the present disclosure.
[0189] The computer-readable storage medium provided in the embodiments of the present disclosure may be any storage medium that can store program codes, such as ROM, PROM, EPROM, EEPROM, FlashMemory, magnetic surface storage, optical disk, or CD-ROM.
[0190] In the above embodiments provided in the present disclosure, it should be understood that the disclosed methods and devices can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as: multiple modules or components can be combined, or can be integrated into another system, or some features can be ignored, or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0191] The units described above as separate components may or may not be physically separated, and the components displayed 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 embodiment of the present disclosure.
[0192] In addition, all functional units in the embodiments of the present disclosure may be integrated into one calling module, or each unit may be distinguished as a separate unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0193] It should be noted that: "first", "second", etc. are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0194] In addition, the technical solutions described in the embodiments of the present disclosure may be arbitrarily combined without conflict.
[0195] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the claims above.
[0196] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A data processing method, characterized in that: Applied to the wasm virtual machine, the method includes: During the running of the wasm program, function call information of the native function is obtained; wherein the function call information includes function index information and function parameter information; In response to detecting a call instruction to a general function during the running of the wasm program, using the general function to determine a target function signature corresponding to the function index information; wherein the target function signature includes a function pointer of a target naitve function to be called; The target naitve function pointed to by the function pointer is called by using the universal function according to the target function signature and the function parameter information.
2. The method according to claim 1, characterized in that: The method further comprises: During the compilation of the wasm program, a function signature corresponding to the function is generated according to the function information of each native function to be called by the wasm program, and function index information is allocated to the function signature; During the registration process of the wasm program, the general function, each function signature, and function index information corresponding to the function signature are registered in association; In response to detecting a call instruction to a universal function during the running of the wasm program, determining the target function signature corresponding to the function index information using the universal function, including: In response to detecting the calling instruction of the universal function during the running of the wasm program, the universal function is used to determine the target function signature corresponding to the function index information in the function calling information according to the associated registered information.
3. The method according to claim 2, characterized in that The generating a function signature corresponding to a function according to the function information of each native function to be called by the wasm program includes: Storing function information of each native function to be called by the wasm program in a preset data structure; Based on the function information corresponding to the native function in the preset data structure, a function signature corresponding to the native function is generated.
4. The method according to claim 1, characterized in that: The function parameter information includes parameter values of associated parameter types, and the target function signature also includes input parameter types and input parameter order of the target native function to be called; The using the universal function to call the target native function pointed to by the function pointer according to the target function signature and the function parameter information includes: The parameter value is assigned to the target native function pointed to by the function pointer by using the general function according to the input parameter type and the input parameter order.
5. The method according to any one of claims 1 to 4, characterized in that The method of using the universal function to call the target naitve function pointed to by the function pointer according to the target function signature and the function parameter information includes: Using the universal function to convert the target function signature and the function parameter information respectively, to obtain a function signature in an encoding format suitable for running the native function, and function parameter information in an encoding format suitable for running the native function; The target naitve function pointed to by the function pointer is called by using the universal function according to the function signature and function parameter information after format conversion.
6. The method according to claim 5, characterized in that The method further comprises: The general function is used to convert the format of the running result obtained by calling the target naitve function to obtain the running result suitable for the wasm program.
7. The method according to claim 3, characterized in that The storing of function information of each native function to be called by the wasm program in a preset data structure includes: storing the function information of each native function in a data substructure in the preset data structure; wherein one piece of function information of the native function corresponds to one data substructure; The generating a function signature corresponding to the native function based on the function information corresponding to the native function in the preset data structure includes: Encode the function information in each data substructure respectively and generate the function signature corresponding to the native function.
8. A data processing device, characterized in that: The device comprises: An acquisition module, used to acquire function call information of a native function during the running of a wasm program; wherein the function call information includes function index information and function parameter information; A determination module, configured to, in response to detecting a call instruction to a general function during the running of the wasm program, determine a target function signature corresponding to the function index information using the general function; wherein the target function signature includes a function pointer of a target naitve function to be called; A calling module is used to use the general function to call the target naitve function pointed to by the function pointer according to the target function signature and the function parameter information.
9. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; Wherein, the processor is configured to: implement the data processing method described in any one of claims 1 to 7 when running the executable instructions.
10. A computer-readable storage medium, characterized in that: The readable storage medium stores an executable program, wherein the executable program, when executed by a processor, implements the data processing method according to any one of claims 1 to 7.