diff --git a/ecmascript/mem/heap.cpp b/ecmascript/mem/heap.cpp index be2844958cae5d1d4a066007ec0961ad73cd7600..38ba365dfd4869389f9118a402422a51c8942f9e 100644 --- a/ecmascript/mem/heap.cpp +++ b/ecmascript/mem/heap.cpp @@ -152,10 +152,7 @@ void Heap::CollectGarbage(TriggerGCType gcType) SetNewSpaceMaximumCapacity(SEMI_SPACE_SIZE_CAPACITY); ResetAppStartup(); } else { - if (CheckAndTriggerCompressGC()) { - compressCollector_->RunPhases(); - RecomputeLimits(); - } else { + if (!CheckAndTriggerCompressGC()) { semiSpaceCollector_->RunPhases(); } } @@ -233,7 +230,7 @@ void Heap::RecomputeLimits() bool Heap::CheckAndTriggerOldGC() { - if (oldSpace_->GetHeapObjectSize() <= oldSpaceAllocLimit_) { + if (oldSpace_->GetCommittedSize() <= oldSpaceAllocLimit_) { return false; } CollectGarbage(TriggerGCType::OLD_GC); @@ -242,7 +239,7 @@ bool Heap::CheckAndTriggerOldGC() bool Heap::CheckAndTriggerCompressGC() { - if (oldSpace_->GetHeapObjectSize() <= oldSpaceAllocLimit_) { + if (oldSpace_->GetCommittedSize() <= oldSpaceAllocLimit_) { return false; } CollectGarbage(TriggerGCType::COMPRESS_FULL_GC); @@ -251,7 +248,7 @@ bool Heap::CheckAndTriggerCompressGC() bool Heap::CheckAndTriggerNonMovableGC() { - if (nonMovableSpace_->GetHeapObjectSize() <= DEFAULT_NON_MOVABLE_SPACE_LIMIT) { + if (nonMovableSpace_->GetCommittedSize() <= DEFAULT_NON_MOVABLE_SPACE_LIMIT) { return false; } CollectGarbage(TriggerGCType::NON_MOVE_GC); diff --git a/ecmascript/mem/tlab_allocator-inl.h b/ecmascript/mem/tlab_allocator-inl.h index 3a36d26b60004c612f6447f9d85c872df0feccec..9e375449efa015acaab0aa368eaafd3c9c3d053b 100644 --- a/ecmascript/mem/tlab_allocator-inl.h +++ b/ecmascript/mem/tlab_allocator-inl.h @@ -24,7 +24,7 @@ #include "ecmascript/mem/tlab_allocator.h" namespace panda::ecmascript { -static constexpr size_t SEMIGC_YOUNG_BUFFER_SIZE = 32 * 1024; +static constexpr size_t YOUNG_BUFFER_SIZE = 32 * 1024; static constexpr size_t OLD_BUFFER_SIZE = 255 * 1024; TlabAllocator::TlabAllocator(Heap *heap, TriggerGCType gcType) @@ -35,11 +35,15 @@ TlabAllocator::TlabAllocator(Heap *heap, TriggerGCType gcType) TlabAllocator::~TlabAllocator() { - FreeObject::FillFreeObject(heap_->GetEcmaVM(), youngTop_, youngEnd_ - youngTop_); - if (gcType_ == TriggerGCType::SEMI_GC) { - heap_->GetSemiSpaceCollector()->oldSpaceAllocator_.Free(oldTop_, oldEnd_); - } else if (gcType_ == TriggerGCType::COMPRESS_FULL_GC) { - heap_->GetCompressCollector()->oldSpaceAllocator_.Free(oldTop_, oldEnd_); + if (youngTop_ != 0 && youngTop_ != youngEnd_) { + FreeObject::FillFreeObject(heap_->GetEcmaVM(), youngTop_, youngEnd_ - youngTop_); + } + if (oldTop_ != 0 && oldTop_ != oldEnd_) { + if (gcType_ == TriggerGCType::SEMI_GC) { + heap_->GetSemiSpaceCollector()->oldSpaceAllocator_.Free(oldTop_, oldEnd_); + } else if (gcType_ == TriggerGCType::COMPRESS_FULL_GC) { + heap_->GetCompressCollector()->oldSpaceAllocator_.Free(oldTop_, oldEnd_); + } } } @@ -114,7 +118,7 @@ bool TlabAllocator::ExpandYoung() { uintptr_t buffer = 0; if (gcType_ == TriggerGCType::SEMI_GC) { - buffer = heap_->GetSemiSpaceCollector()->AllocateYoung(SEMIGC_YOUNG_BUFFER_SIZE); + buffer = heap_->GetSemiSpaceCollector()->AllocateYoung(YOUNG_BUFFER_SIZE); } else { UNREACHABLE(); } @@ -124,7 +128,7 @@ bool TlabAllocator::ExpandYoung() } youngBegin_ = buffer; youngTop_ = youngBegin_; - youngEnd_ = youngBegin_ + SEMIGC_YOUNG_BUFFER_SIZE; + youngEnd_ = youngBegin_ + YOUNG_BUFFER_SIZE; return true; } @@ -132,7 +136,7 @@ bool TlabAllocator::ExpandOld() { uintptr_t buffer = 0; if (gcType_ == TriggerGCType::SEMI_GC) { - buffer = heap_->GetSemiSpaceCollector()->AllocateOld(OLD_BUFFER_SIZE); + buffer = heap_->GetSemiSpaceCollector()->AllocateOld(YOUNG_BUFFER_SIZE); } else if (gcType_ == TriggerGCType::COMPRESS_FULL_GC) { buffer = heap_->GetCompressCollector()->AllocateOld(OLD_BUFFER_SIZE); } else { @@ -144,7 +148,13 @@ bool TlabAllocator::ExpandOld() } oldBegin_ = buffer; oldTop_ = oldBegin_; - oldEnd_ = oldBegin_ + OLD_BUFFER_SIZE; + if (gcType_ == TriggerGCType::SEMI_GC) { + oldEnd_ = oldBegin_ + YOUNG_BUFFER_SIZE; + } else if (gcType_ == TriggerGCType::COMPRESS_FULL_GC) { + oldEnd_ = oldBegin_ + OLD_BUFFER_SIZE; + } else { + UNREACHABLE(); + } return true; } } // namespace panda::ecmascript diff --git a/ecmascript/object_factory.cpp b/ecmascript/object_factory.cpp index 7282588009227f3e99881e2fcce43a598c034e9d..c44e7fe41a3f8dea465014d5414905810041c38c 100644 --- a/ecmascript/object_factory.cpp +++ b/ecmascript/object_factory.cpp @@ -290,6 +290,7 @@ JSHandle ObjectFactory::NewJSObject(const JSHandle &jshclass NewObjectHook(); JSHandle obj(thread_, JSObject::Cast(NewDynObject(jshclass, JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS))); JSHandle emptyArray = EmptyArray(); + Barriers::SetDynPrimitive(*obj, ECMAObject::HASH_OFFSET, JSTaggedValue(0).GetRawData()); obj->SetElements(thread_, emptyArray, SKIP_BARRIER); obj->SetProperties(thread_, emptyArray, SKIP_BARRIER); return obj;