From 99e4ca65be1391d8f74e43ed9210b86d572a9cad Mon Sep 17 00:00:00 2001 From: Troels Bjerre Lund Date: Thu, 25 May 2023 12:48:30 +0000 Subject: [PATCH] [K/N] Fix GC stats reporting sweep in wrong epoch ^KT-55364 Co-authored-by: Troels Lund Merge-request: KOTLIN-MR-696 Merged-by: Alexander Shabalin --- kotlin-native/runtime/src/custom_alloc/cpp/ExtraObjectPage.hpp | 2 +- kotlin-native/runtime/src/custom_alloc/cpp/FixedBlockPage.hpp | 2 +- kotlin-native/runtime/src/custom_alloc/cpp/NextFitPage.hpp | 2 +- kotlin-native/runtime/src/custom_alloc/cpp/PageStore.hpp | 3 ++- .../runtime/src/custom_alloc/cpp/SingleObjectPage.hpp | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/kotlin-native/runtime/src/custom_alloc/cpp/ExtraObjectPage.hpp b/kotlin-native/runtime/src/custom_alloc/cpp/ExtraObjectPage.hpp index d666277d4be..8d5e5bb0983 100644 --- a/kotlin-native/runtime/src/custom_alloc/cpp/ExtraObjectPage.hpp +++ b/kotlin-native/runtime/src/custom_alloc/cpp/ExtraObjectPage.hpp @@ -37,7 +37,7 @@ class alignas(8) ExtraObjectPage { public: using GCSweepScope = gc::GCHandle::GCSweepExtraObjectsScope; - static GCSweepScope currentGCSweepScope() noexcept { return gc::GCHandle::currentEpoch()->sweepExtraObjects(); } + static GCSweepScope currentGCSweepScope(gc::GCHandle& handle) noexcept { return handle.sweepExtraObjects(); } static ExtraObjectPage* Create(uint32_t ignored) noexcept; diff --git a/kotlin-native/runtime/src/custom_alloc/cpp/FixedBlockPage.hpp b/kotlin-native/runtime/src/custom_alloc/cpp/FixedBlockPage.hpp index d2c9ac54e3e..80df4bce42e 100644 --- a/kotlin-native/runtime/src/custom_alloc/cpp/FixedBlockPage.hpp +++ b/kotlin-native/runtime/src/custom_alloc/cpp/FixedBlockPage.hpp @@ -32,7 +32,7 @@ class alignas(8) FixedBlockPage { public: using GCSweepScope = gc::GCHandle::GCSweepScope; - static GCSweepScope currentGCSweepScope() noexcept { return gc::GCHandle::currentEpoch()->sweep(); } + static GCSweepScope currentGCSweepScope(gc::GCHandle& handle) noexcept { return handle.sweep(); } static FixedBlockPage* Create(uint32_t blockSize) noexcept; diff --git a/kotlin-native/runtime/src/custom_alloc/cpp/NextFitPage.hpp b/kotlin-native/runtime/src/custom_alloc/cpp/NextFitPage.hpp index cd32d33ea3f..085ac5b6f0e 100644 --- a/kotlin-native/runtime/src/custom_alloc/cpp/NextFitPage.hpp +++ b/kotlin-native/runtime/src/custom_alloc/cpp/NextFitPage.hpp @@ -20,7 +20,7 @@ class alignas(8) NextFitPage { public: using GCSweepScope = gc::GCHandle::GCSweepScope; - static GCSweepScope currentGCSweepScope() noexcept { return gc::GCHandle::currentEpoch()->sweep(); } + static GCSweepScope currentGCSweepScope(gc::GCHandle& handle) noexcept { return handle.sweep(); } static NextFitPage* Create(uint32_t cellCount) noexcept; diff --git a/kotlin-native/runtime/src/custom_alloc/cpp/PageStore.hpp b/kotlin-native/runtime/src/custom_alloc/cpp/PageStore.hpp index 104fa49020d..831b7dfdfa8 100644 --- a/kotlin-native/runtime/src/custom_alloc/cpp/PageStore.hpp +++ b/kotlin-native/runtime/src/custom_alloc/cpp/PageStore.hpp @@ -48,9 +48,10 @@ public: used_.Push(page); return page; } + auto handle = gc::GCHandle::currentEpoch(); if ((page = unswept_.Pop())) { // If there're unswept_ pages, the GC is in progress. - GCSweepScope sweepHandle = T::currentGCSweepScope(); + GCSweepScope sweepHandle = T::currentGCSweepScope(*handle); if ((page = SweepSingle(sweepHandle, page, unswept_, used_, finalizerQueue))) { return page; } diff --git a/kotlin-native/runtime/src/custom_alloc/cpp/SingleObjectPage.hpp b/kotlin-native/runtime/src/custom_alloc/cpp/SingleObjectPage.hpp index 435013a5f36..51646a70c26 100644 --- a/kotlin-native/runtime/src/custom_alloc/cpp/SingleObjectPage.hpp +++ b/kotlin-native/runtime/src/custom_alloc/cpp/SingleObjectPage.hpp @@ -19,7 +19,7 @@ class alignas(8) SingleObjectPage { public: using GCSweepScope = gc::GCHandle::GCSweepScope; - static GCSweepScope currentGCSweepScope() noexcept { return gc::GCHandle::currentEpoch()->sweep(); } + static GCSweepScope currentGCSweepScope(gc::GCHandle& handle) noexcept { return handle.sweep(); } static SingleObjectPage* Create(uint64_t cellCount) noexcept;