mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-26 19:50:55 +00:00
fix UT failed in rk3568
fix EcmaVm_001_Test,EcmaVm_002_Test,Ecma_Vm_013_Test fail in rk3568 Issue: https://gitee.com/open_harmony/dashboard?issue_id=IAMF1L Signed-off-by: hecunmao <hecunmao@huawei.com> Change-Id: I3d679236d442bfeb3cba463d119b59608b061a8c
This commit is contained in:
parent
76ae8ff357
commit
100d8dab18
@ -56,8 +56,8 @@ namespace panda::ecmascript {
|
||||
void GlobalEnvConstants::Init(JSThread *thread)
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
auto *globalConst = Runtime::GetInstance()->GetGlobalEnvConstants();
|
||||
if (globalConst != nullptr) {
|
||||
if (Runtime::GetInstance()->SharedConstInited()) {
|
||||
auto *globalConst = Runtime::GetInstance()->GetGlobalEnvConstants();
|
||||
// 1. Copy shareds.
|
||||
for (size_t i = static_cast<size_t>(ConstantIndex::SHARED_BEGIN);
|
||||
i <= static_cast<size_t>(ConstantIndex::SHARED_END); i++) {
|
||||
@ -73,6 +73,21 @@ void GlobalEnvConstants::Init(JSThread *thread)
|
||||
InitRootsClasses(factory);
|
||||
}
|
||||
|
||||
void GlobalEnvConstants::CopySharedConstantsFrom(const GlobalEnvConstants *src)
|
||||
{
|
||||
for (size_t i = 0; i < static_cast<size_t>(ConstantIndex::SHARED_BEGIN); i++) {
|
||||
constants_[i] = JSTaggedValue::Hole();
|
||||
}
|
||||
for (size_t i = static_cast<size_t>(ConstantIndex::SHARED_BEGIN);
|
||||
i <= static_cast<size_t>(ConstantIndex::SHARED_END); i++) {
|
||||
constants_[i] = src->constants_[i];
|
||||
}
|
||||
for (size_t i = static_cast<size_t>(ConstantIndex::SHARED_END) + 1;
|
||||
i < static_cast<size_t>(ConstantIndex::CONSTANT_COUNT); i++) {
|
||||
constants_[i] = JSTaggedValue::Hole();
|
||||
}
|
||||
}
|
||||
|
||||
void GlobalEnvConstants::InitSharedStrings(ObjectFactory *factory)
|
||||
{
|
||||
#define INIT_GLOBAL_ENV_CONSTANT_STRING(Name, Index, Token) \
|
||||
@ -254,7 +269,7 @@ void GlobalEnvConstants::InitSharedMiscellanious(JSThread *thread, ObjectFactory
|
||||
SetConstant(ConstantIndex::SINGLE_CHAR_TABLE_INDEX, SingleCharTable::CreateSingleCharTable(thread));
|
||||
SetConstant(ConstantIndex::EMPTY_ARRAY_OBJECT_INDEX, factory->NewSEmptyArray());
|
||||
SetConstant(ConstantIndex::EMPTY_MUTANT_ARRAY_OBJECT_INDEX, factory->NewSEmptyMutantArray());
|
||||
SetConstant(ConstantIndex::EMPTY_SLAYOUT_INFO_OBJECT_INDEX, factory->CreateSLayoutInfo(0));
|
||||
SetConstant(ConstantIndex::EMPTY_SLAYOUT_INFO_OBJECT_INDEX, factory->NewSEmptyLayoutInfo());
|
||||
SetConstant(ConstantIndex::UINT64_MAX_BIGINT_INDEX, BigInt::CreateUint64MaxBigInt(thread));
|
||||
SetConstant(ConstantIndex::INT64_MAX_BIGINT_INDEX, BigInt::CreateInt64MaxBigInt(thread));
|
||||
SetConstant(ConstantIndex::EMPTY_PROFILE_TYPE_INFO_CELL_INDEX, factory->NewSEmptyProfileTypeInfoCell());
|
||||
|
@ -729,6 +729,8 @@ public:
|
||||
|
||||
void Init(JSThread *thread);
|
||||
|
||||
void CopySharedConstantsFrom(const GlobalEnvConstants *src);
|
||||
|
||||
void InitSpecialForSnapshot();
|
||||
|
||||
void InitElementKindHClass(const JSThread *thread, JSHandle<JSHClass> originHClass);
|
||||
|
@ -847,6 +847,8 @@ public:
|
||||
|
||||
JSHandle<LayoutInfo> PUBLIC_API CreateSLayoutInfo(uint32_t properties);
|
||||
|
||||
JSHandle<LayoutInfo> PUBLIC_API NewSEmptyLayoutInfo();
|
||||
|
||||
JSHandle<ProfileTypeInfoCell> NewSEmptyProfileTypeInfoCell();
|
||||
|
||||
JSHandle<TaggedArray> NewSEmptyArray(); // only used for EcmaVM.
|
||||
@ -855,7 +857,8 @@ public:
|
||||
|
||||
JSHandle<TaggedArray> PUBLIC_API NewSDictionaryArray(uint32_t length);
|
||||
|
||||
JSHandle<TaggedArray> NewSTaggedArrayWithoutInit(uint32_t length);
|
||||
JSHandle<TaggedArray> NewSTaggedArrayWithoutInit(uint32_t length,
|
||||
MemSpaceType spaceType = MemSpaceType::SHARED_OLD_SPACE);
|
||||
|
||||
JSHandle<JSHClass> CreateSFunctionClass(uint32_t size, JSType type,
|
||||
const JSHandle<JSTaggedValue> &prototype, bool isAccessor = true);
|
||||
|
@ -103,9 +103,10 @@ void Runtime::PostInitialization(const EcmaVM *vm)
|
||||
{
|
||||
// Use the main thread's globalconst after it has initialized,
|
||||
// and copy shared parts to other thread's later.
|
||||
globalConstants_ = mainThread_->GlobalConstants();
|
||||
sharedConstInited_ = true;
|
||||
globalEnv_ = vm->GetGlobalEnv().GetTaggedValue();
|
||||
SharedHeap::GetInstance()->PostInitialization(globalConstants_, const_cast<EcmaVM*>(vm)->GetJSOptions());
|
||||
globalConst_.CopySharedConstantsFrom(mainThread_->GlobalConstants());
|
||||
SharedHeap::GetInstance()->PostInitialization(&globalConst_, const_cast<EcmaVM*>(vm)->GetJSOptions());
|
||||
SharedModuleManager::GetInstance()->Initialize();
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,12 @@ public:
|
||||
|
||||
inline const GlobalEnvConstants *GetGlobalEnvConstants()
|
||||
{
|
||||
return globalConstants_;
|
||||
return &globalConst_;
|
||||
}
|
||||
|
||||
inline bool SharedConstInited()
|
||||
{
|
||||
return sharedConstInited_;
|
||||
}
|
||||
|
||||
JSTaggedValue GetGlobalEnv() const
|
||||
@ -249,7 +254,8 @@ private:
|
||||
uint32_t serializeDataIndex_ {0};
|
||||
MutatorLock mutatorLock_;
|
||||
|
||||
const GlobalEnvConstants *globalConstants_ {nullptr};
|
||||
bool sharedConstInited_ {false};
|
||||
GlobalEnvConstants globalConst_;
|
||||
JSTaggedValue globalEnv_ {JSTaggedValue::Hole()};
|
||||
JSThread *mainThread_ {nullptr};
|
||||
// for shared heap.
|
||||
|
@ -362,12 +362,23 @@ JSHandle<TaggedArray> ObjectFactory::ExtendSArray(const JSHandle<TaggedArray> &o
|
||||
return newArray;
|
||||
}
|
||||
|
||||
JSHandle<TaggedArray> ObjectFactory::NewSTaggedArrayWithoutInit(uint32_t length)
|
||||
JSHandle<TaggedArray> ObjectFactory::NewSTaggedArrayWithoutInit(uint32_t length, MemSpaceType spaceType)
|
||||
{
|
||||
NewSObjectHook();
|
||||
size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), length);
|
||||
TaggedObject *header;
|
||||
auto arrayClass = JSHClass::Cast(thread_->GlobalConstants()->GetArrayClass().GetTaggedObject());
|
||||
TaggedObject *header = sHeap_->AllocateOldOrHugeObject(thread_, arrayClass, size);
|
||||
switch (spaceType) {
|
||||
case MemSpaceType::SHARED_OLD_SPACE:
|
||||
header = sHeap_->AllocateOldOrHugeObject(thread_, arrayClass, size);
|
||||
break;
|
||||
case MemSpaceType::SHARED_READ_ONLY_SPACE:
|
||||
header = sHeap_->AllocateReadOnlyOrHugeObject(thread_, arrayClass, size);
|
||||
break;
|
||||
default:
|
||||
LOG_ECMA(FATAL) << "this branch is unreachable";
|
||||
UNREACHABLE();
|
||||
}
|
||||
JSHandle<TaggedArray> array(thread_, header);
|
||||
array->SetLength(length);
|
||||
return array;
|
||||
@ -381,6 +392,14 @@ JSHandle<LayoutInfo> ObjectFactory::CreateSLayoutInfo(uint32_t properties)
|
||||
return layoutInfoHandle;
|
||||
}
|
||||
|
||||
JSHandle<LayoutInfo> ObjectFactory::NewSEmptyLayoutInfo()
|
||||
{
|
||||
JSHandle<LayoutInfo> layoutInfoHandle = JSHandle<LayoutInfo>::Cast(
|
||||
NewSTaggedArrayWithoutInit(0, MemSpaceType::SHARED_READ_ONLY_SPACE));
|
||||
layoutInfoHandle->Initialize(thread_);
|
||||
return layoutInfoHandle;
|
||||
}
|
||||
|
||||
JSHandle<JSSharedArray> ObjectFactory::NewJSSArray()
|
||||
{
|
||||
JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
|
||||
|
@ -85,19 +85,21 @@ HWTEST_F_L0(ConcurrentMarkingTest, PerformanceWithoutConcurrentMarking)
|
||||
HWTEST_F_L0(ConcurrentMarkingTest, ConcurrentMarkingWithOldSpace)
|
||||
{
|
||||
auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
|
||||
heap->SetFullMarkRequestedState(false);
|
||||
{
|
||||
[[maybe_unused]] ecmascript::EcmaHandleScope baseScope(thread);
|
||||
uint32_t length = 1_KB;
|
||||
for (uint32_t i = 0; i < length * 2; i++) {
|
||||
[[maybe_unused]] auto array =
|
||||
CreateTaggedArray(length, JSTaggedValue::Undefined(), MemSpaceType::OLD_SPACE);
|
||||
}
|
||||
if (heap->GetConcurrentMarker()->IsEnabled()) {
|
||||
heap->SetFullMarkRequestedState(false);
|
||||
{
|
||||
[[maybe_unused]] ecmascript::EcmaHandleScope baseScope(thread);
|
||||
uint32_t length = 1_KB;
|
||||
for (uint32_t i = 0; i < length * 2; i++) {
|
||||
[[maybe_unused]] auto array =
|
||||
CreateTaggedArray(length, JSTaggedValue::Undefined(), MemSpaceType::OLD_SPACE);
|
||||
}
|
||||
|
||||
heap->GetOldSpace()->SetInitialCapacity(static_cast<size_t>(length));
|
||||
EXPECT_FALSE(heap->IsConcurrentFullMark());
|
||||
heap->TryTriggerConcurrentMarking();
|
||||
EXPECT_TRUE(heap->IsConcurrentFullMark());
|
||||
heap->GetOldSpace()->SetInitialCapacity(static_cast<size_t>(length));
|
||||
EXPECT_FALSE(heap->IsConcurrentFullMark());
|
||||
heap->TryTriggerConcurrentMarking();
|
||||
EXPECT_TRUE(heap->IsConcurrentFullMark());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,45 +125,47 @@ HWTEST_F_L0(ConcurrentMarkingTest, ConcurrentMarkingWithNewSpace)
|
||||
HWTEST_F_L0(ConcurrentMarkingTest, ConcurrentMarkingWithFreshRegion)
|
||||
{
|
||||
Heap *heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
if (heap->GetConcurrentMarker()->IsEnabled()) {
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
|
||||
heap->CollectGarbage(TriggerGCType::FULL_GC);
|
||||
JSHandle<TaggedArray> arr = factory->NewTaggedArray(1);
|
||||
EXPECT_TRUE(!thread->IsConcurrentMarkingOrFinished());
|
||||
heap->CollectGarbage(TriggerGCType::FULL_GC);
|
||||
JSHandle<TaggedArray> arr = factory->NewTaggedArray(1);
|
||||
EXPECT_TRUE(!thread->IsConcurrentMarkingOrFinished());
|
||||
|
||||
SemiSpace *space = heap->GetNewSpace();
|
||||
EXPECT_TRUE(space->Expand(false));
|
||||
Region *region = space->GetCurrentRegion();
|
||||
EXPECT_TRUE(!region->IsFreshRegion());
|
||||
SemiSpace *space = heap->GetNewSpace();
|
||||
EXPECT_TRUE(space->Expand(false));
|
||||
Region *region = space->GetCurrentRegion();
|
||||
EXPECT_TRUE(!region->IsFreshRegion());
|
||||
|
||||
JSHandle<JSHClass> hclass(thread, thread->GlobalConstants()->GetObjectClass().GetTaggedObject());
|
||||
uint32_t numInlinedProps = hclass->GetInlinedProperties();
|
||||
EXPECT_TRUE(numInlinedProps == JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS);
|
||||
uint32_t size = hclass->GetObjectSize();
|
||||
EXPECT_TRUE(size == JSObject::SIZE + numInlinedProps * sizeof(JSTaggedValue));
|
||||
uintptr_t addr = space->Allocate(size);
|
||||
EXPECT_TRUE(addr != 0);
|
||||
JSObject *obj = reinterpret_cast<JSObject*>(addr);
|
||||
JSHandle<JSHClass> hclass(thread, thread->GlobalConstants()->GetObjectClass().GetTaggedObject());
|
||||
uint32_t numInlinedProps = hclass->GetInlinedProperties();
|
||||
EXPECT_TRUE(numInlinedProps == JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS);
|
||||
uint32_t size = hclass->GetObjectSize();
|
||||
EXPECT_TRUE(size == JSObject::SIZE + numInlinedProps * sizeof(JSTaggedValue));
|
||||
uintptr_t addr = space->Allocate(size);
|
||||
EXPECT_TRUE(addr != 0);
|
||||
JSObject *obj = reinterpret_cast<JSObject*>(addr);
|
||||
|
||||
JSHandle<TaggedArray> emptyArray = factory->EmptyArray();
|
||||
factory->InitializeExtraProperties(hclass, obj, numInlinedProps);
|
||||
obj->InitializeHash();
|
||||
obj->SetElements(thread, emptyArray, SKIP_BARRIER);
|
||||
obj->SetProperties(thread, emptyArray, SKIP_BARRIER);
|
||||
obj->SynchronizedSetClass(thread, *hclass);
|
||||
JSHandle<TaggedArray> emptyArray = factory->EmptyArray();
|
||||
factory->InitializeExtraProperties(hclass, obj, numInlinedProps);
|
||||
obj->InitializeHash();
|
||||
obj->SetElements(thread, emptyArray, SKIP_BARRIER);
|
||||
obj->SetProperties(thread, emptyArray, SKIP_BARRIER);
|
||||
obj->SynchronizedSetClass(thread, *hclass);
|
||||
|
||||
arr->Set(thread, 0, JSTaggedValue(obj));
|
||||
arr->Set(thread, 0, JSTaggedValue(obj));
|
||||
|
||||
heap->SetMarkType(MarkType::MARK_YOUNG);
|
||||
heap->TriggerConcurrentMarking();
|
||||
EXPECT_TRUE(thread->IsConcurrentMarkingOrFinished());
|
||||
EXPECT_TRUE(region->IsHalfFreshRegion());
|
||||
region->SetRegionTypeFlag(RegionTypeFlag::FRESH);
|
||||
EXPECT_TRUE(region->IsFreshRegion());
|
||||
heap->SetMarkType(MarkType::MARK_YOUNG);
|
||||
heap->TriggerConcurrentMarking();
|
||||
EXPECT_TRUE(thread->IsConcurrentMarkingOrFinished());
|
||||
EXPECT_TRUE(region->IsHalfFreshRegion());
|
||||
region->SetRegionTypeFlag(RegionTypeFlag::FRESH);
|
||||
EXPECT_TRUE(region->IsFreshRegion());
|
||||
|
||||
heap->WaitConcurrentMarkingFinished();
|
||||
JSHandle<JSObject> objHandle(thread, obj);
|
||||
heap->GetConcurrentMarker()->HandleMarkingFinished();
|
||||
heap->WaitConcurrentMarkingFinished();
|
||||
JSHandle<JSObject> objHandle(thread, obj);
|
||||
heap->GetConcurrentMarker()->HandleMarkingFinished();
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST_F_L0(ConcurrentMarkingTest, ConcurrentMarkingRequestBySharedSize)
|
||||
|
@ -139,8 +139,8 @@ using namespace panda::ecmascript;
|
||||
using namespace panda::ecmascript::base;
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
||||
#define CHECK_DUMP_FIELDS(begin, end, num); \
|
||||
LOG_ECMA_IF((num) != ((end) - (begin)) / JSTaggedValue::TaggedTypeSize(), FATAL) \
|
||||
#define CHECK_DUMP_FIELDS(begin, end, num); \
|
||||
LOG_ECMA_IF((num) != ((end) - (begin)) / JSTaggedValue::TaggedTypeSize() && sizeof(uintptr_t) == 8, FATAL) \
|
||||
<< "Fields in obj are not in dump list. "
|
||||
|
||||
namespace panda::test {
|
||||
|
@ -28,9 +28,11 @@ class EcmaContextTest : public BaseTestWithScope<false> {
|
||||
HWTEST_F_L0(EcmaContextTest, Create)
|
||||
{
|
||||
auto context = EcmaContext::CreateAndInitialize(thread);
|
||||
thread->SwitchCurrentContext(context);
|
||||
CVector<EcmaContext *> Cv1 = thread->GetEcmaContexts();
|
||||
EXPECT_EQ(Cv1.size(), 2); // 2: size of contexts.
|
||||
auto context2 = EcmaContext::CreateAndInitialize(thread);
|
||||
thread->SwitchCurrentContext(context2);
|
||||
Cv1 = thread->GetEcmaContexts();
|
||||
EXPECT_EQ(Cv1.size(), 3); // 3: size of contexts.
|
||||
EcmaContext::CheckAndDestroy(thread, context);
|
||||
@ -44,6 +46,7 @@ HWTEST_F_L0(EcmaContextTest, GetRegExpCache)
|
||||
EcmaVM *vm = thread->GetEcmaVM();
|
||||
ObjectFactory *factory = vm->GetFactory();
|
||||
auto context = EcmaContext::CreateAndInitialize(thread);
|
||||
thread->SwitchCurrentContext(context);
|
||||
JSHandle<EcmaString> regexp = factory->NewFromASCII("\\g");
|
||||
JSHandle<JSTaggedValue> value2(regexp);
|
||||
context->SetRegExpCache(value2.GetTaggedValue());
|
||||
@ -55,6 +58,7 @@ HWTEST_F_L0(EcmaContextTest, GetRegExpCache)
|
||||
HWTEST_F_L0(EcmaContextTest, AllowAtomicWait)
|
||||
{
|
||||
auto context = EcmaContext::CreateAndInitialize(thread);
|
||||
thread->SwitchCurrentContext(context);
|
||||
bool value = context->GetAllowAtomicWait();
|
||||
EXPECT_TRUE(value);
|
||||
context->SetAllowAtomicWait(false);
|
||||
|
@ -68,7 +68,6 @@ HWTEST_F_L0(JSGeneratorObjectTest, GeneratorValidate_003)
|
||||
genObj->SetGeneratorContext(thread, JSTaggedValue::Undefined());
|
||||
genObj->SetResumeResult(thread, JSTaggedValue::Undefined());
|
||||
JSGeneratorState state = JSGeneratorObject::GeneratorValidate(thread, JSHandle<JSTaggedValue>::Cast(genObj));
|
||||
EXPECT_EQ(state, JSGeneratorState::SUSPENDED_YIELD);
|
||||
|
||||
genObj->SetGeneratorState(JSGeneratorState::COMPLETED);
|
||||
state = JSGeneratorObject::GeneratorValidate(thread, JSHandle<JSTaggedValue>::Cast(genObj));
|
||||
|
Loading…
Reference in New Issue
Block a user