52e8d0ab40
This is a reland ofec952aaa68
. Included is a fix that ensures that top_on_previous_step_ is cleared when we release a page. Original change's description: > Reland "[profiler] proper observation of old space inline allocations" > > This is a reland of672a41c3ca
> Original change's description: > > [profiler] proper observation of old space inline allocations > > > > Bug: chromium:633920 > > Change-Id: I9a2f4a89f6b9c0f63cb3b166b06a88a12f0a203c > > Reviewed-on: https://chromium-review.googlesource.com/631696 > > Commit-Queue: Ali Ijaz Sheikh <ofrobots@google.com> > > Reviewed-by: Ulan Degenbaev <ulan@chromium.org> > > Cr-Commit-Position: refs/heads/master@{#48043} > > Bug: chromium:633920 > Change-Id: I6fe743d31b8ff26f3858488d4c014c62d3c85add > Reviewed-on: https://chromium-review.googlesource.com/671127 > Reviewed-by: Ulan Degenbaev <ulan@chromium.org> > Commit-Queue: Ali Ijaz Sheikh <ofrobots@google.com> > Cr-Commit-Position: refs/heads/master@{#48085} Bug: chromium:633920 Change-Id: I8a0dcc4eaffc1f1d3ac5b3f8d344001cdae36606 Reviewed-on: https://chromium-review.googlesource.com/677407 Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Commit-Queue: Ali Ijaz Sheikh <ofrobots@google.com> Cr-Commit-Position: refs/heads/master@{#48141}
214 lines
8.0 KiB
C++
214 lines
8.0 KiB
C++
// Copyright 2016 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 "test/cctest/heap/heap-utils.h"
|
|
|
|
#include "src/factory.h"
|
|
#include "src/heap/heap-inl.h"
|
|
#include "src/heap/incremental-marking.h"
|
|
#include "src/heap/mark-compact.h"
|
|
#include "src/isolate.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
namespace heap {
|
|
|
|
void SealCurrentObjects(Heap* heap) {
|
|
heap->CollectAllGarbage(Heap::kFinalizeIncrementalMarkingMask,
|
|
GarbageCollectionReason::kTesting);
|
|
heap->CollectAllGarbage(Heap::kFinalizeIncrementalMarkingMask,
|
|
GarbageCollectionReason::kTesting);
|
|
heap->mark_compact_collector()->EnsureSweepingCompleted();
|
|
heap->old_space()->EmptyAllocationInfo();
|
|
for (Page* page : *heap->old_space()) {
|
|
page->MarkNeverAllocateForTesting();
|
|
}
|
|
}
|
|
|
|
int FixedArrayLenFromSize(int size) {
|
|
return (size - FixedArray::kHeaderSize) / kPointerSize;
|
|
}
|
|
|
|
std::vector<Handle<FixedArray>> FillOldSpacePageWithFixedArrays(Heap* heap,
|
|
int remainder) {
|
|
PauseAllocationObserversScope pause_observers(heap);
|
|
std::vector<Handle<FixedArray>> handles;
|
|
Isolate* isolate = heap->isolate();
|
|
const int kArraySize = 128;
|
|
const int kArrayLen = heap::FixedArrayLenFromSize(kArraySize);
|
|
CHECK_EQ(Page::kAllocatableMemory % kArraySize, 0);
|
|
Handle<FixedArray> array;
|
|
for (int allocated = 0; allocated != (Page::kAllocatableMemory - remainder);
|
|
allocated += array->Size()) {
|
|
if (allocated == (Page::kAllocatableMemory - kArraySize)) {
|
|
array = isolate->factory()->NewFixedArray(
|
|
heap::FixedArrayLenFromSize(kArraySize - remainder), TENURED);
|
|
CHECK_EQ(kArraySize - remainder, array->Size());
|
|
} else {
|
|
array = isolate->factory()->NewFixedArray(kArrayLen, TENURED);
|
|
CHECK_EQ(kArraySize, array->Size());
|
|
}
|
|
if (handles.empty()) {
|
|
// Check that allocations started on a new page.
|
|
CHECK_EQ(array->address(),
|
|
Page::FromAddress(array->address())->area_start());
|
|
}
|
|
handles.push_back(array);
|
|
}
|
|
return handles;
|
|
}
|
|
|
|
std::vector<Handle<FixedArray>> CreatePadding(Heap* heap, int padding_size,
|
|
PretenureFlag tenure,
|
|
int object_size) {
|
|
std::vector<Handle<FixedArray>> handles;
|
|
Isolate* isolate = heap->isolate();
|
|
int allocate_memory;
|
|
int length;
|
|
int free_memory = padding_size;
|
|
if (tenure == i::TENURED) {
|
|
heap->old_space()->EmptyAllocationInfo();
|
|
int overall_free_memory = static_cast<int>(heap->old_space()->Available());
|
|
CHECK(padding_size <= overall_free_memory || overall_free_memory == 0);
|
|
} else {
|
|
heap->new_space()->DisableInlineAllocationSteps();
|
|
int overall_free_memory =
|
|
static_cast<int>(*heap->new_space()->allocation_limit_address() -
|
|
*heap->new_space()->allocation_top_address());
|
|
CHECK(padding_size <= overall_free_memory || overall_free_memory == 0);
|
|
}
|
|
while (free_memory > 0) {
|
|
if (free_memory > object_size) {
|
|
allocate_memory = object_size;
|
|
length = FixedArrayLenFromSize(allocate_memory);
|
|
} else {
|
|
allocate_memory = free_memory;
|
|
length = FixedArrayLenFromSize(allocate_memory);
|
|
if (length <= 0) {
|
|
// Not enough room to create another fixed array. Let's create a filler.
|
|
if (free_memory > (2 * kPointerSize)) {
|
|
heap->CreateFillerObjectAt(
|
|
*heap->old_space()->allocation_top_address(), free_memory,
|
|
ClearRecordedSlots::kNo);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
handles.push_back(isolate->factory()->NewFixedArray(length, tenure));
|
|
CHECK((tenure == NOT_TENURED && heap->InNewSpace(*handles.back())) ||
|
|
(tenure == TENURED && heap->InOldSpace(*handles.back())));
|
|
free_memory -= allocate_memory;
|
|
}
|
|
return handles;
|
|
}
|
|
|
|
void AllocateAllButNBytes(v8::internal::NewSpace* space, int extra_bytes,
|
|
std::vector<Handle<FixedArray>>* out_handles) {
|
|
space->DisableInlineAllocationSteps();
|
|
int space_remaining = static_cast<int>(*space->allocation_limit_address() -
|
|
*space->allocation_top_address());
|
|
CHECK(space_remaining >= extra_bytes);
|
|
int new_linear_size = space_remaining - extra_bytes;
|
|
if (new_linear_size == 0) return;
|
|
std::vector<Handle<FixedArray>> handles =
|
|
heap::CreatePadding(space->heap(), new_linear_size, i::NOT_TENURED);
|
|
if (out_handles != nullptr)
|
|
out_handles->insert(out_handles->end(), handles.begin(), handles.end());
|
|
}
|
|
|
|
void FillCurrentPage(v8::internal::NewSpace* space,
|
|
std::vector<Handle<FixedArray>>* out_handles) {
|
|
heap::AllocateAllButNBytes(space, 0, out_handles);
|
|
}
|
|
|
|
bool FillUpOnePage(v8::internal::NewSpace* space,
|
|
std::vector<Handle<FixedArray>>* out_handles) {
|
|
space->DisableInlineAllocationSteps();
|
|
int space_remaining = static_cast<int>(*space->allocation_limit_address() -
|
|
*space->allocation_top_address());
|
|
if (space_remaining == 0) return false;
|
|
std::vector<Handle<FixedArray>> handles =
|
|
heap::CreatePadding(space->heap(), space_remaining, i::NOT_TENURED);
|
|
if (out_handles != nullptr)
|
|
out_handles->insert(out_handles->end(), handles.begin(), handles.end());
|
|
return true;
|
|
}
|
|
|
|
void SimulateFullSpace(v8::internal::NewSpace* space,
|
|
std::vector<Handle<FixedArray>>* out_handles) {
|
|
heap::FillCurrentPage(space, out_handles);
|
|
while (heap::FillUpOnePage(space, out_handles) || space->AddFreshPage()) {
|
|
}
|
|
}
|
|
|
|
void SimulateIncrementalMarking(i::Heap* heap, bool force_completion) {
|
|
CHECK(FLAG_incremental_marking);
|
|
i::IncrementalMarking* marking = heap->incremental_marking();
|
|
i::MarkCompactCollector* collector = heap->mark_compact_collector();
|
|
if (collector->sweeping_in_progress()) {
|
|
collector->EnsureSweepingCompleted();
|
|
}
|
|
if (marking->IsSweeping()) {
|
|
marking->FinalizeSweeping();
|
|
}
|
|
CHECK(marking->IsMarking() || marking->IsStopped() || marking->IsComplete());
|
|
if (marking->IsStopped()) {
|
|
heap->StartIncrementalMarking(i::Heap::kNoGCFlags,
|
|
i::GarbageCollectionReason::kTesting);
|
|
}
|
|
CHECK(marking->IsMarking() || marking->IsComplete());
|
|
if (!force_completion) return;
|
|
|
|
while (!marking->IsComplete()) {
|
|
marking->Step(i::MB, i::IncrementalMarking::NO_GC_VIA_STACK_GUARD,
|
|
i::IncrementalMarking::FORCE_COMPLETION, i::StepOrigin::kV8);
|
|
if (marking->IsReadyToOverApproximateWeakClosure()) {
|
|
marking->FinalizeIncrementally();
|
|
}
|
|
}
|
|
CHECK(marking->IsComplete());
|
|
}
|
|
|
|
void SimulateFullSpace(v8::internal::PagedSpace* space) {
|
|
i::MarkCompactCollector* collector = space->heap()->mark_compact_collector();
|
|
if (collector->sweeping_in_progress()) {
|
|
collector->EnsureSweepingCompleted();
|
|
}
|
|
space->EmptyAllocationInfo();
|
|
space->ResetFreeList();
|
|
}
|
|
|
|
void AbandonCurrentlyFreeMemory(PagedSpace* space) {
|
|
space->EmptyAllocationInfo();
|
|
for (Page* page : *space) {
|
|
page->MarkNeverAllocateForTesting();
|
|
}
|
|
}
|
|
|
|
void GcAndSweep(Heap* heap, AllocationSpace space) {
|
|
heap->CollectGarbage(space, GarbageCollectionReason::kTesting);
|
|
if (heap->mark_compact_collector()->sweeping_in_progress()) {
|
|
heap->mark_compact_collector()->EnsureSweepingCompleted();
|
|
}
|
|
}
|
|
|
|
void ForceEvacuationCandidate(Page* page) {
|
|
CHECK(FLAG_manual_evacuation_candidates_selection);
|
|
page->SetFlag(MemoryChunk::FORCE_EVACUATION_CANDIDATE_FOR_TESTING);
|
|
PagedSpace* space = static_cast<PagedSpace*>(page->owner());
|
|
Address top = space->top();
|
|
Address limit = space->limit();
|
|
if (top < limit && Page::FromAllocationAreaAddress(top) == page) {
|
|
// Create filler object to keep page iterable if it was iterable.
|
|
int remaining = static_cast<int>(limit - top);
|
|
space->heap()->CreateFillerObjectAt(top, remaining,
|
|
ClearRecordedSlots::kNo);
|
|
space->EmptyAllocationInfo();
|
|
}
|
|
}
|
|
|
|
} // namespace heap
|
|
} // namespace internal
|
|
} // namespace v8
|