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

Side by Side Diff: src/heap/spaces.cc

Issue 1354383002: [heap] Add more tasks for parallel compaction (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments round 2 Created 5 years, 2 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
« no previous file with comments | « src/heap/spaces.h ('k') | test/cctest/test-spaces.cc » ('j') | 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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/heap/spaces.h" 5 #include "src/heap/spaces.h"
6 6
7 #include "src/base/bits.h" 7 #include "src/base/bits.h"
8 #include "src/base/platform/platform.h" 8 #include "src/base/platform/platform.h"
9 #include "src/full-codegen/full-codegen.h" 9 #include "src/full-codegen/full-codegen.h"
10 #include "src/heap/slots-buffer.h" 10 #include "src/heap/slots-buffer.h"
(...skipping 2200 matching lines...) Expand 10 before | Expand all | Expand 10 after
2211 intptr_t FreeList::Concatenate(FreeList* free_list) { 2211 intptr_t FreeList::Concatenate(FreeList* free_list) {
2212 intptr_t free_bytes = 0; 2212 intptr_t free_bytes = 0;
2213 free_bytes += small_list_.Concatenate(free_list->small_list()); 2213 free_bytes += small_list_.Concatenate(free_list->small_list());
2214 free_bytes += medium_list_.Concatenate(free_list->medium_list()); 2214 free_bytes += medium_list_.Concatenate(free_list->medium_list());
2215 free_bytes += large_list_.Concatenate(free_list->large_list()); 2215 free_bytes += large_list_.Concatenate(free_list->large_list());
2216 free_bytes += huge_list_.Concatenate(free_list->huge_list()); 2216 free_bytes += huge_list_.Concatenate(free_list->huge_list());
2217 return free_bytes; 2217 return free_bytes;
2218 } 2218 }
2219 2219
2220 2220
2221 FreeSpace* PagedSpace::TryRemoveMemory() {
2222 FreeSpace* space = nullptr;
2223 int node_size = 0;
2224 space = free_list()->FindNodeIn(FreeList::kHuge, &node_size);
2225 if (space == nullptr)
2226 space = free_list()->FindNodeIn(FreeList::kLarge, &node_size);
2227 if (space == nullptr)
2228 space = free_list()->FindNodeIn(FreeList::kMedium, &node_size);
2229 if (space == nullptr)
2230 space = free_list()->FindNodeIn(FreeList::kSmall, &node_size);
2231 if (space != nullptr) {
2232 accounting_stats_.DecreaseCapacity(node_size);
2233 }
2234 return space;
2235 }
2236
2237
2238 void PagedSpace::DivideFreeLists(FreeList** free_lists, int num,
2239 intptr_t limit) {
2240 CHECK(num > 0);
2241 CHECK(free_lists != nullptr);
2242 if (limit == 0) {
2243 limit = std::numeric_limits<intptr_t>::max();
2244 }
2245 int index = 0;
2246 FreeSpace* space = nullptr;
2247 while (((space = TryRemoveMemory()) != nullptr) &&
2248 (free_lists[index]->available() < limit)) {
2249 free_lists[index]->owner()->AddMemory(space->address(), space->size());
2250 index = (index + 1) % num;
2251 }
2252 }
2253
2254
2221 void FreeList::Reset() { 2255 void FreeList::Reset() {
2222 small_list_.Reset(); 2256 small_list_.Reset();
2223 medium_list_.Reset(); 2257 medium_list_.Reset();
2224 large_list_.Reset(); 2258 large_list_.Reset();
2225 huge_list_.Reset(); 2259 huge_list_.Reset();
2226 } 2260 }
2227 2261
2228 2262
2229 int FreeList::Free(Address start, int size_in_bytes) { 2263 int FreeList::Free(Address start, int size_in_bytes) {
2230 if (size_in_bytes == 0) return 0; 2264 if (size_in_bytes == 0) return 0;
(...skipping 23 matching lines...) Expand all
2254 } else { 2288 } else {
2255 huge_list_.Free(free_space, size_in_bytes); 2289 huge_list_.Free(free_space, size_in_bytes);
2256 page->add_available_in_huge_free_list(size_in_bytes); 2290 page->add_available_in_huge_free_list(size_in_bytes);
2257 } 2291 }
2258 2292
2259 DCHECK(IsVeryLong() || available() == SumFreeLists()); 2293 DCHECK(IsVeryLong() || available() == SumFreeLists());
2260 return 0; 2294 return 0;
2261 } 2295 }
2262 2296
2263 2297
2298 void FreeList::UpdateFragmentationStats(FreeListCategoryType category,
2299 Address address, int size) {
2300 Page* page = Page::FromAddress(address);
2301 switch (category) {
2302 case kSmall:
2303 page->add_available_in_small_free_list(size);
2304 break;
2305 case kMedium:
2306 page->add_available_in_medium_free_list(size);
2307 break;
2308 case kLarge:
2309 page->add_available_in_large_free_list(size);
2310 break;
2311 case kHuge:
2312 page->add_available_in_huge_free_list(size);
2313 break;
2314 default:
2315 UNREACHABLE();
2316 }
2317 }
2318
2319
2320 FreeSpace* FreeList::FindNodeIn(FreeListCategoryType category, int* node_size) {
2321 FreeSpace* node = GetFreeListCategory(category)->PickNodeFromList(node_size);
2322 if (node != nullptr) {
2323 UpdateFragmentationStats(category, node->address(), -(*node_size));
2324 DCHECK(IsVeryLong() || available() == SumFreeLists());
2325 }
2326 return node;
2327 }
2328
2329
2264 FreeSpace* FreeList::FindNodeFor(int size_in_bytes, int* node_size) { 2330 FreeSpace* FreeList::FindNodeFor(int size_in_bytes, int* node_size) {
2265 FreeSpace* node = NULL; 2331 FreeSpace* node = NULL;
2266 Page* page = NULL; 2332 Page* page = NULL;
2267 2333
2268 if (size_in_bytes <= kSmallAllocationMax) { 2334 if (size_in_bytes <= kSmallAllocationMax) {
2269 node = small_list_.PickNodeFromList(node_size); 2335 node = FindNodeIn(kSmall, node_size);
2270 if (node != NULL) { 2336 if (node != nullptr) {
2271 DCHECK(size_in_bytes <= *node_size); 2337 DCHECK(size_in_bytes <= node->size());
2272 page = Page::FromAddress(node->address());
2273 page->add_available_in_small_free_list(-(*node_size));
2274 DCHECK(IsVeryLong() || available() == SumFreeLists());
2275 return node; 2338 return node;
2276 } 2339 }
2277 } 2340 }
2278 2341
2279 if (size_in_bytes <= kMediumAllocationMax) { 2342 if (size_in_bytes <= kMediumAllocationMax) {
2280 node = medium_list_.PickNodeFromList(node_size); 2343 node = FindNodeIn(kMedium, node_size);
2281 if (node != NULL) { 2344 if (node != nullptr) {
2282 DCHECK(size_in_bytes <= *node_size); 2345 DCHECK(size_in_bytes <= node->size());
2283 page = Page::FromAddress(node->address());
2284 page->add_available_in_medium_free_list(-(*node_size));
2285 DCHECK(IsVeryLong() || available() == SumFreeLists());
2286 return node; 2346 return node;
2287 } 2347 }
2288 } 2348 }
2289 2349
2290 if (size_in_bytes <= kLargeAllocationMax) { 2350 if (size_in_bytes <= kLargeAllocationMax) {
2291 node = large_list_.PickNodeFromList(node_size); 2351 node = FindNodeIn(kLarge, node_size);
2292 if (node != NULL) { 2352 if (node != nullptr) {
2293 DCHECK(size_in_bytes <= *node_size); 2353 DCHECK(size_in_bytes <= node->size());
2294 page = Page::FromAddress(node->address());
2295 page->add_available_in_large_free_list(-(*node_size));
2296 DCHECK(IsVeryLong() || available() == SumFreeLists());
2297 return node; 2354 return node;
2298 } 2355 }
2299 } 2356 }
2300 2357
2301 int huge_list_available = huge_list_.available(); 2358 int huge_list_available = huge_list_.available();
2302 FreeSpace* top_node = huge_list_.top(); 2359 FreeSpace* top_node = huge_list_.top();
2303 for (FreeSpace** cur = &top_node; *cur != NULL; 2360 for (FreeSpace** cur = &top_node; *cur != NULL;
2304 cur = (*cur)->next_address()) { 2361 cur = (*cur)->next_address()) {
2305 FreeSpace* cur_node = *cur; 2362 FreeSpace* cur_node = *cur;
2306 while (cur_node != NULL && 2363 while (cur_node != NULL &&
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
3144 object->ShortPrint(); 3201 object->ShortPrint();
3145 PrintF("\n"); 3202 PrintF("\n");
3146 } 3203 }
3147 printf(" --------------------------------------\n"); 3204 printf(" --------------------------------------\n");
3148 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); 3205 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes());
3149 } 3206 }
3150 3207
3151 #endif // DEBUG 3208 #endif // DEBUG
3152 } // namespace internal 3209 } // namespace internal
3153 } // namespace v8 3210 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/spaces.h ('k') | test/cctest/test-spaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698