v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
main-allocator-inl.h
Go to the documentation of this file.
1// Copyright 2023 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_MAIN_ALLOCATOR_INL_H_
6#define V8_HEAP_MAIN_ALLOCATOR_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
11#include "src/flags/flags.h"
12#include "src/heap/heap-inl.h"
14
15namespace v8 {
16namespace internal {
17
19 AllocationAlignment alignment,
20 AllocationOrigin origin) {
21 size_in_bytes = ALIGN_TO_ALLOCATION_ALIGNMENT(size_in_bytes);
22
24 DCHECK_EQ(in_gc(), isolate_heap()->IsInGC());
25
26 // We are not supposed to allocate in fast c calls.
28 v8_flags.allow_allocation_in_fast_api_call ||
29 !isolate_heap()->isolate()->InFastCCall());
30
32
34 result = AllocateFastAligned(size_in_bytes, nullptr, alignment, origin);
35 } else {
36 result = AllocateFastUnaligned(size_in_bytes, origin);
37 }
38
39 return result.IsFailure() ? AllocateRawSlow(size_in_bytes, alignment, origin)
40 : result;
41}
42
44 AllocationOrigin origin) {
45 size_in_bytes = ALIGN_TO_ALLOCATION_ALIGNMENT(size_in_bytes);
46 if (!allocation_info().CanIncrementTop(size_in_bytes)) {
48 }
50 HeapObject::FromAddress(allocation_info().IncrementTop(size_in_bytes));
51
52 MSAN_ALLOCATED_UNINITIALIZED_MEMORY(obj.address(), size_in_bytes);
53
55 space_heap()->marking_state()->IsMarked(obj));
56
58}
59
61 int size_in_bytes, int* result_aligned_size_in_bytes,
62 AllocationAlignment alignment, AllocationOrigin origin) {
63 Address top = allocation_info().top();
64 int filler_size = Heap::GetFillToAlign(top, alignment);
65 int aligned_size_in_bytes = size_in_bytes + filler_size;
66
67 if (!allocation_info().CanIncrementTop(aligned_size_in_bytes)) {
69 }
71 allocation_info().IncrementTop(aligned_size_in_bytes));
72 if (result_aligned_size_in_bytes)
73 *result_aligned_size_in_bytes = aligned_size_in_bytes;
74
75 if (filler_size > 0) {
76 obj = space_heap()->PrecedeWithFiller(obj, filler_size);
77 }
78
79 MSAN_ALLOCATED_UNINITIALIZED_MEMORY(obj.address(), size_in_bytes);
80
82 space_heap()->marking_state()->IsMarked(obj));
83
85}
86
87bool MainAllocator::TryFreeLast(Address object_address, int object_size) {
88 if (top() != kNullAddress) {
89 return allocation_info().DecrementTopIfAdjacent(object_address,
90 object_size);
91 }
92 return false;
93}
94
95} // namespace internal
96} // namespace v8
97
98#endif // V8_HEAP_MAIN_ALLOCATOR_INL_H_
static AllocationResult Failure()
static AllocationResult FromObject(Tagged< HeapObject > heap_object)
static Tagged< HeapObject > FromAddress(Address address)
V8_EXPORT_PRIVATE Tagged< HeapObject > PrecedeWithFiller(Tagged< HeapObject > object, int filler_size)
Definition heap.cc:3029
V8_INLINE bool DecrementTopIfAdjacent(Address new_top, size_t bytes)
V8_INLINE bool TryFreeLast(Address object_address, int object_size)
LinearAllocationArea & allocation_info()
V8_EXPORT_PRIVATE Heap * space_heap() const
V8_WARN_UNUSED_RESULT V8_INLINE AllocationResult AllocateRaw(int size_in_bytes, AllocationAlignment alignment, AllocationOrigin origin)
V8_WARN_UNUSED_RESULT V8_INLINE AllocationResult AllocateFastAligned(int size_in_bytes, int *result_aligned_size_in_bytes, AllocationAlignment alignment, AllocationOrigin origin)
V8_WARN_UNUSED_RESULT V8_INLINE AllocationResult AllocateFastUnaligned(int size_in_bytes, AllocationOrigin origin)
const BlackAllocation black_allocation_
V8_WARN_UNUSED_RESULT V8_EXPORT_PRIVATE AllocationResult AllocateRawSlow(int size_in_bytes, AllocationAlignment alignment, AllocationOrigin origin)
V8_EXPORT_PRIVATE bool is_main_thread() const
#define USE_ALLOCATION_ALIGNMENT_BOOL
Definition globals.h:1562
#define ALIGN_TO_ALLOCATION_ALIGNMENT(value)
Definition globals.h:1796
Isolate * isolate
ZoneVector< RpoNumber > & result
#define MSAN_ALLOCATED_UNINITIALIZED_MEMORY(start, size)
Definition msan.h:29
V8_EXPORT_PRIVATE FlagValues v8_flags
static constexpr Address kNullAddress
Definition v8-internal.h:53
#define DCHECK_IMPLIES(v1, v2)
Definition logging.h:493
#define DCHECK_EQ(v1, v2)
Definition logging.h:485