comparison src/share/vm/oops/instanceKlass.cpp @ 21823:d5b74c583ec1

8064524: Compiler code generation improvements Reviewed-by: jrose, acorn, vlivanov
author drchase
date Mon, 01 Dec 2014 13:06:20 -0500
parents 3c87c13918fb
children 41c3c456e326
comparison
equal deleted inserted replaced
21822:b7e8193d0b53 21823:d5b74c583ec1
1451 Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const { 1451 Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const {
1452 return find_method_impl(name, signature, false); 1452 return find_method_impl(name, signature, false);
1453 } 1453 }
1454 1454
1455 Method* InstanceKlass::find_method_impl(Symbol* name, Symbol* signature, bool skipping_overpass) const { 1455 Method* InstanceKlass::find_method_impl(Symbol* name, Symbol* signature, bool skipping_overpass) const {
1456 return InstanceKlass::find_method_impl(methods(), name, signature, skipping_overpass); 1456 return InstanceKlass::find_method_impl(methods(), name, signature, skipping_overpass, false);
1457 } 1457 }
1458 1458
1459 // find_instance_method looks up the name/signature in the local methods array 1459 // find_instance_method looks up the name/signature in the local methods array
1460 // and skips over static methods 1460 // and skips over static methods
1461 Method* InstanceKlass::find_instance_method( 1461 Method* InstanceKlass::find_instance_method(
1462 Array<Method*>* methods, Symbol* name, Symbol* signature) { 1462 Array<Method*>* methods, Symbol* name, Symbol* signature) {
1463 Method* meth = InstanceKlass::find_method(methods, name, signature); 1463 Method* meth = InstanceKlass::find_method_impl(methods, name, signature, false, true);
1464 if (meth != NULL && meth->is_static()) {
1465 meth = NULL;
1466 }
1467 return meth; 1464 return meth;
1465 }
1466
1467 // find_instance_method looks up the name/signature in the local methods array
1468 // and skips over static methods
1469 Method* InstanceKlass::find_instance_method(Symbol* name, Symbol* signature) {
1470 return InstanceKlass::find_instance_method(methods(), name, signature);
1468 } 1471 }
1469 1472
1470 // find_method looks up the name/signature in the local methods array 1473 // find_method looks up the name/signature in the local methods array
1471 Method* InstanceKlass::find_method( 1474 Method* InstanceKlass::find_method(
1472 Array<Method*>* methods, Symbol* name, Symbol* signature) { 1475 Array<Method*>* methods, Symbol* name, Symbol* signature) {
1473 return InstanceKlass::find_method_impl(methods, name, signature, false); 1476 return InstanceKlass::find_method_impl(methods, name, signature, false, false);
1474 } 1477 }
1475 1478
1476 Method* InstanceKlass::find_method_impl( 1479 Method* InstanceKlass::find_method_impl(
1477 Array<Method*>* methods, Symbol* name, Symbol* signature, bool skipping_overpass) { 1480 Array<Method*>* methods, Symbol* name, Symbol* signature, bool skipping_overpass, bool skipping_static) {
1478 int hit = find_method_index(methods, name, signature, skipping_overpass); 1481 int hit = find_method_index(methods, name, signature, skipping_overpass, skipping_static);
1479 return hit >= 0 ? methods->at(hit): NULL; 1482 return hit >= 0 ? methods->at(hit): NULL;
1483 }
1484
1485 bool InstanceKlass::method_matches(Method* m, Symbol* signature, bool skipping_overpass, bool skipping_static) {
1486 return (m->signature() == signature) &&
1487 (!skipping_overpass || !m->is_overpass()) &&
1488 (!skipping_static || !m->is_static());
1480 } 1489 }
1481 1490
1482 // Used directly for default_methods to find the index into the 1491 // Used directly for default_methods to find the index into the
1483 // default_vtable_indices, and indirectly by find_method 1492 // default_vtable_indices, and indirectly by find_method
1484 // find_method_index looks in the local methods array to return the index 1493 // find_method_index looks in the local methods array to return the index
1485 // of the matching name/signature. If, overpass methods are being ignored, 1494 // of the matching name/signature. If, overpass methods are being ignored,
1486 // the search continues to find a potential non-overpass match. This capability 1495 // the search continues to find a potential non-overpass match. This capability
1487 // is important during method resolution to prefer a static method, for example, 1496 // is important during method resolution to prefer a static method, for example,
1488 // over an overpass method. 1497 // over an overpass method.
1489 int InstanceKlass::find_method_index( 1498 int InstanceKlass::find_method_index(
1490 Array<Method*>* methods, Symbol* name, Symbol* signature, bool skipping_overpass) { 1499 Array<Method*>* methods, Symbol* name, Symbol* signature, bool skipping_overpass, bool skipping_static) {
1491 int hit = binary_search(methods, name); 1500 int hit = binary_search(methods, name);
1492 if (hit != -1) { 1501 if (hit != -1) {
1493 Method* m = methods->at(hit); 1502 Method* m = methods->at(hit);
1503
1494 // Do linear search to find matching signature. First, quick check 1504 // Do linear search to find matching signature. First, quick check
1495 // for common case, ignoring overpasses if requested. 1505 // for common case, ignoring overpasses if requested.
1496 if ((m->signature() == signature) && (!skipping_overpass || !m->is_overpass())) return hit; 1506 if (method_matches(m, signature, skipping_overpass, skipping_static)) return hit;
1497 1507
1498 // search downwards through overloaded methods 1508 // search downwards through overloaded methods
1499 int i; 1509 int i;
1500 for (i = hit - 1; i >= 0; --i) { 1510 for (i = hit - 1; i >= 0; --i) {
1501 Method* m = methods->at(i); 1511 Method* m = methods->at(i);
1502 assert(m->is_method(), "must be method"); 1512 assert(m->is_method(), "must be method");
1503 if (m->name() != name) break; 1513 if (m->name() != name) break;
1504 if ((m->signature() == signature) && (!skipping_overpass || !m->is_overpass())) return i; 1514 if (method_matches(m, signature, skipping_overpass, skipping_static)) return i;
1505 } 1515 }
1506 // search upwards 1516 // search upwards
1507 for (i = hit + 1; i < methods->length(); ++i) { 1517 for (i = hit + 1; i < methods->length(); ++i) {
1508 Method* m = methods->at(i); 1518 Method* m = methods->at(i);
1509 assert(m->is_method(), "must be method"); 1519 assert(m->is_method(), "must be method");
1510 if (m->name() != name) break; 1520 if (m->name() != name) break;
1511 if ((m->signature() == signature) && (!skipping_overpass || !m->is_overpass())) return i; 1521 if (method_matches(m, signature, skipping_overpass, skipping_static)) return i;
1512 } 1522 }
1513 // not found 1523 // not found
1514 #ifdef ASSERT 1524 #ifdef ASSERT
1515 int index = skipping_overpass ? -1 : linear_search(methods, name, signature); 1525 int index = skipping_overpass || skipping_static ? -1 : linear_search(methods, name, signature);
1516 assert(index == -1, err_msg("binary search should have found entry %d", index)); 1526 assert(index == -1, err_msg("binary search should have found entry %d", index));
1517 #endif 1527 #endif
1518 } 1528 }
1519 return -1; 1529 return -1;
1520 } 1530 }