< prev index next >

src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java

Print this page




 185         }
 186         return UnsafeFieldAccessorFactory.newFieldAccessor(field, override);
 187     }
 188 
 189     public MethodAccessor newMethodAccessor(Method method) {
 190         checkInitted();
 191 
 192         if (Reflection.isCallerSensitive(method)) {
 193             Method altMethod = findMethodForReflection(method);
 194             if (altMethod != null) {
 195                 method = altMethod;
 196             }
 197         }
 198 
 199         // use the root Method that will not cache caller class
 200         Method root = langReflectAccess().getRoot(method);
 201         if (root != null) {
 202             method = root;
 203         }
 204 
 205         if (noInflation && !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) {
 206             return new MethodAccessorGenerator().
 207                 generateMethod(method.getDeclaringClass(),
 208                                method.getName(),
 209                                method.getParameterTypes(),
 210                                method.getReturnType(),
 211                                method.getExceptionTypes(),
 212                                method.getModifiers());
 213         } else {
 214             NativeMethodAccessorImpl acc =
 215                 new NativeMethodAccessorImpl(method);
 216             DelegatingMethodAccessorImpl res =
 217                 new DelegatingMethodAccessorImpl(acc);
 218             acc.setParent(res);
 219             return res;
 220         }
 221     }
 222 
 223     public ConstructorAccessor newConstructorAccessor(Constructor<?> c) {
 224         checkInitted();
 225 


 229         }
 230         if (declaringClass == Class.class) {
 231             return new InstantiationExceptionConstructorAccessorImpl
 232                 ("Can not instantiate java.lang.Class");
 233         }
 234 
 235         // use the root Constructor that will not cache caller class
 236         Constructor<?> root = langReflectAccess().getRoot(c);
 237         if (root != null) {
 238             c = root;
 239         }
 240 
 241         // Bootstrapping issue: since we use Class.newInstance() in
 242         // the ConstructorAccessor generation process, we have to
 243         // break the cycle here.
 244         if (Reflection.isSubclassOf(declaringClass,
 245                                     ConstructorAccessorImpl.class)) {
 246             return new BootstrapConstructorAccessorImpl(c);
 247         }
 248 
 249         if (noInflation && !ReflectUtil.isVMAnonymousClass(c.getDeclaringClass())) {
 250             return new MethodAccessorGenerator().
 251                 generateConstructor(c.getDeclaringClass(),
 252                                     c.getParameterTypes(),
 253                                     c.getExceptionTypes(),
 254                                     c.getModifiers());
 255         } else {
 256             NativeConstructorAccessorImpl acc =
 257                 new NativeConstructorAccessorImpl(c);
 258             DelegatingConstructorAccessorImpl res =
 259                 new DelegatingConstructorAccessorImpl(acc);
 260             acc.setParent(res);
 261             return res;
 262         }
 263     }
 264 
 265     //--------------------------------------------------------------------------
 266     //
 267     // Routines used by java.lang
 268     //
 269     //




 185         }
 186         return UnsafeFieldAccessorFactory.newFieldAccessor(field, override);
 187     }
 188 
 189     public MethodAccessor newMethodAccessor(Method method) {
 190         checkInitted();
 191 
 192         if (Reflection.isCallerSensitive(method)) {
 193             Method altMethod = findMethodForReflection(method);
 194             if (altMethod != null) {
 195                 method = altMethod;
 196             }
 197         }
 198 
 199         // use the root Method that will not cache caller class
 200         Method root = langReflectAccess().getRoot(method);
 201         if (root != null) {
 202             method = root;
 203         }
 204 
 205         if (noInflation && !method.getDeclaringClass().isHidden()) {
 206             return new MethodAccessorGenerator().
 207                 generateMethod(method.getDeclaringClass(),
 208                                method.getName(),
 209                                method.getParameterTypes(),
 210                                method.getReturnType(),
 211                                method.getExceptionTypes(),
 212                                method.getModifiers());
 213         } else {
 214             NativeMethodAccessorImpl acc =
 215                 new NativeMethodAccessorImpl(method);
 216             DelegatingMethodAccessorImpl res =
 217                 new DelegatingMethodAccessorImpl(acc);
 218             acc.setParent(res);
 219             return res;
 220         }
 221     }
 222 
 223     public ConstructorAccessor newConstructorAccessor(Constructor<?> c) {
 224         checkInitted();
 225 


 229         }
 230         if (declaringClass == Class.class) {
 231             return new InstantiationExceptionConstructorAccessorImpl
 232                 ("Can not instantiate java.lang.Class");
 233         }
 234 
 235         // use the root Constructor that will not cache caller class
 236         Constructor<?> root = langReflectAccess().getRoot(c);
 237         if (root != null) {
 238             c = root;
 239         }
 240 
 241         // Bootstrapping issue: since we use Class.newInstance() in
 242         // the ConstructorAccessor generation process, we have to
 243         // break the cycle here.
 244         if (Reflection.isSubclassOf(declaringClass,
 245                                     ConstructorAccessorImpl.class)) {
 246             return new BootstrapConstructorAccessorImpl(c);
 247         }
 248 
 249         if (noInflation && !c.getDeclaringClass().isHidden()) {
 250             return new MethodAccessorGenerator().
 251                 generateConstructor(c.getDeclaringClass(),
 252                                     c.getParameterTypes(),
 253                                     c.getExceptionTypes(),
 254                                     c.getModifiers());
 255         } else {
 256             NativeConstructorAccessorImpl acc =
 257                 new NativeConstructorAccessorImpl(c);
 258             DelegatingConstructorAccessorImpl res =
 259                 new DelegatingConstructorAccessorImpl(acc);
 260             acc.setParent(res);
 261             return res;
 262         }
 263     }
 264 
 265     //--------------------------------------------------------------------------
 266     //
 267     // Routines used by java.lang
 268     //
 269     //


< prev index next >