1387 return -1; |
1387 return -1; |
1388 } |
1388 } |
1389 |
1389 |
1390 // find_method looks up the name/signature in the local methods array |
1390 // find_method looks up the name/signature in the local methods array |
1391 Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const { |
1391 Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const { |
1392 return InstanceKlass::find_method(methods(), name, signature); |
1392 return find_method_impl(name, signature, false); |
|
1393 } |
|
1394 |
|
1395 Method* InstanceKlass::find_method_impl(Symbol* name, Symbol* signature, bool skipping_overpass) const { |
|
1396 return InstanceKlass::find_method_impl(methods(), name, signature, skipping_overpass); |
1393 } |
1397 } |
1394 |
1398 |
1395 // find_instance_method looks up the name/signature in the local methods array |
1399 // find_instance_method looks up the name/signature in the local methods array |
1396 // and skips over static methods |
1400 // and skips over static methods |
1397 Method* InstanceKlass::find_instance_method( |
1401 Method* InstanceKlass::find_instance_method( |
1404 } |
1408 } |
1405 |
1409 |
1406 // find_method looks up the name/signature in the local methods array |
1410 // find_method looks up the name/signature in the local methods array |
1407 Method* InstanceKlass::find_method( |
1411 Method* InstanceKlass::find_method( |
1408 Array<Method*>* methods, Symbol* name, Symbol* signature) { |
1412 Array<Method*>* methods, Symbol* name, Symbol* signature) { |
1409 int hit = find_method_index(methods, name, 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 skipping_overpass) { |
|
1418 int hit = find_method_index(methods, name, signature, skipping_overpass); |
1410 return hit >= 0 ? methods->at(hit): NULL; |
1419 return hit >= 0 ? methods->at(hit): NULL; |
1411 } |
1420 } |
1412 |
1421 |
1413 // Used directly for default_methods to find the index into the |
1422 // Used directly for default_methods to find the index into the |
1414 // default_vtable_indices, and indirectly by find_method |
1423 // default_vtable_indices, and indirectly by find_method |
1415 // find_method_index looks in the local methods array to return the index |
1424 // find_method_index looks in the local methods array to return the index |
1416 // of the matching name/signature |
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. |
1417 int InstanceKlass::find_method_index( |
1429 int InstanceKlass::find_method_index( |
1418 Array<Method*>* methods, Symbol* name, Symbol* signature) { |
1430 Array<Method*>* methods, Symbol* name, Symbol* signature, bool skipping_overpass) { |
1419 int hit = binary_search(methods, name); |
1431 int hit = binary_search(methods, name); |
1420 if (hit != -1) { |
1432 if (hit != -1) { |
1421 Method* m = methods->at(hit); |
1433 Method* m = methods->at(hit); |
1422 // Do linear search to find matching signature. First, quick check |
1434 // Do linear search to find matching signature. First, quick check |
1423 // for common case |
1435 // for common case, ignoring overpasses if requested. |
1424 if (m->signature() == signature) return hit; |
1436 if ((m->signature() == signature) && (!skipping_overpass || !m->is_overpass())) return hit; |
|
1437 |
1425 // search downwards through overloaded methods |
1438 // search downwards through overloaded methods |
1426 int i; |
1439 int i; |
1427 for (i = hit - 1; i >= 0; --i) { |
1440 for (i = hit - 1; i >= 0; --i) { |
1428 Method* m = methods->at(i); |
1441 Method* m = methods->at(i); |
1429 assert(m->is_method(), "must be method"); |
1442 assert(m->is_method(), "must be method"); |
1430 if (m->name() != name) break; |
1443 if (m->name() != name) break; |
1431 if (m->signature() == signature) return i; |
1444 if ((m->signature() == signature) && (!skipping_overpass || !m->is_overpass())) return i; |
1432 } |
1445 } |
1433 // search upwards |
1446 // search upwards |
1434 for (i = hit + 1; i < methods->length(); ++i) { |
1447 for (i = hit + 1; i < methods->length(); ++i) { |
1435 Method* m = methods->at(i); |
1448 Method* m = methods->at(i); |
1436 assert(m->is_method(), "must be method"); |
1449 assert(m->is_method(), "must be method"); |
1437 if (m->name() != name) break; |
1450 if (m->name() != name) break; |
1438 if (m->signature() == signature) return i; |
1451 if ((m->signature() == signature) && (!skipping_overpass || !m->is_overpass())) return i; |
1439 } |
1452 } |
1440 // not found |
1453 // not found |
1441 #ifdef ASSERT |
1454 #ifdef ASSERT |
1442 int index = linear_search(methods, name, signature); |
1455 int index = skipping_overpass ? -1 : linear_search(methods, name, signature); |
1443 assert(index == -1, err_msg("binary search should have found entry %d", index)); |
1456 assert(index == -1, err_msg("binary search should have found entry %d", index)); |
1444 #endif |
1457 #endif |
1445 } |
1458 } |
1446 return -1; |
1459 return -1; |
1447 } |
1460 } |
1463 return -1; |
1476 return -1; |
1464 } |
1477 } |
1465 |
1478 |
1466 // uncached_lookup_method searches both the local class methods array and all |
1479 // uncached_lookup_method searches both the local class methods array and all |
1467 // superclasses methods arrays, skipping any overpass methods in superclasses. |
1480 // superclasses methods arrays, skipping any overpass methods in superclasses. |
1468 Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature) const { |
1481 Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature, MethodLookupMode mode) const { |
|
1482 MethodLookupMode lookup_mode = mode; |
1469 Klass* klass = const_cast<InstanceKlass*>(this); |
1483 Klass* klass = const_cast<InstanceKlass*>(this); |
1470 bool dont_ignore_overpasses = true; // For the class being searched, find its overpasses. |
|
1471 while (klass != NULL) { |
1484 while (klass != NULL) { |
1472 Method* method = InstanceKlass::cast(klass)->find_method(name, signature); |
1485 Method* method = InstanceKlass::cast(klass)->find_method_impl(name, signature, (lookup_mode == skip_overpass)); |
1473 if ((method != NULL) && (dont_ignore_overpasses || !method->is_overpass())) { |
1486 if (method != NULL) { |
1474 return method; |
1487 return method; |
1475 } |
1488 } |
1476 klass = InstanceKlass::cast(klass)->super(); |
1489 klass = InstanceKlass::cast(klass)->super(); |
1477 dont_ignore_overpasses = false; // Ignore overpass methods in all superclasses. |
1490 lookup_mode = skip_overpass; // Always ignore overpass methods in superclasses |
1478 } |
1491 } |
1479 return NULL; |
1492 return NULL; |
1480 } |
1493 } |
1481 |
1494 |
1482 // lookup a method in the default methods list then in all transitive interfaces |
1495 // lookup a method in the default methods list then in all transitive interfaces |
1487 if (default_methods() != NULL) { |
1500 if (default_methods() != NULL) { |
1488 m = find_method(default_methods(), name, signature); |
1501 m = find_method(default_methods(), name, signature); |
1489 } |
1502 } |
1490 // Look up interfaces |
1503 // Look up interfaces |
1491 if (m == NULL) { |
1504 if (m == NULL) { |
1492 m = lookup_method_in_all_interfaces(name, signature, false); |
1505 m = lookup_method_in_all_interfaces(name, signature, normal); |
1493 } |
1506 } |
1494 return m; |
1507 return m; |
1495 } |
1508 } |
1496 |
1509 |
1497 // lookup a method in all the interfaces that this class implements |
1510 // 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 |
1511 // 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 |
1512 // They should only be found in the initial InterfaceMethodRef |
1500 Method* InstanceKlass::lookup_method_in_all_interfaces(Symbol* name, |
1513 Method* InstanceKlass::lookup_method_in_all_interfaces(Symbol* name, |
1501 Symbol* signature, |
1514 Symbol* signature, |
1502 bool skip_default_methods) const { |
1515 MethodLookupMode mode) const { |
1503 Array<Klass*>* all_ifs = transitive_interfaces(); |
1516 Array<Klass*>* all_ifs = transitive_interfaces(); |
1504 int num_ifs = all_ifs->length(); |
1517 int num_ifs = all_ifs->length(); |
1505 InstanceKlass *ik = NULL; |
1518 InstanceKlass *ik = NULL; |
1506 for (int i = 0; i < num_ifs; i++) { |
1519 for (int i = 0; i < num_ifs; i++) { |
1507 ik = InstanceKlass::cast(all_ifs->at(i)); |
1520 ik = InstanceKlass::cast(all_ifs->at(i)); |
1508 Method* m = ik->lookup_method(name, signature); |
1521 Method* m = ik->lookup_method(name, signature); |
1509 if (m != NULL && m->is_public() && !m->is_static() && |
1522 if (m != NULL && m->is_public() && !m->is_static() && |
1510 (!skip_default_methods || !m->is_default_method())) { |
1523 ((mode != skip_defaults) || !m->is_default_method())) { |
1511 return m; |
1524 return m; |
1512 } |
1525 } |
1513 } |
1526 } |
1514 return NULL; |
1527 return NULL; |
1515 } |
1528 } |