annotate src/share/vm/runtime/reflection.hpp @ 1145:e018e6884bd8

6631166: CMS: better heuristics when combatting fragmentation Summary: Autonomic per-worker free block cache sizing, tunable coalition policies, fixes to per-size block statistics, retuned gain and bandwidth of some feedback loop filters to allow quicker reactivity to abrupt changes in ambient demand, and other heuristics to reduce fragmentation of the CMS old gen. Also tightened some assertions, including those related to locking. Reviewed-by: jmasa
author ysr
date Wed, 23 Dec 2009 09:23:54 -0800
parents c89f86385056
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
665
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 // Class Reflection contains utility methods needed for implementing the
a61af66fc99e Initial load
duke
parents:
diff changeset
26 // reflection api.
a61af66fc99e Initial load
duke
parents:
diff changeset
27 //
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // Used by functions in the JVM interface.
a61af66fc99e Initial load
duke
parents:
diff changeset
29 //
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // NOTE that in JDK 1.4 most of reflection is now implemented in Java
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // using dynamic bytecode generation. The Array class has not yet been
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // rewritten using bytecodes; if it were, most of the rest of this
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // class could go away, as well as a few more entry points in jvm.cpp.
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 class FieldStream;
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 class Reflection: public AllStatic {
a61af66fc99e Initial load
duke
parents:
diff changeset
38 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // Access checking
a61af66fc99e Initial load
duke
parents:
diff changeset
40 static bool reflect_check_access(klassOop field_class, AccessFlags acc, klassOop target_class, bool is_method_invoke, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // Conversion
a61af66fc99e Initial load
duke
parents:
diff changeset
43 static klassOop basic_type_mirror_to_arrayklass(oop basic_type_mirror, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
44 static oop basic_type_arrayklass_to_mirror(klassOop basic_type_arrayklass, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 static objArrayHandle get_parameter_types(methodHandle method, int parameter_count, oop* return_type, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
47 static objArrayHandle get_exception_types(methodHandle method, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // Creating new java.lang.reflect.xxx wrappers
a61af66fc99e Initial load
duke
parents:
diff changeset
49 static Handle new_type(symbolHandle signature, KlassHandle k, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // Constants defined by java reflection api classes
a61af66fc99e Initial load
duke
parents:
diff changeset
53 enum SomeConstants {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 PUBLIC = 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
55 DECLARED = 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
56 MEMBER_PUBLIC = 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
57 MEMBER_DECLARED = 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
58 MAX_DIM = 255
a61af66fc99e Initial load
duke
parents:
diff changeset
59 };
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // Boxing. Returns boxed value of appropriate type. Throws IllegalArgumentException.
a61af66fc99e Initial load
duke
parents:
diff changeset
62 static oop box(jvalue* v, BasicType type, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // Unboxing. Returns type code and sets value.
a61af66fc99e Initial load
duke
parents:
diff changeset
64 static BasicType unbox_for_primitive(oop boxed_value, jvalue* value, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
65 static BasicType unbox_for_regular_object(oop boxed_value, jvalue* value);
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // Widening of basic types. Throws IllegalArgumentException.
a61af66fc99e Initial load
duke
parents:
diff changeset
68 static void widen(jvalue* value, BasicType current_type, BasicType wide_type, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // Reflective array access. Returns type code. Throws ArrayIndexOutOfBoundsException.
a61af66fc99e Initial load
duke
parents:
diff changeset
71 static BasicType array_get(jvalue* value, arrayOop a, int index, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
72 static void array_set(jvalue* value, arrayOop a, int index, BasicType value_type, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // Returns mirror on array element type (NULL for basic type arrays and non-arrays).
a61af66fc99e Initial load
duke
parents:
diff changeset
74 static oop array_component_type(oop mirror, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // Object creation
a61af66fc99e Initial load
duke
parents:
diff changeset
77 static arrayOop reflect_new_array(oop element_mirror, jint length, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
78 static arrayOop reflect_new_multi_array(oop element_mirror, typeArrayOop dimensions, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // Verification
a61af66fc99e Initial load
duke
parents:
diff changeset
81 static bool verify_class_access(klassOop current_class, klassOop new_class, bool classloader_only);
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 static bool verify_field_access(klassOop current_class,
a61af66fc99e Initial load
duke
parents:
diff changeset
84 klassOop resolved_class,
a61af66fc99e Initial load
duke
parents:
diff changeset
85 klassOop field_class,
a61af66fc99e Initial load
duke
parents:
diff changeset
86 AccessFlags access,
a61af66fc99e Initial load
duke
parents:
diff changeset
87 bool classloader_only,
a61af66fc99e Initial load
duke
parents:
diff changeset
88 bool protected_restriction = false);
a61af66fc99e Initial load
duke
parents:
diff changeset
89 static bool is_same_class_package(klassOop class1, klassOop class2);
665
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
90 static bool is_same_package_member(klassOop class1, klassOop class2, TRAPS);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 static bool can_relax_access_check_for(
a61af66fc99e Initial load
duke
parents:
diff changeset
93 klassOop accessor, klassOop accesee, bool classloader_only);
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // inner class reflection
665
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
96 // raise an ICCE unless the required relationship can be proven to hold
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
97 // If inner_is_member, require the inner to be a member of the outer.
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
98 // If !inner_is_member, require the inner to be anonymous (a non-member).
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
99 // Caller is responsible for figuring out in advance which case must be true.
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
100 static void check_for_inner_class(instanceKlassHandle outer, instanceKlassHandle inner,
c89f86385056 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 0
diff changeset
101 bool inner_is_member, TRAPS);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 //
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // Support for reflection based on dynamic bytecode generation (JDK 1.4)
a61af66fc99e Initial load
duke
parents:
diff changeset
105 //
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 // Create a java.lang.reflect.Method object based on a method
a61af66fc99e Initial load
duke
parents:
diff changeset
108 static oop new_method(methodHandle method, bool intern_name, bool for_constant_pool_access, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // Create a java.lang.reflect.Constructor object based on a method
a61af66fc99e Initial load
duke
parents:
diff changeset
110 static oop new_constructor(methodHandle method, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // Create a java.lang.reflect.Field object based on a field descriptor
a61af66fc99e Initial load
duke
parents:
diff changeset
112 static oop new_field(fieldDescriptor* fd, bool intern_name, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 //---------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
115 //
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // Support for old native code-based reflection (pre-JDK 1.4)
a61af66fc99e Initial load
duke
parents:
diff changeset
117 //
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // NOTE: the method and constructor invocation code is still used
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // for startup time reasons; see reflectionCompat.hpp.
a61af66fc99e Initial load
duke
parents:
diff changeset
120 //
a61af66fc99e Initial load
duke
parents:
diff changeset
121 //---------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 #ifdef SUPPORT_OLD_REFLECTION
a61af66fc99e Initial load
duke
parents:
diff changeset
124 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // method resolution for invoke
a61af66fc99e Initial load
duke
parents:
diff changeset
126 static methodHandle resolve_interface_call(instanceKlassHandle klass, methodHandle method, KlassHandle recv_klass, Handle receiver, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // Method call (shared by invoke_method and invoke_constructor)
a61af66fc99e Initial load
duke
parents:
diff changeset
128 static oop invoke(instanceKlassHandle klass, methodHandle method, Handle receiver, bool override, objArrayHandle ptypes, BasicType rtype, objArrayHandle args, bool is_method_invoke, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // Narrowing of basic types. Used to create correct jvalues for
a61af66fc99e Initial load
duke
parents:
diff changeset
131 // boolean, byte, char and short return return values from interpreter
a61af66fc99e Initial load
duke
parents:
diff changeset
132 // which are returned as ints. Throws IllegalArgumentException.
a61af66fc99e Initial load
duke
parents:
diff changeset
133 static void narrow(jvalue* value, BasicType narrow_type, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // Conversion
a61af66fc99e Initial load
duke
parents:
diff changeset
136 static BasicType basic_type_mirror_to_basic_type(oop basic_type_mirror, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 static bool match_parameter_types(methodHandle method, objArrayHandle types, int parameter_count, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // Creating new java.lang.reflect.xxx wrappers
a61af66fc99e Initial load
duke
parents:
diff changeset
140 static oop new_field(FieldStream* st, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // Field lookup and verification.
a61af66fc99e Initial load
duke
parents:
diff changeset
144 static bool resolve_field(Handle field_mirror, Handle& receiver, fieldDescriptor* fd, bool check_final, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // Reflective field access. Returns type code. Throws IllegalArgumentException.
a61af66fc99e Initial load
duke
parents:
diff changeset
147 static BasicType field_get(jvalue* value, fieldDescriptor* fd, Handle receiver);
a61af66fc99e Initial load
duke
parents:
diff changeset
148 static void field_set(jvalue* value, fieldDescriptor* fd, Handle receiver, BasicType value_type, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // Reflective lookup of fields. Returns java.lang.reflect.Field instances.
a61af66fc99e Initial load
duke
parents:
diff changeset
151 static oop reflect_field(oop mirror, symbolOop field_name, jint which, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
152 static objArrayOop reflect_fields(oop mirror, jint which, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // Reflective lookup of methods. Returns java.lang.reflect.Method instances.
a61af66fc99e Initial load
duke
parents:
diff changeset
155 static oop reflect_method(oop mirror, symbolHandle method_name, objArrayHandle types, jint which, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 static objArrayOop reflect_methods(oop mirror, jint which, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // Reflective lookup of constructors. Returns java.lang.reflect.Constructor instances.
a61af66fc99e Initial load
duke
parents:
diff changeset
159 static oop reflect_constructor(oop mirror, objArrayHandle types, jint which, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 static objArrayOop reflect_constructors(oop mirror, jint which, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 // Method invokation through java.lang.reflect.Method
a61af66fc99e Initial load
duke
parents:
diff changeset
163 static oop invoke_method(oop method_mirror, Handle receiver, objArrayHandle args, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
164 // Method invokation through java.lang.reflect.Constructor
a61af66fc99e Initial load
duke
parents:
diff changeset
165 static oop invoke_constructor(oop method_mirror, objArrayHandle args, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
166 #endif /* SUPPORT_OLD_REFLECTION */
a61af66fc99e Initial load
duke
parents:
diff changeset
167
a61af66fc99e Initial load
duke
parents:
diff changeset
168 };