Code compiling method and device, equipment and medium

By generating and replacing the global variable bytecode segment of the anonymous inner class, the problem of large bytecode file package size is solved, and efficient code compilation and type parameter information acquisition are achieved.

CN120631361APending Publication Date: 2025-09-12BEIJING ZITIAO NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410282217.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-03-12
Publication Date
2025-09-12

AI Technical Summary

Technical Problem

When writing software programs, the use of anonymous inner classes causes the size of the bytecode file package after the source code is compiled to increase significantly.

Method used

The target bytecode file is generated by generating a global variable bytecode segment of type information in an anonymous inner class, determining an initial bytecode segment using a marker code pair, obtaining a target bytecode segment from the global variable bytecode segment, and replacing the initial bytecode segment.

Benefits of technology

The number of anonymous inner classes is reduced, which prevents excessive growth of the bytecode file package size. At the same time, the acquisition of type parameter information is ensured, thus achieving efficient code compilation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120631361A_ABST
    Figure CN120631361A_ABST
Patent Text Reader

Abstract

The invention provides a code compiling method and device, equipment and a medium, and the method comprises the steps: generating a global variable byte code segment of at least one type of information in an anonymous internal class according to the annotation information of an inline method in a source code file, and setting a mark code pair corresponding to the type information in the code segment of the anonymous internal class; from the byte code segments compiled by the inline method, determining an initial byte code segment of each type information in the anonymous internal class according to the marking code pair, each initial byte code segment comprising the type information; obtaining a target global variable byte code segment from all global variable byte code segments according to each piece of type information; and according to each initial byte code segment and each target global variable byte code segment, generating a target byte code file. According to the method, the number of anonymous internal classes in the inline method can be reduced, so that the volume of a byte code file package after source code compiling is not greatly increased.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of software development technology, and in particular to a code compilation method, apparatus, device, and medium. Background Art

[0002] Usually, when writing the source code of a software program, if you need to implement an interface, but a method in this interface has the same name and parameters as a method in a class, you can implement this interface by using an anonymous inner class to simplify the code.

[0003] However, when compiling source code, each time an inline method containing an anonymous inner class is called, a new anonymous inner class is generated. Furthermore, because anonymous inner classes contain more information, such as class definitions and method definitions, after being compiled into bytecode, they require a larger file size. Therefore, if there are many anonymous inner classes in the source code, the size of the bytecode file after the source code is compiled will increase significantly. Summary of the Invention

[0004] The embodiments of the present application provide a code compilation method, apparatus, device, and medium, which can solve the problem of a significant increase in the size of bytecode file packages after source code compilation.

[0005] In a first aspect, an embodiment of the present application provides a code compilation method, comprising:

[0006] generating, based on annotation information of an inline method in a source code file, a global variable bytecode segment of at least one type information in an anonymous inner class, wherein the anonymous inner class is located in the inline method, and a tag code pair corresponding to the type information is provided in the code segment of the anonymous inner class;

[0007] Determine, from the bytecode segments compiled from the inline method, an initial bytecode segment for each type information in the anonymous inner class according to the tag code pair, each initial bytecode segment including type information;

[0008] According to each of the type information, obtaining a target global variable bytecode segment from all global variable bytecode segments;

[0009] A target bytecode file is generated according to each of the initial bytecode segments and each of the target global variable bytecode segments.

[0010] In a second aspect, an embodiment of the present application provides a code compilation device, comprising:

[0011] a first generating module, configured to generate, based on annotation information of an inline method in a source code file, a global variable bytecode segment of at least one type information in an anonymous inner class, wherein the anonymous inner class is located in the inline method, and a tag code pair corresponding to the type information is provided in the code segment of the anonymous inner class;

[0012] a determination module, configured to determine, from the bytecode segments compiled from the inline method, an initial bytecode segment of each type information in the anonymous inner class according to the tag code pair, wherein each initial bytecode segment includes type information;

[0013] an acquisition module, configured to acquire a target global variable bytecode segment from all global variable bytecode segments according to each of the type information;

[0014] The second generating module is used to generate a target bytecode file according to each of the initial bytecode segments and each of the target global variable bytecode segments.

[0015] In a third aspect, an embodiment of the present application provides an electronic device, including:

[0016] A processor and a memory, the memory being used to store a computer program, and the processor being used to call and run the computer program stored in the memory to execute the code compilation method as described in the embodiment of the first aspect.

[0017] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium for storing a computer program, wherein the computer program enables a computer to execute the code compilation method as described in the embodiment of the first aspect.

[0018] In a fifth aspect, an embodiment of the present application provides a computer program product comprising program instructions. When the program instructions are run on an electronic device, the electronic device executes the code compilation method as described in the embodiment of the first aspect.

[0019] The technical solution disclosed in the embodiment of the present application generates a global variable bytecode segment of at least one type information in the anonymous inner class in the inline method according to the annotation information of the inline method in the source code file, and then determines the initial bytecode segment of each type information in the anonymous inner class from the bytecode segment compiled by the inline method according to the tag code pair corresponding to each type information in the anonymous inner class code segment, and then obtains the target global variable bytecode segment from all global variable bytecode segments according to the type information in each initial bytecode segment, and then generates a target bytecode file according to each initial bytecode segment and each target global variable bytecode segment. The embodiment of the present application replaces the initial bytecode segment of each type information in the anonymous inner class by using the global variable bytecode segment of the type information in the anonymous inner class, so that the anonymous inner class in the inline method is deleted due to no reference, thereby reducing the number of anonymous inner classes in the inline method, so that the volume of the bytecode file package after the source code is compiled will not increase significantly, and at the same time, it can ensure that the specific type information of the type parameters in the inline method can be obtained when the bytecode file is run. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0021] Figure 1 A flowchart of a code compilation method provided in an embodiment of the present application;

[0022] Figure 2 A flowchart of obtaining a target global variable bytecode segment provided in an embodiment of the present application;

[0023] Figure 3 A schematic block diagram of a code compilation device provided in an embodiment of the present application;

[0024] Figure 4 A schematic block diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

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

[0026] It should be noted that the terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or server that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products, or devices.

[0027] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or solution described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or solutions. Specifically, the use of words such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner.

[0028] In the description of the embodiments of the present application, unless otherwise specified, "a plurality of" refers to two or more than two, that is, at least two. "At least one" refers to one or more than one.

[0029] As previously mentioned, when writing software source code, if an interface needs to be implemented, and a method in that interface has the same name and parameters as a method in a class, this interface can be implemented using anonymous inner classes. However, when compiling the source code, a new anonymous inner class is generated each time an inline method containing an anonymous inner class is called. Furthermore, because anonymous inner classes contain more information after being compiled into bytecode, they occupy a larger file size. Therefore, a large number of anonymous inner classes in the source code can significantly increase the size of the bytecode file after the source code is compiled.

[0030] In response to this technical problem, the inventive concept of the present application is as follows: by generating a global variable bytecode segment of at least one type information in an anonymous inner class based on the annotation information of the inline method in the source code file, then determining the initial bytecode segment of each type information in the anonymous inner class based on each tag code pair in the anonymous inner class code segment from the bytecode segment compiled from the inline method, then obtaining the type information in each initial bytecode segment to obtain the target global variable bytecode segment from all the global variable bytecode segments of the type information based on each type information, and then generating a target bytecode file corresponding to the source code file based on each initial bytecode segment and the target global variable bytecode segment. Thus, by using the global variable bytecode segment of the type information in the anonymous inner class to replace the initial bytecode segment of each type information in the anonymous inner class, the anonymous inner class in the inline method is deleted due to being unreferenced, thereby reducing the number of anonymous inner classes in the inline method, so that the size of the bytecode file package after the source code is compiled will not increase significantly, and at the same time, it can ensure that the specific type information of the type parameters in the inline method can be obtained when the bytecode file is run.

[0031] The technical solution of the present application is described in detail below through some embodiments. The embodiments described below can be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.

[0032] Figure 1 This is a flowchart of a code compilation method provided in an embodiment of the present application. The code compilation method provided in an embodiment of the present application can be performed by a code compilation device, which can be composed of hardware and / or software and can be integrated into an electronic device. Optionally, the electronic device in this application can be, but is not limited to, a personal computer, a laptop computer, a tablet computer, and a server. The server can be, but is not limited to, a server cluster or a standalone server.

[0033] like Figure 1 As shown, the method may include the following steps:

[0034] S101, generating a global variable bytecode segment of at least one type information in an anonymous inner class based on annotation information of an inline method in a source code file, wherein the anonymous inner class is located in the inline method, and a tag code pair corresponding to the type information is set in the code segment of the anonymous inner class.

[0035] In this application, the above source code file can be understood as the source code written by the user for any software program. Among them, the user can be selected as a user with code writing requirements, and there is no restriction on it here.

[0036] Furthermore, to reduce the number of anonymous inner classes within inline methods in compiled source code files, users can obtain a tag code pair from a known code library that marks the initial bytecode segment of each type information, and then write this tag code pair into the corresponding anonymous inner class code segment. Known code libraries are all user-accessible libraries, meaning that the code in these libraries is visible to the general public.

[0037] It should be understood that an anonymous inner class is an inner class without a name that is generated to simplify code writing and usually exists inside a method body.

[0038] The above-mentioned inline method can be understood as an inline function (inline). Generally, a source code file may include at least one inline method, and at least one anonymous inner class may be created in an inline method.

[0039] The above-mentioned annotation information can be understood as special marking information in the code, which can be read during code compilation, class loading, or runtime. Annotation information is supplementary information written by the user into the source code without changing the original code and logic. This annotation information can be supplementary information added to a method or a class, and there are no restrictions on this.

[0040] Generally, the code compilation process may include two parts: the compilation front-end and the compilation back-end. Therefore, when the present application compiles the written source code file, it may first obtain the annotation information of the inline method from the source code file through the front-end compilation analysis plug-in in the compilation front-end, such as AnalysisHandlerExtension. Then, the type parameters in the inline method are obtained from the annotation information of the inline method through the front-end compilation analysis plug-in. Furthermore, based on the type information inside the type parameter in the inline method, a global variable bytecode segment of at least one type information in the anonymous inner class is generated.

[0041] In this application, the type parameters in the above inline method can be selected as generic type parameters.

[0042] It should be understood that generics means that the specific types of properties or method parameters in a class will not be set when the class is defined, but the types will be defined when the class is used.

[0043] Among them, bytecode can be understood as an intermediate code between source code and machine code, which is the result obtained by compiling the source code.

[0044] In some optional embodiments, the above-mentioned obtaining of the type parameters in the inline method from the annotation information of the inline method through the front-end compilation and analysis plug-in can be achieved through the analysisCompleted method in the front-end compilation and analysis plug-in implementation code.

[0045] Optionally, in the callback of the analysisCompleted method, the resolvedCall information is collected to filter out the calls of the inline method corresponding to the annotation information, and then the type parameters are obtained from the annotation information of the inline method.

[0046] Considering that in incremental compilation scenarios, the input source code file may only contain modified or added source code rather than the complete source code file, the type parameters of the inline methods obtained from the annotation information of the inline methods through the front-end compilation analysis plug-in will not be the type parameters of all inline methods in the complete source code file.

[0047] However, because in the complete source code file, except for the modified source code or the added source code, the rest of the unchanged source code has completed the compilation process before the modified source code or the added source code is compiled. That is, the rest of the unchanged source code has already obtained the type parameters in the corresponding inline method during the previous compilation process. Therefore, this application obtains the type parameters in the inline method from the annotation information of the inline method in the modified source code or the added source code through the front-end compilation analysis plug-in, and then obtains the type parameters in the inline method in the remaining unchanged source code from the relevant storage unit, and takes the union of these two type parameters as the type parameters in all inline methods in the complete source code file.

[0048] It should be understood that the incremental compilation mentioned above refers to compiling only the modified source code or the added source code during the source code compilation process, and not compiling the remaining unchanged source code.

[0049] In some optional embodiments, the present application generates a global variable bytecode segment of at least one type information in an anonymous inner class based on the type information inside the type parameter in the inline method. Specifically, the type information inside each type parameter is obtained, and then a global variable code segment of each type information is generated based on each type information, and the global variable code segments of all type information are stored.

[0050] Optionally, the above-mentioned global variable code segment for generating each type information can be obtained by inputting each type information into a code generator, such as KotlinPoet, so that the code generator can automatically generate a global variable code segment in the target format based on the type information. The target format can be any pre-set format, and this application does not impose any specific restrictions here.

[0051] After storing the global variable code segments of all type information, this application can compile the code segments of the inline methods in the source code file through the backend compilation analysis plug-in of the compilation backend, such as ClassBuilderInterceptorExtension, to obtain the bytecode segments corresponding to the inline method code segments. At the same time, the backend compilation analysis plug-in of the compilation backend can also compile the stored global variable code segments of each type information to obtain the global variable bytecode segments of each type information.

[0052] In some optional embodiments, the method in the front-end compilation and analysis plug-in in this application may be ClassBuilderFactory.

[0053] S102 , determining an initial bytecode segment of each type information in the anonymous inner class from the bytecode segment compiled from the inline method according to the tag code pair, where each initial bytecode segment includes type information.

[0054] In this application, the initial bytecode segment of type information can be understood as the bytecode segment of the method call for obtaining type information.

[0055] Since the anonymous inner class code segment in the inline method will be compiled together with the compilation of the inline method code segment, accordingly, each tag code pair set in the anonymous inner class code segment will also be compiled into a tag bytecode pair. Therefore, the present application can obtain the tag bytecode pair corresponding to each tag code pair from the bytecode segment compiled from the inline method code segment. Then, based on each tag bytecode pair, the initial bytecode segment of each type information in the anonymous inner class can be determined in the bytecode segment compiled from the inline method.

[0056] That is, when determining the initial bytecode segment for each type of information in the anonymous inner class from the bytecode segment compiled from the inline method, the bytecode segments can be identified by locating the marker bytecode pairs corresponding to the initial bytecode segments of different type of information, such as INVOKESTATIC xxxxx / beginIntercept and INVOKESTATIC xxxxx / endIntercept. Furthermore, the bytecode segment between each located marker bytecode pair can be determined as the initial bytecode segment for each type of information in the anonymous inner class.

[0057] As an optional implementation, this application locates the initial bytecode segment of any type of information of the anonymous inner class by marking the bytecode pair, as shown below:

[0058] INVOKESTATICxxxxx / beginIntercept

[0059] / / This line instantiates an object of an anonymous inner class. The fqName of the class is omitted here.

[0060] NEW com / bytedance / xxxxxxx / Request$get$1

[0061] / / Copy the top element of the stack, which is the object above, because the instance construction method will consume this element

[0062] DUP

[0063] / / Call the instance constructor

[0064] INVOKESPECIAL com / bytedance / xxxxxxx / Request$get$1. <init>V()

[0065] / / Call the getType method of that instance. By the way, the .type is kotlin syntax sugar, and the getType method is actually called

[0066] INVOKEVIRTUAL com / bytedance / xxxxxxx / Request$get$1.getType

[0067] ()Ljava / lang / reflect / Type

[0068] / / Here, because it needs to be loaded and returned later, there will be an astore, and the number behind it may be unspecified.

[0069] ASTORE X

[0070] INVOKESTATICxxxxx / endIntercept

[0071] ALOAD X

[0072] S103 , obtaining a target global variable bytecode segment from all global variable bytecode segments according to each type information.

[0073] In some optional embodiments, type information may be obtained from each located initial bytecode segment. Each piece of type information is then matched against type information in all stored global variable bytecode segments. If each piece of type information matches type information in any stored global variable bytecode segment, the global variable bytecode segment is determined to be the target global variable bytecode segment for the type information.

[0074] It should be understood that the above type information matches the type information in any stored global variable bytecode segment, which may mean that the type information is the same.

[0075] S104: Generate a target bytecode file according to each initial bytecode segment and each target global variable bytecode segment.

[0076] In this application, the target bytecode file can be optionally a class file.

[0077] Optionally, the present application may replace the initial bytecode segment of the corresponding type information by utilizing the determined target global variable bytecode segment, i.e., replace each initial bytecode segment with the corresponding target global variable bytecode segment to generate a target bytecode file corresponding to the source code file.

[0078] Considering that an inline method may include more than one call to a method for obtaining type information, such as a call to getType, this application needs to loop through the bytecode compiled from the source code, searching for the initial bytecode segment related to type information based on the marker code pair, and then replace the found initial bytecode segment with the corresponding target global variable bytecode segment until all initial bytecode segments of type information are replaced.

[0079] In some optional embodiments, considering that jump labels may exist in the initial bytecode segments of some type information in anonymous inner classes, the present application replaces the initial bytecode segment of any type information with the target global variable bytecode segment and also adds the jump labels in the initial bytecode segment to the target global variable bytecode segment to ensure that when the target bytecode file is subsequently executed, no errors will be caused by the absence of jump labels.

[0080] The technical solution disclosed in the embodiment of the present application generates a global variable bytecode segment of at least one type information in the anonymous inner class in the inline method according to the annotation information of the inline method in the source code file, and then determines the initial bytecode segment of each type information in the anonymous inner class from the bytecode segment compiled by the inline method according to the tag code pair corresponding to each type information in the anonymous inner class code segment, and then obtains the target global variable bytecode segment from all global variable bytecode segments according to the type information in each initial bytecode segment, and then generates a target bytecode file according to each initial bytecode segment and each target global variable bytecode segment. The embodiment of the present application replaces the initial bytecode segment of each type information in the anonymous inner class by using the global variable bytecode segment of the type information in the anonymous inner class, so that the anonymous inner class in the inline method is deleted due to no reference, thereby reducing the number of anonymous inner classes in the inline method, so that the volume of the bytecode file package after the source code is compiled will not increase significantly, and at the same time, it can ensure that the specific type information of the type parameters in the inline method can be obtained when the bytecode file is run.

[0081] Based on the above embodiment, considering that the number of global variable bytecode segments generating type information in anonymous inner classes according to the annotation information of the inline method may be large, in order to accurately obtain the target global variable bytecode segment corresponding to each initial bytecode segment to be replaced, this application can provide a detailed explanation of obtaining the target global variable bytecode segment from all global variable bytecode segments according to each type information. Figure 2 As shown, the above step S103 may include the following steps:

[0082] S103-1, in the mapping relationship between type information and variable identifiers, determine the target variable identifier according to the type information.

[0083] S103-2, according to the target variable identifier, obtaining the target global variable bytecode segment from all stored global variable bytecode segments.

[0084] The variable identifier can be understood as identity information that can uniquely identify the variable, such as a variable name or a variable number, etc., and no restrictions are imposed on it here.

[0085] Optionally, after compiling the global variable code segment for each type of information to obtain the global variable bytecode segment for each type of information, the present application can analyze and process each global variable bytecode segment to determine the variable identifier corresponding to the type information in each global variable bytecode segment. Subsequently, a mapping relationship between the type information and the variable identifier is established. Then, each global variable bytecode segment is stored according to the mapping relationship between the type information and the variable identifier.

[0086] Exemplarily, each global variable bytecode segment is stored according to the mapping relationship between type information and variable identifier, as shown in Table 1 below:

[0087] Table 1

[0088]

[0089] Furthermore, when obtaining a target global variable bytecode segment from all stored global variable bytecode segments, the present application may first determine a variable identifier that has a mapping relationship with each type information in the mapping relationship between type information and variable identifiers, and determine the variable identifier as the target variable identifier. The target global variable bytecode segment is then obtained from a preset storage unit based on the target variable identifier.

[0090] The technical solution disclosed in the embodiment of the present application stores the generated global variable bytecode segments according to the mapping relationship between type information and variable identifiers, so that during the back-end compilation process, the back-end compilation analysis plug-in can accurately determine the target global variable bytecode segment corresponding to the type information based on the type information in the initial bytecode segment, thereby ensuring the accuracy of replacing the initial bytecode segment of each type information in the anonymous inner class.

[0091] Please refer to the attached Figure 3 , a code compilation device proposed in the embodiment of the present application is described. Figure 3 As shown, the code compiling device 300 includes: a first generating module 310 , a determining module 320 , an acquiring module 330 and a second generating module 340 .

[0092] The first generating module 310 is configured to generate a global variable bytecode segment of at least one type information in an anonymous inner class based on annotation information of an inline method in a source code file, wherein the anonymous inner class is located in the inline method, and a tag code pair corresponding to the type information is provided in the code segment of the anonymous inner class;

[0093] a determination module 320 configured to determine, from the bytecode segments compiled from the inline method, an initial bytecode segment for each type information in the anonymous inner class according to the tag code pair, wherein each initial bytecode segment includes type information;

[0094] an acquisition module 330, configured to acquire a target global variable bytecode segment from all global variable bytecode segments according to each type information;

[0095] The second generating module 340 is configured to generate a target bytecode file according to each of the initial bytecode segments and each of the target global variable bytecode segments.

[0096] In an optional implementation of the embodiment of the present application, the determining module 320 is specifically configured to:

[0097] Obtaining, from the bytecode segment compiled from the inline method, a marked bytecode pair corresponding to each of the marked code pairs;

[0098] According to each of the tag bytecode pairs, an initial bytecode segment of each type information in the anonymous inner class is determined in the bytecode segment compiled after the inline method is compiled.

[0099] In an optional implementation of the embodiment of the present application, the apparatus 300 further includes:

[0100] an information determination module, configured to determine a variable identifier corresponding to the type information of each global variable bytecode segment;

[0101] A storage module is used to store each of the global variable bytecode segments according to the mapping relationship between the type information and the variable identifier.

[0102] In an optional implementation of the embodiment of the present application, the acquisition module 330 is specifically configured to:

[0103] In the mapping relationship between the type information and the variable identifiers, determining a target variable identifier according to each piece of the type information;

[0104] According to each target variable identifier, a target global variable bytecode segment is obtained from all stored global variable bytecode segments.

[0105] In an optional implementation of the embodiment of the present application, the second generation module 340 is specifically configured to:

[0106] Each of the initial bytecode segments is replaced with the corresponding target global variable bytecode segment to generate a target bytecode file.

[0107] In an optional implementation of the embodiment of the present application, if any of the initial bytecode segments has a jump label, the apparatus 300 further includes:

[0108] An adding module is used to add the jump label to the replaced target global variable bytecode segment.

[0109] In an optional implementation of the embodiment of the present application, the first generation module 310 is specifically configured to:

[0110] Obtaining type parameters in the inline method from the annotation information of the inline method;

[0111] A global variable bytecode segment of at least one type information in the anonymous inner class is generated according to the type information inside the type parameter.

[0112] It should be understood that the device embodiment and the aforementioned method embodiment may correspond to each other, and similar descriptions may refer to the method embodiment. To avoid repetition, no further details will be given here. Specifically, Figure 3 The apparatus 300 shown may perform Figure 1 The corresponding method embodiment, and the aforementioned and other operations and / or functions of each module in the device 300 are respectively to achieve Figure 1 For the sake of brevity, the corresponding processes in each method are not repeated here.

[0113] The above describes the device 300 of the embodiment of the present application from the perspective of functional modules in conjunction with the accompanying drawings. It should be understood that the functional module can be implemented in hardware form, can be implemented by instructions in software form, and can also be implemented by a combination of hardware and software modules. Specifically, the steps of the first aspect method embodiment in the embodiment of the present application can be completed by the hardware integrated logic circuit and / or software form instructions in the processor, and the steps of the first aspect method disclosed in conjunction with the embodiment of the present application can be directly embodied as being executed by a hardware decoding processor, or can be executed by a combination of hardware and software modules in the decoding processor. Optionally, the software module can be located in a mature storage medium in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps in the above-mentioned first aspect method embodiment in conjunction with its hardware.

[0114] Figure 4 This is a schematic block diagram of an electronic device provided in an embodiment of the present application. Figure 4 As shown, the electronic device 400 may include:

[0115] The memory 410 and the processor 420 are configured to store computer programs and transmit the program code to the processor 420. In other words, the processor 420 can call and run the computer program from the memory 410 to implement the code compilation method in the embodiment of the present application.

[0116] For example, the processor 420 may be configured to execute the above code compilation method according to instructions in the computer program.

[0117] In some embodiments of the present application, the processor 420 may include but is not limited to:

[0118] General-purpose processor, digital signal processor (DSP), application-specific integrated circuit (ASIC), field-programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, etc.

[0119] In some embodiments of the present application, the memory 410 includes but is not limited to:

[0120] Volatile memory and / or non-volatile memory. Non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link DRAM (SLDRAM), and direct RAM bus random access memory (DR RAM).

[0121] In some embodiments of the present application, the computer program may be divided into one or more modules, which are stored in the memory 410 and executed by the processor 420 to implement the code compilation method provided by the present application. The one or more modules may be a series of computer program instruction segments capable of performing specific functions, and the instruction segments are used to describe the execution process of the computer program in the electronic device.

[0122] like Figure 4 As shown, the electronic device 400 may further include:

[0123] The transceiver 430 may be connected to the processor 420 or the memory 410 .

[0124] The processor 420 may control the transceiver 430 to communicate with other devices. Specifically, the processor 420 may send information or data to other devices or receive information or data sent by other devices. The transceiver 430 may include a transmitter and a receiver. The transceiver 430 may further include one or more antennas.

[0125] It should be understood that the various components in the electronic device are connected via a bus system, wherein the bus system includes not only a data bus but also a power bus, a control bus and a status signal bus.

[0126] The present application also provides a computer storage medium having a computer program stored thereon. When the computer program is executed by a computer, the computer is enabled to execute the code compilation method of the above method embodiment.

[0127] An embodiment of the present application further provides a computer program product comprising program instructions, which, when executed on an electronic device, enables the electronic device to execute the code compiling method of the above method embodiment.

[0128] When software is used for implementation, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a digital video disc (DVD)), or a semiconductor medium (e.g., a solid state drive (SSD)).

[0129] Those skilled in the art will appreciate that the modules and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0130] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the modules is merely a logical function division. In actual implementation, there may be other division methods, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.

[0131] Modules described as separate components may or may not be physically separate, and components displayed as modules may or may not be physical modules, i.e., they may be located in one place or distributed across multiple network elements. Some or all of the modules may be selected based on actual needs to achieve the purpose of the present embodiment. For example, the functional modules in the various embodiments of the present application may be integrated into a processing module, or each module may exist physically separately, or two or more modules may be integrated into a single module.

[0132] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program that has a predetermined function and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories), or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the functions of the module or unit.

[0133] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.< / init>

Claims

1. A code compilation method, characterized in that: include: generating, based on annotation information of an inline method in a source code file, a global variable bytecode segment of at least one type information in an anonymous inner class, wherein the anonymous inner class is located in the inline method, and a tag code pair corresponding to the type information is provided in the code segment of the anonymous inner class; Determine, from the bytecode segments compiled from the inline method, an initial bytecode segment for each type information in the anonymous inner class according to the tag code pair, each initial bytecode segment including type information; According to each of the type information, obtaining a target global variable bytecode segment from all global variable bytecode segments; A target bytecode file is generated according to each of the initial bytecode segments and each of the target global variable bytecode segments.

2. The method according to claim 1, characterized in that Determining, from the bytecode segment compiled from the inline method, the initial bytecode segment of each type information in the anonymous inner class according to the tag code pair, comprises: Obtaining, from the bytecode segment compiled from the inline method, a marked bytecode pair corresponding to each of the marked code pairs; According to each of the tag bytecode pairs, an initial bytecode segment of each type information in the anonymous inner class is determined in the bytecode segment compiled after the inline method is compiled.

3. The method according to claim 1, characterized in that The method further comprises: Determine a variable identifier corresponding to the type information of each global variable bytecode segment; Each of the global variable bytecode segments is stored according to the mapping relationship between the type information and the variable identifier.

4. The method according to claim 3, characterized in that The step of obtaining a target global variable bytecode segment from all global variable bytecode segments according to each type information includes: In the mapping relationship between the type information and the variable identifiers, determining a target variable identifier according to each piece of the type information; According to each target variable identifier, a target global variable bytecode segment is obtained from all stored global variable bytecode segments.

5. The method according to claim 1, wherein Generating a target bytecode file according to each of the initial bytecode segments and each of the target global variable bytecode segments includes: Each of the initial bytecode segments is replaced with the corresponding target global variable bytecode segment to generate a target bytecode file.

6. The method according to any one of claims 1 to 5, characterized in that If any of the initial bytecode segments has a jump label, the method further includes: The jump label is added to the replaced target global variable bytecode segment.

7. The method according to claim 1, characterized in that The step of generating a global variable bytecode segment of at least one type of information in an anonymous inner class according to the annotation information of the inline method in the source code file includes: Obtaining type parameters in the inline method from the annotation information of the inline method; A global variable bytecode segment of at least one type information in the anonymous inner class is generated according to the type information inside the type parameter.

8. A code compiling device, characterized in that: include: a first generating module, configured to generate, based on annotation information of an inline method in a source code file, a global variable bytecode segment of at least one type information in an anonymous inner class, wherein the anonymous inner class is located in the inline method, and a tag code pair corresponding to the type information is provided in the code segment of the anonymous inner class; a determination module, configured to determine, from the bytecode segments compiled from the inline method, an initial bytecode segment of each type information in the anonymous inner class according to the tag code pair, wherein each initial bytecode segment includes type information; an acquisition module, configured to acquire a target global variable bytecode segment from all global variable bytecode segments according to each of the type information; The second generating module is used to generate a target bytecode file according to each of the initial bytecode segments and each of the target global variable bytecode segments.

9. An electronic device, characterized in that: include: A processor and a memory, the memory being used to store a computer program, and the processor being used to call and run the computer program stored in the memory to execute the code compiling method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that Used to store a computer program, wherein the computer program enables a computer to execute the code compiling method according to any one of claims 1 to 7.