1418 Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const { |
1418 Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const { |
1419 return find_method_impl(name, signature, false); |
1419 return find_method_impl(name, signature, false); |
1420 } |
1420 } |
1421 |
1421 |
1422 Method* InstanceKlass::find_method_impl(Symbol* name, Symbol* signature, bool skipping_overpass) const { |
1422 Method* InstanceKlass::find_method_impl(Symbol* name, Symbol* signature, bool skipping_overpass) const { |
1423 return InstanceKlass::find_method_impl(methods(), name, signature, skipping_overpass); |
1423 return InstanceKlass::find_method_impl(methods(), name, signature, skipping_overpass, false); |
1424 } |
1424 } |
1425 |
1425 |
1426 // find_instance_method looks up the name/signature in the local methods array |
1426 // find_instance_method looks up the name/signature in the local methods array |
1427 // and skips over static methods |
1427 // and skips over static methods |
1428 Method* InstanceKlass::find_instance_method( |
1428 Method* InstanceKlass::find_instance_method( |
1429 Array<Method*>* methods, Symbol* name, Symbol* signature) { |
1429 Array<Method*>* methods, Symbol* name, Symbol* signature) { |
1430 Method* meth = InstanceKlass::find_method(methods, name, signature); |
1430 Method* meth = InstanceKlass::find_method_impl(methods, name, signature, false, true); |
1431 if (meth != NULL && meth->is_static()) { |
|
1432 meth = NULL; |
|
1433 } |
|
1434 return meth; |
1431 return meth; |
|
1432 } |
|
1433 |
|
1434 // find_instance_method looks up the name/signature in the local methods array |
|
1435 // and skips over static methods |
|
1436 Method* InstanceKlass::find_instance_method(Symbol* name, Symbol* signature) { |
|
1437 return InstanceKlass::find_instance_method(methods(), name, signature); |
1435 } |
1438 } |
1436 |
1439 |
1437 // find_method looks up the name/signature in the local methods array |
1440 // find_method looks up the name/signature in the local methods array |
1438 Method* InstanceKlass::find_method( |
1441 Method* InstanceKlass::find_method( |
1439 Array<Method*>* methods, Symbol* name, Symbol* signature) { |
1442 Array<Method*>* methods, Symbol* name, Symbol* signature) { |
1440 return InstanceKlass::find_method_impl(methods, name, signature, false); |
1443 return InstanceKlass::find_method_impl(methods, name, signature, false, false); |
1441 } |
1444 } |
1442 |
1445 |
1443 Method* InstanceKlass::find_method_impl( |
1446 Method* InstanceKlass::find_method_impl( |
1444 Array<Method*>* methods, Symbol* name, Symbol* signature, bool skipping_overpass) { |
1447 Array<Method*>* methods, Symbol* name, Symbol* signature, bool skipping_overpass, bool skipping_static) { |
1445 int hit = find_method_index(methods, name, signature, skipping_overpass); |
1448 int hit = find_method_index(methods, name, signature, skipping_overpass, skipping_static); |
1446 return hit >= 0 ? methods->at(hit): NULL; |
1449 return hit >= 0 ? methods->at(hit): NULL; |
|
1450 } |
|
1451 |
|
1452 bool InstanceKlass::method_matches(Method* m, Symbol* signature, bool skipping_overpass, bool skipping_static) { |
|
1453 return (m->signature() == signature) && |
|
1454 (!skipping_overpass || !m->is_overpass()) && |
|
1455 (!skipping_static || !m->is_static()); |
1447 } |
1456 } |
1448 |
1457 |
1449 // Used directly for default_methods to find the index into the |
1458 // Used directly for default_methods to find the index into the |
1450 // default_vtable_indices, and indirectly by find_method |
1459 // default_vtable_indices, and indirectly by find_method |
1451 // find_method_index looks in the local methods array to return the index |
1460 // find_method_index looks in the local methods array to return the index |
1452 // of the matching name/signature. If, overpass methods are being ignored, |
1461 // of the matching name/signature. If, overpass methods are being ignored, |
1453 // the search continues to find a potential non-overpass match. This capability |
1462 // the search continues to find a potential non-overpass match. This capability |
1454 // is important during method resolution to prefer a static method, for example, |
1463 // is important during method resolution to prefer a static method, for example, |
1455 // over an overpass method. |
1464 // over an overpass method. |
1456 int InstanceKlass::find_method_index( |
1465 int InstanceKlass::find_method_index( |
1457 Array<Method*>* methods, Symbol* name, Symbol* signature, bool skipping_overpass) { |
1466 Array<Method*>* methods, Symbol* name, Symbol* signature, bool skipping_overpass, bool skipping_static) { |
1458 int hit = binary_search(methods, name); |
1467 int hit = binary_search(methods, name); |
1459 if (hit != -1) { |
1468 if (hit != -1) { |
1460 Method* m = methods->at(hit); |
1469 Method* m = methods->at(hit); |
|
1470 |
1461 // Do linear search to find matching signature. First, quick check |
1471 // Do linear search to find matching signature. First, quick check |
1462 // for common case, ignoring overpasses if requested. |
1472 // for common case, ignoring overpasses if requested. |
1463 if ((m->signature() == signature) && (!skipping_overpass || !m->is_overpass())) return hit; |
1473 if (method_matches(m, signature, skipping_overpass, skipping_static)) return hit; |
1464 |
1474 |
1465 // search downwards through overloaded methods |
1475 // search downwards through overloaded methods |
1466 int i; |
1476 int i; |
1467 for (i = hit - 1; i >= 0; --i) { |
1477 for (i = hit - 1; i >= 0; --i) { |
1468 Method* m = methods->at(i); |
1478 Method* m = methods->at(i); |
1469 assert(m->is_method(), "must be method"); |
1479 assert(m->is_method(), "must be method"); |
1470 if (m->name() != name) break; |
1480 if (m->name() != name) break; |
1471 if ((m->signature() == signature) && (!skipping_overpass || !m->is_overpass())) return i; |
1481 if (method_matches(m, signature, skipping_overpass, skipping_static)) return i; |
1472 } |
1482 } |
1473 // search upwards |
1483 // search upwards |
1474 for (i = hit + 1; i < methods->length(); ++i) { |
1484 for (i = hit + 1; i < methods->length(); ++i) { |
1475 Method* m = methods->at(i); |
1485 Method* m = methods->at(i); |
1476 assert(m->is_method(), "must be method"); |
1486 assert(m->is_method(), "must be method"); |
1477 if (m->name() != name) break; |
1487 if (m->name() != name) break; |
1478 if ((m->signature() == signature) && (!skipping_overpass || !m->is_overpass())) return i; |
1488 if (method_matches(m, signature, skipping_overpass, skipping_static)) return i; |
1479 } |
1489 } |
1480 // not found |
1490 // not found |
1481 #ifdef ASSERT |
1491 #ifdef ASSERT |
1482 int index = skipping_overpass ? -1 : linear_search(methods, name, signature); |
1492 int index = skipping_overpass || skipping_static ? -1 : linear_search(methods, name, signature); |
1483 assert(index == -1, err_msg("binary search should have found entry %d", index)); |
1493 assert(index == -1, err_msg("binary search should have found entry %d", index)); |
1484 #endif |
1494 #endif |
1485 } |
1495 } |
1486 return -1; |
1496 return -1; |
1487 } |
1497 } |