forked from v8/v8
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexternal-pointer-table.h
More file actions
74 lines (58 loc) · 1.93 KB
/
external-pointer-table.h
File metadata and controls
74 lines (58 loc) · 1.93 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
// 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_EXECUTION_EXTERNAL_POINTER_TABLE_H_
#define V8_EXECUTION_EXTERNAL_POINTER_TABLE_H_
#include "src/base/platform/wrappers.h"
#include "src/common/external-pointer.h"
#include "src/utils/utils.h"
namespace v8 {
namespace internal {
class V8_EXPORT_PRIVATE ExternalPointerTable {
public:
static const int kExternalPointerTableInitialCapacity = 1024;
ExternalPointerTable()
: buffer_(reinterpret_cast<Address*>(base::Calloc(
kExternalPointerTableInitialCapacity, sizeof(Address)))),
length_(1),
capacity_(kExternalPointerTableInitialCapacity),
freelist_head_(0) {
// Explicitly setup the invalid nullptr entry.
STATIC_ASSERT(kNullExternalPointer == 0);
buffer_[kNullExternalPointer] = kNullAddress;
}
~ExternalPointerTable() { base::Free(buffer_); }
Address get(uint32_t index) const {
CHECK_LT(index, length_);
return buffer_[index];
}
void set(uint32_t index, Address value) {
DCHECK_NE(kNullExternalPointer, index);
CHECK_LT(index, length_);
buffer_[index] = value;
}
uint32_t allocate() {
uint32_t index = length_++;
if (index >= capacity_) {
GrowTable(this);
}
DCHECK_NE(kNullExternalPointer, index);
return index;
}
// Returns true if the entry exists in the table and therefore it can be read.
bool is_valid_index(uint32_t index) const {
// TODO(v8:10391, saelo): also check here if entry is free
return index < length_;
}
uint32_t size() const { return length_; }
static void GrowTable(ExternalPointerTable* table);
private:
friend class Isolate;
Address* buffer_;
uint32_t length_;
uint32_t capacity_;
uint32_t freelist_head_;
};
} // namespace internal
} // namespace v8
#endif // V8_EXECUTION_EXTERNAL_POINTER_TABLE_H_