@Unloadable Class defination (original) (raw)

Daniel Cheng j16sdiz at gmail.com
Tue Mar 24 08:47:59 PDT 2009


AUTHOR(S): Daniel Cheng (aka SDiZ)

OVERVIEW

Introduce a @Unloadable annotation to allow a class to be unloaded even if the ClassLoader is still accessible.

FEATURE SUMMARY:

Introduce a @Unloadable annotation to allow a class to be unloaded even if the ClassLoader is still accessible. This allow opt-in Classes to be optionally unloaded in memory constrained environment.

MAJOR ADVANTAGE:

Developer may define some class as @Unloadable can be unloaded when needed.

MAJOR BENEFIT:

Currently, VM are not allow to unload Class with reachable ClassLoader, this is required for "static variable" to be keep. But this means Class have to keep in memory even if the class is rarely used. Sometimes, the value static variable can be recreated at any time,

MAJOR DISADVANTAGE:

Not I am aware of. Note: This proposal only relax the language specification level to allow VM to unload class annotated with @Unloadable. The VM changes are optional, and is not expect in JDK7.

ALTERNATIVES:

Use micro-ClassLoader for classes. This is very hard to done right.

EXAMPLES

SIMPLE EXAMPLE:

@Unloadable class A {}

ADVANCED EXAMPLE:

@Unloadable class { static int i = 0; static int get() { return i++; // the value of get() may reset to zero, if the class have been reloaded. } }

DETAILS

SPECIFICATION: JLS (3rd Ed.) Section - 12.7 Unloading of Classes and Interfaces

Original text:

An implementation of the Java programming language may unload classes. A class or interface may be unloaded if and only if its defining class loader may be reclaimed by the garbage collector as discussed in §12.6. Classes and interfaces loaded by the bootstrap loader may not be unloaded. Here is the rationale for the rule given in the previous paragraph: [...]

New text:

An implementation of the Java programming language may unload classes. A class or interface may be unloaded if and only if: 1) its defining class loader may be reclaimed by the garbage collector as discussed in §12.6; or 2) it is annotated with @Unloadable annotation (§9.6) Classes and interfaces loaded by the bootstrap loader may not be unloaded. Here is the rationale for the rule given in the previous paragraph: [...] The @Unloadable annotation allow trading the preserve of static variable with memory footprint.

No changes in VM Spec needed.

COMPILATION: (nil)

TESTING: see the ADVANCED EXAMPLE above

LIBRARY SUPPORT: new annotation @java.lang.Unloadable

REFLECTIVE APIS: (nil)

OTHER CHANGES: (nil)

MIGRATION: (nil)

COMPATIBILITY

BREAKING CHANGES: (nil)

EXISTING PROGRAMS (nil)

REFERENCES

EXISTING BUGS: (nil)



More information about the coin-dev mailing list