IP Library Granted Patent US 9,378,034
Granted Patent B2
US 9,378,034 · App. 14/137,858 · Granted Jun 28, 2016

Dynamic bytecode modification of classes and class hierarchies

Inventors: Peter K. Matov (Sofia, BG); Alexandrina Ivanova (Sofia, BG)
Assignee: SAP SE
G06F9/45525
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 9,378,034
App. No.
14/137,858
Granted
Jun 28, 2016
Kind
B2
Abstract

Various systems and methods for dynamic bytecode modification of classes and class hierarchies are described herein. In various embodiments, a Java® agent is received at a launch of a Java® Virtual Machine (JVM®), the agent implementing a premain method, the premain method accepting a reference to an instrumentation instance. The instrumentation reference is then stored, a deployment container is initialized, and, within the deployment container, an instance of an application is created. The instrumentation reference is then provided to the application instance. A class transformer is then retrieved from a persistence provider, and the class transformer is wrapped by an O.R. Persistence Container Class Transformer, which is then registered with the instrumentation instance. A class to be transformed is passed to the class transformer, which dynamically modifies the bytecode of the class before the class is loaded by the JVM®.

Claims (56)

1. A method comprising:

receiving an agent at a launch of a Java® Virtual Machine (JVM®), the agent including a field for storing a reference to an instrumentation instance and implementing a premain method, the premain method accepting the reference to the instrumentation instance;

storing the instrumentation reference;

initializing a deployment container;

creating an instance of an application within the deployment container;

providing the instrumentation reference to the application instance;

retrieving a class transformer from a persistence provider;

registering the class transformer with the instrumentation instance;

passing bytecode of a class to be transformed to the class transformer;

dynamically modifying, using the class transformer, the bytecode of the class before the class is loaded by the JVM® when the class is to be loaded by a class loader other than a regular class loader of the application, wherein the modified class, after being loaded by the JVM®, is arranged to execute according to its modified bytecode.

2. The method of claim 1 , wherein the deployment container is one of an O.R. (Object-Relational) Persistence Deployment Container, an EJB® (Enterprise JavaBeans®) Deployment Container, and a Web Deployment Container.

3. The method of claim 1 , wherein the persistence provider is a Java® Persistence Application Programming Interface (JPA) Persistence Provider.

4. The method of claim 3 , further comprising:

instantiating an entity manager factory during deployment of the application only when dynamic bytecode modification is enabled and when the JPA Persistence Provider is a not the default provider.

5. The method of claim 1 , further comprising:

checking, prior to the dynamic modification, whether the class to be modified is to be loaded by a heavy class loader of the application.

6. The method of claim 1 , further comprising:

instantiating, using lazy initialization, an entity manager factory upon receiving a client request when the JPA provider is the default provider.

7. A non-transitory computer-readable storage medium, with

instructions stored thereon, which when executed by at least one processor of a computing device, cause the computing device to perform operations comprising:

receiving an agent at a launch of a Java® Virtual Machine (JVM®), the agent including a field for storing a reference to an instrument instance and implementing a premain method, the premain method accepting a reference to an instrumentation instance;

storing the instrumentation reference;

initializing a deployment container;

creating an instance of an application within the deployment container;

providing the instrumentation reference to the application instance;

retrieving a class transformer from a persistence provider;

registering the class transformer with the instrumentation instance;

passing bytecode of a class to be transformed to the class transformer;

dynamically modifying, using the class transformer, the bytecode of the class before the class is loaded by the JVM® when the class is to be loaded by a class loader other than a regular class loader of the application, wherein the modified class, after being loaded by the JVM®, is arranged to execute according to its modified bytecode.

8. The non-transitory computer-readable storage medium of claim 7 , wherein the deployment container is one of an O.R. (Object-Relational) Persistence Deployment Container, an EJB® (Enterprise JavaBeans®) Deployment Container, and a Web Deployment Container.

9. The non-transitory computer-readable storage medium of claim 7 , wherein the persistence provider is a Java® Persistence Application Programming Interface (JPA) Persistence Provider.

10. The non-transitory computer-readable storage medium of claim 7 , with further instructions stored thereon which, when executed by the processor, cause the computing device to:

check, prior to the dynamic modification, whether the class to be modified is to be loaded by a heavy class loader of the application.

11. The non-transitory computer-readable storage medium of claim 7 , with further instructions stored thereon which, when executed by the processor, cause the computing device to:

instantiate an entity manager factory during deployment of the application only when dynamic bytecode modification is enabled and when the JPA Persistence Provider is a not the default provider.

12. The non-transitory computer-readable storage medium of claim 7 , with further instructions stored thereon which, when executed by the processor, cause the computing device to:

instantiate, using lazy initialization, an entity manager factory upon receiving a client request when the JPA provider is the default provider.

13. A system, comprising:

a processor and a memory device operatively coupled via a bus; and instructions stored in the memory device and executable by the processor to:

receive an agent at a launch of a Java® Virtual Machine (JVM®), the agent including a field for storing a reference to an instrument instance and implementing a premain method, the premain method accepting a reference to an instrumentation instance;

store the instrumentation reference;

initialize a deployment container;

create an instance of an application within the deployment container;

provide the instrumentation reference to the application instance;

retrieve a class transformer from a persistence provider;

register the class transformer with the instrumentation instance;

pass bytecode of a class to be transformed to the class transformer;

dynamically modify, using the class transformer, the bytecode of the class before the class is loaded by the JVM® when the class is to be loaded by a class loader other than a regular class loader of the application, wherein the modified class, after being loaded by the JVM®, is arranged to execute according to its modified bytecode.

14. The system of claim 13 , wherein the deployment container is one of an O.R. (Object-Relational) Persistence Deployment Container, an EJB® (Enterprise JavaBeans®) Deployment Container, and a Web Deployment Container.

15. The system of claim 13 , wherein the persistence provider is a Java® Persistence Application Programming Interface (JPA) Persistence Provider.

16. The system of claim 13 , instructions stored in the memory device and executable by the processor to:

check, prior to the dynamic modification, whether the class to be modified is to be loaded by a heavy class loader of the application.

17. The system of claim 13 , instructions stored in the memory device and executable by the processor to:

instantiate an entity manager factory during deployment of the application only when dynamic bytecode modification is enabled and when the JPA Persistence Provider is a not the default provider.

18. The system of claim 13 , instructions stored in the memory device and executable by the processor to:

instantiate, using lazy initialization, an entity manager factory upon receiving a client request when the JPA provider is the default provider.

Assignments (2)
CHANGE OF NAME Recorded Aug 26, 2014
From: SAP AG
To: SAP SE
Reel/Frame 033625/0223 →
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Dec 20, 2013
From: MATOV, PETER K.; IVANOVA, ALEXANDRINA
To: SAP AG
Reel/Frame 031835/0177 →
Continuity (2)
Provisional Application 61824203 · May 16, 2013
Related Publication 20140344792A1 · Nov 20, 2014