author | mchung |
Tue, 23 Jul 2019 20:03:03 -0700 | |
changeset 57503 | 042dfb697624 |
parent 52020 | 4c247dde38ed |
permissions | -rw-r--r-- |
2 | 1 |
/* |
57503
042dfb697624
8219774: Reexamine the initialization of LangReflectAccess shared secret at AccessibleObject::<clinit>
mchung
parents:
52020
diff
changeset
|
2 |
* Copyright (c) 2001, 2019, 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 |
||
26 |
package java.lang.reflect; |
|
27 |
||
37363
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
32268
diff
changeset
|
28 |
import jdk.internal.reflect.MethodAccessor; |
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
32268
diff
changeset
|
29 |
import jdk.internal.reflect.ConstructorAccessor; |
2 | 30 |
|
31 |
/** Package-private class implementing the |
|
57503
042dfb697624
8219774: Reexamine the initialization of LangReflectAccess shared secret at AccessibleObject::<clinit>
mchung
parents:
52020
diff
changeset
|
32 |
jdk.internal.access.JavaLangReflectAccess interface, allowing the java.lang |
2 | 33 |
package to instantiate objects in this package. */ |
34 |
||
57503
042dfb697624
8219774: Reexamine the initialization of LangReflectAccess shared secret at AccessibleObject::<clinit>
mchung
parents:
52020
diff
changeset
|
35 |
class ReflectAccess implements jdk.internal.access.JavaLangReflectAccess { |
2 | 36 |
public <T> Constructor<T> newConstructor(Class<T> declaringClass, |
3959
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
2
diff
changeset
|
37 |
Class<?>[] parameterTypes, |
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
2
diff
changeset
|
38 |
Class<?>[] checkedExceptions, |
2 | 39 |
int modifiers, |
40 |
int slot, |
|
41 |
String signature, |
|
42 |
byte[] annotations, |
|
43 |
byte[] parameterAnnotations) |
|
44 |
{ |
|
7803
56bc97d69d93
6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents:
5506
diff
changeset
|
45 |
return new Constructor<>(declaringClass, |
2 | 46 |
parameterTypes, |
47 |
checkedExceptions, |
|
48 |
modifiers, |
|
49 |
slot, |
|
50 |
signature, |
|
51 |
annotations, |
|
52 |
parameterAnnotations); |
|
53 |
} |
|
54 |
||
55 |
public MethodAccessor getMethodAccessor(Method m) { |
|
56 |
return m.getMethodAccessor(); |
|
57 |
} |
|
58 |
||
59 |
public void setMethodAccessor(Method m, MethodAccessor accessor) { |
|
60 |
m.setMethodAccessor(accessor); |
|
61 |
} |
|
62 |
||
3959
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
2
diff
changeset
|
63 |
public ConstructorAccessor getConstructorAccessor(Constructor<?> c) { |
2 | 64 |
return c.getConstructorAccessor(); |
65 |
} |
|
66 |
||
3959
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
2
diff
changeset
|
67 |
public void setConstructorAccessor(Constructor<?> c, |
2 | 68 |
ConstructorAccessor accessor) |
69 |
{ |
|
70 |
c.setConstructorAccessor(accessor); |
|
71 |
} |
|
72 |
||
3959
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
2
diff
changeset
|
73 |
public int getConstructorSlot(Constructor<?> c) { |
2 | 74 |
return c.getSlot(); |
75 |
} |
|
76 |
||
3959
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
2
diff
changeset
|
77 |
public String getConstructorSignature(Constructor<?> c) { |
2 | 78 |
return c.getSignature(); |
79 |
} |
|
80 |
||
3959
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
2
diff
changeset
|
81 |
public byte[] getConstructorAnnotations(Constructor<?> c) { |
2 | 82 |
return c.getRawAnnotations(); |
83 |
} |
|
84 |
||
3959
05a07c0a273b
5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents:
2
diff
changeset
|
85 |
public byte[] getConstructorParameterAnnotations(Constructor<?> c) { |
2 | 86 |
return c.getRawParameterAnnotations(); |
87 |
} |
|
88 |
||
15510
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
9035
diff
changeset
|
89 |
public byte[] getExecutableTypeAnnotationBytes(Executable ex) { |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
9035
diff
changeset
|
90 |
return ex.getTypeAnnotationBytes(); |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
9035
diff
changeset
|
91 |
} |
898d924a7efd
8004698: Implement Core Reflection for Type Annotations
jfranck
parents:
9035
diff
changeset
|
92 |
|
42997
5f83f2054eca
8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents:
42948
diff
changeset
|
93 |
public Class<?>[] getExecutableSharedParameterTypes(Executable ex) { |
5f83f2054eca
8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents:
42948
diff
changeset
|
94 |
return ex.getSharedParameterTypes(); |
5f83f2054eca
8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents:
42948
diff
changeset
|
95 |
} |
5f83f2054eca
8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents:
42948
diff
changeset
|
96 |
|
2 | 97 |
// |
98 |
// Copying routines, needed to quickly fabricate new Field, |
|
99 |
// Method, and Constructor objects from templates |
|
100 |
// |
|
101 |
public Method copyMethod(Method arg) { |
|
102 |
return arg.copy(); |
|
103 |
} |
|
32268
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
25859
diff
changeset
|
104 |
public Method leafCopyMethod(Method arg) { |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
25859
diff
changeset
|
105 |
return arg.leafCopy(); |
9fe7ee60d49d
8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents:
25859
diff
changeset
|
106 |
} |
2 | 107 |
|
108 |
public Field copyField(Field arg) { |
|
109 |
return arg.copy(); |
|
110 |
} |
|
111 |
||
112 |
public <T> Constructor<T> copyConstructor(Constructor<T> arg) { |
|
113 |
return arg.copy(); |
|
114 |
} |
|
50091
05979f6ba560
8202113: Reflection API is causing caller classes to leak
mchung
parents:
47216
diff
changeset
|
115 |
|
05979f6ba560
8202113: Reflection API is causing caller classes to leak
mchung
parents:
47216
diff
changeset
|
116 |
@SuppressWarnings("unchecked") |
05979f6ba560
8202113: Reflection API is causing caller classes to leak
mchung
parents:
47216
diff
changeset
|
117 |
public <T extends AccessibleObject> T getRoot(T obj) { |
05979f6ba560
8202113: Reflection API is causing caller classes to leak
mchung
parents:
47216
diff
changeset
|
118 |
return (T) obj.getRoot(); |
05979f6ba560
8202113: Reflection API is causing caller classes to leak
mchung
parents:
47216
diff
changeset
|
119 |
} |
52020
4c247dde38ed
8206240: java.lang.Class.newInstance() is causing caller to leak
mchung
parents:
50091
diff
changeset
|
120 |
|
4c247dde38ed
8206240: java.lang.Class.newInstance() is causing caller to leak
mchung
parents:
50091
diff
changeset
|
121 |
public <T> T newInstance(Constructor<T> ctor, Object[] args, Class<?> caller) |
4c247dde38ed
8206240: java.lang.Class.newInstance() is causing caller to leak
mchung
parents:
50091
diff
changeset
|
122 |
throws IllegalAccessException, InstantiationException, InvocationTargetException |
4c247dde38ed
8206240: java.lang.Class.newInstance() is causing caller to leak
mchung
parents:
50091
diff
changeset
|
123 |
{ |
4c247dde38ed
8206240: java.lang.Class.newInstance() is causing caller to leak
mchung
parents:
50091
diff
changeset
|
124 |
return ctor.newInstanceWithCaller(args, true, caller); |
4c247dde38ed
8206240: java.lang.Class.newInstance() is causing caller to leak
mchung
parents:
50091
diff
changeset
|
125 |
} |
2 | 126 |
} |