author | redestad |
Thu, 21 Apr 2016 13:39:53 +0200 | |
changeset 37593 | 824750ada3d6 |
parent 37363 | 329dba26ffd2 |
child 37781 | 71ed5645f17c |
permissions | -rw-r--r-- |
2 | 1 |
/* |
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14342
diff
changeset
|
2 |
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
37363
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
33674
diff
changeset
|
26 |
package jdk.internal.reflect; |
2 | 27 |
|
28 |
import java.lang.reflect.Field; |
|
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14342
diff
changeset
|
29 |
import java.lang.reflect.Executable; |
2 | 30 |
import java.lang.reflect.Method; |
31 |
import java.lang.reflect.Constructor; |
|
32 |
import java.lang.reflect.Modifier; |
|
33 |
import java.security.Permission; |
|
34 |
import java.security.PrivilegedAction; |
|
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
35 |
import java.util.Properties; |
21672
33014eb0cb79
8028055: (reflect) invoking Method/Constructor in anonymous classes breaks with -Dsun.reflect.noInflation=true
jfranck
parents:
15510
diff
changeset
|
36 |
import sun.reflect.misc.ReflectUtil; |
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
37 |
import sun.security.action.GetPropertyAction; |
2 | 38 |
|
39 |
/** <P> The master factory for all reflective objects, both those in |
|
40 |
java.lang.reflect (Fields, Methods, Constructors) as well as their |
|
41 |
delegates (FieldAccessors, MethodAccessors, ConstructorAccessors). |
|
42 |
</P> |
|
43 |
||
44 |
<P> The methods in this class are extremely unsafe and can cause |
|
45 |
subversion of both the language and the verifier. For this reason, |
|
46 |
they are all instance methods, and access to the constructor of |
|
47 |
this factory is guarded by a security check, in similar style to |
|
33674
566777f73c32
8140606: Update library code to use internal Unsafe
chegar
parents:
32268
diff
changeset
|
48 |
{@link jdk.internal.misc.Unsafe}. </P> |
2 | 49 |
*/ |
50 |
||
51 |
public class ReflectionFactory { |
|
52 |
||
53 |
private static boolean initted = false; |
|
27489
cf53b2c02ebb
8062771: Core reflection should use final fields whenever possible
martin
parents:
25859
diff
changeset
|
54 |
private static final Permission reflectionFactoryAccessPerm |
2 | 55 |
= new RuntimePermission("reflectionFactoryAccess"); |
27489
cf53b2c02ebb
8062771: Core reflection should use final fields whenever possible
martin
parents:
25859
diff
changeset
|
56 |
private static final ReflectionFactory soleInstance = new ReflectionFactory(); |
2 | 57 |
// Provides access to package-private mechanisms in java.lang.reflect |
58 |
private static volatile LangReflectAccess langReflectAccess; |
|
59 |
||
60 |
// |
|
61 |
// "Inflation" mechanism. Loading bytecodes to implement |
|
62 |
// Method.invoke() and Constructor.newInstance() currently costs |
|
63 |
// 3-4x more than an invocation via native code for the first |
|
64 |
// invocation (though subsequent invocations have been benchmarked |
|
65 |
// to be over 20x faster). Unfortunately this cost increases |
|
66 |
// startup time for certain applications that use reflection |
|
67 |
// intensively (but only once per class) to bootstrap themselves. |
|
68 |
// To avoid this penalty we reuse the existing JVM entry points |
|
69 |
// for the first few invocations of Methods and Constructors and |
|
70 |
// then switch to the bytecode-based implementations. |
|
71 |
// |
|
72 |
// Package-private to be accessible to NativeMethodAccessorImpl |
|
73 |
// and NativeConstructorAccessorImpl |
|
74 |
private static boolean noInflation = false; |
|
75 |
private static int inflationThreshold = 15; |
|
76 |
||
77 |
private ReflectionFactory() { |
|
78 |
} |
|
79 |
||
80 |
/** |
|
81 |
* A convenience class for acquiring the capability to instantiate |
|
82 |
* reflective objects. Use this instead of a raw call to {@link |
|
83 |
* #getReflectionFactory} in order to avoid being limited by the |
|
84 |
* permissions of your callers. |
|
85 |
* |
|
86 |
* <p>An instance of this class can be used as the argument of |
|
87 |
* <code>AccessController.doPrivileged</code>. |
|
88 |
*/ |
|
89 |
public static final class GetReflectionFactoryAction |
|
51 | 90 |
implements PrivilegedAction<ReflectionFactory> { |
91 |
public ReflectionFactory run() { |
|
2 | 92 |
return getReflectionFactory(); |
93 |
} |
|
94 |
} |
|
95 |
||
96 |
/** |
|
97 |
* Provides the caller with the capability to instantiate reflective |
|
98 |
* objects. |
|
99 |
* |
|
100 |
* <p> First, if there is a security manager, its |
|
101 |
* <code>checkPermission</code> method is called with a {@link |
|
102 |
* java.lang.RuntimePermission} with target |
|
103 |
* <code>"reflectionFactoryAccess"</code>. This may result in a |
|
104 |
* security exception. |
|
105 |
* |
|
106 |
* <p> The returned <code>ReflectionFactory</code> object should be |
|
107 |
* carefully guarded by the caller, since it can be used to read and |
|
108 |
* write private data and invoke private methods, as well as to load |
|
109 |
* unverified bytecodes. It must never be passed to untrusted code. |
|
110 |
* |
|
111 |
* @exception SecurityException if a security manager exists and its |
|
112 |
* <code>checkPermission</code> method doesn't allow |
|
113 |
* access to the RuntimePermission "reflectionFactoryAccess". */ |
|
114 |
public static ReflectionFactory getReflectionFactory() { |
|
115 |
SecurityManager security = System.getSecurityManager(); |
|
116 |
if (security != null) { |
|
117 |
// TO DO: security.checkReflectionFactoryAccess(); |
|
118 |
security.checkPermission(reflectionFactoryAccessPerm); |
|
119 |
} |
|
120 |
return soleInstance; |
|
121 |
} |
|
122 |
||
123 |
//-------------------------------------------------------------------------- |
|
124 |
// |
|
125 |
// Routines used by java.lang.reflect |
|
126 |
// |
|
127 |
// |
|
128 |
||
129 |
/** Called only by java.lang.reflect.Modifier's static initializer */ |
|
130 |
public void setLangReflectAccess(LangReflectAccess access) { |
|
131 |
langReflectAccess = access; |
|
132 |
} |
|
133 |
||
134 |
/** |
|
135 |
* Note: this routine can cause the declaring class for the field |
|
136 |
* be initialized and therefore must not be called until the |
|
137 |
* first get/set of this field. |
|
138 |
* @param field the field |
|
28056
0cab6eb92852
8065172: More core reflection final and volatile annotations
martin
parents:
27489
diff
changeset
|
139 |
* @param override true if caller has overridden accessibility |
2 | 140 |
*/ |
141 |
public FieldAccessor newFieldAccessor(Field field, boolean override) { |
|
142 |
checkInitted(); |
|
143 |
return UnsafeFieldAccessorFactory.newFieldAccessor(field, override); |
|
144 |
} |
|
145 |
||
146 |
public MethodAccessor newMethodAccessor(Method method) { |
|
147 |
checkInitted(); |
|
148 |
||
21672
33014eb0cb79
8028055: (reflect) invoking Method/Constructor in anonymous classes breaks with -Dsun.reflect.noInflation=true
jfranck
parents:
15510
diff
changeset
|
149 |
if (noInflation && !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) { |
2 | 150 |
return new MethodAccessorGenerator(). |
151 |
generateMethod(method.getDeclaringClass(), |
|
152 |
method.getName(), |
|
153 |
method.getParameterTypes(), |
|
154 |
method.getReturnType(), |
|
155 |
method.getExceptionTypes(), |
|
156 |
method.getModifiers()); |
|
157 |
} else { |
|
158 |
NativeMethodAccessorImpl acc = |
|
159 |
new NativeMethodAccessorImpl(method); |
|
160 |
DelegatingMethodAccessorImpl res = |
|
161 |
new DelegatingMethodAccessorImpl(acc); |
|
162 |
acc.setParent(res); |
|
163 |
return res; |
|
164 |
} |
|
165 |
} |
|
166 |
||
10342
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
167 |
public ConstructorAccessor newConstructorAccessor(Constructor<?> c) { |
2 | 168 |
checkInitted(); |
169 |
||
51 | 170 |
Class<?> declaringClass = c.getDeclaringClass(); |
2 | 171 |
if (Modifier.isAbstract(declaringClass.getModifiers())) { |
172 |
return new InstantiationExceptionConstructorAccessorImpl(null); |
|
173 |
} |
|
174 |
if (declaringClass == Class.class) { |
|
175 |
return new InstantiationExceptionConstructorAccessorImpl |
|
176 |
("Can not instantiate java.lang.Class"); |
|
177 |
} |
|
178 |
// Bootstrapping issue: since we use Class.newInstance() in |
|
179 |
// the ConstructorAccessor generation process, we have to |
|
180 |
// break the cycle here. |
|
181 |
if (Reflection.isSubclassOf(declaringClass, |
|
182 |
ConstructorAccessorImpl.class)) { |
|
183 |
return new BootstrapConstructorAccessorImpl(c); |
|
184 |
} |
|
185 |
||
21672
33014eb0cb79
8028055: (reflect) invoking Method/Constructor in anonymous classes breaks with -Dsun.reflect.noInflation=true
jfranck
parents:
15510
diff
changeset
|
186 |
if (noInflation && !ReflectUtil.isVMAnonymousClass(c.getDeclaringClass())) { |
2 | 187 |
return new MethodAccessorGenerator(). |
188 |
generateConstructor(c.getDeclaringClass(), |
|
189 |
c.getParameterTypes(), |
|
190 |
c.getExceptionTypes(), |
|
191 |
c.getModifiers()); |
|
192 |
} else { |
|
193 |
NativeConstructorAccessorImpl acc = |
|
194 |
new NativeConstructorAccessorImpl(c); |
|
195 |
DelegatingConstructorAccessorImpl res = |
|
196 |
new DelegatingConstructorAccessorImpl(acc); |
|
197 |
acc.setParent(res); |
|
198 |
return res; |
|
199 |
} |
|
200 |
} |
|
201 |
||
202 |
//-------------------------------------------------------------------------- |
|
203 |
// |
|
204 |
// Routines used by java.lang |
|
205 |
// |
|
206 |
// |
|
207 |
||
208 |
/** Creates a new java.lang.reflect.Field. Access checks as per |
|
209 |
java.lang.reflect.AccessibleObject are not overridden. */ |
|
51 | 210 |
public Field newField(Class<?> declaringClass, |
2 | 211 |
String name, |
51 | 212 |
Class<?> type, |
2 | 213 |
int modifiers, |
214 |
int slot, |
|
215 |
String signature, |
|
216 |
byte[] annotations) |
|
217 |
{ |
|
218 |
return langReflectAccess().newField(declaringClass, |
|
219 |
name, |
|
220 |
type, |
|
221 |
modifiers, |
|
222 |
slot, |
|
223 |
signature, |
|
224 |
annotations); |
|
225 |
} |
|
226 |
||
227 |
/** Creates a new java.lang.reflect.Method. Access checks as per |
|
228 |
java.lang.reflect.AccessibleObject are not overridden. */ |
|
51 | 229 |
public Method newMethod(Class<?> declaringClass, |
2 | 230 |
String name, |
51 | 231 |
Class<?>[] parameterTypes, |
232 |
Class<?> returnType, |
|
233 |
Class<?>[] checkedExceptions, |
|
2 | 234 |
int modifiers, |
235 |
int slot, |
|
236 |
String signature, |
|
237 |
byte[] annotations, |
|
238 |
byte[] parameterAnnotations, |
|
239 |
byte[] annotationDefault) |
|
240 |
{ |
|
241 |
return langReflectAccess().newMethod(declaringClass, |
|
242 |
name, |
|
243 |
parameterTypes, |
|
244 |
returnType, |
|
245 |
checkedExceptions, |
|
246 |
modifiers, |
|
247 |
slot, |
|
248 |
signature, |
|
249 |
annotations, |
|
250 |
parameterAnnotations, |
|
251 |
annotationDefault); |
|
252 |
} |
|
253 |
||
254 |
/** Creates a new java.lang.reflect.Constructor. Access checks as |
|
255 |
per java.lang.reflect.AccessibleObject are not overridden. */ |
|
10342
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
256 |
public Constructor<?> newConstructor(Class<?> declaringClass, |
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
257 |
Class<?>[] parameterTypes, |
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
258 |
Class<?>[] checkedExceptions, |
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
259 |
int modifiers, |
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
260 |
int slot, |
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
261 |
String signature, |
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
262 |
byte[] annotations, |
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
263 |
byte[] parameterAnnotations) |
2 | 264 |
{ |
265 |
return langReflectAccess().newConstructor(declaringClass, |
|
266 |
parameterTypes, |
|
267 |
checkedExceptions, |
|
268 |
modifiers, |
|
269 |
slot, |
|
270 |
signature, |
|
271 |
annotations, |
|
272 |
parameterAnnotations); |
|
273 |
} |
|
274 |
||
275 |
/** Gets the MethodAccessor object for a java.lang.reflect.Method */ |
|
276 |
public MethodAccessor getMethodAccessor(Method m) { |
|
277 |
return langReflectAccess().getMethodAccessor(m); |
|
278 |
} |
|
279 |
||
280 |
/** Sets the MethodAccessor object for a java.lang.reflect.Method */ |
|
281 |
public void setMethodAccessor(Method m, MethodAccessor accessor) { |
|
282 |
langReflectAccess().setMethodAccessor(m, accessor); |
|
283 |
} |
|
284 |
||
285 |
/** Gets the ConstructorAccessor object for a |
|
286 |
java.lang.reflect.Constructor */ |
|
10342
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
287 |
public ConstructorAccessor getConstructorAccessor(Constructor<?> c) { |
2 | 288 |
return langReflectAccess().getConstructorAccessor(c); |
289 |
} |
|
290 |
||
291 |
/** Sets the ConstructorAccessor object for a |
|
292 |
java.lang.reflect.Constructor */ |
|
10342
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
293 |
public void setConstructorAccessor(Constructor<?> c, |
2 | 294 |
ConstructorAccessor accessor) |
295 |
{ |
|
296 |
langReflectAccess().setConstructorAccessor(c, accessor); |
|
297 |
} |
|
298 |
||
299 |
/** Makes a copy of the passed method. The returned method is a |
|
300 |
"child" of the passed one; see the comments in Method.java for |
|
301 |
details. */ |
|
302 |
public Method copyMethod(Method arg) { |
|
303 |
return langReflectAccess().copyMethod(arg); |
|
304 |
} |
|
305 |
||
32268
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
29986
diff
changeset
|
306 |
/** Makes a copy of the passed method. The returned method is NOT |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
29986
diff
changeset
|
307 |
* a "child" but a "sibling" of the Method in arg. Should only be |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
29986
diff
changeset
|
308 |
* used on non-root methods. */ |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
29986
diff
changeset
|
309 |
public Method leafCopyMethod(Method arg) { |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
29986
diff
changeset
|
310 |
return langReflectAccess().leafCopyMethod(arg); |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
29986
diff
changeset
|
311 |
} |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
29986
diff
changeset
|
312 |
|
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
29986
diff
changeset
|
313 |
|
2 | 314 |
/** Makes a copy of the passed field. The returned field is a |
315 |
"child" of the passed one; see the comments in Field.java for |
|
316 |
details. */ |
|
317 |
public Field copyField(Field arg) { |
|
318 |
return langReflectAccess().copyField(arg); |
|
319 |
} |
|
320 |
||
321 |
/** Makes a copy of the passed constructor. The returned |
|
322 |
constructor is a "child" of the passed one; see the comments |
|
323 |
in Constructor.java for details. */ |
|
51 | 324 |
public <T> Constructor<T> copyConstructor(Constructor<T> arg) { |
2 | 325 |
return langReflectAccess().copyConstructor(arg); |
326 |
} |
|
327 |
||
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14342
diff
changeset
|
328 |
/** Gets the byte[] that encodes TypeAnnotations on an executable. |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14342
diff
changeset
|
329 |
*/ |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14342
diff
changeset
|
330 |
public byte[] getExecutableTypeAnnotationBytes(Executable ex) { |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14342
diff
changeset
|
331 |
return langReflectAccess().getExecutableTypeAnnotationBytes(ex); |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14342
diff
changeset
|
332 |
} |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
14342
diff
changeset
|
333 |
|
2 | 334 |
//-------------------------------------------------------------------------- |
335 |
// |
|
336 |
// Routines used by serialization |
|
337 |
// |
|
338 |
// |
|
339 |
||
10342
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
340 |
public Constructor<?> newConstructorForSerialization |
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
341 |
(Class<?> classToInstantiate, Constructor<?> constructorToCall) |
2 | 342 |
{ |
343 |
// Fast path |
|
344 |
if (constructorToCall.getDeclaringClass() == classToInstantiate) { |
|
345 |
return constructorToCall; |
|
346 |
} |
|
347 |
||
348 |
ConstructorAccessor acc = new MethodAccessorGenerator(). |
|
349 |
generateSerializationConstructor(classToInstantiate, |
|
350 |
constructorToCall.getParameterTypes(), |
|
351 |
constructorToCall.getExceptionTypes(), |
|
352 |
constructorToCall.getModifiers(), |
|
353 |
constructorToCall.getDeclaringClass()); |
|
10342
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
354 |
Constructor<?> c = newConstructor(constructorToCall.getDeclaringClass(), |
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
355 |
constructorToCall.getParameterTypes(), |
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
356 |
constructorToCall.getExceptionTypes(), |
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
357 |
constructorToCall.getModifiers(), |
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
358 |
langReflectAccess(). |
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
359 |
getConstructorSlot(constructorToCall), |
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
360 |
langReflectAccess(). |
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
361 |
getConstructorSignature(constructorToCall), |
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
362 |
langReflectAccess(). |
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
363 |
getConstructorAnnotations(constructorToCall), |
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
364 |
langReflectAccess(). |
ca0984bc9d32
7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
365 |
getConstructorParameterAnnotations(constructorToCall)); |
2 | 366 |
setConstructorAccessor(c, acc); |
367 |
return c; |
|
368 |
} |
|
369 |
||
370 |
//-------------------------------------------------------------------------- |
|
371 |
// |
|
372 |
// Internals only below this point |
|
373 |
// |
|
374 |
||
375 |
static int inflationThreshold() { |
|
376 |
return inflationThreshold; |
|
377 |
} |
|
378 |
||
379 |
/** We have to defer full initialization of this class until after |
|
380 |
the static initializer is run since java.lang.reflect.Method's |
|
381 |
static initializer (more properly, that for |
|
382 |
java.lang.reflect.AccessibleObject) causes this class's to be |
|
383 |
run, before the system properties are set up. */ |
|
384 |
private static void checkInitted() { |
|
385 |
if (initted) return; |
|
386 |
||
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
387 |
// Tests to ensure the system properties table is fully |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
388 |
// initialized. This is needed because reflection code is |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
389 |
// called very early in the initialization process (before |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
390 |
// command-line arguments have been parsed and therefore |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
391 |
// these user-settable properties installed.) We assume that |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
392 |
// if System.out is non-null then the System class has been |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
393 |
// fully initialized and that the bulk of the startup code |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
394 |
// has been run. |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
395 |
|
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
396 |
if (System.out == null) { |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
397 |
// java.lang.System not yet fully initialized |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
398 |
return; |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
399 |
} |
2 | 400 |
|
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
401 |
Properties props = GetPropertyAction.getProperties(); |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
402 |
String val = props.getProperty("sun.reflect.noInflation"); |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
403 |
if (val != null && val.equals("true")) { |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
404 |
noInflation = true; |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
405 |
} |
2 | 406 |
|
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
407 |
val = props.getProperty("sun.reflect.inflationThreshold"); |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
408 |
if (val != null) { |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
409 |
try { |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
410 |
inflationThreshold = Integer.parseInt(val); |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
411 |
} catch (NumberFormatException e) { |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
412 |
throw new RuntimeException("Unable to parse property sun.reflect.inflationThreshold", e); |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
413 |
} |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
414 |
} |
2 | 415 |
|
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
37363
diff
changeset
|
416 |
initted = true; |
2 | 417 |
} |
418 |
||
419 |
private static LangReflectAccess langReflectAccess() { |
|
420 |
if (langReflectAccess == null) { |
|
421 |
// Call a static method to get class java.lang.reflect.Modifier |
|
422 |
// initialized. Its static initializer will cause |
|
423 |
// setLangReflectAccess() to be called from the context of the |
|
424 |
// java.lang.reflect package. |
|
425 |
Modifier.isPublic(Modifier.PUBLIC); |
|
426 |
} |
|
427 |
return langReflectAccess; |
|
428 |
} |
|
429 |
} |