blob: 9e4d5f688cb31291e117fb8190a8c07f35c35070 [file] [log] [blame]
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/common/globals.h"
#include "src/heap/heap.h"
#include "src/heap/new-spaces.h"
#include "src/heap/paged-spaces.h"
#include "src/heap/spaces.h"
namespace v8 {
namespace internal {
// Allocator encapsulating thread-local allocation durning collection. Assumes
// that all other allocations also go through EvacuationAllocator.
class EvacuationAllocator {
static const int kLabSize = 32 * KB;
static const int kMaxLabObjectSize = 8 * KB;
explicit EvacuationAllocator(Heap* heap, LocalSpaceKind local_space_kind)
: heap_(heap),
compaction_spaces_(heap, local_space_kind),
lab_allocation_will_fail_(false) {}
// Needs to be called from the main thread to finalize this
// EvacuationAllocator.
void Finalize() {
// Give back remaining LAB space if this EvacuationAllocator's new space LAB
// sits right next to new space allocation top.
const LinearAllocationArea info = new_space_lab_.CloseAndMakeIterable();
const Address top = new_space_->top();
if (info.limit() != kNullAddress && info.limit() == top) {
DCHECK_NE(, kNullAddress);
*new_space_->allocation_top_address() =;
inline AllocationResult Allocate(AllocationSpace space, int object_size,
AllocationOrigin origin,
AllocationAlignment alignment);
inline void FreeLast(AllocationSpace space, HeapObject object,
int object_size);
inline AllocationResult AllocateInNewSpace(int object_size,
AllocationOrigin origin,
AllocationAlignment alignment);
inline bool NewLocalAllocationBuffer();
inline AllocationResult AllocateInLAB(int object_size,
AllocationAlignment alignment);
inline void FreeLastInNewSpace(HeapObject object, int object_size);
inline void FreeLastInOldSpace(HeapObject object, int object_size);
Heap* const heap_;
NewSpace* const new_space_;
CompactionSpaceCollection compaction_spaces_;
LocalAllocationBuffer new_space_lab_;
bool lab_allocation_will_fail_;
} // namespace internal
} // namespace v8