mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-23 18:20:04 +00:00
Modify snapshot env update root type
Description:Modify snapshot env update root type Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IAF2VX?from=project-issue Signed-off-by: dingwen <dingwen6@huawei.com> Change-Id: Ieca0c3345c237f75b7ed6dc903e192bee46fa027
This commit is contained in:
parent
9ae3bad8b0
commit
efcbbe061e
@ -25,7 +25,7 @@ void HeapRootVisitor::VisitHeapRoots(JSThread *thread, const RootVisitor &visito
|
||||
const RootBaseAndDerivedVisitor &derivedVisitor)
|
||||
{
|
||||
auto ecmaVm = GetVMInstance(thread);
|
||||
ecmaVm->Iterate(visitor, rangeVisitor);
|
||||
ecmaVm->Iterate(visitor, rangeVisitor, VMRootVisitType::HEAP_SNAPSHOT);
|
||||
thread->Iterate(visitor, rangeVisitor, derivedVisitor);
|
||||
|
||||
// SerializeRoot from shared heap
|
||||
|
@ -349,7 +349,7 @@ HWTEST_F_L0(HeapDumpTest, TestAllocationEvent)
|
||||
RootBaseAndDerivedVisitor derivedVisitor = []
|
||||
([[maybe_unused]] Root type, [[maybe_unused]] ObjectSlot base, [[maybe_unused]] ObjectSlot derived,
|
||||
[[maybe_unused]] uintptr_t baseOldObject) {};
|
||||
ecmaVm_->Iterate(rootVisitor, rangeVisitor);
|
||||
ecmaVm_->Iterate(rootVisitor, rangeVisitor, VMRootVisitType::HEAP_SNAPSHOT);
|
||||
thread_->Iterate(rootVisitor, rangeVisitor, derivedVisitor);
|
||||
|
||||
bool result = JSNApi::Execute(ecmaVm_, abcFileName, "heapdump");
|
||||
@ -358,7 +358,7 @@ HWTEST_F_L0(HeapDumpTest, TestAllocationEvent)
|
||||
std::unordered_map<TaggedObject *, bool> ObjAfterExecute;
|
||||
ObjMap = &ObjAfterExecute;
|
||||
heap->IterateOverObjects(countCb);
|
||||
ecmaVm_->Iterate(rootVisitor, rangeVisitor);
|
||||
ecmaVm_->Iterate(rootVisitor, rangeVisitor, VMRootVisitType::HEAP_SNAPSHOT);
|
||||
thread_->Iterate(rootVisitor, rangeVisitor, derivedVisitor);
|
||||
ecmaVm_->SetHeapProfile(mockHeapProfiler.profiler_);
|
||||
|
||||
|
@ -708,12 +708,12 @@ void EcmaVM::CollectGarbage(TriggerGCType gcType, GCReason reason) const
|
||||
heap_->CollectGarbage(gcType, reason);
|
||||
}
|
||||
|
||||
void EcmaVM::Iterate(const RootVisitor &v, const RootRangeVisitor &rv)
|
||||
void EcmaVM::Iterate(const RootVisitor &v, const RootRangeVisitor &rv, VMRootVisitType type)
|
||||
{
|
||||
rv(Root::ROOT_VM, ObjectSlot(ToUintPtr(&internalNativeMethods_.front())),
|
||||
ObjectSlot(ToUintPtr(&internalNativeMethods_.back()) + JSTaggedValue::TaggedTypeSize()));
|
||||
if (!WIN_OR_MAC_OR_IOS_PLATFORM && snapshotEnv_!= nullptr) {
|
||||
snapshotEnv_->Iterate(v);
|
||||
snapshotEnv_->Iterate(v, type);
|
||||
}
|
||||
if (pgoProfiler_ != nullptr) {
|
||||
pgoProfiler_->Iterate(v);
|
||||
|
@ -267,7 +267,7 @@ public:
|
||||
return optionalLogEnabled_;
|
||||
}
|
||||
|
||||
void Iterate(const RootVisitor &v, const RootRangeVisitor &rv);
|
||||
void Iterate(const RootVisitor &v, const RootRangeVisitor &rv, VMRootVisitType type);
|
||||
|
||||
const Heap *GetHeap() const
|
||||
{
|
||||
|
@ -111,7 +111,7 @@ void FullGC::Mark()
|
||||
{
|
||||
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "FullGC::Mark");
|
||||
TRACE_GC(GCStats::Scope::ScopeId::Mark, heap_->GetEcmaVM()->GetEcmaGCStats());
|
||||
heap_->GetCompressGCMarker()->MarkRoots(MAIN_THREAD_INDEX);
|
||||
heap_->GetCompressGCMarker()->MarkRoots(MAIN_THREAD_INDEX, VMRootVisitType::UPDATE_ROOT);
|
||||
heap_->GetCompressGCMarker()->ProcessMarkStack(MAIN_THREAD_INDEX);
|
||||
heap_->WaitRunningTaskFinished();
|
||||
// MarkJitCodeMap must be call after other mark work finish to make sure which jserror object js alive.
|
||||
|
@ -129,9 +129,9 @@ public:
|
||||
~ObjectXRay() = default;
|
||||
|
||||
static inline void VisitVMRoots(EcmaVM *vm, const RootVisitor &visitor, const RootRangeVisitor &rangeVisitor,
|
||||
const RootBaseAndDerivedVisitor &derivedVisitor)
|
||||
const RootBaseAndDerivedVisitor &derivedVisitor, VMRootVisitType type)
|
||||
{
|
||||
vm->Iterate(visitor, rangeVisitor);
|
||||
vm->Iterate(visitor, rangeVisitor, type);
|
||||
vm->GetAssociatedJSThread()->Iterate(visitor, rangeVisitor, derivedVisitor);
|
||||
}
|
||||
|
||||
|
@ -332,7 +332,8 @@ void ParallelEvacuator::UpdateRoot()
|
||||
}
|
||||
};
|
||||
|
||||
ObjectXRay::VisitVMRoots(heap_->GetEcmaVM(), gcUpdateYoung, gcUpdateRangeYoung, gcUpdateDerived);
|
||||
ObjectXRay::VisitVMRoots(heap_->GetEcmaVM(), gcUpdateYoung, gcUpdateRangeYoung, gcUpdateDerived,
|
||||
VMRootVisitType::UPDATE_ROOT);
|
||||
}
|
||||
|
||||
void ParallelEvacuator::UpdateRecordWeakReference()
|
||||
|
@ -21,7 +21,7 @@
|
||||
namespace panda::ecmascript {
|
||||
Marker::Marker(Heap *heap) : heap_(heap), workManager_(heap->GetWorkManager()) {}
|
||||
|
||||
void Marker::MarkRoots(uint32_t threadId)
|
||||
void Marker::MarkRoots(uint32_t threadId, VMRootVisitType type)
|
||||
{
|
||||
TRACE_GC(GCStats::Scope::ScopeId::MarkRoots, heap_->GetEcmaVM()->GetEcmaGCStats());
|
||||
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "GC::MarkRoots");
|
||||
@ -33,7 +33,7 @@ void Marker::MarkRoots(uint32_t threadId)
|
||||
},
|
||||
[this](Root type, ObjectSlot base, ObjectSlot derived, uintptr_t baseOldObject) {
|
||||
this->HandleDerivedRoots(type, base, derived, baseOldObject);
|
||||
});
|
||||
}, type);
|
||||
workManager_->PushWorkNodeToGlobal(threadId, false);
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
LOG_GC(DEBUG) << "Marker::Initialize do nothing";
|
||||
}
|
||||
|
||||
void MarkRoots(uint32_t threadId);
|
||||
void MarkRoots(uint32_t threadId, VMRootVisitType type = VMRootVisitType::MARK);
|
||||
void ProcessNewToEden(uint32_t threadId); // for HPPGC only sticky mode
|
||||
void ProcessNewToEdenNoMarkStack(uint32_t threadId);
|
||||
void ProcessOldToNew(uint32_t threadId); // for HPPGC only semi mode
|
||||
|
@ -59,7 +59,7 @@ void SharedGCMarker::MarkLocalVMRoots(uint32_t threadId, EcmaVM *localVm)
|
||||
},
|
||||
[this](Root type, ObjectSlot base, ObjectSlot derived, uintptr_t baseOldObject) {
|
||||
this->HandleLocalDerivedRoots(type, base, derived, baseOldObject);
|
||||
});
|
||||
}, VMRootVisitType::MARK);
|
||||
heap->ProcessSharedGCMarkingLocalBuffer();
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ void STWYoungGC::Mark()
|
||||
} else {
|
||||
heap_->GetSemiGCMarker()->ProcessOldToNew(0, region);
|
||||
heap_->GetSemiGCMarker()->ProcessSnapshotRSet(MAIN_THREAD_INDEX);
|
||||
heap_->GetSemiGCMarker()->MarkRoots(MAIN_THREAD_INDEX);
|
||||
heap_->GetSemiGCMarker()->MarkRoots(MAIN_THREAD_INDEX, VMRootVisitType::UPDATE_ROOT);
|
||||
heap_->GetSemiGCMarker()->ProcessMarkStack(MAIN_THREAD_INDEX);
|
||||
}
|
||||
heap_->WaitRunningTaskFinished();
|
||||
|
@ -467,7 +467,7 @@ size_t Verification::VerifyRoot() const
|
||||
[]([[maybe_unused]] Root type, [[maybe_unused]] ObjectSlot base, [[maybe_unused]] ObjectSlot derived,
|
||||
[[maybe_unused]] uintptr_t baseOldObject) {
|
||||
};
|
||||
ObjectXRay::VisitVMRoots(heap_->GetEcmaVM(), visitor, rangeVisitor, derivedVisitor);
|
||||
ObjectXRay::VisitVMRoots(heap_->GetEcmaVM(), visitor, rangeVisitor, derivedVisitor, VMRootVisitType::VERIFY);
|
||||
if (failCount > 0) {
|
||||
LOG_GC(ERROR) << "VerifyRoot detects deadObject count is " << failCount;
|
||||
}
|
||||
@ -795,7 +795,7 @@ size_t SharedHeapVerification::VerifyRoot() const
|
||||
auto vm = thread->GetEcmaVM();
|
||||
auto localHeap = const_cast<Heap*>(vm->GetHeap());
|
||||
localHeap->GetSweeper()->EnsureAllTaskFinished();
|
||||
ObjectXRay::VisitVMRoots(vm, visitor, rangeVisitor, derivedVisitor);
|
||||
ObjectXRay::VisitVMRoots(vm, visitor, rangeVisitor, derivedVisitor, VMRootVisitType::VERIFY);
|
||||
if (failCount > 0) {
|
||||
LOG_GC(ERROR) << "SharedHeap VerifyRoot detects deadObject count is " << failCount;
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ enum class VisitObjectArea {
|
||||
};
|
||||
|
||||
enum class VisitType : size_t { SEMI_GC_VISIT, OLD_GC_VISIT, SNAPSHOT_VISIT, ALL_VISIT };
|
||||
enum class VMRootVisitType : uint8_t { MARK, UPDATE_ROOT, VERIFY, HEAP_SNAPSHOT };
|
||||
|
||||
using RootVisitor = std::function<void(Root type, ObjectSlot p)>;
|
||||
using RootRangeVisitor = std::function<void(Root type, ObjectSlot start, ObjectSlot end)>;
|
||||
|
@ -43,26 +43,24 @@ JSTaggedType SnapshotEnv::RelocateRootObjectAddr(uint32_t index)
|
||||
return value->GetRawData();
|
||||
}
|
||||
|
||||
void SnapshotEnv::Iterate(const RootVisitor &v)
|
||||
void SnapshotEnv::Iterate(const RootVisitor &v, VMRootVisitType type)
|
||||
{
|
||||
std::vector<std::pair<JSTaggedType, JSTaggedType>> updatedObjPair;
|
||||
for (auto &it : rootObjectMap_) {
|
||||
auto objectAddr = it.first;
|
||||
ObjectSlot slot(reinterpret_cast<uintptr_t>(&objectAddr));
|
||||
v(Root::ROOT_VM, slot);
|
||||
// Record updated obj addr after gc
|
||||
if (slot.GetTaggedType() != it.first) {
|
||||
updatedObjPair.emplace_back(std::make_pair(it.first, slot.GetTaggedType()));
|
||||
if (type == VMRootVisitType::UPDATE_ROOT) {
|
||||
// during update root, rootObjectMap_ key need update
|
||||
std::unordered_map<JSTaggedType, uint32_t> rootObjectMap(rootObjectMap_.size());
|
||||
for (auto &it : rootObjectMap_) {
|
||||
auto objectAddr = it.first;
|
||||
ObjectSlot slot(reinterpret_cast<uintptr_t>(&objectAddr));
|
||||
v(Root::ROOT_VM, slot);
|
||||
rootObjectMap.emplace(slot.GetTaggedType(), it.second);
|
||||
}
|
||||
std::swap(rootObjectMap_, rootObjectMap);
|
||||
rootObjectMap.clear();
|
||||
} else {
|
||||
for (auto &it : rootObjectMap_) {
|
||||
ObjectSlot slot(reinterpret_cast<uintptr_t>(&it));
|
||||
v(Root::ROOT_VM, slot);
|
||||
}
|
||||
}
|
||||
// Update hashmap, erase old objAddr, emplace updated objAddr
|
||||
while (!updatedObjPair.empty()) {
|
||||
auto pair = updatedObjPair.back();
|
||||
ASSERT(rootObjectMap_.find(pair.first) != rootObjectMap_.end());
|
||||
uint32_t index = rootObjectMap_.find(pair.first)->second;
|
||||
rootObjectMap_.erase(pair.first);
|
||||
rootObjectMap_.emplace(pair.second, index);
|
||||
updatedObjPair.pop_back();
|
||||
}
|
||||
}
|
||||
} // namespace panda::ecmascript
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
rootObjectMap_.clear();
|
||||
}
|
||||
|
||||
void Iterate(const RootVisitor &v);
|
||||
void Iterate(const RootVisitor &v, VMRootVisitType type);
|
||||
|
||||
void Push(JSTaggedType objectAddr, uint32_t index)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user