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_LOCAL_HEAP_INL_H_
6 #define V8_HEAP_LOCAL_HEAP_INL_H_
7
8 #include "src/handles/persistent-handles.h"
9 #include "src/heap/concurrent-allocator-inl.h"
10 #include "src/heap/local-heap.h"
11
12 namespace v8 {
13 namespace internal {
14
AllocateRaw(int size_in_bytes,AllocationType type,AllocationOrigin origin,AllocationAlignment alignment)15 AllocationResult LocalHeap::AllocateRaw(int size_in_bytes, AllocationType type,
16 AllocationOrigin origin,
17 AllocationAlignment alignment) {
18 #if DEBUG
19 DCHECK_EQ(LocalHeap::Current(), this);
20 DCHECK(AllowHandleAllocation::IsAllowed());
21 DCHECK(AllowHeapAllocation::IsAllowed());
22 DCHECK(AllowGarbageCollection::IsAllowed());
23 DCHECK_IMPLIES(type == AllocationType::kCode || type == AllocationType::kMap,
24 alignment == AllocationAlignment::kWordAligned);
25 Heap::HeapState state = heap()->gc_state();
26 DCHECK(state == Heap::TEAR_DOWN || state == Heap::NOT_IN_GC);
27 #endif
28
29 bool large_object = size_in_bytes > Heap::MaxRegularHeapObjectSize(type);
30 CHECK_EQ(type, AllocationType::kOld);
31
32 if (large_object)
33 return heap()->lo_space()->AllocateRawBackground(this, size_in_bytes);
34 else
35 return old_space_allocator()->AllocateRaw(size_in_bytes, alignment, origin);
36 }
37
AllocateRawOrFail(int object_size,AllocationType type,AllocationOrigin origin,AllocationAlignment alignment)38 Address LocalHeap::AllocateRawOrFail(int object_size, AllocationType type,
39 AllocationOrigin origin,
40 AllocationAlignment alignment) {
41 AllocationResult result = AllocateRaw(object_size, type, origin, alignment);
42 if (!result.IsRetry()) return result.ToObject().address();
43 return PerformCollectionAndAllocateAgain(object_size, type, origin,
44 alignment);
45 }
46
47 } // namespace internal
48 } // namespace v8
49
50 #endif // V8_HEAP_LOCAL_HEAP_INL_H_
51