mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-07 08:03:29 +00:00
6e5a7e8362
details: 1. use hilog in ohos device 2. use panda logger in host issue: https://gitee.com/openharmony/ark_js_runtime/issues/I5FR5J Signed-off-by: wengchangcheng <wengchangcheng@huawei.com> Change-Id: I6f5de00751154bdb6aac3101515961a3a4432e80
156 lines
5.7 KiB
C++
156 lines
5.7 KiB
C++
/*
|
|
* Copyright (c) 2021 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/mem/full_gc.h"
|
|
|
|
#include "ecmascript/ecma_vm.h"
|
|
#include "ecmascript/mem/clock_scope.h"
|
|
#include "ecmascript/mem/concurrent_marker.h"
|
|
#include "ecmascript/mem/mark_stack.h"
|
|
#include "ecmascript/mem/mem.h"
|
|
#include "ecmascript/mem/parallel_marker-inl.h"
|
|
#include "ecmascript/mem/space-inl.h"
|
|
#include "ecmascript/mem/visitor.h"
|
|
#include "ecmascript/mem/gc_stats.h"
|
|
#include "ecmascript/ecma_string_table.h"
|
|
#include "ecmascript/runtime_call_id.h"
|
|
|
|
namespace panda::ecmascript {
|
|
FullGC::FullGC(Heap *heap) : heap_(heap), workManager_(heap->GetWorkManager()) {}
|
|
|
|
void FullGC::RunPhases()
|
|
{
|
|
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "FullGC::RunPhases");
|
|
MEM_ALLOCATE_AND_GC_TRACE(heap_->GetEcmaVM(), FullGC_RunPhases);
|
|
ClockScope clockScope;
|
|
|
|
if (heap_->CheckOngoingConcurrentMarking()) {
|
|
LOG_GC(DEBUG) << "FullGC after ConcurrentMarking";
|
|
heap_->GetConcurrentMarker()->Reset(); // HPPGC use mark result to move TaggedObject.
|
|
}
|
|
Initialize();
|
|
Mark();
|
|
Sweep();
|
|
Finish();
|
|
heap_->GetEcmaVM()->GetEcmaGCStats()->StatisticFullGC(clockScope.GetPauseTime(), youngAndOldAliveSize_,
|
|
youngSpaceCommitSize_, oldSpaceCommitSize_,
|
|
nonMoveSpaceFreeSize_, nonMoveSpaceCommitSize_);
|
|
LOG_GC(DEBUG) << "FullGC::RunPhases " << clockScope.TotalSpentTime();
|
|
}
|
|
|
|
void FullGC::RunPhasesForAppSpawn()
|
|
{
|
|
auto marker = reinterpret_cast<CompressGCMarker*>(heap_->GetCompressGCMarker());
|
|
marker->SetAppSpawn(true);
|
|
RunPhases();
|
|
marker->SetAppSpawn(false);
|
|
}
|
|
|
|
void FullGC::Initialize()
|
|
{
|
|
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "FullGC::Initialize");
|
|
heap_->Prepare();
|
|
auto callback = [](Region *current) {
|
|
current->ResetAliveObject();
|
|
current->ClearOldToNewRSet();
|
|
};
|
|
heap_->EnumerateNonMovableRegions(callback);
|
|
youngSpaceCommitSize_ = heap_->GetNewSpace()->GetCommittedSize();
|
|
heap_->SwapNewSpace();
|
|
workManager_->Initialize(TriggerGCType::FULL_GC, ParallelGCTaskPhase::COMPRESS_HANDLE_GLOBAL_POOL_TASK);
|
|
heap_->GetCompressGCMarker()->Initialize();
|
|
|
|
youngAndOldAliveSize_ = 0;
|
|
nonMoveSpaceFreeSize_ = 0;
|
|
oldSpaceCommitSize_ = heap_->GetOldSpace()->GetCommittedSize();
|
|
nonMoveSpaceCommitSize_ = heap_->GetNonMovableSpace()->GetCommittedSize();
|
|
}
|
|
|
|
void FullGC::Mark()
|
|
{
|
|
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "FullGC::Mark");
|
|
heap_->GetCompressGCMarker()->MarkRoots(MAIN_THREAD_INDEX);
|
|
heap_->GetCompressGCMarker()->ProcessMarkStack(MAIN_THREAD_INDEX);
|
|
heap_->WaitRunningTaskFinished();
|
|
}
|
|
|
|
void FullGC::Sweep()
|
|
{
|
|
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "FullGC::Sweep");
|
|
// process weak reference
|
|
auto totalThreadCount = Taskpool::GetCurrentTaskpool()->GetTotalThreadNum() + 1; // gc thread and main thread
|
|
for (uint32_t i = 0; i < totalThreadCount; i++) {
|
|
ProcessQueue *queue = workManager_->GetWeakReferenceQueue(i);
|
|
|
|
while (true) {
|
|
auto obj = queue->PopBack();
|
|
if (UNLIKELY(obj == nullptr)) {
|
|
break;
|
|
}
|
|
ObjectSlot slot(ToUintPtr(obj));
|
|
JSTaggedValue value(slot.GetTaggedType());
|
|
auto header = value.GetTaggedWeakRef();
|
|
|
|
Region *objectRegion = Region::ObjectAddressToRange(header);
|
|
if (!objectRegion->InYoungOrOldSpace()) {
|
|
if (!objectRegion->Test(header)) {
|
|
slot.Update(static_cast<JSTaggedType>(JSTaggedValue::Undefined().GetRawData()));
|
|
}
|
|
} else {
|
|
MarkWord markWord(header);
|
|
if (markWord.IsForwardingAddress()) {
|
|
TaggedObject *dst = markWord.ToForwardingAddress();
|
|
auto weakRef = JSTaggedValue(JSTaggedValue(dst).CreateAndGetWeakRef()).GetRawTaggedObject();
|
|
slot.Update(weakRef);
|
|
} else {
|
|
slot.Update(static_cast<JSTaggedType>(JSTaggedValue::Undefined().GetRawData()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
auto stringTable = heap_->GetEcmaVM()->GetEcmaStringTable();
|
|
WeakRootVisitor gcUpdateWeak = [](TaggedObject *header) {
|
|
Region *objectRegion = Region::ObjectAddressToRange(header);
|
|
if (!objectRegion->InYoungOrOldSpace()) {
|
|
if (objectRegion->Test(header)) {
|
|
return header;
|
|
}
|
|
return reinterpret_cast<TaggedObject *>(ToUintPtr(nullptr));
|
|
}
|
|
|
|
MarkWord markWord(header);
|
|
if (markWord.IsForwardingAddress()) {
|
|
return markWord.ToForwardingAddress();
|
|
}
|
|
return reinterpret_cast<TaggedObject *>(ToUintPtr(nullptr));
|
|
};
|
|
stringTable->SweepWeakReference(gcUpdateWeak);
|
|
heap_->GetEcmaVM()->GetJSThread()->IterateWeakEcmaGlobalStorage(gcUpdateWeak);
|
|
heap_->GetEcmaVM()->ProcessReferences(gcUpdateWeak);
|
|
|
|
heap_->UpdateDerivedObjectInStack();
|
|
heap_->GetSweeper()->Sweep(true);
|
|
}
|
|
|
|
void FullGC::Finish()
|
|
{
|
|
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "FullGC::Finish");
|
|
heap_->Resume(FULL_GC);
|
|
youngAndOldAliveSize_ = workManager_->Finish();
|
|
heap_->GetSweeper()->TryFillSweptRegion();
|
|
}
|
|
} // namespace panda::ecmascript
|