< prev index next >

src/hotspot/share/oops/instanceKlass.cpp

Print this page


1553   if (array_klasses() != NULL)
1554     ArrayKlass::cast(array_klasses())->array_klasses_do(f);
1555 }
1556 
1557 #ifdef ASSERT
1558 static int linear_search(const Array<Method*>* methods,
1559                          const Symbol* name,
1560                          const Symbol* signature) {
1561   const int len = methods->length();
1562   for (int index = 0; index < len; index++) {
1563     const Method* const m = methods->at(index);
1564     assert(m->is_method(), "must be method");
1565     if (m->signature() == signature && m->name() == name) {
1566        return index;
1567     }
1568   }
1569   return -1;
1570 }
1571 #endif
1572 
1573 static int binary_search(const Array<Method*>* methods, const Symbol* name) {


1574   int len = methods->length();
1575   // methods are sorted, so do binary search
1576   int l = 0;
1577   int h = len - 1;

















1578   while (l <= h) {
1579     int mid = (l + h) >> 1;
1580     Method* m = methods->at(mid);
1581     assert(m->is_method(), "must be method");
1582     int res = m->name()->fast_compare(name);
1583     if (res == 0) {
1584       return mid;
1585     } else if (res < 0) {
1586       l = mid + 1;
1587     } else {
1588       h = mid - 1;
1589     }
1590   }
1591   return -1;
1592 }
1593 
1594 // find_method looks up the name/signature in the local methods array
1595 Method* InstanceKlass::find_method(const Symbol* name,
1596                                    const Symbol* signature) const {
1597   return find_method_impl(name, signature, find_overpass, find_static, find_private);


1709 // default_vtable_indices, and indirectly by find_method
1710 // find_method_index looks in the local methods array to return the index
1711 // of the matching name/signature. If, overpass methods are being ignored,
1712 // the search continues to find a potential non-overpass match.  This capability
1713 // is important during method resolution to prefer a static method, for example,
1714 // over an overpass method.
1715 // There is the possibility in any _method's array to have the same name/signature
1716 // for a static method, an overpass method and a local instance method
1717 // To correctly catch a given method, the search criteria may need
1718 // to explicitly skip the other two. For local instance methods, it
1719 // is often necessary to skip private methods
1720 int InstanceKlass::find_method_index(const Array<Method*>* methods,
1721                                      const Symbol* name,
1722                                      const Symbol* signature,
1723                                      OverpassLookupMode overpass_mode,
1724                                      StaticLookupMode static_mode,
1725                                      PrivateLookupMode private_mode) {
1726   const bool skipping_overpass = (overpass_mode == skip_overpass);
1727   const bool skipping_static = (static_mode == skip_static);
1728   const bool skipping_private = (private_mode == skip_private);
1729   const int hit = binary_search(methods, name);
1730   if (hit != -1) {
1731     const Method* const m = methods->at(hit);
1732 
1733     // Do linear search to find matching signature.  First, quick check
1734     // for common case, ignoring overpasses if requested.
1735     if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) {
1736       return hit;
1737     }
1738 
1739     // search downwards through overloaded methods
1740     int i;
1741     for (i = hit - 1; i >= 0; --i) {
1742         const Method* const m = methods->at(i);
1743         assert(m->is_method(), "must be method");
1744         if (m->name() != name) {
1745           break;
1746         }
1747         if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) {
1748           return i;
1749         }


1760         }
1761     }
1762     // not found
1763 #ifdef ASSERT
1764     const int index = (skipping_overpass || skipping_static || skipping_private) ? -1 :
1765       linear_search(methods, name, signature);
1766     assert(-1 == index, "binary search should have found entry %d", index);
1767 #endif
1768   }
1769   return -1;
1770 }
1771 
1772 int InstanceKlass::find_method_by_name(const Symbol* name, int* end) const {
1773   return find_method_by_name(methods(), name, end);
1774 }
1775 
1776 int InstanceKlass::find_method_by_name(const Array<Method*>* methods,
1777                                        const Symbol* name,
1778                                        int* end_ptr) {
1779   assert(end_ptr != NULL, "just checking");
1780   int start = binary_search(methods, name);
1781   int end = start + 1;
1782   if (start != -1) {
1783     while (start - 1 >= 0 && (methods->at(start - 1))->name() == name) --start;
1784     while (end < methods->length() && (methods->at(end))->name() == name) ++end;
1785     *end_ptr = end;
1786     return start;
1787   }
1788   return -1;
1789 }
1790 
1791 // uncached_lookup_method searches both the local class methods array and all
1792 // superclasses methods arrays, skipping any overpass methods in superclasses,
1793 // and possibly skipping private methods.
1794 Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
1795                                               const Symbol* signature,
1796                                               OverpassLookupMode overpass_mode,
1797                                               PrivateLookupMode private_mode) const {
1798   OverpassLookupMode overpass_local_mode = overpass_mode;
1799   const Klass* klass = this;
1800   while (klass != NULL) {


2341   constants()->remove_unshareable_info();
2342 
2343   for (int i = 0; i < methods()->length(); i++) {
2344     Method* m = methods()->at(i);
2345     m->remove_unshareable_info();
2346   }
2347 
2348   // do array classes also.
2349   if (array_klasses() != NULL) {
2350     array_klasses()->remove_unshareable_info();
2351   }
2352 
2353   // These are not allocated from metaspace. They are safe to set to NULL.
2354   _source_debug_extension = NULL;
2355   _dep_context = NULL;
2356   _osr_nmethods_head = NULL;
2357 #if INCLUDE_JVMTI
2358   _breakpoints = NULL;
2359   _previous_versions = NULL;
2360   _cached_class_file = NULL;

2361 #endif
2362 
2363   _init_thread = NULL;
2364   _methods_jmethod_ids = NULL;
2365   _jni_ids = NULL;
2366   _oop_map_cache = NULL;
2367   // clear _nest_host to ensure re-load at runtime
2368   _nest_host = NULL;


2369 }
2370 
2371 void InstanceKlass::remove_java_mirror() {
2372   Klass::remove_java_mirror();
2373 
2374   // do array classes also.
2375   if (array_klasses() != NULL) {
2376     array_klasses()->remove_java_mirror();
2377   }
2378 }
2379 
2380 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {
2381   // SystemDictionary::add_to_hierarchy() sets the init_state to loaded
2382   // before the InstanceKlass is added to the SystemDictionary. Make
2383   // sure the current state is <loaded.
2384   assert(!is_loaded(), "invalid init state");
2385   set_package(loader_data, CHECK);
2386   Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
2387 
2388   Array<Method*>* methods = this->methods();




1553   if (array_klasses() != NULL)
1554     ArrayKlass::cast(array_klasses())->array_klasses_do(f);
1555 }
1556 
1557 #ifdef ASSERT
1558 static int linear_search(const Array<Method*>* methods,
1559                          const Symbol* name,
1560                          const Symbol* signature) {
1561   const int len = methods->length();
1562   for (int index = 0; index < len; index++) {
1563     const Method* const m = methods->at(index);
1564     assert(m->is_method(), "must be method");
1565     if (m->signature() == signature && m->name() == name) {
1566        return index;
1567     }
1568   }
1569   return -1;
1570 }
1571 #endif
1572 
1573 bool InstanceKlass::_disable_method_binary_search = false;
1574 
1575 int InstanceKlass::quick_search(const Array<Method*>* methods, const Symbol* name) {
1576   int len = methods->length();

1577   int l = 0;
1578   int h = len - 1;
1579 
1580   if (_disable_method_binary_search) {
1581     // During portions of dynamic dumping, the methods array may not be sorted by ascending
1582     // addresses of their names. However, methods with the same name are still laid out
1583     // consecutively inside the methods array.
1584     assert(DynamicDumpSharedSpaces, "must be");
1585     while (l <= h) {
1586       Method* m = methods->at(l);
1587       if (m->name() == name) {
1588         return l;
1589       }
1590       l ++;
1591     }
1592     return -1;
1593   }
1594 
1595   // methods are sorted, so do binary search
1596   while (l <= h) {
1597     int mid = (l + h) >> 1;
1598     Method* m = methods->at(mid);
1599     assert(m->is_method(), "must be method");
1600     int res = m->name()->fast_compare(name);
1601     if (res == 0) {
1602       return mid;
1603     } else if (res < 0) {
1604       l = mid + 1;
1605     } else {
1606       h = mid - 1;
1607     }
1608   }
1609   return -1;
1610 }
1611 
1612 // find_method looks up the name/signature in the local methods array
1613 Method* InstanceKlass::find_method(const Symbol* name,
1614                                    const Symbol* signature) const {
1615   return find_method_impl(name, signature, find_overpass, find_static, find_private);


1727 // default_vtable_indices, and indirectly by find_method
1728 // find_method_index looks in the local methods array to return the index
1729 // of the matching name/signature. If, overpass methods are being ignored,
1730 // the search continues to find a potential non-overpass match.  This capability
1731 // is important during method resolution to prefer a static method, for example,
1732 // over an overpass method.
1733 // There is the possibility in any _method's array to have the same name/signature
1734 // for a static method, an overpass method and a local instance method
1735 // To correctly catch a given method, the search criteria may need
1736 // to explicitly skip the other two. For local instance methods, it
1737 // is often necessary to skip private methods
1738 int InstanceKlass::find_method_index(const Array<Method*>* methods,
1739                                      const Symbol* name,
1740                                      const Symbol* signature,
1741                                      OverpassLookupMode overpass_mode,
1742                                      StaticLookupMode static_mode,
1743                                      PrivateLookupMode private_mode) {
1744   const bool skipping_overpass = (overpass_mode == skip_overpass);
1745   const bool skipping_static = (static_mode == skip_static);
1746   const bool skipping_private = (private_mode == skip_private);
1747   const int hit = quick_search(methods, name);
1748   if (hit != -1) {
1749     const Method* const m = methods->at(hit);
1750 
1751     // Do linear search to find matching signature.  First, quick check
1752     // for common case, ignoring overpasses if requested.
1753     if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) {
1754       return hit;
1755     }
1756 
1757     // search downwards through overloaded methods
1758     int i;
1759     for (i = hit - 1; i >= 0; --i) {
1760         const Method* const m = methods->at(i);
1761         assert(m->is_method(), "must be method");
1762         if (m->name() != name) {
1763           break;
1764         }
1765         if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) {
1766           return i;
1767         }


1778         }
1779     }
1780     // not found
1781 #ifdef ASSERT
1782     const int index = (skipping_overpass || skipping_static || skipping_private) ? -1 :
1783       linear_search(methods, name, signature);
1784     assert(-1 == index, "binary search should have found entry %d", index);
1785 #endif
1786   }
1787   return -1;
1788 }
1789 
1790 int InstanceKlass::find_method_by_name(const Symbol* name, int* end) const {
1791   return find_method_by_name(methods(), name, end);
1792 }
1793 
1794 int InstanceKlass::find_method_by_name(const Array<Method*>* methods,
1795                                        const Symbol* name,
1796                                        int* end_ptr) {
1797   assert(end_ptr != NULL, "just checking");
1798   int start = quick_search(methods, name);
1799   int end = start + 1;
1800   if (start != -1) {
1801     while (start - 1 >= 0 && (methods->at(start - 1))->name() == name) --start;
1802     while (end < methods->length() && (methods->at(end))->name() == name) ++end;
1803     *end_ptr = end;
1804     return start;
1805   }
1806   return -1;
1807 }
1808 
1809 // uncached_lookup_method searches both the local class methods array and all
1810 // superclasses methods arrays, skipping any overpass methods in superclasses,
1811 // and possibly skipping private methods.
1812 Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
1813                                               const Symbol* signature,
1814                                               OverpassLookupMode overpass_mode,
1815                                               PrivateLookupMode private_mode) const {
1816   OverpassLookupMode overpass_local_mode = overpass_mode;
1817   const Klass* klass = this;
1818   while (klass != NULL) {


2359   constants()->remove_unshareable_info();
2360 
2361   for (int i = 0; i < methods()->length(); i++) {
2362     Method* m = methods()->at(i);
2363     m->remove_unshareable_info();
2364   }
2365 
2366   // do array classes also.
2367   if (array_klasses() != NULL) {
2368     array_klasses()->remove_unshareable_info();
2369   }
2370 
2371   // These are not allocated from metaspace. They are safe to set to NULL.
2372   _source_debug_extension = NULL;
2373   _dep_context = NULL;
2374   _osr_nmethods_head = NULL;
2375 #if INCLUDE_JVMTI
2376   _breakpoints = NULL;
2377   _previous_versions = NULL;
2378   _cached_class_file = NULL;
2379   _jvmti_cached_class_field_map = NULL;
2380 #endif
2381 
2382   _init_thread = NULL;
2383   _methods_jmethod_ids = NULL;
2384   _jni_ids = NULL;
2385   _oop_map_cache = NULL;
2386   // clear _nest_host to ensure re-load at runtime
2387   _nest_host = NULL;
2388   _package_entry = NULL;
2389   _dep_context_last_cleaned = 0;
2390 }
2391 
2392 void InstanceKlass::remove_java_mirror() {
2393   Klass::remove_java_mirror();
2394 
2395   // do array classes also.
2396   if (array_klasses() != NULL) {
2397     array_klasses()->remove_java_mirror();
2398   }
2399 }
2400 
2401 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {
2402   // SystemDictionary::add_to_hierarchy() sets the init_state to loaded
2403   // before the InstanceKlass is added to the SystemDictionary. Make
2404   // sure the current state is <loaded.
2405   assert(!is_loaded(), "invalid init state");
2406   set_package(loader_data, CHECK);
2407   Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
2408 
2409   Array<Method*>* methods = this->methods();


< prev index next >