Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: src/spaces.cc

Issue 13798002: On-the-fly bookkeeping of PagedSpace memory kept in free-lists. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/spaces.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 chunk_size, 690 chunk_size,
691 area_start, 691 area_start,
692 area_end, 692 area_end,
693 executable, 693 executable,
694 owner); 694 owner);
695 result->set_reserved_memory(&reservation); 695 result->set_reserved_memory(&reservation);
696 return result; 696 return result;
697 } 697 }
698 698
699 699
700 void Page::ResetFreeListStatistics() {
701 non_available_small_blocks_ = 0;
702 available_in_small_free_list_ = 0;
703 available_in_medium_free_list_ = 0;
704 available_in_large_free_list_ = 0;
705 available_in_huge_free_list_ = 0;
706 }
707
708
700 Page* MemoryAllocator::AllocatePage(intptr_t size, 709 Page* MemoryAllocator::AllocatePage(intptr_t size,
701 PagedSpace* owner, 710 PagedSpace* owner,
702 Executability executable) { 711 Executability executable) {
703 MemoryChunk* chunk = AllocateChunk(size, size, executable, owner); 712 MemoryChunk* chunk = AllocateChunk(size, size, executable, owner);
704 713
705 if (chunk == NULL) return NULL; 714 if (chunk == NULL) return NULL;
706 715
707 return Page::Initialize(isolate_->heap(), chunk, executable, owner); 716 return Page::Initialize(isolate_->heap(), chunk, executable, owner);
708 } 717 }
709 718
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 PageIterator it(this); 1059 PageIterator it(this);
1051 int count = 0; 1060 int count = 0;
1052 while (it.has_next()) { 1061 while (it.has_next()) {
1053 it.next(); 1062 it.next();
1054 count++; 1063 count++;
1055 } 1064 }
1056 return count; 1065 return count;
1057 } 1066 }
1058 1067
1059 1068
1069 void PagedSpace::ObtainFreeListStatistics(Page* page, SizeStats* sizes) {
1070 sizes->huge_size_ = page->available_in_huge_free_list();
1071 sizes->small_size_ = page->available_in_small_free_list();
1072 sizes->medium_size_ = page->available_in_medium_free_list();
1073 sizes->large_size_ = page->available_in_large_free_list();
1074 }
1075
1076
1077 void PagedSpace::ResetFreeListStatistics() {
1078 PageIterator page_iterator(this);
1079 while (page_iterator.has_next()) {
1080 Page* page = page_iterator.next();
1081 page->ResetFreeListStatistics();
1082 }
1083 }
1084
1085
1060 void PagedSpace::ReleasePage(Page* page, bool unlink) { 1086 void PagedSpace::ReleasePage(Page* page, bool unlink) {
1061 ASSERT(page->LiveBytes() == 0); 1087 ASSERT(page->LiveBytes() == 0);
1062 ASSERT(AreaSize() == page->area_size()); 1088 ASSERT(AreaSize() == page->area_size());
1063 1089
1064 // Adjust list of unswept pages if the page is the head of the list. 1090 // Adjust list of unswept pages if the page is the head of the list.
1065 if (first_unswept_page_ == page) { 1091 if (first_unswept_page_ == page) {
1066 first_unswept_page_ = page->next_page(); 1092 first_unswept_page_ = page->next_page();
1067 if (first_unswept_page_ == anchor()) { 1093 if (first_unswept_page_ == anchor()) {
1068 first_unswept_page_ = Page::FromAddress(NULL); 1094 first_unswept_page_ = Page::FromAddress(NULL);
1069 } 1095 }
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after
2049 } 2075 }
2050 2076
2051 2077
2052 void FreeListCategory::Reset() { 2078 void FreeListCategory::Reset() {
2053 top_ = NULL; 2079 top_ = NULL;
2054 end_ = NULL; 2080 end_ = NULL;
2055 available_ = 0; 2081 available_ = 0;
2056 } 2082 }
2057 2083
2058 2084
2059 intptr_t FreeListCategory::CountFreeListItemsInList(Page* p) {
2060 int sum = 0;
2061 FreeListNode* n = top_;
2062 while (n != NULL) {
2063 if (Page::FromAddress(n->address()) == p) {
2064 FreeSpace* free_space = reinterpret_cast<FreeSpace*>(n);
2065 sum += free_space->Size();
2066 }
2067 n = n->next();
2068 }
2069 return sum;
2070 }
2071
2072
2073 intptr_t FreeListCategory::EvictFreeListItemsInList(Page* p) { 2085 intptr_t FreeListCategory::EvictFreeListItemsInList(Page* p) {
2074 int sum = 0; 2086 int sum = 0;
2075 FreeListNode** n = &top_; 2087 FreeListNode** n = &top_;
2076 while (*n != NULL) { 2088 while (*n != NULL) {
2077 if (Page::FromAddress((*n)->address()) == p) { 2089 if (Page::FromAddress((*n)->address()) == p) {
2078 FreeSpace* free_space = reinterpret_cast<FreeSpace*>(*n); 2090 FreeSpace* free_space = reinterpret_cast<FreeSpace*>(*n);
2079 sum += free_space->Size(); 2091 sum += free_space->Size();
2080 *n = (*n)->next(); 2092 *n = (*n)->next();
2081 } else { 2093 } else {
2082 n = (*n)->next_address(); 2094 n = (*n)->next_address();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2163 large_list_.Reset(); 2175 large_list_.Reset();
2164 huge_list_.Reset(); 2176 huge_list_.Reset();
2165 } 2177 }
2166 2178
2167 2179
2168 int FreeList::Free(Address start, int size_in_bytes) { 2180 int FreeList::Free(Address start, int size_in_bytes) {
2169 if (size_in_bytes == 0) return 0; 2181 if (size_in_bytes == 0) return 0;
2170 2182
2171 FreeListNode* node = FreeListNode::FromAddress(start); 2183 FreeListNode* node = FreeListNode::FromAddress(start);
2172 node->set_size(heap_, size_in_bytes); 2184 node->set_size(heap_, size_in_bytes);
2185 Page* page = Page::FromAddress(start);
2173 2186
2174 // Early return to drop too-small blocks on the floor. 2187 // Early return to drop too-small blocks on the floor.
2175 if (size_in_bytes < kSmallListMin) return size_in_bytes; 2188 if (size_in_bytes < kSmallListMin) {
2189 page->add_non_available_small_blocks(size_in_bytes);
2190 return size_in_bytes;
2191 }
2176 2192
2177 // Insert other blocks at the head of a free list of the appropriate 2193 // Insert other blocks at the head of a free list of the appropriate
2178 // magnitude. 2194 // magnitude.
2179 if (size_in_bytes <= kSmallListMax) { 2195 if (size_in_bytes <= kSmallListMax) {
2180 small_list_.Free(node, size_in_bytes); 2196 small_list_.Free(node, size_in_bytes);
2197 page->add_available_in_small_free_list(size_in_bytes);
2181 } else if (size_in_bytes <= kMediumListMax) { 2198 } else if (size_in_bytes <= kMediumListMax) {
2182 medium_list_.Free(node, size_in_bytes); 2199 medium_list_.Free(node, size_in_bytes);
2200 page->add_available_in_medium_free_list(size_in_bytes);
2183 } else if (size_in_bytes <= kLargeListMax) { 2201 } else if (size_in_bytes <= kLargeListMax) {
2184 large_list_.Free(node, size_in_bytes); 2202 large_list_.Free(node, size_in_bytes);
2203 page->add_available_in_large_free_list(size_in_bytes);
2185 } else { 2204 } else {
2186 huge_list_.Free(node, size_in_bytes); 2205 huge_list_.Free(node, size_in_bytes);
2206 page->add_available_in_huge_free_list(size_in_bytes);
2187 } 2207 }
2188 2208
2189 ASSERT(IsVeryLong() || available() == SumFreeLists()); 2209 ASSERT(IsVeryLong() || available() == SumFreeLists());
2190 return 0; 2210 return 0;
2191 } 2211 }
2192 2212
2193 2213
2194 FreeListNode* FreeList::FindNodeFor(int size_in_bytes, int* node_size) { 2214 FreeListNode* FreeList::FindNodeFor(int size_in_bytes, int* node_size) {
2195 FreeListNode* node = NULL; 2215 FreeListNode* node = NULL;
2216 Page* page = NULL;
2196 2217
2197 if (size_in_bytes <= kSmallAllocationMax) { 2218 if (size_in_bytes <= kSmallAllocationMax) {
2198 node = small_list_.PickNodeFromList(node_size); 2219 node = small_list_.PickNodeFromList(node_size);
2199 if (node != NULL) return node; 2220 if (node != NULL) {
2221 page = Page::FromAddress(node->address());
2222 page->add_available_in_small_free_list(-(*node_size));
2223 return node;
2224 }
2200 } 2225 }
2201 2226
2202 if (size_in_bytes <= kMediumAllocationMax) { 2227 if (size_in_bytes <= kMediumAllocationMax) {
2203 node = medium_list_.PickNodeFromList(node_size); 2228 node = medium_list_.PickNodeFromList(node_size);
2204 if (node != NULL) return node; 2229 if (node != NULL) {
2230 page = Page::FromAddress(node->address());
2231 page->add_available_in_medium_free_list(-(*node_size));
2232 return node;
2233 }
2205 } 2234 }
2206 2235
2207 if (size_in_bytes <= kLargeAllocationMax) { 2236 if (size_in_bytes <= kLargeAllocationMax) {
2208 node = large_list_.PickNodeFromList(node_size); 2237 node = large_list_.PickNodeFromList(node_size);
2209 if (node != NULL) return node; 2238 if (node != NULL) {
2239 page = Page::FromAddress(node->address());
2240 page->add_available_in_large_free_list(-(*node_size));
2241 return node;
2242 }
2210 } 2243 }
2211 2244
2212 int huge_list_available = huge_list_.available(); 2245 int huge_list_available = huge_list_.available();
2213 for (FreeListNode** cur = huge_list_.GetTopAddress(); 2246 for (FreeListNode** cur = huge_list_.GetTopAddress();
2214 *cur != NULL; 2247 *cur != NULL;
2215 cur = (*cur)->next_address()) { 2248 cur = (*cur)->next_address()) {
2216 FreeListNode* cur_node = *cur; 2249 FreeListNode* cur_node = *cur;
2217 while (cur_node != NULL && 2250 while (cur_node != NULL &&
2218 Page::FromAddress(cur_node->address())->IsEvacuationCandidate()) { 2251 Page::FromAddress(cur_node->address())->IsEvacuationCandidate()) {
2219 huge_list_available -= reinterpret_cast<FreeSpace*>(cur_node)->Size(); 2252 int size = reinterpret_cast<FreeSpace*>(cur_node)->Size();
2253 huge_list_available -= size;
2254 page = Page::FromAddress(node->address());
2255 page->add_available_in_huge_free_list(-size);
2220 cur_node = cur_node->next(); 2256 cur_node = cur_node->next();
2221 } 2257 }
2222 2258
2223 *cur = cur_node; 2259 *cur = cur_node;
2224 if (cur_node == NULL) { 2260 if (cur_node == NULL) {
2225 huge_list_.set_end(NULL); 2261 huge_list_.set_end(NULL);
2226 break; 2262 break;
2227 } 2263 }
2228 2264
2229 ASSERT((*cur)->map() == heap_->raw_unchecked_free_space_map()); 2265 ASSERT((*cur)->map() == heap_->raw_unchecked_free_space_map());
2230 FreeSpace* cur_as_free_space = reinterpret_cast<FreeSpace*>(*cur); 2266 FreeSpace* cur_as_free_space = reinterpret_cast<FreeSpace*>(*cur);
2231 int size = cur_as_free_space->Size(); 2267 int size = cur_as_free_space->Size();
2232 if (size >= size_in_bytes) { 2268 if (size >= size_in_bytes) {
2233 // Large enough node found. Unlink it from the list. 2269 // Large enough node found. Unlink it from the list.
2234 node = *cur; 2270 node = *cur;
2235 *cur = node->next(); 2271 *cur = node->next();
2236 *node_size = size; 2272 *node_size = size;
2237 huge_list_available -= size; 2273 huge_list_available -= size;
2274 page = Page::FromAddress(node->address());
2275 page->add_available_in_huge_free_list(-size);
2238 break; 2276 break;
2239 } 2277 }
2240 } 2278 }
2241 2279
2242 if (huge_list_.top() == NULL) { 2280 if (huge_list_.top() == NULL) {
2243 huge_list_.set_end(NULL); 2281 huge_list_.set_end(NULL);
2244 } 2282 }
2245 2283
2246 huge_list_.set_available(huge_list_available); 2284 huge_list_.set_available(huge_list_available);
2247 ASSERT(IsVeryLong() || available() == SumFreeLists()); 2285 ASSERT(IsVeryLong() || available() == SumFreeLists());
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2315 } else { 2353 } else {
2316 // TODO(gc) Try not freeing linear allocation region when bytes_left 2354 // TODO(gc) Try not freeing linear allocation region when bytes_left
2317 // are zero. 2355 // are zero.
2318 owner_->SetTop(NULL, NULL); 2356 owner_->SetTop(NULL, NULL);
2319 } 2357 }
2320 2358
2321 return new_node; 2359 return new_node;
2322 } 2360 }
2323 2361
2324 2362
2325 void FreeList::CountFreeListItems(Page* p, SizeStats* sizes) {
2326 sizes->huge_size_ = huge_list_.CountFreeListItemsInList(p);
2327 if (sizes->huge_size_ < p->area_size()) {
2328 sizes->small_size_ = small_list_.CountFreeListItemsInList(p);
2329 sizes->medium_size_ = medium_list_.CountFreeListItemsInList(p);
2330 sizes->large_size_ = large_list_.CountFreeListItemsInList(p);
2331 } else {
2332 sizes->small_size_ = 0;
2333 sizes->medium_size_ = 0;
2334 sizes->large_size_ = 0;
2335 }
2336 }
2337
2338
2339 intptr_t FreeList::EvictFreeListItems(Page* p) { 2363 intptr_t FreeList::EvictFreeListItems(Page* p) {
2340 intptr_t sum = huge_list_.EvictFreeListItemsInList(p); 2364 intptr_t sum = huge_list_.EvictFreeListItemsInList(p);
2365 p->set_available_in_huge_free_list(0);
2341 2366
2342 if (sum < p->area_size()) { 2367 if (sum < p->area_size()) {
2343 sum += small_list_.EvictFreeListItemsInList(p) + 2368 sum += small_list_.EvictFreeListItemsInList(p) +
2344 medium_list_.EvictFreeListItemsInList(p) + 2369 medium_list_.EvictFreeListItemsInList(p) +
2345 large_list_.EvictFreeListItemsInList(p); 2370 large_list_.EvictFreeListItemsInList(p);
2371 p->set_available_in_small_free_list(0);
2372 p->set_available_in_medium_free_list(0);
2373 p->set_available_in_large_free_list(0);
2346 } 2374 }
2347 2375
2348 return sum; 2376 return sum;
2349 } 2377 }
2350 2378
2351 2379
2352 void FreeList::RepairLists(Heap* heap) { 2380 void FreeList::RepairLists(Heap* heap) {
2353 small_list_.RepairFreeList(heap); 2381 small_list_.RepairFreeList(heap);
2354 medium_list_.RepairFreeList(heap); 2382 medium_list_.RepairFreeList(heap);
2355 large_list_.RepairFreeList(heap); 2383 large_list_.RepairFreeList(heap);
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
3143 object->ShortPrint(); 3171 object->ShortPrint();
3144 PrintF("\n"); 3172 PrintF("\n");
3145 } 3173 }
3146 printf(" --------------------------------------\n"); 3174 printf(" --------------------------------------\n");
3147 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); 3175 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes());
3148 } 3176 }
3149 3177
3150 #endif // DEBUG 3178 #endif // DEBUG
3151 3179
3152 } } // namespace v8::internal 3180 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/spaces.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698