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

Unified Diff: src/heap/spaces.h

Issue 1698983002: [heap] Refactor FreeListCategory. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/heap/spaces.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap/spaces.h
diff --git a/src/heap/spaces.h b/src/heap/spaces.h
index 1ae8101d1d07fdb9711a04016a25980337f02418..efbde12de3fae2fa70ded956ff332a8ce10f5148 100644
--- a/src/heap/spaces.h
+++ b/src/heap/spaces.h
@@ -717,9 +717,16 @@ class MemoryChunk {
friend class MemoryChunkValidator;
};
-
-enum FreeListCategoryType { kSmall, kMedium, kLarge, kHuge };
-
+enum FreeListCategoryType {
+ kSmall,
+ kMedium,
+ kLarge,
+ kHuge,
+
+ kFirstCategory = kSmall,
+ kLastCategory = kHuge,
+ kNumberOfCategories = kLastCategory + 1
+};
// -----------------------------------------------------------------------------
// A page is a memory chunk of a size 1MB. Large object pages may be larger.
@@ -1565,12 +1572,12 @@ class AllocationStats BASE_EMBEDDED {
// A free list category maintains a linked list of free memory blocks.
class FreeListCategory {
public:
- explicit FreeListCategory(FreeList* owner, FreeListCategoryType type)
- : type_(type),
- top_(nullptr),
- end_(nullptr),
- available_(0),
- owner_(owner) {}
+ FreeListCategory() : top_(nullptr), end_(nullptr), available_(0) {}
+
+ void Initialize(FreeList* owner, FreeListCategoryType type) {
+ owner_ = owner;
+ type_ = type;
+ }
// Concatenates {category} into {this}.
//
@@ -1700,8 +1707,11 @@ class FreeList {
// Return the number of bytes available on the free list.
intptr_t Available() {
- return small_list_.available() + medium_list_.available() +
- large_list_.available() + huge_list_.available();
+ intptr_t available = 0;
+ for (int i = kFirstCategory; i < kNumberOfCategories; i++) {
+ available += category_[i].available();
+ }
+ return available;
}
// The method tries to find a {FreeSpace} node of at least {size_in_bytes}
@@ -1713,8 +1723,10 @@ class FreeList {
MUST_USE_RESULT FreeSpace* TryRemoveMemory(intptr_t hint_size_in_bytes);
bool IsEmpty() {
- return small_list_.IsEmpty() && medium_list_.IsEmpty() &&
- large_list_.IsEmpty() && huge_list_.IsEmpty();
+ for (int i = kFirstCategory; i < kNumberOfCategories; i++) {
+ if (!category_[i].IsEmpty()) return false;
+ }
+ return true;
}
// Used after booting the VM.
@@ -1750,29 +1762,13 @@ class FreeList {
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;
+ return &category_[category];
}
PagedSpace* owner_;
base::Mutex mutex_;
intptr_t wasted_bytes_;
- FreeListCategory small_list_;
- FreeListCategory medium_list_;
- FreeListCategory large_list_;
- FreeListCategory huge_list_;
+ FreeListCategory category_[kNumberOfCategories];
DISALLOW_IMPLICIT_CONSTRUCTORS(FreeList);
};
« no previous file with comments | « no previous file | src/heap/spaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698