CN114327774A - Code running method, device, equipment and storage medium - Google Patents

Code running method, device, equipment and storage medium Download PDF

Info

Publication number
CN114327774A
CN114327774A CN202111649775.8A CN202111649775A CN114327774A CN 114327774 A CN114327774 A CN 114327774A CN 202111649775 A CN202111649775 A CN 202111649775A CN 114327774 A CN114327774 A CN 114327774A
Authority
CN
China
Prior art keywords
code
resource
determining
editable
amount
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111649775.8A
Other languages
Chinese (zh)
Inventor
樊冰新
陈逢锦
郑旗
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Baidu Netcom Science and Technology Co Ltd
Original Assignee
Beijing Baidu Netcom Science and Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Baidu Netcom Science and Technology Co Ltd filed Critical Beijing Baidu Netcom Science and Technology Co Ltd
Priority to CN202111649775.8A priority Critical patent/CN114327774A/en
Publication of CN114327774A publication Critical patent/CN114327774A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The disclosure provides a code running method, a code running device, code running equipment and a storage medium, and relates to the technical fields of cloud service, edge computing, artificial intelligence, block chains and the like. The specific implementation scheme is as follows: acquiring a first code of a target program during running; converting the first code into an editable code; determining a stop position of the editable code based on a preset resource use threshold; the running of the editable code stops at the stop position. The implementation mode can stop the running of the code when the resource used by the running of the code is expected to exceed the upper limit of the resource, and prevent the resource occupied by the running of the code from exceeding the upper limit of the resource.

Description

Code running method, device, equipment and storage medium
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to the technical fields of cloud services, edge computing, artificial intelligence, block chaining, and the like, and in particular, to a code running method, apparatus, device, and storage medium.
Background
The stopability of the code has important significance in the fields of block chaining, cloud native application and the like. In the aspect of cloud computing, when the resource consumption exceeds the limit, the operation of the related modules needs to be stopped; the ability to stop malicious code when confronted with malicious code is also desirable.
Disclosure of Invention
The disclosure provides a code running method, a device, equipment and a storage medium.
According to a first aspect, there is provided a code execution method, comprising: acquiring a first code of a target program during running; converting the first code into an editable code; determining a stop position of the editable code based on a preset resource use threshold; the running of the editable code stops at the stop position.
According to a second aspect, there is provided a code execution apparatus comprising: an acquisition unit configured to acquire a first code of a target program at runtime; a conversion unit configured to convert the first code into an editable code; a determination unit configured to determine a stop position of the editable code based on a resource usage threshold set in advance; a stopping unit configured to stop running the editable code to the stopping position.
According to a third aspect, there is provided an electronic device comprising: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method as described in the first aspect.
According to a fourth aspect, there is provided a non-transitory computer readable storage medium having stored thereon computer instructions for causing a computer to execute the method as described in the first aspect.
According to a fifth aspect, a computer program product comprising a computer program which, when executed by a processor, implements the method as described in the first aspect.
The technology according to the present disclosure can stop the running of the code when the resource used by the running of the code is expected to exceed the upper limit of the resource, and prevent the resource occupied by the running of the code from exceeding the upper limit of the resource.
It should be understood that the statements in this section do not necessarily identify key or critical features of the embodiments of the present disclosure, nor do they limit the scope of the present disclosure. Other features of the present disclosure will become apparent from the following description.
Drawings
The drawings are included to provide a better understanding of the present solution and are not to be construed as limiting the present disclosure. Wherein:
FIG. 1 is an exemplary system architecture diagram in which one embodiment of the present disclosure may be applied;
FIG. 2 is a flow diagram for one embodiment of a method of code execution according to the present disclosure;
FIG. 3 is a flow diagram of another embodiment of a method of code execution according to the present disclosure;
FIG. 4 is a schematic diagram of an application scenario for a code execution method according to the present disclosure;
FIG. 5 is a schematic block diagram of one embodiment of a code-running apparatus according to the present disclosure;
fig. 6 is a block diagram of an electronic device for implementing a code execution method of an embodiment of the present disclosure.
Detailed Description
Exemplary embodiments of the present disclosure are described below with reference to the accompanying drawings, in which various details of the embodiments of the disclosure are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the present disclosure. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
It should be noted that, in the present disclosure, the embodiments and features of the embodiments may be combined with each other without conflict. The present disclosure will be described in detail below with reference to the accompanying drawings in conjunction with embodiments.
Fig. 1 illustrates an exemplary system architecture to which embodiments of the code execution method or code execution apparatus of the present disclosure may be applied.
As shown in fig. 1, the system architecture may include a virtual machine and its execution engine. The Virtual Machine may be various Virtual machines such as a Java Virtual Machine (JVM), an Etherhouse Virtual Machine (EVM). The execution engine may be a part Of the virtual machine responsible for code out-Of-execution, such as an AOT (Ahead-Of-Time) execution engine, a JIT (Just-In-Time) execution engine, an interpreter, and so on.
The virtual machine is a concept relative to a 'physical machine', the two machines have code running capability, and the difference is that the running engine of the physical machine is directly established on the processor, cache, instruction set and operating system level, and the running engine of the virtual machine is realized by software, so that the structural systems of the instruction set and the running engine can be customized without being limited by physical conditions, and the instruction set format which is not directly supported by hardware can be run.
It should be noted that the code execution method provided by the embodiment of the present disclosure is generally executed by a virtual machine. Accordingly, the code running apparatus is generally provided in the virtual machine.
It should be understood that the number of virtual machines and runtime engines in FIG. 1 is merely illustrative. There may be any number of virtual machines and runtime engines, as desired for the implementation.
With continued reference to FIG. 2, a flow 200 of one embodiment of a method of code execution in accordance with the present disclosure is shown. The code running method of the embodiment comprises the following steps:
step 201, acquiring a first code of a target program during running.
In this embodiment, the execution subject may first obtain the first code of the target program when running. The target program may be any program installed on the virtual machine. A program running on a hardware or platform requires an intermediate layer for converting the programming language into a machine language understandable by the machine. Here, the machine language may be referred to as a first code. In some specific applications, the target program may be a running engine, Webassembly, which is a method for using non-JavaScript code and making it run in a browser. These codes may be C, C + + or Rust, etc. They are compiled into a browser and run at a speed close to native on the CPU. These codes are in the form of binary files, which can be used directly in JavaScript as modules. Thus, the first code may be binary code or text. The first code may exist in the form of a wasm file or a wait file, both of which are readable forms of WebAssembly.
Step 202, converting the first code into an editable code.
After obtaining the first code, the execution subject may convert the first code into editable code using a code conversion tool. Here, the editable code may be C language code, IR (Intermediate Representation) of LLVM (LLVM is a framework system of a framework compiler, written in C + +), abstract syntax tree, or the like. The transcoding tool may be a WABT (The WebAssembly Binary Toolkit), which is a set of tools for WebAssembly containing a series of tools, such as a wat2wasm tool (converting from WebAssembly text format to WebAssembly Binary format), a wasm2wat tool (converting from Binary format back to text format (also referred to as. wat) as opposed to wat2 wasm), a wasm2C tool (converting from Binary format to C language format), a wasm2js tool (converting from Binary format to JSON language format), and a wasm-objdump (displaying information about a wasm Binary file).
Step 203, based on the preset resource usage threshold, determining the stop position of the editable code.
The execution subject may determine whether the current resource usage is close to the resource usage threshold during the running of the editable code, and if the difference between the current resource usage and the resource usage threshold is within the preset range, the editable code is not run. The current position is the stop position of the editable code. Or, the execution subject estimates the resource amount occupied by each instruction in the editable code before running the editable code. And adding the resource amount occupied by each instruction and comparing the sum with a resource use threshold value. The instruction position where the sum is smaller than and closest to the above-described resource usage threshold value is taken as the stop position.
And step 204, running the editable code to the stop position and stopping.
After the stop position is determined, the editable code can be run to stop at the stop position. In this way, the amount of resources used in the code running process is not caused to exceed the upper limit of the resources.
The code running method provided by the above embodiment of the present disclosure can stop running of the code under an appropriate condition, and prevent the resource occupied by running of the code from exceeding the upper limit of the resource.
With continued reference to FIG. 3, a flow 300 of another embodiment of a method of code execution in accordance with the present disclosure is shown. As shown in fig. 3, the method of the present embodiment may include the following steps:
step 301, a first code of a target program during running is obtained.
Step 302, converting the first code into an editable code.
Step 303, determine a control flow graph of editable code.
The execution subject may further determine a control flow graph of the editable code after determining the editable code. Specifically, the execution subject may analyze an execution sequence of each instruction in the editable code, and if the execution sequence of the instructions is different from the arrangement sequence of the instructions, it is indicated that a jump exists between the instructions. By analyzing the jump relation among the instructions, a control flow graph of editable codes can be obtained. A control flow graph is an abstract representation of a program, in which each node is a basic block and edges represent jump related instructions. A basic block refers to an instruction sequence without any jump instructions, and instructions in a basic block are either all running or none running.
Step 304, determining the stop position of the editable code based on the control flow graph and the preset resource use threshold.
Execution subject after determining the control flow graph, the basic blocks in the editable code may be determined. The execution body may determine the stop position among positions between the basic blocks. Specifically, the execution body may predict the amount of resources occupied by each basic block. And adding the resource quantities in sequence according to the sequence of the basic blocks connected with the control flow graph, and comparing the obtained sum value with a resource use threshold value to obtain the stop position.
In some optional implementations of this embodiment, the execution body may determine the stop position by:
step 3041, determining jump instruction locations between basic blocks of editable code according to the control flow graph.
The execution subject may take as a jump instruction an instruction between two basic blocks of the control flow graph to jump. The execution subject may further confirm the location of the jump instruction in the editable code as the jump instruction location.
Step 3042, at each jump instruction location, determining the total amount of resources occupied by the run basic block.
The execution agent may calculate, at each jump instruction location, the total amount of resources occupied by its previous run basic block. Specifically, the execution subject may count the resource amount occupied by each basic block through the resource counting code to obtain the total resource amount.
In some optional implementations of this embodiment, the execution subject may implement the injecting of the resource statistics code by: determining an injection form of the resource statistical code according to the type of the editable code; according to the injection form, the resource statistic code is injected at the position of the jump instruction.
The execution agent may determine the injection form of the second code according to the type of the editable code. For example, if the editable code is C code, the injected form of the second code may be C code. If the type of editable code is LLVM IR, the injection form of the second code may be instructions of LLVM IR. If the type of the editable code is an abstract syntax tree, the injection form of the second code may be a node of the abstract syntax tree. The execution agent may inject the second code into the editable code via the injection form described above, resulting in the third code. For example, if the type of editable code is an abstract syntax tree, the execution body may inject the second code by modifying nodes of the abstract syntax tree.
Step 3043, predict the amount of resources occupied by the basic blocks that are not running.
The execution agent may further predict the amount of resources that need to be occupied by the un-executed basic blocks following each jump instruction location. Specifically, the execution subject may determine the resource occupation amount corresponding to each instruction according to the instruction included in the non-run basic block. And adding the resource occupation amounts of the instructions to obtain the resource occupation amount of each basic block which does not operate.
Step 3044, determine the stop position of the editable code according to the resource usage threshold, the total amount of resources, and the predicted amount of resources.
The execution subject may add the total amount of resources calculated in step 3042 to the amount of resources calculated in step 3043. And comparing the resulting sum with a resource usage threshold to determine a stopping position.
In some optional implementations of this embodiment, the method may further include: resource statistics code is injected at the jump instruction location. Accordingly, the step 3042 can be specifically realized by the following steps: and determining the total amount of resources occupied by the run basic blocks according to the resource statistical codes.
In this implementation, the execution subject may inject the preset resource statistics code at the jump instruction position. In this way, before the next basic block is run, the resource statistic code can be run to count the resource amount occupied by the run basic block.
In some optional implementation manners of this embodiment, the step 3043 may be specifically implemented by: and predicting the resource amount occupied by the non-operated basic block according to the instruction included in the non-operated basic block and the corresponding relation between the operation and the occupied resource.
In this implementation, the execution subject may obtain the corresponding relationship between the instruction and the occupied resource in advance. The corresponding relationship may include occupied resources corresponding to different types of instructions. In this way, the execution subject can search the instructions included in each basic block in the corresponding relationship, so that the resource amount occupied by each basic block can be predicted.
In some optional implementation manners of this embodiment, the step 3044 may be specifically implemented by: and in response to determining that the sum of the total amount of resources and the predicted amount of resources is greater than a resource usage threshold, determining the current jump instruction position as a stop position.
In this implementation, the execution agent may add the total amount of resources to the predicted amount of resources, and compare the obtained sum with the resource usage threshold. If the sum is greater than the resource usage threshold, it means that if the next basic block is executed, the upper limit of the resource will be exceeded, and the next basic block cannot be executed, and at this time, the current jump instruction position may be determined as the stop position.
In some optional implementations of this embodiment, the method may further include: and in response to determining that the sum of the total amount of resources and the predicted amount of resources is less than or equal to the resource usage threshold, executing a next basic block of the current jump instruction location.
In this implementation, if the sum is less than or equal to the resource usage threshold, it indicates that the next basic block may be run if the running of the next basic block does not exceed the upper limit of the resource.
Step 305, the running of the editable code is stopped at the stop position.
With continued reference to FIG. 4, a schematic diagram of one application scenario of a code execution method in accordance with the present disclosure is shown. In the application scenario of fig. 4, the user source code is converted by the language tool chain to obtain a text file or a binary code of the operation engine webassociation. The text file or binary code is converted by different language conversion tools to obtain different editable codes (including C code, LLVM IR, other modifiable intermediate representation, etc.). A control flow graph of editable code is then determined. And injecting the resource statistical code to the jump instruction position of the editable code to obtain the intermediate representation after the code is injected. And inputting the intermediate representation after the code is injected into different modules in the runtime for running. The resource counting code can count the total amount of resources occupied by each basic block which is operated, and can also predict the amount of resources occupied by the basic blocks which are not operated. Therefore, the control on the resource occupation amount can be realized, and the situation that the resource occupation amount exceeds the upper limit of the resource is avoided.
The code running method provided by the above embodiment of the present disclosure introduces a resource pre-check mechanism, judges whether running of the next basic block will cause resource exceeding the limit at the entry of the basic block, and terminates running in advance if the next basic block exceeds the limit, which can effectively ensure that the resource limit is strictly not exceeded in the block chain technical field.
In the blockchain application field, a user initiates a transaction through a node in a blockchain by using an external account in a blockchain network, and the transaction can be a common transfer transaction and can also be used for creating an intelligent contract or calling the intelligent contract. For example, a user issues an intelligent contract, the user writes the intelligent contract in a high-level language, and the intelligent contract needs to be compiled into Webassembly bytecode by a compiler to generate a contract module (which may also be referred to as a Webassembly module). The user may then publish the contract in the form of a transaction into the blockchain network. Each transaction has a gas limit (the upper limit of gas is used during the operation of the transaction), and when the resource consumption of the operation exceeds the gas limit, the subsequent operation needs to be stopped and the transaction needs to be rolled back. By the method, the resource statistical code can be dynamically injected in the execution process of the intelligent contract, and the gas statistics of each basic block in the editable code is realized, so that the gas usage of each transaction can be counted in real time, and the condition that the gas usage of the transaction exceeds the gas limit is avoided.
With further reference to fig. 5, as an implementation of the methods shown in the above-mentioned figures, the present disclosure provides an embodiment of a code running apparatus, which corresponds to the embodiment of the method shown in fig. 2, and which can be applied in various electronic devices.
As shown in fig. 5, the code running apparatus 500 of the present embodiment includes: an acquisition unit 501, a conversion unit 502, a determination unit 503, and a stop unit 504.
An obtaining unit 501 is configured to obtain a first code of a target program when the target program is running.
A conversion unit 502 configured to convert the first code into an editable code.
A determining unit 503 configured to determine a stop position of the editable code based on a resource usage threshold set in advance.
A stopping unit 504 configured to stop running the editable code at the stopping position.
In some optional implementations of this embodiment, the determining unit 503 may be further configured to: determining a control flow graph of editable code; based on the control flow graph and a preset resource usage threshold, a stop position of the editable code is determined.
In some optional implementations of this embodiment, the determining unit 503 may be further configured to: according to the control flow graph, determining jump instruction positions among basic blocks of editable codes; determining the total amount of resources occupied by the operated basic blocks at the positions of all the jump instructions; predicting the amount of resources occupied by the non-running basic blocks; and determining the stop position of the editable code according to the resource use threshold, the total amount of the resources and the predicted amount of the resources.
In some optional implementations of this embodiment, the apparatus 500 may further include an injection unit configured to: resource statistics code is injected at the jump instruction location. The determining unit 503 may be further configured to: and determining the total amount of resources occupied by the run basic blocks according to the resource statistical codes.
In some optional implementations of this embodiment, the determining unit 503 may be further configured to: and predicting the resource amount occupied by the non-operated basic block according to the instruction included in the non-operated basic block and the corresponding relation between the instruction and the occupied resource.
In some optional implementations of this embodiment, the determining unit 503 may be further configured to: and in response to determining that the sum of the total amount of the resources and the predicted amount of the resources is greater than a resource usage threshold, determining the current jump instruction position as an operation stop position.
In some optional implementations of this embodiment, the execution unit 504 may be further configured to: and in response to determining that the sum of the total amount of resources and the predicted amount of resources is less than or equal to the resource usage threshold, executing a next basic block of the current jump instruction location.
In some optional implementations of this embodiment, the injection unit is further configured to: determining an injection form of the resource statistical code according to the type of the editable code; according to the injection form, the resource statistic code is injected at the position of the jump instruction.
It should be understood that the units described in the code running apparatus 500 correspond to the respective steps in the method described in fig. 2, respectively. Thus, the operations and features described above with respect to the code execution method are equally applicable to the apparatus 500 and the units included therein, and are not described in detail here.
In the technical scheme of the disclosure, the collection, storage, use, processing, transmission, provision, disclosure and other processing of the personal information of the related user are all in accordance with the regulations of related laws and regulations and do not violate the good customs of the public order.
The present disclosure also provides an electronic device, a readable storage medium, and a computer program product according to an embodiment of the present disclosure.
Fig. 6 shows a block diagram of an electronic device 600 that executes a code execution method according to an embodiment of the disclosure. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be examples only, and are not meant to limit implementations of the disclosure described and/or claimed herein.
As shown in fig. 6, the electronic device 600 includes a processor 601 that may perform various suitable actions and processes in accordance with a computer program stored in a Read Only Memory (ROM)602 or a computer program loaded from a memory 608 into a Random Access Memory (RAM) 603. In the RAM603, various programs and data necessary for the operation of the electronic apparatus 600 can also be stored. The processor 601, the ROM 602, and the RAM603 are connected to each other via a bus 604. An I/O interface (input/output interface) 605 is also connected to the bus 604.
Various components in the electronic device 600 are connected to the I/O interface 605, including: an input unit 606 such as a keyboard, a mouse, or the like; an output unit 607 such as various types of displays, speakers, and the like; a memory 608, such as a magnetic disk, optical disk, or the like; and a communication unit 609 such as a network card, modem, wireless communication transceiver, etc. The communication unit 609 allows the electronic device 600 to exchange information/data with other devices through a computer network such as the internet and/or various telecommunication networks.
Processor 601 may be a variety of general and/or special purpose processing components with processing and computing capabilities. Some examples of processor 601 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various specialized Artificial Intelligence (AI) computing chips, various processors running machine learning model algorithms, a Digital Signal Processor (DSP), and any suitable processor, controller, microcontroller, or the like. The processor 601 executes the various methods and processes described above, such as code execution methods. For example, in some embodiments, the code execution method may be implemented as a computer software program tangibly embodied in a machine-readable storage medium, such as memory 608. In some embodiments, part or all of the computer program may be loaded and/or installed onto the electronic device 600 via the ROM 602 and/or the communication unit 609. One or more steps of the code execution method described above may be executed when the computer program is loaded into the RAM603 and executed by the processor 601. Alternatively, in other embodiments, the processor 601 may be configured to execute the code execution method by any other suitable means (e.g., by means of firmware).
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuitry, Field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), system on a chip (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs that are executable and/or interpretable on a programmable system including at least one programmable processor, which may be special or general purpose, receiving data and instructions from, and transmitting data and instructions to, a storage system, at least one input device, and at least one output device.
Program code for implementing the methods of the present disclosure may be written in any combination of one or more programming languages. The program code described above may be packaged as a computer program product. These program code or computer program products may be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the program code, when executed by the processor 601, causes the functions/acts specified in the flowchart and/or block diagram block or blocks to be performed. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of this disclosure, a machine-readable storage medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable storage medium may be a machine-readable signal storage medium or a machine-readable storage medium. A machine-readable storage medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which a user can provide input to the computer. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic, speech, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a back-end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back-end, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), Wide Area Networks (WANs), and the Internet.
The computer system may include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The Server can be a cloud Server, also called a cloud computing Server or a cloud host, and is a host product in a cloud computing service system, so as to solve the defects of high management difficulty and weak service expansibility in the traditional physical host and VPS service ("Virtual Private Server", or simply "VPS"). The server may also be a server of a distributed system, or a server incorporating a blockchain.
It should be understood that various forms of the flows shown above may be used, with steps reordered, added, or deleted. For example, the steps described in this disclosure may be performed in parallel or sequentially or in a different order, and are not limited herein as long as the desired results of the disclosed embodiments are achieved.
The above detailed description should not be construed as limiting the scope of the disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may be made in accordance with design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present disclosure should be included in the protection scope of the present disclosure.

Claims (19)

1. A code execution method, comprising:
acquiring a first code of a target program during running;
converting the first code into an editable code;
determining a stop position of the editable code based on a preset resource use threshold;
and running the editable code to the stop position to stop.
2. The method of claim 1, wherein the determining a stopping position of the editable code based on a preset resource usage threshold comprises:
determining a control flow graph of the editable code;
and determining the stop position of the editable code based on the control flow graph and a preset resource use threshold.
3. The method of claim 2, wherein the determining a stopping position of the editable code based on the control flow graph and a preset resource usage threshold comprises:
according to the control flow graph, determining jump instruction positions among basic blocks of the editable code;
determining the total amount of resources occupied by the operated basic blocks at the positions of all the jump instructions;
predicting the amount of resources occupied by the non-running basic blocks;
and determining the stop position of the editable code according to the resource use threshold, the total resource amount and the predicted resource amount.
4. The method of claim 3, wherein the method further comprises:
injecting a resource statistics code at the jump instruction location; and
the determining the total amount of resources occupied by the run basic blocks includes:
and determining the total amount of resources occupied by the operated basic blocks according to the resource statistical codes.
5. The method of claim 3, wherein the predicting an amount of resources occupied by the non-running basic blocks comprises:
and predicting the resource amount occupied by the non-operated basic block according to the instruction included in the non-operated basic block and the corresponding relation between the instruction and the occupied resource.
6. The method of claim 3, wherein said determining a stopping position of the editable code according to the resource usage threshold, the total amount of resources, and the predicted amount of resources comprises:
and determining the current jump instruction position as a stop position in response to determining that the sum of the total resource amount and the predicted resource amount is greater than the resource use threshold.
7. The method of claim 6, wherein the method further comprises:
and in response to determining that the sum of the total amount of resources and the predicted amount of resources is less than or equal to the resource usage threshold, executing a next basic block of the current jump instruction location.
8. The method of claim 4, wherein said injecting resource statistics code at the jump instruction location comprises:
determining an injection form of the resource statistical code according to the type of the editable code;
injecting the resource statistics code at the jump instruction location according to the injection form.
9. A code-running apparatus comprising:
an acquisition unit configured to acquire a first code of a target program at runtime;
a conversion unit configured to convert the first code into an editable code;
a determination unit configured to determine a stop position of the editable code based on a resource usage threshold set in advance;
a stopping unit configured to stop running the editable code to the stopping position.
10. The apparatus of claim 9, wherein the determining unit is further configured to:
determining a control flow graph of the editable code;
and determining the stop position of the editable code based on the control flow graph and a preset resource use threshold.
11. The apparatus of claim 10, wherein the determining unit is further configured to:
according to the control flow graph, determining jump instruction positions among basic blocks of the editable code;
determining the total amount of resources occupied by the operated basic blocks at the positions of all the jump instructions;
predicting the amount of resources occupied by the non-running basic blocks;
and determining the stop position of the editable code according to the resource use threshold, the total resource amount and the predicted resource amount.
12. The apparatus of claim 11, wherein the apparatus further comprises an injection unit configured to:
injecting a resource statistics code at the jump instruction location; and
the determination unit is further configured to:
and determining the total amount of resources occupied by the operated basic blocks according to the resource statistical codes.
13. The apparatus of claim 11, wherein the determining unit is further configured to:
and predicting the resource amount occupied by the non-operated basic block according to the instruction included in the non-operated basic block and the corresponding relation between the instruction and the occupied resource.
14. The apparatus of claim 11, wherein the determining unit is further configured to:
and determining the current jump instruction position as the operation stop position in response to the fact that the sum of the total resource amount and the predicted resource amount is larger than the resource use threshold value.
15. The apparatus of claim 14, wherein the execution unit is further configured to:
and in response to determining that the sum of the total amount of resources and the predicted amount of resources is less than or equal to the resource usage threshold, executing a next basic block of the current jump instruction location.
16. The apparatus of claim 12, wherein the injection unit is further configured to:
determining an injection form of the resource statistical code according to the type of the editable code;
injecting the resource statistics code at the jump instruction location according to the injection form.
17. An electronic device, comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-8.
18. A non-transitory computer readable storage medium having stored thereon computer instructions for causing the computer to execute the method of any one of claims 1-8.
19. A computer program product comprising a computer program which, when executed by a processor, implements the method according to any one of claims 1-8.
CN202111649775.8A 2021-12-30 2021-12-30 Code running method, device, equipment and storage medium Pending CN114327774A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111649775.8A CN114327774A (en) 2021-12-30 2021-12-30 Code running method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111649775.8A CN114327774A (en) 2021-12-30 2021-12-30 Code running method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114327774A true CN114327774A (en) 2022-04-12

Family

ID=81019127

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111649775.8A Pending CN114327774A (en) 2021-12-30 2021-12-30 Code running method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114327774A (en)

Similar Documents

Publication Publication Date Title
CN113342345A (en) Operator fusion method and device of deep learning framework
CN115759252A (en) Scheduling method, device, equipment and medium of deep learning inference engine
CN114879948B (en) WebAssembly-based intelligent contract processing method, device, equipment and storage medium
CN110780879B (en) Decision execution method, device, equipment and medium based on intelligent compiling technology
CN109766148B (en) Method and apparatus for processing interface method calls
CN112528641A (en) Method and device for establishing information extraction model, electronic equipment and readable storage medium
CN114327481A (en) Code processing method, device, equipment and storage medium
CN114691148A (en) Model reasoning acceleration method and device, electronic equipment and storage medium
CN114816393B (en) Information generation method, device, equipment and storage medium
CN114217848A (en) Dependency relationship processing method and device, electronic equipment and computer storage medium
CN114115884B (en) Method and related device for managing programming service
CN112925522A (en) Dependency graph generation method, dependency graph generation device, dependency graph generation apparatus, storage medium, and program product
CN112925552A (en) Code processing method, device, equipment and storage medium
CN116541069A (en) Key function evaluation method, device, electronic equipment, medium and program product
CN114327774A (en) Code running method, device, equipment and storage medium
CN114297119B (en) Intelligent contract execution method, device, equipment and storage medium
CN114579191A (en) Instruction transmitting method and device, electronic equipment and storage medium
CN114996107A (en) Log file updating method, device, equipment, medium and product
CN114327772A (en) Code injection method, device, equipment and storage medium
CN115081607A (en) Reverse calculation method, device and equipment based on embedded operator and storage medium
CN114090247A (en) Method, device, equipment and storage medium for processing data
CN114327496A (en) Code injection method, device, equipment and storage medium
WO2022035476A1 (en) Representing asynchronous state machine in intermediate code
CN116431108B (en) Object type processing method and device, electronic equipment and storage medium
CN111680867B (en) Resource allocation method and device and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination