63 import jdk.internal.HotSpotIntrinsicCandidate;
64 import jdk.internal.loader.BootLoader;
65 import jdk.internal.loader.BuiltinClassLoader;
66 import jdk.internal.misc.Unsafe;
67 import jdk.internal.misc.VM;
68 import jdk.internal.module.Resources;
69 import jdk.internal.reflect.CallerSensitive;
70 import jdk.internal.reflect.ConstantPool;
71 import jdk.internal.reflect.Reflection;
72 import jdk.internal.reflect.ReflectionFactory;
73 import jdk.internal.vm.annotation.ForceInline;
74 import sun.reflect.generics.factory.CoreReflectionFactory;
75 import sun.reflect.generics.factory.GenericsFactory;
76 import sun.reflect.generics.repository.ClassRepository;
77 import sun.reflect.generics.repository.MethodRepository;
78 import sun.reflect.generics.repository.ConstructorRepository;
79 import sun.reflect.generics.scope.ClassScope;
80 import sun.security.util.SecurityConstants;
81 import sun.reflect.annotation.*;
82 import sun.reflect.misc.ReflectUtil;
83 import static valhalla.shady.MinimalValueTypes_1_0.ACC_VALUE;
84
85 /**
86 * Instances of the class {@code Class} represent classes and
87 * interfaces in a running Java application. An enum is a kind of
88 * class and an annotation is a kind of interface. Every array also
89 * belongs to a class that is reflected as a {@code Class} object
90 * that is shared by all arrays with the same element type and number
91 * of dimensions. The primitive Java types ({@code boolean},
92 * {@code byte}, {@code char}, {@code short},
93 * {@code int}, {@code long}, {@code float}, and
94 * {@code double}), and the keyword {@code void} are also
95 * represented as {@code Class} objects.
96 *
97 * <p> {@code Class} has no public constructor. Instead {@code Class}
98 * objects are constructed automatically by the Java Virtual Machine as classes
99 * are loaded and by calls to the {@code defineClass} method in the class
100 * loader.
101 *
102 * <p> The following example uses a {@code Class} object to print the
446 // java.base has all permissions
447 SecurityManager sm = System.getSecurityManager();
448 if (sm != null) {
449 sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
450 }
451 }
452
453 PrivilegedAction<ClassLoader> pa = module::getClassLoader;
454 ClassLoader cl = AccessController.doPrivileged(pa);
455 Class<?> c;
456 if (cl != null) {
457 c = cl.loadClass(module, name);
458 } else {
459 c = BootLoader.loadClass(module, name);
460 }
461
462 return c != null && !c.isValueClass() ? c : null;
463 }
464
465 boolean isValueClass() {
466 Class<?> c = this;
467 while (c.isArray()) {
468 c = c.getComponentType();
469 }
470
471 // For now, check if it is a subtype of __Value
472 return __Value.class.isAssignableFrom(c) && c != __Value.class;
473 }
474
475 private void ensureNotValueClass() {
476 // temporary workaround until compiler/valhalla/valuetypes/ValueTypeBenchTest.java
477 // is updated to do reflection on VCC instead of VVT declared with __ByValue
478 if (this.isValueClass() && !Boolean.parseBoolean(VM.getSavedProperty("jdk.lang.reflect.DVT"))) {
479 throw new UnsupportedOperationException("cannot reflect on derived value type "
480 + this.getName());
481 }
482 }
483
484 /**
485 * Creates a new instance of the class represented by this {@code Class}
486 * object. The class is instantiated as if by a {@code new}
487 * expression with an empty argument list. The class is initialized if it
488 * has not already been initialized.
489 *
490 * @deprecated This method propagates any exception thrown by the
491 * nullary constructor, including a checked exception. Use of
492 * this method effectively bypasses the compile-time exception
|
63 import jdk.internal.HotSpotIntrinsicCandidate;
64 import jdk.internal.loader.BootLoader;
65 import jdk.internal.loader.BuiltinClassLoader;
66 import jdk.internal.misc.Unsafe;
67 import jdk.internal.misc.VM;
68 import jdk.internal.module.Resources;
69 import jdk.internal.reflect.CallerSensitive;
70 import jdk.internal.reflect.ConstantPool;
71 import jdk.internal.reflect.Reflection;
72 import jdk.internal.reflect.ReflectionFactory;
73 import jdk.internal.vm.annotation.ForceInline;
74 import sun.reflect.generics.factory.CoreReflectionFactory;
75 import sun.reflect.generics.factory.GenericsFactory;
76 import sun.reflect.generics.repository.ClassRepository;
77 import sun.reflect.generics.repository.MethodRepository;
78 import sun.reflect.generics.repository.ConstructorRepository;
79 import sun.reflect.generics.scope.ClassScope;
80 import sun.security.util.SecurityConstants;
81 import sun.reflect.annotation.*;
82 import sun.reflect.misc.ReflectUtil;
83 import valhalla.shady.MinimalValueTypes_1_0;
84
85 import static valhalla.shady.MinimalValueTypes_1_0.ACC_VALUE;
86
87 /**
88 * Instances of the class {@code Class} represent classes and
89 * interfaces in a running Java application. An enum is a kind of
90 * class and an annotation is a kind of interface. Every array also
91 * belongs to a class that is reflected as a {@code Class} object
92 * that is shared by all arrays with the same element type and number
93 * of dimensions. The primitive Java types ({@code boolean},
94 * {@code byte}, {@code char}, {@code short},
95 * {@code int}, {@code long}, {@code float}, and
96 * {@code double}), and the keyword {@code void} are also
97 * represented as {@code Class} objects.
98 *
99 * <p> {@code Class} has no public constructor. Instead {@code Class}
100 * objects are constructed automatically by the Java Virtual Machine as classes
101 * are loaded and by calls to the {@code defineClass} method in the class
102 * loader.
103 *
104 * <p> The following example uses a {@code Class} object to print the
448 // java.base has all permissions
449 SecurityManager sm = System.getSecurityManager();
450 if (sm != null) {
451 sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
452 }
453 }
454
455 PrivilegedAction<ClassLoader> pa = module::getClassLoader;
456 ClassLoader cl = AccessController.doPrivileged(pa);
457 Class<?> c;
458 if (cl != null) {
459 c = cl.loadClass(module, name);
460 } else {
461 c = BootLoader.loadClass(module, name);
462 }
463
464 return c != null && !c.isValueClass() ? c : null;
465 }
466
467 boolean isValueClass() {
468 // ensure that system properties have been initialized.
469 if (VM.initLevel() < 1)
470 return false;
471
472 Class<?> c = this;
473 while (c.isArray()) {
474 c = c.getComponentType();
475 }
476
477 // For now, check if it is a subtype of __Value
478 Class<?> valueBaseClass = MinimalValueTypes_1_0.getValueClass();
479 return valueBaseClass != null && c != valueBaseClass && valueBaseClass.isAssignableFrom(c);
480 }
481
482 private void ensureNotValueClass() {
483 // temporary workaround until compiler/valhalla/valuetypes/ValueTypeBenchTest.java
484 // is updated to do reflection on VCC instead of VVT declared with __ByValue
485 if (this.isValueClass() && !Boolean.parseBoolean(VM.getSavedProperty("jdk.lang.reflect.DVT"))) {
486 throw new UnsupportedOperationException("cannot reflect on derived value type "
487 + this.getName());
488 }
489 }
490
491 /**
492 * Creates a new instance of the class represented by this {@code Class}
493 * object. The class is instantiated as if by a {@code new}
494 * expression with an empty argument list. The class is initialized if it
495 * has not already been initialized.
496 *
497 * @deprecated This method propagates any exception thrown by the
498 * nullary constructor, including a checked exception. Use of
499 * this method effectively bypasses the compile-time exception
|