!8682 Fix some tsan warning

Merge pull request !8682 from dingwen/tsan_br
This commit is contained in:
openharmony_ci 2024-08-17 10:36:57 +00:00 committed by Gitee
commit cd5b5a8e8b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 41 additions and 51 deletions

View File

@ -31,7 +31,6 @@ namespace ecmascript {
V(ReMark) \
V(Mark) \
V(MarkRoots) \
V(ProcessMarkStack) \
V(ProcessSharedGCRSetWorkList) \
V(Sweep) \
V(ClearNativeObject) \

View File

@ -226,8 +226,6 @@ void GCStats::PrintGCDurationStatistic()
<< STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::Mark]) << "ms\n"
<< STATS_DESCRIPTION_FORMAT("MarkRoots:")
<< STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::MarkRoots]) << "ms\n"
<< STATS_DESCRIPTION_FORMAT("ProcessMarkStack:")
<< STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::ProcessMarkStack]) << "ms\n"
<< STATS_DESCRIPTION_FORMAT("Sweep:")
<< STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::Sweep]) << "ms\n"
<< STATS_DESCRIPTION_FORMAT("Finish:")
@ -248,8 +246,6 @@ void GCStats::PrintGCDurationStatistic()
<< STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::ConcurrentMark]) << "ms\n"
<< STATS_DESCRIPTION_FORMAT("WaitConcurrentMarkFinish:")
<< STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::WaitConcurrentMarkFinished]) << "ms\n"
<< STATS_DESCRIPTION_FORMAT("ProcessMarkStack:")
<< STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::ProcessMarkStack]) << "ms\n"
<< STATS_DESCRIPTION_FORMAT("ReMark:")
<< STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::ReMark]) << "ms\n"
<< STATS_DESCRIPTION_FORMAT("ProcessSharedGCRSetWorkList:")
@ -288,8 +284,6 @@ void GCStats::PrintGCDurationStatistic()
<< STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::Mark]) << "ms\n"
<< STATS_DESCRIPTION_FORMAT("MarkRoots:")
<< STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::MarkRoots]) << "ms\n"
<< STATS_DESCRIPTION_FORMAT("ProcessMarkStack:")
<< STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::ProcessMarkStack]) << "ms\n"
<< STATS_DESCRIPTION_FORMAT("Sweep:")
<< STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::Sweep]) << "ms\n"
<< STATS_DESCRIPTION_FORMAT("Finish:")

View File

@ -29,10 +29,7 @@ public:
void Stop();
void ResetAllocator();
void IterateOverObjects(const std::function<void(TaggedObject *object)> &objectVisitor) const;
void DecreaseSurvivalObjectSize(size_t objSize)
{
survivalObjectSize_ -= objSize;
}
const uintptr_t *GetAllocationTopAddress()
{
return allocator_.GetTopAddress();

View File

@ -118,7 +118,6 @@ void NonMovableMarker::MarkJitCodeMap(uint32_t threadId)
void NonMovableMarker::ProcessMarkStack(uint32_t threadId)
{
TRACE_GC(GCStats::Scope::ScopeId::ProcessMarkStack, heap_->GetEcmaVM()->GetEcmaGCStats());
bool isFullMark = heap_->IsConcurrentFullMark();
auto cb = [&](ObjectSlot s, Region *rootRegion, bool needBarrier) {
MarkValue(threadId, s, rootRegion, needBarrier);
@ -159,7 +158,6 @@ void NonMovableMarker::ProcessMarkStack(uint32_t threadId)
void NonMovableMarker::ProcessIncrementalMarkStack(uint32_t threadId, uint32_t markStepSize)
{
TRACE_GC(GCStats::Scope::ScopeId::ProcessMarkStack, heap_->GetEcmaVM()->GetEcmaGCStats());
bool isFullMark = heap_->IsConcurrentFullMark();
uint32_t visitAddrNum = 0;
auto cb = [&](ObjectSlot s, Region *rootRegion, bool needBarrier) {
@ -211,7 +209,6 @@ void SemiGCMarker::Initialize()
void SemiGCMarker::ProcessMarkStack(uint32_t threadId)
{
TRACE_GC(GCStats::Scope::ScopeId::ProcessMarkStack, heap_->GetEcmaVM()->GetEcmaGCStats());
auto cb = [&](ObjectSlot s, TaggedObject *root) { MarkValue(threadId, root, s); };
EcmaObjectRangeVisitor visitor = [this, threadId, cb](TaggedObject *root, ObjectSlot start,
ObjectSlot end, VisitObjectArea area) {
@ -233,7 +230,6 @@ void SemiGCMarker::ProcessMarkStack(uint32_t threadId)
void CompressGCMarker::ProcessMarkStack(uint32_t threadId)
{
TRACE_GC(GCStats::Scope::ScopeId::ProcessMarkStack, heap_->GetEcmaVM()->GetEcmaGCStats());
auto cb = [&](ObjectSlot s, [[maybe_unused]] TaggedObject *root) { MarkValue(threadId, s); };
EcmaObjectRangeVisitor visitor = [this, threadId, cb](TaggedObject *root, ObjectSlot start,
ObjectSlot end, VisitObjectArea area) {

View File

@ -54,9 +54,8 @@ void SharedSparseSpace::ResetTopPointer(uintptr_t top)
uintptr_t SharedSparseSpace::AllocateWithoutGC(JSThread *thread, size_t size)
{
uintptr_t object = TryAllocate(thread, size);
CHECK_SOBJECT_AND_INC_OBJ_SIZE(size);
CHECK_SOBJECT_NOT_NULL();
object = AllocateWithExpand(thread, size);
CHECK_SOBJECT_AND_INC_OBJ_SIZE(size);
return object;
}
@ -77,18 +76,18 @@ uintptr_t SharedSparseSpace::Allocate(JSThread *thread, size_t size, bool allowG
localHeap->TryTriggerFullMarkBySharedSize(size);
}
uintptr_t object = TryAllocate(thread, size);
CHECK_SOBJECT_AND_INC_OBJ_SIZE(size);
CHECK_SOBJECT_NOT_NULL();
if (sweepState_ == SweepState::SWEEPING) {
object = AllocateAfterSweepingCompleted(thread, size);
CHECK_SOBJECT_AND_INC_OBJ_SIZE(size);
CHECK_SOBJECT_NOT_NULL();
}
// Check whether it is necessary to trigger Shared GC before expanding to avoid OOM risk.
if (allowGC && sHeap_->CheckAndTriggerSharedGC(thread)) {
object = TryAllocate(thread, size);
CHECK_SOBJECT_AND_INC_OBJ_SIZE(size);
CHECK_SOBJECT_NOT_NULL();
}
object = AllocateWithExpand(thread, size);
CHECK_SOBJECT_AND_INC_OBJ_SIZE(size);
CHECK_SOBJECT_NOT_NULL();
if (allowGC) {
sHeap_->CollectGarbage<TriggerGCType::SHARED_GC, GCReason::ALLOCATION_FAILED>(thread);
object = Allocate(thread, size, false);
@ -99,14 +98,13 @@ uintptr_t SharedSparseSpace::Allocate(JSThread *thread, size_t size, bool allowG
uintptr_t SharedSparseSpace::TryAllocateAndExpand(JSThread *thread, size_t size, bool expand)
{
uintptr_t object = TryAllocate(thread, size);
CHECK_SOBJECT_AND_INC_OBJ_SIZE(size);
CHECK_SOBJECT_NOT_NULL();
if (sweepState_ == SweepState::SWEEPING) {
object = AllocateAfterSweepingCompleted(thread, size);
CHECK_SOBJECT_AND_INC_OBJ_SIZE(size);
CHECK_SOBJECT_NOT_NULL();
}
if (expand) {
object = AllocateWithExpand(thread, size);
CHECK_SOBJECT_AND_INC_OBJ_SIZE(size);
}
return object;
}
@ -120,10 +118,9 @@ uintptr_t SharedSparseSpace::AllocateNoGCAndExpand(JSThread *thread, size_t size
}
#endif
uintptr_t object = TryAllocate(thread, size);
CHECK_SOBJECT_AND_INC_OBJ_SIZE(size);
CHECK_SOBJECT_NOT_NULL();
if (sweepState_ == SweepState::SWEEPING) {
object = AllocateAfterSweepingCompleted(thread, size);
CHECK_SOBJECT_AND_INC_OBJ_SIZE(size);
}
return object;
}
@ -131,7 +128,9 @@ uintptr_t SharedSparseSpace::AllocateNoGCAndExpand(JSThread *thread, size_t size
uintptr_t SharedSparseSpace::TryAllocate([[maybe_unused]] JSThread *thread, size_t size)
{
LockHolder lock(allocateLock_);
return allocator_->Allocate(size);
uintptr_t object = allocator_->Allocate(size);
IncAllocSObjectSize(object, size);
return object;
}
uintptr_t SharedSparseSpace::AllocateWithExpand(JSThread *thread, size_t size)
@ -143,6 +142,7 @@ uintptr_t SharedSparseSpace::AllocateWithExpand(JSThread *thread, size_t size)
if (object == 0 && Expand(thread)) {
object = allocator_->Allocate(size);
}
IncAllocSObjectSize(object, size);
return object;
}
@ -184,18 +184,24 @@ void SharedSparseSpace::MergeDeserializeAllocateRegions(const std::vector<Region
uintptr_t SharedSparseSpace::AllocateAfterSweepingCompleted([[maybe_unused]] JSThread *thread, size_t size)
{
LockHolder lock(allocateLock_);
uintptr_t object = 0U;
if (sweepState_ != SweepState::SWEEPING) {
return allocator_->Allocate(size);
object = allocator_->Allocate(size);
IncAllocSObjectSize(object, size);
return object;
}
if (TryFillSweptRegion()) {
auto object = allocator_->Allocate(size);
object = allocator_->Allocate(size);
IncAllocSObjectSize(object, size);
if (object != 0) {
return object;
}
}
// Parallel sweep and fill
sHeap_->GetSweeper()->EnsureTaskFinished(spaceType_);
return allocator_->Allocate(size);
object = allocator_->Allocate(size);
IncAllocSObjectSize(object, size);
return object;
}
void SharedSparseSpace::PrepareSweeping()
@ -388,6 +394,19 @@ void SharedSparseSpace::CheckAndTriggerLocalFullMark(JSThread *thread)
}
}
void SharedSparseSpace::IncAllocSObjectSize(uintptr_t object, size_t size)
{
if (object != 0) {
IncreaseLiveObjectSize(size);
if (sHeap_->IsReadyToConcurrentMark()) {
Region::ObjectAddressToRange(object)->IncreaseAliveObject(size);
}
#ifdef ECMASCRIPT_SUPPORT_HEAPSAMPLING
InvokeAllocationInspector(object, size, size);
#endif
}
}
SharedAppSpawnSpace::SharedAppSpawnSpace(SharedHeap *heap, size_t initialCapacity)
: SharedSparseSpace(heap, MemSpaceType::SHARED_APPSPAWN_SPACE, initialCapacity, initialCapacity)
{

View File

@ -20,26 +20,10 @@
#include "ecmascript/mem/sparse_space.h"
namespace panda::ecmascript {
#ifdef ECMASCRIPT_SUPPORT_HEAPSAMPLING
#define CHECK_SOBJECT_AND_INC_OBJ_SIZE(size) \
#define CHECK_SOBJECT_NOT_NULL() \
if (object != 0) { \
IncreaseLiveObjectSize(size); \
if (sHeap_->IsReadyToConcurrentMark()) { \
Region::ObjectAddressToRange(object)->IncreaseAliveObject(size); \
} \
InvokeAllocationInspector(object, size, size); \
return object; \
}
#else
#define CHECK_SOBJECT_AND_INC_OBJ_SIZE(size) \
if (object != 0) { \
IncreaseLiveObjectSize(size); \
if (heap_->IsReadyToConcurrentMark()) { \
Region::ObjectAddressToRange(object)->IncreaseAliveObject(size); \
} \
return object; \
}
#endif
class SharedHeap;
class SharedLocalSpace;
@ -127,6 +111,7 @@ private:
uintptr_t TryAllocate(JSThread *thread, size_t size);
// For sweeping
uintptr_t AllocateAfterSweepingCompleted(JSThread *thread, size_t size);
void IncAllocSObjectSize(uintptr_t object, size_t size);
Mutex lock_;
Mutex allocateLock_;

View File

@ -98,11 +98,11 @@ public:
bool GetExecuteMode() const
{
return isExecuteBuffer_;
return isExecuteBuffer_.load(std::memory_order_acquire);
}
void SetExecuteMode(bool mode)
{
isExecuteBuffer_ = mode;
isExecuteBuffer_.store(mode, std::memory_order_release);
}
static CString PUBLIC_API GetRecordName(JSTaggedValue module);
@ -176,7 +176,7 @@ private:
EcmaVM *vm_ {nullptr};
CUnorderedMap<CString, JSTaggedValue> resolvedModules_;
bool isExecuteBuffer_ {false};
std::atomic<bool> isExecuteBuffer_ {false};
CVector<CString> InstantiatingSModuleList_;
friend class EcmaVM;

View File

@ -35,7 +35,7 @@ void ObjectFactory::NewSObjectHook() const
if (count++ % frequency == 0) {
if (count % (CONCURRENT_MARK_FREQUENCY_FACTOR * frequency) == 0) {
sHeap_->CollectGarbage<TriggerGCType::SHARED_GC, GCReason::OTHER>(thread_);
} else {
} else if (sHeap_->CheckCanTriggerConcurrentMarking(thread_)) {
sHeap_->TriggerConcurrentMarking<TriggerGCType::SHARED_GC, GCReason::OTHER>(thread_);
}
if (!ecmascript::AnFileDataManager::GetInstance()->IsEnable()) {