blob: ba578f3820376b7c545c84df76a7edfca0e7d004 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_HEAP_CPPGC_FREE_LIST_H_
#define V8_HEAP_CPPGC_FREE_LIST_H_
#include <array>
#include "src/base/macros.h"
#include "src/heap/cppgc/globals.h"
#include "src/heap/cppgc/heap-object-header.h"
namespace cppgc {
namespace internal {
class V8_EXPORT_PRIVATE FreeList {
public:
struct Block {
void* address;
size_t size;
};
FreeList();
FreeList(const FreeList&) = delete;
FreeList& operator=(const FreeList&) = delete;
FreeList(FreeList&& freelist) V8_NOEXCEPT;
FreeList& operator=(FreeList&& freelist) V8_NOEXCEPT;
// Allocates entries which are at least of the provided size.
Block Allocate(size_t);
// Adds block to the freelist. The minimal block size is two words.
void Add(Block);
// Append other freelist into this.
void Append(FreeList&&);
void Clear();
size_t Size() const;
bool IsEmpty() const;
bool Contains(Block) const;
private:
class Entry;
bool IsConsistent(size_t) const;
// All |Entry|s in the nth list have size >= 2^n.
std::array<Entry*, kPageSizeLog2> free_list_heads_;
std::array<Entry*, kPageSizeLog2> free_list_tails_;
size_t biggest_free_list_index_ = 0;
};
} // namespace internal
} // namespace cppgc
#endif // V8_HEAP_CPPGC_FREE_LIST_H_
|