diff --git a/common_components/heap/space/nonmovable_space.cpp b/common_components/heap/space/nonmovable_space.cpp index e5217d3e455c21616944480608b4b1062984752f..647e4bf4b955f9db2207b4a9b0f2092990b15f66 100644 --- a/common_components/heap/space/nonmovable_space.cpp +++ b/common_components/heap/space/nonmovable_space.cpp @@ -128,7 +128,7 @@ uintptr_t NonMovableSpace::Alloc(size_t size, bool allowGC) size_t cellCount = size / sizeof(uint64_t) - 1; RegionList* list = recentMonoSizeRegionList_[cellCount]; std::mutex& listMutex = list->GetListMutex(); - listMutex.lock(); + std::lock_guard lock(listMutex); RegionDesc* headRegion = list->GetHeadRegion(); if (headRegion != nullptr) { addr = headRegion->Alloc(size); @@ -140,7 +140,6 @@ uintptr_t NonMovableSpace::Alloc(size_t size, bool allowGC) RegionDesc* region = regionManager_.TakeRegion(1, RegionDesc::UnitRole::SMALL_SIZED_UNITS, false, allowGC); if (region == nullptr) { - listMutex.unlock(); return 0; } DLOG(REGION, "alloc non-movable region @0x%zx+%zu type %u", region->GetRegionStart(), @@ -154,7 +153,6 @@ uintptr_t NonMovableSpace::Alloc(size_t size, bool allowGC) addr = region->Alloc(size); } DLOG(ALLOC, "alloc non-movable obj 0x%zx(%zu)", addr, size); - listMutex.unlock(); return addr; } diff --git a/common_components/heap/space/regional_space.h b/common_components/heap/space/regional_space.h index 6f541b6d49b9879d5a091e898fcd74cc539f7181..d8fcef3838cd7dacb3db0dc02ddcdef2e587016d 100644 --- a/common_components/heap/space/regional_space.h +++ b/common_components/heap/space/regional_space.h @@ -54,6 +54,9 @@ protected: void InitRegionPhaseLine(RegionDesc* region) { + if (region == nullptr) { + return; + } GCPhase phase = Mutator::GetMutator()->GetMutatorPhase(); if (phase == GC_PHASE_ENUM || phase == GC_PHASE_MARK || phase == GC_PHASE_REMARK_SATB || phase == GC_PHASE_POST_MARK) {