OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 1911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1922 ASSERT(map() == NULL || Size() >= kNextOffset + kPointerSize); | 1922 ASSERT(map() == NULL || Size() >= kNextOffset + kPointerSize); |
1923 Memory::Address_at(address() + kNextOffset) = | 1923 Memory::Address_at(address() + kNextOffset) = |
1924 reinterpret_cast<Address>(next); | 1924 reinterpret_cast<Address>(next); |
1925 } else { | 1925 } else { |
1926 Memory::Address_at(address() + kPointerSize) = | 1926 Memory::Address_at(address() + kPointerSize) = |
1927 reinterpret_cast<Address>(next); | 1927 reinterpret_cast<Address>(next); |
1928 } | 1928 } |
1929 } | 1929 } |
1930 | 1930 |
1931 | 1931 |
| 1932 void FreeListCategory::Reset() { |
| 1933 top_ = NULL; |
| 1934 end_ = NULL; |
| 1935 available_ = 0; |
| 1936 } |
| 1937 |
| 1938 |
| 1939 intptr_t FreeListCategory::CountFreeListItemsInList(Page* p) { |
| 1940 intptr_t sum = 0; |
| 1941 FreeListNode* n = top_; |
| 1942 while (n != NULL) { |
| 1943 if (Page::FromAddress(n->address()) == p) { |
| 1944 FreeSpace* free_space = reinterpret_cast<FreeSpace*>(n); |
| 1945 sum += free_space->Size(); |
| 1946 } |
| 1947 n = n->next(); |
| 1948 } |
| 1949 return sum; |
| 1950 } |
| 1951 |
| 1952 |
| 1953 intptr_t FreeListCategory::EvictFreeListItemsInList(Page* p) { |
| 1954 intptr_t sum = 0; |
| 1955 FreeListNode** n = &top_; |
| 1956 while (*n != NULL) { |
| 1957 if (Page::FromAddress((*n)->address()) == p) { |
| 1958 FreeSpace* free_space = reinterpret_cast<FreeSpace*>(*n); |
| 1959 sum += free_space->Size(); |
| 1960 *n = (*n)->next(); |
| 1961 } else { |
| 1962 n = (*n)->next_address(); |
| 1963 } |
| 1964 } |
| 1965 if (top_ == NULL) { |
| 1966 end_ = NULL; |
| 1967 } |
| 1968 available_ -= sum; |
| 1969 return sum; |
| 1970 } |
| 1971 |
| 1972 |
| 1973 FreeListNode* FreeListCategory::PickNodeFromList(int *node_size) { |
| 1974 FreeListNode* node = top_; |
| 1975 |
| 1976 if (node == NULL) return NULL; |
| 1977 |
| 1978 while (node != NULL && |
| 1979 Page::FromAddress(node->address())->IsEvacuationCandidate()) { |
| 1980 available_ -= node->Size(); |
| 1981 node = node->next(); |
| 1982 } |
| 1983 |
| 1984 if (node != NULL) { |
| 1985 set_top(node->next()); |
| 1986 *node_size = node->Size(); |
| 1987 available_ -= *node_size; |
| 1988 } else { |
| 1989 set_top(NULL); |
| 1990 } |
| 1991 |
| 1992 if (top() == NULL) { |
| 1993 set_end(NULL); |
| 1994 } |
| 1995 |
| 1996 return node; |
| 1997 } |
| 1998 |
| 1999 |
| 2000 void FreeListCategory::Free(FreeListNode* node, int size_in_bytes) { |
| 2001 node->set_next(top_); |
| 2002 top_ = node; |
| 2003 if (end_ == NULL) { |
| 2004 end_ = node; |
| 2005 } |
| 2006 available_ += size_in_bytes; |
| 2007 } |
| 2008 |
| 2009 |
| 2010 void FreeListCategory::RepairFreeList(Heap* heap) { |
| 2011 FreeListNode* n = top_; |
| 2012 while (n != NULL) { |
| 2013 Map** map_location = reinterpret_cast<Map**>(n->address()); |
| 2014 if (*map_location == NULL) { |
| 2015 *map_location = heap->free_space_map(); |
| 2016 } else { |
| 2017 ASSERT(*map_location == heap->free_space_map()); |
| 2018 } |
| 2019 n = n->next(); |
| 2020 } |
| 2021 } |
| 2022 |
| 2023 |
1932 FreeList::FreeList(PagedSpace* owner) | 2024 FreeList::FreeList(PagedSpace* owner) |
1933 : owner_(owner), heap_(owner->heap()) { | 2025 : owner_(owner), heap_(owner->heap()) { |
1934 Reset(); | 2026 Reset(); |
1935 } | 2027 } |
1936 | 2028 |
1937 | 2029 |
1938 void FreeList::Reset() { | 2030 void FreeList::Reset() { |
1939 available_ = 0; | 2031 small_list_.Reset(); |
1940 small_list_ = NULL; | 2032 medium_list_.Reset(); |
1941 medium_list_ = NULL; | 2033 large_list_.Reset(); |
1942 large_list_ = NULL; | 2034 huge_list_.Reset(); |
1943 huge_list_ = NULL; | |
1944 } | 2035 } |
1945 | 2036 |
1946 | 2037 |
1947 int FreeList::Free(Address start, int size_in_bytes) { | 2038 int FreeList::Free(Address start, int size_in_bytes) { |
1948 if (size_in_bytes == 0) return 0; | 2039 if (size_in_bytes == 0) return 0; |
| 2040 |
1949 FreeListNode* node = FreeListNode::FromAddress(start); | 2041 FreeListNode* node = FreeListNode::FromAddress(start); |
1950 node->set_size(heap_, size_in_bytes); | 2042 node->set_size(heap_, size_in_bytes); |
1951 | 2043 |
1952 // Early return to drop too-small blocks on the floor. | 2044 // Early return to drop too-small blocks on the floor. |
1953 if (size_in_bytes < kSmallListMin) return size_in_bytes; | 2045 if (size_in_bytes < kSmallListMin) return size_in_bytes; |
1954 | 2046 |
1955 // Insert other blocks at the head of a free list of the appropriate | 2047 // Insert other blocks at the head of a free list of the appropriate |
1956 // magnitude. | 2048 // magnitude. |
1957 if (size_in_bytes <= kSmallListMax) { | 2049 if (size_in_bytes <= kSmallListMax) { |
1958 node->set_next(small_list_); | 2050 small_list_.Free(node, size_in_bytes); |
1959 small_list_ = node; | |
1960 } else if (size_in_bytes <= kMediumListMax) { | 2051 } else if (size_in_bytes <= kMediumListMax) { |
1961 node->set_next(medium_list_); | 2052 medium_list_.Free(node, size_in_bytes); |
1962 medium_list_ = node; | |
1963 } else if (size_in_bytes <= kLargeListMax) { | 2053 } else if (size_in_bytes <= kLargeListMax) { |
1964 node->set_next(large_list_); | 2054 large_list_.Free(node, size_in_bytes); |
1965 large_list_ = node; | |
1966 } else { | 2055 } else { |
1967 node->set_next(huge_list_); | 2056 huge_list_.Free(node, size_in_bytes); |
1968 huge_list_ = node; | |
1969 } | 2057 } |
1970 available_ += size_in_bytes; | 2058 |
1971 ASSERT(IsVeryLong() || available_ == SumFreeLists()); | 2059 ASSERT(IsVeryLong() || available() == SumFreeLists()); |
1972 return 0; | 2060 return 0; |
1973 } | 2061 } |
1974 | 2062 |
1975 | 2063 |
1976 FreeListNode* FreeList::PickNodeFromList(FreeListNode** list, int* node_size) { | |
1977 FreeListNode* node = *list; | |
1978 | |
1979 if (node == NULL) return NULL; | |
1980 | |
1981 while (node != NULL && | |
1982 Page::FromAddress(node->address())->IsEvacuationCandidate()) { | |
1983 available_ -= node->Size(); | |
1984 node = node->next(); | |
1985 } | |
1986 | |
1987 if (node != NULL) { | |
1988 *node_size = node->Size(); | |
1989 *list = node->next(); | |
1990 } else { | |
1991 *list = NULL; | |
1992 } | |
1993 | |
1994 return node; | |
1995 } | |
1996 | |
1997 | |
1998 FreeListNode* FreeList::FindNodeFor(int size_in_bytes, int* node_size) { | 2064 FreeListNode* FreeList::FindNodeFor(int size_in_bytes, int* node_size) { |
1999 FreeListNode* node = NULL; | 2065 FreeListNode* node = NULL; |
2000 | 2066 |
2001 if (size_in_bytes <= kSmallAllocationMax) { | 2067 if (size_in_bytes <= kSmallAllocationMax) { |
2002 node = PickNodeFromList(&small_list_, node_size); | 2068 node = small_list_.PickNodeFromList(node_size); |
2003 if (node != NULL) return node; | 2069 if (node != NULL) return node; |
2004 } | 2070 } |
2005 | 2071 |
2006 if (size_in_bytes <= kMediumAllocationMax) { | 2072 if (size_in_bytes <= kMediumAllocationMax) { |
2007 node = PickNodeFromList(&medium_list_, node_size); | 2073 node = medium_list_.PickNodeFromList(node_size); |
2008 if (node != NULL) return node; | 2074 if (node != NULL) return node; |
2009 } | 2075 } |
2010 | 2076 |
2011 if (size_in_bytes <= kLargeAllocationMax) { | 2077 if (size_in_bytes <= kLargeAllocationMax) { |
2012 node = PickNodeFromList(&large_list_, node_size); | 2078 node = large_list_.PickNodeFromList(node_size); |
2013 if (node != NULL) return node; | 2079 if (node != NULL) return node; |
2014 } | 2080 } |
2015 | 2081 |
2016 for (FreeListNode** cur = &huge_list_; | 2082 int huge_list_available = huge_list_.available(); |
| 2083 for (FreeListNode** cur = huge_list_.GetTopAddress(); |
2017 *cur != NULL; | 2084 *cur != NULL; |
2018 cur = (*cur)->next_address()) { | 2085 cur = (*cur)->next_address()) { |
2019 FreeListNode* cur_node = *cur; | 2086 FreeListNode* cur_node = *cur; |
2020 while (cur_node != NULL && | 2087 while (cur_node != NULL && |
2021 Page::FromAddress(cur_node->address())->IsEvacuationCandidate()) { | 2088 Page::FromAddress(cur_node->address())->IsEvacuationCandidate()) { |
2022 available_ -= reinterpret_cast<FreeSpace*>(cur_node)->Size(); | 2089 huge_list_available -= reinterpret_cast<FreeSpace*>(cur_node)->Size(); |
2023 cur_node = cur_node->next(); | 2090 cur_node = cur_node->next(); |
2024 } | 2091 } |
2025 | 2092 |
2026 *cur = cur_node; | 2093 *cur = cur_node; |
2027 if (cur_node == NULL) break; | 2094 if (cur_node == NULL) { |
| 2095 huge_list_.set_end(NULL); |
| 2096 break; |
| 2097 } |
2028 | 2098 |
2029 ASSERT((*cur)->map() == HEAP->raw_unchecked_free_space_map()); | 2099 ASSERT((*cur)->map() == HEAP->raw_unchecked_free_space_map()); |
2030 FreeSpace* cur_as_free_space = reinterpret_cast<FreeSpace*>(*cur); | 2100 FreeSpace* cur_as_free_space = reinterpret_cast<FreeSpace*>(*cur); |
2031 int size = cur_as_free_space->Size(); | 2101 int size = cur_as_free_space->Size(); |
2032 if (size >= size_in_bytes) { | 2102 if (size >= size_in_bytes) { |
2033 // Large enough node found. Unlink it from the list. | 2103 // Large enough node found. Unlink it from the list. |
2034 node = *cur; | 2104 node = *cur; |
| 2105 *cur = node->next(); |
2035 *node_size = size; | 2106 *node_size = size; |
2036 *cur = node->next(); | 2107 huge_list_available -= size; |
2037 break; | 2108 break; |
2038 } | 2109 } |
2039 } | 2110 } |
2040 | 2111 |
| 2112 if (huge_list_.top() == NULL) { |
| 2113 huge_list_.set_end(NULL); |
| 2114 } |
| 2115 |
| 2116 huge_list_.set_available(huge_list_available); |
| 2117 ASSERT(IsVeryLong() || available() == SumFreeLists()); |
| 2118 |
2041 return node; | 2119 return node; |
2042 } | 2120 } |
2043 | 2121 |
2044 | 2122 |
2045 // Allocation on the old space free list. If it succeeds then a new linear | 2123 // Allocation on the old space free list. If it succeeds then a new linear |
2046 // allocation space has been set up with the top and limit of the space. If | 2124 // allocation space has been set up with the top and limit of the space. If |
2047 // the allocation fails then NULL is returned, and the caller can perform a GC | 2125 // the allocation fails then NULL is returned, and the caller can perform a GC |
2048 // or allocate a new page before retrying. | 2126 // or allocate a new page before retrying. |
2049 HeapObject* FreeList::Allocate(int size_in_bytes) { | 2127 HeapObject* FreeList::Allocate(int size_in_bytes) { |
2050 ASSERT(0 < size_in_bytes); | 2128 ASSERT(0 < size_in_bytes); |
2051 ASSERT(size_in_bytes <= kMaxBlockSize); | 2129 ASSERT(size_in_bytes <= kMaxBlockSize); |
2052 ASSERT(IsAligned(size_in_bytes, kPointerSize)); | 2130 ASSERT(IsAligned(size_in_bytes, kPointerSize)); |
2053 // Don't free list allocate if there is linear space available. | 2131 // Don't free list allocate if there is linear space available. |
2054 ASSERT(owner_->limit() - owner_->top() < size_in_bytes); | 2132 ASSERT(owner_->limit() - owner_->top() < size_in_bytes); |
2055 | 2133 |
2056 int new_node_size = 0; | 2134 int new_node_size = 0; |
2057 FreeListNode* new_node = FindNodeFor(size_in_bytes, &new_node_size); | 2135 FreeListNode* new_node = FindNodeFor(size_in_bytes, &new_node_size); |
2058 if (new_node == NULL) return NULL; | 2136 if (new_node == NULL) return NULL; |
2059 | 2137 |
2060 available_ -= new_node_size; | |
2061 ASSERT(IsVeryLong() || available_ == SumFreeLists()); | |
2062 | 2138 |
2063 int bytes_left = new_node_size - size_in_bytes; | 2139 int bytes_left = new_node_size - size_in_bytes; |
2064 ASSERT(bytes_left >= 0); | 2140 ASSERT(bytes_left >= 0); |
2065 | 2141 |
2066 int old_linear_size = static_cast<int>(owner_->limit() - owner_->top()); | 2142 int old_linear_size = static_cast<int>(owner_->limit() - owner_->top()); |
2067 // Mark the old linear allocation area with a free space map so it can be | 2143 // Mark the old linear allocation area with a free space map so it can be |
2068 // skipped when scanning the heap. This also puts it back in the free list | 2144 // skipped when scanning the heap. This also puts it back in the free list |
2069 // if it is big enough. | 2145 // if it is big enough. |
2070 owner_->Free(owner_->top(), old_linear_size); | 2146 owner_->Free(owner_->top(), old_linear_size); |
2071 | 2147 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2109 } else { | 2185 } else { |
2110 // TODO(gc) Try not freeing linear allocation region when bytes_left | 2186 // TODO(gc) Try not freeing linear allocation region when bytes_left |
2111 // are zero. | 2187 // are zero. |
2112 owner_->SetTop(NULL, NULL); | 2188 owner_->SetTop(NULL, NULL); |
2113 } | 2189 } |
2114 | 2190 |
2115 return new_node; | 2191 return new_node; |
2116 } | 2192 } |
2117 | 2193 |
2118 | 2194 |
2119 static intptr_t CountFreeListItemsInList(FreeListNode* n, Page* p) { | |
2120 intptr_t sum = 0; | |
2121 while (n != NULL) { | |
2122 if (Page::FromAddress(n->address()) == p) { | |
2123 FreeSpace* free_space = reinterpret_cast<FreeSpace*>(n); | |
2124 sum += free_space->Size(); | |
2125 } | |
2126 n = n->next(); | |
2127 } | |
2128 return sum; | |
2129 } | |
2130 | |
2131 | |
2132 void FreeList::CountFreeListItems(Page* p, SizeStats* sizes) { | 2195 void FreeList::CountFreeListItems(Page* p, SizeStats* sizes) { |
2133 sizes->huge_size_ = CountFreeListItemsInList(huge_list_, p); | 2196 sizes->huge_size_ = huge_list_.CountFreeListItemsInList(p); |
2134 if (sizes->huge_size_ < p->area_size()) { | 2197 if (sizes->huge_size_ < p->area_size()) { |
2135 sizes->small_size_ = CountFreeListItemsInList(small_list_, p); | 2198 sizes->small_size_ = small_list_.CountFreeListItemsInList(p); |
2136 sizes->medium_size_ = CountFreeListItemsInList(medium_list_, p); | 2199 sizes->medium_size_ = medium_list_.CountFreeListItemsInList(p); |
2137 sizes->large_size_ = CountFreeListItemsInList(large_list_, p); | 2200 sizes->large_size_ = large_list_.CountFreeListItemsInList(p); |
2138 } else { | 2201 } else { |
2139 sizes->small_size_ = 0; | 2202 sizes->small_size_ = 0; |
2140 sizes->medium_size_ = 0; | 2203 sizes->medium_size_ = 0; |
2141 sizes->large_size_ = 0; | 2204 sizes->large_size_ = 0; |
2142 } | 2205 } |
2143 } | 2206 } |
2144 | 2207 |
2145 | 2208 |
2146 static intptr_t EvictFreeListItemsInList(FreeListNode** n, Page* p) { | |
2147 intptr_t sum = 0; | |
2148 while (*n != NULL) { | |
2149 if (Page::FromAddress((*n)->address()) == p) { | |
2150 FreeSpace* free_space = reinterpret_cast<FreeSpace*>(*n); | |
2151 sum += free_space->Size(); | |
2152 *n = (*n)->next(); | |
2153 } else { | |
2154 n = (*n)->next_address(); | |
2155 } | |
2156 } | |
2157 return sum; | |
2158 } | |
2159 | |
2160 | |
2161 intptr_t FreeList::EvictFreeListItems(Page* p) { | 2209 intptr_t FreeList::EvictFreeListItems(Page* p) { |
2162 intptr_t sum = EvictFreeListItemsInList(&huge_list_, p); | 2210 intptr_t sum = huge_list_.EvictFreeListItemsInList(p); |
2163 | 2211 |
2164 if (sum < p->area_size()) { | 2212 if (sum < p->area_size()) { |
2165 sum += EvictFreeListItemsInList(&small_list_, p) + | 2213 sum += small_list_.EvictFreeListItemsInList(p) + |
2166 EvictFreeListItemsInList(&medium_list_, p) + | 2214 medium_list_.EvictFreeListItemsInList(p) + |
2167 EvictFreeListItemsInList(&large_list_, p); | 2215 large_list_.EvictFreeListItemsInList(p); |
2168 } | 2216 } |
2169 | 2217 |
2170 available_ -= static_cast<int>(sum); | |
2171 | |
2172 return sum; | 2218 return sum; |
2173 } | 2219 } |
2174 | 2220 |
2175 | 2221 |
| 2222 void FreeList::RepairLists(Heap* heap) { |
| 2223 small_list_.RepairFreeList(heap); |
| 2224 medium_list_.RepairFreeList(heap); |
| 2225 large_list_.RepairFreeList(heap); |
| 2226 huge_list_.RepairFreeList(heap); |
| 2227 } |
| 2228 |
| 2229 |
2176 #ifdef DEBUG | 2230 #ifdef DEBUG |
2177 intptr_t FreeList::SumFreeList(FreeListNode* cur) { | 2231 intptr_t FreeListCategory::SumFreeList() { |
2178 intptr_t sum = 0; | 2232 intptr_t sum = 0; |
| 2233 FreeListNode* cur = top_; |
2179 while (cur != NULL) { | 2234 while (cur != NULL) { |
2180 ASSERT(cur->map() == HEAP->raw_unchecked_free_space_map()); | 2235 ASSERT(cur->map() == HEAP->raw_unchecked_free_space_map()); |
2181 FreeSpace* cur_as_free_space = reinterpret_cast<FreeSpace*>(cur); | 2236 FreeSpace* cur_as_free_space = reinterpret_cast<FreeSpace*>(cur); |
2182 sum += cur_as_free_space->Size(); | 2237 sum += cur_as_free_space->Size(); |
2183 cur = cur->next(); | 2238 cur = cur->next(); |
2184 } | 2239 } |
2185 return sum; | 2240 return sum; |
2186 } | 2241 } |
2187 | 2242 |
2188 | 2243 |
2189 static const int kVeryLongFreeList = 500; | 2244 static const int kVeryLongFreeList = 500; |
2190 | 2245 |
2191 | 2246 |
2192 int FreeList::FreeListLength(FreeListNode* cur) { | 2247 int FreeListCategory::FreeListLength() { |
2193 int length = 0; | 2248 int length = 0; |
| 2249 FreeListNode* cur = top_; |
2194 while (cur != NULL) { | 2250 while (cur != NULL) { |
2195 length++; | 2251 length++; |
2196 cur = cur->next(); | 2252 cur = cur->next(); |
2197 if (length == kVeryLongFreeList) return length; | 2253 if (length == kVeryLongFreeList) return length; |
2198 } | 2254 } |
2199 return length; | 2255 return length; |
2200 } | 2256 } |
2201 | 2257 |
2202 | 2258 |
2203 bool FreeList::IsVeryLong() { | 2259 bool FreeList::IsVeryLong() { |
2204 if (FreeListLength(small_list_) == kVeryLongFreeList) return true; | 2260 if (small_list_.FreeListLength() == kVeryLongFreeList) return true; |
2205 if (FreeListLength(medium_list_) == kVeryLongFreeList) return true; | 2261 if (medium_list_.FreeListLength() == kVeryLongFreeList) return true; |
2206 if (FreeListLength(large_list_) == kVeryLongFreeList) return true; | 2262 if (large_list_.FreeListLength() == kVeryLongFreeList) return true; |
2207 if (FreeListLength(huge_list_) == kVeryLongFreeList) return true; | 2263 if (huge_list_.FreeListLength() == kVeryLongFreeList) return true; |
2208 return false; | 2264 return false; |
2209 } | 2265 } |
2210 | 2266 |
2211 | 2267 |
2212 // This can take a very long time because it is linear in the number of entries | 2268 // This can take a very long time because it is linear in the number of entries |
2213 // on the free list, so it should not be called if FreeListLength returns | 2269 // on the free list, so it should not be called if FreeListLength returns |
2214 // kVeryLongFreeList. | 2270 // kVeryLongFreeList. |
2215 intptr_t FreeList::SumFreeLists() { | 2271 intptr_t FreeList::SumFreeLists() { |
2216 intptr_t sum = SumFreeList(small_list_); | 2272 intptr_t sum = small_list_.SumFreeList(); |
2217 sum += SumFreeList(medium_list_); | 2273 sum += medium_list_.SumFreeList(); |
2218 sum += SumFreeList(large_list_); | 2274 sum += large_list_.SumFreeList(); |
2219 sum += SumFreeList(huge_list_); | 2275 sum += huge_list_.SumFreeList(); |
2220 return sum; | 2276 return sum; |
2221 } | 2277 } |
2222 #endif | 2278 #endif |
2223 | 2279 |
2224 | 2280 |
2225 // ----------------------------------------------------------------------------- | 2281 // ----------------------------------------------------------------------------- |
2226 // OldSpace implementation | 2282 // OldSpace implementation |
2227 | 2283 |
2228 bool NewSpace::ReserveSpace(int bytes) { | 2284 bool NewSpace::ReserveSpace(int bytes) { |
2229 // We can't reliably unpack a partial snapshot that needs more new space | 2285 // We can't reliably unpack a partial snapshot that needs more new space |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2297 // Mark the old linear allocation area with a free space so it can be | 2353 // Mark the old linear allocation area with a free space so it can be |
2298 // skipped when scanning the heap. This also puts it back in the free list | 2354 // skipped when scanning the heap. This also puts it back in the free list |
2299 // if it is big enough. | 2355 // if it is big enough. |
2300 Free(top(), old_linear_size); | 2356 Free(top(), old_linear_size); |
2301 | 2357 |
2302 SetTop(new_area->address(), new_area->address() + size_in_bytes); | 2358 SetTop(new_area->address(), new_area->address() + size_in_bytes); |
2303 return true; | 2359 return true; |
2304 } | 2360 } |
2305 | 2361 |
2306 | 2362 |
2307 static void RepairFreeList(Heap* heap, FreeListNode* n) { | |
2308 while (n != NULL) { | |
2309 Map** map_location = reinterpret_cast<Map**>(n->address()); | |
2310 if (*map_location == NULL) { | |
2311 *map_location = heap->free_space_map(); | |
2312 } else { | |
2313 ASSERT(*map_location == heap->free_space_map()); | |
2314 } | |
2315 n = n->next(); | |
2316 } | |
2317 } | |
2318 | |
2319 | |
2320 void FreeList::RepairLists(Heap* heap) { | |
2321 RepairFreeList(heap, small_list_); | |
2322 RepairFreeList(heap, medium_list_); | |
2323 RepairFreeList(heap, large_list_); | |
2324 RepairFreeList(heap, huge_list_); | |
2325 } | |
2326 | |
2327 | |
2328 // After we have booted, we have created a map which represents free space | 2363 // After we have booted, we have created a map which represents free space |
2329 // on the heap. If there was already a free list then the elements on it | 2364 // on the heap. If there was already a free list then the elements on it |
2330 // were created with the wrong FreeSpaceMap (normally NULL), so we need to | 2365 // were created with the wrong FreeSpaceMap (normally NULL), so we need to |
2331 // fix them. | 2366 // fix them. |
2332 void PagedSpace::RepairFreeListsAfterBoot() { | 2367 void PagedSpace::RepairFreeListsAfterBoot() { |
2333 free_list_.RepairLists(heap()); | 2368 free_list_.RepairLists(heap()); |
2334 } | 2369 } |
2335 | 2370 |
2336 | 2371 |
2337 // You have to call this last, since the implementation from PagedSpace | 2372 // You have to call this last, since the implementation from PagedSpace |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2950 object->ShortPrint(); | 2985 object->ShortPrint(); |
2951 PrintF("\n"); | 2986 PrintF("\n"); |
2952 } | 2987 } |
2953 printf(" --------------------------------------\n"); | 2988 printf(" --------------------------------------\n"); |
2954 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 2989 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
2955 } | 2990 } |
2956 | 2991 |
2957 #endif // DEBUG | 2992 #endif // DEBUG |
2958 | 2993 |
2959 } } // namespace v8::internal | 2994 } } // namespace v8::internal |
OLD | NEW |