blob: 1fb265f39fbddfe1943acda6d2ec09f964676492 (
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
// 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.
#include "src/heap/memory-chunk-layout.h"
#include "src/common/globals.h"
#include "src/heap/marking.h"
#include "src/heap/memory-allocator.h"
#include "src/heap/memory-chunk.h"
namespace v8 {
namespace internal {
size_t MemoryChunkLayout::CodePageGuardStartOffset() {
// We are guarding code pages: the first OS page after the header
// will be protected as non-writable.
return ::RoundUp(MemoryChunk::kHeaderSize + Bitmap::kSize,
MemoryAllocator::GetCommitPageSize());
}
size_t MemoryChunkLayout::CodePageGuardSize() {
return MemoryAllocator::GetCommitPageSize();
}
intptr_t MemoryChunkLayout::ObjectStartOffsetInCodePage() {
// The first page also includes padding for code alignment.
return ObjectPageOffsetInCodePage() +
InstructionStream::kCodeAlignmentMinusCodeHeader;
}
intptr_t MemoryChunkLayout::ObjectPageOffsetInCodePage() {
// We are guarding code pages: the first OS page after the header
// will be protected as non-writable.
return CodePageGuardStartOffset() + CodePageGuardSize();
}
intptr_t MemoryChunkLayout::ObjectEndOffsetInCodePage() {
// We are guarding code pages: the last OS page will be protected as
// non-writable.
return MemoryChunk::kPageSize -
static_cast<int>(MemoryAllocator::GetCommitPageSize());
}
size_t MemoryChunkLayout::AllocatableMemoryInCodePage() {
size_t memory = ObjectEndOffsetInCodePage() - ObjectStartOffsetInCodePage();
return memory;
}
intptr_t MemoryChunkLayout::ObjectStartOffsetInDataPage() {
return RoundUp(MemoryChunk::kHeaderSize + Bitmap::kSize,
ALIGN_TO_ALLOCATION_ALIGNMENT(kDoubleSize));
}
intptr_t MemoryChunkLayout::ObjectStartOffsetInReadOnlyPage() {
return RoundUp(BasicMemoryChunk::kHeaderSize,
ALIGN_TO_ALLOCATION_ALIGNMENT(kDoubleSize));
}
size_t MemoryChunkLayout::ObjectStartOffsetInMemoryChunk(
AllocationSpace space) {
if (space == CODE_SPACE || space == CODE_LO_SPACE) {
return ObjectStartOffsetInCodePage();
}
if (space == RO_SPACE) {
return ObjectStartOffsetInReadOnlyPage();
}
return ObjectStartOffsetInDataPage();
}
size_t MemoryChunkLayout::AllocatableMemoryInDataPage() {
size_t memory = MemoryChunk::kPageSize - ObjectStartOffsetInDataPage();
DCHECK_LE(kMaxRegularHeapObjectSize, memory);
return memory;
}
size_t MemoryChunkLayout::AllocatableMemoryInReadOnlyPage() {
size_t memory = MemoryChunk::kPageSize - ObjectStartOffsetInReadOnlyPage();
DCHECK_LE(kMaxRegularHeapObjectSize, memory);
return memory;
}
size_t MemoryChunkLayout::AllocatableMemoryInMemoryChunk(
AllocationSpace space) {
if (space == CODE_SPACE) {
return AllocatableMemoryInCodePage();
}
if (space == RO_SPACE) {
return AllocatableMemoryInReadOnlyPage();
}
return AllocatableMemoryInDataPage();
}
int MemoryChunkLayout::MaxRegularCodeObjectSize() {
int size = static_cast<int>(
RoundDown(AllocatableMemoryInCodePage() / 2, kTaggedSize));
DCHECK_LE(size, kMaxRegularHeapObjectSize);
return size;
}
} // namespace internal
} // namespace v8
|