Dynamic Class Redefinition in Java Application Servers
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
The existing Java development cycle requires developers to edit, build, and deploy code before testing changes, which is time-consuming and loses non-serializable state data and running Servlets, Filters, and Listeners.
Innovation Solution
The system employs a ClassFileTransformer function that maintains the original shape of redefinable classes by using synthetic methods and fields, allowing dynamic redefinition of class files without altering their behavior or appearance to outside code, and utilizes a metadata structure to index and manage class members across versions.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Reliability
If developers use traditional Java build and deploy cycle to make changes to deployed application, then code changes can be tested, but development time increases significantly
Solution Approach 1:
The system dynamically redefines class files at runtime without requiring a redeploy cycle. The ClassFileTransformer dynamically transforms class bytes to incorporate changes, and the redefinable ClassLoader loads and replaces class definitions on-the-fly, enabling continuous operation during development iterations.
Solution Approach 2:
The patent introduces intermediary components including the ClassFileTransformer that acts as a mediator between source code changes and the running application, and the metadata structure that mediates between old and new class versions, allowing changes to be applied without full redeployment.
2Reliability
If traditional deploy cycle is used to update class files, then code changes are applied, but non-serializable state data and running Servlets, Filters, and Listeners are lost
Solution Approach 1:
The system performs preliminary actions by maintaining metadata about class members before redefinition occurs. The metadata structure pre-identifies fields, methods, and other class elements, allowing the system to preserve state data and maintain running components during the transition from old to new class versions.
Solution Approach 2:
The patent discards only the class definition bytes while recovering and preserving the runtime state data, instantiated objects, and active Servlets, Filters, and Listeners. The metadata structure enables selective discarding of outdated class information while recovering valuable runtime state.
3Productivity
If class files are redefined dynamically, then development time is reduced, but Java's class shape requirements must be maintained
Solution Approach 1:
The system creates copies of class definitions in the metadata structure that mirror the original class shape. These copied class member definitions allow the system to manage dynamic redefinition while presenting a stable, unchanging class shape interface to the rest of the application, satisfying Java's requirements.
Data Source
AI summary
Disclosed herein is a system and method for dynamically redefining class files in a Java-based development environment. The existing development cycle in Java generally requires developers to edit, build, and deploy before they can test changes to the code. This process can be quite time consuming. There is a need for dynamically redefining and testing class files in a development environment without a significant time delay or loss of data. In one embodiment, when a developer modifies the class definition a ClassFileTransformer function is used to maintain the original shape of a redefinable class, i.e. its declared fields and methods, without affecting the redefined class' behavior or appearance to outside code.


