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

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

Issue 1840083002: FreeList::FindNodeFor should not account for node size twice. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | 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 // 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/slot-set.h" 10 #include "src/heap/slot-set.h"
(...skipping 2309 matching lines...) Expand 10 before | Expand all | Expand 10 after
2320 ->add_available_in_free_list(-(*node_size)); 2320 ->add_available_in_free_list(-(*node_size));
2321 DCHECK(IsVeryLong() || Available() == SumFreeLists()); 2321 DCHECK(IsVeryLong() || Available() == SumFreeLists());
2322 return node; 2322 return node;
2323 } 2323 }
2324 } 2324 }
2325 return node; 2325 return node;
2326 } 2326 }
2327 2327
2328 FreeSpace* FreeList::FindNodeFor(int size_in_bytes, int* node_size) { 2328 FreeSpace* FreeList::FindNodeFor(int size_in_bytes, int* node_size) {
2329 FreeSpace* node = nullptr; 2329 FreeSpace* node = nullptr;
2330 Page* page = nullptr;
2331 2330
2332 // First try the allocation fast path: try to allocate the minimum element 2331 // First try the allocation fast path: try to allocate the minimum element
2333 // size of a free list category. This operation is constant time. 2332 // size of a free list category. This operation is constant time.
2334 FreeListCategoryType type = 2333 FreeListCategoryType type =
2335 SelectFastAllocationFreeListCategoryType(size_in_bytes); 2334 SelectFastAllocationFreeListCategoryType(size_in_bytes);
2336 for (int i = type; i < kHuge; i++) { 2335 for (int i = type; i < kHuge; i++) {
2337 node = FindNodeIn(static_cast<FreeListCategoryType>(i), node_size); 2336 node = FindNodeIn(static_cast<FreeListCategoryType>(i), node_size);
2338 if (node != nullptr) return node; 2337 if (node != nullptr) return node;
2339 } 2338 }
2340 2339
2341 // Next search the huge list for free list nodes. This takes linear time in 2340 // Next search the huge list for free list nodes. This takes linear time in
2342 // the number of huge elements. 2341 // the number of huge elements.
2343 node = SearchForNodeInList(kHuge, node_size, size_in_bytes); 2342 node = SearchForNodeInList(kHuge, node_size, size_in_bytes);
2344 if (node != nullptr) { 2343 if (node != nullptr) {
2345 DCHECK(IsVeryLong() || Available() == SumFreeLists()); 2344 DCHECK(IsVeryLong() || Available() == SumFreeLists());
2346 return node; 2345 return node;
2347 } 2346 }
2348 2347
2349 // We need a huge block of memory, but we didn't find anything in the huge 2348 // We need a huge block of memory, but we didn't find anything in the huge
2350 // list. 2349 // list.
2351 if (type == kHuge) return nullptr; 2350 if (type == kHuge) return nullptr;
2352 2351
2353 // Now search the best fitting free list for a node that has at least the 2352 // Now search the best fitting free list for a node that has at least the
2354 // requested size. 2353 // requested size.
2355 type = SelectFreeListCategoryType(size_in_bytes); 2354 type = SelectFreeListCategoryType(size_in_bytes);
2356 node = TryFindNodeIn(type, node_size, size_in_bytes); 2355 node = TryFindNodeIn(type, node_size, size_in_bytes);
2357 if (node != nullptr) {
2358 DCHECK(size_in_bytes <= *node_size);
2359 page = Page::FromAddress(node->address());
2360 page->add_available_in_free_list(-(*node_size));
2361 }
2362 2356
2363 DCHECK(IsVeryLong() || Available() == SumFreeLists()); 2357 DCHECK(IsVeryLong() || Available() == SumFreeLists());
2364 return node; 2358 return node;
2365 } 2359 }
2366 2360
2367 // Allocation on the old space free list. If it succeeds then a new linear 2361 // Allocation on the old space free list. If it succeeds then a new linear
2368 // allocation space has been set up with the top and limit of the space. If 2362 // allocation space has been set up with the top and limit of the space. If
2369 // the allocation fails then NULL is returned, and the caller can perform a GC 2363 // the allocation fails then NULL is returned, and the caller can perform a GC
2370 // or allocate a new page before retrying. 2364 // or allocate a new page before retrying.
2371 HeapObject* FreeList::Allocate(int size_in_bytes) { 2365 HeapObject* FreeList::Allocate(int size_in_bytes) {
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
3167 object->ShortPrint(); 3161 object->ShortPrint();
3168 PrintF("\n"); 3162 PrintF("\n");
3169 } 3163 }
3170 printf(" --------------------------------------\n"); 3164 printf(" --------------------------------------\n");
3171 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); 3165 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes());
3172 } 3166 }
3173 3167
3174 #endif // DEBUG 3168 #endif // DEBUG
3175 } // namespace internal 3169 } // namespace internal
3176 } // namespace v8 3170 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698