From a75bb2074ec45fc37c5fb1918718b53881374aa6 Mon Sep 17 00:00:00 2001 From: starunvs Date: Tue, 2 Sep 2025 15:12:33 +0800 Subject: [PATCH] runtime: change array length threshold for CMC Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICVZCC Change-Id: I4e22831aa4eb84dc7d351bf74d6b39df37aa3add Signed-off-by: starunvs --- .../compiler/new_object_stub_builder.cpp | 32 +++++++++++++++++-- ecmascript/compiler/new_object_stub_builder.h | 1 + ecmascript/object_factory.cpp | 12 +++---- ecmascript/object_factory.h | 5 ++- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/ecmascript/compiler/new_object_stub_builder.cpp b/ecmascript/compiler/new_object_stub_builder.cpp index 62b62f8ab2..deed12fb9c 100644 --- a/ecmascript/compiler/new_object_stub_builder.cpp +++ b/ecmascript/compiler/new_object_stub_builder.cpp @@ -789,7 +789,21 @@ GateRef NewObjectStubBuilder::NewTaggedArray(GateRef glue, GateRef len) { Label next(env); Label slowPath(env); - BRANCH(Int32LessThan(len, Int32(MAX_TAGGED_ARRAY_LENGTH)), &next, &slowPath); + Label isCMCGC(env); + Label notCMCGC(env); + + BRANCH_UNLIKELY(LoadPrimitive(VariableType::BOOL(), glue_, + IntPtr(JSThread::GlueData::GetIsEnableCMCGCOffset(env->Is32Bit()))), + &isCMCGC, ¬CMCGC); + Bind(&isCMCGC); + { + BRANCH(Int32LessThan(len, Int32(CMC_MAX_TAGGED_ARRAY_LENGTH)), &next, &slowPath); + } + Bind(¬CMCGC); + { + BRANCH(Int32LessThan(len, Int32(MAX_TAGGED_ARRAY_LENGTH)), &next, &slowPath); + } + Bind(&next); { NewTaggedArrayChecked(&result, len, &exit); @@ -829,7 +843,21 @@ GateRef NewObjectStubBuilder::NewMutantTaggedArray(GateRef glue, GateRef len) { Label next(env); Label slowPath(env); - BRANCH(Int32LessThan(len, Int32(MAX_TAGGED_ARRAY_LENGTH)), &next, &slowPath); + Label isCMCGC(env); + Label notCMCGC(env); + + BRANCH_UNLIKELY(LoadPrimitive(VariableType::BOOL(), glue_, + IntPtr(JSThread::GlueData::GetIsEnableCMCGCOffset(env->Is32Bit()))), + &isCMCGC, ¬CMCGC); + Bind(&isCMCGC); + { + BRANCH(Int32LessThan(len, Int32(CMC_MAX_TAGGED_ARRAY_LENGTH)), &next, &slowPath); + } + Bind(¬CMCGC); + { + BRANCH(Int32LessThan(len, Int32(MAX_TAGGED_ARRAY_LENGTH)), &next, &slowPath); + } + Bind(&next); { NewMutantTaggedArrayChecked(&result, len, &exit); diff --git a/ecmascript/compiler/new_object_stub_builder.h b/ecmascript/compiler/new_object_stub_builder.h index 3d426631c1..7b5ca556b8 100644 --- a/ecmascript/compiler/new_object_stub_builder.h +++ b/ecmascript/compiler/new_object_stub_builder.h @@ -162,6 +162,7 @@ public: private: static constexpr int MAX_TAGGED_ARRAY_LENGTH = 50; + static constexpr int CMC_MAX_TAGGED_ARRAY_LENGTH = 4096; static constexpr int MAX_EXTEND_ARRAY_LENGTH = 2048; GateRef LoadTrackInfo(GateRef glue, GateRef jsFunc, TraceIdInfo traceIdInfo, GateRef profileTypeInfo, GateRef slotId, GateRef slotValue, GateRef arrayLiteral, ProfileOperation callback); diff --git a/ecmascript/object_factory.cpp b/ecmascript/object_factory.cpp index 800818e3e7..c4ff345fd6 100644 --- a/ecmascript/object_factory.cpp +++ b/ecmascript/object_factory.cpp @@ -845,7 +845,7 @@ JSHandle ObjectFactory::NewJsonFixedArray(size_t start, size_t leng return EmptyArray(); } - MemSpaceType spaceType = length < LENGTH_THRESHOLD ? MemSpaceType::SEMI_SPACE : MemSpaceType::OLD_SPACE; + MemSpaceType spaceType = length < GetLengthThreshold() ? MemSpaceType::SEMI_SPACE : MemSpaceType::OLD_SPACE; JSHandle array = NewTaggedArrayWithoutInit(length, spaceType); array->SetExtraLength(0); for (size_t i = 0; i < length; i++) { @@ -2893,7 +2893,7 @@ JSHandle ObjectFactory::NewAndCopyTaggedArray(JSHandle uint32_t oldLength, uint32_t k) { ASSERT(oldLength <= newLength); - MemSpaceType spaceType = newLength < LENGTH_THRESHOLD ? MemSpaceType::SEMI_SPACE : MemSpaceType::OLD_SPACE; + MemSpaceType spaceType = newLength < GetLengthThreshold() ? MemSpaceType::SEMI_SPACE : MemSpaceType::OLD_SPACE; JSHandle dstElements = NewTaggedArrayWithoutInit(newLength, spaceType); dstElements->SetExtraLength(srcElements->GetExtraLength()); if (newLength == 0) { @@ -2910,7 +2910,7 @@ JSHandle ObjectFactory::NewAndCopyTaggedArraySkipBarrier(JSHandle dstElements = NewTaggedArrayWithoutInit(newLength, spaceType); if (newLength == 0) { return dstElements; @@ -2958,7 +2958,7 @@ JSHandle ObjectFactory::NewAndCopyTaggedArrayByObject(JSHandle dstElements(NewTaggedArrayWithoutInit(newLength, spaceType)); TaggedArray *srcElements = TaggedArray::Cast(thisObjHandle->GetElements(thread_).GetTaggedObject()); dstElements->SetExtraLength(srcElements->GetExtraLength()); @@ -2980,7 +2980,7 @@ JSHandle ObjectFactory::NewAndCopyMutantTaggedArrayByObject(J uint32_t k) { ASSERT(oldLength <= newLength); - MemSpaceType spaceType = newLength < LENGTH_THRESHOLD ? MemSpaceType::SEMI_SPACE : MemSpaceType::OLD_SPACE; + MemSpaceType spaceType = newLength < GetLengthThreshold() ? MemSpaceType::SEMI_SPACE : MemSpaceType::OLD_SPACE; JSHandle dstElements(NewMutantTaggedArrayWithoutInit(newLength, spaceType)); MutantTaggedArray *srcElements = MutantTaggedArray::Cast(thisObjHandle->GetElements(thread_).GetTaggedObject()); dstElements->SetExtraLength(srcElements->GetExtraLength()); @@ -3065,7 +3065,7 @@ JSHandle ObjectFactory::NewTaggedArray(uint32_t length, JSTaggedVal if (length == 0) { return EmptyArray(); } - MemSpaceType spaceType = length < LENGTH_THRESHOLD ? MemSpaceType::SEMI_SPACE : MemSpaceType::OLD_SPACE; + MemSpaceType spaceType = length < GetLengthThreshold() ? MemSpaceType::SEMI_SPACE : MemSpaceType::OLD_SPACE; JSHandle array = NewTaggedArrayWithoutInit(length, spaceType); array->InitializeWithSpecialValue(initVal, length); return array; diff --git a/ecmascript/object_factory.h b/ecmascript/object_factory.h index a764282ca6..34c990dc63 100644 --- a/ecmascript/object_factory.h +++ b/ecmascript/object_factory.h @@ -375,7 +375,8 @@ public: JSHandle ConvertListToArray(const JSThread *thread, const JSHandle &list, uint32_t numberOfNodes) { - MemSpaceType spaceType = numberOfNodes < LENGTH_THRESHOLD ? MemSpaceType::SEMI_SPACE : MemSpaceType::OLD_SPACE; + MemSpaceType spaceType = + numberOfNodes < GetLengthThreshold() ? MemSpaceType::SEMI_SPACE : MemSpaceType::OLD_SPACE; JSHandle dstElements = NewTaggedArrayWithoutInit(numberOfNodes, spaceType); if (numberOfNodes == 0) { return dstElements; @@ -989,6 +990,8 @@ private: SharedHeap *sHeap_ {nullptr}; static constexpr uint32_t LENGTH_THRESHOLD = 50; + static constexpr uint32_t CMC_LENGTH_THRESHOLD = 4096; + uint32_t GetLengthThreshold() const { return g_isEnableCMCGC ? CMC_LENGTH_THRESHOLD : LENGTH_THRESHOLD; } NO_COPY_SEMANTIC(ObjectFactory); NO_MOVE_SEMANTIC(ObjectFactory); -- Gitee