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

By identifying and converting variable definition information of the main thread and child threads, and using a Java Agent to modify bytecode files, the problem of needing to modify code for context passing between threads is solved, thus improving program development efficiency.

CN119690449BActive Publication Date: 2025-11-18CHINA PING AN LIFE INSURANCE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

When passing context between threads, existing techniques require code modifications, leading to cumbersome and inefficient practices.

Method used

By obtaining instruction parameters from the code compilation instructions, the main thread and child thread are identified, their respective variable definition information is obtained, and the main program and child program are converted into bytecode files. The Java Agent is then used to pass variables without modifying the code.

Benefits of technology

It enables efficient passing of local variables between threads without modifying the code, thus improving program development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119690449B_ABST
    Figure CN119690449B_ABST
Patent Text Reader

Abstract

The application relates to the field of computer programs, and provides a program code compiling method and device, equipment and a computer storage medium, the method comprising the following steps: acquiring a code compiling instruction, and identifying instruction parameters in the code compiling instruction; acquiring a source file corresponding to the code compiling instruction, and identifying a main thread and a sub-thread in the source file in the case of identifying target instruction parameters; acquiring 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 sub-program 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, in particular to a program code compiling method and device, computer equipment and storage medium. BACKGROUND

[0002] A thread is a basic unit of program execution, each thread has its own running environment, including its own program counter, stack, register, etc., and the context information of each thread is saved in the thread variable, and the thread variables of different threads are isolated. However, in actual system design, it is often necessary to create another child thread in a thread to complete asynchronous operations such as asynchronous requests, asynchronous calculations, asynchronous logs, etc. If the thread variable is ignored and the context is passed using the thread variable, the context loss problem will occur. In order to avoid this problem, the context transfer of the thread variable usually needs to modify the code, which is relatively cumbersome, and how to efficiently implement the context transfer of the thread variable has become a problem to be solved. SUMMARY

[0003] The main purpose of the present application is to provide a program code compiling method, device, equipment and computer storage medium, which aims to improve the efficiency of program development.

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

[0005] Obtain a code compiling instruction and identify the instruction parameters in the code compiling instruction;

[0006] Obtain the source file corresponding to the code compiling instruction, and identify the main thread and the child thread in the source file in the case of identifying the target instruction parameter;

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

[0008] According to the first variable definition information, the main program in the source file is converted into a first bytecode file, and according to the second variable definition information, the child program in the source file is converted into a second bytecode file;

[0009] According to the first variable definition information, the second bytecode file is modified to obtain the third bytecode file;

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

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

[0012] An instruction obtaining module is configured to obtain a code compilation instruction and identify an instruction parameter in the code compilation instruction.

[0013] An instruction response module is configured to obtain a source file corresponding to the code compilation instruction and identify a main thread and a sub-thread in the source file in a case where the target instruction parameter is identified.

[0014] A definition information obtaining module is configured to obtain first variable definition information corresponding to the main thread and second variable definition information corresponding to the sub-thread.

[0015] A file conversion module is configured to convert a main program in the source file into a first bytecode file according to the first variable definition information and convert a sub-program in the source file into a second bytecode file according to the second variable definition information.

[0016] A file modification module is configured to modify the second bytecode file according to the first variable definition information to obtain a third bytecode file.

[0017] A target file output module is configured to determine a 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 further provides a computer device, which comprises a processor, a memory, and a computer program stored in the memory and executable by the processor, wherein the computer program is executed by the processor to implement the program code compilation method as described above.

[0019] In a fourth aspect, the present application further provides a computer readable storage medium, which stores a computer program, wherein the computer program is executed by a processor to implement the program code compilation method as described above.

[0020] The application provides a program code compiling method, device and equipment and a computer storage medium. The application obtains a code compiling instruction, identifies instruction parameters in the code compiling instruction, obtains a source file corresponding to the code compiling instruction, identifies a main thread and a sub-thread in the source file in a case where a target instruction parameter is identified, obtains first variable definition information corresponding to the main thread and second variable definition information corresponding to the sub-thread, converts a main program in the source file into a first bytecode file according to the first variable definition information, converts a 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 a third bytecode file, and determines a target file corresponding to the source file according to the first bytecode file and the third bytecode file. Since the variable transmission between the main program and the sub-program is indicated by the target parameter instruction, the local variable inside the main program can be used in the sub-program without modifying the code, and the efficiency of program development is improved. BRIEF DESCRIPTION OF DRAWINGS

[0021] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.

[0022] Figure 1 A flowchart of a program code compiling method provided by an embodiment of the present application is shown.

[0023] Figure 2 A use scenario diagram of a program code compiling method provided by an embodiment of the present application is shown.

[0024] Figure 3 A schematic block diagram of a program code compiling device provided by an embodiment of the present application is shown.

[0025] Figure 4 A structural schematic block diagram of a computer device related to an embodiment of the present application is shown. DETAILED DESCRIPTION

[0026] The technical solutions in the embodiments of the present application will be described clearly and completely in combination with the drawings in the embodiments of the present application. Obviously, the described embodiments are some embodiments of the present application, not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the protection scope of the present application.

[0027] The flowchart shown in the drawings is only an example and does not necessarily include all contents and operations / steps, nor does it have to be executed in the order described. For example, some operations / steps can be further divided, combined or partially merged, so the actual execution order can be changed according to actual conditions.

[0028] The embodiment of the present application provides a program code compiling method, device, computer equipment and computer readable storage medium.

[0029] Some embodiments of the present application will be described in detail below with reference to the accompanying drawings. The following embodiments and features in the embodiments can be combined with each other without conflict.

[0030] Please refer to Figure 1 , Figure 1 A flowchart of a program code compiling method provided by an embodiment of the present application is shown. The program code compiling method can be used in a terminal or a server to realize variable transfer between a main program and a subprogram. The terminal can be an electronic device such as a mobile phone, a tablet computer, a notebook computer, a desktop computer, a personal digital assistant and a wearable device. The server can be a stand-alone server, a server cluster, a cloud server providing cloud services, cloud database, cloud computing, cloud function, cloud storage, network service, cloud communication, middleware service, domain name service, security service, content distribution network (CDN) and basic cloud computing services such as big data and artificial intelligence platform.

[0031] Please refer to Figure 2 , Figure 2 A use scenario provided by an embodiment of the present application is shown. As shown in Figure 2 , the first bytecode file and the second bytecode file are generated according to the source file. If a pointcut is detected in the second bytecode file, the second bytecode file is converted into a third bytecode file, and the target file is generated based on the first bytecode file and the third bytecode file. If no pointcut is detected in the second bytecode file, the target file is directly generated based on the first bytecode file and the second bytecode file.

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

[0033] In step S101, a code compiling instruction is acquired, and an instruction parameter in the code compiling instruction is identified.

[0034] For example, code compilation directives are used to instruct the compilation of program code. In these directives, users can specify one or more source files containing program code to be compiled. Code compilation directives can also include other optional directive parameters. For instance, in Java, the directive parameter "-proc:{none,only}" can be used to control whether comment processing and compilation are performed, and the directive parameter "-processor_class1_[,_class2_...]" can be used to specify the name of the comment processor to be run. The types of directive parameters are not limited to these, and directive parameters can also be omitted from the code compilation directives; this is not a limitation here.

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

[0036] For example, the program code compilation method provided in this application embodiment is executed when the code compilation instructions contain target instruction parameters.

[0037] In some implementations, obtaining the source file corresponding to the code compilation instructions, and identifying the main thread and child threads in the source file when the target instruction parameters are identified, includes:

[0038] If the code compilation instructions include a preset Java probe, the main thread and child threads in the source file are identified.

[0039] For example, the target instruction parameter can be a preset Java probe, i.e. a preset Java Agent instruction. By adding the preset Java Agent instruction to the code compilation instruction, the program code is avoided from being modified in order to pass variables between the main thread and the child thread, thus reducing the complexity of variable passing.

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

[0041] In related technologies, local variables in the main thread and child threads are defined using first variable definition information and second variable definition information, respectively, and can only be used within their respective threads.

[0042] For example, the program code compilation method provided in this application compiles the main thread and the child thread by obtaining the first variable information and the second variable information respectively, and facilitates the subsequent transfer of variables between the main thread and the child thread.

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

[0044] For example, 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 instance, a Java program is compiled into bytecode, which is then interpreted and executed by the Java Virtual Machine (JVM) at runtime; while a C / C++ program, after being compiled into machine code, can be directly executed by the CPU. Therefore, by converting the main thread into the first bytecode file and the child threads into the second bytecode file, the source file is transformed into a file that can run in the Java Virtual Machine.

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

[0046] Based on the first variable definition information, determine the first bytecode corresponding to the first variable in the main program, and convert the first variable in the main program into the first bytecode to obtain the first bytecode file;

[0047] The second bytecode corresponding to the second variable in the subroutine is determined based on the second variable definition information, and the second variable in the subroutine is converted into the second bytecode;

[0048] If a third variable that is not present 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] For example, the first variable information and the second variable information are used to represent local variables within the main thread and the child thread. Specifically, for thread-local variables, Java provides the ThreadLocal class to support them. The compiler generates a special bytecode instruction for each thread-local variable to access and update its value. Therefore, during compilation, the bytecode corresponding to the first variable in the main thread and the second variable in the child thread can be determined based on the ThreadLocal of the main program and the child program, respectively. The bytecode file is then obtained by replacing the first variable with its corresponding first bytecode and the second variable with its corresponding second bytecode.

[0050] For example, the program code compilation method provided in the embodiments of this application allows local variables defined only in the main thread to be called in a child thread. During the compilation process, if a second variable with undefined second variable information appears in the child thread, it is first replaced with a preset symbol so that the preset symbol can be 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 based on the first variable definition information, and converting the subroutine in the source file into a second bytecode file based on the second variable definition information, includes:

[0052] The source file is subjected to a first analysis process to identify a preset character sequence in the source file and convert the preset character sequence into a target tag to obtain a first intermediate file;

[0053] The first intermediate file is subjected to a second analysis process to determine the abstract syntax tree corresponding to the first intermediate file, thereby obtaining the second intermediate file.

[0054] The second intermediate file is converted into an intermediate representation to obtain the third intermediate file;

[0055] The third intermediate file is converted into bytecode based on the intermediate representation to obtain the first bytecode file corresponding to the main program and the second bytecode file corresponding to the subroutine.

[0056] In related technologies, program compilation not only processes variables but also other code. Therefore, the source file needs to undergo the following analysis, such as syntax analysis and semantic analysis, to obtain the Abstract Syntax Tree (AST) corresponding to the source file, and then the AST is converted 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, and operators. Next, it performs syntax analysis, constructing an abstract syntax tree (IR). During this process, the compiler checks whether the declarations and uses of variables conform to the syntax rules of the Java language. Then, it performs semantic analysis, checking the type, scope, and lifetime of variables. This step determines the type, scope, and lifetime of each variable, as well as whether they can be accessed. After obtaining one or more intermediate representations (IRs) from the IR, the compiler assigns a symbol table entry to each variable to track its information, such as type, scope, and lifetime. Finally, the compiler converts the IR into bytecode. In this process, the compiler generates corresponding bytecode instructions based on the scope and lifetime of the variables. For example, local variables are allocated space in a stack frame, while instance variables and static variables are allocated space in class fields. In the program code compilation method provided in the embodiments of this 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 passing.

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

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

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

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

[0062] The third bytecode corresponding to the third variable is determined based on the first variable definition information;

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

[0064] For example, the Java Agent works by dynamically modifying bytecode during class loading or runtime through mechanisms provided by the Java Instrumentation API. In the program code compilation method provided in this application embodiment, the JavaAgent is used to modify the third variable corresponding to a preset symbol based on the first variable definition information of the main program. Specifically, it determines the third bytecode corresponding to the third variable based on the first variable definition information and modifies the preset symbol to the corresponding third bytecode, thereby enabling the transfer of local variables between the main thread and the child thread. This ensures that the second variable in the child thread is determined according to the second variable definition information, while the third variable in the child thread is determined according to the first variable definition information.

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

[0066] If the third variable is not present in the first variable definition information, output the exception message corresponding to the third variable.

[0067] For example, if the third variable is not defined in the definition information of the first variable, and the third variable cannot be passed from the main thread to the child thread, the third variable itself may be abnormal. An abnormal message will be output for the third variable, prompting the developer to modify the third variable.

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

[0069] For example, in the program code compilation method provided in the embodiments of this application, the second bytecode file is equivalent to an intermediate file in the subroutine compilation process, and the final 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 embodiments, after determining the target file corresponding to the source file based on the first bytecode file and the third bytecode file, the method further includes:

[0071] Create a virtual environment for running the target file, and load the target file into the virtual environment to run it.

[0072] For example, the virtual environment may be a Java Virtual Machine (JVM), but it is not limited to this and is not restricted here.

[0073] Since the program code compilation method provided in this application embodiment does not require modification of the code itself, but only requires referencing the target instruction parameters in the code compilation instructions, such as the parameters corresponding to the Java Agent, local variables can be passed between the main program and the subroutine. Specifically, simply inputting "-transmit-threadcontext.jar" during the code compilation process saves the time and tedious operations required to modify the code, thus improving operational efficiency.

[0074] The program code compilation method provided in the above embodiments obtains code compilation instructions and identifies instruction parameters in the code compilation instructions; obtains the source file corresponding to the code compilation instructions, and, upon identifying target instruction parameters, identifies the main thread and sub-threads in the source file; obtains first variable definition information corresponding to the main thread and second variable definition information corresponding to the sub-threads; converts the main program in the source file into a first bytecode file according to the first variable definition information, and converts the subroutines in the source file into second bytecode files 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 based on the first bytecode file and the third bytecode file. This method enables the use of local variables within the main program in subroutines without modifying the code, improving program development efficiency.

[0075] Please see Figure 3 , Figure 3 This is a schematic diagram of a program code compilation device provided in an embodiment of this application. The program code compilation device can be configured in a server or terminal to execute the aforementioned program code compilation method.

[0076] like Figure 3 As shown, the program code compilation 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 an object file output module 160.

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

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

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

[0080] The file conversion module 140 is used to convert the main program in the source file into a first bytecode file according to the first variable definition information, and to convert the subroutine in the source file into a second bytecode file according to the second variable definition information.

[0081] The file modification module 150 is used 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 based on 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 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 used to implement:

[0084] Based on the first variable definition information, determine the first bytecode corresponding to the first variable in the main program, and convert the first variable in the main program into the first bytecode to obtain the first bytecode file;

[0085] The second bytecode corresponding to the second variable in the subroutine is determined based on the second variable definition information, and the second variable in the subroutine is converted into the second bytecode;

[0086] If a third variable that is not present 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] The variable corresponding to the preset symbol in the source file is determined as a third variable;

[0089] The third bytecode corresponding to the third variable is determined based on the first variable definition information;

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

[0091] In some embodiments, the program code compilation apparatus, in implementing the program code compilation method, is further configured to implement:

[0092] If the third variable is not present in the first variable definition information, output the exception message corresponding to the third variable.

[0093] In some embodiments, the file conversion module 140, 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 used to implement:

[0094] The source file is subjected to a first analysis process to identify a preset character sequence in the source file and convert the preset character sequence into a target tag to obtain a first intermediate file;

[0095] The first intermediate file is subjected to a second analysis process to determine the abstract syntax tree corresponding to the first intermediate file, thereby obtaining the second intermediate file.

[0096] The second intermediate file is converted into an intermediate representation to obtain the third intermediate file;

[0097] The third intermediate file is converted into bytecode based on the intermediate representation to obtain the first bytecode file corresponding to the main program and the second bytecode file corresponding to the subroutine.

[0098] In some embodiments, after the program code compilation apparatus implements the step of determining the target file corresponding to the source file based on the first bytecode file and the third bytecode file, it is configured to:

[0099] Create a virtual environment for running the target file, and load the target file into the virtual environment to run it.

[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 sub-thread in the source file when the target instruction parameter is identified, is used to implement:

[0101] If the code compilation instructions include a preset Java probe, the main thread and child threads in the source file are identified.

[0102] It should be noted that those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the above-described apparatus and its modules and units can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0103] The methods and apparatus of this application can be used in a wide variety of general-purpose or special-purpose computing system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics devices, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This 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. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.

[0104] For example, the above-described method and apparatus can be implemented as a computer program, which can be used in, for example... Figure 4 It runs on the computer device shown.

[0105] Please see Figure 4 , Figure 4 This is a schematic block diagram illustrating the structure of a computer device provided in an embodiment of this 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 internal memory.

[0107] The storage medium can store the operating system and computer programs. These computer programs include program instructions that, when executed, cause the processor to perform any program code compilation method.

[0108] The processor provides computing and control capabilities, supporting the operation of the entire computer device.

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

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

[0111] It should be understood that the processor can be a Central Processing Unit (CPU), but it can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among these, a general-purpose processor can be a microprocessor or any conventional processor.

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

[0113] Obtain code compilation instructions and identify the instruction parameters in the code compilation instructions;

[0114] Obtain the source file corresponding to the code compilation instructions, and identify the main thread and sub-thread in the source file when the target instruction parameters are identified;

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

[0116] The main program in the source file is converted into a first bytecode file according to the first variable definition information, and the subroutine in the source file is converted into a second bytecode file according to the second variable definition information.

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

[0118] The target file corresponding to the source file is determined based on the first bytecode file and the third bytecode file.

[0119] In some embodiments, during 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, the processor is configured to perform:

[0120] Based on the first variable definition information, determine the first bytecode corresponding to the first variable in the main program, and convert the first variable in the main program into the first bytecode to obtain the first bytecode file;

[0121] The second bytecode corresponding to the second variable in the subroutine is determined based on the second variable definition information, and the second variable in the subroutine is converted into the second bytecode;

[0122] If a third variable that is not present 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, during the process of modifying the second bytecode file according to the first variable definition information to obtain the third bytecode file, the processor is configured to perform:

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

[0125] The third bytecode corresponding to the third variable is determined based on the first variable definition information;

[0126] The preset symbols in the second bytecode file are 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] If the third variable is not present in the first variable definition information, output the exception message corresponding to the third variable.

[0129] In some embodiments, during 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, the processor is configured to perform:

[0130] The source file is subjected to a first analysis process to identify a preset character sequence in the source file and convert the preset character sequence into a target marker to obtain a first intermediate file;

[0131] The first intermediate file is subjected to a second analysis process to determine the abstract syntax tree corresponding to the first intermediate file, thereby obtaining the second intermediate file.

[0132] The second intermediate file is converted into an intermediate representation to obtain the third intermediate file;

[0133] The third intermediate file is converted into bytecode based on the intermediate representation to obtain the first bytecode file corresponding to the main program and the second bytecode file corresponding to the subroutine.

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

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

[0136] In some embodiments, during the process of obtaining the source file corresponding to the code compilation instructions and, upon recognizing the target instruction parameters, identifying the main thread and sub-thread in the source file, the processor performs the following:

[0137] If the code compilation instructions include a preset Java probe, the main thread and child threads in the source file are identified.

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

[0139] This application also provides a computer-readable storage medium storing a computer program, the computer program including program instructions, and the method implemented when the program instructions are executed can be referred to various embodiments of the program code compilation method of this application.

[0140] The computer-readable storage medium may be an internal storage unit of the computer device described in the foregoing embodiments, such as the 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, SmartMedia Card (SMC), Secure Digital (SD) card, or Flash Card equipped on the computer device.

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

[0142] It should also be understood that the term "and / or" as used in this specification and the appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes such combinations. It should be noted that, herein, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or system. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.

[0143] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments. The above descriptions are merely specific implementations of this application, but the scope of protection of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A method for compiling program code, characterized in that, The method includes: Obtain code compilation instructions and identify the instruction parameters in the code compilation instructions; Obtain the source file corresponding to the code compilation instructions, and identify the main thread and sub-thread in the source file when the target instruction parameters are identified; Obtain the first variable definition information corresponding to the main thread, and the second variable definition information corresponding to the child thread; The source file is subjected to a first analysis process to identify a preset character sequence in the source file and convert the preset character sequence into a target marker to obtain a first intermediate file; The first intermediate file is subjected to a second analysis process to determine the abstract syntax tree corresponding to the first intermediate file, thereby obtaining the second intermediate file. The second intermediate file is converted into an intermediate representation to obtain the third intermediate file; The third intermediate file is converted into bytecode according to the intermediate representation to obtain the first bytecode file corresponding to the main program in the source file and the second bytecode file corresponding to the subprogram in the source file. If a third variable that is not present 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; The variable corresponding to the preset symbol in the source file is determined as a third variable; The third bytecode corresponding to the third variable is determined based on the first variable definition information; Replace the preset symbols in the second bytecode file with the corresponding third bytecode to obtain the third bytecode file; The target file corresponding to the source file is determined based on the first bytecode file and the third bytecode file.

2. The program code compilation method according to claim 1, characterized in that, The step of converting the third intermediate file into bytecode based on the intermediate representation to obtain the first bytecode file corresponding to the main program in the source file and the second bytecode file corresponding to the subroutine in the source file includes: Based on the first variable definition information, determine the first bytecode corresponding to the first variable in the main program, and convert the first variable in the main program into the first bytecode to obtain the first bytecode file; The second bytecode corresponding to the second variable in the subroutine is determined based on the second variable definition information, and the second variable in the subroutine is converted into the second bytecode.

3. The program code compilation method according to claim 1, characterized in that, The method further includes: If the third variable is not present in the first variable definition information, output the exception message corresponding to the third variable.

4. The program code compilation method according to claim 1, characterized in that, After determining the target file corresponding to the source file based on the first bytecode file and the third bytecode file, the method further includes: Create a virtual environment for running the target file, and load the target file into the virtual environment to run it.

5. The program code compilation method according to claim 1, characterized in that, The step of obtaining the source file corresponding to the code compilation instructions, and identifying the main thread and child threads in the source file when the target instruction parameters are identified, includes: If the code compilation instructions include a preset Java probe, the main thread and child threads in the source file are identified.

6. A program code compilation apparatus, characterized in that, The program code compilation device includes: The instruction acquisition module is used to acquire code compilation instructions and identify the instruction parameters in the code compilation instructions; The instruction response module is used to obtain the source file corresponding to the code compilation instruction, and, upon recognizing the target instruction parameter, to identify the main thread and sub-thread in the source file; The definition information acquisition module is used to acquire the first variable definition information corresponding to the main thread and the second variable definition information corresponding to the child thread; The file conversion module is used to perform a first analysis on the source file, identify a preset character sequence in the source file, and convert the preset character sequence into a target token to obtain a first intermediate file; perform a second analysis on the first intermediate file to determine the abstract syntax tree corresponding to the first intermediate file to obtain a second intermediate file; convert the second intermediate file into an intermediate representation to obtain a third intermediate file; convert the third intermediate file into bytecode according to the intermediate representation to obtain a first bytecode file corresponding to the main program in the source file and a second bytecode file corresponding to the subroutine in the source file; if 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; The file modification module is used to modify 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 variable corresponding to the preset symbol in the source file as a third variable; determine the third bytecode corresponding to the third variable according to the first variable definition information; and replace the preset symbol in the second bytecode file with the corresponding third bytecode to obtain the third bytecode file.

7. A computer device, characterized in that, The computer device includes 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, it implements the steps of the program code compilation method as described in any one of claims 1 to 5.

8. 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, it implements the steps of the program code compilation method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

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

    CN117421040A

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

    US20100287541A1