v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
zone-segment.h
Go to the documentation of this file.
1
// Copyright 2016 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_ZONE_ZONE_SEGMENT_H_
6
#define V8_ZONE_ZONE_SEGMENT_H_
7
8
#include "
src/init/v8.h
"
9
10
// Segments represent chunks of memory: They have starting address
11
// (encoded in the this pointer) and a size in bytes. Segments are
12
// chained together forming a LIFO structure with the newest segment
13
// available as segment_head_. Segments are allocated using malloc()
14
// and de-allocated using free().
15
namespace
v8
{
16
namespace
internal
{
17
18
// Forward declarations.
19
class
AccountingAllocator;
20
class
Zone
;
21
22
class
Segment
{
23
public
:
24
Zone
*
zone
()
const
{
return
zone_
; }
25
void
set_zone
(
Zone
*
const
zone
) {
zone_
=
zone
; }
26
27
Segment
*
next
()
const
{
return
next_
; }
28
void
set_next
(
Segment
*
const
next
) {
next_
=
next
; }
29
30
// {total_size} returns the allocated size including the bookkeeping bytes of
31
// the {Segment}.
32
size_t
total_size
()
const
{
return
size_
; }
33
34
// {capacity} returns the number of storage bytes in this {Segment}, i.e.
35
// {end() - start()}.
36
size_t
capacity
()
const
{
return
size_
-
sizeof
(
Segment
); }
37
38
Address
start
()
const
{
return
address
(
sizeof
(
Segment
)); }
39
Address
end
()
const
{
return
address
(
size_
); }
40
41
// Zap the contents of the segment (but not the header).
42
void
ZapContents
();
43
// Zaps the header and makes the segment unusable this way.
44
void
ZapHeader
();
45
46
private
:
47
// Segments are only created by the AccountingAllocator.
48
friend
class
AccountingAllocator
;
49
50
explicit
Segment
(
size_t
size) :
size_
(size) {}
51
52
#ifdef DEBUG
53
// Constant byte value used for zapping dead memory in debug mode.
54
static
const
unsigned
char
kZapDeadByte = 0xcd;
55
#endif
56
57
// Computes the address of the nth byte in this segment.
58
Address
address
(
size_t
n)
const
{
59
return
reinterpret_cast<
Address
>
(
this
) + n;
60
}
61
62
Zone
*
zone_
=
nullptr
;
63
Segment
*
next_
=
nullptr
;
64
const
size_t
size_
;
65
};
66
67
}
// namespace internal
68
}
// namespace v8
69
70
#endif
// V8_ZONE_ZONE_SEGMENT_H_
Zone
friend Zone
Definition
asm-types.cc:195
v8::internal::AccountingAllocator
Definition
accounting-allocator.h:27
v8::internal::Segment
Definition
zone-segment.h:22
v8::internal::Segment::next
Segment * next() const
Definition
zone-segment.h:27
v8::internal::Segment::zone_
Zone * zone_
Definition
zone-segment.h:62
v8::internal::Segment::start
Address start() const
Definition
zone-segment.h:38
v8::internal::Segment::total_size
size_t total_size() const
Definition
zone-segment.h:32
v8::internal::Segment::ZapHeader
void ZapHeader()
Definition
zone-segment.cc:19
v8::internal::Segment::zone
Zone * zone() const
Definition
zone-segment.h:24
v8::internal::Segment::set_next
void set_next(Segment *const next)
Definition
zone-segment.h:28
v8::internal::Segment::set_zone
void set_zone(Zone *const zone)
Definition
zone-segment.h:25
v8::internal::Segment::address
Address address(size_t n) const
Definition
zone-segment.h:58
v8::internal::Segment::size_
const size_t size_
Definition
zone-segment.h:64
v8::internal::Segment::end
Address end() const
Definition
zone-segment.h:39
v8::internal::Segment::capacity
size_t capacity() const
Definition
zone-segment.h:36
v8::internal::Segment::Segment
Segment(size_t size)
Definition
zone-segment.h:50
v8::internal::Segment::next_
Segment * next_
Definition
zone-segment.h:63
v8::internal::Segment::ZapContents
void ZapContents()
Definition
zone-segment.cc:12
v8::internal::Zone
Definition
zone.h:43
v8::internal::internal
internal
Definition
wasm-objects-inl.h:458
v8::internal::Address
Address
Definition
api-callbacks-inl.h:36
v8
Definition
api-arguments-inl.h:19
v8.h
src
zone
zone-segment.h
Generated on Sun Apr 6 2025 21:08:58 for v8 by
1.12.0