Dynamic AOP implementation method and device based on bytecode injection

Through the dynamic AOP method based on bytecode injection, bytecode insertion technology and global class converter, the dynamic AOP access without service is realized, which solves the serious problem of service coupling in the existing technology and improves the Stability and matching efficiency of slit point implantation.

CN118567625BActive Publication Date: 2025-01-07ANT GROUP CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411037523.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-30
Publication Date
2025-01-07
Estimated Expiration
2044-07-30

AI Technical Summary

Technical Problem

The existing AOP technology is seriously coupled with the business when implementing dynamic agents, requiring business participation, resulting in infringement and stability problems.

Method used

Using dynamic AOP method based on bytecode injection, using JVMTI and bytecode instrumentation technology, a unique bytecode identifier is generated at the injection point of the target class file through a preset bytecode template, and the facet program is injected into the target class. Files realize business-in-aware code entry, and maintain the mapping relationship between injection points and section programs through global class converters to ensure the stability of section implantation.

Benefits of technology

It realizes dynamic AOP access without service perception, avoids business coupling, improves the stability and matching efficiency of point-cutting implantation, and solves the serious problem of traditional AOP and business coupling.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118567625B_ABST
    Figure CN118567625B_ABST
Patent Text Reader

Abstract

The embodiment of the present application discloses a dynamic AOP implementation method based on bytecode injection, which is applicable to the ranger framework of the Java virtual machine, including: for at least one target business module accessed by the ranger framework, obtaining the aspect program to be injected submitted by the target business module; determining the target class file corresponding to the target business module and at least one injection point of the target class file; calling a preset bytecode template, generating a unique bytecode identifier at at least one injection point of the target class file, and associating the injection point with the aspect program to be injected through the bytecode identifier; injecting the aspect program to be injected into the target class file according to the association relationship between the bytecode identifier and the aspect program to be injected. This method uses business-unaware bytecode plugging technology to access AOP to achieve business-unaware code entry.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a dynamic AOP implementation method and device based on bytecode injection. Background Art

[0002] AOP (Aspect Oriented Programming) refers to aspect-oriented programming. It is a technology that can dynamically and uniformly add functions to a program without modifying the source code through pre-compilation and runtime dynamic proxy. In existing solutions, AOP is usually accessed through SDK, and the AOP logic is implemented through dynamic proxy. This method usually requires business participation and is highly coupled with the business. Summary of the invention

[0003] One or more embodiments of this specification provide a method, device, storage medium and electronic device for implementing dynamic AOP based on bytecode injection to solve the problems existing in the related art.

[0004] In a first aspect, a dynamic AOP implementation method based on bytecode injection is provided, which is applicable to a ranger framework of a Java virtual machine, and the method comprises:

[0005] For at least one target business module accessed by the ranger framework, obtain the aspect program to be injected submitted by the target business module;

[0006] Determine a target class file corresponding to the target business module and at least one injection point of the target class file;

[0007] Calling a preset bytecode template, generating a unique bytecode identifier at the at least one injection point of the target class file, and associating the injection point with the aspect program to be injected through the bytecode identifier;

[0008] According to the association relationship between the bytecode identifier and the aspect program to be injected, the aspect program to be injected is injected into the target class file.

[0009] As an optional implementation manner of the method of the first aspect, associating the injection point with the aspect program to be injected through the bytecode identifier specifically includes:

[0010] The bytecode template is called to match the injection point with the cut point of the aspect program to be injected, so as to implant the cut point of the aspect program to be injected into the target class file.

[0011] As an optional implementation of the method described in the first aspect, the ranger framework also maintains a mapping relationship between the aspect program to be injected submitted by the at least one target business module and the injection point of the corresponding target class file; a global class converter is registered in the ranger framework, and the global class converter is configured to inject the aspect program to be injected into the corresponding target class file according to the mapping relationship between the aspect program to be injected submitted by the at least one target business module and the injection point of the corresponding target class file.

[0012] Specifically, the mapping relationship between the aspect program to be injected submitted by the at least one target business module and the injection point of the corresponding target class file specifically includes:

[0013] a mapping relationship between the cut point of the aspect program to be injected and the injection point of the target class file corresponding to the target business module; and

[0014] The mapping relationship between the injection point type and injection method of the target class file corresponding to the target business module.

[0015] More specifically, the ranger framework maintains a mapping relationship between the aspect program to be injected submitted by the at least one target business module and the injection point of the corresponding target class file, specifically including:

[0016] In response to the access of the target business module, performing structural analysis on the target class file corresponding to the business module to determine the injection point type corresponding to the target class file;

[0017] Determine the injection method according to the injection point type corresponding to the target class file;

[0018] Constructing a mapping relationship between the injection point type and the injection method corresponding to the target class file;

[0019] In response to the target business module submitting the aspect program to be injected, determining a matching relationship between the aspect point of the aspect program to be injected and the injection point of the target class file corresponding to the target business module;

[0020] Construct a mapping relationship between the cut point of the aspect program to be injected and the injection point of the target class file corresponding to the target business module.

[0021] Specifically, calling a preset bytecode template, generating a unique bytecode identifier at the at least one injection point of the target class file, and associating the injection point with the aspect program to be injected through the bytecode identifier, specifically includes:

[0022] According to the mapping relationship between the aspect program to be injected submitted by the target business module and the injection point of the corresponding target class file, the bytecode template is called to generate a unique bytecode identifier at at least one injection point of the target class file, and the at least one injection point is associated with the aspect program to be injected through the bytecode identifier.

[0023] In a second aspect, a dynamic AOP implementation device based on bytecode injection is provided, which is applicable to a ranger framework of a Java virtual machine, and the device includes:

[0024] A data acquisition module, configured to acquire, for at least one target business module accessed by the ranger framework, a slice program to be injected submitted by the target business module;

[0025] an association module configured to determine a target class file corresponding to the target business module and at least one injection point of the target class file; call a preset bytecode template to generate a unique bytecode identifier at the at least one injection point of the target class file, and associate the injection point with the aspect program to be injected through the bytecode identifier;

[0026] The injection module is configured to inject the aspect program to be injected into the target class file according to the association relationship between the bytecode identifier and the aspect program to be injected.

[0027] As an optional implementation of the device described in the second aspect, the association module is specifically used to call the bytecode template to match the injection point with the cut-off point of the aspect program to be injected, so as to implant the cut-off point of the aspect program to be injected into the target class file.

[0028] As an optional implementation of the device of the second aspect, the ranger framework further maintains a mapping relationship between the aspect program to be injected submitted by the at least one target business module and the injection point of the corresponding target class file; a global class converter is registered in the ranger framework;

[0029] The injection module is specifically used to call the global class converter, and inject the aspect program to be injected into the corresponding target class file according to the mapping relationship between the aspect program to be injected submitted by the at least one target business module and the injection point of the corresponding target class file.

[0030] Specifically, in another optional implementation manner of the device according to the second aspect, the Java virtual machine is specifically configured as follows:

[0031] According to the mapping relationship between the aspect program to be injected submitted by the target business module and the injection point of the corresponding target class file, the bytecode template is called to generate a unique bytecode identifier at at least one injection point of the target class file, and the at least one injection point is associated with the aspect program to be injected through the bytecode identifier.

[0032] In a third aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the above-mentioned dynamic AOP implementation method based on bytecode injection is implemented.

[0033] In a fourth aspect, an electronic device is provided, including:

[0034] one or more processors; and

[0035] A memory associated with the one or more processors, the memory being used to store program instructions, wherein when the program instructions are read and executed by the one or more processors, the specific steps of the above-mentioned dynamic AOP implementation method based on bytecode injection are executed.

[0036] The beneficial effect of the dynamic AOP implementation method based on bytecode injection described in one or more embodiments of this specification is that the method uses the business-unaware bytecode plugging technology to access AOP and implement business-unaware code entry. At the same time, in order to avoid the business-unaware bytecode plugging technology from causing damage to the business, the method implements the pointcut implantation through a bytecode template, and only implants the bytecode identifier of the injection point corresponding to the pointcut each time, and associates the aspect program to be injected through the bytecode identifier, thereby ensuring the stability of the pointcut implantation logic.

[0037] The dynamic AOP implementation device based on bytecode injection, storage medium and electronic device described in the embodiments of this specification also have the above-mentioned beneficial effects. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0039] Figure 1 The flowchart of a dynamic AOP implementation method based on bytecode injection described in an embodiment of this specification is exemplarily shown.

[0040] Figure 2The schematic diagram of the structure of a ranger framework described in the embodiment of this specification is exemplarily shown.

[0041] Figure 3 The structure diagram of a bytecode injection-based AOP dynamic implementation device described in an embodiment of this specification is exemplarily shown.

[0042] Figure 4 The structural diagram of an electronic device described in an embodiment of this specification is exemplarily shown. DETAILED DESCRIPTION

[0043] First of all, it should be noted that the terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "the" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates otherwise.

[0044] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Therefore, it should be recognized by those skilled in the art that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0045] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.

[0046] At present, AOP usually accesses class files in the form of SDK, and implements AOP logic through dynamic proxy. This method usually requires business participation and is highly coupled with business.

[0047] In view of this, this specification provides a dynamic AOP implementation solution based on bytecode injection, which uses JVMTI and bytecode instrumentation technology to implement dynamic AOP.

[0048] In order to make the purpose, technical solutions and advantages of this specification more clear, the technical solutions of this specification will be clearly and completely described below in combination with the specific embodiments of this specification and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of this specification, not all of them. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this specification.

[0049] The technical solutions provided by the embodiments of this specification are described in detail below in conjunction with the accompanying drawings.

[0050] Please refer to Figure 1 , Figure 1 The present invention is a flowchart of a dynamic AOP implementation method based on bytecode injection proposed in one or more embodiments of this specification. Figure 1 The method shown can be executed by a dynamic AOP implementation device based on bytecode injection, but is not limited to this device.

[0051] like Figure 1 As shown, the above-mentioned dynamic AOP implementation method based on bytecode injection is applicable to the ranger framework of the Java virtual machine, and the method includes steps S100-S106.

[0052] S100: For at least one target business module accessed by the ranger framework, obtain the aspect program to be injected submitted by the target business module.

[0053] In Java, SPI (Service Provider Interface) is a mechanism for implementing pluggable applications. The key features of SPI are pluggability and dynamic loading. Through SPI, we can dynamically load specific service implementations at runtime. Therefore, the SPI interface of the above target business module can be defined in Java in advance, and then the target business module provided by the service provider can be discovered through the SPI interface, so as to connect the target business module to the ranger framework. The target business module can be provided by the service provider in the form of an implementation class.

[0054] The above-mentioned target business module is a business module with code injection requirements. After accessing the target business module in the ranger framework of the Java virtual machine, the aspect program to be injected submitted by the target business module can be obtained, and then the target class file corresponding to the target business module can be determined according to the aspect program to be injected.

[0055] S102: Determine a target class file corresponding to a target business module and at least one injection point of the target class file.

[0056] The JoinPoint refers to the place in the target class file where the injection can be done. Specifically, it refers to the moment when the target class file runs to a specific section of code during the execution process. Before performing aspect program injection, it is necessary to determine the place in the target class file where the injection can be done, that is, the JoinPoint.

[0057] After obtaining the aspect program to be injected submitted by the target business module and the target class file corresponding to the target business module, the injection point corresponding to the target class file can be determined.

[0058] S104: calling a preset bytecode template, generating a unique bytecode identifier at at least one injection point of the target class file, and associating the injection point with the aspect program to be injected through the bytecode identifier.

[0059] Aspect programs are a collection of advices and pointcuts. Pointcuts are used to match and locate join points. Pointcuts can be a function signature, an interface, an annotation, or an expression with wildcards. Pointcuts can be embedded in different locations of functions in the target class file, such as atBefore, atReturn, and atThrow. Advice refers to the execution logic after the pointcut is injected, and supports callbacks at the entry and exit of the injection method.

[0060] Before the aspect program is injected, the injection point needs to be matched with the aspect program's pointcut through a matching interface (usually a Method Matcher interface) to implement the implantation of the aspect program's pointcut. A pointcut has a matching interface, and a matching interface can match multiple injection points, which means that there is a many-to-many relationship between the injection point and the pointcut.

[0061] In this step, by using the bytecode stubbing technology, before the Java virtual machine loads the above-mentioned target class file, the aspect program to be injected is injected into the target class file to modify the target class file.

[0062] Since the business-unaware bytecode instrumentation technology may cause certain damage to the business, in order to control the risk, the ranger framework calls a preset bytecode template to generate a unique bytecode identifier at at least one injection point in the target class file, and associates the injection point with the aspect program to be injected through the bytecode identifier.

[0063] Specifically, each time the ranger framework implants a pointcut, it implants a section of bytecode template code, which is mainly used to complete the registration of the pointcut, that is, to save the Class, Method, ClassLoader and other information of the pointcut to the injection point instance, so as to match the injection point of the target class file with the pointcut of the aspect program to be injected. At the same time, this section of bytecode template code will generate a unique PointId at the injection point of the target class file, that is, only the PointId is implanted each time, and the PointId is bound to the aspect program to be injected. The callback process of the pointcut is the execution process of the aspect program.

[0064] S106: Injecting the aspect program to be injected into the target class file according to the association relationship between the bytecode identifier and the aspect program to be injected.

[0065] Java supports setting multiple class transformers (i.e. ClassFileTransformer) during the class loading phase. Class transformers can implement bytecode injection before the class is loaded into the JVM. For each injection point, a new class transformer is created to implement class transformation. These class transformers use a chain structure to achieve the purpose of reweaving the class. Therefore, when transforming a class, chain matching weaving is required. By executing class transformers one by one to determine whether to transform, even the same injection point will be woven multiple times, resulting in a long time-consuming bytecode modification.

[0066] In order to solve the above-mentioned problem of Java in the class loading stage, in some implementations, the mapping relationship between the aspect program to be injected submitted by the above-mentioned at least one target business module and the injection point of the corresponding target class file can be maintained in the ranger framework. At the same time, a global class converter can be registered in the ranger framework of the Java virtual machine, and the aspect program to be injected can be injected into the corresponding target class file according to the mapping relationship between the aspect program to be injected submitted by the above-mentioned at least one target business module and the injection point of the corresponding target class file through this global class converter. In this way, the time consumption of bytecode modification can be shortened.

[0067] The mapping relationship between the aspect program to be injected submitted by at least one target business module and the injection point of the corresponding target class file specifically includes: the mapping relationship between the aspect program to be injected and the injection point of the target class file corresponding to the target business module; and the mapping relationship between the injection point type and injection method of the target class file corresponding to the target business module.

[0068] like Figure 2As shown, the ranger framework can maintain the mapping relationship between the aspect program to be injected submitted by the at least one target business module and the injection point of the corresponding target class file by creating a global mapping relationship set.

[0069] In an achievable implementation, the construction of the above-mentioned global mapping relationship set can be implemented in the following manner:

[0070] In response to the access of the target business module, a structure analysis is performed on the target class file corresponding to the business module to determine the injection point type corresponding to the target class file;

[0071] Determine the injection method according to the injection point type corresponding to the target class file;

[0072] Construct a mapping relationship between the injection point type and injection method corresponding to the target class file;

[0073] In response to the target business module submitting the aspect program to be injected, determining a matching relationship between the aspect point of the aspect program to be injected and the injection point of the target class file corresponding to the target business module;

[0074] Construct a mapping relationship between the cut point of the aspect program to be injected and the injection point of the target class file corresponding to the target business module.

[0075] Specifically, the above-mentioned injection point types include interface injection type and class injection type, and the injection methods include precise injection and fuzzy injection. For injection points of interface injection type, fuzzy injection method can be used; for injection points of class injection type, precise injection method can be used. The above-mentioned fuzzy injection refers to a method of injecting code into all target class files contained in the interface that inherits the target class file. The above-mentioned precise injection refers to a method of injecting code into the target class file based on the class name information corresponding to the target class file.

[0076] Before constructing the above-mentioned global mapping relationship set, it is necessary to determine the injection point type of the target class file.

[0077] In one embodiment, the injection point type corresponding to the target class file can be determined by performing structural analysis on the target class file. For example, the target class file can be determined based on the result of structural analysis whether it is a superclass inherited by other interfaces. If so, the injection point type of the target class file is determined to be an interface injection type, and then the injection method of the injection point of the target class file is determined to be a fuzzy injection method. If not, the injection point type of the target class file is determined to be a class injection type, and then the injection method of the injection point of the target class file is determined to be a precise injection method.

[0078] In another embodiment, the judgment can also be made directly by the class name of the target class file, that is, if the class name of the target class file is the class name concerned by the target business module, the injection point type of the target class file can be determined to be a class injection type, thereby determining to use a precise injection method. Otherwise, the injection point type of the target class file can be determined to be an interface injection type, thereby determining to use a fuzzy injection method. The above judgment of the class name of the target class file can be implemented using matching rules.

[0079] Through the mapping relationship between the aspect program to be injected submitted by the target business module maintained by the ranger framework and the injection point of the corresponding target class file, the global class converter can select different injection methods for different injection point types to inject the aspect program to be injected. In this way, the matching efficiency can be improved, and for scenarios with only precise injection, there is no need to even perform class structure analysis.

[0080] The above is a dynamic AOP implementation method based on bytecode injection described in one or more embodiments of this specification. This method implements the implantation of pointcuts through a bytecode template. Each time, only the bytecode identifier of the injection point corresponding to the pointcut is implanted. The bytecode identifier is used to associate the aspect program to be injected, thereby ensuring the stability of the pointcut implantation logic, thereby realizing dynamic AOP access without business perception and solving the problem of serious coupling between traditional AOP and business.

[0081] In addition, the method uses the ranger framework to create a global mapping relationship set to maintain the mapping relationship between the aspect program to be injected submitted by the at least one target business module and the injection point of the corresponding target class file, thereby realizing the exposure of AOP semantics.

[0082] Based on the same idea, this specification also provides a corresponding AOP dynamic implementation device based on bytecode injection, such as Figure 3 shown. Figure 3 The structure diagram of a bytecode injection-based AOP dynamic implementation device is schematically shown. It should be noted that the bytecode injection-based AOP dynamic implementation method described in one or more embodiments of the present application can rely on Figure 3 The device shown implements, but is not limited to, this device.

[0083] like Figure 3 As shown, the device comprises:

[0084] The data acquisition module 301 is configured to acquire the aspect program to be injected submitted by the target business module for at least one target business module accessed by the ranger framework.

[0085] The association module 302 is configured to determine the target class file corresponding to the target business module and at least one injection point of the target class file; call a preset bytecode template, generate a unique bytecode identifier at at least one injection point of the target class file, and associate the injection point with the aspect program to be injected through the bytecode identifier.

[0086] The injection module 303 is configured to inject the aspect program to be injected into the target class file according to the association relationship between the bytecode identifier and the aspect program to be injected.

[0087] Optionally, the above-mentioned data acquisition module 301 can pre-define the SPI interface of the above-mentioned target business module in the ranger framework, and then discover the target business module provided by the service provider through the SPI interface, thereby connecting the target business module to the ranger framework and obtaining the aspect program to be injected submitted by the target business module.

[0088] Optionally, the above-mentioned association module 302 can determine the target class file corresponding to the target business module according to the aspect program to be injected, and then determine the injection point corresponding to the target class file. Then, the preset bytecode template is called through the ranger framework to generate a unique bytecode identifier at at least one injection point of the target class file, and the injection point is associated with the aspect program to be injected through the bytecode identifier. Specifically, each time the ranger framework implants a pointcut, it implants a section of bytecode template code. This section of bytecode template code is mainly used to complete the registration of the pointcut, that is, to save the Class, Method, ClassLoader and other information of the pointcut to the injection point instance, so as to match the injection point of the target class file with the pointcut of the aspect program to be injected. At the same time, this section of bytecode template code will generate a unique PointId at the injection point of the target class file, that is, only PointId is implanted each time, and PointId is bound to the aspect program to be injected, and the callback process of the pointcut is the execution process of the aspect program.

[0089] Optionally, the above-mentioned ranger framework also maintains a mapping relationship between the aspect program to be injected submitted by at least one target business module and the injection point of the corresponding target class file. In addition, a global class converter is also registered in the ranger framework. Based on this, the above-mentioned association module 302 can call the bytecode template according to the mapping relationship between the aspect program to be injected submitted by the target business module maintained by the ranger framework and the injection point of the corresponding target class file, generate a unique bytecode identifier at at least one injection point of the target class file, and associate at least one injection point with the aspect program to be injected through the bytecode identifier. Then, the above-mentioned injection module 303 can specifically call the global class converter, and inject the aspect program to be injected into the corresponding target class file according to the mapping relationship between the aspect program to be injected submitted by at least one target business module and the injection point of the corresponding target class file.

[0090] Specifically, the mapping relationship between the aspect program to be injected submitted by at least one target business module and the injection point of the corresponding target class file specifically includes: the mapping relationship between the aspect program to be injected and the injection point of the target class file corresponding to the target business module; and the mapping relationship between the injection point type and injection method of the target class file corresponding to the target business module.

[0091] The ranger framework can maintain the mapping relationship between the aspect program to be injected submitted by at least one target business module and the injection point of the corresponding target class file by creating a global mapping relationship set.

[0092] In an achievable implementation, the construction of the above-mentioned global mapping relationship set can be implemented in the following manner:

[0093] In response to the access of the target business module, a structure analysis is performed on the target class file corresponding to the business module to determine the injection point type corresponding to the target class file;

[0094] Determine the injection method according to the injection point type corresponding to the target class file;

[0095] Construct a mapping relationship between the injection point type and injection method corresponding to the target class file;

[0096] In response to the target business module submitting the aspect program to be injected, determining a matching relationship between the aspect point of the aspect program to be injected and the injection point of the target class file corresponding to the target business module;

[0097] Construct a mapping relationship between the cut point of the aspect program to be injected and the injection point of the target class file corresponding to the target business module.

[0098] Specifically, the above-mentioned injection point types include interface injection type and class injection type, and the injection methods include precise injection and fuzzy injection. For injection points of interface injection type, fuzzy injection method can be used; for injection points of class injection type, precise injection method can be used. The above-mentioned fuzzy injection refers to a method of injecting code into all target class files contained in the interface that inherits the target class file. The above-mentioned precise injection refers to a method of injecting code into the target class file based on the class name information corresponding to the target class file.

[0099] Before building the above-mentioned global mapping relationship set, the ranger framework needs to determine the injection point type of the target class file.

[0100] In one embodiment, the injection point type corresponding to the target class file can be determined by performing structural analysis on the target class file. For example, the target class file can be determined based on the result of structural analysis whether it is a superclass inherited by other interfaces. If so, the injection point type of the target class file is determined to be an interface injection type, and then the injection method of the injection point of the target class file is determined to be a fuzzy injection method. If not, the injection point type of the target class file is determined to be a class injection type, and then the injection method of the injection point of the target class file is determined to be a precise injection method.

[0101] In another embodiment, the judgment can also be made directly by the class name of the target class file, that is, if the class name of the target class file is the class name concerned by the target business module, the injection point type of the target class file can be determined to be a class injection type, thereby determining to use a precise injection method. Otherwise, the injection point type of the target class file can be determined to be an interface injection type, thereby determining to use a fuzzy injection method. The above judgment of the class name of the target class file can be implemented using matching rules.

[0102] For the above-mentioned dynamic AOP implementation device based on bytecode injection, taking a module as an example of a software functional unit, the data acquisition module 301 may include code running on a computing instance. Among them, the computing instance may include at least one of a physical host (computing device), a virtual machine, and a container. Further, the above-mentioned computing instance may be one or more. For example, the data acquisition module 301 may include code running on multiple hosts / virtual machines / containers. Multiple hosts / virtual machines / containers for running the code may be distributed in the same region (region) or in different regions. Furthermore, multiple hosts / virtual machines / containers for running the code may be distributed in the same availability zone (AZ) or in different AZs, each AZ including a data center or multiple data centers with close geographical locations. Among them, usually a region may include multiple AZs.

[0103] Similarly, multiple hosts / virtual machines / containers used to run the code can be distributed in the same virtual private cloud (VPC) or in multiple VPCs. Usually, a VPC is set up in a region. For cross-region communication between two VPCs in the same region and between VPCs in different regions, a communication gateway needs to be set up in each VPC to achieve interconnection between VPCs through the communication gateway.

[0104] As an example of a hardware functional unit, the data acquisition module 301 may include at least one computing device, such as a server, etc. Alternatively, the data acquisition module 301 may also be a device implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The PLD may be a complex programmable logical device (CPLD), a field programmable gate array (FPGA), a generic array logic (GAL) or any combination thereof.

[0105] The multiple computing devices included in the data acquisition module 301 can be distributed in the same region or in different regions. The multiple computing devices included in the data acquisition module 301 can be distributed in the same AZ or in different AZs. Similarly, the multiple computing devices included in the data acquisition module 301 can be distributed in the same VPC or in multiple VPCs. The multiple computing devices can be any combination of computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, and GALs.

[0106] In other embodiments, the data acquisition module 301 can be used to execute any step in the above-mentioned dynamic AOP implementation method based on bytecode injection, the association module 302 can be used to execute any step in the above-mentioned dynamic AOP implementation method based on bytecode injection, and the injection module 303 can be used to execute any step in the above-mentioned dynamic AOP implementation method based on bytecode injection. The steps that the data acquisition module 301, the association module 302, and the injection module 303 are responsible for implementing can be specified as needed, and the data acquisition module 301, the association module 302, and the injection module 303 respectively implement different steps in the above-mentioned dynamic AOP implementation method based on bytecode injection to implement all the functions of the above-mentioned dynamic AOP implementation device based on bytecode injection.

[0107] In this implementation, the dynamic AOP implementation device based on bytecode injection can also be applied to computing devices such as computers and servers, or to a computing device cluster including at least one computing device, to implement the dynamic AOP implementation function based on bytecode injection.

[0108] In some embodiments, an electronic device is also provided. Figure 4 , the electronic device includes: a bus 401, a processor 402, a memory 403 and a communication interface 404. The processor 402, the memory 403 and the communication interface 404 communicate with each other through the bus 401. The electronic device can be a server or a terminal device. It should be understood that the present application does not limit the number of processors and memories in the electronic device.

[0109] The bus 401 may be a peripheral component interconnect (PCI) bus, or an extended industry standard architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4The use of only one line does not mean that there is only one bus or one type of bus. Bus 401 may include a path for transmitting information between various components of the electronic device (eg, processor 402, memory 403, and communication interface 404).

[0110] The processor 402 may include any one or more processors such as a CPU, a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).

[0111] The memory 403 may include a volatile memory, such as a random access memory (RAM). The memory 403 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid state drive (SSD).

[0112] The memory 403 stores executable program codes, and the processor 502 executes the executable program codes to respectively implement the functions of the aforementioned data acquisition module 301, the association module 302 and the injection module 303, that is, to implement the functions of the aforementioned dynamic AOP implementation device based on bytecode injection, thereby implementing the aforementioned dynamic AOP implementation method based on bytecode injection.

[0113] The communication interface 404 uses a transceiver module such as, but not limited to, a network interface card or a transceiver to implement communication between the electronic device and other devices or a communication network.

[0114] In some embodiments, a computer-readable storage medium is further provided, on which a computer program is stored. When the computer program is executed by a processor, the above-mentioned dynamic AOP implementation method based on bytecode injection is implemented.

[0115] The computer-readable storage medium may be any available medium that can be stored in an electronic device or a data storage device such as a data center that includes one or more available media. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a magnetic tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk). The computer-readable storage medium includes instructions that instruct the electronic device to execute the above-mentioned dynamic AOP implementation method based on bytecode injection.

[0116] It is to be understood that the structure illustrated in the embodiments of this specification does not constitute a specific limitation on the system of the embodiments of this specification. In other embodiments of the specification, the above system may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0117] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0118] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0119] It should be noted that the above examples are only specific embodiments of the present invention, and the present invention is obviously not limited to the above examples, and there are many similar variations. All variations directly derived or associated from the contents disclosed by the technicians in this field should fall within the protection scope of the present invention.

Claims

1. A dynamic AOP implementation method based on bytecode injection, applicable to the ranger framework of a Java virtual machine, the method comprising: For at least one target business module accessed by the ranger framework, obtain the aspect program to be injected submitted by the target business module; Determine a target class file corresponding to the target business module and at least one injection point of the target class file; Calling a preset bytecode template, generating a unique bytecode identifier at the at least one injection point of the target class file, and matching the injection point with the cut point of the aspect program to be injected through the bytecode identifier, so as to implant the cut point of the aspect program to be injected into the target class file; According to the association relationship between the bytecode identifier and the aspect program to be injected, the aspect program to be injected is injected into the target class file.

2. According to the method as described in claim 1, the ranger framework also maintains a mapping relationship between the aspect program to be injected submitted by the at least one target business module and the injection point of the corresponding target class file; a global class converter is registered in the ranger framework, and the global class converter is configured to inject the aspect program to be injected into the corresponding target class file according to the mapping relationship between the aspect program to be injected submitted by the at least one target business module and the injection point of the corresponding target class file.

3. The method according to claim 2, wherein the mapping relationship between the aspect program to be injected submitted by the at least one target business module and the injection point of the corresponding target class file specifically comprises: The mapping relationship between the cut point of the aspect program to be injected and the injection point of the target class file corresponding to the target business module; as well as, The mapping relationship between the injection point type and injection method of the target class file corresponding to the target business module.

4. The method according to claim 3, wherein the ranger framework maintains a mapping relationship between the aspect program to be injected submitted by the at least one target business module and the injection point of the corresponding target class file, specifically comprising: In response to the access of the target business module, performing structural analysis on the target class file corresponding to the business module to determine the injection point type corresponding to the target class file; Determine the injection method according to the injection point type corresponding to the target class file; Constructing a mapping relationship between the injection point type and the injection method corresponding to the target class file; In response to the target business module submitting the aspect program to be injected, determining a matching relationship between the aspect point of the aspect program to be injected and the injection point of the target class file corresponding to the target business module; Construct a mapping relationship between the cut point of the aspect program to be injected and the injection point of the target class file corresponding to the target business module.

5. The method according to claim 2, calling a preset bytecode template, generating a unique bytecode identifier at the at least one injection point of the target class file, and associating the injection point with the aspect program to be injected through the bytecode identifier, specifically comprises: According to the mapping relationship between the aspect program to be injected submitted by the target business module and the injection point of the corresponding target class file, the bytecode template is called to generate a unique bytecode identifier at at least one injection point of the target class file, and the at least one injection point is associated with the aspect program to be injected through the bytecode identifier.

6. A dynamic AOP implementation device based on bytecode injection, suitable for the ranger framework of a Java virtual machine, the device comprising: A data acquisition module is configured to acquire, for at least one target business module accessed by the ranger framework, a slice program to be injected submitted by the target business module; An association module, configured to determine a target class file corresponding to the target business module and at least one injection point of the target class file; Calling a preset bytecode template, generating a unique bytecode identifier at the at least one injection point of the target class file, and matching the injection point with the cut point of the aspect program to be injected through the bytecode identifier, so as to implant the cut point of the aspect program to be injected into the target class file; The injection module is configured to inject the aspect program to be injected into the target class file according to the association relationship between the bytecode identifier and the aspect program to be injected.

7. The device according to claim 6, wherein the ranger framework further maintains a mapping relationship between the aspect program to be injected submitted by the at least one target business module and the injection point of the corresponding target class file; a global class converter is registered in the ranger framework; The injection module is specifically used to call the global class converter, and inject the aspect program to be injected into the corresponding target class file according to the mapping relationship between the aspect program to be injected submitted by the at least one target business module and the injection point of the corresponding target class file.

8. The device according to claim 7, wherein the association module is specifically used for: According to the mapping relationship between the aspect program to be injected submitted by the target business module and the injection point of the corresponding target class file, the bytecode template is called to generate a unique bytecode identifier at at least one injection point of the target class file, and the at least one injection point is associated with the aspect program to be injected through the bytecode identifier.

9. A computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method according to any one of claims 1 to 5.

10. An electronic device, comprising: one or more processors; as well as A memory associated with the one or more processors, the memory being used to store program instructions, wherein the program instructions, when read and executed by the one or more processors, execute the specific steps of the method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Java bytecode injection method and device, electronic equipment and storage medium

    CN115904611A