Index: test/cctest/heap/heap-utils.cc |
diff --git a/test/cctest/heap/utils-inl.h b/test/cctest/heap/heap-utils.cc |
similarity index 62% |
rename from test/cctest/heap/utils-inl.h |
rename to test/cctest/heap/heap-utils.cc |
index 0e943b4197538bccb7bd79c14c0bcd352a512177..e6daa454417ab5b78d87873e4420ea61b372522a 100644 |
--- a/test/cctest/heap/utils-inl.h |
+++ b/test/cctest/heap/heap-utils.cc |
@@ -1,9 +1,8 @@ |
-// Copyright 2015 the V8 project authors. All rights reserved. |
+// 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. |
-#ifndef HEAP_UTILS_H_ |
-#define HEAP_UTILS_H_ |
+#include "test/cctest/heap/heap-utils.h" |
#include "src/factory.h" |
#include "src/heap/heap-inl.h" |
@@ -11,18 +10,29 @@ |
#include "src/heap/mark-compact.h" |
#include "src/isolate.h" |
- |
namespace v8 { |
namespace internal { |
+namespace heap { |
+ |
+void SealCurrentObjects(Heap* heap) { |
+ heap->CollectAllGarbage(); |
+ heap->CollectAllGarbage(); |
+ heap->mark_compact_collector()->EnsureSweepingCompleted(); |
+ PageIterator it(heap->old_space()); |
+ heap->old_space()->EmptyAllocationInfo(); |
+ while (it.has_next()) { |
+ Page* page = it.next(); |
+ page->MarkNeverAllocateForTesting(); |
+ } |
+} |
-static int LenFromSize(int size) { |
+int FixedArrayLenFromSize(int size) { |
return (size - FixedArray::kHeaderSize) / kPointerSize; |
} |
- |
-static inline std::vector<Handle<FixedArray>> CreatePadding( |
- Heap* heap, int padding_size, PretenureFlag tenure, |
- int object_size = Page::kMaxRegularHeapObjectSize) { |
+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; |
@@ -42,14 +52,17 @@ static inline std::vector<Handle<FixedArray>> CreatePadding( |
while (free_memory > 0) { |
if (free_memory > object_size) { |
allocate_memory = object_size; |
- length = LenFromSize(allocate_memory); |
+ length = FixedArrayLenFromSize(allocate_memory); |
} else { |
allocate_memory = free_memory; |
- length = LenFromSize(allocate_memory); |
+ length = FixedArrayLenFromSize(allocate_memory); |
if (length <= 0) { |
// Not enough room to create another fixed array. Let's create a filler. |
- heap->CreateFillerObjectAt(*heap->old_space()->allocation_top_address(), |
- free_memory, ClearRecordedSlots::kNo); |
+ if (free_memory > (2 * kPointerSize)) { |
+ heap->CreateFillerObjectAt( |
+ *heap->old_space()->allocation_top_address(), free_memory, |
+ ClearRecordedSlots::kNo); |
+ } |
break; |
} |
} |
@@ -61,66 +74,46 @@ static inline std::vector<Handle<FixedArray>> CreatePadding( |
return handles; |
} |
- |
-// Helper function that simulates a full new-space in the heap. |
-static inline bool FillUpOnePage( |
- v8::internal::NewSpace* space, |
- std::vector<Handle<FixedArray>>* out_handles = nullptr) { |
+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()); |
- if (space_remaining == 0) return false; |
+ CHECK(space_remaining >= extra_bytes); |
+ int new_linear_size = space_remaining - extra_bytes; |
+ if (new_linear_size == 0) return; |
std::vector<Handle<FixedArray>> handles = |
- CreatePadding(space->heap(), space_remaining, i::NOT_TENURED); |
+ heap::CreatePadding(space->heap(), new_linear_size, i::NOT_TENURED); |
if (out_handles != nullptr) |
out_handles->insert(out_handles->end(), handles.begin(), handles.end()); |
- return true; |
} |
+void FillCurrentPage(v8::internal::NewSpace* space, |
+ std::vector<Handle<FixedArray>>* out_handles) { |
+ heap::AllocateAllButNBytes(space, 0, out_handles); |
+} |
-// Helper function that simulates a fill new-space in the heap. |
-static inline void AllocateAllButNBytes( |
- v8::internal::NewSpace* space, int extra_bytes, |
- std::vector<Handle<FixedArray>>* out_handles = nullptr) { |
+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()); |
- CHECK(space_remaining >= extra_bytes); |
- int new_linear_size = space_remaining - extra_bytes; |
- if (new_linear_size == 0) return; |
+ if (space_remaining == 0) return false; |
std::vector<Handle<FixedArray>> handles = |
- CreatePadding(space->heap(), new_linear_size, i::NOT_TENURED); |
+ 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; |
} |
-static inline void FillCurrentPage( |
- v8::internal::NewSpace* space, |
- std::vector<Handle<FixedArray>>* out_handles = nullptr) { |
- AllocateAllButNBytes(space, 0, out_handles); |
-} |
- |
-static inline void SimulateFullSpace( |
- v8::internal::NewSpace* space, |
- std::vector<Handle<FixedArray>>* out_handles = nullptr) { |
- FillCurrentPage(space, out_handles); |
- while (FillUpOnePage(space, out_handles) || space->AddFreshPage()) { |
+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()) { |
} |
} |
- |
-// Helper function that simulates a full old-space in the heap. |
-static inline void SimulateFullSpace(v8::internal::PagedSpace* space) { |
- space->EmptyAllocationInfo(); |
- space->ResetFreeList(); |
- space->ClearStats(); |
-} |
- |
- |
-// Helper function that simulates many incremental marking steps until |
-// marking is completed. |
-static inline void SimulateIncrementalMarking(i::Heap* heap, |
- bool force_completion = true) { |
+void SimulateIncrementalMarking(i::Heap* heap, bool force_completion) { |
i::MarkCompactCollector* collector = heap->mark_compact_collector(); |
i::IncrementalMarking* marking = heap->incremental_marking(); |
if (collector->sweeping_in_progress()) { |
@@ -142,7 +135,12 @@ static inline void SimulateIncrementalMarking(i::Heap* heap, |
CHECK(marking->IsComplete()); |
} |
+void SimulateFullSpace(v8::internal::PagedSpace* space) { |
+ space->EmptyAllocationInfo(); |
+ space->ResetFreeList(); |
+ space->ClearStats(); |
+} |
+ |
+} // namespace heap |
} // namespace internal |
} // namespace v8 |
- |
-#endif // HEAP_UTILS_H_ |