1 // Copyright 2020 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/heap/cppgc/heap-space.h"
6
7 #include <algorithm>
8
9 #include "src/base/logging.h"
10 #include "src/base/platform/mutex.h"
11 #include "src/heap/cppgc/heap-page.h"
12 #include "src/heap/cppgc/object-start-bitmap.h"
13
14 namespace cppgc {
15 namespace internal {
16
BaseSpace(RawHeap * heap,size_t index,PageType type,bool is_compactable)17 BaseSpace::BaseSpace(RawHeap* heap, size_t index, PageType type,
18 bool is_compactable)
19 : heap_(heap), index_(index), type_(type), is_compactable_(is_compactable) {
20 USE(is_compactable_);
21 }
22
23 BaseSpace::~BaseSpace() = default;
24
AddPage(BasePage * page)25 void BaseSpace::AddPage(BasePage* page) {
26 v8::base::LockGuard<v8::base::Mutex> lock(&pages_mutex_);
27 DCHECK_EQ(pages_.cend(), std::find(pages_.cbegin(), pages_.cend(), page));
28 pages_.push_back(page);
29 }
30
RemovePage(BasePage * page)31 void BaseSpace::RemovePage(BasePage* page) {
32 v8::base::LockGuard<v8::base::Mutex> lock(&pages_mutex_);
33 auto it = std::find(pages_.cbegin(), pages_.cend(), page);
34 DCHECK_NE(pages_.cend(), it);
35 pages_.erase(it);
36 }
37
RemoveAllPages()38 BaseSpace::Pages BaseSpace::RemoveAllPages() {
39 Pages pages = std::move(pages_);
40 pages_.clear();
41 return pages;
42 }
43
NormalPageSpace(RawHeap * heap,size_t index,bool is_compactable)44 NormalPageSpace::NormalPageSpace(RawHeap* heap, size_t index,
45 bool is_compactable)
46 : BaseSpace(heap, index, PageType::kNormal, is_compactable) {}
47
LargePageSpace(RawHeap * heap,size_t index)48 LargePageSpace::LargePageSpace(RawHeap* heap, size_t index)
49 : BaseSpace(heap, index, PageType::kLarge, false /* is_compactable */) {}
50
51 } // namespace internal
52 } // namespace cppgc
53