< prev index next >

src/share/vm/oops/instanceKlass.cpp

Print this page




1482     if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) return hit;
1483 
1484     // search downwards through overloaded methods
1485     int i;
1486     for (i = hit - 1; i >= 0; --i) {
1487         Method* m = methods->at(i);
1488         assert(m->is_method(), "must be method");
1489         if (m->name() != name) break;
1490         if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) return i;
1491     }
1492     // search upwards
1493     for (i = hit + 1; i < methods->length(); ++i) {
1494         Method* m = methods->at(i);
1495         assert(m->is_method(), "must be method");
1496         if (m->name() != name) break;
1497         if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) return i;
1498     }
1499     // not found
1500 #ifdef ASSERT
1501     int index = (skipping_overpass || skipping_static || skipping_private) ? -1 : linear_search(methods, name, signature);
1502     assert(index == -1, err_msg("binary search should have found entry %d", index));
1503 #endif
1504   }
1505   return -1;
1506 }
1507 int InstanceKlass::find_method_by_name(Symbol* name, int* end) {
1508   return find_method_by_name(methods(), name, end);
1509 }
1510 
1511 int InstanceKlass::find_method_by_name(
1512     Array<Method*>* methods, Symbol* name, int* end_ptr) {
1513   assert(end_ptr != NULL, "just checking");
1514   int start = binary_search(methods, name);
1515   int end = start + 1;
1516   if (start != -1) {
1517     while (start - 1 >= 0 && (methods->at(start - 1))->name() == name) --start;
1518     while (end < methods->length() && (methods->at(end))->name() == name) ++end;
1519     *end_ptr = end;
1520     return start;
1521   }
1522   return -1;


1898     if (nm == b->get_nmethod()) {
1899       b->increment();
1900       return deps;
1901     }
1902   }
1903   return new nmethodBucket(nm, deps);
1904 }
1905 
1906 //
1907 // Decrement count of the nmethod in the dependency list and remove
1908 // the bucket completely when the count goes to 0.  This method must
1909 // find a corresponding bucket otherwise there's a bug in the
1910 // recording of dependencies. Returns true if the bucket is ready for reclamation.
1911 //
1912 bool nmethodBucket::remove_dependent_nmethod(nmethodBucket* deps, nmethod* nm) {
1913   assert_locked_or_safepoint(CodeCache_lock);
1914 
1915   for (nmethodBucket* b = deps; b != NULL; b = b->next()) {
1916     if (nm == b->get_nmethod()) {
1917       int val = b->decrement();
1918       guarantee(val >= 0, err_msg("Underflow: %d", val));
1919       return (val == 0);
1920     }
1921   }
1922 #ifdef ASSERT
1923   tty->print_raw_cr("### can't find dependent nmethod");
1924   nm->print();
1925 #endif // ASSERT
1926   ShouldNotReachHere();
1927   return false;
1928 }
1929 
1930 //
1931 // Reclaim all unused buckets. Returns new head of the list.
1932 //
1933 nmethodBucket* nmethodBucket::clean_dependent_nmethods(nmethodBucket* deps) {
1934   nmethodBucket* first = deps;
1935   nmethodBucket* last = NULL;
1936   nmethodBucket* b = first;
1937 
1938   while (b != NULL) {
1939     assert(b->count() >= 0, err_msg("bucket count: %d", b->count()));
1940     nmethodBucket* next = b->next();
1941     if (b->count() == 0) {
1942       if (last == NULL) {
1943         first = next;
1944       } else {
1945         last->set_next(next);
1946       }
1947       delete b;
1948       // last stays the same.
1949     } else {
1950       last = b;
1951     }
1952     b = next;
1953   }
1954   return first;
1955 }
1956 
1957 #ifndef PRODUCT
1958 void nmethodBucket::print_dependent_nmethods(nmethodBucket* deps, bool verbose) {
1959   int idx = 0;
1960   for (nmethodBucket* b = deps; b != NULL; b = b->next()) {
1961     nmethod* nm = b->get_nmethod();
1962     tty->print("[%d] count=%d { ", idx++, b->count());
1963     if (!verbose) {
1964       nm->print_on(tty, "nmethod");
1965       tty->print_cr(" } ");
1966     } else {
1967       nm->print();
1968       nm->print_dependencies();
1969       tty->print_cr("--- } ");
1970     }
1971   }
1972 }
1973 
1974 bool nmethodBucket::is_dependent_nmethod(nmethodBucket* deps, nmethod* nm) {
1975   for (nmethodBucket* b = deps; b != NULL; b = b->next()) {
1976     if (nm == b->get_nmethod()) {
1977 #ifdef ASSERT
1978       int count = b->count();
1979       assert(count >= 0, err_msg("count shouldn't be negative: %d", count));
1980 #endif
1981       return true;
1982     }
1983   }
1984   return false;
1985 }
1986 #endif //PRODUCT
1987 
1988 int InstanceKlass::mark_dependent_nmethods(DepChange& changes) {
1989   assert_locked_or_safepoint(CodeCache_lock);
1990   return nmethodBucket::mark_dependent_nmethods(_dependencies, changes);
1991 }
1992 
1993 void InstanceKlass::clean_dependent_nmethods() {
1994   assert_locked_or_safepoint(CodeCache_lock);
1995 
1996   if (has_unloaded_dependent()) {
1997     _dependencies = nmethodBucket::clean_dependent_nmethods(_dependencies);
1998     set_has_unloaded_dependent(false);
1999   }
2000 #ifdef ASSERT
2001   else {
2002     // Verification
2003     for (nmethodBucket* b = _dependencies; b != NULL; b = b->next()) {
2004       assert(b->count() >= 0, err_msg("bucket count: %d", b->count()));
2005       assert(b->count() != 0, "empty buckets need to be cleaned");
2006     }
2007   }
2008 #endif
2009 }
2010 
2011 void InstanceKlass::add_dependent_nmethod(nmethod* nm) {
2012   assert_locked_or_safepoint(CodeCache_lock);
2013   _dependencies = nmethodBucket::add_dependent_nmethod(_dependencies, nm);
2014 }
2015 
2016 void InstanceKlass::remove_dependent_nmethod(nmethod* nm) {
2017   assert_locked_or_safepoint(CodeCache_lock);
2018 
2019   if (nmethodBucket::remove_dependent_nmethod(_dependencies, nm)) {
2020     set_has_unloaded_dependent(true);
2021   }
2022 }
2023 
2024 #ifndef PRODUCT


3093             "this class isn't found in class loader data");
3094 
3095   // Verify vtables
3096   if (is_linked()) {
3097     ResourceMark rm;
3098     // $$$ This used to be done only for m/s collections.  Doing it
3099     // always seemed a valid generalization.  (DLD -- 6/00)
3100     vtable()->verify(st);
3101   }
3102 
3103   // Verify first subklass
3104   if (subklass() != NULL) {
3105     guarantee(subklass()->is_klass(), "should be klass");
3106   }
3107 
3108   // Verify siblings
3109   Klass* super = this->super();
3110   Klass* sib = next_sibling();
3111   if (sib != NULL) {
3112     if (sib == this) {
3113       fatal(err_msg("subclass points to itself " PTR_FORMAT, sib));
3114     }
3115 
3116     guarantee(sib->is_klass(), "should be klass");
3117     guarantee(sib->super() == super, "siblings should have same superklass");
3118   }
3119 
3120   // Verify implementor fields
3121   Klass* im = implementor();
3122   if (im != NULL) {
3123     guarantee(is_interface(), "only interfaces should have implementor set");
3124     guarantee(im->is_klass(), "should be klass");
3125     guarantee(!im->is_interface() || im == this,
3126       "implementors cannot be interfaces");
3127   }
3128 
3129   // Verify local interfaces
3130   if (local_interfaces()) {
3131     Array<Klass*>* local_interfaces = this->local_interfaces();
3132     for (int j = 0; j < local_interfaces->length(); j++) {
3133       Klass* e = local_interfaces->at(j);




1482     if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) return hit;
1483 
1484     // search downwards through overloaded methods
1485     int i;
1486     for (i = hit - 1; i >= 0; --i) {
1487         Method* m = methods->at(i);
1488         assert(m->is_method(), "must be method");
1489         if (m->name() != name) break;
1490         if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) return i;
1491     }
1492     // search upwards
1493     for (i = hit + 1; i < methods->length(); ++i) {
1494         Method* m = methods->at(i);
1495         assert(m->is_method(), "must be method");
1496         if (m->name() != name) break;
1497         if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) return i;
1498     }
1499     // not found
1500 #ifdef ASSERT
1501     int index = (skipping_overpass || skipping_static || skipping_private) ? -1 : linear_search(methods, name, signature);
1502     assert(index == -1, "binary search should have found entry %d", index);
1503 #endif
1504   }
1505   return -1;
1506 }
1507 int InstanceKlass::find_method_by_name(Symbol* name, int* end) {
1508   return find_method_by_name(methods(), name, end);
1509 }
1510 
1511 int InstanceKlass::find_method_by_name(
1512     Array<Method*>* methods, Symbol* name, int* end_ptr) {
1513   assert(end_ptr != NULL, "just checking");
1514   int start = binary_search(methods, name);
1515   int end = start + 1;
1516   if (start != -1) {
1517     while (start - 1 >= 0 && (methods->at(start - 1))->name() == name) --start;
1518     while (end < methods->length() && (methods->at(end))->name() == name) ++end;
1519     *end_ptr = end;
1520     return start;
1521   }
1522   return -1;


1898     if (nm == b->get_nmethod()) {
1899       b->increment();
1900       return deps;
1901     }
1902   }
1903   return new nmethodBucket(nm, deps);
1904 }
1905 
1906 //
1907 // Decrement count of the nmethod in the dependency list and remove
1908 // the bucket completely when the count goes to 0.  This method must
1909 // find a corresponding bucket otherwise there's a bug in the
1910 // recording of dependencies. Returns true if the bucket is ready for reclamation.
1911 //
1912 bool nmethodBucket::remove_dependent_nmethod(nmethodBucket* deps, nmethod* nm) {
1913   assert_locked_or_safepoint(CodeCache_lock);
1914 
1915   for (nmethodBucket* b = deps; b != NULL; b = b->next()) {
1916     if (nm == b->get_nmethod()) {
1917       int val = b->decrement();
1918       guarantee(val >= 0, "Underflow: %d", val);
1919       return (val == 0);
1920     }
1921   }
1922 #ifdef ASSERT
1923   tty->print_raw_cr("### can't find dependent nmethod");
1924   nm->print();
1925 #endif // ASSERT
1926   ShouldNotReachHere();
1927   return false;
1928 }
1929 
1930 //
1931 // Reclaim all unused buckets. Returns new head of the list.
1932 //
1933 nmethodBucket* nmethodBucket::clean_dependent_nmethods(nmethodBucket* deps) {
1934   nmethodBucket* first = deps;
1935   nmethodBucket* last = NULL;
1936   nmethodBucket* b = first;
1937 
1938   while (b != NULL) {
1939     assert(b->count() >= 0, "bucket count: %d", b->count());
1940     nmethodBucket* next = b->next();
1941     if (b->count() == 0) {
1942       if (last == NULL) {
1943         first = next;
1944       } else {
1945         last->set_next(next);
1946       }
1947       delete b;
1948       // last stays the same.
1949     } else {
1950       last = b;
1951     }
1952     b = next;
1953   }
1954   return first;
1955 }
1956 
1957 #ifndef PRODUCT
1958 void nmethodBucket::print_dependent_nmethods(nmethodBucket* deps, bool verbose) {
1959   int idx = 0;
1960   for (nmethodBucket* b = deps; b != NULL; b = b->next()) {
1961     nmethod* nm = b->get_nmethod();
1962     tty->print("[%d] count=%d { ", idx++, b->count());
1963     if (!verbose) {
1964       nm->print_on(tty, "nmethod");
1965       tty->print_cr(" } ");
1966     } else {
1967       nm->print();
1968       nm->print_dependencies();
1969       tty->print_cr("--- } ");
1970     }
1971   }
1972 }
1973 
1974 bool nmethodBucket::is_dependent_nmethod(nmethodBucket* deps, nmethod* nm) {
1975   for (nmethodBucket* b = deps; b != NULL; b = b->next()) {
1976     if (nm == b->get_nmethod()) {
1977 #ifdef ASSERT
1978       int count = b->count();
1979       assert(count >= 0, "count shouldn't be negative: %d", count);
1980 #endif
1981       return true;
1982     }
1983   }
1984   return false;
1985 }
1986 #endif //PRODUCT
1987 
1988 int InstanceKlass::mark_dependent_nmethods(DepChange& changes) {
1989   assert_locked_or_safepoint(CodeCache_lock);
1990   return nmethodBucket::mark_dependent_nmethods(_dependencies, changes);
1991 }
1992 
1993 void InstanceKlass::clean_dependent_nmethods() {
1994   assert_locked_or_safepoint(CodeCache_lock);
1995 
1996   if (has_unloaded_dependent()) {
1997     _dependencies = nmethodBucket::clean_dependent_nmethods(_dependencies);
1998     set_has_unloaded_dependent(false);
1999   }
2000 #ifdef ASSERT
2001   else {
2002     // Verification
2003     for (nmethodBucket* b = _dependencies; b != NULL; b = b->next()) {
2004       assert(b->count() >= 0, "bucket count: %d", b->count());
2005       assert(b->count() != 0, "empty buckets need to be cleaned");
2006     }
2007   }
2008 #endif
2009 }
2010 
2011 void InstanceKlass::add_dependent_nmethod(nmethod* nm) {
2012   assert_locked_or_safepoint(CodeCache_lock);
2013   _dependencies = nmethodBucket::add_dependent_nmethod(_dependencies, nm);
2014 }
2015 
2016 void InstanceKlass::remove_dependent_nmethod(nmethod* nm) {
2017   assert_locked_or_safepoint(CodeCache_lock);
2018 
2019   if (nmethodBucket::remove_dependent_nmethod(_dependencies, nm)) {
2020     set_has_unloaded_dependent(true);
2021   }
2022 }
2023 
2024 #ifndef PRODUCT


3093             "this class isn't found in class loader data");
3094 
3095   // Verify vtables
3096   if (is_linked()) {
3097     ResourceMark rm;
3098     // $$$ This used to be done only for m/s collections.  Doing it
3099     // always seemed a valid generalization.  (DLD -- 6/00)
3100     vtable()->verify(st);
3101   }
3102 
3103   // Verify first subklass
3104   if (subklass() != NULL) {
3105     guarantee(subklass()->is_klass(), "should be klass");
3106   }
3107 
3108   // Verify siblings
3109   Klass* super = this->super();
3110   Klass* sib = next_sibling();
3111   if (sib != NULL) {
3112     if (sib == this) {
3113       fatal("subclass points to itself " PTR_FORMAT, sib);
3114     }
3115 
3116     guarantee(sib->is_klass(), "should be klass");
3117     guarantee(sib->super() == super, "siblings should have same superklass");
3118   }
3119 
3120   // Verify implementor fields
3121   Klass* im = implementor();
3122   if (im != NULL) {
3123     guarantee(is_interface(), "only interfaces should have implementor set");
3124     guarantee(im->is_klass(), "should be klass");
3125     guarantee(!im->is_interface() || im == this,
3126       "implementors cannot be interfaces");
3127   }
3128 
3129   // Verify local interfaces
3130   if (local_interfaces()) {
3131     Array<Klass*>* local_interfaces = this->local_interfaces();
3132     for (int j = 0; j < local_interfaces->length(); j++) {
3133       Klass* e = local_interfaces->at(j);


< prev index next >