Commit deccbde1 authored by mlippautz's avatar mlippautz Committed by Commit bot

[heap] Free list refactoring of finding nodes.

R=ulan@chromium.org
BUG=chromium:524425
LOG=N

Review URL: https://codereview.chromium.org/1394863002

Cr-Commit-Position: refs/heads/master@{#31183}
parent 2b87016a
...@@ -2262,10 +2262,10 @@ intptr_t FreeList::Concatenate(FreeList* other) { ...@@ -2262,10 +2262,10 @@ intptr_t FreeList::Concatenate(FreeList* other) {
wasted_bytes_ += wasted_bytes; wasted_bytes_ += wasted_bytes;
other->wasted_bytes_ = 0; other->wasted_bytes_ = 0;
usable_bytes += small_list_.Concatenate(other->small_list()); usable_bytes += small_list_.Concatenate(other->GetFreeListCategory(kSmall));
usable_bytes += medium_list_.Concatenate(other->medium_list()); usable_bytes += medium_list_.Concatenate(other->GetFreeListCategory(kMedium));
usable_bytes += large_list_.Concatenate(other->large_list()); usable_bytes += large_list_.Concatenate(other->GetFreeListCategory(kLarge));
usable_bytes += huge_list_.Concatenate(other->huge_list()); usable_bytes += huge_list_.Concatenate(other->GetFreeListCategory(kHuge));
if (!other->owner()->is_local()) other->mutex()->Unlock(); if (!other->owner()->is_local()) other->mutex()->Unlock();
if (!owner()->is_local()) mutex_.Unlock(); if (!owner()->is_local()) mutex_.Unlock();
...@@ -2318,38 +2318,40 @@ int FreeList::Free(Address start, int size_in_bytes) { ...@@ -2318,38 +2318,40 @@ int FreeList::Free(Address start, int size_in_bytes) {
} }
FreeSpace* FreeList::FindNodeIn(FreeListCategoryType category, int* node_size) {
FreeSpace* node = GetFreeListCategory(category)->PickNodeFromList(node_size);
if (node != nullptr) {
Page::FromAddress(node->address())
->add_available_in_free_list(category, -(*node_size));
DCHECK(IsVeryLong() || available() == SumFreeLists());
}
return node;
}
FreeSpace* FreeList::FindNodeFor(int size_in_bytes, int* node_size) { FreeSpace* FreeList::FindNodeFor(int size_in_bytes, int* node_size) {
FreeSpace* node = NULL; FreeSpace* node = NULL;
Page* page = NULL; Page* page = NULL;
if (size_in_bytes <= kSmallAllocationMax) { if (size_in_bytes <= kSmallAllocationMax) {
node = small_list_.PickNodeFromList(node_size); node = FindNodeIn(kSmall, node_size);
if (node != NULL) { if (node != NULL) {
DCHECK(size_in_bytes <= *node_size);
page = Page::FromAddress(node->address());
page->add_available_in_small_free_list(-(*node_size));
DCHECK(IsVeryLong() || available() == SumFreeLists()); DCHECK(IsVeryLong() || available() == SumFreeLists());
return node; return node;
} }
} }
if (size_in_bytes <= kMediumAllocationMax) { if (size_in_bytes <= kMediumAllocationMax) {
node = medium_list_.PickNodeFromList(node_size); node = FindNodeIn(kMedium, node_size);
if (node != NULL) { if (node != NULL) {
DCHECK(size_in_bytes <= *node_size);
page = Page::FromAddress(node->address());
page->add_available_in_medium_free_list(-(*node_size));
DCHECK(IsVeryLong() || available() == SumFreeLists()); DCHECK(IsVeryLong() || available() == SumFreeLists());
return node; return node;
} }
} }
if (size_in_bytes <= kLargeAllocationMax) { if (size_in_bytes <= kLargeAllocationMax) {
node = large_list_.PickNodeFromList(node_size); node = FindNodeIn(kLarge, node_size);
if (node != NULL) { if (node != NULL) {
DCHECK(size_in_bytes <= *node_size);
page = Page::FromAddress(node->address());
page->add_available_in_large_free_list(-(*node_size));
DCHECK(IsVeryLong() || available() == SumFreeLists()); DCHECK(IsVeryLong() || available() == SumFreeLists());
return node; return node;
} }
......
...@@ -1743,11 +1743,6 @@ class FreeList { ...@@ -1743,11 +1743,6 @@ class FreeList {
intptr_t EvictFreeListItems(Page* p); intptr_t EvictFreeListItems(Page* p);
bool ContainsPageFreeListItems(Page* p); bool ContainsPageFreeListItems(Page* p);
FreeListCategory* small_list() { return &small_list_; }
FreeListCategory* medium_list() { return &medium_list_; }
FreeListCategory* large_list() { return &large_list_; }
FreeListCategory* huge_list() { return &huge_list_; }
PagedSpace* owner() { return owner_; } PagedSpace* owner() { return owner_; }
intptr_t wasted_bytes() { return wasted_bytes_; } intptr_t wasted_bytes() { return wasted_bytes_; }
base::Mutex* mutex() { return &mutex_; } base::Mutex* mutex() { return &mutex_; }
...@@ -1766,6 +1761,25 @@ class FreeList { ...@@ -1766,6 +1761,25 @@ class FreeList {
static const int kLargeAllocationMax = kMediumListMax; static const int kLargeAllocationMax = kMediumListMax;
FreeSpace* FindNodeFor(int size_in_bytes, int* node_size); FreeSpace* FindNodeFor(int size_in_bytes, int* node_size);
FreeSpace* FindNodeIn(FreeListCategoryType category, int* node_size);
FreeListCategory* GetFreeListCategory(FreeListCategoryType category) {
switch (category) {
case kSmall:
return &small_list_;
case kMedium:
return &medium_list_;
case kLarge:
return &large_list_;
case kHuge:
return &huge_list_;
default:
UNREACHABLE();
}
UNREACHABLE();
return nullptr;
}
PagedSpace* owner_; PagedSpace* owner_;
Heap* heap_; Heap* heap_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment