1 /* |
1 /* |
2 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
164 result[index] = (jclass) env->jni_reference(get_element(index)); |
164 result[index] = (jclass) env->jni_reference(get_element(index)); |
165 } |
165 } |
166 } |
166 } |
167 |
167 |
168 // Finally, the static methods that are the callbacks |
168 // Finally, the static methods that are the callbacks |
169 static void increment(klassOop k) { |
169 static void increment(Klass* k) { |
170 JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this(); |
170 JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this(); |
171 if (that->get_initiatingLoader() == NULL) { |
171 if (that->get_initiatingLoader() == NULL) { |
172 for (klassOop l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) { |
172 for (Klass* l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) { |
173 that->set_count(that->get_count() + 1); |
173 that->set_count(that->get_count() + 1); |
174 } |
174 } |
175 } else if (k != NULL) { |
175 } else if (k != NULL) { |
176 // if initiating loader not null, just include the instance with 1 dimension |
176 // if initiating loader not null, just include the instance with 1 dimension |
177 that->set_count(that->get_count() + 1); |
177 that->set_count(that->get_count() + 1); |
178 } |
178 } |
179 } |
179 } |
180 |
180 |
181 static void increment_with_loader(klassOop k, oop loader) { |
181 static void increment_with_loader(Klass* k, ClassLoaderData* loader_data) { |
182 JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this(); |
182 JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this(); |
183 if (loader == JNIHandles::resolve(that->get_initiatingLoader())) { |
183 oop class_loader = loader_data->class_loader(); |
184 for (klassOop l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) { |
184 if (class_loader == JNIHandles::resolve(that->get_initiatingLoader())) { |
|
185 for (Klass* l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) { |
185 that->set_count(that->get_count() + 1); |
186 that->set_count(that->get_count() + 1); |
186 } |
187 } |
187 } |
188 } |
188 } |
189 } |
189 |
190 |
190 static void prim_array_increment_with_loader(klassOop array, oop loader) { |
191 static void prim_array_increment_with_loader(Klass* array, ClassLoaderData* loader_data) { |
191 JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this(); |
192 JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this(); |
192 if (loader == JNIHandles::resolve(that->get_initiatingLoader())) { |
193 oop class_loader = loader_data->class_loader(); |
|
194 if (class_loader == JNIHandles::resolve(that->get_initiatingLoader())) { |
193 that->set_count(that->get_count() + 1); |
195 that->set_count(that->get_count() + 1); |
194 } |
196 } |
195 } |
197 } |
196 |
198 |
197 static void add(klassOop k) { |
199 static void add(Klass* k) { |
198 JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this(); |
200 JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this(); |
199 if (that->available()) { |
201 if (that->available()) { |
200 if (that->get_initiatingLoader() == NULL) { |
202 if (that->get_initiatingLoader() == NULL) { |
201 for (klassOop l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) { |
203 for (Klass* l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) { |
202 oop mirror = Klass::cast(l)->java_mirror(); |
204 oop mirror = Klass::cast(l)->java_mirror(); |
203 that->set_element(that->get_index(), mirror); |
205 that->set_element(that->get_index(), mirror); |
204 that->set_index(that->get_index() + 1); |
206 that->set_index(that->get_index() + 1); |
205 } |
207 } |
206 } else if (k != NULL) { |
208 } else if (k != NULL) { |
210 that->set_index(that->get_index() + 1); |
212 that->set_index(that->get_index() + 1); |
211 } |
213 } |
212 } |
214 } |
213 } |
215 } |
214 |
216 |
215 static void add_with_loader(klassOop k, oop loader) { |
217 static void add_with_loader(Klass* k, ClassLoaderData* loader_data) { |
216 JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this(); |
218 JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this(); |
217 if (that->available()) { |
219 if (that->available()) { |
218 if (loader == JNIHandles::resolve(that->get_initiatingLoader())) { |
220 oop class_loader = loader_data->class_loader(); |
219 for (klassOop l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) { |
221 if (class_loader == JNIHandles::resolve(that->get_initiatingLoader())) { |
|
222 for (Klass* l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) { |
220 oop mirror = Klass::cast(l)->java_mirror(); |
223 oop mirror = Klass::cast(l)->java_mirror(); |
221 that->set_element(that->get_index(), mirror); |
224 that->set_element(that->get_index(), mirror); |
222 that->set_index(that->get_index() + 1); |
225 that->set_index(that->get_index() + 1); |
223 } |
226 } |
224 } |
227 } |
226 } |
229 } |
227 |
230 |
228 // increment the count for the given basic type array class (and any |
231 // increment the count for the given basic type array class (and any |
229 // multi-dimensional arrays). For example, for [B we check for |
232 // multi-dimensional arrays). For example, for [B we check for |
230 // [[B, [[[B, .. and the count is incremented for each one that exists. |
233 // [[B, [[[B, .. and the count is incremented for each one that exists. |
231 static void increment_for_basic_type_arrays(klassOop k) { |
234 static void increment_for_basic_type_arrays(Klass* k) { |
232 JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this(); |
235 JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this(); |
233 assert(that != NULL, "no JvmtiGetLoadedClassesClosure"); |
236 assert(that != NULL, "no JvmtiGetLoadedClassesClosure"); |
234 for (klassOop l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) { |
237 for (Klass* l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) { |
235 that->set_count(that->get_count() + 1); |
238 that->set_count(that->get_count() + 1); |
236 } |
239 } |
237 } |
240 } |
238 |
241 |
239 // add the basic type array class and its multi-dimensional array classes to the list |
242 // add the basic type array class and its multi-dimensional array classes to the list |
240 static void add_for_basic_type_arrays(klassOop k) { |
243 static void add_for_basic_type_arrays(Klass* k) { |
241 JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this(); |
244 JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this(); |
242 assert(that != NULL, "no JvmtiGetLoadedClassesClosure"); |
245 assert(that != NULL, "no JvmtiGetLoadedClassesClosure"); |
243 assert(that->available(), "no list"); |
246 assert(that->available(), "no list"); |
244 for (klassOop l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) { |
247 for (Klass* l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) { |
245 oop mirror = Klass::cast(l)->java_mirror(); |
248 oop mirror = Klass::cast(l)->java_mirror(); |
246 that->set_element(that->get_index(), mirror); |
249 that->set_element(that->get_index(), mirror); |
247 that->set_index(that->get_index() + 1); |
250 that->set_index(that->get_index() + 1); |
248 } |
251 } |
249 } |
252 } |