!8056 fix bug in full gc when enable jitdump code

Merge pull request !8056 from wangyue/fullGC
This commit is contained in:
openharmony_ci 2024-07-18 20:27:15 +00:00 committed by Gitee
commit 6db22c9787
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 87 additions and 39 deletions

View File

@ -48,43 +48,6 @@ void Marker::ProcessNewToEdenNoMarkStack(uint32_t threadId)
heap_->EnumerateNewSpaceRegions([this, threadId](Region *region) {this->HandleNewToEdenRSet(threadId, region);});
}
void Marker::MarkJitCodeMap(uint32_t threadId)
{
// To keep MachineCode objects alive (for dump) before JsError object be free, we have to know which JsError is
// alive first. So this method must be call after all other mark work finish.
TRACE_GC(GCStats::Scope::ScopeId::MarkRoots, heap_->GetEcmaVM()->GetEcmaGCStats());
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "GC::MarkJitCodeMap");
ObjectXRay::VisitJitCodeMap(heap_->GetEcmaVM(),
[this, threadId](std::map<JSTaggedType, JitCodeVector *> &jitCodeMaps) {
this->HandleVisitJitCodeMap(threadId, jitCodeMaps);
});
ProcessMarkStack(threadId);
}
void Marker::HandleVisitJitCodeMap(uint32_t threadId, std::map<JSTaggedType, JitCodeVector *> &jitCodeMaps)
{
if (!heap_->IsFullMark()) {
return;
}
auto it = jitCodeMaps.begin();
while (it != jitCodeMaps.end()) {
JSTaggedType jsError = it->first;
Region *objectRegion = Region::ObjectAddressToRange(reinterpret_cast<TaggedObject *>(jsError));
if (!objectRegion->Test(reinterpret_cast<TaggedObject *>(jsError))) {
++it;
continue;
}
for (auto jitCodeMap : *(it->second)) {
auto jitCode = std::get<0>(jitCodeMap);
Region *jitCodeRegion = Region::ObjectAddressToRange(reinterpret_cast<TaggedObject *>(jitCode));
if (!jitCodeRegion->Test(jitCode)) {
MarkObject(threadId, jitCode);
}
}
++it;
}
}
void Marker::ProcessOldToNew(uint32_t threadId)
{
heap_->EnumerateOldSpaceRegions([this, threadId](Region *region) {
@ -123,6 +86,36 @@ void Marker::ProcessSnapshotRSetNoMarkStack(uint32_t threadId)
});
}
void NonMovableMarker::MarkJitCodeMap(uint32_t threadId)
{
// To keep MachineCode objects alive (for dump) before JsError object be free, we have to know which JsError is
// alive first. So this method must be call after all other mark work finish.
TRACE_GC(GCStats::Scope::ScopeId::MarkRoots, heap_->GetEcmaVM()->GetEcmaGCStats());
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "GC::MarkJitCodeMap");
if (!heap_->IsFullMark()) {
return;
}
auto Visitor = [this, threadId](std::map<JSTaggedType, JitCodeVector *> &jitCodeMaps) {
auto it = jitCodeMaps.begin();
while (it != jitCodeMaps.end()) {
JSTaggedType jsError = it->first;
Region *objectRegion = Region::ObjectAddressToRange(reinterpret_cast<TaggedObject *>(jsError));
if (!objectRegion->Test(reinterpret_cast<TaggedObject *>(jsError))) {
++it;
continue;
}
for (auto &jitCodeMap : *(it->second)) {
auto &jitCode = std::get<0>(jitCodeMap);
MarkObject(threadId, jitCode);
}
++it;
}
};
ObjectXRay::VisitJitCodeMap(heap_->GetEcmaVM(), Visitor);
ProcessMarkStack(threadId);
heap_->WaitRunningTaskFinished();
}
void NonMovableMarker::ProcessMarkStack(uint32_t threadId)
{
TRACE_GC(GCStats::Scope::ScopeId::ProcessMarkStack, heap_->GetEcmaVM()->GetEcmaGCStats());
@ -279,6 +272,56 @@ void CompressGCMarker::ProcessMarkStack(uint32_t threadId)
}
}
void CompressGCMarker::MarkJitCodeMap(uint32_t threadId)
{
// To keep MachineCode objects alive (for dump) before JsError object be free, we have to know which JsError is
// alive first. So this method must be call after all other mark work finish.
TRACE_GC(GCStats::Scope::ScopeId::MarkRoots, heap_->GetEcmaVM()->GetEcmaGCStats());
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "GC::MarkJitCodeMap");
ObjectXRay::VisitJitCodeMap(heap_->GetEcmaVM(),
[this, threadId](std::map<JSTaggedType, JitCodeVector *> &jitCodeMaps) {
this->HandleVisitJitCodeMap(threadId, jitCodeMaps);
});
ProcessMarkStack(threadId);
heap_->WaitRunningTaskFinished();
}
void CompressGCMarker::HandleVisitJitCodeMap(uint32_t threadId, std::map<JSTaggedType, JitCodeVector *> &jitCodeMaps)
{
auto it = jitCodeMaps.begin();
while (it != jitCodeMaps.end()) {
JSTaggedType jsError = it->first;
auto jsErrorObj = reinterpret_cast<TaggedObject *>(jsError);
Region *objectRegion = Region::ObjectAddressToRange(jsErrorObj);
auto jitCodeVec = it->second;
if (!NeedEvacuate(objectRegion)) {
if (!objectRegion->InSharedHeap() && !objectRegion->Test(jsErrorObj)) {
delete it->second;
it = jitCodeMaps.erase(it);
continue;
}
} else {
MarkWord markWord(jsErrorObj);
if (markWord.IsForwardingAddress()) {
TaggedObject *dst = markWord.ToForwardingAddress();
jitCodeMaps.emplace(JSTaggedValue(dst).GetRawData(), it->second);
it = jitCodeMaps.erase(it);
} else {
delete it->second;
it = jitCodeMaps.erase(it);
continue;
}
}
for (auto &jitCodeMap : *jitCodeVec) {
auto &jitCode = std::get<0>(jitCodeMap);
auto obj = static_cast<TaggedObject *>(jitCode);
// jitcode is MachineCode, and MachineCode is in the MachineCode space, will not be evacute.
MarkObject(threadId, obj, ObjectSlot(reinterpret_cast<uintptr_t>(&jitCode)));
}
++it;
}
}
uintptr_t CompressGCMarker::AllocateForwardAddress(uint32_t threadId, size_t size, JSHClass *hclass,
TaggedObject *object)
{

View File

@ -45,8 +45,10 @@ public:
void ProcessOldToNew(uint32_t threadId, Region *region); // for SemiGC
void ProcessSnapshotRSet(uint32_t threadId); // for SemiGC
void ProcessSnapshotRSetNoMarkStack(uint32_t threadId);
void MarkJitCodeMap(uint32_t threadId);
void HandleVisitJitCodeMap(uint32_t threadId, std::map<JSTaggedType, JitCodeVector *> &jitCodeMap);
virtual void MarkJitCodeMap([[maybe_unused]] uint32_t threadId)
{
LOG_GC(FATAL) << "can not call this method";
}
virtual void ProcessMarkStack([[maybe_unused]] uint32_t threadId)
{
@ -99,6 +101,7 @@ public:
protected:
void ProcessMarkStack(uint32_t threadId) override;
void MarkJitCodeMap(uint32_t threadId) override;
template <typename Callback>
inline bool VisitBodyInObj(TaggedObject *root, ObjectSlot start, ObjectSlot end,
bool needBarrier, Callback callback);
@ -179,7 +182,9 @@ public:
}
protected:
void MarkJitCodeMap(uint32_t threadId) override;
void ProcessMarkStack(uint32_t threadId) override;
void HandleVisitJitCodeMap(uint32_t threadId, std::map<JSTaggedType, JitCodeVector *> &jitCodeMaps);
inline void MarkValue(uint32_t threadId, ObjectSlot slot);
inline SlotStatus MarkObject(uint32_t threadId, TaggedObject *object, ObjectSlot slot) override;