v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
free-space-inl.h
Go to the documentation of this file.
1// Copyright 2018 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_OBJECTS_FREE_SPACE_INL_H_
6#define V8_OBJECTS_FREE_SPACE_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
13#include "src/heap/heap.h"
15
16// Has to be the last include (doesn't have include guards):
18
19namespace v8 {
20namespace internal {
21
22#include "torque-generated/src/objects/free-space-tq-inl.inc"
23
25
26RELAXED_SMI_ACCESSORS(FreeSpace, size, kSizeOffset)
27
28// static
29inline void FreeSpace::SetSize(const WritableFreeSpace& writable_free_space,
30 int size, RelaxedStoreTag tag) {
31 writable_free_space.WriteHeaderSlot<Smi, kSizeOffset>(Smi::FromInt(size),
32 tag);
33}
34
36
38 DCHECK(IsValid());
39#ifdef V8_EXTERNAL_CODE_SPACE
40 intptr_t diff_to_next =
41 static_cast<intptr_t>(TaggedField<Smi, kNextOffset>::load(*this).value());
42 if (diff_to_next == 0) {
43 return FreeSpace();
44 }
45 Address next_ptr = ptr() + diff_to_next * kObjectAlignment;
47#else
50#endif // V8_EXTERNAL_CODE_SPACE
51}
52
53void FreeSpace::SetNext(const WritableFreeSpace& writable_free_space,
54 Tagged<FreeSpace> next) {
55 DCHECK(IsValid());
56
57#ifdef V8_EXTERNAL_CODE_SPACE
58 if (next.is_null()) {
59 writable_free_space.WriteHeaderSlot<Smi, kNextOffset>(Smi::zero(),
61 return;
62 }
63 intptr_t diff_to_next = next.ptr() - ptr();
64 DCHECK(IsAligned(diff_to_next, kObjectAlignment));
65 writable_free_space.WriteHeaderSlot<Smi, kNextOffset>(
67#else
68 writable_free_space.WriteHeaderSlot<Object, kNextOffset>(next, kRelaxedStore);
69#endif // V8_EXTERNAL_CODE_SPACE
70}
71
72bool FreeSpace::IsValid() const { return Heap::IsFreeSpaceValid(*this); }
73
74} // namespace internal
75} // namespace v8
76
78
79#endif // V8_OBJECTS_FREE_SPACE_INL_H_
void SetNext(const WritableFreeSpace &writable_free_space, Tagged< FreeSpace > next)
Tagged< FreeSpace > next() const
static constexpr Tagged< Smi > FromInt(int value)
Definition smi.h:38
static constexpr Tagged< Smi > FromIntptr(intptr_t value)
Definition smi.h:43
static constexpr Tagged< Smi > zero()
Definition smi.h:99
static PtrType load(Tagged< HeapObject > host, int offset=0)
V8_INLINE void WriteHeaderSlot(Tagged< T > value, RelaxedStoreTag) const
constexpr intptr_t kObjectAlignment
Definition globals.h:930
Handle< To > UncheckedCast(Handle< From > value)
Definition handles-inl.h:55
static constexpr RelaxedLoadTag kRelaxedLoad
Definition globals.h:2909
static constexpr RelaxedStoreTag kRelaxedStore
Definition globals.h:2911
#define TQ_OBJECT_CONSTRUCTORS_IMPL(Type)
#define RELAXED_SMI_ACCESSORS(holder, name, offset)
#define DCHECK(condition)
Definition logging.h:482
constexpr bool IsAligned(T value, U alignment)
Definition macros.h:403