275 (unsigned char**)&result_list); 276 277 if (error == JVMTI_ERROR_NONE) { 278 int count = closure.extract(result_list); 279 *classCountPtr = count; 280 *classesPtr = result_list; 281 } 282 return error; 283 } 284 285 jvmtiError 286 JvmtiGetLoadedClasses::getClassLoaderClasses(JvmtiEnv *env, jobject initiatingLoader, 287 jint* classCountPtr, jclass** classesPtr) { 288 // Since ClassLoaderDataGraph::dictionary_all_entries_do only takes a function pointer 289 // and doesn't call back with a closure data pointer, 290 // we can only pass static methods. 291 JvmtiGetLoadedClassesClosure closure(initiatingLoader); 292 { 293 // To get a consistent list of classes we need MultiArray_lock to ensure 294 // array classes aren't created, and SystemDictionary_lock to ensure that 295 // classes aren't added to the system dictionary, 296 MutexLocker ma(MultiArray_lock); 297 MutexLocker sd(SystemDictionary_lock); 298 // First, count the classes in the system dictionary which have this loader recorded 299 // as an initiating loader. For basic type arrays this information is not recorded 300 // so GetClassLoaderClasses will return all of the basic type arrays. This is okay 301 // because the defining loader for basic type arrays is always the boot class loader 302 // and these classes are "visible" to all loaders. 303 ClassLoaderDataGraph::dictionary_all_entries_do(&JvmtiGetLoadedClassesClosure::increment_with_loader); 304 Universe::basic_type_classes_do(&JvmtiGetLoadedClassesClosure::increment_for_basic_type_arrays); 305 // Next, fill in the classes 306 closure.allocate(); 307 ClassLoaderDataGraph::dictionary_all_entries_do(&JvmtiGetLoadedClassesClosure::add_with_loader); 308 Universe::basic_type_classes_do(&JvmtiGetLoadedClassesClosure::add_for_basic_type_arrays); 309 // Drop the SystemDictionary_lock, so the results could be wrong from here, 310 // but we still have a snapshot. 311 } 312 // Post results 313 jclass* result_list; 314 jvmtiError err = env->Allocate(closure.get_count() * sizeof(jclass), 315 (unsigned char**)&result_list); 316 if (err != JVMTI_ERROR_NONE) { 317 return err; 318 } | 275 (unsigned char**)&result_list); 276 277 if (error == JVMTI_ERROR_NONE) { 278 int count = closure.extract(result_list); 279 *classCountPtr = count; 280 *classesPtr = result_list; 281 } 282 return error; 283 } 284 285 jvmtiError 286 JvmtiGetLoadedClasses::getClassLoaderClasses(JvmtiEnv *env, jobject initiatingLoader, 287 jint* classCountPtr, jclass** classesPtr) { 288 // Since ClassLoaderDataGraph::dictionary_all_entries_do only takes a function pointer 289 // and doesn't call back with a closure data pointer, 290 // we can only pass static methods. 291 JvmtiGetLoadedClassesClosure closure(initiatingLoader); 292 { 293 // To get a consistent list of classes we need MultiArray_lock to ensure 294 // array classes aren't created, and SystemDictionary_lock to ensure that 295 // classes aren't added to the class loader data dictionaries. 296 MutexLocker ma(MultiArray_lock); 297 MutexLocker sd(SystemDictionary_lock); 298 // First, count the classes in the class loader data dictionaries which have this loader recorded 299 // as an initiating loader. For basic type arrays this information is not recorded 300 // so GetClassLoaderClasses will return all of the basic type arrays. This is okay 301 // because the defining loader for basic type arrays is always the boot class loader 302 // and these classes are "visible" to all loaders. 303 ClassLoaderDataGraph::dictionary_all_entries_do(&JvmtiGetLoadedClassesClosure::increment_with_loader); 304 Universe::basic_type_classes_do(&JvmtiGetLoadedClassesClosure::increment_for_basic_type_arrays); 305 // Next, fill in the classes 306 closure.allocate(); 307 ClassLoaderDataGraph::dictionary_all_entries_do(&JvmtiGetLoadedClassesClosure::add_with_loader); 308 Universe::basic_type_classes_do(&JvmtiGetLoadedClassesClosure::add_for_basic_type_arrays); 309 // Drop the SystemDictionary_lock, so the results could be wrong from here, 310 // but we still have a snapshot. 311 } 312 // Post results 313 jclass* result_list; 314 jvmtiError err = env->Allocate(closure.get_count() * sizeof(jclass), 315 (unsigned char**)&result_list); 316 if (err != JVMTI_ERROR_NONE) { 317 return err; 318 } |