-
Enhancement
-
Resolution: Not an Issue
-
P3
-
repo-valhalla
In a jdk.internal package somewhere, make a factory method which builds new instances of java.lang.Class.
package jdk.internal.vm;
public class ClassMirrors {
/**
Make a fresh non-classfile mirror with the given name.
If primary is non-null, the mirror will be secondary to the given one.
That means, in part, that all operational reflective API points will delegate
from the secondary to the primary.
If primary is null there is no delegation.
The userData may be null; it is available to other clients.
*/
public static native Class<?> makeSecondaryMirror(String name, Class<?> primary, Object userData);
public static native Class<?> primaryOf(Class<?> secondary);
public static native Object userDataOf(Class<?> secondary);
}
The purpose of this is to allow reflection to create mirrors which correspond to variant view of classes. For example, given a primitive class P with two mirrors P.ref.class and P.val.class, perhaps P.ref.class is the "real" mirror (the primary, created when P is loaded) and P.val.class is a secondary which points back to P.ref.class. (Or vice versa.)
One could validate the design by re-implementing int.class (Integer.TYPE) using this mechanism, instead of the ad hoc JVM logic that currently support int.class.
package jdk.internal.vm;
public class ClassMirrors {
/**
Make a fresh non-classfile mirror with the given name.
If primary is non-null, the mirror will be secondary to the given one.
That means, in part, that all operational reflective API points will delegate
from the secondary to the primary.
If primary is null there is no delegation.
The userData may be null; it is available to other clients.
*/
public static native Class<?> makeSecondaryMirror(String name, Class<?> primary, Object userData);
public static native Class<?> primaryOf(Class<?> secondary);
public static native Object userDataOf(Class<?> secondary);
}
The purpose of this is to allow reflection to create mirrors which correspond to variant view of classes. For example, given a primitive class P with two mirrors P.ref.class and P.val.class, perhaps P.ref.class is the "real" mirror (the primary, created when P is loaded) and P.val.class is a secondary which points back to P.ref.class. (Or vice versa.)
One could validate the design by re-implementing int.class (Integer.TYPE) using this mechanism, instead of the ad hoc JVM logic that currently support int.class.