799 #endif //ASSERT |
803 #endif //ASSERT |
800 } |
804 } |
801 } |
805 } |
802 |
806 |
803 // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access) |
807 // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access) |
804 void InstanceKlass::initialize_super_interfaces(instanceKlassHandle this_oop, TRAPS) { |
808 void InstanceKlass::initialize_super_interfaces(instanceKlassHandle this_k, TRAPS) { |
805 if (this_oop->has_default_methods()) { |
809 assert (this_k->has_default_methods(), "caller should have checked this"); |
806 for (int i = 0; i < this_oop->local_interfaces()->length(); ++i) { |
810 for (int i = 0; i < this_k->local_interfaces()->length(); ++i) { |
807 Klass* iface = this_oop->local_interfaces()->at(i); |
811 Klass* iface = this_k->local_interfaces()->at(i); |
808 InstanceKlass* ik = InstanceKlass::cast(iface); |
812 InstanceKlass* ik = InstanceKlass::cast(iface); |
809 if (ik->should_be_initialized()) { |
813 |
810 if (ik->has_default_methods()) { |
814 // Initialization is depth first search ie. we start with top of the inheritance tree |
811 ik->initialize_super_interfaces(ik, THREAD); |
815 // has_default_methods drives searching superinterfaces since it |
812 } |
816 // means has_default_methods in its superinterface hierarchy |
813 // Only initialize() interfaces that "declare" concrete methods. |
817 if (ik->has_default_methods()) { |
814 // has_default_methods drives searching superinterfaces since it |
818 ik->initialize_super_interfaces(ik, CHECK); |
815 // means has_default_methods in its superinterface hierarchy |
819 } |
816 if (!HAS_PENDING_EXCEPTION && ik->declares_default_methods()) { |
820 |
817 ik->initialize(THREAD); |
821 // Only initialize() interfaces that "declare" concrete methods. |
818 } |
822 if (ik->should_be_initialized() && ik->declares_default_methods()) { |
819 if (HAS_PENDING_EXCEPTION) { |
823 ik->initialize(CHECK); |
820 Handle e(THREAD, PENDING_EXCEPTION); |
|
821 CLEAR_PENDING_EXCEPTION; |
|
822 { |
|
823 EXCEPTION_MARK; |
|
824 // Locks object, set state, and notify all waiting threads |
|
825 this_oop->set_initialization_state_and_notify( |
|
826 initialization_error, THREAD); |
|
827 |
|
828 // ignore any exception thrown, superclass initialization error is |
|
829 // thrown below |
|
830 CLEAR_PENDING_EXCEPTION; |
|
831 } |
|
832 THROW_OOP(e()); |
|
833 } |
|
834 } |
|
835 } |
824 } |
836 } |
825 } |
837 } |
826 } |
838 |
827 |
839 void InstanceKlass::initialize_impl(instanceKlassHandle this_oop, TRAPS) { |
828 void InstanceKlass::initialize_impl(instanceKlassHandle this_oop, TRAPS) { |
895 this_oop->set_init_state(being_initialized); |
884 this_oop->set_init_state(being_initialized); |
896 this_oop->set_init_thread(self); |
885 this_oop->set_init_thread(self); |
897 } |
886 } |
898 |
887 |
899 // Step 7 |
888 // Step 7 |
900 Klass* super_klass = this_oop->super(); |
889 // Next, if C is a class rather than an interface, initialize its super class and super |
901 if (super_klass != NULL && !this_oop->is_interface() && super_klass->should_be_initialized()) { |
890 // interfaces. |
902 super_klass->initialize(THREAD); |
891 if (!this_oop->is_interface()) { |
903 |
892 Klass* super_klass = this_oop->super(); |
|
893 if (super_klass != NULL && super_klass->should_be_initialized()) { |
|
894 super_klass->initialize(THREAD); |
|
895 } |
|
896 // If C implements any interfaces that declares a non-abstract, non-static method, |
|
897 // the initialization of C triggers initialization of its super interfaces. |
|
898 // Only need to recurse if has_default_methods which includes declaring and |
|
899 // inheriting default methods |
|
900 if (!HAS_PENDING_EXCEPTION && this_oop->has_default_methods()) { |
|
901 this_oop->initialize_super_interfaces(this_oop, THREAD); |
|
902 } |
|
903 |
|
904 // If any exceptions, complete abruptly, throwing the same exception as above. |
904 if (HAS_PENDING_EXCEPTION) { |
905 if (HAS_PENDING_EXCEPTION) { |
905 Handle e(THREAD, PENDING_EXCEPTION); |
906 Handle e(THREAD, PENDING_EXCEPTION); |
906 CLEAR_PENDING_EXCEPTION; |
907 CLEAR_PENDING_EXCEPTION; |
907 { |
908 { |
908 EXCEPTION_MARK; |
909 EXCEPTION_MARK; |
909 this_oop->set_initialization_state_and_notify(initialization_error, THREAD); // Locks object, set state, and notify all waiting threads |
910 // Locks object, set state, and notify all waiting threads |
910 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, superclass initialization error is thrown below |
911 this_oop->set_initialization_state_and_notify(initialization_error, THREAD); |
|
912 CLEAR_PENDING_EXCEPTION; |
911 } |
913 } |
912 DTRACE_CLASSINIT_PROBE_WAIT(super__failed, InstanceKlass::cast(this_oop()), -1,wait); |
914 DTRACE_CLASSINIT_PROBE_WAIT(super__failed, InstanceKlass::cast(this_oop()), -1,wait); |
913 THROW_OOP(e()); |
915 THROW_OOP(e()); |
914 } |
916 } |
915 } |
|
916 |
|
917 // Recursively initialize any superinterfaces that declare default methods |
|
918 // Only need to recurse if has_default_methods which includes declaring and |
|
919 // inheriting default methods |
|
920 if (this_oop->has_default_methods()) { |
|
921 this_oop->initialize_super_interfaces(this_oop, CHECK); |
|
922 } |
917 } |
923 |
918 |
924 // Step 8 |
919 // Step 8 |
925 { |
920 { |
926 assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl"); |
921 assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl"); |
1473 return -1; |
1473 return -1; |
1474 } |
1474 } |
1475 |
1475 |
1476 // find_method looks up the name/signature in the local methods array |
1476 // find_method looks up the name/signature in the local methods array |
1477 Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const { |
1477 Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const { |
1478 return find_method_impl(name, signature, false); |
1478 return find_method_impl(name, signature, find_overpass, find_static, find_private); |
1479 } |
1479 } |
1480 |
1480 |
1481 Method* InstanceKlass::find_method_impl(Symbol* name, Symbol* signature, bool skipping_overpass) const { |
1481 Method* InstanceKlass::find_method_impl(Symbol* name, Symbol* signature, |
1482 return InstanceKlass::find_method_impl(methods(), name, signature, skipping_overpass, false); |
1482 OverpassLookupMode overpass_mode, |
|
1483 StaticLookupMode static_mode, |
|
1484 PrivateLookupMode private_mode) const { |
|
1485 return InstanceKlass::find_method_impl(methods(), name, signature, overpass_mode, static_mode, private_mode); |
1483 } |
1486 } |
1484 |
1487 |
1485 // find_instance_method looks up the name/signature in the local methods array |
1488 // find_instance_method looks up the name/signature in the local methods array |
1486 // and skips over static methods |
1489 // and skips over static methods |
1487 Method* InstanceKlass::find_instance_method( |
1490 Method* InstanceKlass::find_instance_method( |
1488 Array<Method*>* methods, Symbol* name, Symbol* signature) { |
1491 Array<Method*>* methods, Symbol* name, Symbol* signature) { |
1489 Method* meth = InstanceKlass::find_method_impl(methods, name, signature, false, true); |
1492 Method* meth = InstanceKlass::find_method_impl(methods, name, signature, |
|
1493 find_overpass, skip_static, find_private); |
|
1494 assert(((meth == NULL) || !meth->is_static()), "find_instance_method should have skipped statics"); |
1490 return meth; |
1495 return meth; |
1491 } |
1496 } |
1492 |
1497 |
1493 // find_instance_method looks up the name/signature in the local methods array |
1498 // find_instance_method looks up the name/signature in the local methods array |
1494 // and skips over static methods |
1499 // and skips over static methods |
1495 Method* InstanceKlass::find_instance_method(Symbol* name, Symbol* signature) { |
1500 Method* InstanceKlass::find_instance_method(Symbol* name, Symbol* signature) { |
1496 return InstanceKlass::find_instance_method(methods(), name, signature); |
1501 return InstanceKlass::find_instance_method(methods(), name, signature); |
1497 } |
1502 } |
1498 |
1503 |
|
1504 // Find looks up the name/signature in the local methods array |
|
1505 // and filters on the overpass, static and private flags |
|
1506 // This returns the first one found |
|
1507 // note that the local methods array can have up to one overpass, one static |
|
1508 // and one instance (private or not) with the same name/signature |
|
1509 Method* InstanceKlass::find_local_method(Symbol* name, Symbol* signature, |
|
1510 OverpassLookupMode overpass_mode, |
|
1511 StaticLookupMode static_mode, |
|
1512 PrivateLookupMode private_mode) const { |
|
1513 return InstanceKlass::find_method_impl(methods(), name, signature, overpass_mode, static_mode, private_mode); |
|
1514 } |
|
1515 |
|
1516 // Find looks up the name/signature in the local methods array |
|
1517 // and filters on the overpass, static and private flags |
|
1518 // This returns the first one found |
|
1519 // note that the local methods array can have up to one overpass, one static |
|
1520 // and one instance (private or not) with the same name/signature |
|
1521 Method* InstanceKlass::find_local_method(Array<Method*>* methods, |
|
1522 Symbol* name, Symbol* signature, |
|
1523 OverpassLookupMode overpass_mode, |
|
1524 StaticLookupMode static_mode, |
|
1525 PrivateLookupMode private_mode) { |
|
1526 return InstanceKlass::find_method_impl(methods, name, signature, overpass_mode, static_mode, private_mode); |
|
1527 } |
|
1528 |
|
1529 |
1499 // find_method looks up the name/signature in the local methods array |
1530 // find_method looks up the name/signature in the local methods array |
1500 Method* InstanceKlass::find_method( |
1531 Method* InstanceKlass::find_method( |
1501 Array<Method*>* methods, Symbol* name, Symbol* signature) { |
1532 Array<Method*>* methods, Symbol* name, Symbol* signature) { |
1502 return InstanceKlass::find_method_impl(methods, name, signature, false, false); |
1533 return InstanceKlass::find_method_impl(methods, name, signature, find_overpass, find_static, find_private); |
1503 } |
1534 } |
1504 |
1535 |
1505 Method* InstanceKlass::find_method_impl( |
1536 Method* InstanceKlass::find_method_impl( |
1506 Array<Method*>* methods, Symbol* name, Symbol* signature, bool skipping_overpass, bool skipping_static) { |
1537 Array<Method*>* methods, Symbol* name, Symbol* signature, |
1507 int hit = find_method_index(methods, name, signature, skipping_overpass, skipping_static); |
1538 OverpassLookupMode overpass_mode, StaticLookupMode static_mode, |
|
1539 PrivateLookupMode private_mode) { |
|
1540 int hit = find_method_index(methods, name, signature, overpass_mode, static_mode, private_mode); |
1508 return hit >= 0 ? methods->at(hit): NULL; |
1541 return hit >= 0 ? methods->at(hit): NULL; |
1509 } |
1542 } |
1510 |
1543 |
1511 bool InstanceKlass::method_matches(Method* m, Symbol* signature, bool skipping_overpass, bool skipping_static) { |
1544 bool InstanceKlass::method_matches(Method* m, Symbol* signature, bool skipping_overpass, bool skipping_static, bool skipping_private) { |
1512 return (m->signature() == signature) && |
1545 return ((m->signature() == signature) && |
1513 (!skipping_overpass || !m->is_overpass()) && |
1546 (!skipping_overpass || !m->is_overpass()) && |
1514 (!skipping_static || !m->is_static()); |
1547 (!skipping_static || !m->is_static()) && |
|
1548 (!skipping_private || !m->is_private())); |
1515 } |
1549 } |
1516 |
1550 |
1517 // Used directly for default_methods to find the index into the |
1551 // Used directly for default_methods to find the index into the |
1518 // default_vtable_indices, and indirectly by find_method |
1552 // default_vtable_indices, and indirectly by find_method |
1519 // find_method_index looks in the local methods array to return the index |
1553 // find_method_index looks in the local methods array to return the index |
1520 // of the matching name/signature. If, overpass methods are being ignored, |
1554 // of the matching name/signature. If, overpass methods are being ignored, |
1521 // the search continues to find a potential non-overpass match. This capability |
1555 // the search continues to find a potential non-overpass match. This capability |
1522 // is important during method resolution to prefer a static method, for example, |
1556 // is important during method resolution to prefer a static method, for example, |
1523 // over an overpass method. |
1557 // over an overpass method. |
|
1558 // There is the possibility in any _method's array to have the same name/signature |
|
1559 // for a static method, an overpass method and a local instance method |
|
1560 // To correctly catch a given method, the search criteria may need |
|
1561 // to explicitly skip the other two. For local instance methods, it |
|
1562 // is often necessary to skip private methods |
1524 int InstanceKlass::find_method_index( |
1563 int InstanceKlass::find_method_index( |
1525 Array<Method*>* methods, Symbol* name, Symbol* signature, bool skipping_overpass, bool skipping_static) { |
1564 Array<Method*>* methods, Symbol* name, Symbol* signature, |
|
1565 OverpassLookupMode overpass_mode, StaticLookupMode static_mode, |
|
1566 PrivateLookupMode private_mode) { |
|
1567 bool skipping_overpass = (overpass_mode == skip_overpass); |
|
1568 bool skipping_static = (static_mode == skip_static); |
|
1569 bool skipping_private = (private_mode == skip_private); |
1526 int hit = binary_search(methods, name); |
1570 int hit = binary_search(methods, name); |
1527 if (hit != -1) { |
1571 if (hit != -1) { |
1528 Method* m = methods->at(hit); |
1572 Method* m = methods->at(hit); |
1529 |
1573 |
1530 // Do linear search to find matching signature. First, quick check |
1574 // Do linear search to find matching signature. First, quick check |
1531 // for common case, ignoring overpasses if requested. |
1575 // for common case, ignoring overpasses if requested. |
1532 if (method_matches(m, signature, skipping_overpass, skipping_static)) return hit; |
1576 if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) return hit; |
1533 |
1577 |
1534 // search downwards through overloaded methods |
1578 // search downwards through overloaded methods |
1535 int i; |
1579 int i; |
1536 for (i = hit - 1; i >= 0; --i) { |
1580 for (i = hit - 1; i >= 0; --i) { |
1537 Method* m = methods->at(i); |
1581 Method* m = methods->at(i); |
1538 assert(m->is_method(), "must be method"); |
1582 assert(m->is_method(), "must be method"); |
1539 if (m->name() != name) break; |
1583 if (m->name() != name) break; |
1540 if (method_matches(m, signature, skipping_overpass, skipping_static)) return i; |
1584 if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) return i; |
1541 } |
1585 } |
1542 // search upwards |
1586 // search upwards |
1543 for (i = hit + 1; i < methods->length(); ++i) { |
1587 for (i = hit + 1; i < methods->length(); ++i) { |
1544 Method* m = methods->at(i); |
1588 Method* m = methods->at(i); |
1545 assert(m->is_method(), "must be method"); |
1589 assert(m->is_method(), "must be method"); |
1546 if (m->name() != name) break; |
1590 if (m->name() != name) break; |
1547 if (method_matches(m, signature, skipping_overpass, skipping_static)) return i; |
1591 if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) return i; |
1548 } |
1592 } |
1549 // not found |
1593 // not found |
1550 #ifdef ASSERT |
1594 #ifdef ASSERT |
1551 int index = skipping_overpass || skipping_static ? -1 : linear_search(methods, name, signature); |
1595 int index = (skipping_overpass || skipping_static || skipping_private) ? -1 : linear_search(methods, name, signature); |
1552 assert(index == -1, err_msg("binary search should have found entry %d", index)); |
1596 assert(index == -1, err_msg("binary search should have found entry %d", index)); |
1553 #endif |
1597 #endif |
1554 } |
1598 } |
1555 return -1; |
1599 return -1; |
1556 } |
1600 } |