v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
memory-chunk-layout.h
Go to the documentation of this file.
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#ifndef V8_HEAP_MEMORY_CHUNK_LAYOUT_H_
6#define V8_HEAP_MEMORY_CHUNK_LAYOUT_H_
7
11
12namespace v8::internal {
13
15 public:
16 // Code pages have padding on the first page for code alignment, so the
17 // ObjectStartOffset will not be page aligned.
18 static constexpr intptr_t ObjectStartOffsetInCodePage() {
19 // The instruction stream data (so after the header) should be aligned to
20 // kCodeAlignment.
21 return RoundUp(sizeof(MemoryChunk) + InstructionStream::kHeaderSize,
23 InstructionStream::kHeaderSize;
24 }
25
26 static constexpr size_t AllocatableMemoryInCodePage() {
27 return kRegularPageSize - ObjectStartOffsetInCodePage();
28 }
29
30 static constexpr size_t ObjectStartOffsetInDataPage() {
31 return RoundUp(sizeof(MemoryChunk),
33 }
34
35 static constexpr size_t AllocatableMemoryInDataPage() {
36 constexpr size_t kAllocatableMemoryInDataPage =
37 kRegularPageSize - ObjectStartOffsetInDataPage();
38 static_assert(kMaxRegularHeapObjectSize <= kAllocatableMemoryInDataPage);
39 return kAllocatableMemoryInDataPage;
40 }
41
42 static constexpr size_t ObjectStartOffsetInMemoryChunk(
43 AllocationSpace space) {
44 if (IsAnyCodeSpace(space)) {
45 return ObjectStartOffsetInCodePage();
46 }
47 // Read-only pages use the same layout as regular pages.
48 return ObjectStartOffsetInDataPage();
49 }
50
51 static constexpr size_t AllocatableMemoryInMemoryChunk(
52 AllocationSpace space) {
54 if (space == CODE_SPACE) {
55 return AllocatableMemoryInCodePage();
56 }
57 // Read-only pages use the same layout as regular pages.
58 return AllocatableMemoryInDataPage();
59 }
60
61 static constexpr int MaxRegularCodeObjectSize() {
62 constexpr int kMaxRegularCodeObjectSize = static_cast<int>(
63 RoundDown(AllocatableMemoryInCodePage() / 2, kTaggedSize));
64 static_assert(kMaxRegularCodeObjectSize <= kMaxRegularHeapObjectSize);
65 return kMaxRegularCodeObjectSize;
66 }
67};
68
69} // namespace v8::internal
70
71#endif // V8_HEAP_MEMORY_CHUNK_LAYOUT_H_
constexpr int kRegularPageSize
static constexpr size_t AllocatableMemoryInMemoryChunk(AllocationSpace space)
static constexpr size_t AllocatableMemoryInCodePage()
static constexpr size_t AllocatableMemoryInDataPage()
static constexpr size_t ObjectStartOffsetInMemoryChunk(AllocationSpace space)
static constexpr int MaxRegularCodeObjectSize()
static constexpr intptr_t ObjectStartOffsetInCodePage()
static constexpr size_t ObjectStartOffsetInDataPage()
#define ALIGN_TO_ALLOCATION_ALIGNMENT(value)
Definition globals.h:1796
constexpr int kTaggedSize
Definition globals.h:542
constexpr int kMaxRegularHeapObjectSize
Definition globals.h:680
constexpr intptr_t kCodeAlignment
Definition globals.h:964
constexpr bool IsAnyCodeSpace(AllocationSpace space)
Definition globals.h:1334
constexpr int kDoubleSize
Definition globals.h:407
#define DCHECK_NE(v1, v2)
Definition logging.h:486
constexpr T RoundUp(T x, intptr_t m)
Definition macros.h:387
constexpr T RoundDown(T x, intptr_t m)
Definition macros.h:371
#define V8_EXPORT_PRIVATE
Definition macros.h:460