156 //-------------------------------------------------------------------------- 157 // 158 // Routines used by java.lang.reflect 159 // 160 // 161 162 /** Called only by java.lang.reflect.Modifier's static initializer */ 163 public void setLangReflectAccess(LangReflectAccess access) { 164 langReflectAccess = access; 165 } 166 167 /** 168 * Note: this routine can cause the declaring class for the field 169 * be initialized and therefore must not be called until the 170 * first get/set of this field. 171 * @param field the field 172 * @param override true if caller has overridden accessibility 173 */ 174 public FieldAccessor newFieldAccessor(Field field, boolean override) { 175 checkInitted(); 176 return UnsafeFieldAccessorFactory.newFieldAccessor(field, override); 177 } 178 179 public MethodAccessor newMethodAccessor(Method method) { 180 checkInitted(); 181 182 if (Reflection.isCallerSensitive(method)) { 183 Method altMethod = findMethodForReflection(method); 184 if (altMethod != null) { 185 method = altMethod; 186 } 187 } 188 189 if (noInflation && !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) { 190 return new MethodAccessorGenerator(). 191 generateMethod(method.getDeclaringClass(), 192 method.getName(), 193 method.getParameterTypes(), 194 method.getReturnType(), 195 method.getExceptionTypes(), 196 method.getModifiers()); 197 } else { 198 NativeMethodAccessorImpl acc = 199 new NativeMethodAccessorImpl(method); 200 DelegatingMethodAccessorImpl res = 201 new DelegatingMethodAccessorImpl(acc); 202 acc.setParent(res); 203 return res; 204 } 205 } 206 207 public ConstructorAccessor newConstructorAccessor(Constructor<?> c) { 208 checkInitted(); 209 210 Class<?> declaringClass = c.getDeclaringClass(); 211 if (Modifier.isAbstract(declaringClass.getModifiers())) { 212 return new InstantiationExceptionConstructorAccessorImpl(null); 213 } 214 if (declaringClass == Class.class) { 215 return new InstantiationExceptionConstructorAccessorImpl 216 ("Can not instantiate java.lang.Class"); 217 } 218 // Bootstrapping issue: since we use Class.newInstance() in 219 // the ConstructorAccessor generation process, we have to 220 // break the cycle here. 221 if (Reflection.isSubclassOf(declaringClass, 222 ConstructorAccessorImpl.class)) { 223 return new BootstrapConstructorAccessorImpl(c); 224 } 225 226 if (noInflation && !ReflectUtil.isVMAnonymousClass(c.getDeclaringClass())) { 227 return new MethodAccessorGenerator(). 228 generateConstructor(c.getDeclaringClass(), 229 c.getParameterTypes(), 230 c.getExceptionTypes(), 231 c.getModifiers()); 232 } else { 233 NativeConstructorAccessorImpl acc = 234 new NativeConstructorAccessorImpl(c); 235 DelegatingConstructorAccessorImpl res = 236 new DelegatingConstructorAccessorImpl(acc); 237 acc.setParent(res); | 156 //-------------------------------------------------------------------------- 157 // 158 // Routines used by java.lang.reflect 159 // 160 // 161 162 /** Called only by java.lang.reflect.Modifier's static initializer */ 163 public void setLangReflectAccess(LangReflectAccess access) { 164 langReflectAccess = access; 165 } 166 167 /** 168 * Note: this routine can cause the declaring class for the field 169 * be initialized and therefore must not be called until the 170 * first get/set of this field. 171 * @param field the field 172 * @param override true if caller has overridden accessibility 173 */ 174 public FieldAccessor newFieldAccessor(Field field, boolean override) { 175 checkInitted(); 176 177 // use the root Field that will not cache caller class 178 Field f = langReflectAccess.getRoot(field); 179 if (f != null) { 180 field = f; 181 } 182 return UnsafeFieldAccessorFactory.newFieldAccessor(field, override); 183 } 184 185 public MethodAccessor newMethodAccessor(Method method) { 186 checkInitted(); 187 188 if (Reflection.isCallerSensitive(method)) { 189 Method altMethod = findMethodForReflection(method); 190 if (altMethod != null) { 191 method = altMethod; 192 } 193 } 194 195 // use the root Method that will not cache caller class 196 Method m = langReflectAccess.getRoot(method); 197 if (m != null) { 198 method = m; 199 } 200 201 if (noInflation && !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) { 202 return new MethodAccessorGenerator(). 203 generateMethod(method.getDeclaringClass(), 204 method.getName(), 205 method.getParameterTypes(), 206 method.getReturnType(), 207 method.getExceptionTypes(), 208 method.getModifiers()); 209 } else { 210 NativeMethodAccessorImpl acc = 211 new NativeMethodAccessorImpl(method); 212 DelegatingMethodAccessorImpl res = 213 new DelegatingMethodAccessorImpl(acc); 214 acc.setParent(res); 215 return res; 216 } 217 } 218 219 public ConstructorAccessor newConstructorAccessor(Constructor<?> c) { 220 checkInitted(); 221 222 Class<?> declaringClass = c.getDeclaringClass(); 223 if (Modifier.isAbstract(declaringClass.getModifiers())) { 224 return new InstantiationExceptionConstructorAccessorImpl(null); 225 } 226 if (declaringClass == Class.class) { 227 return new InstantiationExceptionConstructorAccessorImpl 228 ("Can not instantiate java.lang.Class"); 229 } 230 231 // use the root Constructor that will not cache caller class 232 Constructor<?> ctr = langReflectAccess.getRoot(c); 233 if (ctr != null) { 234 c = ctr; 235 } 236 237 // Bootstrapping issue: since we use Class.newInstance() in 238 // the ConstructorAccessor generation process, we have to 239 // break the cycle here. 240 if (Reflection.isSubclassOf(declaringClass, 241 ConstructorAccessorImpl.class)) { 242 return new BootstrapConstructorAccessorImpl(c); 243 } 244 245 if (noInflation && !ReflectUtil.isVMAnonymousClass(c.getDeclaringClass())) { 246 return new MethodAccessorGenerator(). 247 generateConstructor(c.getDeclaringClass(), 248 c.getParameterTypes(), 249 c.getExceptionTypes(), 250 c.getModifiers()); 251 } else { 252 NativeConstructorAccessorImpl acc = 253 new NativeConstructorAccessorImpl(c); 254 DelegatingConstructorAccessorImpl res = 255 new DelegatingConstructorAccessorImpl(acc); 256 acc.setParent(res); |