OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1712 if (external_string_table_.old_space_strings_.length() > 0) { | 1712 if (external_string_table_.old_space_strings_.length() > 0) { |
1713 Object** start = &external_string_table_.old_space_strings_[0]; | 1713 Object** start = &external_string_table_.old_space_strings_[0]; |
1714 Object** end = start + external_string_table_.old_space_strings_.length(); | 1714 Object** end = start + external_string_table_.old_space_strings_.length(); |
1715 for (Object** p = start; p < end; ++p) *p = updater_func(this, p); | 1715 for (Object** p = start; p < end; ++p) *p = updater_func(this, p); |
1716 } | 1716 } |
1717 | 1717 |
1718 UpdateNewSpaceReferencesInExternalStringTable(updater_func); | 1718 UpdateNewSpaceReferencesInExternalStringTable(updater_func); |
1719 } | 1719 } |
1720 | 1720 |
1721 | 1721 |
1722 template <class T> | |
1723 struct WeakListVisitor; | |
1724 | |
1725 | |
1726 template <class T> | |
1727 static Object* VisitWeakList(Heap* heap, | |
1728 Object* list, | |
1729 WeakObjectRetainer* retainer, | |
1730 bool record_slots) { | |
1731 Object* undefined = heap->undefined_value(); | |
1732 Object* head = undefined; | |
1733 T* tail = NULL; | |
1734 MarkCompactCollector* collector = heap->mark_compact_collector(); | |
1735 while (list != undefined) { | |
1736 // Check whether to keep the candidate in the list. | |
1737 T* candidate = reinterpret_cast<T*>(list); | |
1738 Object* retained = retainer->RetainAs(list); | |
1739 if (retained != NULL) { | |
1740 if (head == undefined) { | |
1741 // First element in the list. | |
1742 head = retained; | |
1743 } else { | |
1744 // Subsequent elements in the list. | |
1745 ASSERT(tail != NULL); | |
1746 WeakListVisitor<T>::SetWeakNext(tail, retained); | |
1747 if (record_slots) { | |
1748 Object** next_slot = | |
1749 HeapObject::RawField(tail, WeakListVisitor<T>::WeakNextOffset()); | |
1750 collector->RecordSlot(next_slot, next_slot, retained); | |
1751 } | |
1752 } | |
1753 // Retained object is new tail. | |
1754 ASSERT(!retained->IsUndefined()); | |
1755 candidate = reinterpret_cast<T*>(retained); | |
1756 tail = candidate; | |
1757 | |
1758 | |
1759 // tail is a live object, visit it. | |
1760 WeakListVisitor<T>::VisitLiveObject( | |
1761 heap, tail, retainer, record_slots); | |
1762 } else { | |
1763 WeakListVisitor<T>::VisitPhantomObject(heap, candidate); | |
1764 } | |
1765 | |
1766 // Move to next element in the list. | |
1767 list = WeakListVisitor<T>::WeakNext(candidate); | |
1768 } | |
1769 | |
1770 // Terminate the list if there is one or more elements. | |
1771 if (tail != NULL) { | |
1772 WeakListVisitor<T>::SetWeakNext(tail, undefined); | |
1773 } | |
1774 return head; | |
1775 } | |
1776 | |
1777 | |
1778 template <class T> | |
1779 static void ClearWeakList(Heap* heap, | |
1780 Object* list) { | |
1781 Object* undefined = heap->undefined_value(); | |
1782 while (list != undefined) { | |
1783 T* candidate = reinterpret_cast<T*>(list); | |
1784 list = WeakListVisitor<T>::WeakNext(candidate); | |
1785 WeakListVisitor<T>::SetWeakNext(candidate, undefined); | |
1786 } | |
1787 } | |
1788 | |
1789 | |
1790 template<> | |
1791 struct WeakListVisitor<JSFunction> { | |
1792 static void SetWeakNext(JSFunction* function, Object* next) { | |
1793 function->set_next_function_link(next); | |
1794 } | |
1795 | |
1796 static Object* WeakNext(JSFunction* function) { | |
1797 return function->next_function_link(); | |
1798 } | |
1799 | |
1800 static int WeakNextOffset() { | |
1801 return JSFunction::kNextFunctionLinkOffset; | |
1802 } | |
1803 | |
1804 static void VisitLiveObject(Heap*, JSFunction*, | |
1805 WeakObjectRetainer*, bool) { | |
1806 } | |
1807 | |
1808 static void VisitPhantomObject(Heap*, JSFunction*) { | |
1809 } | |
1810 }; | |
1811 | |
1812 | |
1813 template<> | |
1814 struct WeakListVisitor<Code> { | |
1815 static void SetWeakNext(Code* code, Object* next) { | |
1816 code->set_next_code_link(next); | |
1817 } | |
1818 | |
1819 static Object* WeakNext(Code* code) { | |
1820 return code->next_code_link(); | |
1821 } | |
1822 | |
1823 static int WeakNextOffset() { | |
1824 return Code::kNextCodeLinkOffset; | |
1825 } | |
1826 | |
1827 static void VisitLiveObject(Heap*, Code*, | |
1828 WeakObjectRetainer*, bool) { | |
1829 } | |
1830 | |
1831 static void VisitPhantomObject(Heap*, Code*) { | |
1832 } | |
1833 }; | |
1834 | |
1835 | |
1836 template<> | |
1837 struct WeakListVisitor<Context> { | |
1838 static void SetWeakNext(Context* context, Object* next) { | |
1839 context->set(Context::NEXT_CONTEXT_LINK, | |
1840 next, | |
1841 UPDATE_WRITE_BARRIER); | |
1842 } | |
1843 | |
1844 static Object* WeakNext(Context* context) { | |
1845 return context->get(Context::NEXT_CONTEXT_LINK); | |
1846 } | |
1847 | |
1848 static void VisitLiveObject(Heap* heap, | |
1849 Context* context, | |
1850 WeakObjectRetainer* retainer, | |
1851 bool record_slots) { | |
1852 // Process the three weak lists linked off the context. | |
1853 DoWeakList<JSFunction>(heap, context, retainer, record_slots, | |
1854 Context::OPTIMIZED_FUNCTIONS_LIST); | |
1855 DoWeakList<Code>(heap, context, retainer, record_slots, | |
1856 Context::OPTIMIZED_CODE_LIST); | |
1857 DoWeakList<Code>(heap, context, retainer, record_slots, | |
1858 Context::DEOPTIMIZED_CODE_LIST); | |
1859 } | |
1860 | |
1861 template<class T> | |
1862 static void DoWeakList(Heap* heap, | |
1863 Context* context, | |
1864 WeakObjectRetainer* retainer, | |
1865 bool record_slots, | |
1866 int index) { | |
1867 // Visit the weak list, removing dead intermediate elements. | |
1868 Object* list_head = VisitWeakList<T>(heap, context->get(index), retainer, | |
1869 record_slots); | |
1870 | |
1871 // Update the list head. | |
1872 context->set(index, list_head, UPDATE_WRITE_BARRIER); | |
1873 | |
1874 if (record_slots) { | |
1875 // Record the updated slot if necessary. | |
1876 Object** head_slot = HeapObject::RawField( | |
1877 context, FixedArray::SizeFor(index)); | |
1878 heap->mark_compact_collector()->RecordSlot( | |
1879 head_slot, head_slot, list_head); | |
1880 } | |
1881 } | |
1882 | |
1883 static void VisitPhantomObject(Heap* heap, Context* context) { | |
1884 ClearWeakList<JSFunction>(heap, | |
1885 context->get(Context::OPTIMIZED_FUNCTIONS_LIST)); | |
1886 ClearWeakList<Code>(heap, context->get(Context::OPTIMIZED_CODE_LIST)); | |
1887 ClearWeakList<Code>(heap, context->get(Context::DEOPTIMIZED_CODE_LIST)); | |
1888 } | |
1889 | |
1890 static int WeakNextOffset() { | |
1891 return FixedArray::SizeFor(Context::NEXT_CONTEXT_LINK); | |
1892 } | |
1893 }; | |
1894 | |
1895 | |
1896 void Heap::ProcessWeakReferences(WeakObjectRetainer* retainer) { | 1722 void Heap::ProcessWeakReferences(WeakObjectRetainer* retainer) { |
1897 // We don't record weak slots during marking or scavenges. | 1723 // We don't record weak slots during marking or scavenges. |
1898 // Instead we do it once when we complete mark-compact cycle. | 1724 // Instead we do it once when we complete mark-compact cycle. |
1899 // Note that write barrier has no effect if we are already in the middle of | 1725 // Note that write barrier has no effect if we are already in the middle of |
1900 // compacting mark-sweep cycle and we have to record slots manually. | 1726 // compacting mark-sweep cycle and we have to record slots manually. |
1901 bool record_slots = | 1727 bool record_slots = |
1902 gc_state() == MARK_COMPACT && | 1728 gc_state() == MARK_COMPACT && |
1903 mark_compact_collector()->is_compacting(); | 1729 mark_compact_collector()->is_compacting(); |
1904 ProcessArrayBuffers(retainer, record_slots); | 1730 ProcessArrayBuffers(retainer, record_slots); |
1905 ProcessNativeContexts(retainer, record_slots); | 1731 ProcessNativeContexts(retainer, record_slots); |
1906 // TODO(mvstanton): AllocationSites only need to be processed during | 1732 // TODO(mvstanton): AllocationSites only need to be processed during |
1907 // MARK_COMPACT, as they live in old space. Verify and address. | 1733 // MARK_COMPACT, as they live in old space. Verify and address. |
1908 ProcessAllocationSites(retainer, record_slots); | 1734 ProcessAllocationSites(retainer, record_slots); |
1909 } | 1735 } |
1910 | 1736 |
1911 void Heap::ProcessNativeContexts(WeakObjectRetainer* retainer, | 1737 void Heap::ProcessNativeContexts(WeakObjectRetainer* retainer, |
1912 bool record_slots) { | 1738 bool record_slots) { |
1913 Object* head = | 1739 Object* head = |
1914 VisitWeakList<Context>( | 1740 VisitWeakList<Context>( |
1915 this, native_contexts_list(), retainer, record_slots); | 1741 this, native_contexts_list(), retainer, record_slots); |
1916 // Update the head of the list of contexts. | 1742 // Update the head of the list of contexts. |
1917 native_contexts_list_ = head; | 1743 native_contexts_list_ = head; |
1918 } | 1744 } |
1919 | 1745 |
1920 | 1746 |
1921 template<> | |
1922 struct WeakListVisitor<JSArrayBufferView> { | |
1923 static void SetWeakNext(JSArrayBufferView* obj, Object* next) { | |
1924 obj->set_weak_next(next); | |
1925 } | |
1926 | |
1927 static Object* WeakNext(JSArrayBufferView* obj) { | |
1928 return obj->weak_next(); | |
1929 } | |
1930 | |
1931 static void VisitLiveObject(Heap*, | |
1932 JSArrayBufferView* obj, | |
1933 WeakObjectRetainer* retainer, | |
1934 bool record_slots) {} | |
1935 | |
1936 static void VisitPhantomObject(Heap*, JSArrayBufferView*) {} | |
1937 | |
1938 static int WeakNextOffset() { | |
1939 return JSArrayBufferView::kWeakNextOffset; | |
1940 } | |
1941 }; | |
1942 | |
1943 | |
1944 template<> | |
1945 struct WeakListVisitor<JSArrayBuffer> { | |
1946 static void SetWeakNext(JSArrayBuffer* obj, Object* next) { | |
1947 obj->set_weak_next(next); | |
1948 } | |
1949 | |
1950 static Object* WeakNext(JSArrayBuffer* obj) { | |
1951 return obj->weak_next(); | |
1952 } | |
1953 | |
1954 static void VisitLiveObject(Heap* heap, | |
1955 JSArrayBuffer* array_buffer, | |
1956 WeakObjectRetainer* retainer, | |
1957 bool record_slots) { | |
1958 Object* typed_array_obj = | |
1959 VisitWeakList<JSArrayBufferView>( | |
1960 heap, | |
1961 array_buffer->weak_first_view(), | |
1962 retainer, record_slots); | |
1963 array_buffer->set_weak_first_view(typed_array_obj); | |
1964 if (typed_array_obj != heap->undefined_value() && record_slots) { | |
1965 Object** slot = HeapObject::RawField( | |
1966 array_buffer, JSArrayBuffer::kWeakFirstViewOffset); | |
1967 heap->mark_compact_collector()->RecordSlot(slot, slot, typed_array_obj); | |
1968 } | |
1969 } | |
1970 | |
1971 static void VisitPhantomObject(Heap* heap, JSArrayBuffer* phantom) { | |
1972 Runtime::FreeArrayBuffer(heap->isolate(), phantom); | |
1973 } | |
1974 | |
1975 static int WeakNextOffset() { | |
1976 return JSArrayBuffer::kWeakNextOffset; | |
1977 } | |
1978 }; | |
1979 | |
1980 | |
1981 void Heap::ProcessArrayBuffers(WeakObjectRetainer* retainer, | 1747 void Heap::ProcessArrayBuffers(WeakObjectRetainer* retainer, |
1982 bool record_slots) { | 1748 bool record_slots) { |
1983 Object* array_buffer_obj = | 1749 Object* array_buffer_obj = |
1984 VisitWeakList<JSArrayBuffer>(this, | 1750 VisitWeakList<JSArrayBuffer>(this, |
1985 array_buffers_list(), | 1751 array_buffers_list(), |
1986 retainer, record_slots); | 1752 retainer, record_slots); |
1987 set_array_buffers_list(array_buffer_obj); | 1753 set_array_buffers_list(array_buffer_obj); |
1988 } | 1754 } |
1989 | 1755 |
1990 | 1756 |
1991 void Heap::TearDownArrayBuffers() { | 1757 void Heap::TearDownArrayBuffers() { |
1992 Object* undefined = undefined_value(); | 1758 Object* undefined = undefined_value(); |
1993 for (Object* o = array_buffers_list(); o != undefined;) { | 1759 for (Object* o = array_buffers_list(); o != undefined;) { |
1994 JSArrayBuffer* buffer = JSArrayBuffer::cast(o); | 1760 JSArrayBuffer* buffer = JSArrayBuffer::cast(o); |
1995 Runtime::FreeArrayBuffer(isolate(), buffer); | 1761 Runtime::FreeArrayBuffer(isolate(), buffer); |
1996 o = buffer->weak_next(); | 1762 o = buffer->weak_next(); |
1997 } | 1763 } |
1998 array_buffers_list_ = undefined; | 1764 array_buffers_list_ = undefined; |
1999 } | 1765 } |
2000 | 1766 |
2001 | 1767 |
2002 template<> | |
2003 struct WeakListVisitor<AllocationSite> { | |
2004 static void SetWeakNext(AllocationSite* obj, Object* next) { | |
2005 obj->set_weak_next(next); | |
2006 } | |
2007 | |
2008 static Object* WeakNext(AllocationSite* obj) { | |
2009 return obj->weak_next(); | |
2010 } | |
2011 | |
2012 static void VisitLiveObject(Heap* heap, | |
2013 AllocationSite* site, | |
2014 WeakObjectRetainer* retainer, | |
2015 bool record_slots) {} | |
2016 | |
2017 static void VisitPhantomObject(Heap* heap, AllocationSite* phantom) {} | |
2018 | |
2019 static int WeakNextOffset() { | |
2020 return AllocationSite::kWeakNextOffset; | |
2021 } | |
2022 }; | |
2023 | |
2024 | |
2025 void Heap::ProcessAllocationSites(WeakObjectRetainer* retainer, | 1768 void Heap::ProcessAllocationSites(WeakObjectRetainer* retainer, |
2026 bool record_slots) { | 1769 bool record_slots) { |
2027 Object* allocation_site_obj = | 1770 Object* allocation_site_obj = |
2028 VisitWeakList<AllocationSite>(this, | 1771 VisitWeakList<AllocationSite>(this, |
2029 allocation_sites_list(), | 1772 allocation_sites_list(), |
2030 retainer, record_slots); | 1773 retainer, record_slots); |
2031 set_allocation_sites_list(allocation_site_obj); | 1774 set_allocation_sites_list(allocation_site_obj); |
2032 } | 1775 } |
2033 | 1776 |
2034 | 1777 |
(...skipping 2139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4174 code->set_raw_kind_specific_flags2(0); | 3917 code->set_raw_kind_specific_flags2(0); |
4175 code->set_is_crankshafted(crankshafted); | 3918 code->set_is_crankshafted(crankshafted); |
4176 code->set_deoptimization_data(empty_fixed_array(), SKIP_WRITE_BARRIER); | 3919 code->set_deoptimization_data(empty_fixed_array(), SKIP_WRITE_BARRIER); |
4177 code->set_raw_type_feedback_info(undefined_value()); | 3920 code->set_raw_type_feedback_info(undefined_value()); |
4178 code->set_next_code_link(undefined_value()); | 3921 code->set_next_code_link(undefined_value()); |
4179 code->set_handler_table(empty_fixed_array(), SKIP_WRITE_BARRIER); | 3922 code->set_handler_table(empty_fixed_array(), SKIP_WRITE_BARRIER); |
4180 code->set_gc_metadata(Smi::FromInt(0)); | 3923 code->set_gc_metadata(Smi::FromInt(0)); |
4181 code->set_ic_age(global_ic_age_); | 3924 code->set_ic_age(global_ic_age_); |
4182 code->set_prologue_offset(prologue_offset); | 3925 code->set_prologue_offset(prologue_offset); |
4183 if (code->kind() == Code::OPTIMIZED_FUNCTION) { | 3926 if (code->kind() == Code::OPTIMIZED_FUNCTION) { |
4184 code->set_marked_for_deoptimization(false); | 3927 ASSERT(!code->marked_for_deoptimization()); |
| 3928 } |
| 3929 if (code->is_inline_cache_stub()) { |
| 3930 ASSERT(!code->is_weak_stub()); |
| 3931 ASSERT(!code->is_invalidated_weak_stub()); |
4185 } | 3932 } |
4186 | 3933 |
4187 if (FLAG_enable_ool_constant_pool) { | 3934 if (FLAG_enable_ool_constant_pool) { |
4188 desc.origin->PopulateConstantPool(constant_pool); | 3935 desc.origin->PopulateConstantPool(constant_pool); |
4189 } | 3936 } |
4190 code->set_constant_pool(constant_pool); | 3937 code->set_constant_pool(constant_pool); |
4191 | 3938 |
4192 #ifdef ENABLE_DEBUGGER_SUPPORT | 3939 #ifdef ENABLE_DEBUGGER_SUPPORT |
4193 if (code->kind() == Code::FUNCTION) { | 3940 if (code->kind() == Code::FUNCTION) { |
4194 code->set_has_debug_break_slots( | 3941 code->set_has_debug_break_slots( |
(...skipping 3670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7865 static_cast<int>(object_sizes_last_time_[index])); | 7612 static_cast<int>(object_sizes_last_time_[index])); |
7866 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 7613 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
7867 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 7614 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
7868 | 7615 |
7869 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 7616 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
7870 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 7617 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
7871 ClearObjectStats(); | 7618 ClearObjectStats(); |
7872 } | 7619 } |
7873 | 7620 |
7874 } } // namespace v8::internal | 7621 } } // namespace v8::internal |
OLD | NEW |