hotspot/src/share/vm/code/nmethod.cpp
changeset 27247 99db666dbe8e
parent 26912 19021f626ad2
child 27429 4ccd0992d680
equal deleted inserted replaced
27155:9059987242ca 27247:99db666dbe8e
  1698   // attempt to report the event in the unlikely scenario where the
  1698   // attempt to report the event in the unlikely scenario where the
  1699   // event is enabled at the time the nmethod is made a zombie.
  1699   // event is enabled at the time the nmethod is made a zombie.
  1700   set_unload_reported();
  1700   set_unload_reported();
  1701 }
  1701 }
  1702 
  1702 
  1703 void static clean_ic_if_metadata_is_dead(CompiledIC *ic, BoolObjectClosure *is_alive) {
  1703 void static clean_ic_if_metadata_is_dead(CompiledIC *ic, BoolObjectClosure *is_alive, bool mark_on_stack) {
  1704   if (ic->is_icholder_call()) {
  1704   if (ic->is_icholder_call()) {
  1705     // The only exception is compiledICHolder oops which may
  1705     // The only exception is compiledICHolder oops which may
  1706     // yet be marked below. (We check this further below).
  1706     // yet be marked below. (We check this further below).
  1707     CompiledICHolder* cichk_oop = ic->cached_icholder();
  1707     CompiledICHolder* cichk_oop = ic->cached_icholder();
       
  1708 
       
  1709     if (mark_on_stack) {
       
  1710       Metadata::mark_on_stack(cichk_oop->holder_method());
       
  1711       Metadata::mark_on_stack(cichk_oop->holder_klass());
       
  1712     }
       
  1713 
  1708     if (cichk_oop->holder_method()->method_holder()->is_loader_alive(is_alive) &&
  1714     if (cichk_oop->holder_method()->method_holder()->is_loader_alive(is_alive) &&
  1709         cichk_oop->holder_klass()->is_loader_alive(is_alive)) {
  1715         cichk_oop->holder_klass()->is_loader_alive(is_alive)) {
  1710       return;
  1716       return;
  1711     }
  1717     }
  1712   } else {
  1718   } else {
  1713     Metadata* ic_oop = ic->cached_metadata();
  1719     Metadata* ic_oop = ic->cached_metadata();
  1714     if (ic_oop != NULL) {
  1720     if (ic_oop != NULL) {
       
  1721       if (mark_on_stack) {
       
  1722         Metadata::mark_on_stack(ic_oop);
       
  1723       }
       
  1724 
  1715       if (ic_oop->is_klass()) {
  1725       if (ic_oop->is_klass()) {
  1716         if (((Klass*)ic_oop)->is_loader_alive(is_alive)) {
  1726         if (((Klass*)ic_oop)->is_loader_alive(is_alive)) {
  1717           return;
  1727           return;
  1718         }
  1728         }
  1719       } else if (ic_oop->is_method()) {
  1729       } else if (ic_oop->is_method()) {
  1770   if (unloading_occurred) {
  1780   if (unloading_occurred) {
  1771     RelocIterator iter(this, low_boundary);
  1781     RelocIterator iter(this, low_boundary);
  1772     while(iter.next()) {
  1782     while(iter.next()) {
  1773       if (iter.type() == relocInfo::virtual_call_type) {
  1783       if (iter.type() == relocInfo::virtual_call_type) {
  1774         CompiledIC *ic = CompiledIC_at(&iter);
  1784         CompiledIC *ic = CompiledIC_at(&iter);
  1775         clean_ic_if_metadata_is_dead(ic, is_alive);
  1785         clean_ic_if_metadata_is_dead(ic, is_alive, false);
  1776       }
  1786       }
  1777     }
  1787     }
  1778   }
  1788   }
  1779 
  1789 
  1780   // Compiled code
  1790   // Compiled code
  1838 
  1848 
  1839 static bool clean_if_nmethod_is_unloaded(CompiledStaticCall *csc, BoolObjectClosure *is_alive, nmethod* from) {
  1849 static bool clean_if_nmethod_is_unloaded(CompiledStaticCall *csc, BoolObjectClosure *is_alive, nmethod* from) {
  1840   return clean_if_nmethod_is_unloaded(csc, csc->destination(), is_alive, from);
  1850   return clean_if_nmethod_is_unloaded(csc, csc->destination(), is_alive, from);
  1841 }
  1851 }
  1842 
  1852 
       
  1853 bool nmethod::unload_if_dead_at(RelocIterator* iter_at_oop, BoolObjectClosure *is_alive, bool unloading_occurred) {
       
  1854   assert(iter_at_oop->type() == relocInfo::oop_type, "Wrong relocation type");
       
  1855 
       
  1856   oop_Relocation* r = iter_at_oop->oop_reloc();
       
  1857   // Traverse those oops directly embedded in the code.
       
  1858   // Other oops (oop_index>0) are seen as part of scopes_oops.
       
  1859   assert(1 == (r->oop_is_immediate()) +
       
  1860          (r->oop_addr() >= oops_begin() && r->oop_addr() < oops_end()),
       
  1861          "oop must be found in exactly one place");
       
  1862   if (r->oop_is_immediate() && r->oop_value() != NULL) {
       
  1863     // Unload this nmethod if the oop is dead.
       
  1864     if (can_unload(is_alive, r->oop_addr(), unloading_occurred)) {
       
  1865       return true;;
       
  1866     }
       
  1867   }
       
  1868 
       
  1869   return false;
       
  1870 }
       
  1871 
       
  1872 void nmethod::mark_metadata_on_stack_at(RelocIterator* iter_at_metadata) {
       
  1873   assert(iter_at_metadata->type() == relocInfo::metadata_type, "Wrong relocation type");
       
  1874 
       
  1875   metadata_Relocation* r = iter_at_metadata->metadata_reloc();
       
  1876   // In this metadata, we must only follow those metadatas directly embedded in
       
  1877   // the code.  Other metadatas (oop_index>0) are seen as part of
       
  1878   // the metadata section below.
       
  1879   assert(1 == (r->metadata_is_immediate()) +
       
  1880          (r->metadata_addr() >= metadata_begin() && r->metadata_addr() < metadata_end()),
       
  1881          "metadata must be found in exactly one place");
       
  1882   if (r->metadata_is_immediate() && r->metadata_value() != NULL) {
       
  1883     Metadata* md = r->metadata_value();
       
  1884     if (md != _method) Metadata::mark_on_stack(md);
       
  1885   }
       
  1886 }
       
  1887 
       
  1888 void nmethod::mark_metadata_on_stack_non_relocs() {
       
  1889     // Visit the metadata section
       
  1890     for (Metadata** p = metadata_begin(); p < metadata_end(); p++) {
       
  1891       if (*p == Universe::non_oop_word() || *p == NULL)  continue;  // skip non-oops
       
  1892       Metadata* md = *p;
       
  1893       Metadata::mark_on_stack(md);
       
  1894     }
       
  1895 
       
  1896     // Visit metadata not embedded in the other places.
       
  1897     if (_method != NULL) Metadata::mark_on_stack(_method);
       
  1898 }
       
  1899 
  1843 bool nmethod::do_unloading_parallel(BoolObjectClosure* is_alive, bool unloading_occurred) {
  1900 bool nmethod::do_unloading_parallel(BoolObjectClosure* is_alive, bool unloading_occurred) {
  1844   ResourceMark rm;
  1901   ResourceMark rm;
  1845 
  1902 
  1846   // Make sure the oop's ready to receive visitors
  1903   // Make sure the oop's ready to receive visitors
  1847   assert(!is_zombie() && !is_unloaded(),
  1904   assert(!is_zombie() && !is_unloaded(),
  1867     // call to post_compiled_method_unload() so that the unloading
  1924     // call to post_compiled_method_unload() so that the unloading
  1868     // of this nmethod is reported.
  1925     // of this nmethod is reported.
  1869     unloading_occurred = true;
  1926     unloading_occurred = true;
  1870   }
  1927   }
  1871 
  1928 
       
  1929   // When class redefinition is used all metadata in the CodeCache has to be recorded,
       
  1930   // so that unused "previous versions" can be purged. Since walking the CodeCache can
       
  1931   // be expensive, the "mark on stack" is piggy-backed on this parallel unloading code.
       
  1932   bool mark_metadata_on_stack = a_class_was_redefined;
       
  1933 
  1872   // Exception cache
  1934   // Exception cache
  1873   clean_exception_cache(is_alive);
  1935   clean_exception_cache(is_alive);
  1874 
  1936 
  1875   bool is_unloaded = false;
  1937   bool is_unloaded = false;
  1876   bool postponed = false;
  1938   bool postponed = false;
  1882 
  1944 
  1883     case relocInfo::virtual_call_type:
  1945     case relocInfo::virtual_call_type:
  1884       if (unloading_occurred) {
  1946       if (unloading_occurred) {
  1885         // If class unloading occurred we first iterate over all inline caches and
  1947         // If class unloading occurred we first iterate over all inline caches and
  1886         // clear ICs where the cached oop is referring to an unloaded klass or method.
  1948         // clear ICs where the cached oop is referring to an unloaded klass or method.
  1887         clean_ic_if_metadata_is_dead(CompiledIC_at(&iter), is_alive);
  1949         clean_ic_if_metadata_is_dead(CompiledIC_at(&iter), is_alive, mark_metadata_on_stack);
  1888       }
  1950       }
  1889 
  1951 
  1890       postponed |= clean_if_nmethod_is_unloaded(CompiledIC_at(&iter), is_alive, this);
  1952       postponed |= clean_if_nmethod_is_unloaded(CompiledIC_at(&iter), is_alive, this);
  1891       break;
  1953       break;
  1892 
  1954 
  1898       postponed |= clean_if_nmethod_is_unloaded(compiledStaticCall_at(iter.reloc()), is_alive, this);
  1960       postponed |= clean_if_nmethod_is_unloaded(compiledStaticCall_at(iter.reloc()), is_alive, this);
  1899       break;
  1961       break;
  1900 
  1962 
  1901     case relocInfo::oop_type:
  1963     case relocInfo::oop_type:
  1902       if (!is_unloaded) {
  1964       if (!is_unloaded) {
  1903         // Unload check
  1965         is_unloaded = unload_if_dead_at(&iter, is_alive, unloading_occurred);
  1904         oop_Relocation* r = iter.oop_reloc();
       
  1905         // Traverse those oops directly embedded in the code.
       
  1906         // Other oops (oop_index>0) are seen as part of scopes_oops.
       
  1907         assert(1 == (r->oop_is_immediate()) +
       
  1908                   (r->oop_addr() >= oops_begin() && r->oop_addr() < oops_end()),
       
  1909               "oop must be found in exactly one place");
       
  1910         if (r->oop_is_immediate() && r->oop_value() != NULL) {
       
  1911           if (can_unload(is_alive, r->oop_addr(), unloading_occurred)) {
       
  1912             is_unloaded = true;
       
  1913           }
       
  1914         }
       
  1915       }
  1966       }
  1916       break;
  1967       break;
  1917 
  1968 
  1918     }
  1969     case relocInfo::metadata_type:
       
  1970       if (mark_metadata_on_stack) {
       
  1971         mark_metadata_on_stack_at(&iter);
       
  1972       }
       
  1973     }
       
  1974   }
       
  1975 
       
  1976   if (mark_metadata_on_stack) {
       
  1977     mark_metadata_on_stack_non_relocs();
  1919   }
  1978   }
  1920 
  1979 
  1921   if (is_unloaded) {
  1980   if (is_unloaded) {
  1922     return postponed;
  1981     return postponed;
  1923   }
  1982   }
  2063     // Visit all immediate references that are embedded in the instruction stream.
  2122     // Visit all immediate references that are embedded in the instruction stream.
  2064     RelocIterator iter(this, low_boundary);
  2123     RelocIterator iter(this, low_boundary);
  2065     while (iter.next()) {
  2124     while (iter.next()) {
  2066       if (iter.type() == relocInfo::metadata_type ) {
  2125       if (iter.type() == relocInfo::metadata_type ) {
  2067         metadata_Relocation* r = iter.metadata_reloc();
  2126         metadata_Relocation* r = iter.metadata_reloc();
  2068         // In this lmetadata, we must only follow those metadatas directly embedded in
  2127         // In this metadata, we must only follow those metadatas directly embedded in
  2069         // the code.  Other metadatas (oop_index>0) are seen as part of
  2128         // the code.  Other metadatas (oop_index>0) are seen as part of
  2070         // the metadata section below.
  2129         // the metadata section below.
  2071         assert(1 == (r->metadata_is_immediate()) +
  2130         assert(1 == (r->metadata_is_immediate()) +
  2072                (r->metadata_addr() >= metadata_begin() && r->metadata_addr() < metadata_end()),
  2131                (r->metadata_addr() >= metadata_begin() && r->metadata_addr() < metadata_end()),
  2073                "metadata must be found in exactly one place");
  2132                "metadata must be found in exactly one place");
  2097     if (*p == Universe::non_oop_word() || *p == NULL)  continue;  // skip non-oops
  2156     if (*p == Universe::non_oop_word() || *p == NULL)  continue;  // skip non-oops
  2098     Metadata* md = *p;
  2157     Metadata* md = *p;
  2099     f(md);
  2158     f(md);
  2100   }
  2159   }
  2101 
  2160 
  2102   // Call function Method*, not embedded in these other places.
  2161   // Visit metadata not embedded in the other places.
  2103   if (_method != NULL) f(_method);
  2162   if (_method != NULL) f(_method);
  2104 }
  2163 }
  2105 
  2164 
  2106 void nmethod::oops_do(OopClosure* f, bool allow_zombie) {
  2165 void nmethod::oops_do(OopClosure* f, bool allow_zombie) {
  2107   // make sure the oops ready to receive visitors
  2166   // make sure the oops ready to receive visitors