JEP 159: Enhanced Class Redefinition

OwnerThomas Wuerthinger
Created2011/07/27 20:00
Updated2014/09/29 11:26
TypeFeature
StatusSubmitted
Componenthotspot / svc
ScopeImplementation
Discussionserviceability dash dev at openjdk dot java dot net
Priority4
Reviewed byChristian Thalinger, Coleen Phillimore, Douglas Simon, John Rose, Mikael Vidstedt, Staffan Friberg, Tim Quinn
Issue8046149
Relates to4910812: Enhance Hot Code Replacement

Summary

Enhance the class redefinition capabilities of the HotSpot VM to support, at runtime, the addition of supertypes and the addition and removal of methods and fields.

Non-Goals

Introduction of additional API in JVMTI, JDWP, JDI or the java.lang.instrument package is not a goal. The new mechanism will be accessed using the existing class redefinition interfaces.

Motivation

The current class redefinition capabilities only allow the swapping of method bodies, which is a severe restriction. The proposed feature relaxes the restriction and improves the productivity of Java programmers during development of an application by removing the need to restart an application after changes. The benefit is particularly high when developing on an application server or for applications with long startup times.

Description

The proposed feature enhances the implementation of the JVMTI class redefinition functionality in the HotSpot VM. It does not modify any Java APIs or library/JVM interfaces.

In particular the proposed enhancement to class redefinition includes the ability to modify classes at run time by:

The behavior of the current mechanism that swaps method bodies is unaffected. Removing supertypes from a class remains prohibited.

Adding or removing instance fields affects all existing instances of a class. Newly inserted fields are initialized with 0, null or false according to their type. Calling a method after it was deleted or accessing a field after it was deleted results in a NoSuchMethodError or NoSuchFieldError respectively.

There are several publications about the technical details of the proposed implementation:

Additionally, there is an existing prototype, the Dynamic Code Evolution VM, that fully supports the proposed features and can be downloaded in source and binary form.

Testing

In addition to the current class redefinition tests, there need to be new tests for the enhanced functionality (i.e., tests that add/remove fields and methods and add supertypes).

Impact

This proposal only impacts the implementation of the HotSpot VM and does not impact other JDK components. There is a small impact on the API documentation for the class redefinition functionality in JVMTI, JDWP, JDI, and the java.lang.instrument API.