Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/Development/Dynamic/def1"
(→Mechanism in Java7) |
(→Mechanism in Java7) |
||
Line 10: | Line 10: | ||
===== Mechanism in Java7 ===== | ===== Mechanism in Java7 ===== | ||
<i>Future</i><br />JSR-292 (Supporting Dynamically Typed Languages on the Java ™ Platform) introduces a new type of classloader, | <i>Future</i><br />JSR-292 (Supporting Dynamically Typed Languages on the Java ™ Platform) introduces a new type of classloader, | ||
− | <code>java.dyn.AnonymousClassLoader<code>. <code>AnonymousClassLoader<code> is designed to solve two problems: | + | <code>java.dyn.AnonymousClassLoader</code>. <code>AnonymousClassLoader</code> is designed to solve two problems: |
# Generating many classes with similar bytecode and only minor changes is very inefficient, wasting a lot of precious memory. | # Generating many classes with similar bytecode and only minor changes is very inefficient, wasting a lot of precious memory. | ||
# Generated bytecode must be contained in a class, which must be contained in a ClassLoader, which keeps a hard reference to the class; as a result, to make even one byte of bytecode garbage-collectable, it must be wrapped in its own class and its own classloader. | # Generated bytecode must be contained in a class, which must be contained in a ClassLoader, which keeps a hard reference to the class; as a result, to make even one byte of bytecode garbage-collectable, it must be wrapped in its own class and its own classloader. | ||
− | First, classes loaded by AnonymousClassLoader are not given full-fledged symbolic names in the global symbol tables; they're given rough numeric identifiers. They are effectively anonymized, allowing much more | + | First, classes loaded by <code>AnonymousClassLoader</code> are not given full-fledged symbolic names in the global symbol tables; they're given rough numeric identifiers. They are effectively anonymized, allowing much more freedom to generate them at will, since naming conflicts essentially do not happen. |
Second, the classes are loaded without a parent ClassLoader, so there's no overprotective mother keeping them on a short leash. When the last normal references to the class disappear, it's eligible for garbage collection like any other object. | Second, the classes are loaded without a parent ClassLoader, so there's no overprotective mother keeping them on a short leash. When the last normal references to the class disappear, it's eligible for garbage collection like any other object. | ||
Third, it provides a mechanism whereby an existing class can be loaded and slightly modified, producing a new class with those modifications but sharing the rest of its structure and data. | Third, it provides a mechanism whereby an existing class can be loaded and slightly modified, producing a new class with those modifications but sharing the rest of its structure and data. |
Revision as of 14:51, 31 August 2009
Dynamic Persistence
Dynamic Persistence is defined as the ability to create a persistent entity class and use it within an application without a-priori the Java class existing (no .class file on the classpath or in the relevant .jar/.war archive).
Mechanism in Java5/Java6
In order to create a Java class at runtime without the use of the javac compiler, the use of a custom ClassLoaderer is required, along with a bytecode manipulation library (such as ASM or some other framework).
Mechanism in Java7
Future
JSR-292 (Supporting Dynamically Typed Languages on the Java ™ Platform) introduces a new type of classloader,
java.dyn.AnonymousClassLoader
. AnonymousClassLoader
is designed to solve two problems:
- Generating many classes with similar bytecode and only minor changes is very inefficient, wasting a lot of precious memory.
- Generated bytecode must be contained in a class, which must be contained in a ClassLoader, which keeps a hard reference to the class; as a result, to make even one byte of bytecode garbage-collectable, it must be wrapped in its own class and its own classloader.
First, classes loaded by AnonymousClassLoader
are not given full-fledged symbolic names in the global symbol tables; they're given rough numeric identifiers. They are effectively anonymized, allowing much more freedom to generate them at will, since naming conflicts essentially do not happen.
Second, the classes are loaded without a parent ClassLoader, so there's no overprotective mother keeping them on a short leash. When the last normal references to the class disappear, it's eligible for garbage collection like any other object.
Third, it provides a mechanism whereby an existing class can be loaded and slightly modified, producing a new class with those modifications but sharing the rest of its structure and data.