A proposal in advance of the OpenJDK development crew would include hidden classes to Java, a capability meant to improve the performance of language implementations crafted on the JVM.
Concealed classes are classes that are unable to be applied instantly by the bytecode of other classes, in accordance to the JDK Enhancement Proposal. Fairly, hidden classes are meant to be applied by frameworks that deliver classes at runtime and use them indirectly by using reflection. A hidden class can be defined as a member of an entry manage nest and might be weakly referenced by its class loader. There is no timetable nevertheless for when hidden classes may well seem in Java.
In explaining the motivation driving the prepare, the proposal states that quite a few language implementations crafted on the JVM leverage dynamic class technology for performance and overall flexibility. Java’s javac compiler, for instance, does not translate a lambda expression into a committed class file at compile time but emits bytecode to dynamically deliver and instantiate a class. In the same way, non-Java JVM languages normally implement better-buy options by using dynamic proxies to deliver classes dynamically.
The implementers of these languages generally want a dynamically produced class to be part of an current statically produced class and to have properties fascinating of dynamically produced classes these as non-discoverability and entry manage. Nevertheless, the normal APIs that determine a class weren’t built with these needs in head.
If the normal APIs could determine hidden, non-discoverable classes with a restricted lifecycle, then frameworks inside of and outside the house of the JDK that deliver classes dynamically could determine hidden classes as an alternative, improving upon JVM language performance.
Aims of the hidden classes proposal incorporate:
- Enabling frameworks to determine classes as non-discoverable implementation details of the framework, so they are unable to be joined towards by other classes, or identified by using reflection.
- Deprecation of the non-normal API,
misc.Unsafe::defineAnonymousClass
, with the objective of removing it in a long term launch. - Not altering the Java language at all.
- Help extending an entry-manage nest with non-discoverable classes.
- Supporting intense unloading of non-discoverable classes, offering frameworks the overall flexibility to determine as wanted.