diff --git a/ecmascript/daemon/daemon_thread.cpp b/ecmascript/daemon/daemon_thread.cpp index c927706531..48411d44a3 100644 --- a/ecmascript/daemon/daemon_thread.cpp +++ b/ecmascript/daemon/daemon_thread.cpp @@ -55,7 +55,7 @@ void DaemonThread::StartRunning() ASSERT(tasks_.empty()); Taskpool::GetCurrentTaskpool()->Initialize(); ASSERT(GetThreadId() == 0); - thread_ = std::make_unique(&DaemonThread::Run, this); + thread_ = std::make_unique([this] {this->Run();}); // Wait until daemon thread is running. while (!IsRunning()); #ifdef ENABLE_QOS diff --git a/ecmascript/js_thread.cpp b/ecmascript/js_thread.cpp index 60de6a0c0d..11dab319a4 100644 --- a/ecmascript/js_thread.cpp +++ b/ecmascript/js_thread.cpp @@ -115,24 +115,24 @@ JSThread::JSThread(EcmaVM *vm) : id_(os::thread::GetCurrentThreadId()), vm_(vm) auto chunk = vm->GetChunk(); if (!vm_->GetJSOptions().EnableGlobalLeakCheck()) { globalStorage_ = chunk->New>(this, vm->GetNativeAreaAllocator()); - newGlobalHandle_ = std::bind(&EcmaGlobalStorage::NewGlobalHandle, globalStorage_, std::placeholders::_1); - disposeGlobalHandle_ = std::bind(&EcmaGlobalStorage::DisposeGlobalHandle, globalStorage_, - std::placeholders::_1); - setWeak_ = std::bind(&EcmaGlobalStorage::SetWeak, globalStorage_, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3, std::placeholders::_4); - clearWeak_ = std::bind(&EcmaGlobalStorage::ClearWeak, globalStorage_, std::placeholders::_1); - isWeak_ = std::bind(&EcmaGlobalStorage::IsWeak, globalStorage_, std::placeholders::_1); + newGlobalHandle_ = [this](JSTaggedType value) { return globalStorage_->NewGlobalHandle(value); }; + disposeGlobalHandle_ = [this](uintptr_t nodeAddr) { globalStorage_->DisposeGlobalHandle(nodeAddr); }; + setWeak_ = [this](uintptr_t nodeAddr, void *ref, WeakClearCallback freeGlobalCallBack, + WeakClearCallback nativeFinalizeCallBack) { + return globalStorage_->SetWeak(nodeAddr, ref, freeGlobalCallBack, nativeFinalizeCallBack); + }; + clearWeak_ = [this](uintptr_t nodeAddr) { return globalStorage_->ClearWeak(nodeAddr); }; + isWeak_ = [this](uintptr_t addr) { return globalStorage_->IsWeak(addr); }; } else { - globalDebugStorage_ = - chunk->New>(this, vm->GetNativeAreaAllocator()); - newGlobalHandle_ = std::bind(&EcmaGlobalStorage::NewGlobalHandle, globalDebugStorage_, - std::placeholders::_1); - disposeGlobalHandle_ = std::bind(&EcmaGlobalStorage::DisposeGlobalHandle, globalDebugStorage_, - std::placeholders::_1); - setWeak_ = std::bind(&EcmaGlobalStorage::SetWeak, globalDebugStorage_, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3, std::placeholders::_4); - clearWeak_ = std::bind(&EcmaGlobalStorage::ClearWeak, globalDebugStorage_, std::placeholders::_1); - isWeak_ = std::bind(&EcmaGlobalStorage::IsWeak, globalDebugStorage_, std::placeholders::_1); + globalDebugStorage_ = chunk->New>(this, vm->GetNativeAreaAllocator()); + newGlobalHandle_ = [this](JSTaggedType value) { return globalDebugStorage_->NewGlobalHandle(value); }; + disposeGlobalHandle_ = [this](uintptr_t nodeAddr) { globalDebugStorage_->DisposeGlobalHandle(nodeAddr); }; + setWeak_ = [this](uintptr_t nodeAddr, void *ref, WeakClearCallback freeGlobalCallBack, + WeakClearCallback nativeFinalizeCallBack) { + return globalDebugStorage_->SetWeak(nodeAddr, ref, freeGlobalCallBack, nativeFinalizeCallBack); + }; + clearWeak_ = [this](uintptr_t nodeAddr) { return globalDebugStorage_->ClearWeak(nodeAddr); }; + isWeak_ = [this](uintptr_t addr) { return globalDebugStorage_->IsWeak(addr); }; } vmThreadControl_ = new VmThreadControl(this); SetBCStubStatus(BCStubStatus::NORMAL_BC_STUB); diff --git a/ecmascript/mem/heap.cpp b/ecmascript/mem/heap.cpp index fef4e9e269..6966151256 100644 --- a/ecmascript/mem/heap.cpp +++ b/ecmascript/mem/heap.cpp @@ -1222,8 +1222,9 @@ size_t Heap::VerifyHeapObjects(VerifyKind verifyKind) const verifyKind == VerifyKind::VERIFY_EVACUATE_OLD || verifyKind == VerifyKind::VERIFY_EVACUATE_FULL) { inactiveSemiSpace_->EnumerateRegions([this](Region *region) { - region->IterateAllMarkedBits(std::bind(&VerifyObjectVisitor::VerifyInactiveSemiSpaceMarkedObject, - this, std::placeholders::_1)); + region->IterateAllMarkedBits([this](void *addr) { + VerifyObjectVisitor::VerifyInactiveSemiSpaceMarkedObject(this, addr); + }); }); } } diff --git a/ecmascript/mem/parallel_marker.cpp b/ecmascript/mem/parallel_marker.cpp index c113634a44..93ff7d45ae 100644 --- a/ecmascript/mem/parallel_marker.cpp +++ b/ecmascript/mem/parallel_marker.cpp @@ -27,23 +27,25 @@ void Marker::MarkRoots(uint32_t threadId) ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "GC::MarkRoots"); ObjectXRay::VisitVMRoots( heap_->GetEcmaVM(), - std::bind(&Marker::HandleRoots, this, threadId, std::placeholders::_1, std::placeholders::_2), - std::bind(&Marker::HandleRangeRoots, this, threadId, std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3), - std::bind(&Marker::HandleDerivedRoots, this, std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4)); + [this, threadId](Root type, ObjectSlot slot) {this->HandleRoots(threadId, type, slot);}, + [this, threadId](Root type, ObjectSlot start, ObjectSlot end) { + this->HandleRangeRoots(threadId, type, start, end); + }, + [this](Root type, ObjectSlot base, ObjectSlot derived, uintptr_t baseOldObject) { + this->HandleDerivedRoots(type, base, derived, baseOldObject); + }); workManager_->PushWorkNodeToGlobal(threadId, false); } void Marker::ProcessNewToEden(uint32_t threadId) { - heap_->EnumerateNewSpaceRegions(std::bind(&Marker::HandleNewToEdenRSet, this, threadId, std::placeholders::_1)); + heap_->EnumerateNewSpaceRegions([this, threadId](Region *region) {this->HandleNewToEdenRSet(threadId, region);}); ProcessMarkStack(threadId); } void Marker::ProcessNewToEdenNoMarkStack(uint32_t threadId) { - heap_->EnumerateNewSpaceRegions(std::bind(&Marker::HandleNewToEdenRSet, this, threadId, std::placeholders::_1)); + heap_->EnumerateNewSpaceRegions([this, threadId](Region *region) {this->HandleNewToEdenRSet(threadId, region);}); } void Marker::MarkJitCodeMap(uint32_t threadId) @@ -53,7 +55,9 @@ void Marker::MarkJitCodeMap(uint32_t threadId) TRACE_GC(GCStats::Scope::ScopeId::MarkRoots, heap_->GetEcmaVM()->GetEcmaGCStats()); ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "GC::MarkJitCodeMap"); ObjectXRay::VisitJitCodeMap(heap_->GetEcmaVM(), - std::bind(&Marker::HandleVisitJitCodeMap, this, threadId, std::placeholders::_1)); + [this, threadId](std::map &jitCodeMaps) { + this->HandleVisitJitCodeMap(threadId, jitCodeMaps); + }); ProcessMarkStack(threadId); } @@ -83,31 +87,40 @@ void Marker::HandleVisitJitCodeMap(uint32_t threadId, std::mapEnumerateOldSpaceRegions(std::bind(&Marker::HandleOldToNewRSet, this, threadId, std::placeholders::_1)); + heap_->EnumerateOldSpaceRegions([this, threadId](Region *region) { + this->HandleOldToNewRSet(threadId, region); + }); ProcessMarkStack(threadId); } void Marker::ProcessOldToNewNoMarkStack(uint32_t threadId) { - heap_->EnumerateOldSpaceRegions(std::bind(&Marker::HandleOldToNewRSet, this, threadId, std::placeholders::_1)); + heap_->EnumerateOldSpaceRegions([this, threadId](Region *region) { + this->HandleOldToNewRSet(threadId, region); + }); } void Marker::ProcessOldToNew(uint32_t threadId, Region *region) { - heap_->EnumerateOldSpaceRegions(std::bind(&Marker::HandleOldToNewRSet, this, threadId, std::placeholders::_1), - region); + heap_->EnumerateOldSpaceRegions([this, threadId](Region *region) { + this->HandleOldToNewRSet(threadId, region); + }, region); ProcessMarkStack(threadId); } void Marker::ProcessSnapshotRSet(uint32_t threadId) { - heap_->EnumerateSnapshotSpaceRegions(std::bind(&Marker::HandleOldToNewRSet, this, threadId, std::placeholders::_1)); + heap_->EnumerateSnapshotSpaceRegions([this, threadId](Region *region) { + this->HandleOldToNewRSet(threadId, region); + }); ProcessMarkStack(threadId); } void Marker::ProcessSnapshotRSetNoMarkStack(uint32_t threadId) { - heap_->EnumerateSnapshotSpaceRegions(std::bind(&Marker::HandleOldToNewRSet, this, threadId, std::placeholders::_1)); + heap_->EnumerateSnapshotSpaceRegions([this, threadId](Region *region) { + this->HandleOldToNewRSet(threadId, region); + }); } void NonMovableMarker::ProcessMarkStack(uint32_t threadId) diff --git a/ecmascript/mem/shared_heap/shared_gc_marker.cpp b/ecmascript/mem/shared_heap/shared_gc_marker.cpp index 8aaea622f4..679362dd96 100644 --- a/ecmascript/mem/shared_heap/shared_gc_marker.cpp +++ b/ecmascript/mem/shared_heap/shared_gc_marker.cpp @@ -53,11 +53,13 @@ void SharedGCMarker::MarkLocalVMRoots(uint32_t threadId, EcmaVM *localVm) heap->WaitClearTaskFinished(); ObjectXRay::VisitVMRoots( localVm, - std::bind(&SharedGCMarker::HandleLocalRoots, this, threadId, std::placeholders::_1, std::placeholders::_2), - std::bind(&SharedGCMarker::HandleLocalRangeRoots, this, threadId, std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3), - std::bind(&SharedGCMarker::HandleLocalDerivedRoots, this, std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4)); + [this, threadId](Root type, ObjectSlot slot) {this->HandleLocalRoots(threadId, type, slot);}, + [this, threadId](Root type, ObjectSlot start, ObjectSlot end) { + this->HandleLocalRangeRoots(threadId, type, start, end); + }, + [this](Root type, ObjectSlot base, ObjectSlot derived, uintptr_t baseOldObject) { + this->HandleLocalDerivedRoots(type, base, derived, baseOldObject); + }); heap->ProcessSharedGCMarkingLocalBuffer(); } @@ -73,25 +75,23 @@ void SharedGCMarker::CollectLocalVMRSet(EcmaVM *localVm) void SharedGCMarker::MarkSerializeRoots(uint32_t threadId) { ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "SharedGCMarker::MarkSerializeRoots"); - auto callback = - std::bind(&SharedGCMarker::HandleRoots, this, threadId, std::placeholders::_1, std::placeholders::_2); + auto callback = [this, threadId](Root type, ObjectSlot slot) {this->HandleRoots(threadId, type, slot);}; Runtime::GetInstance()->IterateSerializeRoot(callback); } void SharedGCMarker::MarkStringCache(uint32_t threadId) { ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "SharedGCMarker::MarkStringCache"); - auto cacheStringCallback = - std::bind(&SharedGCMarker::HandleLocalRangeRoots, this, threadId, std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3); + auto cacheStringCallback = [this, threadId](Root type, ObjectSlot start, ObjectSlot end) { + this->HandleLocalRangeRoots(threadId, type, start, end); + }; Runtime::GetInstance()->IterateCachedStringRoot(cacheStringCallback); } void SharedGCMarker::MarkSharedModule(uint32_t threadId) { ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "SharedGCMarker::MarkSharedModule"); - auto visitor = std::bind(&SharedGCMarker::HandleRoots, this, threadId, std::placeholders::_1, - std::placeholders::_2); + auto visitor = [this, threadId](Root type, ObjectSlot slot) {this->HandleRoots(threadId, type, slot);}; SharedModuleManager::GetInstance()->Iterate(visitor); } diff --git a/ecmascript/taskpool/runner.cpp b/ecmascript/taskpool/runner.cpp index 6cfe6e6e11..acf0d24967 100644 --- a/ecmascript/taskpool/runner.cpp +++ b/ecmascript/taskpool/runner.cpp @@ -30,7 +30,7 @@ Runner::Runner(uint32_t threadNum, const std::function thread = std::make_unique(&Runner::Run, this, i + 1); + std::unique_ptr thread = std::make_unique([this, i] {this->Run(i + 1);}); threadPool_.emplace_back(std::move(thread)); }