arkcompiler_ets_runtime/ecmascript/tests/incremental_marking_test.cpp
Aleksandr Emelenko 5a48b9b5e7 [Suspend/Resume] Added mutator scopes and native scopes in the corresponding methods of the VM.
Changed JS thread state just after creation (now it is in NATIVE state before execution of the bytecode)

Issue:#I91O3N

Change-Id: I410c5c4a47a05e6e3b79cc41374431d1e9188503
Signed-off-by: Emelenko Aleksandr 00537379 <emelenko.aleksandr@huawei.com>
2024-02-27 20:32:15 +08:00

86 lines
2.8 KiB
C++

/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecmascript/tests/test_helper.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h"
#include "ecmascript/js_handle.h"
#include "ecmascript/mem/clock_scope.h"
#include "ecmascript/mem/incremental_marker.h"
#include "ecmascript/mem/verification.h"
using namespace panda::ecmascript;
namespace panda::test {
class IncrementalMarkingTest : public testing::Test {
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "TearDownCase";
}
void SetUp() override
{
JSRuntimeOptions options;
instance = JSNApi::CreateEcmaVM(options);
ASSERT_TRUE(instance != nullptr) << "Cannot create EcmaVM";
thread = instance->GetJSThread();
thread->ManagedCodeBegin();
scope = new EcmaHandleScope(thread);
instance->SetEnableForceGC(false);
}
void TearDown() override
{
TestHelper::DestroyEcmaVMWithScope(instance, scope);
}
JSHandle<TaggedArray> CreateTaggedArray(uint32_t length, JSTaggedValue initVal, MemSpaceType spaceType)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
return factory->NewTaggedArray(length, initVal, spaceType);
}
EcmaVM *instance {nullptr};
ecmascript::EcmaHandleScope *scope {nullptr};
JSThread *thread {nullptr};
};
HWTEST_F_L0(IncrementalMarkingTest, PerformanceWithIncrementalMarking)
{
uint32_t length = 1_KB;
JSHandle<TaggedArray> rootArray =
CreateTaggedArray(length, JSTaggedValue::Undefined(), MemSpaceType::OLD_SPACE);
for (uint32_t i = 0; i < length; i++) {
auto array = CreateTaggedArray(length, JSTaggedValue::Undefined(), MemSpaceType::OLD_SPACE);
rootArray->Set(thread, i, array);
}
auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
heap->EnableNotifyIdle();
heap->SetIdleTask(IdleTaskType::INCREMENTAL_MARK); // incremental mark
for (uint32_t i = 0; i < length; i++) {
auto array = CreateTaggedArray(length, JSTaggedValue::Undefined(), MemSpaceType::OLD_SPACE);
rootArray->Set(thread, i, array);
}
heap->CollectGarbage(TriggerGCType::OLD_GC);
}
} // namespace panda::test