annotate src/share/vm/prims/jvmtiGetLoadedClasses.cpp @ 973:ad6585fd4087

6830542: Performance: JVM_DefineClass already verified. Reviewed-by: kamg, phh
author acorn
date Fri, 04 Sep 2009 12:53:02 -0400
parents a61af66fc99e
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
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
a61af66fc99e Initial load
duke
parents:
diff changeset
26 # include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27 # include "incls/_jvmtiGetLoadedClasses.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // The closure for GetLoadedClasses and GetClassLoaderClasses
a61af66fc99e Initial load
duke
parents:
diff changeset
31 class JvmtiGetLoadedClassesClosure : public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // Since the SystemDictionary::classes_do callback
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // doesn't pass a closureData pointer,
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // we use a thread-local slot to hold a pointer to
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // a stack allocated instance of this structure.
a61af66fc99e Initial load
duke
parents:
diff changeset
36 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
37 jobject _initiatingLoader;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 int _count;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 Handle* _list;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 int _index;
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // Getting and setting the thread local pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
44 static JvmtiGetLoadedClassesClosure* get_this() {
a61af66fc99e Initial load
duke
parents:
diff changeset
45 JvmtiGetLoadedClassesClosure* result = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 JavaThread* thread = JavaThread::current();
a61af66fc99e Initial load
duke
parents:
diff changeset
47 result = thread->get_jvmti_get_loaded_classes_closure();
a61af66fc99e Initial load
duke
parents:
diff changeset
48 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 }
a61af66fc99e Initial load
duke
parents:
diff changeset
50 static void set_this(JvmtiGetLoadedClassesClosure* that) {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 JavaThread* thread = JavaThread::current();
a61af66fc99e Initial load
duke
parents:
diff changeset
52 thread->set_jvmti_get_loaded_classes_closure(that);
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // Constructor/Destructor
a61af66fc99e Initial load
duke
parents:
diff changeset
57 JvmtiGetLoadedClassesClosure() {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 JvmtiGetLoadedClassesClosure* that = get_this();
a61af66fc99e Initial load
duke
parents:
diff changeset
59 assert(that == NULL, "JvmtiGetLoadedClassesClosure in use");
a61af66fc99e Initial load
duke
parents:
diff changeset
60 _initiatingLoader = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 _count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 _list = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 _index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 set_this(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 JvmtiGetLoadedClassesClosure(jobject initiatingLoader) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 JvmtiGetLoadedClassesClosure* that = get_this();
a61af66fc99e Initial load
duke
parents:
diff changeset
69 assert(that == NULL, "JvmtiGetLoadedClassesClosure in use");
a61af66fc99e Initial load
duke
parents:
diff changeset
70 _initiatingLoader = initiatingLoader;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 _count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 _list = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 _index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 set_this(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 ~JvmtiGetLoadedClassesClosure() {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 JvmtiGetLoadedClassesClosure* that = get_this();
a61af66fc99e Initial load
duke
parents:
diff changeset
79 assert(that != NULL, "JvmtiGetLoadedClassesClosure not found");
a61af66fc99e Initial load
duke
parents:
diff changeset
80 set_this(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
81 _initiatingLoader = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 _count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 if (_list != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 FreeHeap(_list);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 _list = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87 _index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // Accessors.
a61af66fc99e Initial load
duke
parents:
diff changeset
91 jobject get_initiatingLoader() {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 return _initiatingLoader;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 int get_count() {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 return _count;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 void set_count(int value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 _count = value;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 Handle* get_list() {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 return _list;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 void set_list(Handle* value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 _list = value;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 int get_index() {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 return _index;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 void set_index(int value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 _index = value;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 Handle get_element(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 if ((_list != NULL) && (index < _count)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 return _list[index];
a61af66fc99e Initial load
duke
parents:
diff changeset
122 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 assert(false, "empty get_element");
a61af66fc99e Initial load
duke
parents:
diff changeset
124 return Handle();
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 void set_element(int index, Handle value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 if ((_list != NULL) && (index < _count)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 _list[index] = value;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 assert(false, "bad set_element");
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // Other predicates
a61af66fc99e Initial load
duke
parents:
diff changeset
137 bool available() {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 return (_list != NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // For debugging.
a61af66fc99e Initial load
duke
parents:
diff changeset
143 void check(int limit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 for (int i = 0; i < limit; i += 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 assert(Universe::heap()->is_in(get_element(i)()), "check fails");
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // Public methods that get called within the scope of the closure
a61af66fc99e Initial load
duke
parents:
diff changeset
151 void allocate() {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 _list = NEW_C_HEAP_ARRAY(Handle, _count);
a61af66fc99e Initial load
duke
parents:
diff changeset
153 assert(_list != NULL, "Out of memory");
a61af66fc99e Initial load
duke
parents:
diff changeset
154 if (_list == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 _count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 void extract(JvmtiEnv *env, jclass* result) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 for (int index = 0; index < _count; index += 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 result[index] = (jclass) env->jni_reference(get_element(index));
a61af66fc99e Initial load
duke
parents:
diff changeset
162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 // Finally, the static methods that are the callbacks
a61af66fc99e Initial load
duke
parents:
diff changeset
166 static void increment(klassOop k) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this();
a61af66fc99e Initial load
duke
parents:
diff changeset
168 if (that->get_initiatingLoader() == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 for (klassOop l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 that->set_count(that->get_count() + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172 } else if (k != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // if initiating loader not null, just include the instance with 1 dimension
a61af66fc99e Initial load
duke
parents:
diff changeset
174 that->set_count(that->get_count() + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 static void increment_with_loader(klassOop k, oop loader) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this();
a61af66fc99e Initial load
duke
parents:
diff changeset
180 if (loader == JNIHandles::resolve(that->get_initiatingLoader())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 for (klassOop l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
182 that->set_count(that->get_count() + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 static void prim_array_increment_with_loader(klassOop array, oop loader) {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this();
a61af66fc99e Initial load
duke
parents:
diff changeset
189 if (loader == JNIHandles::resolve(that->get_initiatingLoader())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 that->set_count(that->get_count() + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 static void add(klassOop k) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this();
a61af66fc99e Initial load
duke
parents:
diff changeset
196 if (that->available()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 if (that->get_initiatingLoader() == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
198 for (klassOop l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 oop mirror = Klass::cast(l)->java_mirror();
a61af66fc99e Initial load
duke
parents:
diff changeset
200 that->set_element(that->get_index(), mirror);
a61af66fc99e Initial load
duke
parents:
diff changeset
201 that->set_index(that->get_index() + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203 } else if (k != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 // if initiating loader not null, just include the instance with 1 dimension
a61af66fc99e Initial load
duke
parents:
diff changeset
205 oop mirror = Klass::cast(k)->java_mirror();
a61af66fc99e Initial load
duke
parents:
diff changeset
206 that->set_element(that->get_index(), mirror);
a61af66fc99e Initial load
duke
parents:
diff changeset
207 that->set_index(that->get_index() + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 static void add_with_loader(klassOop k, oop loader) {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this();
a61af66fc99e Initial load
duke
parents:
diff changeset
214 if (that->available()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
215 if (loader == JNIHandles::resolve(that->get_initiatingLoader())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
216 for (klassOop l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 oop mirror = Klass::cast(l)->java_mirror();
a61af66fc99e Initial load
duke
parents:
diff changeset
218 that->set_element(that->get_index(), mirror);
a61af66fc99e Initial load
duke
parents:
diff changeset
219 that->set_index(that->get_index() + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222 }
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224
a61af66fc99e Initial load
duke
parents:
diff changeset
225 // increment the count for the given basic type array class (and any
a61af66fc99e Initial load
duke
parents:
diff changeset
226 // multi-dimensional arrays). For example, for [B we check for
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // [[B, [[[B, .. and the count is incremented for each one that exists.
a61af66fc99e Initial load
duke
parents:
diff changeset
228 static void increment_for_basic_type_arrays(klassOop k) {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this();
a61af66fc99e Initial load
duke
parents:
diff changeset
230 assert(that != NULL, "no JvmtiGetLoadedClassesClosure");
a61af66fc99e Initial load
duke
parents:
diff changeset
231 for (klassOop l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
232 that->set_count(that->get_count() + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
233 }
a61af66fc99e Initial load
duke
parents:
diff changeset
234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
235
a61af66fc99e Initial load
duke
parents:
diff changeset
236 // add the basic type array class and its multi-dimensional array classes to the list
a61af66fc99e Initial load
duke
parents:
diff changeset
237 static void add_for_basic_type_arrays(klassOop k) {
a61af66fc99e Initial load
duke
parents:
diff changeset
238 JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this();
a61af66fc99e Initial load
duke
parents:
diff changeset
239 assert(that != NULL, "no JvmtiGetLoadedClassesClosure");
a61af66fc99e Initial load
duke
parents:
diff changeset
240 assert(that->available(), "no list");
a61af66fc99e Initial load
duke
parents:
diff changeset
241 for (klassOop l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 oop mirror = Klass::cast(l)->java_mirror();
a61af66fc99e Initial load
duke
parents:
diff changeset
243 that->set_element(that->get_index(), mirror);
a61af66fc99e Initial load
duke
parents:
diff changeset
244 that->set_index(that->get_index() + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
245 }
a61af66fc99e Initial load
duke
parents:
diff changeset
246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
247 };
a61af66fc99e Initial load
duke
parents:
diff changeset
248
a61af66fc99e Initial load
duke
parents:
diff changeset
249
a61af66fc99e Initial load
duke
parents:
diff changeset
250 jvmtiError
a61af66fc99e Initial load
duke
parents:
diff changeset
251 JvmtiGetLoadedClasses::getLoadedClasses(JvmtiEnv *env, jint* classCountPtr, jclass** classesPtr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
252 // Since SystemDictionary::classes_do only takes a function pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
253 // and doesn't call back with a closure data pointer,
a61af66fc99e Initial load
duke
parents:
diff changeset
254 // we can only pass static methods.
a61af66fc99e Initial load
duke
parents:
diff changeset
255
a61af66fc99e Initial load
duke
parents:
diff changeset
256 JvmtiGetLoadedClassesClosure closure;
a61af66fc99e Initial load
duke
parents:
diff changeset
257 {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 // To get a consistent list of classes we need MultiArray_lock to ensure
a61af66fc99e Initial load
duke
parents:
diff changeset
259 // array classes aren't created, and SystemDictionary_lock to ensure that
a61af66fc99e Initial load
duke
parents:
diff changeset
260 // classes aren't added to the system dictionary,
a61af66fc99e Initial load
duke
parents:
diff changeset
261 MutexLocker ma(MultiArray_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
262 MutexLocker sd(SystemDictionary_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
263
a61af66fc99e Initial load
duke
parents:
diff changeset
264 // First, count the classes
a61af66fc99e Initial load
duke
parents:
diff changeset
265 SystemDictionary::classes_do(&JvmtiGetLoadedClassesClosure::increment);
a61af66fc99e Initial load
duke
parents:
diff changeset
266 Universe::basic_type_classes_do(&JvmtiGetLoadedClassesClosure::increment);
a61af66fc99e Initial load
duke
parents:
diff changeset
267 // Next, fill in the classes
a61af66fc99e Initial load
duke
parents:
diff changeset
268 closure.allocate();
a61af66fc99e Initial load
duke
parents:
diff changeset
269 SystemDictionary::classes_do(&JvmtiGetLoadedClassesClosure::add);
a61af66fc99e Initial load
duke
parents:
diff changeset
270 Universe::basic_type_classes_do(&JvmtiGetLoadedClassesClosure::add);
a61af66fc99e Initial load
duke
parents:
diff changeset
271 // Drop the SystemDictionary_lock, so the results could be wrong from here,
a61af66fc99e Initial load
duke
parents:
diff changeset
272 // but we still have a snapshot.
a61af66fc99e Initial load
duke
parents:
diff changeset
273 }
a61af66fc99e Initial load
duke
parents:
diff changeset
274 // Post results
a61af66fc99e Initial load
duke
parents:
diff changeset
275 jclass* result_list;
a61af66fc99e Initial load
duke
parents:
diff changeset
276 jvmtiError err = env->Allocate(closure.get_count() * sizeof(jclass),
a61af66fc99e Initial load
duke
parents:
diff changeset
277 (unsigned char**)&result_list);
a61af66fc99e Initial load
duke
parents:
diff changeset
278 if (err != JVMTI_ERROR_NONE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
279 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
280 }
a61af66fc99e Initial load
duke
parents:
diff changeset
281 closure.extract(env, result_list);
a61af66fc99e Initial load
duke
parents:
diff changeset
282 *classCountPtr = closure.get_count();
a61af66fc99e Initial load
duke
parents:
diff changeset
283 *classesPtr = result_list;
a61af66fc99e Initial load
duke
parents:
diff changeset
284 return JVMTI_ERROR_NONE;
a61af66fc99e Initial load
duke
parents:
diff changeset
285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
286
a61af66fc99e Initial load
duke
parents:
diff changeset
287 jvmtiError
a61af66fc99e Initial load
duke
parents:
diff changeset
288 JvmtiGetLoadedClasses::getClassLoaderClasses(JvmtiEnv *env, jobject initiatingLoader,
a61af66fc99e Initial load
duke
parents:
diff changeset
289 jint* classCountPtr, jclass** classesPtr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
290 // Since SystemDictionary::classes_do only takes a function pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
291 // and doesn't call back with a closure data pointer,
a61af66fc99e Initial load
duke
parents:
diff changeset
292 // we can only pass static methods.
a61af66fc99e Initial load
duke
parents:
diff changeset
293 JvmtiGetLoadedClassesClosure closure(initiatingLoader);
a61af66fc99e Initial load
duke
parents:
diff changeset
294 {
a61af66fc99e Initial load
duke
parents:
diff changeset
295 // To get a consistent list of classes we need MultiArray_lock to ensure
a61af66fc99e Initial load
duke
parents:
diff changeset
296 // array classes aren't created, and SystemDictionary_lock to ensure that
a61af66fc99e Initial load
duke
parents:
diff changeset
297 // classes aren't added to the system dictionary,
a61af66fc99e Initial load
duke
parents:
diff changeset
298 MutexLocker ma(MultiArray_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
299 MutexLocker sd(SystemDictionary_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
300 // First, count the classes in the system dictionary which have this loader recorded
a61af66fc99e Initial load
duke
parents:
diff changeset
301 // as an initiating loader. For basic type arrays this information is not recorded
a61af66fc99e Initial load
duke
parents:
diff changeset
302 // so GetClassLoaderClasses will return all of the basic type arrays. This is okay
a61af66fc99e Initial load
duke
parents:
diff changeset
303 // because the defining loader for basic type arrays is always the boot class loader
a61af66fc99e Initial load
duke
parents:
diff changeset
304 // and these classes are "visible" to all loaders.
a61af66fc99e Initial load
duke
parents:
diff changeset
305 SystemDictionary::classes_do(&JvmtiGetLoadedClassesClosure::increment_with_loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
306 Universe::basic_type_classes_do(&JvmtiGetLoadedClassesClosure::increment_for_basic_type_arrays);
a61af66fc99e Initial load
duke
parents:
diff changeset
307 // Next, fill in the classes
a61af66fc99e Initial load
duke
parents:
diff changeset
308 closure.allocate();
a61af66fc99e Initial load
duke
parents:
diff changeset
309 SystemDictionary::classes_do(&JvmtiGetLoadedClassesClosure::add_with_loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
310 Universe::basic_type_classes_do(&JvmtiGetLoadedClassesClosure::add_for_basic_type_arrays);
a61af66fc99e Initial load
duke
parents:
diff changeset
311 // Drop the SystemDictionary_lock, so the results could be wrong from here,
a61af66fc99e Initial load
duke
parents:
diff changeset
312 // but we still have a snapshot.
a61af66fc99e Initial load
duke
parents:
diff changeset
313 }
a61af66fc99e Initial load
duke
parents:
diff changeset
314 // Post results
a61af66fc99e Initial load
duke
parents:
diff changeset
315 jclass* result_list;
a61af66fc99e Initial load
duke
parents:
diff changeset
316 jvmtiError err = env->Allocate(closure.get_count() * sizeof(jclass),
a61af66fc99e Initial load
duke
parents:
diff changeset
317 (unsigned char**)&result_list);
a61af66fc99e Initial load
duke
parents:
diff changeset
318 if (err != JVMTI_ERROR_NONE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
319 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
320 }
a61af66fc99e Initial load
duke
parents:
diff changeset
321 closure.extract(env, result_list);
a61af66fc99e Initial load
duke
parents:
diff changeset
322 *classCountPtr = closure.get_count();
a61af66fc99e Initial load
duke
parents:
diff changeset
323 *classesPtr = result_list;
a61af66fc99e Initial load
duke
parents:
diff changeset
324 return JVMTI_ERROR_NONE;
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }