2016-09-06 22:49:51 +02:00
|
|
|
// 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.
|
|
|
|
|
2019-08-01 08:38:30 +02:00
|
|
|
#include "src/execution/isolate.h"
|
2022-11-18 09:50:46 +00:00
|
|
|
#include "src/heap/marking-state-inl.h"
|
2022-09-21 13:28:42 +02:00
|
|
|
#include "test/unittests/heap/heap-utils.h"
|
2016-09-06 22:49:51 +02:00
|
|
|
|
2017-09-12 11:34:59 +02:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2017-10-18 15:03:02 -07:00
|
|
|
namespace heap {
|
2017-09-12 11:34:59 +02:00
|
|
|
|
2019-03-12 09:01:49 +01:00
|
|
|
// Tests don't work when --optimize-for-size is set.
|
|
|
|
#ifndef V8_LITE_MODE
|
|
|
|
|
2016-09-06 22:49:51 +02:00
|
|
|
namespace {
|
|
|
|
|
2022-09-21 13:28:42 +02:00
|
|
|
class PagePromotionTest : public TestWithHeapInternalsAndContext {};
|
2016-09-06 22:49:51 +02:00
|
|
|
|
2024-04-19 12:51:52 +02:00
|
|
|
PageMetadata* FindPageInNewSpace(
|
|
|
|
const std::vector<Handle<FixedArray>>& handles) {
|
2017-09-12 11:34:59 +02:00
|
|
|
for (auto rit = handles.rbegin(); rit != handles.rend(); ++rit) {
|
2019-03-12 09:01:49 +01:00
|
|
|
// One deref gets the Handle, the second deref gets the FixedArray.
|
2024-04-19 12:51:52 +02:00
|
|
|
PageMetadata* candidate = PageMetadata::FromHeapObject(**rit);
|
|
|
|
if (candidate->Chunk()->InNewSpace() &&
|
2023-10-05 08:46:07 +02:00
|
|
|
candidate->heap()->new_space()->IsPromotionCandidate(candidate))
|
|
|
|
return candidate;
|
2017-09-12 11:34:59 +02:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-09-06 22:49:51 +02:00
|
|
|
|
2017-09-12 11:34:59 +02:00
|
|
|
} // namespace
|
2016-09-06 22:49:51 +02:00
|
|
|
|
2022-09-21 13:28:42 +02:00
|
|
|
TEST_F(PagePromotionTest, PagePromotion_NewToOld) {
|
|
|
|
if (i::v8_flags.single_generation) return;
|
|
|
|
if (!i::v8_flags.incremental_marking) return;
|
|
|
|
if (!i::v8_flags.page_promotion) return;
|
|
|
|
v8_flags.page_promotion_threshold = 0;
|
|
|
|
// Parallel evacuation messes with fragmentation in a way that objects that
|
|
|
|
// should be copied in semi space are promoted to old space because of
|
|
|
|
// fragmentation.
|
|
|
|
v8_flags.parallel_compaction = false;
|
|
|
|
// Parallel scavenge introduces too much fragmentation.
|
|
|
|
v8_flags.parallel_scavenge = false;
|
|
|
|
// We cannot optimize for size as we require a new space with more than one
|
|
|
|
// page.
|
|
|
|
v8_flags.optimize_for_size = false;
|
|
|
|
|
|
|
|
ManualGCScope manual_gc_scope(isolate());
|
2017-06-06 10:28:14 +02:00
|
|
|
|
2016-09-06 22:49:51 +02:00
|
|
|
{
|
2022-09-21 13:28:42 +02:00
|
|
|
v8::HandleScope handle_scope(reinterpret_cast<v8::Isolate*>(isolate()));
|
|
|
|
Heap* heap = isolate()->heap();
|
2016-09-06 22:49:51 +02:00
|
|
|
|
2019-03-15 18:35:06 +05:30
|
|
|
// Ensure that the new space is empty so that the page to be promoted
|
|
|
|
// does not contain the age mark.
|
2023-10-05 08:46:07 +02:00
|
|
|
EmptyNewSpaceUsingGC();
|
2019-03-15 18:35:06 +05:30
|
|
|
|
2016-09-06 22:49:51 +02:00
|
|
|
std::vector<Handle<FixedArray>> handles;
|
2022-09-21 13:28:42 +02:00
|
|
|
SimulateFullSpace(heap->new_space(), &handles);
|
2023-10-05 08:46:07 +02:00
|
|
|
if (v8_flags.minor_ms) InvokeMinorGC();
|
2016-09-06 22:49:51 +02:00
|
|
|
CHECK_GT(handles.size(), 0u);
|
2024-04-19 12:51:52 +02:00
|
|
|
PageMetadata* const to_be_promoted_page = FindPageInNewSpace(handles);
|
2017-09-12 11:34:59 +02:00
|
|
|
CHECK_NOT_NULL(to_be_promoted_page);
|
2022-09-21 13:28:42 +02:00
|
|
|
CHECK(heap->new_space()->IsPromotionCandidate(to_be_promoted_page));
|
2016-09-06 22:49:51 +02:00
|
|
|
// To perform a sanity check on live bytes we need to mark the heap.
|
2022-09-21 13:28:42 +02:00
|
|
|
SimulateIncrementalMarking(true);
|
2016-09-06 22:49:51 +02:00
|
|
|
// Sanity check that the page meets the requirements for promotion.
|
2019-03-12 09:01:49 +01:00
|
|
|
const int threshold_bytes = static_cast<int>(
|
2022-09-21 13:28:42 +02:00
|
|
|
v8_flags.page_promotion_threshold *
|
2019-03-12 09:01:49 +01:00
|
|
|
MemoryChunkLayout::AllocatableMemoryInDataPage() / 100);
|
2023-10-05 08:46:07 +02:00
|
|
|
CHECK_GE(to_be_promoted_page->live_bytes(), threshold_bytes);
|
2016-09-06 22:49:51 +02:00
|
|
|
|
|
|
|
// Actual checks: The page is in new space first, but is moved to old space
|
|
|
|
// during a full GC.
|
2024-04-19 12:51:52 +02:00
|
|
|
CHECK(heap->new_space()->ContainsSlow(to_be_promoted_page->ChunkAddress()));
|
|
|
|
CHECK(
|
|
|
|
!heap->old_space()->ContainsSlow(to_be_promoted_page->ChunkAddress()));
|
2023-10-05 08:46:07 +02:00
|
|
|
EmptyNewSpaceUsingGC();
|
2024-04-19 12:51:52 +02:00
|
|
|
CHECK(
|
|
|
|
!heap->new_space()->ContainsSlow(to_be_promoted_page->ChunkAddress()));
|
|
|
|
CHECK(heap->old_space()->ContainsSlow(to_be_promoted_page->ChunkAddress()));
|
2016-09-06 22:49:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-12 09:01:49 +01:00
|
|
|
#endif // V8_LITE_MODE
|
|
|
|
|
2017-10-18 15:03:02 -07:00
|
|
|
} // namespace heap
|
2016-09-06 22:49:51 +02:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|