Program code compiling method and device, computer equipment and storage medium

By identifying and processing variable definition information of the main thread and child thread and generating target files, the problem of context loss in thread variable context transmission is solved, and the efficiency of program development is improved.

CN119690449AActive Publication Date: 2025-03-25CHINA PING AN LIFE INSURANCE CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411749146.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-28
Publication Date
2025-03-25
Estimated Expiration
2044-11-28

AI Technical Summary

Technical Problem

In program development, the context transmission of thread variables has a problem of context loss, which leads to cumbersome modification of the code to avoid this problem.

Method used

By obtaining code compilation instructions and identifying instruction parameters, identifying the main thread and child thread, and obtaining their respective variable definition information. The main program is converted into the first bytecode file, the subroutine is converted into the second bytecode file, and the bytecode file of the subthread is modified according to the variable definition information of the main thread to generate the target file.

Benefits of technology

It implements the use of local variables inside the main program in the subroutine without modifying the code, which improves the efficiency of program development.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119690449A_ABST
    Figure CN119690449A_ABST
Patent Text Reader

Abstract

The invention relates to the field of computer programs, and provides a program code compiling method, device and equipment and a computer storage medium. The method comprises the steps that a code compiling instruction is acquired, and instruction parameters in the code compiling instruction are identified; obtaining a source file corresponding to the code compiling instruction, and identifying a main thread and a sub-thread in the source file under the condition that the target instruction parameter is identified; obtaining first variable definition information corresponding to the main thread and second variable definition information corresponding to the sub-thread; converting a main program in the source file into a first bytecode file according to the first variable definition information, and converting a subprogram in the source file into a second bytecode file according to the second variable definition information; modifying the second bytecode file according to the first variable definition information to obtain a third bytecode file; and determining a target file corresponding to the source file according to the first bytecode file and the third bytecode file.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer programs, and in particular to a program code compiling method, apparatus, computer equipment and storage medium. Background Art

[0002] Threads are the basic units of program execution. Each thread has its own operating environment, including its own program counter, stack, registers, etc. The context information of each thread is stored in its own thread variables, and the thread variables of different threads are isolated. However, in actual system design, it is often necessary to create another child thread in one thread to complete asynchronous operations, such as asynchronous requests, asynchronous calculations, asynchronous logging, etc. If the thread variable's thread isolation feature is ignored and the thread variable is used for context transfer, the problem of context loss will occur. In order to avoid this problem, the context transfer of thread variables usually requires code modification, which is cumbersome. How to efficiently implement the context transfer of thread variables has become an urgent problem to be solved. Summary of the invention

[0003] The main purpose of this application is to provide a program code compilation method, device, equipment and computer storage medium, aiming to improve the efficiency of program development.

[0004] In a first aspect, the present application provides a method for compiling a program code, the method comprising the following steps:

[0005] Obtaining a code compilation instruction and identifying instruction parameters in the code compilation instruction;

[0006] Obtaining a source file corresponding to the code compilation instruction, and identifying a main thread and a sub-thread in the source file when a target instruction parameter is identified;

[0007] Obtaining first variable definition information corresponding to the main thread and second variable definition information corresponding to the child thread;

[0008] Converting a main program in the source file into a first bytecode file according to the first variable definition information, and converting a subprogram in the source file into a second bytecode file according to the second variable definition information;

[0009] Modify the second bytecode file according to the first variable definition information to obtain the third bytecode file;

[0010] A target file corresponding to the source file is determined according to the first bytecode file and the third bytecode file.

[0011] In a second aspect, the present application further provides a program code compiling device, the program code compiling device comprising:

[0012] An instruction acquisition module, used to acquire a code compilation instruction and identify instruction parameters in the code compilation instruction;

[0013] An instruction response module, used for obtaining a source file corresponding to the code compilation instruction, and identifying a main thread and a sub-thread in the source file when a target instruction parameter is identified;

[0014] A definition information acquisition module, used to acquire first variable definition information corresponding to the main thread and second variable definition information corresponding to the child thread;

[0015] A file conversion module, configured to convert a main program in the source file into a first bytecode file according to the first variable definition information, and to convert a subroutine in the source file into a second bytecode file according to the second variable definition information;

[0016] A file modification module, used for modifying the second bytecode file according to the first variable definition information to obtain the third bytecode file;

[0017] The target file output module is used to determine the target file corresponding to the source file according to the first bytecode file and the third bytecode file.

[0018] In a third aspect, the present application also provides a computer device, comprising a processor, a memory, and a computer program stored in the memory and executable by the processor, wherein when the computer program is executed by the processor, the program code compilation method as described above is implemented.

[0019] In a fourth aspect, the present application further provides a computer-readable storage medium, on which a computer program is stored, wherein when the computer program is executed by a processor, the program code compilation method as described above is implemented.

[0020] The present application provides a program code compilation method, device, equipment and computer storage medium. The present application obtains a code compilation instruction and identifies the instruction parameters in the code compilation instruction; obtains the source file corresponding to the code compilation instruction, and identifies the main thread and the sub-thread in the source file when the target instruction parameter is identified; obtains the first variable definition information corresponding to the main thread, and the second variable definition information corresponding to the sub-thread; converts the main program in the source file into a first bytecode file according to the first variable definition information, and converts the sub-program in the source file into a second bytecode file according to the second variable definition information; modifies the second bytecode file according to the first variable definition information to obtain the third bytecode file; determines the target file corresponding to the source file according to the first bytecode file and the third bytecode file. Since the variable transfer between the main program and the sub-program is indicated by the target parameter instruction, the local variables inside the main program can be used in the sub-program without modifying the code, thereby improving the efficiency of program development. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0022] Figure 1 A flowchart of a program code compiling method provided in one embodiment of the present application;

[0023] Figure 2 A usage scenario diagram of a program code compilation method provided in one embodiment of the present application;

[0024] Figure 3 A schematic block diagram of a program code compiling device provided in one embodiment of the present application;

[0025] Figure 4 The present invention is a block diagram showing the structure of a computer device according to an embodiment of the present application. DETAILED DESCRIPTION

[0026] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0027] The flowcharts shown in the accompanying drawings are only examples and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may also be decomposed, combined or partially merged, so the actual execution order may change according to actual conditions.

[0028] Embodiments of the present application provide a program code compiling method, apparatus, computer equipment, and computer-readable storage medium.

[0029] In conjunction with the accompanying drawings, some embodiments of the present application are described in detail below. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.

[0030] Please refer to Figure 1 , Figure 1 A flow chart of a program code compilation method provided for an embodiment of the present application. The program code compilation method can be used in a terminal or a server to implement variable transfer between a main program and a subroutine. Among them, the terminal can be an electronic device such as a mobile phone, a tablet computer, a laptop computer, a desktop computer, a personal digital assistant, and a wearable device; the server can be an independent server, or a server cluster, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and big data and artificial intelligence platforms.

[0031] Please refer to Figure 2 , Figure 2 This is a usage scenario diagram provided by an embodiment of the present application. Figure 2 As shown, the first bytecode file and the second bytecode file are generated according to the source file. If a tangent point is detected in the second bytecode file, the second bytecode file is converted into a third bytecode file, and a target file is generated based on the first bytecode file and the third bytecode file; if a tangent point is not detected in the second bytecode file, the target file is directly generated based on the first bytecode file and the second bytecode file.

[0032] like Figure 1 As shown, the program code compiling method includes steps S101 to S106.

[0033] Step S101: Obtain a code compilation instruction, and identify instruction parameters in the code compilation instruction.

[0034] Exemplarily, the code compilation instruction is used to instruct the start of compiling the program code. In the code compilation instruction, the user can specify to compile one or more source files that record the program code. The code compilation instruction can also include other optional instruction parameters. For example, in Java, the instruction parameter "-proc:{none,only}" can be used to control whether to perform annotation processing and compilation, and the instruction parameter "-processor_class1_[,_class2_...]" can be used to specify the name of the annotation processor to be run. The type of instruction parameter is not limited to this, and the instruction parameter may not be used in the code compilation instruction, which is not limited here.

[0035] Step S102: Obtain a source file corresponding to the code compilation instruction, and identify a main thread and a sub-thread in the source file when a target instruction parameter is identified.

[0036] Exemplarily, the program code compiling method provided in the embodiment of the present application is executed when it is recognized that the code compiling instruction contains a target instruction parameter.

[0037] In some implementations, obtaining a source file corresponding to the code compilation instruction, and identifying a main thread and a sub-thread in the source file when a target instruction parameter is identified, includes:

[0038] When the code compilation instruction includes a preset Java probe, the main thread and the sub-thread in the source file are identified.

[0039] Exemplarily, the target instruction parameter may be, for example, a preset Java probe, that is, a preset Java Agent instruction. By adding the preset Java Agent instruction to the code compilation instruction, it is possible to avoid modifying the program code in order to transfer variables between the main thread and the child thread, thereby reducing the complexity of variable transfer.

[0040] Step S103: Obtain first variable definition information corresponding to the main thread and second variable definition information corresponding to the child thread.

[0041] In the related art, local variables in the main thread and the sub-thread are defined by first variable definition information and second variable definition information respectively, and can only be used in their respective corresponding threads.

[0042] Exemplarily, the program code compiling method provided in the embodiment of the present application compiles the main thread and the sub-thread respectively by obtaining the first variable information and the second variable information respectively, and subsequently facilitates variable transfer between the main thread and the sub-thread.

[0043] Step S104: converting the main program in the source file into a first bytecode file according to the first variable definition information, and converting the subroutine in the source file into a second bytecode file according to the second variable definition information.

[0044] Exemplarily, compilation is the process of converting source code written in a high-level programming language into a low-level language (usually machine code) that a computer can understand and execute. For example, after a Java program is compiled into bytecode, it is interpreted and executed by a Java virtual machine (JVM) at runtime; and after a C / C++ program is compiled into machine code, it can be directly executed by a CPU. Therefore, by converting the main thread into a first bytecode file and converting the child thread into a second bytecode file, the source file is converted into a file that can be run in a Java virtual machine.

[0045] In some implementations, converting the main program in the source file into a first bytecode file according to the first variable definition information, and converting the subroutine in the source file into a second bytecode file according to the second variable definition information includes:

[0046] Determine a first bytecode corresponding to a first variable in the main program according to the first variable definition information, and convert the first variable in the main program into the first bytecode to obtain the first bytecode file;

[0047] Determine a second bytecode corresponding to a second variable in the subprogram according to the second variable definition information, and convert the second variable in the subprogram into the second bytecode;

[0048] In the case where a third variable that does not exist in the second variable definition information appears in the subroutine, the third variable in the subroutine is converted into a preset symbol to obtain the second bytecode file.

[0049] Exemplarily, the first variable information and the second variable information are used to represent local variables in the main thread and the child thread. Specifically, for variables in a thread, Java provides a ThreadLocal class to support thread local variables, and the compiler generates a special bytecode instruction for each thread local variable to access and update the value of the thread local variable. Therefore, when compiling, the bytecodes corresponding to the first variable in the main thread and the second variable in the child thread can be determined according to the ThreadLocals corresponding to the main program and the child program, so as to obtain a bytecode file by replacing the first variable with the corresponding first bytecode and the second variable with the corresponding second bytecode.

[0050] Exemplarily, the program code compilation method provided by the embodiment of the present application allows calling local variables defined only in the main thread in the child thread. During the compilation process, if a second variable whose second variable information is not defined appears in the child thread, it is first replaced with a preset symbol so that the preset symbol can be subsequently processed according to the first variable information of the main thread, thereby realizing the transfer of local variables between the main thread and the child thread.

[0051] In some implementations, converting the main program in the source file into a first bytecode file according to the first variable definition information, and converting the subroutine in the source file into a second bytecode file according to the second variable definition information includes:

[0052] Performing a first analysis process on the source file, identifying a preset character sequence in the source file, and converting the preset character sequence into a target mark to obtain a first intermediate file;

[0053] Performing a second analysis process on the first intermediate file to determine an abstract syntax tree corresponding to the first intermediate file, thereby obtaining a second intermediate file;

[0054] Converting the second intermediate file into an intermediate representation to obtain a third intermediate file;

[0055] The third intermediate file is converted into bytecode according to the intermediate representation to obtain a first bytecode file corresponding to the main program and a second bytecode file corresponding to the subprogram.

[0056] In the related technology, in addition to processing variables, program compilation also needs to process other codes besides variables. Therefore, it is necessary to perform the following method analysis, syntax analysis, semantic analysis, etc. on the source file to obtain the Abstract Syntax Tree (AST) corresponding to the source file, and then convert the abstract syntax tree into a bytecode file.

[0057] Specifically, the compiler first performs lexical analysis on the source code, breaking it down into a series of tokens, such as keywords, identifiers, constants, operators, etc.; secondly, the compiler performs syntax analysis and builds an abstract syntax tree. During this process, the compiler checks whether the declaration and use of variables conform to the syntax rules of the Java language; then it performs semantic analysis to check the type, scope, and life cycle of the variables. This step determines the type, scope, and life cycle of each variable, as well as whether they can be accessed; after obtaining one or more intermediate representations (IRs) converted from the abstract syntax tree, the compiler allocates a symbol table entry to each variable to track the variable's information, such as type, scope, life cycle, etc.; finally, the compiler converts the IR into bytecode. During this process, the compiler generates corresponding bytecode instructions based on the scope and life cycle of the variable. For example, local variables are allocated space in the stack frame, while instance variables and static variables are allocated space in the field of the class. In the program code compilation method provided in the embodiment of the present application, if the compiler detects an undefined local variable in a child thread, it will not report an error, but will replace the undefined local variable with a preset symbol and wait for subsequent variable transfer.

[0058] Step S105: modify the second bytecode file according to the first variable definition information to obtain the third bytecode file.

[0059] Exemplarily, in the second bytecode file generated in step S104, the third variables in the subroutine that are not defined by the second variable information are replaced by preset symbols. At this time, the Java Agent can search the first variable information to see whether the third variables corresponding to these preset symbols are defined in the first variable information, and modify the preset symbols according to the first variable information, thereby realizing the transfer of local variables between the main program and the subroutine.

[0060] In some implementations, the modifying the second bytecode file according to the first variable definition information to obtain the third bytecode file includes:

[0061] Determine the variable corresponding to the preset symbol in the source file as a third variable;

[0062] Determine a third bytecode corresponding to the third variable according to the first variable definition information;

[0063] The preset symbol in the second bytecode file is replaced with the corresponding third bytecode to obtain the third bytecode file.

[0064] Exemplarily, the principle of Java Agent is to dynamically modify the bytecode at class loading or runtime through the mechanism provided by Java Instrumentation API. In the program code compilation method provided in the embodiment of the present application, JavaAgent is used to modify the third variable corresponding to the preset symbol according to the first variable definition information of the main program. Specifically, the third bytecode corresponding to the third variable is determined based on the first variable definition information, and the preset symbol is modified to the corresponding third bytecode, so as to realize the transfer of local variables between the main thread and the child thread, so that the second variable in the child thread is determined according to the second variable definition information, and the third variable in the child thread is determined according to the first variable definition information.

[0065] In some embodiments, the method further comprises:

[0066] When the third variable does not exist in the first variable definition information, abnormal prompt information corresponding to the third variable is output.

[0067] Exemplarily, if the third variable is not defined in the first variable definition information and the third variable cannot be passed from the main thread to the child thread, the third variable itself may have an exception, and an exception prompt message is output for the third variable to prompt the developer to modify the third variable.

[0068] Step S106: Determine a target file corresponding to the source file according to the first bytecode file and the third bytecode file.

[0069] Exemplarily, in the program code compilation method provided in the embodiment of the present application, the second bytecode file is equivalent to an intermediate file in the subroutine compilation process, and the final running target file is determined based on the first bytecode file corresponding to the main program and the third bytecode file corresponding to the subroutine.

[0070] In some implementations, after determining the target file corresponding to the source file according to the first bytecode file and the third bytecode file, the method further includes:

[0071] A virtual environment is created for the target file to run, and the target file is loaded into the virtual environment for running.

[0072] Exemplarily, the virtual environment may be, for example, a Java virtual machine (JVM), but is certainly not limited thereto and is not limited here.

[0073] Since the program code compilation method provided in the embodiment of the present application does not require modification of the code itself, it only needs to reference the target instruction parameters in the code compilation instruction, such as the parameters corresponding to the Java Agent, so that local variables can be passed between the main program and the subprogram. Specifically, when instructing the code to compile, input "-transmit-threadcontext.jar", which saves the time and tedious operations required for modifying the code and improves the operation efficiency.

[0074] The program code compiling method provided in the above embodiment obtains a code compiling instruction and identifies the instruction parameters in the code compiling instruction; obtains the source file corresponding to the code compiling instruction, and identifies the main thread and the sub-thread in the source file when the target instruction parameters are identified; obtains the first variable definition information corresponding to the main thread, and the second variable definition information corresponding to the sub-thread; converts the main program in the source file into a first bytecode file according to the first variable definition information, and converts the sub-program in the source file into a second bytecode file according to the second variable definition information; modifies the second bytecode file according to the first variable definition information to obtain the third bytecode file; and determines the target file corresponding to the source file according to the first bytecode file and the third bytecode file. The local variables inside the main program can be used in the sub-program without modifying the code, which improves the efficiency of program development.

[0075] See also Figure 3 , Figure 3 is a schematic diagram of a program code compiling device provided in an embodiment of the present application. The program code compiling device can be configured in a server or a terminal to execute the aforementioned program code compiling method.

[0076] like Figure 3 As shown, the program code compiling device includes: an instruction acquisition module 110, an instruction response module 120, a definition information acquisition module 130, a file conversion module 140, a file modification module 150, and a target file output module 160.

[0077] The instruction acquisition module 110 is used to acquire the code compilation instruction and identify the instruction parameters in the code compilation instruction;

[0078] The instruction response module 120 is used to obtain the source file corresponding to the code compilation instruction, and identify the main thread and the sub-thread in the source file when the target instruction parameter is identified;

[0079] A definition information acquisition module 130, used to acquire first variable definition information corresponding to the main thread and second variable definition information corresponding to the child thread;

[0080] A file conversion module 140, configured to convert a main program in the source file into a first bytecode file according to the first variable definition information, and to convert a subroutine in the source file into a second bytecode file according to the second variable definition information;

[0081] A file modification module 150, configured to modify the second bytecode file according to the first variable definition information to obtain the third bytecode file;

[0082] The target file output module 160 is used to determine the target file corresponding to the source file according to the first bytecode file and the third bytecode file.

[0083] In some embodiments, the file conversion module 140, in the process of converting the main program in the source file into the first bytecode file according to the first variable definition information, and converting the subroutine in the source file into the second bytecode file according to the second variable definition information, is used to implement:

[0084] Determine a first bytecode corresponding to a first variable in the main program according to the first variable definition information, and convert the first variable in the main program into the first bytecode to obtain the first bytecode file;

[0085] Determine a second bytecode corresponding to a second variable in the subprogram according to the second variable definition information, and convert the second variable in the subprogram into the second bytecode;

[0086] In the case where a third variable that does not exist in the second variable definition information appears in the subroutine, the third variable in the subroutine is converted into a preset symbol to obtain the second bytecode file.

[0087] In some embodiments, the file modification module 150, in the process of modifying the second bytecode file according to the first variable definition information to obtain the third bytecode file, is used to implement:

[0088] Determine the variable corresponding to the preset symbol in the source file as a third variable;

[0089] Determine a third bytecode corresponding to the third variable according to the first variable definition information;

[0090] The preset symbol in the second bytecode file is replaced with the corresponding third bytecode to obtain the third bytecode file.

[0091] In some embodiments, the program code compiling apparatus, in the process of implementing the program code compiling method, is further used to implement:

[0092] When the third variable does not exist in the first variable definition information, abnormal prompt information corresponding to the third variable is output.

[0093] In some embodiments, the file conversion module 140, in the process of converting the main program in the source file into the first bytecode file according to the first variable definition information, and converting the subroutine in the source file into the second bytecode file according to the second variable definition information, is used to implement:

[0094] Performing a first analysis process on the source file, identifying a preset character sequence in the source file, and converting the preset character sequence into a target mark to obtain a first intermediate file;

[0095] Performing a second analysis process on the first intermediate file to determine an abstract syntax tree corresponding to the first intermediate file, thereby obtaining a second intermediate file;

[0096] Converting the second intermediate file into an intermediate representation to obtain a third intermediate file;

[0097] The third intermediate file is converted into bytecode according to the intermediate representation to obtain a first bytecode file corresponding to the main program and a second bytecode file corresponding to the subprogram.

[0098] In some embodiments, after implementing the step of determining the target file corresponding to the source file according to the first bytecode file and the third bytecode file, the program code compiling device is used to implement:

[0099] A virtual environment is created for the target file to run, and the target file is loaded into the virtual environment for running.

[0100] In some embodiments, the instruction acquisition module 110, in the process of acquiring the source file corresponding to the code compilation instruction and identifying the main thread and the sub-thread in the source file when the target instruction parameter is identified, is used to implement:

[0101] When the code compilation instruction includes a preset Java probe, the main thread and the sub-thread in the source file are identified.

[0102] It should be noted that those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules and units can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

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

[0104] Exemplarily, the above method and apparatus may be implemented in the form of a computer program. The computer program may be implemented in Figure 4 Runs on the computer device shown.

[0105] See also Figure 4 , Figure 4 A schematic block diagram of the structure of a computer device provided in an embodiment of the present application. The computer device may be a server or a terminal.

[0106] like Figure 4 As shown, the computer device includes a processor, a memory, and a network interface connected via a system bus, wherein the memory may include a storage medium and an internal memory.

[0107] The storage medium can store an operating system and a computer program. The computer program includes program instructions, and when the program instructions are executed, the processor can execute any program code compilation method.

[0108] The processor is used to provide computing and control capabilities and support the operation of the entire computer equipment.

[0109] The internal memory provides an environment for the operation of the computer program in the storage medium. When the computer program is executed by the processor, the processor can execute any program code compilation method.

[0110] The network interface is used for network communication, such as sending assigned tasks, etc. Those skilled in the art will understand that Figure 4 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0111] It should be understood that the processor may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0112] In one embodiment, the processor is used to run a computer program stored in the memory to implement the following steps:

[0113] Obtaining a code compilation instruction and identifying instruction parameters in the code compilation instruction;

[0114] Obtaining a source file corresponding to the code compilation instruction, and identifying a main thread and a sub-thread in the source file when a target instruction parameter is identified;

[0115] Obtaining first variable definition information corresponding to the main thread and second variable definition information corresponding to the child thread;

[0116] Converting a main program in the source file into a first bytecode file according to the first variable definition information, and converting a subprogram in the source file into a second bytecode file according to the second variable definition information;

[0117] Modify the second bytecode file according to the first variable definition information to obtain the third bytecode file;

[0118] A target file corresponding to the source file is determined according to the first bytecode file and the third bytecode file.

[0119] In some embodiments, the processor, in the process of converting the main program in the source file into a first bytecode file according to the first variable definition information and converting the subroutine in the source file into a second bytecode file according to the second variable definition information, is configured to execute:

[0120] Determine a first bytecode corresponding to a first variable in the main program according to the first variable definition information, and convert the first variable in the main program into the first bytecode to obtain the first bytecode file;

[0121] Determine a second bytecode corresponding to a second variable in the subprogram according to the second variable definition information, and convert the second variable in the subprogram into the second bytecode;

[0122] In the case where a third variable that does not exist in the second variable definition information appears in the subroutine, the third variable in the subroutine is converted into a preset symbol to obtain the second bytecode file.

[0123] In some embodiments, the processor, in the process of modifying the second bytecode file according to the first variable definition information to obtain the third bytecode file, is used to execute:

[0124] Determine the variable corresponding to the preset symbol in the source file as a third variable;

[0125] Determine a third bytecode corresponding to the third variable according to the first variable definition information;

[0126] The preset symbol in the second bytecode file is replaced with the corresponding third bytecode to obtain the third bytecode file.

[0127] In some embodiments, the processor, during the execution of the method, is configured to perform:

[0128] When the third variable does not exist in the first variable definition information, abnormal prompt information corresponding to the third variable is output.

[0129] In some embodiments, the processor, in the process of converting the main program in the source file into a first bytecode file according to the first variable definition information and converting the subroutine in the source file into a second bytecode file according to the second variable definition information, is configured to execute:

[0130] Performing a first analysis process on the source file, identifying a preset character sequence in the source file, and converting the preset character sequence into a target mark to obtain a first intermediate file;

[0131] Performing a second analysis process on the first intermediate file to determine an abstract syntax tree corresponding to the first intermediate file, thereby obtaining a second intermediate file;

[0132] Converting the second intermediate file into an intermediate representation to obtain a third intermediate file;

[0133] The third intermediate file is converted into bytecode according to the intermediate representation to obtain a first bytecode file corresponding to the main program and a second bytecode file corresponding to the subprogram.

[0134] In some embodiments, after executing the step of determining the target file corresponding to the source file according to the first bytecode file and the third bytecode file, the processor is further configured to execute:

[0135] Create a virtual environment for the target file to run, and load the target file into the virtual environment to run

[0136] In some embodiments, the processor, in the process of obtaining the source file corresponding to the code compilation instruction and identifying the main thread and the sub-thread in the source file when the target instruction parameter is identified, is used to perform:

[0137] When the code compilation instruction includes a preset Java probe, the main thread and the sub-thread in the source file are identified.

[0138] It should be noted that those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of program code compilation described above can refer to the corresponding process in the aforementioned program code compilation control method embodiment, and will not be repeated here.

[0139] An embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored. The computer program includes program instructions. The method implemented when the program instructions are executed can refer to the various embodiments of the program code compilation method of the present application.

[0140] The computer-readable storage medium may be an internal storage unit of the computer device described in the foregoing embodiment, such as a hard disk or memory of the computer device. The computer-readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, a smart memory card (SmartMedia Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc., equipped on the computer device.

[0141] It should be understood that the terms used in this application specification are only for the purpose of describing specific embodiments and are not intended to limit the application. As used in this application specification and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.

[0142] It should also be understood that the term "and / or" used in the specification of this application and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, including these combinations. It should be noted that, in this article, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "including a..." does not exclude the presence of other identical elements in the process, method, article or system including the element.

[0143] The serial numbers of the embodiments of the present application are for description only and do not represent the advantages and disadvantages of the embodiments. The above description is only a specific implementation mode of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.

Claims

1. A method for compiling a program code, characterized in that: The method comprises: Obtaining a code compilation instruction and identifying instruction parameters in the code compilation instruction; Obtaining a source file corresponding to the code compilation instruction, and identifying a main thread and a sub-thread in the source file when a target instruction parameter is identified; Obtaining first variable definition information corresponding to the main thread and second variable definition information corresponding to the child thread; Converting a main program in the source file into a first bytecode file according to the first variable definition information, and converting a subprogram in the source file into a second bytecode file according to the second variable definition information; Modify the second bytecode file according to the first variable definition information to obtain the third bytecode file; A target file corresponding to the source file is determined according to the first bytecode file and the third bytecode file.

2. The program code compiling method according to claim 1, characterized in that: The method of converting the main program in the source file into a first bytecode file according to the first variable definition information, and converting the subprogram in the source file into a second bytecode file according to the second variable definition information includes: Determine a first bytecode corresponding to a first variable in the main program according to the first variable definition information, and convert the first variable in the main program into the first bytecode to obtain the first bytecode file; Determine a second bytecode corresponding to a second variable in the subprogram according to the second variable definition information, and convert the second variable in the subprogram into the second bytecode; In the case where a third variable that does not exist in the second variable definition information appears in the subroutine, the third variable in the subroutine is converted into a preset symbol to obtain the second bytecode file.

3. The program code compiling method according to claim 2, characterized in that: The step of modifying the second bytecode file according to the first variable definition information to obtain the third bytecode file includes: Determine the variable corresponding to the preset symbol in the source file as a third variable; Determine a third bytecode corresponding to the third variable according to the first variable definition information; The preset symbol in the second bytecode file is replaced with the corresponding third bytecode to obtain the third bytecode file.

4. The program code compiling method according to claim 3, characterized in that: The method further comprises: When the third variable does not exist in the first variable definition information, abnormal prompt information corresponding to the third variable is output.

5. The program code compiling method according to claim 1, characterized in that: The method of converting the main program in the source file into a first bytecode file according to the first variable definition information, and converting the subprogram in the source file into a second bytecode file according to the second variable definition information includes: Performing a first analysis process on the source file, identifying a preset character sequence in the source file, and converting the preset character sequence into a target mark to obtain a first intermediate file; Performing a second analysis process on the first intermediate file to determine an abstract syntax tree corresponding to the first intermediate file, thereby obtaining a second intermediate file; Converting the second intermediate file into an intermediate representation to obtain a third intermediate file; The third intermediate file is converted into bytecode according to the intermediate representation to obtain a first bytecode file corresponding to the main program and a second bytecode file corresponding to the subprogram.

6. The program code compiling method according to claim 1, characterized in that: After determining the target file corresponding to the source file according to the first bytecode file and the third bytecode file, the method further includes: A virtual environment is created for the target file to run, and the target file is loaded into the virtual environment for running.

7. The program code compiling method according to claim 1, characterized in that: The obtaining of the source file corresponding to the code compilation instruction and, when the target instruction parameter is identified, identifying the main thread and the sub-thread in the source file includes: When the code compilation instruction includes a preset Java probe, the main thread and the sub-thread in the source file are identified.

8. A program code compiling device, characterized in that: The program code compiling device comprises: An instruction acquisition module, used to acquire a code compilation instruction and identify instruction parameters in the code compilation instruction; An instruction response module, used for obtaining a source file corresponding to the code compilation instruction, and identifying a main thread and a sub-thread in the source file when a target instruction parameter is identified; A definition information acquisition module, used to acquire first variable definition information corresponding to the main thread and second variable definition information corresponding to the child thread; A file conversion module, configured to convert a main program in the source file into a first bytecode file according to the first variable definition information, and to convert a subroutine in the source file into a second bytecode file according to the second variable definition information; A file modification module, used for modifying the second bytecode file according to the first variable definition information to obtain the third bytecode file; The target file output module is used to determine the target file corresponding to the source file according to the first bytecode file and the third bytecode file.

9. A computer device, characterized in that: The computer device comprises a processor, a memory, and a computer program stored in the memory and executable by the processor, wherein when the computer program is executed by the processor, the steps of the program code compiling method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the steps of the program code compiling method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Bytecode instrumentation method, device and equipment, storage medium and product

    CN117421040A

  • Dynamic compiling and loading at runtime

    US20100218174A1

  • Instrumenting An Application With Flexible Tracers To Provide Correlation Data And Metrics

    US20100287541A1