1372 int l = 0; 1373 int h = len - 1; 1374 while (l <= h) { 1375 int mid = (l + h) >> 1; 1376 Method* m = methods->at(mid); 1377 assert(m->is_method(), "must be method"); 1378 int res = m->name()->fast_compare(name); 1379 if (res == 0) { 1380 return mid; 1381 } else if (res < 0) { 1382 l = mid + 1; 1383 } else { 1384 h = mid - 1; 1385 } 1386 } 1387 return -1; 1388 } 1389 1390 // find_method looks up the name/signature in the local methods array 1391 Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const { 1392 return InstanceKlass::find_method(methods(), name, signature); 1393 } 1394 1395 // find_instance_method looks up the name/signature in the local methods array 1396 // and skips over static methods 1397 Method* InstanceKlass::find_instance_method( 1398 Array<Method*>* methods, Symbol* name, Symbol* signature) { 1399 Method* meth = InstanceKlass::find_method(methods, name, signature); 1400 if (meth != NULL && meth->is_static()) { 1401 meth = NULL; 1402 } 1403 return meth; 1404 } 1405 1406 // find_method looks up the name/signature in the local methods array 1407 Method* InstanceKlass::find_method( 1408 Array<Method*>* methods, Symbol* name, Symbol* signature) { 1409 int hit = find_method_index(methods, name, signature); 1410 return hit >= 0 ? methods->at(hit): NULL; 1411 } 1412 1413 // Used directly for default_methods to find the index into the 1414 // default_vtable_indices, and indirectly by find_method 1415 // find_method_index looks in the local methods array to return the index 1416 // of the matching name/signature 1417 int InstanceKlass::find_method_index( 1418 Array<Method*>* methods, Symbol* name, Symbol* signature) { 1419 int hit = binary_search(methods, name); 1420 if (hit != -1) { 1421 Method* m = methods->at(hit); 1422 // Do linear search to find matching signature. First, quick check 1423 // for common case 1424 if (m->signature() == signature) return hit; 1425 // search downwards through overloaded methods 1426 int i; 1427 for (i = hit - 1; i >= 0; --i) { 1428 Method* m = methods->at(i); 1429 assert(m->is_method(), "must be method"); 1430 if (m->name() != name) break; 1431 if (m->signature() == signature) return i; 1432 } 1433 // search upwards 1434 for (i = hit + 1; i < methods->length(); ++i) { 1435 Method* m = methods->at(i); 1436 assert(m->is_method(), "must be method"); 1437 if (m->name() != name) break; 1438 if (m->signature() == signature) return i; 1439 } 1440 // not found 1441 #ifdef ASSERT 1442 int index = linear_search(methods, name, signature); 1443 assert(index == -1, err_msg("binary search should have found entry %d", index)); 1444 #endif 1445 } 1446 return -1; 1447 } 1448 int InstanceKlass::find_method_by_name(Symbol* name, int* end) { 1449 return find_method_by_name(methods(), name, end); 1450 } 1451 1452 int InstanceKlass::find_method_by_name( 1453 Array<Method*>* methods, Symbol* name, int* end_ptr) { 1454 assert(end_ptr != NULL, "just checking"); 1455 int start = binary_search(methods, name); 1456 int end = start + 1; 1457 if (start != -1) { 1458 while (start - 1 >= 0 && (methods->at(start - 1))->name() == name) --start; 1459 while (end < methods->length() && (methods->at(end))->name() == name) ++end; 1460 *end_ptr = end; 1461 return start; 1462 } 1463 return -1; 1464 } 1465 1466 // uncached_lookup_method searches both the local class methods array and all 1467 // superclasses methods arrays, skipping any overpass methods in superclasses. 1468 Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature) const { 1469 Klass* klass = const_cast<InstanceKlass*>(this); 1470 bool dont_ignore_overpasses = true; // For the class being searched, find its overpasses. 1471 while (klass != NULL) { 1472 Method* method = InstanceKlass::cast(klass)->find_method(name, signature); 1473 if ((method != NULL) && (dont_ignore_overpasses || !method->is_overpass())) { 1474 return method; 1475 } 1476 klass = InstanceKlass::cast(klass)->super(); 1477 dont_ignore_overpasses = false; // Ignore overpass methods in all superclasses. 1478 } 1479 return NULL; 1480 } 1481 1482 // lookup a method in the default methods list then in all transitive interfaces 1483 // Do NOT return private or static methods 1484 Method* InstanceKlass::lookup_method_in_ordered_interfaces(Symbol* name, 1485 Symbol* signature) const { 1486 Method* m = NULL; 1487 if (default_methods() != NULL) { 1488 m = find_method(default_methods(), name, signature); 1489 } 1490 // Look up interfaces 1491 if (m == NULL) { 1492 m = lookup_method_in_all_interfaces(name, signature, false); 1493 } 1494 return m; 1495 } 1496 1497 // lookup a method in all the interfaces that this class implements 1498 // Do NOT return private or static methods, new in JDK8 which are not externally visible 1499 // They should only be found in the initial InterfaceMethodRef 1500 Method* InstanceKlass::lookup_method_in_all_interfaces(Symbol* name, 1501 Symbol* signature, 1502 bool skip_default_methods) const { 1503 Array<Klass*>* all_ifs = transitive_interfaces(); 1504 int num_ifs = all_ifs->length(); 1505 InstanceKlass *ik = NULL; 1506 for (int i = 0; i < num_ifs; i++) { 1507 ik = InstanceKlass::cast(all_ifs->at(i)); 1508 Method* m = ik->lookup_method(name, signature); 1509 if (m != NULL && m->is_public() && !m->is_static() && 1510 (!skip_default_methods || !m->is_default_method())) { 1511 return m; 1512 } 1513 } 1514 return NULL; 1515 } 1516 1517 /* jni_id_for_impl for jfieldIds only */ 1518 JNIid* InstanceKlass::jni_id_for_impl(instanceKlassHandle this_k, int offset) { 1519 MutexLocker ml(JfieldIdCreation_lock); 1520 // Retry lookup after we got the lock 1521 JNIid* probe = this_k->jni_ids() == NULL ? NULL : this_k->jni_ids()->find(offset); 1522 if (probe == NULL) { 1523 // Slow case, allocate new static field identifier 1524 probe = new JNIid(this_k(), offset, this_k->jni_ids()); 1525 this_k->set_jni_ids(probe); 1526 } 1527 return probe; 1528 } 1529 1530 | 1372 int l = 0; 1373 int h = len - 1; 1374 while (l <= h) { 1375 int mid = (l + h) >> 1; 1376 Method* m = methods->at(mid); 1377 assert(m->is_method(), "must be method"); 1378 int res = m->name()->fast_compare(name); 1379 if (res == 0) { 1380 return mid; 1381 } else if (res < 0) { 1382 l = mid + 1; 1383 } else { 1384 h = mid - 1; 1385 } 1386 } 1387 return -1; 1388 } 1389 1390 // find_method looks up the name/signature in the local methods array 1391 Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const { 1392 return find_method_impl(name, signature, false); 1393 } 1394 1395 Method* InstanceKlass::find_method_impl(Symbol* name, Symbol* signature, bool skip_overpass) const { 1396 return InstanceKlass::find_method_impl(methods(), name, signature, skip_overpass); 1397 } 1398 1399 // find_instance_method looks up the name/signature in the local methods array 1400 // and skips over static methods 1401 Method* InstanceKlass::find_instance_method( 1402 Array<Method*>* methods, Symbol* name, Symbol* signature) { 1403 Method* meth = InstanceKlass::find_method(methods, name, signature); 1404 if (meth != NULL && meth->is_static()) { 1405 meth = NULL; 1406 } 1407 return meth; 1408 } 1409 1410 // find_method looks up the name/signature in the local methods array 1411 Method* InstanceKlass::find_method( 1412 Array<Method*>* methods, Symbol* name, Symbol* signature) { 1413 return InstanceKlass::find_method_impl(methods, name, signature, false); 1414 } 1415 1416 Method* InstanceKlass::find_method_impl( 1417 Array<Method*>* methods, Symbol* name, Symbol* signature, bool skip_overpass) { 1418 int hit = find_method_index(methods, name, signature, skip_overpass); 1419 return hit >= 0 ? methods->at(hit): NULL; 1420 } 1421 1422 // Used directly for default_methods to find the index into the 1423 // default_vtable_indices, and indirectly by find_method 1424 // find_method_index looks in the local methods array to return the index 1425 // of the matching name/signature. If, overpass methods are being ignored, 1426 // the search continues to find a potential non-overpass match. This capability 1427 // is important during method resolution to prefer a static method, for example, 1428 // over an overpass method. 1429 int InstanceKlass::find_method_index( 1430 Array<Method*>* methods, Symbol* name, Symbol* signature, bool skip_overpass) { 1431 int hit = binary_search(methods, name); 1432 if (hit != -1) { 1433 Method* m = methods->at(hit); 1434 // Do linear search to find matching signature. First, quick check 1435 // for common case, ignoring overpasses if requested. 1436 if ((m->signature() == signature) && (!skip_overpass || !m->is_overpass())) return hit; 1437 1438 // search downwards through overloaded methods 1439 int i; 1440 for (i = hit - 1; i >= 0; --i) { 1441 Method* m = methods->at(i); 1442 assert(m->is_method(), "must be method"); 1443 if (m->name() != name) break; 1444 if ((m->signature() == signature) && (!skip_overpass || !m->is_overpass())) return i; 1445 } 1446 // search upwards 1447 for (i = hit + 1; i < methods->length(); ++i) { 1448 Method* m = methods->at(i); 1449 assert(m->is_method(), "must be method"); 1450 if (m->name() != name) break; 1451 if ((m->signature() == signature) && (!skip_overpass || !m->is_overpass())) return i; 1452 } 1453 // not found 1454 #ifdef ASSERT 1455 int index = skip_overpass ? -1 : linear_search(methods, name, signature); 1456 assert(index == -1, err_msg("binary search should have found entry %d", index)); 1457 #endif 1458 } 1459 return -1; 1460 } 1461 int InstanceKlass::find_method_by_name(Symbol* name, int* end) { 1462 return find_method_by_name(methods(), name, end); 1463 } 1464 1465 int InstanceKlass::find_method_by_name( 1466 Array<Method*>* methods, Symbol* name, int* end_ptr) { 1467 assert(end_ptr != NULL, "just checking"); 1468 int start = binary_search(methods, name); 1469 int end = start + 1; 1470 if (start != -1) { 1471 while (start - 1 >= 0 && (methods->at(start - 1))->name() == name) --start; 1472 while (end < methods->length() && (methods->at(end))->name() == name) ++end; 1473 *end_ptr = end; 1474 return start; 1475 } 1476 return -1; 1477 } 1478 1479 // uncached_lookup_method searches both the local class methods array and all 1480 // superclasses methods arrays, skipping any overpass methods in superclasses. 1481 Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature, MethodLookupMode mode) const { 1482 Klass* klass = const_cast<InstanceKlass*>(this); 1483 while (klass != NULL) { 1484 Method* method = InstanceKlass::cast(klass)->find_method_impl(name, signature, mode == skip_overpass); 1485 if (method != NULL) { 1486 return method; 1487 } 1488 klass = InstanceKlass::cast(klass)->super(); 1489 mode = skip_overpass; // Always ignore overpass methods in superclasses 1490 } 1491 return NULL; 1492 } 1493 1494 // lookup a method in the default methods list then in all transitive interfaces 1495 // Do NOT return private or static methods 1496 Method* InstanceKlass::lookup_method_in_ordered_interfaces(Symbol* name, 1497 Symbol* signature) const { 1498 Method* m = NULL; 1499 if (default_methods() != NULL) { 1500 m = find_method(default_methods(), name, signature); 1501 } 1502 // Look up interfaces 1503 if (m == NULL) { 1504 m = lookup_method_in_all_interfaces(name, signature, normal); 1505 } 1506 return m; 1507 } 1508 1509 // lookup a method in all the interfaces that this class implements 1510 // Do NOT return private or static methods, new in JDK8 which are not externally visible 1511 // They should only be found in the initial InterfaceMethodRef 1512 Method* InstanceKlass::lookup_method_in_all_interfaces(Symbol* name, 1513 Symbol* signature, 1514 MethodLookupMode mode) const { 1515 Array<Klass*>* all_ifs = transitive_interfaces(); 1516 int num_ifs = all_ifs->length(); 1517 InstanceKlass *ik = NULL; 1518 for (int i = 0; i < num_ifs; i++) { 1519 ik = InstanceKlass::cast(all_ifs->at(i)); 1520 Method* m = ik->lookup_method(name, signature); 1521 if (m != NULL && m->is_public() && !m->is_static() && 1522 ((mode != skip_defaults) || !m->is_default_method())) { 1523 return m; 1524 } 1525 } 1526 return NULL; 1527 } 1528 1529 /* jni_id_for_impl for jfieldIds only */ 1530 JNIid* InstanceKlass::jni_id_for_impl(instanceKlassHandle this_k, int offset) { 1531 MutexLocker ml(JfieldIdCreation_lock); 1532 // Retry lookup after we got the lock 1533 JNIid* probe = this_k->jni_ids() == NULL ? NULL : this_k->jni_ids()->find(offset); 1534 if (probe == NULL) { 1535 // Slow case, allocate new static field identifier 1536 probe = new JNIid(this_k(), offset, this_k->jni_ids()); 1537 this_k->set_jni_ids(probe); 1538 } 1539 return probe; 1540 } 1541 1542 |