diff --git a/common_components/heap/ark_collector/ark_collector.h b/common_components/heap/ark_collector/ark_collector.h index 34c959ab60b950b670bc2d9e7dd92c0a7964c386..3ef15a68f5b013909828ec00cbb99aee6b1f43b3 100755 --- a/common_components/heap/ark_collector/ark_collector.h +++ b/common_components/heap/ark_collector/ark_collector.h @@ -19,6 +19,7 @@ #include #include "common_components/heap/allocator/region_space.h" +#include "common_components/heap/collector/copy_data_manager.h" #include "common_components/heap/collector/marking_collector.h" #include "common_interfaces/base_runtime.h" @@ -81,6 +82,11 @@ public: #endif } + void Fini() override + { + HeapBitmapManager::GetHeapBitmapManager().DestroyHeapBitmap(); + } + bool ShouldIgnoreRequest(GCRequest& request) override; bool MarkObject(BaseObject* obj) const override; diff --git a/common_components/heap/collector/copy_data_manager.cpp b/common_components/heap/collector/copy_data_manager.cpp index fb49d2dc01df11b56ae971aeda4afd3c559966f8..4aeec4197d115dc8095c1b2b18e64bd7ec169ec5 100755 --- a/common_components/heap/collector/copy_data_manager.cpp +++ b/common_components/heap/collector/copy_data_manager.cpp @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "base/common.h" #ifdef _WIN64 #include #include @@ -31,6 +32,7 @@ HeapBitmapManager& HeapBitmapManager::GetHeapBitmapManager() { return *forwardDa void HeapBitmapManager::InitializeHeapBitmap() { + DCHECK_CC(!initialized); size_t maxHeapBytes = Heap::GetHeap().GetMaxCapacity(); size_t heapBitmapSize = RoundUp(GetHeapBitmapSize(maxHeapBytes), COMMON_PAGE_SIZE); allHeapBitmapSize_ = heapBitmapSize; @@ -57,5 +59,21 @@ void HeapBitmapManager::InitializeHeapBitmap() heapBitmap_[0].InitializeMemory(heapBitmapStart_, heapBitmapSize, regionUnitCount_); os::PrctlSetVMA(startAddress, allHeapBitmapSize_, "ArkTS Heap CMCGC HeapBitMap"); + initialized = true; } + +void HeapBitmapManager::DestroyHeapBitmap() +{ +#ifdef _WIN64 + if (!VirtualFree(reinterpret_cast(heapBitmapStart_), 0, MEM_RELEASE)) { + LOG_COMMON(ERROR) << "VirtualFree error for HeapBitmapManager"; + } +#else + if (munmap(reinterpret_cast(heapBitmapStart_), allHeapBitmapSize_) != 0) { + LOG_COMMON(ERROR) << "munmap error for HeapBitmapManager"; + } +#endif + initialized = false; +} + } // namespace common diff --git a/common_components/heap/collector/copy_data_manager.h b/common_components/heap/collector/copy_data_manager.h index 1d1e386b497a1f52972ecb9af6775ee152c24cb1..74f3e508ea6238d4dd7ab1fa87b0832507b6eab2 100755 --- a/common_components/heap/collector/copy_data_manager.h +++ b/common_components/heap/collector/copy_data_manager.h @@ -16,6 +16,7 @@ #ifndef COMMON_COMPONENTS_HEAP_COLLECTOR_COPY_DATA_MANAGER_H #define COMMON_COMPONENTS_HEAP_COLLECTOR_COPY_DATA_MANAGER_H +#include "base/common.h" #include "common_components/base/immortal_wrapper.h" #include "common_components/heap/heap.h" #if defined(__linux__) || defined(PANDA_TARGET_OHOS) || defined(__APPLE__) @@ -123,20 +124,13 @@ public: HeapBitmapManager() = default; ~HeapBitmapManager() { -#ifdef _WIN64 - if (!VirtualFree(reinterpret_cast(heapBitmapStart_), 0, MEM_RELEASE)) { - LOG_COMMON(ERROR) << "VirtualFree error for HeapBitmapManager"; - } -#else - if (munmap(reinterpret_cast(heapBitmapStart_), allHeapBitmapSize_) != 0) { - LOG_COMMON(ERROR) << "munmap error for HeapBitmapManager"; - } -#endif + CHECK_CC(!initialized); } static HeapBitmapManager& GetHeapBitmapManager(); void InitializeHeapBitmap(); + void DestroyHeapBitmap(); void ClearHeapBitmap() { heapBitmap_[0].ReleaseMemory(); } @@ -168,6 +162,7 @@ private: size_t regionUnitCount_ = 0; uintptr_t heapBitmapStart_ = 0; size_t allHeapBitmapSize_ = 0; + bool initialized = false; }; } // namespace common #endif // COMMON_COMPONENTS_HEAP_COLLECTOR_COPY_DATA_MANAGER_H