< prev index next >

src/share/vm/oops/instanceKlass.cpp

Print this page




1813   size_t idnum = (size_t)method->method_idnum();
1814   jmethodID* jmeths = methods_jmethod_ids_acquire();
1815   size_t length;                                // length assigned as debugging crumb
1816   jmethodID id = NULL;
1817   if (jmeths != NULL &&                         // If there is a cache
1818       (length = (size_t)jmeths[0]) > idnum) {   // and if it is long enough,
1819     id = jmeths[idnum+1];                       // Look up the id (may be NULL)
1820   }
1821   return id;
1822 }
1823 
1824 int nmethodBucket::decrement() {
1825   return Atomic::add(-1, (volatile int *)&_count);
1826 }
1827 
1828 //
1829 // Walk the list of dependent nmethods searching for nmethods which
1830 // are dependent on the changes that were passed in and mark them for
1831 // deoptimization.  Returns the number of nmethods found.
1832 //
1833 int InstanceKlass::mark_dependent_nmethods(DepChange& changes) {
1834   assert_locked_or_safepoint(CodeCache_lock);
1835   int found = 0;
1836   nmethodBucket* b = _dependencies;
1837   while (b != NULL) {
1838     nmethod* nm = b->get_nmethod();
1839     // since dependencies aren't removed until an nmethod becomes a zombie,
1840     // the dependency list may contain nmethods which aren't alive.
1841     if (b->count() > 0 && nm->is_alive() && !nm->is_marked_for_deoptimization() && nm->check_dependency_on(changes)) {
1842       if (TraceDependencies) {
1843         ResourceMark rm;
1844         tty->print_cr("Marked for deoptimization");
1845         tty->print_cr("  context = %s", this->external_name());
1846         changes.print();
1847         nm->print();
1848         nm->print_dependencies();
1849       }
1850       nm->mark_for_deoptimization();
1851       found++;
1852     }
1853     b = b->next();
1854   }
1855   return found;
1856 }
1857 
1858 void InstanceKlass::clean_dependent_nmethods() {
1859   assert_locked_or_safepoint(CodeCache_lock);
1860 
1861   if (has_unloaded_dependent()) {
1862     nmethodBucket* b = _dependencies;
1863     nmethodBucket* last = NULL;
1864     while (b != NULL) {
1865       assert(b->count() >= 0, err_msg("bucket count: %d", b->count()));
1866 
1867       nmethodBucket* next = b->next();
1868 
1869       if (b->count() == 0) {
1870         if (last == NULL) {
1871           _dependencies = next;
1872         } else {
1873           last->set_next(next);
1874         }
1875         delete b;
1876         // last stays the same.
1877       } else {
1878         last = b;
1879       }
1880 
1881       b = next;
1882     }
1883     set_has_unloaded_dependent(false);
1884   }
1885 #ifdef ASSERT
1886   else {
1887     // Verification
1888     for (nmethodBucket* b = _dependencies; b != NULL; b = b->next()) {
1889       assert(b->count() >= 0, err_msg("bucket count: %d", b->count()));
1890       assert(b->count() != 0, "empty buckets need to be cleaned");
1891     }
1892   }
1893 #endif
1894 }
1895 
1896 //
1897 // Add an nmethodBucket to the list of dependencies for this nmethod.
1898 // It's possible that an nmethod has multiple dependencies on this klass
1899 // so a count is kept for each bucket to guarantee that creation and
1900 // deletion of dependencies is consistent.
1901 //
1902 void InstanceKlass::add_dependent_nmethod(nmethod* nm) {
1903   assert_locked_or_safepoint(CodeCache_lock);
1904   nmethodBucket* b = _dependencies;
1905   nmethodBucket* last = NULL;
1906   while (b != NULL) {
1907     if (nm == b->get_nmethod()) {
1908       b->increment();
1909       return;
1910     }
1911     b = b->next();
1912   }
1913   _dependencies = new nmethodBucket(nm, _dependencies);
1914 }
1915 
1916 
1917 //
1918 // Decrement count of the nmethod in the dependency list and remove
1919 // the bucket competely when the count goes to 0.  This method must
1920 // find a corresponding bucket otherwise there's a bug in the
1921 // recording of dependecies.
1922 //
1923 void InstanceKlass::remove_dependent_nmethod(nmethod* nm) {
1924   assert_locked_or_safepoint(CodeCache_lock);
1925   nmethodBucket* b = _dependencies;
1926   nmethodBucket* last = NULL;
1927   while (b != NULL) {
1928     if (nm == b->get_nmethod()) {
1929       int val = b->decrement();
1930       guarantee(val >= 0, err_msg("Underflow: %d", val));
1931       if (val == 0) {
1932         set_has_unloaded_dependent(true);
1933       }
1934       return;
1935     }
1936     last = b;
1937     b = b->next();
1938   }
1939 #ifdef ASSERT
1940   tty->print_cr("### %s can't find dependent nmethod:", this->external_name());
1941   nm->print();
1942 #endif // ASSERT
1943   ShouldNotReachHere();

1944 }
1945 


























1946 
1947 #ifndef PRODUCT
1948 void InstanceKlass::print_dependent_nmethods(bool verbose) {
1949   nmethodBucket* b = _dependencies;
1950   int idx = 0;
1951   while (b != NULL) {
1952     nmethod* nm = b->get_nmethod();
1953     tty->print("[%d] count=%d { ", idx++, b->count());
1954     if (!verbose) {
1955       nm->print_on(tty, "nmethod");
1956       tty->print_cr(" } ");
1957     } else {
1958       nm->print();
1959       nm->print_dependencies();
1960       tty->print_cr("--- } ");
1961     }
1962     b = b->next();
1963   }
1964 }
1965 
1966 
1967 bool InstanceKlass::is_dependent_nmethod(nmethod* nm) {
1968   nmethodBucket* b = _dependencies;
1969   while (b != NULL) {
1970     if (nm == b->get_nmethod()) {
1971 #ifdef ASSERT
1972       int count = b->count();
1973       assert(count >= 0, err_msg("count shouldn't be negative: %d", count));
1974 #endif
1975       return true;
1976     }
1977     b = b->next();
1978   }
1979   return false;
1980 }
1981 #endif //PRODUCT
1982 














































1983 void InstanceKlass::clean_implementors_list(BoolObjectClosure* is_alive) {
1984   assert(class_loader_data()->is_alive(is_alive), "this klass should be live");
1985   if (is_interface()) {
1986     if (ClassUnloading) {
1987       Klass* impl = implementor();
1988       if (impl != NULL) {
1989         if (!impl->is_loader_alive(is_alive)) {
1990           // remove this guy
1991           Klass** klass = adr_implementor();
1992           assert(klass != NULL, "null klass");
1993           if (klass != NULL) {
1994             *klass = NULL;
1995           }
1996         }
1997       }
1998     }
1999   }
2000 }
2001 
2002 void InstanceKlass::clean_method_data(BoolObjectClosure* is_alive) {




1813   size_t idnum = (size_t)method->method_idnum();
1814   jmethodID* jmeths = methods_jmethod_ids_acquire();
1815   size_t length;                                // length assigned as debugging crumb
1816   jmethodID id = NULL;
1817   if (jmeths != NULL &&                         // If there is a cache
1818       (length = (size_t)jmeths[0]) > idnum) {   // and if it is long enough,
1819     id = jmeths[idnum+1];                       // Look up the id (may be NULL)
1820   }
1821   return id;
1822 }
1823 
1824 int nmethodBucket::decrement() {
1825   return Atomic::add(-1, (volatile int *)&_count);
1826 }
1827 
1828 //
1829 // Walk the list of dependent nmethods searching for nmethods which
1830 // are dependent on the changes that were passed in and mark them for
1831 // deoptimization.  Returns the number of nmethods found.
1832 //
1833 int nmethodBucket::mark_dependent_nmethods(nmethodBucket* deps, DepChange& changes) {
1834   assert_locked_or_safepoint(CodeCache_lock);
1835   int found = 0;
1836   for (nmethodBucket* b = deps; b != NULL; b = b->next()) {

1837     nmethod* nm = b->get_nmethod();
1838     // since dependencies aren't removed until an nmethod becomes a zombie,
1839     // the dependency list may contain nmethods which aren't alive.
1840     if (b->count() > 0 && nm->is_alive() && !nm->is_marked_for_deoptimization() && nm->check_dependency_on(changes)) {
1841       if (TraceDependencies) {
1842         ResourceMark rm;
1843         tty->print_cr("Marked for deoptimization");

1844         changes.print();
1845         nm->print();
1846         nm->print_dependencies();
1847       }
1848       nm->mark_for_deoptimization();
1849       found++;
1850     }

1851   }
1852   return found;
1853 }
1854 






































1855 //
1856 // Add an nmethodBucket to the list of dependencies for this nmethod.
1857 // It's possible that an nmethod has multiple dependencies on this klass
1858 // so a count is kept for each bucket to guarantee that creation and
1859 // deletion of dependencies is consistent. Returns new head of the list.
1860 //
1861 nmethodBucket* nmethodBucket::add_dependent_nmethod(nmethodBucket* deps, nmethod* nm) {
1862   assert_locked_or_safepoint(CodeCache_lock);
1863   for (nmethodBucket* b = deps; b != NULL; b = b->next()) {


1864     if (nm == b->get_nmethod()) {
1865       b->increment();
1866       return deps;
1867     }

1868   }
1869   return new nmethodBucket(nm, deps);
1870 }
1871 

1872 //
1873 // Decrement count of the nmethod in the dependency list and remove
1874 // the bucket completely when the count goes to 0.  This method must
1875 // find a corresponding bucket otherwise there's a bug in the
1876 // recording of dependencies. Returns true if the bucket is ready for reclamation.
1877 //
1878 bool nmethodBucket::remove_dependent_nmethod(nmethodBucket* deps, nmethod* nm) {
1879   assert_locked_or_safepoint(CodeCache_lock);
1880 
1881   for (nmethodBucket* b = deps; b != NULL; b = b->next()) {

1882     if (nm == b->get_nmethod()) {
1883       int val = b->decrement();
1884       guarantee(val >= 0, err_msg("Underflow: %d", val));
1885       return (val == 0);



1886     }


1887   }
1888 #ifdef ASSERT
1889   tty->print_raw_cr("### can't find dependent nmethod");
1890   nm->print();
1891 #endif // ASSERT
1892   ShouldNotReachHere();
1893   return false;
1894 }
1895 
1896 //
1897 // Reclaim all unused buckets. Returns new head of the list.
1898 //
1899 nmethodBucket* nmethodBucket::clean_dependent_nmethods(nmethodBucket* deps) {
1900   nmethodBucket* first = deps;
1901   nmethodBucket* last = NULL;
1902   nmethodBucket* b = first;
1903 
1904   while (b != NULL) {
1905     assert(b->count() >= 0, err_msg("bucket count: %d", b->count()));
1906     nmethodBucket* next = b->next();
1907     if (b->count() == 0) {
1908       if (last == NULL) {
1909         first = next;
1910       } else {
1911         last->set_next(next);
1912       }
1913       delete b;
1914       // last stays the same.
1915     } else {
1916       last = b;
1917     }
1918     b = next;
1919   }
1920   return first;
1921 }
1922 
1923 #ifndef PRODUCT
1924 void nmethodBucket::print_dependent_nmethods(nmethodBucket* deps, bool verbose) {

1925   int idx = 0;
1926   for (nmethodBucket* b = deps; b != NULL; b = b->next()) {
1927     nmethod* nm = b->get_nmethod();
1928     tty->print("[%d] count=%d { ", idx++, b->count());
1929     if (!verbose) {
1930       nm->print_on(tty, "nmethod");
1931       tty->print_cr(" } ");
1932     } else {
1933       nm->print();
1934       nm->print_dependencies();
1935       tty->print_cr("--- } ");
1936     }

1937   }
1938 }
1939 
1940 bool nmethodBucket::is_dependent_nmethod(nmethodBucket* deps, nmethod* nm) {
1941   for (nmethodBucket* b = deps; b != NULL; b = b->next()) {


1942     if (nm == b->get_nmethod()) {
1943 #ifdef ASSERT
1944       int count = b->count();
1945       assert(count >= 0, err_msg("count shouldn't be negative: %d", count));
1946 #endif
1947       return true;
1948     }

1949   }
1950   return false;
1951 }
1952 #endif //PRODUCT
1953 
1954 int InstanceKlass::mark_dependent_nmethods(DepChange& changes) {
1955   assert_locked_or_safepoint(CodeCache_lock);
1956   return nmethodBucket::mark_dependent_nmethods(_dependencies, changes);
1957 }
1958 
1959 void InstanceKlass::clean_dependent_nmethods() {
1960   assert_locked_or_safepoint(CodeCache_lock);
1961 
1962   if (has_unloaded_dependent()) {
1963     _dependencies = nmethodBucket::clean_dependent_nmethods(_dependencies);
1964     set_has_unloaded_dependent(false);
1965   }
1966 #ifdef ASSERT
1967   else {
1968     // Verification
1969     for (nmethodBucket* b = _dependencies; b != NULL; b = b->next()) {
1970       assert(b->count() >= 0, err_msg("bucket count: %d", b->count()));
1971       assert(b->count() != 0, "empty buckets need to be cleaned");
1972     }
1973   }
1974 #endif
1975 }
1976 
1977 void InstanceKlass::add_dependent_nmethod(nmethod* nm) {
1978   assert_locked_or_safepoint(CodeCache_lock);
1979   _dependencies = nmethodBucket::add_dependent_nmethod(_dependencies, nm);
1980 }
1981 
1982 void InstanceKlass::remove_dependent_nmethod(nmethod* nm) {
1983   assert_locked_or_safepoint(CodeCache_lock);
1984 
1985   if (nmethodBucket::remove_dependent_nmethod(_dependencies, nm)) {
1986     set_has_unloaded_dependent(true);
1987   }
1988 }
1989 
1990 #ifndef PRODUCT
1991 void InstanceKlass::print_dependent_nmethods(bool verbose) {
1992   nmethodBucket::print_dependent_nmethods(_dependencies, verbose);
1993 }
1994 
1995 bool InstanceKlass::is_dependent_nmethod(nmethod* nm) {
1996   return nmethodBucket::is_dependent_nmethod(_dependencies, nm);
1997 }
1998 #endif //PRODUCT
1999 
2000 void InstanceKlass::clean_implementors_list(BoolObjectClosure* is_alive) {
2001   assert(class_loader_data()->is_alive(is_alive), "this klass should be live");
2002   if (is_interface()) {
2003     if (ClassUnloading) {
2004       Klass* impl = implementor();
2005       if (impl != NULL) {
2006         if (!impl->is_loader_alive(is_alive)) {
2007           // remove this guy
2008           Klass** klass = adr_implementor();
2009           assert(klass != NULL, "null klass");
2010           if (klass != NULL) {
2011             *klass = NULL;
2012           }
2013         }
2014       }
2015     }
2016   }
2017 }
2018 
2019 void InstanceKlass::clean_method_data(BoolObjectClosure* is_alive) {


< prev index next >