1299 |
1299 |
1300 |
1300 |
1301 // Inner class reflection /////////////////////////////////////////////////////////////////////////////// |
1301 // Inner class reflection /////////////////////////////////////////////////////////////////////////////// |
1302 |
1302 |
1303 JVM_ENTRY(jobjectArray, JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass)) |
1303 JVM_ENTRY(jobjectArray, JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass)) |
1304 const int inner_class_info_index = 0; |
|
1305 const int outer_class_info_index = 1; |
|
1306 |
|
1307 JvmtiVMObjectAllocEventCollector oam; |
1304 JvmtiVMObjectAllocEventCollector oam; |
1308 // ofClass is a reference to a java_lang_Class object. The mirror object |
1305 // ofClass is a reference to a java_lang_Class object. The mirror object |
1309 // of an instanceKlass |
1306 // of an instanceKlass |
1310 |
1307 |
1311 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) || |
1308 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) || |
1313 oop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL); |
1310 oop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL); |
1314 return (jobjectArray)JNIHandles::make_local(env, result); |
1311 return (jobjectArray)JNIHandles::make_local(env, result); |
1315 } |
1312 } |
1316 |
1313 |
1317 instanceKlassHandle k(thread, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass))); |
1314 instanceKlassHandle k(thread, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass))); |
1318 |
1315 InnerClassesIterator iter(k); |
1319 if (k->inner_classes()->length() == 0) { |
1316 |
|
1317 if (iter.length() == 0) { |
1320 // Neither an inner nor outer class |
1318 // Neither an inner nor outer class |
1321 oop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL); |
1319 oop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL); |
1322 return (jobjectArray)JNIHandles::make_local(env, result); |
1320 return (jobjectArray)JNIHandles::make_local(env, result); |
1323 } |
1321 } |
1324 |
1322 |
1325 // find inner class info |
1323 // find inner class info |
1326 typeArrayHandle icls(thread, k->inner_classes()); |
|
1327 constantPoolHandle cp(thread, k->constants()); |
1324 constantPoolHandle cp(thread, k->constants()); |
1328 int length = icls->length(); |
1325 int length = iter.length(); |
1329 |
1326 |
1330 // Allocate temp. result array |
1327 // Allocate temp. result array |
1331 objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), length/4, CHECK_NULL); |
1328 objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), length/4, CHECK_NULL); |
1332 objArrayHandle result (THREAD, r); |
1329 objArrayHandle result (THREAD, r); |
1333 int members = 0; |
1330 int members = 0; |
1334 |
1331 |
1335 for(int i = 0; i < length; i += 4) { |
1332 for (; !iter.done(); iter.next()) { |
1336 int ioff = icls->ushort_at(i + inner_class_info_index); |
1333 int ioff = iter.inner_class_info_index(); |
1337 int ooff = icls->ushort_at(i + outer_class_info_index); |
1334 int ooff = iter.outer_class_info_index(); |
1338 |
1335 |
1339 if (ioff != 0 && ooff != 0) { |
1336 if (ioff != 0 && ooff != 0) { |
1340 // Check to see if the name matches the class we're looking for |
1337 // Check to see if the name matches the class we're looking for |
1341 // before attempting to find the class. |
1338 // before attempting to find the class. |
1342 if (cp->klass_name_at_matches(k, ooff)) { |
1339 if (cp->klass_name_at_matches(k, ooff)) { |
1390 // should be in instanceKlass.cpp, but is here for historical reasons |
1387 // should be in instanceKlass.cpp, but is here for historical reasons |
1391 klassOop instanceKlass::compute_enclosing_class_impl(instanceKlassHandle k, |
1388 klassOop instanceKlass::compute_enclosing_class_impl(instanceKlassHandle k, |
1392 bool* inner_is_member, |
1389 bool* inner_is_member, |
1393 TRAPS) { |
1390 TRAPS) { |
1394 Thread* thread = THREAD; |
1391 Thread* thread = THREAD; |
1395 const int inner_class_info_index = inner_class_inner_class_info_offset; |
1392 InnerClassesIterator iter(k); |
1396 const int outer_class_info_index = inner_class_outer_class_info_offset; |
1393 if (iter.length() == 0) { |
1397 |
|
1398 if (k->inner_classes()->length() == 0) { |
|
1399 // No inner class info => no declaring class |
1394 // No inner class info => no declaring class |
1400 return NULL; |
1395 return NULL; |
1401 } |
1396 } |
1402 |
1397 |
1403 typeArrayHandle i_icls(thread, k->inner_classes()); |
|
1404 constantPoolHandle i_cp(thread, k->constants()); |
1398 constantPoolHandle i_cp(thread, k->constants()); |
1405 int i_length = i_icls->length(); |
|
1406 |
1399 |
1407 bool found = false; |
1400 bool found = false; |
1408 klassOop ok; |
1401 klassOop ok; |
1409 instanceKlassHandle outer_klass; |
1402 instanceKlassHandle outer_klass; |
1410 *inner_is_member = false; |
1403 *inner_is_member = false; |
1411 |
1404 |
1412 // Find inner_klass attribute |
1405 // Find inner_klass attribute |
1413 for (int i = 0; i < i_length && !found; i += inner_class_next_offset) { |
1406 for (; !iter.done() && !found; iter.next()) { |
1414 int ioff = i_icls->ushort_at(i + inner_class_info_index); |
1407 int ioff = iter.inner_class_info_index(); |
1415 int ooff = i_icls->ushort_at(i + outer_class_info_index); |
1408 int ooff = iter.outer_class_info_index(); |
1416 int noff = i_icls->ushort_at(i + inner_class_inner_name_offset); |
1409 int noff = iter.inner_name_index(); |
1417 if (ioff != 0) { |
1410 if (ioff != 0) { |
1418 // Check to see if the name matches the class we're looking for |
1411 // Check to see if the name matches the class we're looking for |
1419 // before attempting to find the class. |
1412 // before attempting to find the class. |
1420 if (i_cp->klass_name_at_matches(k, ioff)) { |
1413 if (i_cp->klass_name_at_matches(k, ioff)) { |
1421 klassOop inner_klass = i_cp->klass_at(ioff, CHECK_NULL); |
1414 klassOop inner_klass = i_cp->klass_at(ioff, CHECK_NULL); |