author | mgerdin |
Thu, 23 Feb 2012 14:58:35 +0100 | |
changeset 12095 | cc3d6f08a4c4 |
parent 10504 | 754cf4e432f4 |
child 13728 | 882756847a04 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
8921
14bfe81f2a9d
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents:
8076
diff
changeset
|
2 |
* Copyright (c) 1997, 2011, 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 |
private: |
|
47 |
// Access checking |
|
48 |
static bool reflect_check_access(klassOop field_class, AccessFlags acc, klassOop target_class, bool is_method_invoke, TRAPS); |
|
49 |
||
50 |
// Conversion |
|
51 |
static klassOop basic_type_mirror_to_arrayklass(oop basic_type_mirror, TRAPS); |
|
52 |
static oop basic_type_arrayklass_to_mirror(klassOop basic_type_arrayklass, TRAPS); |
|
53 |
||
54 |
static objArrayHandle get_parameter_types(methodHandle method, int parameter_count, oop* return_type, TRAPS); |
|
55 |
static objArrayHandle get_exception_types(methodHandle method, TRAPS); |
|
56 |
// Creating new java.lang.reflect.xxx wrappers |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
57 |
static Handle new_type(Symbol* signature, KlassHandle k, TRAPS); |
1 | 58 |
|
59 |
public: |
|
60 |
// Constants defined by java reflection api classes |
|
61 |
enum SomeConstants { |
|
62 |
PUBLIC = 0, |
|
63 |
DECLARED = 1, |
|
64 |
MEMBER_PUBLIC = 0, |
|
65 |
MEMBER_DECLARED = 1, |
|
66 |
MAX_DIM = 255 |
|
67 |
}; |
|
68 |
||
69 |
// Boxing. Returns boxed value of appropriate type. Throws IllegalArgumentException. |
|
70 |
static oop box(jvalue* v, BasicType type, TRAPS); |
|
71 |
// Unboxing. Returns type code and sets value. |
|
72 |
static BasicType unbox_for_primitive(oop boxed_value, jvalue* value, TRAPS); |
|
73 |
static BasicType unbox_for_regular_object(oop boxed_value, jvalue* value); |
|
74 |
||
75 |
// Widening of basic types. Throws IllegalArgumentException. |
|
76 |
static void widen(jvalue* value, BasicType current_type, BasicType wide_type, TRAPS); |
|
77 |
||
78 |
// Reflective array access. Returns type code. Throws ArrayIndexOutOfBoundsException. |
|
79 |
static BasicType array_get(jvalue* value, arrayOop a, int index, TRAPS); |
|
80 |
static void array_set(jvalue* value, arrayOop a, int index, BasicType value_type, TRAPS); |
|
81 |
// Returns mirror on array element type (NULL for basic type arrays and non-arrays). |
|
82 |
static oop array_component_type(oop mirror, TRAPS); |
|
83 |
||
84 |
// Object creation |
|
85 |
static arrayOop reflect_new_array(oop element_mirror, jint length, TRAPS); |
|
86 |
static arrayOop reflect_new_multi_array(oop element_mirror, typeArrayOop dimensions, TRAPS); |
|
87 |
||
88 |
// Verification |
|
89 |
static bool verify_class_access(klassOop current_class, klassOop new_class, bool classloader_only); |
|
90 |
||
91 |
static bool verify_field_access(klassOop current_class, |
|
92 |
klassOop resolved_class, |
|
93 |
klassOop field_class, |
|
94 |
AccessFlags access, |
|
95 |
bool classloader_only, |
|
96 |
bool protected_restriction = false); |
|
97 |
static bool is_same_class_package(klassOop class1, klassOop class2); |
|
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
1
diff
changeset
|
98 |
static bool is_same_package_member(klassOop class1, klassOop class2, TRAPS); |
1 | 99 |
|
100 |
static bool can_relax_access_check_for( |
|
101 |
klassOop accessor, klassOop accesee, bool classloader_only); |
|
102 |
||
103 |
// inner class reflection |
|
2332
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
1
diff
changeset
|
104 |
// 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
|
105 |
// 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
|
106 |
// 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
|
107 |
// Caller is responsible for figuring out in advance which case must be true. |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
1
diff
changeset
|
108 |
static void check_for_inner_class(instanceKlassHandle outer, instanceKlassHandle inner, |
5c7b6f4ce0a1
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
1
diff
changeset
|
109 |
bool inner_is_member, 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 |
|
116 |
static oop new_method(methodHandle method, bool intern_name, bool for_constant_pool_access, TRAPS); |
|
117 |
// Create a java.lang.reflect.Constructor object based on a method |
|
118 |
static oop new_constructor(methodHandle method, TRAPS); |
|
119 |
// Create a java.lang.reflect.Field object based on a field descriptor |
|
120 |
static oop new_field(fieldDescriptor* fd, bool intern_name, TRAPS); |
|
121 |
||
122 |
private: |
|
123 |
// method resolution for invoke |
|
124 |
static methodHandle resolve_interface_call(instanceKlassHandle klass, methodHandle method, KlassHandle recv_klass, Handle receiver, TRAPS); |
|
125 |
// Method call (shared by invoke_method and invoke_constructor) |
|
126 |
static oop invoke(instanceKlassHandle klass, methodHandle method, Handle receiver, bool override, objArrayHandle ptypes, BasicType rtype, objArrayHandle args, bool is_method_invoke, TRAPS); |
|
127 |
||
128 |
// Narrowing of basic types. Used to create correct jvalues for |
|
129 |
// boolean, byte, char and short return return values from interpreter |
|
130 |
// which are returned as ints. Throws IllegalArgumentException. |
|
131 |
static void narrow(jvalue* value, BasicType narrow_type, TRAPS); |
|
132 |
||
133 |
// Conversion |
|
134 |
static BasicType basic_type_mirror_to_basic_type(oop basic_type_mirror, TRAPS); |
|
135 |
||
136 |
public: |
|
137 |
// Method invokation through java.lang.reflect.Method |
|
138 |
static oop invoke_method(oop method_mirror, Handle receiver, objArrayHandle args, TRAPS); |
|
139 |
// Method invokation through java.lang.reflect.Constructor |
|
140 |
static oop invoke_constructor(oop method_mirror, objArrayHandle args, TRAPS); |
|
141 |
||
142 |
}; |
|
7397 | 143 |
|
144 |
#endif // SHARE_VM_RUNTIME_REFLECTION_HPP |