author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 46329 | hotspot/src/share/vm/runtime/reflection.hpp@53ccc37bda19 |
child 50735 | 2f2af62dfac7 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
46262
83280d968b96
8174092: Remove array-related access checks from Reflection::verify_class_access()
hseigel
parents:
36508
diff
changeset
|
2 |
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
2332
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
2332
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
2332
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_RUNTIME_REFLECTION_HPP |
26 |
#define SHARE_VM_RUNTIME_REFLECTION_HPP |
|
27 |
||
28 |
#include "oops/oop.hpp" |
|
29 |
#include "runtime/fieldDescriptor.hpp" |
|
30 |
#include "utilities/accessFlags.hpp" |
|
31 |
#include "utilities/growableArray.hpp" |
|
32 |
||
1 | 33 |
// Class Reflection contains utility methods needed for implementing the |
34 |
// reflection api. |
|
35 |
// |
|
36 |
// Used by functions in the JVM interface. |
|
37 |
// |
|
38 |
// NOTE that in JDK 1.4 most of reflection is now implemented in Java |
|
39 |
// using dynamic bytecode generation. The Array class has not yet been |
|
40 |
// rewritten using bytecodes; if it were, most of the rest of this |
|
41 |
// class could go away, as well as a few more entry points in jvm.cpp. |
|
42 |
||
43 |
class FieldStream; |
|
44 |
||
45 |
class Reflection: public AllStatic { |
|
46 |
public: |
|
47 |
// Constants defined by java reflection api classes |
|
48 |
enum SomeConstants { |
|
49 |
PUBLIC = 0, |
|
50 |
DECLARED = 1, |
|
51 |
MEMBER_PUBLIC = 0, |
|
52 |
MEMBER_DECLARED = 1, |
|
53 |
MAX_DIM = 255 |
|
54 |
}; |
|
55 |
||
36508 | 56 |
// Results returned by verify_class_access() |
57 |
enum VerifyClassAccessResults { |
|
58 |
ACCESS_OK = 0, |
|
59 |
MODULE_NOT_READABLE = 1, |
|
60 |
TYPE_NOT_EXPORTED = 2, |
|
61 |
OTHER_PROBLEM = 3 |
|
62 |
}; |
|
63 |
||
1 | 64 |
// Boxing. Returns boxed value of appropriate type. Throws IllegalArgumentException. |
65 |
static oop box(jvalue* v, BasicType type, TRAPS); |
|
66 |
// Unboxing. Returns type code and sets value. |
|
67 |
static BasicType unbox_for_primitive(oop boxed_value, jvalue* value, TRAPS); |
|
68 |
static BasicType unbox_for_regular_object(oop boxed_value, jvalue* value); |
|
69 |
||
70 |
// Widening of basic types. Throws IllegalArgumentException. |
|
71 |
static void widen(jvalue* value, BasicType current_type, BasicType wide_type, TRAPS); |
|
72 |
||
73 |
// Reflective array access. Returns type code. Throws ArrayIndexOutOfBoundsException. |
|
74 |
static BasicType array_get(jvalue* value, arrayOop a, int index, TRAPS); |
|
75 |
static void array_set(jvalue* value, arrayOop a, int index, BasicType value_type, TRAPS); |
|
76 |
// Returns mirror on array element type (NULL for basic type arrays and non-arrays). |
|
77 |
static oop array_component_type(oop mirror, TRAPS); |
|
78 |
||
79 |
// Object creation |
|
80 |
static arrayOop reflect_new_array(oop element_mirror, jint length, TRAPS); |
|
81 |
static arrayOop reflect_new_multi_array(oop element_mirror, typeArrayOop dimensions, TRAPS); |
|
82 |
||
83 |
// Verification |
|
36508 | 84 |
static VerifyClassAccessResults verify_class_access(const Klass* current_class, |
46262
83280d968b96
8174092: Remove array-related access checks from Reflection::verify_class_access()
hseigel
parents:
36508
diff
changeset
|
85 |
const InstanceKlass* new_class, |
36508 | 86 |
bool classloader_only); |
87 |
// Return an error message specific to the specified Klass*'s and result. |
|
88 |
// This function must be called from within a block containing a ResourceMark. |
|
89 |
static char* verify_class_access_msg(const Klass* current_class, |
|
46262
83280d968b96
8174092: Remove array-related access checks from Reflection::verify_class_access()
hseigel
parents:
36508
diff
changeset
|
90 |
const InstanceKlass* new_class, |
36508 | 91 |
const VerifyClassAccessResults result); |
1 | 92 |
|
34666 | 93 |
static bool verify_field_access(const Klass* current_class, |
94 |
const Klass* resolved_class, |
|
95 |
const Klass* field_class, |
|
1 | 96 |
AccessFlags access, |
97 |
bool classloader_only, |
|
98 |
bool protected_restriction = false); |
|
34666 | 99 |
static bool is_same_class_package(const Klass* class1, const Klass* class2); |
1 | 100 |
|
101 |
// inner class reflection |
|
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
1
diff
changeset
|
102 |
// raise an ICCE unless the required relationship can be proven to hold |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
1
diff
changeset
|
103 |
// If inner_is_member, require the inner to be a member of the outer. |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
1
diff
changeset
|
104 |
// If !inner_is_member, require the inner to be anonymous (a non-member). |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
1
diff
changeset
|
105 |
// Caller is responsible for figuring out in advance which case must be true. |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46262
diff
changeset
|
106 |
static void check_for_inner_class(const InstanceKlass* outer, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46262
diff
changeset
|
107 |
const InstanceKlass* inner, |
34666 | 108 |
bool inner_is_member, |
109 |
TRAPS); |
|
1 | 110 |
|
111 |
// |
|
112 |
// Support for reflection based on dynamic bytecode generation (JDK 1.4) |
|
113 |
// |
|
114 |
||
115 |
// Create a java.lang.reflect.Method object based on a method |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
25057
diff
changeset
|
116 |
static oop new_method(const methodHandle& method, bool for_constant_pool_access, TRAPS); |
1 | 117 |
// Create a java.lang.reflect.Constructor object based on a method |
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
25057
diff
changeset
|
118 |
static oop new_constructor(const methodHandle& method, TRAPS); |
1 | 119 |
// Create a java.lang.reflect.Field object based on a field descriptor |
24456
8c7933fa5a1f
8025580: Temporary flags: UseNewReflection and ReflectionWrapResolutionErrors
coleenp
parents:
22551
diff
changeset
|
120 |
static oop new_field(fieldDescriptor* fd, TRAPS); |
15102
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
13728
diff
changeset
|
121 |
// Create a java.lang.reflect.Parameter object based on a |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
13728
diff
changeset
|
122 |
// MethodParameterElement |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
13728
diff
changeset
|
123 |
static oop new_parameter(Handle method, int index, Symbol* sym, |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
13728
diff
changeset
|
124 |
int flags, TRAPS); |
22551 | 125 |
// Method invocation through java.lang.reflect.Method |
34666 | 126 |
static oop invoke_method(oop method_mirror, |
127 |
Handle receiver, |
|
128 |
objArrayHandle args, |
|
129 |
TRAPS); |
|
22551 | 130 |
// Method invocation through java.lang.reflect.Constructor |
1 | 131 |
static oop invoke_constructor(oop method_mirror, objArrayHandle args, TRAPS); |
132 |
||
133 |
}; |
|
7397 | 134 |
|
135 |
#endif // SHARE_VM_RUNTIME_REFLECTION_HPP |