A code system, a code execution method, a code compilation method, and a device thereof

By designing non-dynamic code and dynamic code processing modules at the business end and the execution end in the code execution system, combining the two-way linkage mechanism between the virtual machine and the interpreter, the hybrid execution of non-dynamic code and dynamic code is achieved, and the existing technology is solved It is difficult to balance the technical challenges of both execution performance and dynamic issues.

CN114816414BActive Publication Date: 2024-11-05ALIBABA (CHINA) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210225985.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-07
Publication Date
2024-11-05
Estimated Expiration
2042-03-07

AI Technical Summary

Technical Problem

The prior art is difficult to utilize the advantages of non-dynamic code and dynamic code in the code execution system to obtain good execution performance and support dynamic execution.

Method used

Design a code system, including the business end and the execution end, with a non-dynamic code processing module and a dynamic code processing module in the business end, and a virtual machine and a dynamic code interpreter in the execution end, which can be connected through a two-way linkage mechanism to achieve hybridization. Execution of code. Non-dynamic code is executed directly by the virtual machine, and dynamic code is executed jointly by the virtual machine and the interpreter, and distinguishes and calls the classes and functions in the two codes through optimization modules and calling modules.

Benefits of technology

It realizes the execution of non-dynamic code and dynamic code simultaneously in the code execution system, makes full use of the advantages of the two code execution modes, supports the flexibility of dynamic code and the high performance of non-dynamic code, and solves the problem of taking into account code updates and execution efficiency. .

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114816414B_ABST
    Figure CN114816414B_ABST
Patent Text Reader

Abstract

The present application provides a code system, and related code execution methods, code execution devices, code compilation methods, code compilation devices, electronic devices, and computer storage media. In the execution end of the above-mentioned code system, a virtual machine and a dynamic code interpreter are set at the same time. The virtual machine executes non-dynamic code alone, and can also execute dynamic code together with the dynamic code interpreter, so that the system can execute non-dynamic code and dynamic code in a mixed manner, making full use of the advantages of the two code execution modes. Furthermore, since the virtual machine and the dynamic code interpreter are connected in a two-way linkage mechanism, the class in the dynamic code is called when the non-dynamic code is executed, or the class in the non-dynamic code is called when the dynamic code is executed, the two code execution modes realize mutual calling of each other's classes and functions. The technical solution of the present application realizes the mixed execution of non-dynamic and dynamic codes, combining the advantages of two forms of code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and specifically to a code system, and a related code execution method, a code execution device, a code compilation method, a code compilation device, an electronic device, and a computer storage medium. Background Art

[0002] Code development includes technologies such as code writing, adjustment, compilation, and interpretation. It is a core technology in the computer field. The final work product is an executable instruction set, which can be provided to a computing device for execution. The execution device can perform related operations according to the instructions provided by the instruction set. Among them, the instruction set can be compiled into binary machine code or assembly language and provided to the computing device for execution. This mode is called assembly mode; the instruction set can also be formed into interpretable and executable statements, which are interpreted by the interpreter sentence by sentence and converted into binary machine language and provided to the computing device for execution. This mode is called interpretation mode.

[0003] In order to facilitate the development of code, especially to facilitate the development of code that adapts to multiple platforms under one framework, some code development frameworks are provided in the prior art. The Flutter framework is a widely used cross-platform mobile code development platform, which focuses on satisfying the code development under multiple platforms such as iOS system, Android system, and Web system, and realizes the universality of code on multiple platforms. The code generated by writing the Flutter framework can run on the above-mentioned multiple platforms. Since the present application involves the above-mentioned code development framework and the processing and execution process of the code by the computing device, the present application refers to the hardware and software environment composed of the above-mentioned code development framework and the entire process of executing the developed code as a code system.

[0004] The Flutter framework provides four modes including Debug, Release, Profile and Test. Among them, Profile mode and Release mode compile and execute code in AOT (Ahead Of Time, i.e., pre-compilation mode, compile the code into native code of the execution end before running) compilation mode, i.e., compile the code into binary machine code or at least assembly language code of the target platform in the development environment, and finally execute the function in the form of integrated machine code on the target platform, thereby obtaining better performance and package size. However, this compilation mode is also not flexible enough. If changes are required, the entire code needs to be recompiled. Therefore, the compilation mode cannot be updated at any time as needed after the machine code is executed, and it belongs to non-dynamic code. In many cases, in order to facilitate flexible execution of tasks, it is necessary to adopt an interpreted execution method, for example, bytecode interpreted execution; bytecode, abbreviated as KBC (Kernel Bytecode), is based on bytecode interpreted execution. Through the form of bytecode interpreted execution, the program can be modified and updated more flexibly, that is, dynamic code execution is supported. Of course, since the program is interpreted and executed at the same time, while it has the advantage of better flexibility, it cannot achieve overall optimization, and its execution efficiency is generally not as good as compiled code.

[0005] Therefore, how to utilize the advantages of both non-dynamic code and dynamic code in a code execution system while obtaining good execution performance and supporting the execution of dynamic code has become a technical problem that urgently needs to be solved. Summary of the invention

[0006] The present application provides a code system to solve the technical problem of how to execute non-dynamic code and dynamic code simultaneously so that the executed code has good performance and supports dynamic execution; at the same time, the present application also provides a code execution method, a code execution device, a code compilation method, a code compilation device, an electronic device and a computer storage medium.

[0007] The present application provides a code system, including: a business end and an execution end;

[0008] The service end is provided with a non-dynamic code processing module and a dynamic code processing module;

[0009] The non-dynamic code processing module is used to convert the source code into non-dynamic code;

[0010] The dynamic code processing module is used to convert the source code into an interpretable and executable dynamic code;

[0011] The execution end is provided with a virtual machine and a dynamic code interpreter; the virtual machine can read the non-dynamic code and dynamic code loaded into the execution end respectively;

[0012] The virtual machine is used to execute the non-dynamic code; and provide the dynamic code to the dynamic code interpreter, and execute the dynamic code together with the dynamic code interpreter;

[0013] The virtual machine and the dynamic code interpreter are connected in a two-way linkage mechanism to implement the execution of the mixed code.

[0014] Optionally, converting the source code into a non-dynamic code includes: converting the source code into a machine code suitable for execution on a target platform;

[0015] The virtual machine is specifically used to execute the machine code.

[0016] Optionally, the converting the source code into an interpretable and executable dynamic code includes: converting the source code into a bytecode suitable for execution on a target platform;

[0017] The virtual machine and the dynamic code interpreter jointly execute the bytecode.

[0018] Optionally, the service end further includes: an optimization module;

[0019] The optimization module is used to determine the maximum identification value of the class in the non-dynamic code and use it as the initial value of the current maximum identification value; when it is necessary to load the class in the dynamic code, the current maximum identification value is increased by 1 as the identification value of the class in the dynamic code that needs to be called, and the identification value is used to update the current maximum identification value.

[0020] Optionally, it also includes: a calling module; the calling module is used to determine whether the called class belongs to the class of dynamic code according to the identification value of the class. If it belongs to the class of dynamic code, its inheritance relationship is processed according to the record of the code itself.

[0021] Optionally, a devirtualization module is included to determine whether the dynamically called function being processed belongs to dynamic code or non-dynamic code; if it belongs to non-dynamic code, a first calling mechanism is used for processing; if it belongs to dynamic code, a second calling mechanism is used for processing.

[0022] Optionally, the devirtualization module determines whether the dynamically called function being processed belongs to dynamic code or non-dynamic code based on an identification value of a class to which the dynamically called function belongs.

[0023] Optionally, the first calling mechanism is a Dispatch table Call mechanism, and the second calling mechanism is a Switchable Call mechanism.

[0024] Optionally, the first calling mechanism calls the function of the class in the non-dynamic code based on a dispatch table including an array of function pointers, wherein the first calling mechanism uses an offset value involved in a code compilation process and a class identification value to make the call.

[0025] Optionally, the second calling mechanism is called based on a dynamic distribution mechanism of a state machine.

[0026] The present application also provides a code execution method, which is applied to an execution end and includes:

[0027] Obtain the non-dynamic code and interpretable dynamic code provided by the business end;

[0028] Using a virtual machine to execute the non-dynamic code;

[0029] The virtual machine and the dynamic code interpreter are used to execute the dynamic code together;

[0030] The virtual machine and the dynamic code interpreter are connected in a two-way linkage mechanism to implement the execution of the mixed code.

[0031] The present application also provides a code compilation method, which is applied to a business end and includes:

[0032] Using a non-dynamic code processing module to convert source code into non-dynamic code;

[0033] Using a dynamic code processing module to convert source code into dynamic code that can be interpreted and executed;

[0034] The non-dynamic code and the dynamic code are provided to an execution end.

[0035] The present application also provides a code execution device, applied to an execution end, comprising:

[0036] A non-dynamic code and dynamic code obtaining unit, used to obtain non-dynamic code and interpretable and executable dynamic code provided by a business end;

[0037] A first execution unit, configured to execute the non-dynamic code using a virtual machine;

[0038] A second execution unit, configured to execute the dynamic code by using the virtual machine and the dynamic code interpreter;

[0039] The virtual machine and the dynamic code interpreter are connected in a two-way linkage mechanism to implement the execution of the mixed code.

[0040] The present application also provides a code compilation device, which is applied to a service end, including:

[0041] A first conversion unit, used for converting the source code into the non-dynamic code by using the non-dynamic code processing module;

[0042] A second conversion unit is used to convert the source code into an interpretable and executable dynamic code by using the dynamic code processing module;

[0043] The providing unit is used to provide the non-dynamic code and the dynamic code to the execution end.

[0044] The present application also provides an electronic device, comprising:

[0045] processor;

[0046] The memory is used to store a computer program, and the computer program is run by the processor to execute the above-mentioned code execution method and code compilation method.

[0047] The present application also provides a computer storage medium, wherein the computer storage medium stores a computer program, and the computer program is run by a processor to execute the above-mentioned code execution method and code compilation method.

[0048] Compared with the prior art, the embodiments of the present application have the following advantages:

[0049] The present application provides a code system, including: a business end and an execution end; a non-dynamic code processing module and a dynamic code processing module are provided in the business end; the non-dynamic code processing module is used to convert the source code into non-dynamic code; the dynamic code processing module is used to convert the source code into an interpretable and executable dynamic code; a virtual machine and a dynamic code interpreter are provided in the execution end; the virtual machine can read the non-dynamic code and the dynamic code loaded into the execution end respectively; the virtual machine is used to execute the non-dynamic code; and the dynamic code is provided to the dynamic code interpreter, and the dynamic code is executed together with the dynamic code interpreter; the virtual machine and the dynamic code interpreter are connected in a two-way linkage mechanism to realize the execution of mixed code. In the present application, a virtual machine and a dynamic code interpreter are set up in the system at the same time. Since the virtual machine can execute non-dynamic code alone and can also execute dynamic code together with the dynamic code interpreter, the system can execute non-dynamic code and dynamic code at the same time, and then the system can make full use of the advantages of the two code execution modes. Furthermore, since the virtual machine and the dynamic code interpreter are connected in a two-way linkage mechanism, the execution of mixed code is realized, and the class or function in the dynamic code is called when the non-dynamic code is executed, or the class or function in the non-dynamic code is called when the dynamic code is executed, thereby realizing the fusion of the two code execution modes. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.

[0051] Figure 1 A schematic diagram of the overall structure of the code system provided in the first embodiment of the present application;

[0052] Figure 2 A first schematic diagram of a scenario of a code system provided in the first embodiment of the present application;

[0053] Figure 3 A second schematic diagram of a scenario of a code system provided in the first embodiment of the present application;

[0054] Figure 4 A third schematic diagram of a scenario of a code system provided in the first embodiment of the present application;

[0055] Figure 5 A flowchart of a code execution method provided in the second embodiment of the present application;

[0056] Figure 6 A flowchart of a code compilation method provided in the third embodiment of the present application;

[0057] Figure 7 A schematic diagram of a code execution device provided in a fourth embodiment of the present application;

[0058] Figure 8 A schematic diagram of a code compiling device provided in a fifth embodiment of the present application;

[0059] Fig. 9 A schematic diagram of an electronic device provided for the sixth embodiment of the present application. DETAILED DESCRIPTION

[0060] Many specific details are described in the following description to facilitate a full understanding of the present application. However, the present application can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of the present application. Therefore, the present application is not limited to the specific implementation disclosed below.

[0061] The present application provides a code system, a code execution method, a code execution device, a code compilation method, a code compilation device, an electronic device, and a computer storage medium. The code system, code execution method, code execution device, code compilation method, code compilation device, electronic device, and computer storage medium of the present application are introduced below through specific embodiments.

[0062] First embodiment

[0063] The first embodiment of the present application provides a code system, as follows Figures 1 to 4 Provide explanation.

[0064] Please refer to Figure 1 , which is a schematic diagram of the overall structure of the code system provided in the first embodiment of the present application. Figure 1 As shown in the figure, the code system of this embodiment includes a business end 1 and an execution end 2.

[0065] The business end 1, in this application, refers to a platform configured with a programming environment for implementing code development; a typical implementation method is to configure a computer or server with a Flutter development framework. In this hardware + software environment, source code can be written and processed, including the compilation of non-dynamic code to form binary machine code, such as AOT machine code; and the source code is processed into dynamic code that can be interpreted and executed, such as bytecode. The Flutter framework used in the above example is a cross-platform mobile system development system commonly used in the industry. The system can realize application development on platforms such as mobile terminals, Web terminals, PC terminals, and server backends. It is a high-performance, cross-platform technical solution; it can be used to quickly develop Android and iOS applications, and can also be used to develop Web applications. Of course, those skilled in the art also know that there are other similar cross-platform mobile development systems, such as Cordova hybrid development framework (Hybrid App) and RN (React Native) development framework. The above-mentioned entire process of developing a software project under the Flutter framework can be called a Flutter project; in this embodiment, the part that develops non-dynamic code is called a non-dynamic Flutter project, and the part that develops dynamic code is called a dynamic Flutter project. In the Flutter framework, the Dart language is used. The source code obtained by programming in this language can be compiled into binary executable machine code, such as AOT machine code, or compiled into bytecode that needs further interpretation, such as KBC bytecode.

[0066] The execution end 2, which may also be called a client, refers to a platform on which the developed code can actually run after being compiled; the specific execution end 2 can be various mobile terminals, such as mobile phones, tablet computers, laptops, and can also be servers; in this application, the typical scenario refers to mobile terminals, such as mobile phones. Of course, the execution end 2 has a common hardware environment such as a central processing unit, memory, bus, power supply, etc., and is also configured with a basic software environment such as an operating system. In order to realize the operation of the code, a corresponding code running environment will also be set up at the execution end 2, such as a virtual machine set up to implement an interface with a specific operating system platform.

[0067] Corresponding to different types of codes, the source codes of non-dynamic codes and dynamic codes can be compiled or pre-compiled in the service end 1, and these source codes can be processed in a manner corresponding to the code type, that is, whether it belongs to non-dynamic code or dynamic code. The part that processes non-dynamic code can be called a non-dynamic code processing module, which is used to compile non-dynamic code into binary machine code (or assembly language code) that can be directly executed by the execution end 2; the part that processes dynamic code can be called a dynamic code processing module, which is used to compile dynamic code into bytecode that needs to be further interpreted by an interpreter before it can be processed by the execution end.

[0068] This embodiment takes the processing of Flutter project in the system as an example to introduce the code system in detail, in which the Dart programming language is used. Although the source code corresponding to the Dart programming language can be converted into non-dynamic code or interpretable and executable dynamic code through the mechanism provided by the Dart programming language, under the prior art, for the same Flutter project, if it includes both non-dynamic code and dynamic code, it cannot be executed normally.

[0069] The service end 1 of this embodiment can compile the source code to different degrees (wherein, converting the dynamic code into bytecode that can be interpreted and executed can be regarded as a special compilation), and the execution end 2 is used to execute the converted non-dynamic code and dynamic code. As mentioned above, the execution end can be a computing device such as a mobile terminal or a PC in terms of hardware, and can use an iOS system, an Android system, or a Web system in terms of software.

[0070] In the scenario of processing Flutter projects, the non-dynamic code processing module can refer to Figure 1 The Flutter engineering engine 102 shown in FIG. 1 may include a dynamic code processing module such as Figure 1 The command tool 104 is shown.

[0071] Specifically, the non-dynamic code processing module is used to convert the source code into non-dynamic code; the non-dynamic code may refer to machine code in the form of AOT, that is, AOT machine code, which is actually a binary file that can be directly executed by a computer device. The AOT machine code can be executed on the target platform. The target platform may refer to the platform of the system supported by the execution end 2. In this embodiment, the non-dynamic code is compiled in advance according to the source code. That is: the source code generated by the non-dynamic Flutter project 101 in the business end 1 is compiled and processed by the Flutter project engine 102 also located in the business end 1 to form an AOT machine code 201. The AOT machine code 201 and the AOT machine code resources 202 that cooperate with it are configured in the execution end 2; the specific configuration method can be to install it to the execution end 2 by downloading and installing, which is actually to load the AOT machine code 201 into the memory of the execution end 2. The AOT machine code resources 202 can also be loaded into the memory of the execution end 2, or they can be partially or completely located in a software server that can communicate through the network; in Figure 1 It is assumed that the AOT machine code resource 202 is located in the non-volatile memory of the execution end 2. When the application software is executed, the Dart language virtual machine 203 reads the AOT machine code 201 from the memory, converts the AOT machine code 201 into a code form suitable for the current system environment, and executes it.

[0072] The dynamic code processing module, such as the command tool 104 of this embodiment, is used to convert the source code into an interpretable and executable dynamic code; the dynamic code may refer to a bytecode in the form of KBC (i.e., KBC bytecode), which actually corresponds to instructions to be executed one by one. The KBC bytecode can also be executed on the target platform. Different from the generation and execution methods of the above-mentioned non-dynamic code, the dynamic code is not pre-compiled and generated, but is executed in the following manner: the command tool 104 processes the source code into KBC bytecode 205, which is stored in the memory of the execution end 2. When the software application is executed, the Dart language virtual machine 203 reads it sentence by sentence according to the execution needs, and calls the KBC interpreter 204 to interpret and execute. In other words, the dynamic code cannot be executed directly, but needs to be interpreted and processed by the interpreter to form an executable machine code before it can be executed by the computing device (i.e., the execution end 2).

[0073] It can be seen that when the Flutter framework is used, the business end 1 needs to convert the source code into binary executable code (AOT machine code 201) and bytecode that needs to be interpreted and executed (KBC bytecode 205) as needed, and then send these codes to the execution end 2. The execution end 2 directly executes through the virtual machine or executes after interpretation by the interpreter according to the situation.

[0074] That is, the execution end 2 specifically uses different methods when executing non-dynamic code and dynamic code. To this end, a virtual machine (e.g. Figure 1 Dart language virtual machine 203) and dynamic code interpreter (e.g. Figure 2 KBC interpreter 204 in.

[0075] The virtual machine is a code conversion device set up to enable the same source code to be applied to different platforms. Its function is to "translate" the compiled code according to the current operating system platform so that the machine code can be executed on the current specific platform; therefore, for different operating system environments, a corresponding virtual machine will be set for the code of a certain programming language. In this embodiment, a Dart language virtual machine is set at the execution end for the Dart programming language adopted by the Flutter framework; if it is an iOS system, the Dart language virtual machine under the iOS system is used, and if it is an Android system, the Dart language virtual machine under the Android system is used.

[0076] In this embodiment, the Dart language virtual machine 203 can make the compiled executable code suitable for the specific operating system scenario of the execution end, that is, the compiled executable code of the non-dynamic code can be directly executed by the Dart language virtual machine 203.

[0077] For this application, it is also necessary to solve the problem of dynamic code execution, which requires the programming language virtual machine and the dynamic code interpreter to execute together. For this reason, this embodiment is specially designed.

[0078] Specifically, see Figure 1 In the above Flutter project processing scenario, the programming language virtual machine can be Figure 1 The Dart language virtual machine 203 and the dynamic code interpreter are KBC interpreter 204.

[0079] In this embodiment, the reason why the Dart language virtual machine 203 can execute the AOT machine code 201 and the KBC bytecode 202 is that the KBC interpreter 204 is embedded in the Dart language virtual machine 203. In this way, when the KBC bytecode 205 is called, it can be handed over to the KBC interpreter 204 for interpretation and execution. The Dart language virtual machine 203 first reads the AOT machine code 201 and its AOT machine code resources 202 compiled by the Flutter engineering engine 102 and loaded to the execution end 2 from the local storage unit, and executes according to the instructions of the AOT machine code 201. When necessary, the KBC bytecode 205 and KBC bytecode resources 206 compiled by the command tool 104 and loaded to the execution end 2 are read from the local storage unit sentence by sentence, and the KBC bytecode 205 is handed over to the KBC interpreter 204 for interpretation, and then executed according to its interpretation result.

[0080] In summary, when the Dart language virtual machine 203 reads the AOT machine code 201, it can execute the AOT machine code 201 independently. When the Dart language virtual machine 203 reads the KBC bytecode 205 when needed, it can provide the KBC bytecode 205 to the KBC interpreter 204 at the same time, and execute the KBC bytecode 205 with the help of the interpretation function of the KBC interpreter 204.

[0081] More specifically, the AOT machine code 201 may also include its corresponding AOT machine code resources 202, that is, the non-dynamic code compiled by the Flutter engineering engine 102, which actually includes the AOT machine code 201 and the corresponding AOT machine code resources 202. The software package is called a static package because it corresponds to non-dynamic instructions. When the AOT machine code 201 is executed on the execution end 2, it is necessary to declare execution permissions for it in the memory.

[0082] The KBC bytecode 205 actually also includes its corresponding resources, that is, what the Dart language virtual machine receives is actually a software package consisting of the KBC bytecode 205 and its corresponding resources KBC bytecode resources 206, which are stored in a designated storage location. Correspondingly, the software package is called a dynamic package. When executing the KBC bytecode 205, there is no need to declare execution permissions for it in memory.

[0083] Since the AOT machine code 201 stored in the execution end 2 and the static package of its corresponding resources have been completely compiled, and internal optimization at the machine code level has been performed during the compilation process, when the AOT machine code 201 is subsequently executed, internal functions can be executed in the form of machine code, thereby obtaining better performance and package size. However, the execution of such AOT machine code 201 does not support the execution of dynamic code, sacrificing dynamicity. In the system of the present application, the KBC interpreter 204 is embedded in the Dart language virtual machine 203, so that the system can execute non-dynamic code while also executing dynamic code.

[0084] Obviously, in the process of executing the AOT machine code 201, calling and executing the dynamic code will inevitably cause some conflicts. Solving these conflicts is the key to implementing the technical solution of this embodiment; it is explained below.

[0085] In general, in this system, the programming language virtual machine and the dynamic code interpreter are connected in a two-way linkage mechanism, and the execution of the mixed code can be realized by the two-way linkage mechanism, so that the class in the dynamic code can be called when the non-dynamic code is executed, and the function in the class of the dynamic code can be executed, or the class in the non-dynamic code can be called when the dynamic code is executed, and the function in the class in the non-dynamic code can be executed. Therefore, in the process of executing the AOT machine code 201 and the KBC bytecode 205 at the same time, the core problem is to solve the mutual calling of the classes of different types of codes, and to allocate the calling mechanism of the appropriate function execution. The above-mentioned mixed code execution process and the above-mentioned two core problems are explained below.

[0086] During the specific execution process, the AOT machine code 201 will fetch the KBC bytecode 205 according to the request issued during the program running, and load it into the memory, and redirect the relevant KBC bytecode resources 206 to meet the execution requirements; after the KBC bytecode 205 is loaded into the memory, it is executed instruction by instruction by the KBC interpreter 204.

[0087] In the mechanism provided by the Dart language, both non-dynamic code and dynamic code can be executed, but the function calling mechanisms of the two are different. For non-dynamic code, the Dispatch table Call calling mechanism mentioned later is used to execute its function; for dynamic code, the Switchable Call-based calling mechanism mentioned later is used to call and execute its function. Therefore, when executing non-dynamic code and dynamic code at the same time, it is necessary to distinguish which type of function belongs to and adopt the corresponding calling mechanism.

[0088] Regarding the mutual calling of classes, it should be noted that the AOT machine code 201 is generally optimized during the compilation phase, that is, it is optimized during the process of converting the source code into the AOT machine code. This optimization process is a radical optimization performed under the premise that all code information is known, thereby implementing optimization strategies to improve performance such as call devirtualization, function parameters, code constants or branch deletion, but these strategies make it impossible for the newly added classes or functions to be called by the optimized code, so that the AOT machine code cannot call the newly added code under the Patch. For example, the Class ID optimization algorithm will cause an exception in the polymorphism of the KBC class. That is, the AOT machine code 201 cannot call the class in the KBC bytecode 205 normally.

[0089] Specifically, see Figure 2 , which is a first schematic diagram of a scenario of a code system provided in the first embodiment of the present application. The diagram illustrates a deep optimization traversal of classes in AOT machine code and KBC bytecode to determine a subclass of a class, that is, to determine a class that has an inheritance relationship with a class.

[0090] For example, through the Figure 2 The tree diagram can determine the subclasses of class A in the AOT machine code. Since the AOT machine code is pre-compiled, the class IDs therein are also pre-determined and unique, and the range of the IDs of all classes in the AOT machine code can be known in advance. Therefore, by judging the class ID, it is possible to determine which classes in the AOT machine code are subclasses of class A in the AOT machine code. The classes in the KBC bytecode are different. Since the KBC bytecode is not pre-compiled, the class IDs in the KBC bytecode are also random and uncertain. Therefore, it is impossible to determine which classes in the KBC bytecode are subclasses of class A in the AOT machine code by judging the class ID.

[0091] Please continue to refer to Figure 2 , through the "Instance of" judgment process to determine which classes in the AOT machine code are subclasses of class A in the AOT machine code, for example, as long as the class ID (Class ID) in the AOT machine code is greater than or equal to 1 and less than or equal to 3, Figure 2 It can be seen that the ID of class A in the AOT machine code is 1, the ID of class A0 in the AOT machine code is 2, and the ID of class A1 in the AOT machine code is 3. The above "Instance of" is a way to obtain the information of its class through an object, which can be understood as a general function.

[0092] However, the above judgment method cannot be used to determine whether a class in the KBC bytecode is a subclass of class A in the AOT machine code. This is mainly due to the randomness of the class ID in the KBC bytecode, which results in a class that has an inheritance relationship with class A in the AOT machine code not being confirmed as a subclass of class A in the AOT machine code by the above judgment method. This is because the class ID in the KBC bytecode is not within the class ID range in the AOT machine code, resulting in an error in the judgment and failure to traverse the inheritance tree.

[0093] For example, the above judgment method can judge that class A0 in the AOT machine code and class A1 in the AOT machine code are subclasses of class A in the AOT machine code, but cannot judge that the class in the KBC bytecode is a subclass of class A in the AOT machine code. This will lead to the problem that the above AOT machine code cannot normally call the class in the KBC bytecode.

[0094] In order to solve the above problem, the IDs of the classes in the AOT machine code and the classes in the KBC bytecode are distinguished by setting an optimization module on the business side of the system.

[0095] The optimization module is used to determine the maximum identification value of the class in the non-dynamic code and use it as the initial value of the current maximum identification value; when the class in the dynamic code needs to be loaded - the dynamic code is loaded from the storage location when needed, and the class is assigned an ID at this time, the current maximum identification value is increased by 1 as the identification value of the class in the dynamic code that needs to be called - generally, it is the class ID, and the identification value is used to update the current maximum identification value.

[0096] As mentioned above, the identification value of the above class can specifically refer to the ID of the class, so that the ID of the class in the KBC bytecode is greater than the maximum ID of the class in the AOT machine code, thereby distinguishing the ID of the class in the AOT machine code and the class in the KBC bytecode.

[0097] After the above optimization, if the class ID is greater than the maximum class ID in the AOT machine code when judging the class ID, the class currently being judged is naturally the class in the KBC bytecode. For details, see Figure 3 , which is a second schematic diagram of the scenario of the code system provided by the first embodiment of the present application. Figure 2 On this basis, a method is added to determine whether the ID of the current class is greater than the maximum ID of the class in the AOT machine code (ie, Class ID>AOT MAX Class ID). If so, the inheritance tree can be continued to be traversed. From the tree diagram, it can be seen that the class in the KBC bytecode is a subclass of class A in the AOT machine code.

[0098] In the system, a calling module is also provided; the calling module is used to determine whether the called class belongs to the class of dynamic code according to the identification value of the class, and if it belongs to the class of dynamic code, the inheritance relationship is processed according to the record of the code itself.

[0099] The above optimization module actually processes the class ID in the KBC bytecode, and can distinguish the class ID in the KBC bytecode from the class ID in the AOT machine code, so as to help the calling module to process the inheritance relationship according to the record of the code itself when calling the class in the KBC bytecode, so as to successfully call the class in the KBC bytecode. Figure 3 It can be seen that the class in the KBC bytecode is a subclass of class A in the AOT machine code. This inheritance relationship can be used to call the class in the KBC bytecode.

[0100] Therefore, to ensure that the AOT machine code can call the KBC bytecode normally, the AOT code point needs to be optimized for KBC after the Class ID optimization algorithm. Because the Class ID of the class in the KBC bytecode is assigned by adding 1 to the maximum Class ID value of the AOT machine code when the class is loaded at runtime. Therefore, the Class ID of all classes in the KBC bytecode is greater than the maximum Class ID in the AOT machine code, so Figure 3 The optimization process shown is actually as long as Figure 2 Just add a Class ID judgment logic on this basis.

[0101] In order to successfully call the class function in the KBC bytecode or the class function in the AOT machine code, a devirtualization module is also provided in the system, which is used to determine whether the dynamic call function being processed belongs to dynamic code or non-dynamic code; if it belongs to non-dynamic code, the first call mechanism is used for processing; if it belongs to dynamic code, the second call mechanism is used for processing. The first call mechanism is the Dispatch table Call mechanism, and the second call mechanism is the SwitchableCall mechanism.

[0102] The devirtualization module enables the function currently being dynamically called to determine whether it belongs to dynamic code or non-dynamic code based on the identification value of the class to which the dynamically called function belongs.

[0103] Specifically, in the devirtualization module, it may actually refer to judging whether the dynamically called function belongs to a function of a class in the AOT machine code or a function of a class in the KBC bytecode based on the ID of the class to which the dynamically called function belongs.

[0104] To understand the working principle of the deblurring module, please refer to Figure 4, which is the third schematic diagram of the scenario of the code system provided by the first embodiment of the present application, in which the first calling mechanism specifically calls the function of the class in the non-dynamic code based on the dispatch table containing the function pointer array. In addition, the first calling mechanism uses the offset value involved in the code compilation process and the class identification value to call.

[0105] For example, in Figure 4 In the process, based on the ID of the class to which the dynamic call function belongs (i.e., Class ID), it is determined whether it belongs to a function of a class in the AOT machine code or a function of a class in the KBC bytecode. If it is determined to be a function of a class in the AOT machine code based on the Class ID, the Dispatch table Call mechanism is adopted, that is, the function is found in the Dispatch table based on the offset value (offset) and the class identification value (Class ID) involved in the code compilation process. If it is determined to be a function of a class in the KBC bytecode based on the Class ID, the Switchable Call mechanism is switched, and the Switchable Call mechanism is based on the dynamic dispatch mechanism of the state machine to call the function. At this time, if the KBC bytecode can be called based on the Switchable Call mechanism, the KBC interpreter is enabled to interpret the function of the class in the KBC bytecode.

[0106] In the first calling mechanism, since the Dispatch table Call is a design of dynamic call distribution based on the conditions of AOT compilation Close World, it mainly relies on the Dispatch table data structure, and the Dispatchtable itself is just an array of function pointers, but the order of its function pointers is arranged according to the class inheritance relationship. Therefore, in the AOT machine code, when a Call site calls a function, it only needs an offset value calculated at compile time + Class ID to find the target function.

[0107] Therefore, the first calling mechanism mentioned above only needs to compare the read Class ID with the AOT Max Class ID when calling the Dispatch table Call function to determine whether the function is a function of the class in the KBC bytecode. If so, it is forwarded to the Switchable Call.

[0108] Switchable Call is a dynamic dispatch mechanism designed based on the concept of state machine. Figure 4 As shown, it also searches for functions based on Class ID.

[0109] In the present application, a virtual machine and a dynamic code interpreter are set up in the system at the same time. Since the virtual machine can execute non-dynamic code alone and can also execute dynamic code together with the dynamic code interpreter, the system can execute non-dynamic code and dynamic code at the same time, and thus the system can fully utilize the advantages of the two code execution modes. Furthermore, since the virtual machine and the dynamic code interpreter are connected in a two-way linkage mechanism, the execution of mixed code is realized, and then the class or function in the dynamic code is called when the non-dynamic code is executed, or the class or function in the non-dynamic code is called when the dynamic code is executed, so that the fusion of the two code execution modes is realized.

[0110] Second embodiment

[0111] Corresponding to the code system provided in the first embodiment of the present application, the second embodiment of the present application also provides a code execution method. In fact, the code execution method corresponds to the part of the execution end of the system that executes the code. Since the process of executing the code in this embodiment is described in the first embodiment, the description is relatively simple. For the relevant parts, please refer to the partial description of the first embodiment. The method embodiment described below is only illustrative.

[0112] Please refer to Figure 5 , which is a flowchart of the code execution method provided in the second embodiment of the present application.

[0113] The code execution method of this embodiment includes the following steps:

[0114] Step S501: Obtain the non-dynamic code and the interpretable and executable dynamic code provided by the business end.

[0115] In this embodiment, the non-dynamic code includes: machine code suitable for execution on the target platform; that is, the virtual machine specifically executes the machine code.

[0116] In this embodiment, the interpretable and executable dynamic code includes: bytecode suitable for execution on the target platform; that is, the bytecode is jointly executed by the virtual machine and the dynamic code interpreter.

[0117] Step S502: using a virtual machine to execute non-dynamic code.

[0118] Of course, it is understandable that when the execution end is running, when the code to be executed is non-dynamic code, a virtual machine is used to execute the non-dynamic code.

[0119] Step S503: Use the virtual machine and the dynamic code interpreter to jointly execute the dynamic code.

[0120] It is also understandable that when the execution end is running, when the code to be executed is dynamic code, a virtual machine and a dynamic code interpreter are used to execute the dynamic code.

[0121] In this embodiment, the virtual machine and the dynamic code interpreter are connected in a bidirectional linkage mechanism to implement the execution of the hybrid code.

[0122] In this embodiment, the calling module can also be used to determine whether the called class belongs to the class of dynamic code according to the identification value of the class. If it belongs to the class of dynamic code, its inheritance relationship is processed according to the record of the code itself.

[0123] At the same time, in this embodiment, the devirtualization module can also be used to determine whether the dynamically called function being processed belongs to dynamic code or non-dynamic code; if it belongs to non-dynamic code, the first calling mechanism is used for processing; if it belongs to dynamic code, the second calling mechanism is used for processing.

[0124] Specifically, the devirtualization module determines whether the dynamically called function being processed belongs to dynamic code or non-dynamic code based on the identification value of the class to which the dynamically called function belongs.

[0125] In this embodiment, the first calling mechanism is a Dispatch table Call mechanism, and the second calling mechanism is a Switchable Call mechanism.

[0126] In this embodiment, the first calling mechanism calls the function of the class in the non-dynamic code based on the dispatch table including the function pointer array, wherein the first calling mechanism uses the offset value involved in the code compilation process and the class identification value to call.

[0127] In this embodiment, the second calling mechanism is based on a dynamic distribution mechanism of a state machine for calling.

[0128] Third embodiment

[0129] Corresponding to the code system provided in the first embodiment of the present application, the third embodiment of the present application also provides a code compilation method. In fact, the code compilation method corresponds to the part of the service end processing code in the system. Since the process of processing the code in this embodiment is described in the first embodiment, the description is relatively simple. For the relevant parts, please refer to the partial description of the first embodiment. The method embodiment described below is only illustrative.

[0130] Please refer to Figure 6 , which is a flowchart of the code compilation method provided in the third embodiment of the present application.

[0131] The code compilation method of this embodiment includes the following steps:

[0132] Step S601: using a non-dynamic code processing module to convert source code into non-dynamic code.

[0133] In this embodiment, converting the source code into the non-dynamic code includes: converting the source code into a machine code suitable for execution on the target platform.

[0134] Step S602: using a dynamic code processing module to convert the source code into an interpretable and executable dynamic code.

[0135] In this embodiment, converting the source code into interpretable and executable dynamic code includes: converting the source code into bytecode suitable for execution on the target platform.

[0136] Step S603: providing the non-dynamic code and the dynamic code to the execution end.

[0137] In this embodiment, the optimization module can also be used to determine the maximum identification value of the class in the non-dynamic code and use it as the initial value of the current maximum identification value; when the class in the dynamic code needs to be loaded, the current maximum identification value is increased by 1 as the identification value of the class in the dynamic code that needs to be called, and the identification value is used to update the current maximum identification value.

[0138] Fourth embodiment

[0139] Corresponding to the code execution method provided in the second embodiment of the present application, the fourth embodiment of the present application also provides a code execution device. Since the device embodiment is basically similar to the second embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the second embodiment. The device embodiment described below is only illustrative.

[0140] Please refer to Figure 7 , which is a schematic diagram of a code execution device provided in the fourth embodiment of the present application.

[0141] The code execution device comprises:

[0142] The non-dynamic code and dynamic code obtaining unit 701 is used to obtain the non-dynamic code and the interpretable and executable dynamic code provided by the service end;

[0143] A first execution unit 702, configured to execute the non-dynamic code using a virtual machine;

[0144] A second execution unit 703, configured to execute the dynamic code by using the virtual machine and the dynamic code interpreter;

[0145] The virtual machine and the dynamic code interpreter are connected in a two-way linkage mechanism to implement the execution of the mixed code.

[0146] Fifth embodiment

[0147] Corresponding to the code compiling method provided in the third embodiment of the present application, the fifth embodiment of the present application further provides a code compiling device. Since the device embodiment is basically similar to the third embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the third embodiment. The device embodiment described below is only illustrative.

[0148] Please refer to Figure 8 , which is a schematic diagram of a code compiling device provided in the fifth embodiment of the present application.

[0149] The code compilation device includes:

[0150] The first conversion unit 801 is used to convert the source code into the non-dynamic code by using the non-dynamic code processing module;

[0151] The second conversion unit 802 is used to convert the source code into an interpretable and executable dynamic code by using the dynamic code processing module;

[0152] The providing unit 803 is used to provide the non-dynamic code and the dynamic code to the execution end.

[0153] Sixth embodiment

[0154] Corresponding to the methods of the first and second embodiments of the present application, the sixth embodiment of the present application further provides an electronic device.

[0155] like Fig. 9 As shown, Fig. 9 This is a schematic diagram of an electronic device provided in the sixth embodiment of the present application. The electronic device includes: a processor 901; a memory 902 for storing a computer program, the computer program is run by the processor to execute the methods of the first embodiment and the second embodiment.

[0156] Seventh embodiment

[0157] Corresponding to the methods of the first and second embodiments of the present application, the seventh embodiment of the present application further provides a computer storage medium, wherein the computer storage medium stores a computer program, and the computer program is run by a processor to execute the methods of the first and second embodiments.

[0158] Although the present application is disclosed as above in the form of a preferred embodiment, it is not intended to limit the present application. Any technical personnel in this field may make possible changes and modifications without departing from the spirit and scope of the present application. Therefore, the scope of protection of the present application shall be based on the scope defined by the claims of the present application.

[0159] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory. The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.

[0160] 1. Computer readable media includes permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined in this article, computer readable media does not include non-transitory computer readable storage media (non-transitorycomputer readable storage media), such as modulated data signals and carrier waves.

[0161] 2. Those skilled in the art should understand that the embodiments of the present application can be provided as methods, systems or computer program products. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

Claims

1. A code system, It is characterized in that include: Business side and execution side; The service end is provided with a non-dynamic code processing module and a dynamic code processing module; The non-dynamic code processing module is used to convert the source code into non-dynamic code; The dynamic code processing module is used to convert the source code into an interpretable and executable dynamic code; The execution end is provided with a virtual machine and a dynamic code interpreter; the virtual machine can read the non-dynamic code and dynamic code loaded into the execution end respectively; The virtual machine is used to execute the non-dynamic code; and provide the dynamic code to the dynamic code interpreter, and execute the dynamic code together with the dynamic code interpreter; The virtual machine and the dynamic code interpreter are connected in a two-way linkage mechanism to implement the execution of the hybrid code.

2. The code system according to claim 1, It is characterized in that The converting the source code into the non-dynamic code includes: converting the source code into a machine code suitable for execution on a target platform; The virtual machine is specifically used to execute the machine code.

3. The code system according to claim 1, It is characterized in that The converting of the source code into an interpretable and executable dynamic code comprises: converting the source code into a bytecode suitable for execution on a target platform; The virtual machine and the dynamic code interpreter jointly execute the bytecode.

4. The code system according to claim 1, It is characterized in that The business end also includes: an optimization module; The optimization module is used to determine the maximum identification value of the class in the non-dynamic code and use it as the initial value of the current maximum identification value; when it is necessary to load the class in the dynamic code, the current maximum identification value is increased by 1 as the identification value of the class in the dynamic code that needs to be called, and the identification value is used to update the current maximum identification value.

5. The code system according to claim 1, It is characterized in that Also includes: Call module; The calling module is used to determine whether the called class belongs to the class of dynamic code according to the identification value of the class. If it belongs to the class of dynamic code, its inheritance relationship is processed according to the record of the code itself.

6. The code system according to claim 5, It is characterized in that It includes a devirtualization module for determining whether the dynamically called function being processed belongs to dynamic code or non-dynamic code; If it is a non-dynamic code, the first calling mechanism is used for processing; If it is a dynamic code, the second calling mechanism is used for processing.

7. The code system according to claim 6, It is characterized in that The basis for the devirtualization module to determine whether the dynamically called function being processed belongs to dynamic code or non-dynamic code is to make the determination based on the identification value of the class to which the dynamically called function belongs.

8. The code system according to claim 7, It is characterized in that The first calling mechanism is the Dispatch tableCall mechanism, and the second calling mechanism is the Switchable Call mechanism.

9. The code system according to claim 6, It is characterized in that The first calling mechanism calls the function of the class in the non-dynamic code based on a dispatch table including a function pointer array, wherein the first calling mechanism uses an offset value involved in a code compilation process and a class identification value for the call.

10. The code system according to claim 6, It is characterized in that The second calling mechanism performs calling based on a dynamic distribution mechanism of a state machine.

11. A code execution method, applied to an execution end, It is characterized in that include: Obtain the non-dynamic code and interpretable dynamic code provided by the business end; Using a virtual machine to execute the non-dynamic code; The virtual machine and the dynamic code interpreter are used to execute the dynamic code together; The virtual machine and the dynamic code interpreter are connected in a two-way linkage mechanism to implement the execution of the hybrid code.

12. A code compilation method, applied to the business end, It is characterized in that include: Using a non-dynamic code processing module to convert source code into non-dynamic code; Using a dynamic code processing module to convert source code into dynamic code that can be interpreted and executed; The non-dynamic code and the dynamic code are provided to an execution end.

13. A code execution device, applied to an execution end, It is characterized in that include: A non-dynamic code and dynamic code obtaining unit, used to obtain non-dynamic code and interpretable and executable dynamic code provided by a business end; A first execution unit, configured to execute the non-dynamic code using a virtual machine; A second execution unit, configured to execute the dynamic code by using the virtual machine and the dynamic code interpreter; The virtual machine and the dynamic code interpreter are connected in a two-way linkage mechanism to implement the execution of the hybrid code.

14. A code compilation device, applied to a business end, It is characterized in that include: A first conversion unit, used for converting the source code into the non-dynamic code by using the non-dynamic code processing module; A second conversion unit, used for converting the source code into an interpretable and executable dynamic code by using the dynamic code processing module; The providing unit is used to provide the non-dynamic code and the dynamic code to the execution end.

15. An electronic device, It is characterized in that include: processor; A memory for storing a computer program, wherein the computer program is executed by a processor to perform the method according to any one of claims 11 to 12.

16. A computer storage medium, It is characterized in that The computer storage medium stores a computer program, which is executed by a processor to perform the method according to any one of claims 11 to 12.