14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci 164514f5e3Sopenharmony_ci#include "ecmascript/builtins/builtins_ark_tools.h" 174514f5e3Sopenharmony_ci#include "ecmascript/ecma_vm.h" 184514f5e3Sopenharmony_ci#include "ecmascript/mem/full_gc.h" 194514f5e3Sopenharmony_ci#include "ecmascript/object_factory-inl.h" 204514f5e3Sopenharmony_ci#include "ecmascript/mem/concurrent_marker.h" 214514f5e3Sopenharmony_ci#include "ecmascript/mem/partial_gc.h" 224514f5e3Sopenharmony_ci#include "ecmascript/mem/incremental_marker.h" 234514f5e3Sopenharmony_ci#include "ecmascript/tests/ecma_test_common.h" 244514f5e3Sopenharmony_ci 254514f5e3Sopenharmony_ciusing namespace panda; 264514f5e3Sopenharmony_ci 274514f5e3Sopenharmony_ciusing namespace panda::ecmascript; 284514f5e3Sopenharmony_ci 294514f5e3Sopenharmony_cinamespace panda::test { 304514f5e3Sopenharmony_ciclass GCTest : public BaseTestWithScope<false> { 314514f5e3Sopenharmony_cipublic: 324514f5e3Sopenharmony_ci void SetUp() override 334514f5e3Sopenharmony_ci { 344514f5e3Sopenharmony_ci JSRuntimeOptions options; 354514f5e3Sopenharmony_ci options.SetEnableEdenGC(true); 364514f5e3Sopenharmony_ci instance = JSNApi::CreateEcmaVM(options); 374514f5e3Sopenharmony_ci ASSERT_TRUE(instance != nullptr) << "Cannot create EcmaVM"; 384514f5e3Sopenharmony_ci thread = instance->GetJSThread(); 394514f5e3Sopenharmony_ci thread->ManagedCodeBegin(); 404514f5e3Sopenharmony_ci scope = new EcmaHandleScope(thread); 414514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 424514f5e3Sopenharmony_ci heap->GetConcurrentMarker()->EnableConcurrentMarking(EnableConcurrentMarkType::ENABLE); 434514f5e3Sopenharmony_ci heap->GetSweeper()->EnableConcurrentSweep(EnableConcurrentSweepType::ENABLE); 444514f5e3Sopenharmony_ci } 454514f5e3Sopenharmony_ci}; 464514f5e3Sopenharmony_ci 474514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, ArkToolsHintGC) 484514f5e3Sopenharmony_ci{ 494514f5e3Sopenharmony_ci Heap *heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 504514f5e3Sopenharmony_ci heap->GetConcurrentMarker()->EnableConcurrentMarking(EnableConcurrentMarkType::CONFIG_DISABLE); 514514f5e3Sopenharmony_ci auto getSizeAfterCreateAndCallHintGC = [this, heap] (size_t &newSize, size_t &finalSize) -> bool { 524514f5e3Sopenharmony_ci { 534514f5e3Sopenharmony_ci [[maybe_unused]] ecmascript::EcmaHandleScope baseScope(thread); 544514f5e3Sopenharmony_ci for (int i = 0; i < 2048; i++) { 554514f5e3Sopenharmony_ci [[maybe_unused]] JSHandle<TaggedArray> obj = thread->GetEcmaVM()->GetFactory()-> 564514f5e3Sopenharmony_ci NewTaggedArray(10 * 1024, JSTaggedValue::Hole(), MemSpaceType::OLD_SPACE); 574514f5e3Sopenharmony_ci } 584514f5e3Sopenharmony_ci newSize = heap->GetCommittedSize(); 594514f5e3Sopenharmony_ci } 604514f5e3Sopenharmony_ci std::vector<JSTaggedValue> vals{JSTaggedValue(static_cast<double>(2))}; 614514f5e3Sopenharmony_ci auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, vals, 624514f5e3Sopenharmony_ci 6); 634514f5e3Sopenharmony_ci [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); 644514f5e3Sopenharmony_ci JSTaggedValue result = builtins::BuiltinsArkTools::HintGC(ecmaRuntimeCallInfo); 654514f5e3Sopenharmony_ci finalSize = heap->GetCommittedSize(); 664514f5e3Sopenharmony_ci TestHelper::TearDownFrame(thread, prev); 674514f5e3Sopenharmony_ci 684514f5e3Sopenharmony_ci return result.ToBoolean(); 694514f5e3Sopenharmony_ci }; 704514f5e3Sopenharmony_ci { 714514f5e3Sopenharmony_ci // Test HintGC() when sensitive. 724514f5e3Sopenharmony_ci heap->CollectGarbage(TriggerGCType::FULL_GC); 734514f5e3Sopenharmony_ci heap->NotifyHighSensitive(true); 744514f5e3Sopenharmony_ci size_t originSize = heap->GetCommittedSize(); 754514f5e3Sopenharmony_ci size_t newSize = 0; 764514f5e3Sopenharmony_ci size_t finalSize = 0; 774514f5e3Sopenharmony_ci bool res = getSizeAfterCreateAndCallHintGC(newSize, finalSize); 784514f5e3Sopenharmony_ci EXPECT_FALSE(res); 794514f5e3Sopenharmony_ci EXPECT_TRUE(newSize > originSize); 804514f5e3Sopenharmony_ci EXPECT_TRUE(finalSize == newSize); 814514f5e3Sopenharmony_ci heap->NotifyHighSensitive(false); 824514f5e3Sopenharmony_ci } 834514f5e3Sopenharmony_ci { 844514f5e3Sopenharmony_ci#ifdef NDEBUG 854514f5e3Sopenharmony_ci size_t originSize = heap->GetCommittedSize(); 864514f5e3Sopenharmony_ci size_t newSize = 0; 874514f5e3Sopenharmony_ci size_t finalSize = 0; 884514f5e3Sopenharmony_ci bool res = getSizeAfterCreateAndCallHintGC(newSize, finalSize); 894514f5e3Sopenharmony_ci EXPECT_TRUE(res); 904514f5e3Sopenharmony_ci EXPECT_TRUE(newSize > originSize); 914514f5e3Sopenharmony_ci EXPECT_TRUE(finalSize < newSize); 924514f5e3Sopenharmony_ci#endif 934514f5e3Sopenharmony_ci } 944514f5e3Sopenharmony_ci} 954514f5e3Sopenharmony_ci 964514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, LargeOverShootSizeTest) 974514f5e3Sopenharmony_ci{ 984514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 994514f5e3Sopenharmony_ci size_t originalYoungSize = heap->GetNewSpace()->GetCommittedSize(); 1004514f5e3Sopenharmony_ci 1014514f5e3Sopenharmony_ci EXPECT_FALSE(heap->GetNewSpace()->CommittedSizeIsLarge()); 1024514f5e3Sopenharmony_ci heap->GetConcurrentMarker()->ConfigConcurrentMark(false); 1034514f5e3Sopenharmony_ci heap->NotifyHighSensitive(true); 1044514f5e3Sopenharmony_ci { 1054514f5e3Sopenharmony_ci [[maybe_unused]] ecmascript::EcmaHandleScope baseScope(thread); 1064514f5e3Sopenharmony_ci for (int i = 0; i < 500; i++) { 1074514f5e3Sopenharmony_ci [[maybe_unused]] JSHandle<TaggedArray> array = thread->GetEcmaVM()->GetFactory()->NewTaggedArray( 1084514f5e3Sopenharmony_ci 10 * 1024, JSTaggedValue::Hole(), MemSpaceType::SEMI_SPACE); 1094514f5e3Sopenharmony_ci } 1104514f5e3Sopenharmony_ci } 1114514f5e3Sopenharmony_ci size_t newYoungSize = heap->GetNewSpace()->GetCommittedSize(); 1124514f5e3Sopenharmony_ci size_t originalOverShootSize = heap->GetNewSpace()->GetOvershootSize(); 1134514f5e3Sopenharmony_ci EXPECT_TRUE(heap->GetNewSpace()->CommittedSizeIsLarge()); 1144514f5e3Sopenharmony_ci EXPECT_TRUE(originalYoungSize < newYoungSize); 1154514f5e3Sopenharmony_ci 1164514f5e3Sopenharmony_ci heap->NotifyHighSensitive(false); 1174514f5e3Sopenharmony_ci heap->CollectGarbage(TriggerGCType::YOUNG_GC); 1184514f5e3Sopenharmony_ci newYoungSize = heap->GetNewSpace()->GetCommittedSize(); 1194514f5e3Sopenharmony_ci size_t newOverShootSize = heap->GetNewSpace()->GetOvershootSize(); 1204514f5e3Sopenharmony_ci 1214514f5e3Sopenharmony_ci EXPECT_TRUE(originalYoungSize < newYoungSize); 1224514f5e3Sopenharmony_ci EXPECT_TRUE(originalOverShootSize < newOverShootSize); 1234514f5e3Sopenharmony_ci EXPECT_TRUE(0 < newOverShootSize); 1244514f5e3Sopenharmony_ci 1254514f5e3Sopenharmony_ci { 1264514f5e3Sopenharmony_ci [[maybe_unused]] ecmascript::EcmaHandleScope baseScope(thread); 1274514f5e3Sopenharmony_ci for (int i = 0; i < 2049; i++) { 1284514f5e3Sopenharmony_ci [[maybe_unused]] JSHandle<TaggedArray> array = thread->GetEcmaVM()->GetFactory()->NewTaggedArray( 1294514f5e3Sopenharmony_ci 1024, JSTaggedValue::Hole(), MemSpaceType::SEMI_SPACE); 1304514f5e3Sopenharmony_ci } 1314514f5e3Sopenharmony_ci } 1324514f5e3Sopenharmony_ci size_t newSize = heap->GetNewSpace()->GetCommittedSize(); 1334514f5e3Sopenharmony_ci EXPECT_TRUE(originalYoungSize <= newSize); 1344514f5e3Sopenharmony_ci} 1354514f5e3Sopenharmony_ci 1364514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, CheckAndTriggerSharedGCTest001) 1374514f5e3Sopenharmony_ci{ 1384514f5e3Sopenharmony_ci SharedHeap *heap = SharedHeap::GetInstance(); 1394514f5e3Sopenharmony_ci ASSERT_EQ(heap->CheckAndTriggerSharedGC(thread), false); 1404514f5e3Sopenharmony_ci} 1414514f5e3Sopenharmony_ci 1424514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, CheckHugeAndTriggerSharedGCTest001) 1434514f5e3Sopenharmony_ci{ 1444514f5e3Sopenharmony_ci SharedHeap *heap = SharedHeap::GetInstance(); 1454514f5e3Sopenharmony_ci ASSERT_EQ(heap->CheckHugeAndTriggerSharedGC(thread, 1374210560), true); 1464514f5e3Sopenharmony_ci} 1474514f5e3Sopenharmony_ci 1484514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, CheckHugeAndTriggerSharedGCTest002) 1494514f5e3Sopenharmony_ci{ 1504514f5e3Sopenharmony_ci SharedHeap *heap = SharedHeap::GetInstance(); 1514514f5e3Sopenharmony_ci ASSERT_EQ(heap->CheckHugeAndTriggerSharedGC(thread, 1), false); 1524514f5e3Sopenharmony_ci} 1534514f5e3Sopenharmony_ci 1544514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, ObjectExceedMaxHeapSizeTest001) 1554514f5e3Sopenharmony_ci{ 1564514f5e3Sopenharmony_ci SharedHeap *heap = SharedHeap::GetInstance(); 1574514f5e3Sopenharmony_ci ASSERT_EQ(heap->ObjectExceedMaxHeapSize(), false); 1584514f5e3Sopenharmony_ci} 1594514f5e3Sopenharmony_ci 1604514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, CheckAndTriggerHintGCTest001) 1614514f5e3Sopenharmony_ci{ 1624514f5e3Sopenharmony_ci#ifdef NDEBUG 1634514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 1644514f5e3Sopenharmony_ci heap->CollectGarbage(TriggerGCType::OLD_GC); 1654514f5e3Sopenharmony_ci ASSERT_EQ(heap->CheckAndTriggerHintGC(MemoryReduceDegree::LOW, GCReason::HINT_GC), false); 1664514f5e3Sopenharmony_ci { 1674514f5e3Sopenharmony_ci [[maybe_unused]] ecmascript::EcmaHandleScope baseScope(thread); 1684514f5e3Sopenharmony_ci for (int i = 0; i < 4048; i++) { 1694514f5e3Sopenharmony_ci [[maybe_unused]] JSHandle<TaggedArray> array = thread->GetEcmaVM()->GetFactory()->NewTaggedArray( 1704514f5e3Sopenharmony_ci 1024, JSTaggedValue::Hole(), MemSpaceType::OLD_SPACE); 1714514f5e3Sopenharmony_ci } 1724514f5e3Sopenharmony_ci } 1734514f5e3Sopenharmony_ci ASSERT_EQ(heap->CheckAndTriggerHintGC(MemoryReduceDegree::LOW, GCReason::HINT_GC), true); 1744514f5e3Sopenharmony_ci#endif 1754514f5e3Sopenharmony_ci} 1764514f5e3Sopenharmony_ci 1774514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, CheckAndTriggerHintGCTest002) 1784514f5e3Sopenharmony_ci{ 1794514f5e3Sopenharmony_ci#ifdef NDEBUG 1804514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 1814514f5e3Sopenharmony_ci heap->CollectGarbage(TriggerGCType::FULL_GC); 1824514f5e3Sopenharmony_ci ASSERT_EQ(heap->CheckAndTriggerHintGC(MemoryReduceDegree::MIDDLE, GCReason::HINT_GC), false); 1834514f5e3Sopenharmony_ci { 1844514f5e3Sopenharmony_ci [[maybe_unused]] ecmascript::EcmaHandleScope baseScope(thread); 1854514f5e3Sopenharmony_ci for (int i = 0; i < 4048; i++) { 1864514f5e3Sopenharmony_ci [[maybe_unused]] JSHandle<TaggedArray> array = thread->GetEcmaVM()->GetFactory()->NewTaggedArray( 1874514f5e3Sopenharmony_ci 1024, JSTaggedValue::Hole(), MemSpaceType::OLD_SPACE); 1884514f5e3Sopenharmony_ci } 1894514f5e3Sopenharmony_ci } 1904514f5e3Sopenharmony_ci ASSERT_EQ(heap->CheckAndTriggerHintGC(MemoryReduceDegree::MIDDLE, GCReason::HINT_GC), true); 1914514f5e3Sopenharmony_ci#endif 1924514f5e3Sopenharmony_ci} 1934514f5e3Sopenharmony_ci 1944514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, CheckAndTriggerHintGCTest003) 1954514f5e3Sopenharmony_ci{ 1964514f5e3Sopenharmony_ci#ifdef NDEBUG 1974514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 1984514f5e3Sopenharmony_ci heap->CollectGarbage(TriggerGCType::FULL_GC); 1994514f5e3Sopenharmony_ci ASSERT_EQ(heap->CheckAndTriggerHintGC(MemoryReduceDegree::HIGH, GCReason::HINT_GC), false); 2004514f5e3Sopenharmony_ci { 2014514f5e3Sopenharmony_ci [[maybe_unused]] ecmascript::EcmaHandleScope baseScope(thread); 2024514f5e3Sopenharmony_ci for (int i = 0; i < 1049; i++) { 2034514f5e3Sopenharmony_ci [[maybe_unused]] JSHandle<TaggedArray> array = thread->GetEcmaVM()->GetFactory()->NewTaggedArray( 2044514f5e3Sopenharmony_ci 1024, JSTaggedValue::Hole(), MemSpaceType::OLD_SPACE); 2054514f5e3Sopenharmony_ci } 2064514f5e3Sopenharmony_ci } 2074514f5e3Sopenharmony_ci ASSERT_EQ(heap->CheckAndTriggerHintGC(MemoryReduceDegree::HIGH, GCReason::HINT_GC), true); 2084514f5e3Sopenharmony_ci#endif 2094514f5e3Sopenharmony_ci} 2104514f5e3Sopenharmony_ci 2114514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, CheckAndTriggerHintGCTest004) 2124514f5e3Sopenharmony_ci{ 2134514f5e3Sopenharmony_ci#ifdef NDEBUG 2144514f5e3Sopenharmony_ci auto sHeap = SharedHeap::GetInstance(); 2154514f5e3Sopenharmony_ci sHeap->CollectGarbage<TriggerGCType::SHARED_GC, GCReason::OTHER>(thread); 2164514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 2174514f5e3Sopenharmony_ci ASSERT_EQ(heap->CheckAndTriggerHintGC(MemoryReduceDegree::LOW, GCReason::HINT_GC), false); 2184514f5e3Sopenharmony_ci { 2194514f5e3Sopenharmony_ci [[maybe_unused]] ecmascript::EcmaHandleScope baseScope(thread); 2204514f5e3Sopenharmony_ci for (int i = 0; i < 4048; i++) { 2214514f5e3Sopenharmony_ci [[maybe_unused]] JSHandle<TaggedArray> array = thread->GetEcmaVM()->GetFactory()-> 2224514f5e3Sopenharmony_ci NewSOldSpaceTaggedArray(1024, JSTaggedValue::Undefined()); 2234514f5e3Sopenharmony_ci } 2244514f5e3Sopenharmony_ci } 2254514f5e3Sopenharmony_ci ASSERT_EQ(heap->CheckAndTriggerHintGC(MemoryReduceDegree::LOW, GCReason::HINT_GC), true); 2264514f5e3Sopenharmony_ci#endif 2274514f5e3Sopenharmony_ci} 2284514f5e3Sopenharmony_ci 2294514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, CheckAndTriggerHintGCTest005) 2304514f5e3Sopenharmony_ci{ 2314514f5e3Sopenharmony_ci#ifdef NDEBUG 2324514f5e3Sopenharmony_ci auto sHeap = SharedHeap::GetInstance(); 2334514f5e3Sopenharmony_ci sHeap->CollectGarbage<TriggerGCType::SHARED_FULL_GC, GCReason::OTHER>(thread); 2344514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 2354514f5e3Sopenharmony_ci ASSERT_EQ(heap->CheckAndTriggerHintGC(MemoryReduceDegree::MIDDLE, GCReason::HINT_GC), false); 2364514f5e3Sopenharmony_ci { 2374514f5e3Sopenharmony_ci [[maybe_unused]] ecmascript::EcmaHandleScope baseScope(thread); 2384514f5e3Sopenharmony_ci for (int i = 0; i < 4048; i++) { 2394514f5e3Sopenharmony_ci [[maybe_unused]] JSHandle<TaggedArray> array = thread->GetEcmaVM()->GetFactory()-> 2404514f5e3Sopenharmony_ci NewSOldSpaceTaggedArray(1024, JSTaggedValue::Undefined()); 2414514f5e3Sopenharmony_ci } 2424514f5e3Sopenharmony_ci } 2434514f5e3Sopenharmony_ci ASSERT_EQ(heap->CheckAndTriggerHintGC(MemoryReduceDegree::MIDDLE, GCReason::HINT_GC), true); 2444514f5e3Sopenharmony_ci#endif 2454514f5e3Sopenharmony_ci} 2464514f5e3Sopenharmony_ci 2474514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, CheckAndTriggerHintGCTest006) 2484514f5e3Sopenharmony_ci{ 2494514f5e3Sopenharmony_ci#ifdef NDEBUG 2504514f5e3Sopenharmony_ci auto sHeap = SharedHeap::GetInstance(); 2514514f5e3Sopenharmony_ci sHeap->CollectGarbage<TriggerGCType::SHARED_FULL_GC, GCReason::OTHER>(thread); 2524514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 2534514f5e3Sopenharmony_ci ASSERT_EQ(heap->CheckAndTriggerHintGC(MemoryReduceDegree::HIGH, GCReason::HINT_GC), false); 2544514f5e3Sopenharmony_ci { 2554514f5e3Sopenharmony_ci [[maybe_unused]] ecmascript::EcmaHandleScope baseScope(thread); 2564514f5e3Sopenharmony_ci for (int i = 0; i < 2049; i++) { 2574514f5e3Sopenharmony_ci [[maybe_unused]] JSHandle<TaggedArray> array = thread->GetEcmaVM()->GetFactory()-> 2584514f5e3Sopenharmony_ci NewSOldSpaceTaggedArray(1024, JSTaggedValue::Undefined()); 2594514f5e3Sopenharmony_ci } 2604514f5e3Sopenharmony_ci } 2614514f5e3Sopenharmony_ci ASSERT_EQ(heap->CheckAndTriggerHintGC(MemoryReduceDegree::HIGH, GCReason::HINT_GC), true); 2624514f5e3Sopenharmony_ci#endif 2634514f5e3Sopenharmony_ci} 2644514f5e3Sopenharmony_ci 2654514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, CalculateIdleDurationTest001) 2664514f5e3Sopenharmony_ci{ 2674514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 2684514f5e3Sopenharmony_ci heap->SetMarkType(MarkType::MARK_EDEN); 2694514f5e3Sopenharmony_ci ASSERT_EQ(heap->GetMarkType(), MarkType::MARK_EDEN); 2704514f5e3Sopenharmony_ci heap->CalculateIdleDuration(); 2714514f5e3Sopenharmony_ci} 2724514f5e3Sopenharmony_ci 2734514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, CalculateIdleDurationTest002) 2744514f5e3Sopenharmony_ci{ 2754514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 2764514f5e3Sopenharmony_ci heap->SetMarkType(MarkType::MARK_YOUNG); 2774514f5e3Sopenharmony_ci ASSERT_EQ(heap->GetMarkType(), MarkType::MARK_YOUNG); 2784514f5e3Sopenharmony_ci heap->CalculateIdleDuration(); 2794514f5e3Sopenharmony_ci} 2804514f5e3Sopenharmony_ci 2814514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, CalculateIdleDurationTest003) 2824514f5e3Sopenharmony_ci{ 2834514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 2844514f5e3Sopenharmony_ci heap->SetMarkType(MarkType::MARK_FULL); 2854514f5e3Sopenharmony_ci ASSERT_EQ(heap->GetMarkType(), MarkType::MARK_FULL); 2864514f5e3Sopenharmony_ci heap->CalculateIdleDuration(); 2874514f5e3Sopenharmony_ci} 2884514f5e3Sopenharmony_ci 2894514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, TryTriggerFullMarkBySharedLimitTest001) 2904514f5e3Sopenharmony_ci{ 2914514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 2924514f5e3Sopenharmony_ci ASSERT_EQ(heap->TryTriggerFullMarkBySharedLimit(), false); 2934514f5e3Sopenharmony_ci} 2944514f5e3Sopenharmony_ci 2954514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, TryTriggerFullMarkBySharedLimitTest002) 2964514f5e3Sopenharmony_ci{ 2974514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 2984514f5e3Sopenharmony_ci heap->SetIdleTask(IdleTaskType::FINISH_MARKING); 2994514f5e3Sopenharmony_ci ASSERT_EQ(heap->TryTriggerFullMarkBySharedLimit(), false); 3004514f5e3Sopenharmony_ci} 3014514f5e3Sopenharmony_ci 3024514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, TryTriggerFullMarkBySharedLimitTest003) 3034514f5e3Sopenharmony_ci{ 3044514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 3054514f5e3Sopenharmony_ci for (size_t i = 0; i < 4; i++) { 3064514f5e3Sopenharmony_ci ConcurrentMarker::TryIncreaseTaskCounts(); 3074514f5e3Sopenharmony_ci } 3084514f5e3Sopenharmony_ci ASSERT_EQ(heap->TryTriggerFullMarkBySharedLimit(), true); 3094514f5e3Sopenharmony_ci} 3104514f5e3Sopenharmony_ci 3114514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, CheckAndTriggerTaskFinishedGCTest001) 3124514f5e3Sopenharmony_ci{ 3134514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 3144514f5e3Sopenharmony_ci heap->CheckAndTriggerTaskFinishedGC(); 3154514f5e3Sopenharmony_ci} 3164514f5e3Sopenharmony_ci 3174514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, TryTriggerFullMarkBySharedSizeTest001) 3184514f5e3Sopenharmony_ci{ 3194514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 3204514f5e3Sopenharmony_ci heap->TryTriggerFullMarkBySharedSize(81579214); 3214514f5e3Sopenharmony_ci} 3224514f5e3Sopenharmony_ci 3234514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, DecreaseNativeBindingSizeTest001) 3244514f5e3Sopenharmony_ci{ 3254514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 3264514f5e3Sopenharmony_ci heap->DecreaseNativeBindingSize(0); 3274514f5e3Sopenharmony_ci} 3284514f5e3Sopenharmony_ci 3294514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, TriggerConcurrentMarkingTest001) 3304514f5e3Sopenharmony_ci{ 3314514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 3324514f5e3Sopenharmony_ci heap->SetMarkType(MarkType::MARK_FULL); 3334514f5e3Sopenharmony_ci heap->SetIdleTask(IdleTaskType::YOUNG_GC); 3344514f5e3Sopenharmony_ci heap->TriggerConcurrentMarking(); 3354514f5e3Sopenharmony_ci} 3364514f5e3Sopenharmony_ci 3374514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, TriggerIdleCollectionTest001) 3384514f5e3Sopenharmony_ci{ 3394514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 3404514f5e3Sopenharmony_ci heap->SetIdleTask(IdleTaskType::NO_TASK); 3414514f5e3Sopenharmony_ci heap->TriggerIdleCollection(1000); 3424514f5e3Sopenharmony_ci} 3434514f5e3Sopenharmony_ci 3444514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, TriggerIdleCollectionTest002) 3454514f5e3Sopenharmony_ci{ 3464514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 3474514f5e3Sopenharmony_ci heap->SetIdleTask(IdleTaskType::INCREMENTAL_MARK); 3484514f5e3Sopenharmony_ci heap->TriggerIdleCollection(1000); 3494514f5e3Sopenharmony_ci} 3504514f5e3Sopenharmony_ci 3514514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, TriggerIdleCollectionTest003) 3524514f5e3Sopenharmony_ci{ 3534514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 3544514f5e3Sopenharmony_ci heap->SetIdleTask(IdleTaskType::FINISH_MARKING); 3554514f5e3Sopenharmony_ci heap->TriggerIdleCollection(-1); 3564514f5e3Sopenharmony_ci} 3574514f5e3Sopenharmony_ci 3584514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, TriggerIdleCollectionTest004) 3594514f5e3Sopenharmony_ci{ 3604514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 3614514f5e3Sopenharmony_ci heap->SetIdleTask(IdleTaskType::FINISH_MARKING); 3624514f5e3Sopenharmony_ci heap->SetMarkType(MarkType::MARK_FULL); 3634514f5e3Sopenharmony_ci heap->TriggerIdleCollection(1000); 3644514f5e3Sopenharmony_ci} 3654514f5e3Sopenharmony_ci 3664514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, TriggerIdleCollectionTest005) 3674514f5e3Sopenharmony_ci{ 3684514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 3694514f5e3Sopenharmony_ci heap->SetIdleTask(IdleTaskType::FINISH_MARKING); 3704514f5e3Sopenharmony_ci heap->SetMarkType(MarkType::MARK_EDEN); 3714514f5e3Sopenharmony_ci heap->TriggerIdleCollection(1000); 3724514f5e3Sopenharmony_ci} 3734514f5e3Sopenharmony_ci 3744514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, TriggerIdleCollectionTest006) 3754514f5e3Sopenharmony_ci{ 3764514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 3774514f5e3Sopenharmony_ci heap->SetIdleTask(IdleTaskType::YOUNG_GC); 3784514f5e3Sopenharmony_ci heap->TriggerIdleCollection(1000); 3794514f5e3Sopenharmony_ci} 3804514f5e3Sopenharmony_ci 3814514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, NotifyFinishColdStartTest001) 3824514f5e3Sopenharmony_ci{ 3834514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 3844514f5e3Sopenharmony_ci heap->SetIdleTask(IdleTaskType::YOUNG_GC); 3854514f5e3Sopenharmony_ci heap->NotifyFinishColdStart(true); 3864514f5e3Sopenharmony_ci} 3874514f5e3Sopenharmony_ci 3884514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, NotifyFinishColdStartSoonTest001) 3894514f5e3Sopenharmony_ci{ 3904514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 3914514f5e3Sopenharmony_ci heap->NotifyFinishColdStartSoon(); 3924514f5e3Sopenharmony_ci} 3934514f5e3Sopenharmony_ci 3944514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, NeedStopCollectionTest001) 3954514f5e3Sopenharmony_ci{ 3964514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 3974514f5e3Sopenharmony_ci heap->SetOnSerializeEvent(true); 3984514f5e3Sopenharmony_ci ASSERT_EQ(heap->NeedStopCollection(), true); 3994514f5e3Sopenharmony_ci} 4004514f5e3Sopenharmony_ci 4014514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, ReclaimTest001) 4024514f5e3Sopenharmony_ci{ 4034514f5e3Sopenharmony_ci SharedHeap *heap = SharedHeap::GetInstance(); 4044514f5e3Sopenharmony_ci heap->DisableParallelGC(thread); 4054514f5e3Sopenharmony_ci heap->Reclaim(TriggerGCType::EDEN_GC); 4064514f5e3Sopenharmony_ci} 4074514f5e3Sopenharmony_ci 4084514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, CollectGarbageTest001) 4094514f5e3Sopenharmony_ci{ 4104514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 4114514f5e3Sopenharmony_ci heap->CollectGarbage(TriggerGCType::EDEN_GC, GCReason::IDLE); 4124514f5e3Sopenharmony_ci} 4134514f5e3Sopenharmony_ci 4144514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, CollectGarbageTest002) 4154514f5e3Sopenharmony_ci{ 4164514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 4174514f5e3Sopenharmony_ci heap->SetMarkType(MarkType::MARK_FULL); 4184514f5e3Sopenharmony_ci ASSERT_EQ(heap->GetMarkType(), MarkType::MARK_FULL); 4194514f5e3Sopenharmony_ci heap->CollectGarbage(TriggerGCType::EDEN_GC, GCReason::IDLE); 4204514f5e3Sopenharmony_ci} 4214514f5e3Sopenharmony_ci 4224514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, CollectGarbageTest003) 4234514f5e3Sopenharmony_ci{ 4244514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 4254514f5e3Sopenharmony_ci heap->GetJSThread()->SetMarkStatus(MarkStatus::READY_TO_MARK); 4264514f5e3Sopenharmony_ci heap->CollectGarbage(TriggerGCType::FULL_GC, GCReason::IDLE); 4274514f5e3Sopenharmony_ci} 4284514f5e3Sopenharmony_ci 4294514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, NeedStopCollectionTest002) 4304514f5e3Sopenharmony_ci{ 4314514f5e3Sopenharmony_ci SharedHeap *heap = SharedHeap::GetInstance(); 4324514f5e3Sopenharmony_ci heap->SetSensitiveStatus(AppSensitiveStatus::ENTER_HIGH_SENSITIVE); 4334514f5e3Sopenharmony_ci ASSERT_EQ(heap->NeedStopCollection(), true); 4344514f5e3Sopenharmony_ci} 4354514f5e3Sopenharmony_ci 4364514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, NeedStopCollectionTest003) 4374514f5e3Sopenharmony_ci{ 4384514f5e3Sopenharmony_ci SharedHeap *heap = SharedHeap::GetInstance(); 4394514f5e3Sopenharmony_ci heap->SetSensitiveStatus(AppSensitiveStatus::ENTER_HIGH_SENSITIVE); 4404514f5e3Sopenharmony_ci heap->GetOldSpace()->SetInitialCapacity(1000); 4414514f5e3Sopenharmony_ci ASSERT_EQ(heap->NeedStopCollection(), false); 4424514f5e3Sopenharmony_ci} 4434514f5e3Sopenharmony_ci 4444514f5e3Sopenharmony_ciHWTEST_F_L0(GCTest, TriggerIdleCollectionTest007) 4454514f5e3Sopenharmony_ci{ 4464514f5e3Sopenharmony_ci auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap()); 4474514f5e3Sopenharmony_ci heap->SetIdleTask(IdleTaskType::INCREMENTAL_MARK); 4484514f5e3Sopenharmony_ci ASSERT_EQ(heap->GetIncrementalMarker()->GetIncrementalGCStates(), IncrementalGCStates::ROOT_SCAN); 4494514f5e3Sopenharmony_ci heap->GetIncrementalMarker()->TriggerIncrementalMark(1000); 4504514f5e3Sopenharmony_ci heap->TriggerIdleCollection(1000); 4514514f5e3Sopenharmony_ci} 4524514f5e3Sopenharmony_ci 4534514f5e3Sopenharmony_ci} // namespace panda::test 454