• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <chrono>
16 #include <thread>
17 
18 #include "ecmascript/builtins/builtins_ark_tools.h"
19 #include "ecmascript/ecma_vm.h"
20 #include "ecmascript/mem/full_gc.h"
21 #include "ecmascript/mem/idle_gc_trigger.h"
22 #include "ecmascript/object_factory-inl.h"
23 #include "ecmascript/mem/concurrent_marker.h"
24 #include "ecmascript/mem/partial_gc.h"
25 #include "ecmascript/tests/ecma_test_common.h"
26 #include "ecmascript/napi/include/jsnapi_expo.h"
27 #include "ecmascript/mem/free_object_list.h"
28 #include "ecmascript/mem/gc_stats.h"
29 #include "ecmascript/mem/free_object_set.h"
30 #include "ecmascript/mem/shared_mem_controller.h"
31 #include "ecmascript/mem/mem_controller_utils.h"
32 #include "ecmascript/mem/mem_controller.h"
33 #include "ecmascript/mem/incremental_marker.h"
34 
35 using namespace panda;
36 
37 using namespace panda::ecmascript;
38 using TRIGGER_IDLE_GC_TYPE = panda::JSNApi::TRIGGER_IDLE_GC_TYPE;
39 
40 namespace panda::test {
41 class GCTest : public BaseTestWithScope<false> {
42 public:
SetUp()43     void SetUp() override
44     {
45         JSRuntimeOptions options;
46         instance = JSNApi::CreateEcmaVM(options);
47         ASSERT_TRUE(instance != nullptr) << "Cannot create EcmaVM";
48         thread = instance->GetJSThread();
49         thread->ManagedCodeBegin();
50         scope = new EcmaHandleScope(thread);
51         auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
52         heap->GetConcurrentMarker()->EnableConcurrentMarking(EnableConcurrentMarkType::ENABLE);
53         heap->GetSweeper()->EnableConcurrentSweep(EnableConcurrentSweepType::ENABLE);
54     }
55 };
56 
HWTEST_F_L0(GCTest,NativeGCTestConcurrentMarkDisabled)57 HWTEST_F_L0(GCTest, NativeGCTestConcurrentMarkDisabled)
58 {
59     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
60     // Disable concurrent mark.
61     heap->GetConcurrentMarker()->ConfigConcurrentMark(false);
62     size_t oldNativeSize = heap->GetNativeBindingSize();
63     EcmaTestCommon::GcCommonCase(thread, heap, false);
64     const_cast<Heap *>(thread->GetEcmaVM()->GetHeap())->CollectGarbage(TriggerGCType::OLD_GC);
65     auto newNativeSize = heap->GetNativeBindingSize();
66     EXPECT_EQ(newNativeSize - oldNativeSize, 0UL);
67 }
68 
HWTEST_F_L0(GCTest,NonNewSpaceNativeGCTestConcurrentMarkDisabled)69 HWTEST_F_L0(GCTest, NonNewSpaceNativeGCTestConcurrentMarkDisabled)
70 {
71     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
72     // Disable concurrent mark.
73     heap->GetConcurrentMarker()->ConfigConcurrentMark(false);
74     size_t oldNativeSize = heap->GetNativeBindingSize();
75     EcmaTestCommon::GcCommonCase(thread, heap);
76     const_cast<Heap *>(thread->GetEcmaVM()->GetHeap())->CollectGarbage(TriggerGCType::OLD_GC);
77     auto newNativeSize = heap->GetNativeBindingSize();
78     EXPECT_EQ(newNativeSize - oldNativeSize, 0UL);
79 }
80 
HWTEST_F_L0(GCTest,ArkToolsForceFullGC)81 HWTEST_F_L0(GCTest, ArkToolsForceFullGC)
82 {
83     const_cast<Heap *>(thread->GetEcmaVM()->GetHeap())->CollectGarbage(TriggerGCType::FULL_GC);
84     size_t originalHeapSize = thread->GetEcmaVM()->GetHeap()->GetCommittedSize();
85     size_t newSize = originalHeapSize;
86     {
87         [[maybe_unused]] ecmascript::EcmaHandleScope baseScope(thread);
88 
89         for (int i = 0; i < 10; i++) {
90             [[maybe_unused]] JSHandle<TaggedArray> obj = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(1024 * 1024);
91         }
92         newSize = thread->GetEcmaVM()->GetHeap()->GetCommittedSize();
93     }
94     EXPECT_TRUE(newSize > originalHeapSize);
95     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 0);
96 
97     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
98     [[maybe_unused]] JSTaggedValue result1 = builtins::BuiltinsArkTools::ForceFullGC(ecmaRuntimeCallInfo);
99 
100     ASSERT_TRUE(thread->GetEcmaVM()->GetHeap()->GetCommittedSize() < newSize);
101 }
102 
HWTEST_F_L0(GCTest,ColdStartForceExpand)103 HWTEST_F_L0(GCTest, ColdStartForceExpand)
104 {
105     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
106     size_t originalHeapSize = heap->GetCommittedSize();
107     heap->GetConcurrentMarker()->ConfigConcurrentMark(false);
108     heap->NotifyPostFork();
109     heap->NotifyFinishColdStartSoon();
110     {
111         [[maybe_unused]] ecmascript::EcmaHandleScope baseScope(thread);
112         for (int i = 0; i < 500; i++) {
113             [[maybe_unused]] JSHandle<TaggedArray> array = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(
114                 10 * 1024, JSTaggedValue::Hole(), MemSpaceType::SEMI_SPACE);
115         }
116     }
117     size_t expandHeapSize = thread->GetEcmaVM()->GetHeap()->GetCommittedSize();
118     usleep(10000000);
119     size_t newSize = EcmaTestCommon::GcCommonCase(thread);
120     EXPECT_TRUE(originalHeapSize < expandHeapSize);
121     EXPECT_TRUE(expandHeapSize > newSize);
122 }
123 
HWTEST_F_L0(GCTest,HighSensitiveForceExpand)124 HWTEST_F_L0(GCTest, HighSensitiveForceExpand)
125 {
126     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
127     size_t originalHeapSize = heap->GetCommittedSize();
128     heap->GetConcurrentMarker()->ConfigConcurrentMark(false);
129     heap->NotifyHighSensitive(true);
130     {
131         [[maybe_unused]] ecmascript::EcmaHandleScope baseScope(thread);
132         for (int i = 0; i < 500; i++) {
133             [[maybe_unused]] JSHandle<TaggedArray> array = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(
134                 10 * 1024, JSTaggedValue::Hole(), MemSpaceType::SEMI_SPACE);
135         }
136     }
137     size_t expandHeapSize = thread->GetEcmaVM()->GetHeap()->GetCommittedSize();
138     const_cast<Heap *>(thread->GetEcmaVM()->GetHeap())->NotifyHighSensitive(false);
139     size_t newSize = EcmaTestCommon::GcCommonCase(thread);
140     EXPECT_TRUE(originalHeapSize < expandHeapSize);
141     EXPECT_TRUE(expandHeapSize > newSize);
142 }
143 
HWTEST_F_L0(GCTest,HighSensitiveExceedMaxHeapSize)144 HWTEST_F_L0(GCTest, HighSensitiveExceedMaxHeapSize)
145 {
146     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
147     heap->NotifyHighSensitive(true);
148     // First allocate about 250M TaggedArray, not reach max heap size
149     {
150         [[maybe_unused]] ecmascript::EcmaHandleScope baseScope(thread);
151         for (int i = 0; i < 16 * 1000; i++) {
152             [[maybe_unused]] JSHandle<TaggedArray> array = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(
153                 1024, JSTaggedValue::Hole(), MemSpaceType::SEMI_SPACE);
154         }
155     }
156     // Continue allocate about 250M TaggedArray, now reach max heap size, must trigger gc to avoid OOM
157     {
158         [[maybe_unused]] ecmascript::EcmaHandleScope baseScope(thread);
159         for (int i = 0; i < 10 * 1000; i++) {
160             [[maybe_unused]] JSHandle<TaggedArray> array = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(
161                 1024, JSTaggedValue::Hole(), MemSpaceType::SEMI_SPACE);
162         }
163     }
164     size_t commitSize = thread->GetEcmaVM()->GetHeap()->GetCommittedSize();
165     const_cast<Heap *>(thread->GetEcmaVM()->GetHeap())->NotifyHighSensitive(false);
166     EXPECT_TRUE(commitSize < thread->GetEcmaVM()->GetEcmaParamConfiguration().GetMaxHeapSize());
167 }
168 
HWTEST_F_L0(GCTest,ColdStartNoConcurrentMark)169 HWTEST_F_L0(GCTest, ColdStartNoConcurrentMark)
170 {
171     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
172     heap->NotifyPostFork();
173     heap->NotifyHighSensitive(true);
174     {
175         [[maybe_unused]] ecmascript::EcmaHandleScope baseScope(thread);
176         for (int i = 0; i < 500; i++) {
177             [[maybe_unused]] JSHandle<TaggedArray> array = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(
178                 10 * 1024, JSTaggedValue::Hole(), MemSpaceType::SEMI_SPACE);
179         }
180     }
181     EXPECT_FALSE(heap->HandleExitHighSensitiveEvent());
182     heap->NotifyHighSensitive(false);
183     EXPECT_FALSE(heap->HandleExitHighSensitiveEvent());
184     heap->FinishStartupEvent();
185 
186     heap->NotifyHighSensitive(true);
187     heap->NotifyHighSensitive(false);
188     EXPECT_TRUE(heap->HandleExitHighSensitiveEvent());
189 }
190 
HWTEST_F_L0(GCTest,ColdStartGCRestrainInternal)191 HWTEST_F_L0(GCTest, ColdStartGCRestrainInternal)
192 {
193     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
194     heap->NotifyPostFork();
195     heap->NotifyFinishColdStartSoon();
196     std::this_thread::sleep_for(std::chrono::seconds(3));
197     if (!heap->OnStartupEvent()) {
198         StartupStatus startupStatus = heap->GetStartupStatus();
199         EXPECT_TRUE(startupStatus == StartupStatus::JUST_FINISH_STARTUP);
200     }
201 }
202 
HWTEST_F_L0(GCTest,ColdStartGCRestrainExternal)203 HWTEST_F_L0(GCTest, ColdStartGCRestrainExternal)
204 {
205     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
206     heap->NotifyPostFork();
207     heap->NotifyFinishColdStartSoon();
208     std::this_thread::sleep_for(std::chrono::seconds(1));
209     heap->NotifyFinishColdStart(true);
210     EXPECT_FALSE(heap->OnStartupEvent());
211     StartupStatus startupStatus = heap->GetStartupStatus();
212     EXPECT_TRUE(startupStatus == StartupStatus::JUST_FINISH_STARTUP);
213 }
214 
HWTEST_F_L0(GCTest,CallbackTask)215 HWTEST_F_L0(GCTest, CallbackTask)
216 {
217     auto vm = thread->GetEcmaVM();
218     Heap *heap = const_cast<Heap *>(vm->GetHeap());
219     auto factory = vm->GetFactory();
220     {
221         [[maybe_unused]] ecmascript::EcmaHandleScope baseScope(thread);
222 
223         for (int i = 0; i < 10; i++) {
224             // NOLINTNEXTLINE(cppcoreguidelines-no-malloc)
225             void *externalPointer = malloc(10);
226             [[maybe_unused]] JSHandle<JSNativePointer> nativePointer = factory->NewJSNativePointer(
227                 externalPointer, []([[maybe_unused]] void *env, void* pointer, [[maybe_unused]] void* data) {
228                 if (pointer != nullptr) {
229                     free(pointer);
230                 }
231             },
232             nullptr, false, 10, Concurrent::YES);
233         }
234     }
235     size_t number = heap->concurrentNativePointerList_.size();
236     EXPECT_TRUE(number > 0);
237     heap->CollectGarbage(TriggerGCType::OLD_GC);
238     size_t newNumber = heap->concurrentNativePointerList_.size();
239     EXPECT_TRUE(number > newNumber);
240 }
241 
HWTEST_F_L0(GCTest,RecomputeLimitsTest)242 HWTEST_F_L0(GCTest, RecomputeLimitsTest)
243 {
244     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
245     auto oldCapacity = heap->GetOldSpace()->GetInitialCapacity();
246     heap->CollectGarbage(TriggerGCType::FULL_GC);
247     EXPECT_FALSE(heap->IsConcurrentFullMark());
248     EXPECT_FALSE(heap->IsFullMarkRequested());
249     auto newCapacity = heap->GetOldSpace()->GetInitialCapacity();
250     EXPECT_NE(newCapacity, oldCapacity);
251     double gcSpeed = heap->GetMemController()->CalculateMarkCompactSpeedPerMS();
252     double mutatorSpeed = heap->GetMemController()->GetCurrentOldSpaceAllocationThroughputPerMS();
253     size_t oldSpaceSize = heap->GetOldSpace()->GetHeapObjectSize() + heap->GetHugeObjectSpace()->GetHeapObjectSize() +
254         heap->GetHugeMachineCodeSpace()->GetHeapObjectSize();
255     size_t newSpaceCapacity = heap->GetNewSpace()->GetInitialCapacity();
256     double growingFactor =  heap->GetMemController()->CalculateGrowingFactor(gcSpeed, mutatorSpeed);
257     size_t maxOldSpaceCapacity = heap->GetOldSpace()->GetMaximumCapacity() - newSpaceCapacity;
258     auto newOldSpaceLimit = heap->GetMemController()->CalculateAllocLimit(oldSpaceSize, MIN_OLD_SPACE_LIMIT,
259         maxOldSpaceCapacity, newSpaceCapacity, growingFactor);
260     EXPECT_EQ(newCapacity, newOldSpaceLimit);
261 }
262 
HWTEST_F_L0(GCTest,GlobalNativeSizeLargerThanLimitTest)263 HWTEST_F_L0(GCTest, GlobalNativeSizeLargerThanLimitTest)
264 {
265     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
266     auto ret = heap->GlobalNativeSizeLargerThanLimit();
267     EXPECT_FALSE(ret);
268     heap->GetNativeAreaAllocator()->IncreaseNativeMemoryUsage(300*1000*1000);
269     ret = heap->GlobalNativeSizeLargerThanLimit();
270     EXPECT_TRUE(ret);
271 }
272 #ifdef NDEBUG
HWTEST_F_L0(GCTest,IdleGCTriggerTest)273 HWTEST_F_L0(GCTest, IdleGCTriggerTest)
274 {
275     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
276     auto idleGCTrigger = heap->GetIdleGCTrigger();
277     auto sHeap = SharedHeap::GetInstance();
278     heap->CollectGarbage(TriggerGCType::FULL_GC);
279     int baseLocalGCCount = heap->GetEcmaGCStats()->GetGCCount();
280     int baseSharedGCCount = sHeap->GetEcmaGCStats()->GetGCCount();
281     heap->GetConcurrentMarker()->ConfigConcurrentMark(false);
282     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
283     // Apply for some memory that cannot be released to simulate the actual situation
284     for (int i = 0; i < 5120; i++) {
285         factory->NewTaggedArray(1024, JSTaggedValue::Hole(), MemSpaceType::OLD_SPACE);
286         factory->NewSOldSpaceTaggedArray(1024, JSTaggedValue::Hole());
287     }
288     for (size_t i = 0; i < 10240; i++)
289     {
290         factory->NewTaggedArray(512, JSTaggedValue::Hole(), MemSpaceType::OLD_SPACE);
291         factory->NewSOldSpaceTaggedArray(512, JSTaggedValue::Hole());
292         [[maybe_unused]] ecmascript::EcmaHandleScope baseScope(thread);
293         [[maybe_unused]] JSHandle<TaggedArray> array = factory->NewTaggedArray(1024, JSTaggedValue::Hole(),
294                     MemSpaceType::OLD_SPACE);
295         [[maybe_unused]] JSHandle<TaggedArray> sArray = factory->NewSOldSpaceTaggedArray(1024,
296                     JSTaggedValue::Hole());
297         if (i%340 == 0) {
298             idleGCTrigger->NotifyVsyncIdleStart();
299         }
300     }
301     idleGCTrigger->TryTriggerIdleGC(TRIGGER_IDLE_GC_TYPE::FULL_GC);
302     idleGCTrigger->TryTriggerIdleGC(TRIGGER_IDLE_GC_TYPE::SHARED_FULL_GC);
303     int afterLocalGCCount = heap->GetEcmaGCStats()->GetGCCount();
304     int afterSharedGCCount = sHeap->GetEcmaGCStats()->GetGCCount();
305     EXPECT_TRUE(afterLocalGCCount - baseLocalGCCount < 10);
306     EXPECT_TRUE(afterSharedGCCount - baseSharedGCCount < 10);
307     heap->CollectGarbage(TriggerGCType::FULL_GC);
308 }
309 #endif  // #ifndef NDEBUG
310 
HWTEST_F_L0(GCTest,AdjustCapacity)311 HWTEST_F_L0(GCTest, AdjustCapacity)
312 {
313 #if defined(PANDA_TARGET_ARM64)
314     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
315     SemiSpace * space = heap->GetNewSpace();
316 
317     EXPECT_EQ(space->GetSurvivalObjectSize(), 0);
318     {
319         [[maybe_unused]] ecmascript::EcmaHandleScope baseScope(thread);
320         for (int i = 0; i < 300; i++) {
321             [[maybe_unused]] JSHandle<TaggedArray> array = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(
322                 10 * 1024, JSTaggedValue::Hole(), MemSpaceType::SEMI_SPACE);
323         }
324     }
325     EXPECT_GT(space->GetSurvivalObjectSize(), 0);
326 
327     EXPECT_FALSE(space->AdjustCapacity(0, thread));
328     size_t size = space->GetInitialCapacity() * GROW_OBJECT_SURVIVAL_RATE / 2;
329     EXPECT_FALSE(space->AdjustCapacity(size, thread));
330 
331     space->SetInitialCapacity(space->GetSurvivalObjectSize() / GROW_OBJECT_SURVIVAL_RATE - 1);
332     size = space->GetSurvivalObjectSize() / GROW_OBJECT_SURVIVAL_RATE - 1;
333     size_t oldMaxCapacity = space->GetMaximumCapacity();
334     space->SetMaximumCapacity(space->GetInitialCapacity());
335     EXPECT_TRUE(space->AdjustCapacity(size, thread));
336     space->SetMaximumCapacity(oldMaxCapacity);
337     EXPECT_TRUE(space->AdjustCapacity(size, thread));
338 #endif
339 }
340 
HWTEST_F_L0(GCTest,NativeMemAllocInSensitive)341 HWTEST_F_L0(GCTest, NativeMemAllocInSensitive)
342 {
343     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
344     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
345     heap->NotifyHighSensitive(true);
346     for (size_t i = 0; i < 20; i++) {
347         [[maybe_unused]] ecmascript::EcmaHandleScope baseScope(thread);
348         factory->NewJSArrayBuffer(300 * 1024 * 1024); // 300MB
349     }
350     EXPECT_TRUE(heap->GetGlobalNativeSize() < 1 * 1024 * 1024* 1024); // 1GB
351 }
352 
HWTEST_F_L0(GCTest,RecordAllocationForIdleTest001)353 HWTEST_F_L0(GCTest, RecordAllocationForIdleTest001)
354 {
355     SharedHeap *heap = SharedHeap::GetInstance();
356     SharedMemController *controller = new SharedMemController(heap);
357     controller->RecordAllocationForIdle();
358     controller->RecordAllocationForIdle();
359 }
360 
HWTEST_F_L0(GCTest,RecordAllocationForIdleTest002)361 HWTEST_F_L0(GCTest, RecordAllocationForIdleTest002)
362 {
363     SharedHeap *heap = SharedHeap::GetInstance();
364     SharedMemController *controller = new SharedMemController(heap);
365     controller->RecordAllocationForIdle();
366     size_t before = heap->GetHeapObjectSize();
367     heap->ReclaimForAppSpawn();
368     size_t after = heap->GetHeapObjectSize();
369     ASSERT_NE(before, after);
370     controller->RecordAllocationForIdle();
371 }
372 
HWTEST_F_L0(GCTest,PrintGCStatisticTest001)373 HWTEST_F_L0(GCTest, PrintGCStatisticTest001)
374 {
375     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
376     int prop = 1 << 15;
377     heap->GetEcmaVM()->GetJSOptions().SetArkProperties(prop);
378     ASSERT_EQ(heap->GetEcmaVM()->GetJSOptions().EnableGCTracer(), true);
379     GCStats *stats = new GCStats(heap);
380     stats->PrintGCStatistic();
381 
382     prop = 1 << 14;
383     heap->GetEcmaVM()->GetJSOptions().SetArkProperties(prop);
384     ASSERT_EQ(heap->GetEcmaVM()->GetJSOptions().EnableGCTracer(), false);
385     stats->PrintGCStatistic();
386 }
387 
HWTEST_F_L0(GCTest,GCReasonToStringTest001)388 HWTEST_F_L0(GCTest, GCReasonToStringTest001)
389 {
390     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
391     GCStats *stats = new GCStats(heap);
392     ASSERT_EQ(strcmp(stats->GCReasonToString(GCReason::SWITCH_BACKGROUND), "Switch to background"), 0);
393     ASSERT_EQ(strcmp(stats->GCReasonToString(GCReason::EXTERNAL_TRIGGER), "Externally triggered"), 0);
394     ASSERT_EQ(strcmp(stats->GCReasonToString(GCReason::WORKER_DESTRUCTION), "Worker Destruction"), 0);
395     ASSERT_EQ(strcmp(stats->GCReasonToString(GCReason::TRIGGER_BY_ARKUI), "Trigger by ArkUI"), 0);
396     ASSERT_EQ(strcmp(stats->GCReasonToString(GCReason::TRIGGER_BY_ABILITY), "Trigger by AbilityRuntime"), 0);
397     ASSERT_EQ(strcmp(stats->GCReasonToString(GCReason::TRIGGER_BY_MEM_TOOLS), "Trigger by Mem tools"), 0);
398     ASSERT_EQ(strcmp(stats->GCReasonToString(GCReason::TRIGGER_BY_TASKPOOL), "Trigger by taskPool"), 0);
399 }
400 
HWTEST_F_L0(GCTest,PrintGCMemoryStatisticTest002)401 HWTEST_F_L0(GCTest, PrintGCMemoryStatisticTest002)
402 {
403     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
404     heap->SetMarkType(MarkType::MARK_YOUNG);
405     GCStats *stats = new GCStats(heap);
406     stats->RecordStatisticBeforeGC(TriggerGCType::YOUNG_GC, GCReason::TRIGGER_BY_ARKUI);
407     stats->PrintGCMemoryStatistic();
408 }
409 
HWTEST_F_L0(GCTest,CheckIfNeedPrintTest001)410 HWTEST_F_L0(GCTest, CheckIfNeedPrintTest001)
411 {
412     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
413     heap->SetMarkType(MarkType::MARK_YOUNG);
414     GCStats *stats = new GCStats(heap);
415     stats->SetRecordData(RecordData::YOUNG_COUNT, 1);
416     stats->PrintStatisticResult();
417 }
418 
HWTEST_F_L0(GCTest,PrintGCSummaryStatisticTest001)419 HWTEST_F_L0(GCTest, PrintGCSummaryStatisticTest001)
420 {
421     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
422     heap->SetMarkType(MarkType::MARK_YOUNG);
423     GCStats *stats = new GCStats(heap);
424     stats->PrintStatisticResult();
425 }
426 
HWTEST_F_L0(GCTest,CalculateGrowingFactorTest001)427 HWTEST_F_L0(GCTest, CalculateGrowingFactorTest001)
428 {
429     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
430     heap->SetMemGrowingType(MemGrowingType::CONSERVATIVE);
431     auto controller = new MemController(heap);
432     controller->CalculateGrowingFactor(1, 1);
433 }
434 
HWTEST_F_L0(GCTest,CalculateGrowingFactorTest002)435 HWTEST_F_L0(GCTest, CalculateGrowingFactorTest002)
436 {
437     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
438     heap->SetMemGrowingType(MemGrowingType::PRESSURE);
439     auto controller = new MemController(heap);
440     controller->CalculateGrowingFactor(1, 1);
441 }
442 
HWTEST_F_L0(GCTest,CalculateGrowingFactorTest003)443 HWTEST_F_L0(GCTest, CalculateGrowingFactorTest003)
444 {
445     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
446     heap->SetMemGrowingType(MemGrowingType::CONSERVATIVE);
447     auto controller = new MemController(heap);
448     controller->CalculateGrowingFactor(1, 0);
449 }
450 
HWTEST_F_L0(GCTest,StopCalculationAfterGCTest001)451 HWTEST_F_L0(GCTest, StopCalculationAfterGCTest001)
452 {
453     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
454     auto controller = new MemController(heap);
455     std::this_thread::sleep_for(std::chrono::milliseconds(10));
456     controller->StartCalculationBeforeGC();
457     controller->StopCalculationAfterGC(TriggerGCType::YOUNG_GC);
458 }
459 
HWTEST_F_L0(GCTest,RecordAllocationForIdleTest003)460 HWTEST_F_L0(GCTest, RecordAllocationForIdleTest003)
461 {
462     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
463     auto controller = new MemController(heap);
464     controller->RecordAllocationForIdle();
465 }
466 
HWTEST_F_L0(GCTest,TryTriggerIdleCollectionTest001)467 HWTEST_F_L0(GCTest, TryTriggerIdleCollectionTest001)
468 {
469     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
470     heap->SetIdleTask(IdleTaskType::YOUNG_GC);
471     heap->TryTriggerIdleCollection();
472 }
473 
HWTEST_F_L0(GCTest,WaitAllTasksFinishedTest001)474 HWTEST_F_L0(GCTest, WaitAllTasksFinishedTest001)
475 {
476     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
477     heap->GetJSThread()->SetMarkStatus(MarkStatus::MARKING);
478     heap->WaitAllTasksFinished();
479 }
480 
HWTEST_F_L0(GCTest,WaitAllTasksFinishedTest002)481 HWTEST_F_L0(GCTest, WaitAllTasksFinishedTest002)
482 {
483     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
484     heap->GetJSThread()->SetMarkStatus(MarkStatus::MARKING);
485     heap->GetConcurrentMarker()->Mark();
486     heap->WaitAllTasksFinished();
487 }
488 
HWTEST_F_L0(GCTest,ChangeGCParamsTest001)489 HWTEST_F_L0(GCTest, ChangeGCParamsTest001)
490 {
491     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
492     heap->GetOldSpace()->IncreaseLiveObjectSize(2098000);
493     heap->ChangeGCParams(true);
494 }
495 
HWTEST_F_L0(GCTest,ChangeGCParamsTest002)496 HWTEST_F_L0(GCTest, ChangeGCParamsTest002)
497 {
498     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
499     heap->GetOldSpace()->IncreaseLiveObjectSize(2098000);
500     heap->GetOldSpace()->IncreaseCommitted(31457300);
501     heap->ChangeGCParams(true);
502 }
503 
HWTEST_F_L0(GCTest,ChangeGCParamsTest003)504 HWTEST_F_L0(GCTest, ChangeGCParamsTest003)
505 {
506     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
507     auto sHeap = SharedHeap::GetInstance();
508     sHeap->GetOldSpace()->IncreaseLiveObjectSize(2098000);
509     heap->ChangeGCParams(true);
510 }
511 
HWTEST_F_L0(GCTest,ChangeGCParamsTest004)512 HWTEST_F_L0(GCTest, ChangeGCParamsTest004)
513 {
514     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
515     heap->SetMemGrowingType(MemGrowingType::HIGH_THROUGHPUT);
516     heap->ChangeGCParams(true);
517 }
518 
HWTEST_F_L0(GCTest,IncrementMarkerTest001)519 HWTEST_F_L0(GCTest, IncrementMarkerTest001)
520 {
521     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
522     heap->GetIncrementalMarker()->TriggerIncrementalMark(100);
523     heap->GetIncrementalMarker()->TriggerIncrementalMark(100);
524 }
525 
HWTEST_F_L0(GCTest,IncrementMarkerTest002)526 HWTEST_F_L0(GCTest, IncrementMarkerTest002)
527 {
528     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
529     heap->GetIncrementalMarker()->TriggerIncrementalMark(0);
530 }
531 
HWTEST_F_L0(GCTest,IncrementMarkerTest003)532 HWTEST_F_L0(GCTest, IncrementMarkerTest003)
533 {
534     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
535     heap->GetIncrementalMarker()->SetMarkingFinished(true);
536     heap->GetIncrementalMarker()->TriggerIncrementalMark(100);
537 }
538 
HWTEST_F_L0(GCTest,IncrementMarkerTest004)539 HWTEST_F_L0(GCTest, IncrementMarkerTest004)
540 {
541     thread->GetEcmaVM()->GetJSOptions().SetArkProperties(0);
542     auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
543     heap->GetIncrementalMarker()->SetMarkingFinished(true);
544     heap->GetIncrementalMarker()->TriggerIncrementalMark(100);
545 }
546 
547 } // namespace panda::test
548