1718 // attempt to report the event in the unlikely scenario where the |
1718 // attempt to report the event in the unlikely scenario where the |
1719 // event is enabled at the time the nmethod is made a zombie. |
1719 // event is enabled at the time the nmethod is made a zombie. |
1720 set_unload_reported(); |
1720 set_unload_reported(); |
1721 } |
1721 } |
1722 |
1722 |
1723 void static clean_ic_if_metadata_is_dead(CompiledIC *ic, BoolObjectClosure *is_alive) { |
1723 void static clean_ic_if_metadata_is_dead(CompiledIC *ic, BoolObjectClosure *is_alive, bool mark_on_stack) { |
1724 if (ic->is_icholder_call()) { |
1724 if (ic->is_icholder_call()) { |
1725 // The only exception is compiledICHolder oops which may |
1725 // The only exception is compiledICHolder oops which may |
1726 // yet be marked below. (We check this further below). |
1726 // yet be marked below. (We check this further below). |
1727 CompiledICHolder* cichk_oop = ic->cached_icholder(); |
1727 CompiledICHolder* cichk_oop = ic->cached_icholder(); |
|
1728 |
|
1729 if (mark_on_stack) { |
|
1730 Metadata::mark_on_stack(cichk_oop->holder_method()); |
|
1731 Metadata::mark_on_stack(cichk_oop->holder_klass()); |
|
1732 } |
|
1733 |
1728 if (cichk_oop->holder_method()->method_holder()->is_loader_alive(is_alive) && |
1734 if (cichk_oop->holder_method()->method_holder()->is_loader_alive(is_alive) && |
1729 cichk_oop->holder_klass()->is_loader_alive(is_alive)) { |
1735 cichk_oop->holder_klass()->is_loader_alive(is_alive)) { |
1730 return; |
1736 return; |
1731 } |
1737 } |
1732 } else { |
1738 } else { |
1733 Metadata* ic_oop = ic->cached_metadata(); |
1739 Metadata* ic_oop = ic->cached_metadata(); |
1734 if (ic_oop != NULL) { |
1740 if (ic_oop != NULL) { |
|
1741 if (mark_on_stack) { |
|
1742 Metadata::mark_on_stack(ic_oop); |
|
1743 } |
|
1744 |
1735 if (ic_oop->is_klass()) { |
1745 if (ic_oop->is_klass()) { |
1736 if (((Klass*)ic_oop)->is_loader_alive(is_alive)) { |
1746 if (((Klass*)ic_oop)->is_loader_alive(is_alive)) { |
1737 return; |
1747 return; |
1738 } |
1748 } |
1739 } else if (ic_oop->is_method()) { |
1749 } else if (ic_oop->is_method()) { |
1790 if (unloading_occurred) { |
1800 if (unloading_occurred) { |
1791 RelocIterator iter(this, low_boundary); |
1801 RelocIterator iter(this, low_boundary); |
1792 while(iter.next()) { |
1802 while(iter.next()) { |
1793 if (iter.type() == relocInfo::virtual_call_type) { |
1803 if (iter.type() == relocInfo::virtual_call_type) { |
1794 CompiledIC *ic = CompiledIC_at(&iter); |
1804 CompiledIC *ic = CompiledIC_at(&iter); |
1795 clean_ic_if_metadata_is_dead(ic, is_alive); |
1805 clean_ic_if_metadata_is_dead(ic, is_alive, false); |
1796 } |
1806 } |
1797 } |
1807 } |
1798 } |
1808 } |
1799 |
1809 |
1800 // Compiled code |
1810 // Compiled code |
1858 |
1868 |
1859 static bool clean_if_nmethod_is_unloaded(CompiledStaticCall *csc, BoolObjectClosure *is_alive, nmethod* from) { |
1869 static bool clean_if_nmethod_is_unloaded(CompiledStaticCall *csc, BoolObjectClosure *is_alive, nmethod* from) { |
1860 return clean_if_nmethod_is_unloaded(csc, csc->destination(), is_alive, from); |
1870 return clean_if_nmethod_is_unloaded(csc, csc->destination(), is_alive, from); |
1861 } |
1871 } |
1862 |
1872 |
|
1873 bool nmethod::unload_if_dead_at(RelocIterator* iter_at_oop, BoolObjectClosure *is_alive, bool unloading_occurred) { |
|
1874 assert(iter_at_oop->type() == relocInfo::oop_type, "Wrong relocation type"); |
|
1875 |
|
1876 oop_Relocation* r = iter_at_oop->oop_reloc(); |
|
1877 // Traverse those oops directly embedded in the code. |
|
1878 // Other oops (oop_index>0) are seen as part of scopes_oops. |
|
1879 assert(1 == (r->oop_is_immediate()) + |
|
1880 (r->oop_addr() >= oops_begin() && r->oop_addr() < oops_end()), |
|
1881 "oop must be found in exactly one place"); |
|
1882 if (r->oop_is_immediate() && r->oop_value() != NULL) { |
|
1883 // Unload this nmethod if the oop is dead. |
|
1884 if (can_unload(is_alive, r->oop_addr(), unloading_occurred)) { |
|
1885 return true;; |
|
1886 } |
|
1887 } |
|
1888 |
|
1889 return false; |
|
1890 } |
|
1891 |
|
1892 void nmethod::mark_metadata_on_stack_at(RelocIterator* iter_at_metadata) { |
|
1893 assert(iter_at_metadata->type() == relocInfo::metadata_type, "Wrong relocation type"); |
|
1894 |
|
1895 metadata_Relocation* r = iter_at_metadata->metadata_reloc(); |
|
1896 // In this metadata, we must only follow those metadatas directly embedded in |
|
1897 // the code. Other metadatas (oop_index>0) are seen as part of |
|
1898 // the metadata section below. |
|
1899 assert(1 == (r->metadata_is_immediate()) + |
|
1900 (r->metadata_addr() >= metadata_begin() && r->metadata_addr() < metadata_end()), |
|
1901 "metadata must be found in exactly one place"); |
|
1902 if (r->metadata_is_immediate() && r->metadata_value() != NULL) { |
|
1903 Metadata* md = r->metadata_value(); |
|
1904 if (md != _method) Metadata::mark_on_stack(md); |
|
1905 } |
|
1906 } |
|
1907 |
|
1908 void nmethod::mark_metadata_on_stack_non_relocs() { |
|
1909 // Visit the metadata section |
|
1910 for (Metadata** p = metadata_begin(); p < metadata_end(); p++) { |
|
1911 if (*p == Universe::non_oop_word() || *p == NULL) continue; // skip non-oops |
|
1912 Metadata* md = *p; |
|
1913 Metadata::mark_on_stack(md); |
|
1914 } |
|
1915 |
|
1916 // Visit metadata not embedded in the other places. |
|
1917 if (_method != NULL) Metadata::mark_on_stack(_method); |
|
1918 } |
|
1919 |
1863 bool nmethod::do_unloading_parallel(BoolObjectClosure* is_alive, bool unloading_occurred) { |
1920 bool nmethod::do_unloading_parallel(BoolObjectClosure* is_alive, bool unloading_occurred) { |
1864 ResourceMark rm; |
1921 ResourceMark rm; |
1865 |
1922 |
1866 // Make sure the oop's ready to receive visitors |
1923 // Make sure the oop's ready to receive visitors |
1867 assert(!is_zombie() && !is_unloaded(), |
1924 assert(!is_zombie() && !is_unloaded(), |
1887 // call to post_compiled_method_unload() so that the unloading |
1944 // call to post_compiled_method_unload() so that the unloading |
1888 // of this nmethod is reported. |
1945 // of this nmethod is reported. |
1889 unloading_occurred = true; |
1946 unloading_occurred = true; |
1890 } |
1947 } |
1891 |
1948 |
|
1949 // When class redefinition is used all metadata in the CodeCache has to be recorded, |
|
1950 // so that unused "previous versions" can be purged. Since walking the CodeCache can |
|
1951 // be expensive, the "mark on stack" is piggy-backed on this parallel unloading code. |
|
1952 bool mark_metadata_on_stack = a_class_was_redefined; |
|
1953 |
1892 // Exception cache |
1954 // Exception cache |
1893 clean_exception_cache(is_alive); |
1955 clean_exception_cache(is_alive); |
1894 |
1956 |
1895 bool is_unloaded = false; |
1957 bool is_unloaded = false; |
1896 bool postponed = false; |
1958 bool postponed = false; |
1902 |
1964 |
1903 case relocInfo::virtual_call_type: |
1965 case relocInfo::virtual_call_type: |
1904 if (unloading_occurred) { |
1966 if (unloading_occurred) { |
1905 // If class unloading occurred we first iterate over all inline caches and |
1967 // If class unloading occurred we first iterate over all inline caches and |
1906 // clear ICs where the cached oop is referring to an unloaded klass or method. |
1968 // clear ICs where the cached oop is referring to an unloaded klass or method. |
1907 clean_ic_if_metadata_is_dead(CompiledIC_at(&iter), is_alive); |
1969 clean_ic_if_metadata_is_dead(CompiledIC_at(&iter), is_alive, mark_metadata_on_stack); |
1908 } |
1970 } |
1909 |
1971 |
1910 postponed |= clean_if_nmethod_is_unloaded(CompiledIC_at(&iter), is_alive, this); |
1972 postponed |= clean_if_nmethod_is_unloaded(CompiledIC_at(&iter), is_alive, this); |
1911 break; |
1973 break; |
1912 |
1974 |
1918 postponed |= clean_if_nmethod_is_unloaded(compiledStaticCall_at(iter.reloc()), is_alive, this); |
1980 postponed |= clean_if_nmethod_is_unloaded(compiledStaticCall_at(iter.reloc()), is_alive, this); |
1919 break; |
1981 break; |
1920 |
1982 |
1921 case relocInfo::oop_type: |
1983 case relocInfo::oop_type: |
1922 if (!is_unloaded) { |
1984 if (!is_unloaded) { |
1923 // Unload check |
1985 is_unloaded = unload_if_dead_at(&iter, is_alive, unloading_occurred); |
1924 oop_Relocation* r = iter.oop_reloc(); |
|
1925 // Traverse those oops directly embedded in the code. |
|
1926 // Other oops (oop_index>0) are seen as part of scopes_oops. |
|
1927 assert(1 == (r->oop_is_immediate()) + |
|
1928 (r->oop_addr() >= oops_begin() && r->oop_addr() < oops_end()), |
|
1929 "oop must be found in exactly one place"); |
|
1930 if (r->oop_is_immediate() && r->oop_value() != NULL) { |
|
1931 if (can_unload(is_alive, r->oop_addr(), unloading_occurred)) { |
|
1932 is_unloaded = true; |
|
1933 } |
|
1934 } |
|
1935 } |
1986 } |
1936 break; |
1987 break; |
1937 |
1988 |
1938 } |
1989 case relocInfo::metadata_type: |
|
1990 if (mark_metadata_on_stack) { |
|
1991 mark_metadata_on_stack_at(&iter); |
|
1992 } |
|
1993 } |
|
1994 } |
|
1995 |
|
1996 if (mark_metadata_on_stack) { |
|
1997 mark_metadata_on_stack_non_relocs(); |
1939 } |
1998 } |
1940 |
1999 |
1941 if (is_unloaded) { |
2000 if (is_unloaded) { |
1942 return postponed; |
2001 return postponed; |
1943 } |
2002 } |
2083 // Visit all immediate references that are embedded in the instruction stream. |
2142 // Visit all immediate references that are embedded in the instruction stream. |
2084 RelocIterator iter(this, low_boundary); |
2143 RelocIterator iter(this, low_boundary); |
2085 while (iter.next()) { |
2144 while (iter.next()) { |
2086 if (iter.type() == relocInfo::metadata_type ) { |
2145 if (iter.type() == relocInfo::metadata_type ) { |
2087 metadata_Relocation* r = iter.metadata_reloc(); |
2146 metadata_Relocation* r = iter.metadata_reloc(); |
2088 // In this lmetadata, we must only follow those metadatas directly embedded in |
2147 // In this metadata, we must only follow those metadatas directly embedded in |
2089 // the code. Other metadatas (oop_index>0) are seen as part of |
2148 // the code. Other metadatas (oop_index>0) are seen as part of |
2090 // the metadata section below. |
2149 // the metadata section below. |
2091 assert(1 == (r->metadata_is_immediate()) + |
2150 assert(1 == (r->metadata_is_immediate()) + |
2092 (r->metadata_addr() >= metadata_begin() && r->metadata_addr() < metadata_end()), |
2151 (r->metadata_addr() >= metadata_begin() && r->metadata_addr() < metadata_end()), |
2093 "metadata must be found in exactly one place"); |
2152 "metadata must be found in exactly one place"); |
2117 if (*p == Universe::non_oop_word() || *p == NULL) continue; // skip non-oops |
2176 if (*p == Universe::non_oop_word() || *p == NULL) continue; // skip non-oops |
2118 Metadata* md = *p; |
2177 Metadata* md = *p; |
2119 f(md); |
2178 f(md); |
2120 } |
2179 } |
2121 |
2180 |
2122 // Call function Method*, not embedded in these other places. |
2181 // Visit metadata not embedded in the other places. |
2123 if (_method != NULL) f(_method); |
2182 if (_method != NULL) f(_method); |
2124 } |
2183 } |
2125 |
2184 |
2126 void nmethod::oops_do(OopClosure* f, bool allow_zombie) { |
2185 void nmethod::oops_do(OopClosure* f, bool allow_zombie) { |
2127 // make sure the oops ready to receive visitors |
2186 // make sure the oops ready to receive visitors |