CN114003317B - Inline implementation method and device, electronic equipment, storage medium and program product - Google Patents
Inline implementation method and device, electronic equipment, storage medium and program product Download PDFInfo
- Publication number
- CN114003317B CN114003317B CN202111272867.9A CN202111272867A CN114003317B CN 114003317 B CN114003317 B CN 114003317B CN 202111272867 A CN202111272867 A CN 202111272867A CN 114003317 B CN114003317 B CN 114003317B
- Authority
- CN
- China
- Prior art keywords
- inline
- class
- instruction
- methods
- instructions
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 499
- 230000003068 static effect Effects 0.000 claims description 9
- 238000004590 computer program Methods 0.000 claims description 4
- 230000008569 process Effects 0.000 claims description 4
- 238000005516 engineering process Methods 0.000 abstract description 2
- 230000006870 function Effects 0.000 description 8
- 238000010586 diagram Methods 0.000 description 6
- 238000004891 communication Methods 0.000 description 3
- 230000003287 optical effect Effects 0.000 description 3
- 230000006978 adaptation Effects 0.000 description 2
- 238000004458 analytical method Methods 0.000 description 2
- 239000013307 optical fiber Substances 0.000 description 2
- 230000000644 propagated effect Effects 0.000 description 2
- 230000009471 action Effects 0.000 description 1
- 238000003491 array Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000002708 enhancing effect Effects 0.000 description 1
- 230000003993 interaction Effects 0.000 description 1
- 238000007726 management method Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000002093 peripheral effect Effects 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/448—Execution paradigms, e.g. implementations of programming paradigms
- G06F9/4488—Object-oriented
- G06F9/449—Object-oriented method invocation or resolution
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/31—Programming languages or programming paradigms
- G06F8/315—Object-oriented languages
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/70—Software maintenance or management
- G06F8/73—Program documentation
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Library & Information Science (AREA)
- Computing Systems (AREA)
- Devices For Executing Special Programs (AREA)
Abstract
The disclosure relates to an inline implementation method and device, electronic equipment, a storage medium and a program product, and relates to the technical field of computers. The method comprises the following steps: acquiring configuration information, wherein the configuration information comprises classes with inline methods and corresponding inline methods; obtaining a class file of a class with an inline method in the configuration information, and obtaining a method node of the inline method in the configuration information through a byte code control framework; generating a corresponding relation between the class with the inline method and a method node of the inline method; and traversing the method instructions in the class file through the byte code control framework, and if the byte code instructions in the method instructions are calling instructions and the classes and the methods corresponding to the method instructions belong to the corresponding relations, acquiring the method nodes corresponding to the method instructions, and replacing the method instructions by the method nodes. The method can realize the inlining in Java semantics and solve the problem of time consuming program operation caused by inlining the method in the related technology.
Description
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to an inline implementation method and apparatus, an electronic device, a storage medium, and a program product.
Background
Java method inlining is a technique of "copying" caller function code into caller function, reducing the cost of calling due to functions. In the related art, java does not support semantic inlining, and the judgment of the inlining method needs to be performed by a virtual machine. When a method is not marked as an inline method by a virtual machine, the calling of the common method can cause frequent entry and ejection of a virtual machine stack, and the time consumption of program running is increased.
It should be noted that the information disclosed in the above background section is only for enhancing understanding of the background of the present disclosure and thus may include information that does not constitute prior art known to those of ordinary skill in the art.
Disclosure of Invention
The present disclosure provides an inline implementation method and apparatus, an electronic device, a storage medium, and a program product, so as to at least solve the problem of time consuming program running caused by method inline in the related art. The technical scheme of the present disclosure is as follows:
According to an aspect of the embodiments of the present disclosure, there is provided an inline implementation method, including: acquiring configuration information, wherein the configuration information comprises classes with inline methods and corresponding inline methods; obtaining a class file of the class with the inline method in the configuration information, and obtaining a method node of the inline method in the configuration information through a byte code control framework; generating a corresponding relation between the class with the inline method and a method node of the inline method; traversing the method instructions in the class file through the byte code control framework, and if the byte code instructions in the method instructions are calling instructions and the classes and the methods corresponding to the method instructions belong to the corresponding relations, acquiring the method nodes corresponding to the method instructions, and replacing the method instructions by the method nodes.
In one embodiment of the present disclosure, the method further comprises: inquiring the inline method through an annotation processor, and determining the class with the inline method according to the inline method; and generating the configuration information by taking the class name of the class with the inline method as an index and taking the method signature of one or more inline methods contained in the class with the inline method as a value.
In one embodiment of the disclosure, the generating the correspondence between the class with the inline method and the method node of the inline method includes: and storing Map data by taking class names of the classes with the inline methods as indexes and taking method nodes of one or more inline methods contained in the classes with the inline methods as values.
In one embodiment of the disclosure, if the bytecode instruction in the method instruction is a call instruction and the class and the method corresponding to the method instruction belong to the correspondence, acquiring a method node corresponding to the method instruction, and replacing the method instruction with the method node, including: judging whether a byte code instruction in the method instruction is a calling instruction or not, and judging that the class name and the method name behind the method instruction belong to stored Map data; if yes, inquiring a method node corresponding to the method instruction in the stored Map data according to the class name and the method name behind the method instruction, and further replacing the method instruction by using an instruction in the inquired method node.
In one embodiment of the present disclosure, the inline method has inline annotation tags.
In one embodiment of the present disclosure, the inline method is a static method.
According to another aspect of the embodiments of the present disclosure, there is provided an inline implementation apparatus including: a configuration module configured to obtain configuration information, the configuration information including classes with inline methods and corresponding inline methods; the acquisition module is configured to acquire a class file of the class with the inline method in the configuration information, and acquire a method node of the inline method in the configuration information through a byte code control framework; a generation module configured to generate a correspondence between the class with the inline method and a method node of the inline method; and the replacement module is configured to traverse the method instructions in the class file through the byte code control framework, and if the byte code instructions in the method instructions are calling instructions and the class and the method corresponding to the method instructions belong to the corresponding relation, the method nodes corresponding to the method instructions are obtained, and the method instructions are replaced by the method nodes.
In one embodiment of the present disclosure, the configuration module is configured to: inquiring the inline method through an annotation processor, and determining the class with the inline method according to the inline method; and generating the configuration information by taking the class name of the class with the inline method as an index and taking the method signature of one or more inline methods contained in the class with the inline method as a value.
In one embodiment of the present disclosure, the generation module is configured to: and storing Map data by taking class names of the classes with the inline methods as indexes and taking method nodes of one or more inline methods contained in the classes with the inline methods as values.
In one embodiment of the present disclosure, the replacement module is configured to: judging whether a byte code instruction in the method instruction is a calling instruction or not, and judging that the class name and the method name behind the method instruction belong to stored Map data; if yes, inquiring a method node corresponding to the method instruction in the stored Map data according to the class name and the method name behind the method instruction, and further replacing the method instruction by using an instruction in the inquired method node.
In one embodiment of the present disclosure, the inline method has inline annotation tags.
In one embodiment of the present disclosure, the inline method is a static method.
According to still another aspect of the embodiments of the present disclosure, there is provided an electronic apparatus including: a processor; a memory for storing the processor-executable instructions; wherein the processor is configured to execute the instructions to implement the inline implementation method described above.
According to yet another aspect of embodiments of the present disclosure, a computer-readable storage medium is provided, which when executed by a processor of an electronic device, enables the electronic device to perform the above-described inline implementation method.
According to yet another aspect of the disclosed embodiments, a computer program product is provided, comprising a computer program/instruction which, when executed by a processor, implements the inline implementation described above.
The technical scheme provided by the embodiment of the disclosure at least brings the following beneficial effects: configuration information comprising a class with an inline method and an inline method can be obtained, and then class files of the class with the inline method are analyzed by utilizing a byte code control framework to obtain method nodes of the inline method, and corresponding relations between the class with the inline method and the method nodes of the inline method are generated.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the disclosure and together with the description, serve to explain the principles of the disclosure and do not constitute an undue limitation on the disclosure.
FIG. 1 is a flow chart illustrating a method of inline implementation, according to an exemplary embodiment.
Fig. 2 is a flow chart illustrating generating configuration information according to an exemplary embodiment.
Fig. 3 is a data structure diagram of the Map data generated.
FIG. 4 is a flowchart illustrating analysis of method instructions in a class file, according to an example embodiment.
Fig. 5 is a flow chart illustrating a method of inline implementation according to yet another exemplary embodiment.
Fig. 6 is a block diagram illustrating an inline implementation according to an example embodiment.
Fig. 7 is a block diagram illustrating the structure of an in-line implementation device, according to an example embodiment.
Detailed Description
In order to enable those skilled in the art to better understand the technical solutions of the present disclosure, the technical solutions of the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings.
It should be noted that the terms "first," "second," and the like in the description and claims of the present disclosure and in the foregoing figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the disclosure described herein may be capable of operation in sequences other than those illustrated or described herein. The implementations described in the following exemplary examples are not representative of all implementations consistent with the present disclosure. Rather, they are merely examples of apparatus and methods consistent with some aspects of the present disclosure as detailed in the accompanying claims.
The method provided by the embodiments of the present disclosure may be performed by any type of electronic device, such as a server or a terminal device, or an interaction of a server and a terminal device. The terminal device and the server may be directly or indirectly connected through wired or wireless communication, and the present application is not limited herein.
The server may be an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, or a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDNs (Content Delivery Network, content delivery networks), basic cloud computing services such as big data and artificial intelligent platforms, and the like.
The terminal device may be, but is not limited to, a smart phone, a tablet computer, a notebook computer, a desktop computer, a smart speaker, a smart watch, etc.
FIG. 1 is a flow chart illustrating a method of inline implementation, according to an exemplary embodiment. As shown in fig. 1, the inline implementation method includes the following steps.
In step S110, configuration information is obtained, wherein the configuration information includes classes with inline methods and corresponding inline methods.
An inline method refers to a method in a Java file that needs to be inline, and if a method is an inline method, then the code of the method needs to be "copied" into a caller function. In the embodiment of the disclosure, the inline method is a static method. Thus, an inline method belongs to a class, does not belong to an object, and can be called by class name before instantiating the object.
Classes with inline methods refer to methods that include in the class that require inline. For example, class1, class2 and class3 are classes with inline methods, and methods requiring inline in class1 are methods 1, 4, methods 2, 3, 5, and then class1, class2 and class3, and methods 1, 2, 3, 4 and 5.
In step S120, a class file of the class with the inline method in the configuration information is obtained, and a method node of the inline method in the configuration information is obtained through a bytecode manipulation framework.
The class file is a file generated by compiling a Java file, and is also called a byte code file. After the class with the inline method in the configuration information is obtained, the class file may be traversed, and then the class file with the class with the inline method may be obtained, and then the class file with the class with the inline method may be analyzed by ASM (i.e., a bytecode manipulation framework) to obtain methodnode (i.e., a method node) of the inline method in the configuration information. The specific implementation may be that a plug-in is customized gradle (i.e., an open source tool is automatically built based on the project of the concepts APACHE ANT and APACHE MAVEN), the gradle plug-in is used to manipulate class files of the class with the inline method through the object model access mode in the ASM, and the class files can obtain methodnode through classnode, so that methodnode of the inline method recorded in the configuration information can be obtained. Wherein methodnode has an attribute InsnList, insnList that is a doubly linked list object that contains the byte instruction of the storage method.
In step S130, a correspondence between the class with the inline method and a method node of the inline method is generated.
After methodnode of the inline method and the class with the inline method are obtained, a correspondence between the class with the inline method and methodnode of the inline method may be generated. For example, methods requiring an interconnection in class1 include method1 and method4, and step S120 can obtain methodnode of method1 and methodnode of method4, so that the correspondence between class1 and methodnode of method1 and methodnode of method4 can be generated.
In step S140, traversing the method instruction in the class file through the byte code control framework, if the byte code instruction in the method instruction is a call instruction and the class and the method corresponding to the method instruction belong to the corresponding relation, acquiring a method node corresponding to the method instruction, and replacing the method instruction by using the method node.
Traversing the class file, and traversing method instructions of all methods in the class file by using the ASM. If the byte code instruction in a method instruction is a calling instruction, the method is indicated as a calling method. In this case, if the class and method corresponding to the method instruction are included in the correspondence generated in step S130, it is explained that the method inline needs to be executed, so methodnode corresponding to the method instruction may be acquired, and the method instruction may be replaced with methodnode.
The Java inline implementation method provided by the embodiment of the disclosure can acquire configuration information including classes with inline methods and inline methods, further analyze class files with the classes with inline methods by using ASM to acquire methodnode of the inline methods, generate a corresponding relation between the classes with inline methods and methodnode of the inline methods, and thus determine a method instruction to be replaced by combining the generated corresponding relation when traversing method instructions in the class files, and replace the method instruction by using methodnode of the inline methods, thereby realizing Java semantic inline, solving the problem of program operation time consumption caused by the inline methods in the related art, reducing the number of calling methods, and reducing program operation calling cost.
In an exemplary embodiment, the inline implementation method may further include generation of configuration information. Fig. 2 is a flow chart illustrating generating configuration information according to an exemplary embodiment. As shown in fig. 2, the step of generating configuration information may include:
Step S210, inquiring the inline method through an annotation processor, and further determining the class with the inline method according to the inline method.
And step S220, taking the class name of the class with the inline method as an index, taking the method signature of one or more inline methods contained in the class with the inline method as a value, and generating the configuration information.
In the encoding period of the Java file, a method that an Inline annotation mark needs to be Inline, such as a method that an Inline annotation mark needs to be Inline through @ Inline, can be adopted, so that a method with the annotation mark can be queried through an annotation processor in the compiling period. Thus, in embodiments of the present disclosure, an inline method has inline annotation tags.
The annotation processor may be understood as a piece of Java program that may be used to parse annotations at the compilation-time of the Java file. When the Java file is compiled into the byte code file, the method with the inline annotation mark in the Java file can be analyzed through the annotation processor, that is, the inline method can be queried through the annotation processor, and then the class of the inline method can be determined, namely the class with the inline method can be determined. Next, configuration information may be generated with a class name of the class having the inline method as an index and a method signature of the inline method included in the class having the inline method as a value. Wherein the method signature consists of a method name and a list of parameters (i.e. the order and type of parameters of the method).
For example, methods method1, method2, method3, method4 and method5 are Inline methods, and then during the encoding period of the Java file, the marking methods method1, method2, method3, method4 and method5 can be annotated by @ Inline. When encoding a Java file, methods method1, method2, method3, method4, and method5 marked with @ line annotation are queried by the annotation processor. Also, it can be determined that methods method1 and method4 belong to class1, methods method2 and method3 belong to class2, and method5 belongs to class3, then class1, class2, and class3 with inline methods can be obtained. Finally, configuration information is generated with class name of class1 as an index, with method signatures of inline methods method1 and method4 contained in class1 as values, configuration information with class name of class2 as an index, with method signatures of inline methods method2 and method3 contained in class2 as values, and configuration information with class name of class3 as an index, with method signature of inline method5 contained in class3 as values.
In the related art, a virtual machine is required to carry out an inline judgment, in the embodiment of the disclosure, an inline annotation mark is adopted to carry out an inline method in the encoding period of a Java file, so that the method requiring inline is acquired through an annotation processor in the compiling period of the Java file, and a configuration file comprising classes with the inline method and the inline method is further generated, so that subsequent use of the configuration file to realize Java semantic inline is facilitated.
In an exemplary embodiment, the generating of the correspondence between the class with inline method and methodnode of the inline method in step S130 may include: and storing Map data by taking class names of the classes with the inline methods as indexes and taking methodnode of one or more inline methods contained in the classes with the inline methods as values.
Fig. 3 is a data structure diagram of the Map data generated. In FIG. 3, methods 1,2,3,4 and 5 are inline methods, and class1, class2 and class3 are classes with inline methods. It can be seen that class1 corresponds to method nodes of methods 1 and 4, class2 corresponds to method nodes of methods 2 and 3, and class3 corresponds to method node of method 5. That is, method nodes of methods 1 and 4 can be queried rapidly through class1, method nodes of methods 2 and 3 can be queried rapidly through class2, and method nodes of method5 can be queried rapidly through class 3.
In the embodiment of the disclosure, map data can be stored by using class names of classes with inline methods as indexes and methodnode of inline methods contained in the classes with inline methods as values, and because Map data are key values and data types, the Map data have extremely high searching speed, the corresponding method nodes can be quickly searched according to the stored Map data by replacing instructions, and the time consumption for running a program is further reduced.
FIG. 4 is a flowchart illustrating analysis of method instructions in a class file, according to an example embodiment. As shown in fig. 4, the step of analyzing the method instructions in the class file may include:
Step S410, judging whether the byte code in the method instruction is a calling instruction, if yes, executing step S420;
Step S420, judging whether the class name and the method name behind the method instruction belong to stored Map data, if yes, executing step S430;
step S430, inquiring a method node corresponding to the method instruction in the stored Map data according to the class name and the method name behind the method instruction, and further replacing the method instruction by the inquired instruction in the method node.
And traversing the method instructions in the class file through the ASM, namely sequentially analyzing the instruction contents of all the methods in the class file. If the bytecode in a method instruction is a call instruction invokestatic and the class name and the method name behind the method instruction belong to the stored Map data, the description "copies" the method function code, so that methodnode corresponding to the method instruction can be queried in the stored Map data and then replaced. Taking Map data as shown in fig. 3 as an example, a bytecode in a method instruction Method Instruction1 is a call instruction invokestatic, a class name is class1 and a method name is method1, then the instruction statement is deleted, and an instruction in methodnode of method1 is added to the position of the deleted instruction. If the class name following a method instruction Method Instruction is found to be class1 and the method name is found to be method2, instruction replacement is not needed because the class name is not stored in Map data.
Fig. 5 is a flowchart illustrating a Java inline implementation method according to yet another exemplary embodiment. As shown in fig. 5, the inline implementation method includes the following steps:
step S510, inquiring an inline method in the Java file through the annotation processor, and further determining a class with the inline method according to the inquired inline method, wherein the inquired inline method is a static method;
Step S520, generating configuration information by taking the class name of the class with the inline method as an index and taking the method signature of one or more inline methods contained in the class with the inline method as a value;
step S530, traversing Java class files through gradle plug-ins and ASM to obtain class files of classes with inline methods in the configuration information, and obtaining method nodes of the inline methods in the configuration information;
Step S540, the class name of the class with the inline method is used as an index, and the method nodes of one or more inline methods contained in the class with the inline method are used as values to store the class with the inline method as Map data;
step S550, traversing the method instruction in the Java class file through ASM;
Step S560, judging whether the byte code instruction in the method instruction is a calling instruction invokestatic and the class name and the method name behind the method instruction belong to the stored Map data, if yes, executing step S570, and if no, executing step S580;
Step S570, inquiring a method node corresponding to the method instruction in the stored Map data according to the class name and the method name behind the method instruction, and further replacing the method instruction by the instruction in the inquired method node;
Step S580 judges whether to traverse all the method instructions in the Java class file, if so, the process is ended, java inlining is realized, otherwise, the process is continued.
In the encoding period of the Java file, an inline annotation mark can be adopted to mark a static method needing inline, so that the inline method (namely, the static method needing inline) in the Java file can be queried through an annotation processor to obtain a class with the inline method, then a gradle plug-in unit and an ASM (advanced service management) can be utilized to modify the class file, the Java semantic inline is realized, the judgment of the inline through a virtual machine is avoided, the frequent entry and exit of a virtual machine stack can be reduced, the number of calling methods is reduced, and the program operation calling overhead is reduced.
The following describes the summation of two parameters by using an inline method, and the inline implementation method provided by the embodiment of the present disclosure is also applicable to service data in other service scenarios, which is not limited in the present disclosure.
As indicated by the code above, definition class T contains a method add that sums parameter a and parameter b, returns to c, and adds an Inline annotation tag @ Inline to the method add. Therefore, at the compiling period, the annotation processor queries the method add and the class T to which the method add belongs, and then corresponding configuration information can be generated by taking the class name of the class T as an index and the method signature of the method add contained in the class T as a value. Then, through gradle plug-ins and ASM, class files of class T are obtained, and methodnode of method add is obtained. Then, map data is stored with the class name of the class T as an index and methodnode of the method add included in the class T as a value. When the method instruction in the class file of the class User is traversed, the method instruction is determined to be a calling instruction, the class corresponding to the method instruction is T, and the corresponding method is add, so that the method instruction can be replaced by an instruction in methodnode of the method add, the code int c=T.add (a, b) can be changed into c=a+b after compiling, the calling of the method is avoided, and the method is connected.
Fig. 6 is a block diagram illustrating an inline implementation according to an example embodiment. Referring to fig. 6, the inline implementation apparatus 600 includes a configuration module 610, an acquisition module 620, a generation module 630, and a replacement module 640.
The configuration module 610 is configured to obtain configuration information. Wherein, the configuration information may include: classes with inline methods and corresponding inline methods.
The obtaining module 620 is configured to obtain a class file of a class having an inline method in the configuration information, and obtain methodnode of the inline method in the configuration information through ASM.
The generation module 630 is configured to generate a correspondence between the class with inline method and methodnode of the inline method.
The replacing module 640 is configured to traverse the method instructions in the class file through the ASM, and if the bytecode instruction in the method instructions is a call instruction and the class and the method corresponding to the method instructions belong to the corresponding relationship, obtain methodnode corresponding to the method instructions, and replace the method instructions with methodnode.
In an exemplary embodiment, the configuration module 610 may be further configured to: inquiring an inline method through an annotation processor, and determining a class with the inline method according to the inline method; the method includes generating configuration information with a class name of a class having an inline method as an index, and with a method signature of one or more inline methods included in the class having the inline method as a value.
In an exemplary embodiment, the generation module 630 may be further configured to: the class name of the class with the inline method is used as an index, and the method nodes of one or more inline methods contained in the class with the inline method are used as values and stored as Map data.
In an exemplary embodiment, the replacement module 640 may be further configured to: judging whether a byte code instruction in the method instruction is a calling instruction or not, and the class name and the method name behind the method instruction belong to stored Map data; if yes, inquiring a method node corresponding to the method instruction in the stored Map data according to the class name and the method name behind the method instruction, and replacing the method instruction by the instruction in the inquired method node.
In an exemplary embodiment, the inline method has inline annotation tags.
In an exemplary embodiment, the inline method is a static method.
The specific manner in which the various modules perform the operations in the apparatus of the above embodiments have been described in detail in connection with the embodiments of the method, and will not be described in detail herein.
Fig. 7 is a block diagram illustrating the structure of an in-line implementation device, according to an example embodiment. It should be noted that the illustrated electronic device is only an example, and should not impose any limitation on the functions and application scope of the embodiments of the present invention.
An electronic device 700 according to this embodiment of the invention is described below with reference to fig. 7. The electronic device 700 shown in fig. 7 is merely an example, and should not be construed as limiting the functionality and scope of use of embodiments of the present invention.
As shown in fig. 7, the electronic device 700 is embodied in the form of a general purpose computing device. Components of electronic device 700 may include, but are not limited to: the at least one processing unit 710, the at least one memory unit 720, and a bus 730 connecting the different system components, including the memory unit 720 and the processing unit 710.
Wherein the storage unit stores program code that is executable by the processing unit 710 such that the processing unit 710 performs steps according to various exemplary embodiments of the present invention described in the above-mentioned "exemplary methods" section of the present specification. For example, the processing unit 710 may perform step S110 shown in fig. 1, obtain configuration information, where the configuration information includes a class with an inline method and a corresponding inline method; step S120, obtaining a class file of the class with the inline method in the configuration information, and obtaining a method node of the inline method in the configuration information through a byte code control framework; step S130, generating a corresponding relation between the class with the inline method and a method node of the inline method; step S140, traversing the method instructions in the class file through the byte code control framework, and if the byte code instructions in the method instructions are calling instructions and the classes and the methods corresponding to the method instructions belong to the corresponding relations, acquiring the method nodes corresponding to the method instructions, and replacing the method instructions by the method nodes.
The memory unit 720 may include readable media in the form of volatile memory units, such as Random Access Memory (RAM) 7201 and/or cache memory 7202, and may further include Read Only Memory (ROM) 7203.
The storage unit 720 may also include a program/utility 7204 having a set (at least one) of program modules 7205, such program modules 7205 including, but not limited to: an operating system, one or more application programs, other program modules, and program data, each or some combination of which may include an implementation of a network environment.
Bus 730 may be a bus representing one or more of several types of bus structures including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
The electronic device 700 may also communicate with one or more external devices 800 (e.g., keyboard, pointing device, bluetooth device, etc.), one or more devices that enable a user to interact with the electronic device 700, and/or any device (e.g., router, modem, etc.) that enables the electronic device 700 to communicate with one or more other computing devices. Such communication may occur through an input/output (I/O) interface 750. Also, the electronic device 700 may communicate with one or more networks such as a Local Area Network (LAN), a Wide Area Network (WAN) and/or a public network, such as the Internet, through a network adapter 770. As shown, network adapter 770 communicates with other modules of electronic device 700 via bus 730. It should be appreciated that although not shown, other hardware and/or software modules may be used in connection with electronic device 700, including, but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, data backup storage systems, and the like.
From the above description of embodiments, those skilled in the art will readily appreciate that the example embodiments described herein may be implemented in software, or may be implemented in software in combination with the necessary hardware. Thus, the technical solution according to the embodiments of the present disclosure may be embodied in the form of a software product, which may be stored in a non-volatile storage medium (may be a CD-ROM, a U-disk, a mobile hard disk, etc.) or on a network, including several instructions to cause a computing device (may be a personal computer, a server, a terminal device, or a network device, etc.) to perform the method according to the embodiments of the present disclosure.
In an exemplary embodiment of the present disclosure, a computer-readable storage medium having stored thereon a program product capable of implementing the method described above in the present specification is also provided. In some possible embodiments, the various aspects of the invention may also be implemented in the form of a program product comprising program code for causing a terminal device to carry out the steps according to the various exemplary embodiments of the invention as described in the "exemplary methods" section of this specification, when said program product is run on the terminal device.
A program product for implementing the above-described method according to an embodiment of the present invention may employ a portable compact disc read-only memory (CD-ROM) and include program code, and may be run on a terminal device such as a personal computer. However, the program product of the present invention is not limited thereto, and in this document, a readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium can be, for example, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium would include the following: an electrical connection having one or more wires, a portable disk, a hard disk, random Access Memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
The computer readable signal medium may include a data signal propagated in baseband or as part of a carrier wave with readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A readable signal medium may also be any readable medium that is not a readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Program code for carrying out operations of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, C++ or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device, partly on a remote computing device, or entirely on the remote computing device or server. In the case of remote computing devices, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., connected via the Internet using an Internet service provider).
It should be noted that although in the above detailed description several modules or units of a device for action execution are mentioned, such a division is not mandatory. Indeed, the features and functionality of two or more modules or units described above may be embodied in one module or unit in accordance with embodiments of the present disclosure. Conversely, the features and functions of one module or unit described above may be further divided into a plurality of modules or units to be embodied.
Furthermore, although the steps of the methods in the present disclosure are depicted in a particular order in the drawings, this does not require or imply that the steps must be performed in that particular order, or that all illustrated steps be performed, to achieve desirable results. Additionally or alternatively, certain steps may be omitted, multiple steps combined into one step to perform, and/or one step decomposed into multiple steps to perform, etc.
From the above description of embodiments, those skilled in the art will readily appreciate that the example embodiments described herein may be implemented in software, or may be implemented in software in combination with the necessary hardware. Thus, the technical solution according to the embodiments of the present disclosure may be embodied in the form of a software product, which may be stored in a non-volatile storage medium (may be a CD-ROM, a U-disk, a mobile hard disk, etc.) or on a network, including several instructions to cause a computing device (may be a personal computer, a server, a mobile terminal, or a network device, etc.) to perform the method according to the embodiments of the present disclosure.
Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure disclosed herein. This application is intended to cover any adaptations, uses, or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.
It is to be understood that the present disclosure is not limited to the precise arrangements and instrumentalities shown in the drawings, and that various modifications and changes may be effected without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims (11)
1. An inline implementation method, comprising:
acquiring configuration information, wherein the configuration information comprises classes with inline methods and corresponding inline methods; the inline method has inline annotation tags;
Obtaining a class file of the class with the inline method in the configuration information, and obtaining a method node of the inline method in the configuration information through a byte code control framework;
Generating a corresponding relation between the class with the inline method and a method node of the inline method;
Traversing a method instruction in a class file through a byte code control framework, and if the byte code instruction in the method instruction is a calling instruction and the class and the method corresponding to the method instruction belong to the corresponding relation, acquiring a method node corresponding to the method instruction, and replacing the method instruction by the method node;
wherein the method further comprises: inquiring the inline method with the inline annotation mark through an annotation processor, and determining the class with the inline method according to the inline method; and generating the configuration information by taking the class name of the class with the inline method as an index and taking the method signature of one or more inline methods contained in the class with the inline method as a value.
2. The method of claim 1, wherein the generating the correspondence between the class with inline method and method nodes of the inline method comprises:
And storing Map data by taking class names of the classes with the inline methods as indexes and taking method nodes of one or more inline methods contained in the classes with the inline methods as values.
3. The method according to claim 2, wherein if the bytecode instruction in the method instruction is a call instruction and the class and the method corresponding to the method instruction belong to the correspondence, acquiring a method node corresponding to the method instruction, and replacing the method instruction with the method node, includes:
judging whether a byte code instruction in the method instruction is a calling instruction or not, and judging that the class name and the method name behind the method instruction belong to stored Map data;
If yes, inquiring a method node corresponding to the method instruction in the stored Map data according to the class name and the method name behind the method instruction, and further replacing the method instruction by using an instruction in the inquired method node.
4. A method according to any one of claims 1 to 3, wherein the inline method is a static method.
5. An inline implementation apparatus, comprising:
a configuration module configured to obtain configuration information, the configuration information including classes with inline methods and corresponding inline methods; the inline method has inline annotation tags;
the acquisition module is configured to acquire a class file of the class with the inline method in the configuration information, and acquire a method node of the inline method in the configuration information through a byte code control framework;
A generation module configured to generate a correspondence between the class with the inline method and a method node of the inline method;
The replacing module is configured to traverse the method instructions in the class file through the byte code control framework, and if the byte code instructions in the method instructions are calling instructions and the classes and the methods corresponding to the method instructions belong to the corresponding relations, the method nodes corresponding to the method instructions are obtained, and the method instructions are replaced by the method nodes;
Wherein the configuration module is configured to: inquiring the inline method with the inline annotation mark through an annotation processor, and determining the class with the inline method according to the inline method; and generating the configuration information by taking the class name of the class with the inline method as an index and taking the method signature of one or more inline methods contained in the class with the inline method as a value.
6. The apparatus of claim 5, wherein the generation module is configured to:
And storing Map data by taking class names of the classes with the inline methods as indexes and taking method nodes of one or more inline methods contained in the classes with the inline methods as values.
7. The apparatus of claim 6, wherein the replacement module is configured to:
Judging whether a byte code instruction in the method instruction is a calling instruction or not, and judging that the class name and the method name behind the method instruction belong to stored Map data; if yes, inquiring a method node corresponding to the method instruction in the stored Map data according to the class name and the method name behind the method instruction, and further replacing the method instruction by using an instruction in the inquired method node.
8. The apparatus according to any one of claims 5 to 7, wherein the inline process is a static process.
9. An electronic device, comprising:
A processor;
a memory for storing the processor-executable instructions;
Wherein the processor is configured to execute the instructions to implement the inline implementation of any of claims 1 to 4.
10. A computer readable storage medium, which when executed by a processor of an electronic device, causes the electronic device to perform the inline implementation of any of claims 1 to 4.
11. A computer program product comprising computer programs/instructions which, when executed by a processor, implement the inline implementation of any of claims 1 to 4.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111272867.9A CN114003317B (en) | 2021-10-29 | 2021-10-29 | Inline implementation method and device, electronic equipment, storage medium and program product |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111272867.9A CN114003317B (en) | 2021-10-29 | 2021-10-29 | Inline implementation method and device, electronic equipment, storage medium and program product |
Publications (2)
Publication Number | Publication Date |
---|---|
CN114003317A CN114003317A (en) | 2022-02-01 |
CN114003317B true CN114003317B (en) | 2024-09-20 |
Family
ID=79925297
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202111272867.9A Active CN114003317B (en) | 2021-10-29 | 2021-10-29 | Inline implementation method and device, electronic equipment, storage medium and program product |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114003317B (en) |
Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109032572A (en) * | 2017-06-08 | 2018-12-18 | 阿里巴巴集团控股有限公司 | A method of the JAVA program technic based on bytecode is inline |
Family Cites Families (11)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6760907B2 (en) * | 1998-06-30 | 2004-07-06 | Sun Microsystems, Inc. | Code generation for a bytecode compiler |
KR100818919B1 (en) * | 2006-02-24 | 2008-04-03 | 삼성전자주식회사 | Method for invoking method and java virtual machine using the same |
JP5466601B2 (en) * | 2010-08-31 | 2014-04-09 | インターナショナル・ビジネス・マシーンズ・コーポレーション | Code generation method, system and program |
US20150199186A1 (en) * | 2011-10-07 | 2015-07-16 | Google Inc. | Implement inline cache using a data array |
US10908886B2 (en) * | 2016-07-12 | 2021-02-02 | Oracle International Corporation | Accessing a migrated member in an updated type |
CN108614702B (en) * | 2016-12-28 | 2022-02-11 | 阿里巴巴集团控股有限公司 | Byte code optimization method and device |
CN108021370B (en) * | 2017-12-26 | 2020-05-12 | 网易(杭州)网络有限公司 | Byte code optimization method and device, storage medium, processor and terminal |
CN108614960B (en) * | 2018-05-11 | 2020-06-16 | 西北大学 | JavaScript virtualization protection method based on front-end byte code technology |
CN111008022B (en) * | 2019-12-04 | 2023-12-12 | 浙江大搜车软件技术有限公司 | Relationship diagram generation method, device, computer equipment and storage medium |
CN111078279B (en) * | 2019-12-20 | 2023-06-16 | 抖音视界有限公司 | Method, device, equipment and storage medium for processing byte code file |
CN111796865B (en) * | 2020-06-28 | 2024-04-16 | 北京字节跳动网络技术有限公司 | Byte code file modification method, device, terminal equipment and medium |
-
2021
- 2021-10-29 CN CN202111272867.9A patent/CN114003317B/en active Active
Patent Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109032572A (en) * | 2017-06-08 | 2018-12-18 | 阿里巴巴集团控股有限公司 | A method of the JAVA program technic based on bytecode is inline |
Also Published As
Publication number | Publication date |
---|---|
CN114003317A (en) | 2022-02-01 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
EP3433768A1 (en) | Efficient state machines for real-time dataflow programming | |
CN108090351B (en) | Method and apparatus for processing request message | |
CN107391528B (en) | Front-end component dependent information searching method and equipment | |
CN111240772B (en) | Block chain-based data processing method, device and storage medium | |
CN115599386A (en) | Code generation method, device, equipment and storage medium | |
CN109063059A (en) | User behaviors log processing method, device and electronic equipment | |
CN108845864A (en) | A kind of JVM rubbish recovering method and device based on spring frame | |
US8607201B2 (en) | Augmenting visualization of a call stack | |
CN116450723A (en) | Data extraction method, device, computer equipment and storage medium | |
CN114003317B (en) | Inline implementation method and device, electronic equipment, storage medium and program product | |
CN112346774A (en) | Method and device for generating application installation package | |
CN114626352B (en) | Report automatic generation method, device, computer equipment and storage medium | |
CN115640279A (en) | Method and device for constructing data blood relationship | |
CN116010461A (en) | Data blood relationship analysis method and device, storage medium and electronic equipment | |
CN112416875B (en) | Log management method, device, computer equipment and storage medium | |
CN114625372A (en) | Automatic component compiling method and device, computer equipment and storage medium | |
CN114398152A (en) | Interface simulation service calling method and device | |
CN113419738A (en) | Interface document generation method and device and interface management equipment | |
Habibi et al. | Generating test as a web service (TaaWS) through a method-based attribute grammar | |
US20150324333A1 (en) | Systems and methods for automatically generating hyperlinks | |
CN111580799A (en) | Domain specific language script assembling method and system | |
CN112527880B (en) | Method, device, equipment and medium for collecting metadata information of big data cluster | |
Cheney | Provenance, XML and the scientific web | |
CN117827269A (en) | Computer application program packaging and analyzing method and system | |
CN114625377A (en) | Frame item conversion method, frame item conversion device, equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |