Rename SingleThreadMarkAndSweep into SameThreadMarkAndSweep

This commit is contained in:
Alexander Shabalin
2021-06-03 13:18:42 +03:00
committed by Space
parent 9ebba93dd9
commit cf47d95aa5
8 changed files with 66 additions and 67 deletions

View File

@@ -279,18 +279,18 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
}
}
put(GARBAGE_COLLECTOR, when (arguments.gc) {
null -> GC.SINGLE_THREAD_MARK_SWEEP
null -> GC.SAME_THREAD_MARK_AND_SWEEP
"noop" -> {
assertGcSupported()
GC.NOOP
}
"stms" -> {
assertGcSupported()
GC.SINGLE_THREAD_MARK_SWEEP
GC.SAME_THREAD_MARK_AND_SWEEP
}
else -> {
configuration.report(ERROR, "Unsupported GC ${arguments.gc}")
GC.SINGLE_THREAD_MARK_SWEEP
GC.SAME_THREAD_MARK_AND_SWEEP
}
})
}

View File

@@ -7,5 +7,5 @@ package org.jetbrains.kotlin.backend.konan
enum class GC {
NOOP,
SINGLE_THREAD_MARK_SWEEP,
}
SAME_THREAD_MARK_AND_SWEEP,
}

View File

@@ -164,9 +164,9 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
MemoryModel.EXPERIMENTAL -> {
add("common_gc.bc")
when (gc) {
GC.SINGLE_THREAD_MARK_SWEEP -> {
GC.SAME_THREAD_MARK_AND_SWEEP -> {
add("experimental_memory_manager_stms.bc")
add("single_thread_ms_gc.bc")
add("same_thread_ms_gc.bc")
}
GC.NOOP -> {
add("experimental_memory_manager_noop.bc")

View File

@@ -44,7 +44,7 @@ bitcode {
"${target}ExperimentalMemoryManagerNoop",
"${target}ExperimentalMemoryManagerStms",
"${target}CommonGc",
"${target}SingleThreadMsGc",
"${target}SameThreadMsGc",
"${target}NoopGc"
)
includeRuntime()
@@ -126,7 +126,7 @@ bitcode {
includeRuntime()
}
create("single_thread_ms_gc", file("src/gc/stms")) {
create("same_thread_ms_gc", file("src/gc/stms")) {
headersDirs += files("src/gc/stms/cpp", "src/gc/common/cpp", "src/mm/cpp")
includeRuntime()
}
@@ -174,7 +174,7 @@ targetList.forEach { targetName ->
"${targetName}Runtime",
"${targetName}ExperimentalMemoryManagerStms",
"${targetName}CommonGc",
"${targetName}SingleThreadMsGc",
"${targetName}SameThreadMsGc",
"${targetName}Release",
"${targetName}Mimalloc",
"${targetName}OptAlloc"
@@ -192,7 +192,7 @@ targetList.forEach { targetName ->
"${targetName}Runtime",
"${targetName}ExperimentalMemoryManagerStms",
"${targetName}CommonGc",
"${targetName}SingleThreadMsGc",
"${targetName}SameThreadMsGc",
"${targetName}Release",
"${targetName}StdAlloc"
)

View File

@@ -6,12 +6,12 @@
#ifndef RUNTIME_GC_STMS_GC_H
#define RUNTIME_GC_STMS_GC_H
#include "SingleThreadMarkAndSweep.hpp"
#include "SameThreadMarkAndSweep.hpp"
namespace kotlin {
namespace gc {
using GC = kotlin::gc::SingleThreadMarkAndSweep;
using GC = kotlin::gc::SameThreadMarkAndSweep;
inline constexpr bool kSupportsMultipleMutators = true;

View File

@@ -3,7 +3,7 @@
* that can be found in the LICENSE file.
*/
#include "SingleThreadMarkAndSweep.hpp"
#include "SameThreadMarkAndSweep.hpp"
#include "GlobalData.hpp"
#include "MarkAndSweepUtils.hpp"
@@ -20,48 +20,48 @@ namespace {
struct MarkTraits {
static bool IsMarked(ObjHeader* object) noexcept {
auto& objectData = mm::ObjectFactory<gc::SingleThreadMarkAndSweep>::NodeRef::From(object).GCObjectData();
return objectData.color() == gc::SingleThreadMarkAndSweep::ObjectData::Color::kBlack;
auto& objectData = mm::ObjectFactory<gc::SameThreadMarkAndSweep>::NodeRef::From(object).GCObjectData();
return objectData.color() == gc::SameThreadMarkAndSweep::ObjectData::Color::kBlack;
}
static bool TryMark(ObjHeader* object) noexcept {
auto& objectData = mm::ObjectFactory<gc::SingleThreadMarkAndSweep>::NodeRef::From(object).GCObjectData();
if (objectData.color() == gc::SingleThreadMarkAndSweep::ObjectData::Color::kBlack) return false;
objectData.setColor(gc::SingleThreadMarkAndSweep::ObjectData::Color::kBlack);
auto& objectData = mm::ObjectFactory<gc::SameThreadMarkAndSweep>::NodeRef::From(object).GCObjectData();
if (objectData.color() == gc::SameThreadMarkAndSweep::ObjectData::Color::kBlack) return false;
objectData.setColor(gc::SameThreadMarkAndSweep::ObjectData::Color::kBlack);
return true;
};
};
struct SweepTraits {
using ObjectFactory = mm::ObjectFactory<gc::SingleThreadMarkAndSweep>;
using ObjectFactory = mm::ObjectFactory<gc::SameThreadMarkAndSweep>;
static bool TryResetMark(ObjectFactory::NodeRef node) noexcept {
auto& objectData = node.GCObjectData();
if (objectData.color() == gc::SingleThreadMarkAndSweep::ObjectData::Color::kWhite) return false;
objectData.setColor(gc::SingleThreadMarkAndSweep::ObjectData::Color::kWhite);
if (objectData.color() == gc::SameThreadMarkAndSweep::ObjectData::Color::kWhite) return false;
objectData.setColor(gc::SameThreadMarkAndSweep::ObjectData::Color::kWhite);
return true;
}
};
struct FinalizeTraits {
using ObjectFactory = mm::ObjectFactory<gc::SingleThreadMarkAndSweep>;
using ObjectFactory = mm::ObjectFactory<gc::SameThreadMarkAndSweep>;
};
} // namespace
void gc::SingleThreadMarkAndSweep::ThreadData::SafePointFunctionEpilogue() noexcept {
void gc::SameThreadMarkAndSweep::ThreadData::SafePointFunctionEpilogue() noexcept {
SafePointRegular(1);
}
void gc::SingleThreadMarkAndSweep::ThreadData::SafePointLoopBody() noexcept {
void gc::SameThreadMarkAndSweep::ThreadData::SafePointLoopBody() noexcept {
SafePointRegular(1);
}
void gc::SingleThreadMarkAndSweep::ThreadData::SafePointExceptionUnwind() noexcept {
void gc::SameThreadMarkAndSweep::ThreadData::SafePointExceptionUnwind() noexcept {
SafePointRegular(1);
}
void gc::SingleThreadMarkAndSweep::ThreadData::SafePointAllocation(size_t size) noexcept {
void gc::SameThreadMarkAndSweep::ThreadData::SafePointAllocation(size_t size) noexcept {
size_t allocationOverhead =
gc_.GetAllocationThresholdBytes() == 0 ? allocatedBytes_ : allocatedBytes_ % gc_.GetAllocationThresholdBytes();
if (threadData_.suspensionData().suspendIfRequested()) {
@@ -73,8 +73,8 @@ void gc::SingleThreadMarkAndSweep::ThreadData::SafePointAllocation(size_t size)
allocatedBytes_ += size;
}
void gc::SingleThreadMarkAndSweep::ThreadData::PerformFullGC() noexcept {
mm::ObjectFactory<gc::SingleThreadMarkAndSweep>::FinalizerQueue finalizerQueue;
void gc::SameThreadMarkAndSweep::ThreadData::PerformFullGC() noexcept {
mm::ObjectFactory<gc::SameThreadMarkAndSweep>::FinalizerQueue finalizerQueue;
{
// Switch state to native to simulate this thread being a GC thread.
// As a bonus, if we failed to suspend threads (which means some other thread asked for a GC),
@@ -94,11 +94,11 @@ void gc::SingleThreadMarkAndSweep::ThreadData::PerformFullGC() noexcept {
finalizerQueue.Finalize();
}
void gc::SingleThreadMarkAndSweep::ThreadData::OnOOM(size_t size) noexcept {
void gc::SameThreadMarkAndSweep::ThreadData::OnOOM(size_t size) noexcept {
PerformFullGC();
}
void gc::SingleThreadMarkAndSweep::ThreadData::SafePointRegular(size_t weight) noexcept {
void gc::SameThreadMarkAndSweep::ThreadData::SafePointRegular(size_t weight) noexcept {
size_t counterOverhead = gc_.GetThreshold() == 0 ? safePointsCounter_ : safePointsCounter_ % gc_.GetThreshold();
if (threadData_.suspensionData().suspendIfRequested()) {
safePointsCounter_ = 0;
@@ -109,7 +109,7 @@ void gc::SingleThreadMarkAndSweep::ThreadData::SafePointRegular(size_t weight) n
safePointsCounter_ += weight;
}
mm::ObjectFactory<gc::SingleThreadMarkAndSweep>::FinalizerQueue gc::SingleThreadMarkAndSweep::PerformFullGC() noexcept {
mm::ObjectFactory<gc::SameThreadMarkAndSweep>::FinalizerQueue gc::SameThreadMarkAndSweep::PerformFullGC() noexcept {
bool didSuspend = mm::SuspendThreads();
if (!didSuspend) {
// Somebody else suspended the threads, and so ran a GC.

View File

@@ -3,8 +3,8 @@
* that can be found in the LICENSE file.
*/
#ifndef RUNTIME_GC_STMS_SINGLE_THREAD_MARK_AND_SWEEP_H
#define RUNTIME_GC_STMS_SINGLE_THREAD_MARK_AND_SWEEP_H
#ifndef RUNTIME_GC_STMS_SAME_THREAD_MARK_AND_SWEEP_H
#define RUNTIME_GC_STMS_SAME_THREAD_MARK_AND_SWEEP_H
#include <cstddef>
@@ -21,8 +21,7 @@ class ThreadData;
namespace gc {
// Stop-the-world Mark-and-Sweep that runs on mutator threads. Can support targets that do not have threads.
// TODO: Rename it away from SingleThreadMarkAndSweep, but keep it STMS.
class SingleThreadMarkAndSweep : private Pinned {
class SameThreadMarkAndSweep : private Pinned {
public:
class ObjectData {
public:
@@ -41,9 +40,9 @@ public:
class ThreadData : private Pinned {
public:
using ObjectData = SingleThreadMarkAndSweep::ObjectData;
using ObjectData = SameThreadMarkAndSweep::ObjectData;
explicit ThreadData(SingleThreadMarkAndSweep& gc, mm::ThreadData& threadData) noexcept : gc_(gc), threadData_(threadData) {}
explicit ThreadData(SameThreadMarkAndSweep& gc, mm::ThreadData& threadData) noexcept : gc_(gc), threadData_(threadData) {}
~ThreadData() = default;
void SafePointFunctionEpilogue() noexcept;
@@ -58,14 +57,14 @@ public:
private:
void SafePointRegular(size_t weight) noexcept;
SingleThreadMarkAndSweep& gc_;
SameThreadMarkAndSweep& gc_;
mm::ThreadData& threadData_;
size_t allocatedBytes_ = 0;
size_t safePointsCounter_ = 0;
};
SingleThreadMarkAndSweep() noexcept {}
~SingleThreadMarkAndSweep() = default;
SameThreadMarkAndSweep() noexcept {}
~SameThreadMarkAndSweep() = default;
void SetThreshold(size_t value) noexcept { threshold_ = value; }
size_t GetThreshold() noexcept { return threshold_; }
@@ -77,7 +76,7 @@ public:
bool GetAutoTune() noexcept { return autoTune_; }
private:
mm::ObjectFactory<SingleThreadMarkAndSweep>::FinalizerQueue PerformFullGC() noexcept;
mm::ObjectFactory<SameThreadMarkAndSweep>::FinalizerQueue PerformFullGC() noexcept;
size_t threshold_ = 1000;
size_t allocationThresholdBytes_ = 10000;
@@ -87,4 +86,4 @@ private:
} // namespace gc
} // namespace kotlin
#endif // RUNTIME_GC_STMS_SINGLE_THREAD_MARK_AND_SWEEP_H
#endif // RUNTIME_GC_STMS_SAME_THREAD_MARK_AND_SWEEP_H

View File

@@ -3,7 +3,7 @@
* that can be found in the LICENSE file.
*/
#include "SingleThreadMarkAndSweep.hpp"
#include "SameThreadMarkAndSweep.hpp"
#include <condition_variable>
#include <future>
@@ -23,7 +23,7 @@
using namespace kotlin;
// These tests can only work if `GC` is `SingleThreadMarkAndSweep`.
// These tests can only work if `GC` is `SameThreadMarkAndSweep`.
// TODO: Extracting GC into a separate module will help with this.
namespace {
@@ -197,10 +197,10 @@ KStdVector<ObjHeader*> Alive(mm::ThreadData& threadData) {
return objects;
}
using Color = gc::SingleThreadMarkAndSweep::ObjectData::Color;
using Color = gc::SameThreadMarkAndSweep::ObjectData::Color;
Color GetColor(ObjHeader* objHeader) {
auto nodeRef = mm::ObjectFactory<gc::SingleThreadMarkAndSweep>::NodeRef::From(objHeader);
auto nodeRef = mm::ObjectFactory<gc::SameThreadMarkAndSweep>::NodeRef::From(objHeader);
return nodeRef.GCObjectData().color();
}
@@ -213,9 +213,9 @@ WeakCounter& InstallWeakCounter(mm::ThreadData& threadData, ObjHeader* objHeader
return weakCounter;
}
class SingleThreadMarkAndSweepTest : public testing::Test {
class SameThreadMarkAndSweepTest : public testing::Test {
public:
~SingleThreadMarkAndSweepTest() {
~SameThreadMarkAndSweepTest() {
mm::GlobalsRegistry::Instance().ClearForTests();
mm::GlobalData::Instance().objectFactory().ClearForTests();
}
@@ -228,7 +228,7 @@ private:
} // namespace
TEST_F(SingleThreadMarkAndSweepTest, RootSet) {
TEST_F(SameThreadMarkAndSweepTest, RootSet) {
RunInNewThread([](mm::ThreadData& threadData) {
GlobalObjectHolder global1{threadData};
GlobalObjectArrayHolder global2{threadData};
@@ -263,7 +263,7 @@ TEST_F(SingleThreadMarkAndSweepTest, RootSet) {
});
}
TEST_F(SingleThreadMarkAndSweepTest, InterconnectedRootSet) {
TEST_F(SameThreadMarkAndSweepTest, InterconnectedRootSet) {
RunInNewThread([](mm::ThreadData& threadData) {
GlobalObjectHolder global1{threadData};
GlobalObjectArrayHolder global2{threadData};
@@ -309,7 +309,7 @@ TEST_F(SingleThreadMarkAndSweepTest, InterconnectedRootSet) {
});
}
TEST_F(SingleThreadMarkAndSweepTest, FreeObjects) {
TEST_F(SameThreadMarkAndSweepTest, FreeObjects) {
RunInNewThread([](mm::ThreadData& threadData) {
auto& object1 = AllocateObject(threadData);
auto& object2 = AllocateObject(threadData);
@@ -324,7 +324,7 @@ TEST_F(SingleThreadMarkAndSweepTest, FreeObjects) {
});
}
TEST_F(SingleThreadMarkAndSweepTest, FreeObjectsWithFinalizers) {
TEST_F(SameThreadMarkAndSweepTest, FreeObjectsWithFinalizers) {
RunInNewThread([this](mm::ThreadData& threadData) {
auto& object1 = AllocateObjectWithFinalizer(threadData);
auto& object2 = AllocateObjectWithFinalizer(threadData);
@@ -341,7 +341,7 @@ TEST_F(SingleThreadMarkAndSweepTest, FreeObjectsWithFinalizers) {
});
}
TEST_F(SingleThreadMarkAndSweepTest, FreeObjectWithFreeWeak) {
TEST_F(SameThreadMarkAndSweepTest, FreeObjectWithFreeWeak) {
RunInNewThread([](mm::ThreadData& threadData) {
auto& object1 = AllocateObject(threadData);
auto& weak1 = ([&threadData, &object1]() -> WeakCounter& {
@@ -360,7 +360,7 @@ TEST_F(SingleThreadMarkAndSweepTest, FreeObjectWithFreeWeak) {
});
}
TEST_F(SingleThreadMarkAndSweepTest, FreeObjectWithHoldedWeak) {
TEST_F(SameThreadMarkAndSweepTest, FreeObjectWithHoldedWeak) {
RunInNewThread([](mm::ThreadData& threadData) {
auto& object1 = AllocateObject(threadData);
StackObjectHolder stack{threadData};
@@ -379,7 +379,7 @@ TEST_F(SingleThreadMarkAndSweepTest, FreeObjectWithHoldedWeak) {
});
}
TEST_F(SingleThreadMarkAndSweepTest, ObjectReferencedFromRootSet) {
TEST_F(SameThreadMarkAndSweepTest, ObjectReferencedFromRootSet) {
RunInNewThread([](mm::ThreadData& threadData) {
GlobalObjectHolder global{threadData};
StackObjectHolder stack{threadData};
@@ -419,7 +419,7 @@ TEST_F(SingleThreadMarkAndSweepTest, ObjectReferencedFromRootSet) {
});
}
TEST_F(SingleThreadMarkAndSweepTest, ObjectsWithCycles) {
TEST_F(SameThreadMarkAndSweepTest, ObjectsWithCycles) {
RunInNewThread([](mm::ThreadData& threadData) {
GlobalObjectHolder global{threadData};
StackObjectHolder stack{threadData};
@@ -468,7 +468,7 @@ TEST_F(SingleThreadMarkAndSweepTest, ObjectsWithCycles) {
});
}
TEST_F(SingleThreadMarkAndSweepTest, ObjectsWithCyclesAndFinalizers) {
TEST_F(SameThreadMarkAndSweepTest, ObjectsWithCyclesAndFinalizers) {
RunInNewThread([this](mm::ThreadData& threadData) {
GlobalObjectHolder global{threadData};
StackObjectHolder stack{threadData};
@@ -519,7 +519,7 @@ TEST_F(SingleThreadMarkAndSweepTest, ObjectsWithCyclesAndFinalizers) {
});
}
TEST_F(SingleThreadMarkAndSweepTest, ObjectsWithCyclesIntoRootSet) {
TEST_F(SameThreadMarkAndSweepTest, ObjectsWithCyclesIntoRootSet) {
RunInNewThread([](mm::ThreadData& threadData) {
GlobalObjectHolder global{threadData};
StackObjectHolder stack{threadData};
@@ -547,7 +547,7 @@ TEST_F(SingleThreadMarkAndSweepTest, ObjectsWithCyclesIntoRootSet) {
});
}
TEST_F(SingleThreadMarkAndSweepTest, RunGCTwice) {
TEST_F(SameThreadMarkAndSweepTest, RunGCTwice) {
RunInNewThread([](mm::ThreadData& threadData) {
GlobalObjectHolder global{threadData};
StackObjectHolder stack{threadData};
@@ -597,7 +597,7 @@ TEST_F(SingleThreadMarkAndSweepTest, RunGCTwice) {
});
}
TEST_F(SingleThreadMarkAndSweepTest, PermanentObjects) {
TEST_F(SameThreadMarkAndSweepTest, PermanentObjects) {
RunInNewThread([](mm::ThreadData& threadData) {
GlobalPermanentObjectHolder global1{threadData};
GlobalObjectHolder global2{threadData};
@@ -619,7 +619,7 @@ TEST_F(SingleThreadMarkAndSweepTest, PermanentObjects) {
});
}
TEST_F(SingleThreadMarkAndSweepTest, SameObjectInRootSet) {
TEST_F(SameThreadMarkAndSweepTest, SameObjectInRootSet) {
RunInNewThread([](mm::ThreadData& threadData) {
GlobalObjectHolder global{threadData};
StackObjectHolder stack(*global);
@@ -743,7 +743,7 @@ private:
} // namespace
TEST_F(SingleThreadMarkAndSweepTest, MultipleMutatorsCollect) {
TEST_F(SameThreadMarkAndSweepTest, MultipleMutatorsCollect) {
KStdVector<Mutator> mutators(kDefaultThreadCount);
KStdVector<ObjHeader*> globals(kDefaultThreadCount);
KStdVector<ObjHeader*> locals(kDefaultThreadCount);
@@ -799,7 +799,7 @@ TEST_F(SingleThreadMarkAndSweepTest, MultipleMutatorsCollect) {
}
}
TEST_F(SingleThreadMarkAndSweepTest, MultipleMutatorsAllCollect) {
TEST_F(SameThreadMarkAndSweepTest, MultipleMutatorsAllCollect) {
KStdVector<Mutator> mutators(kDefaultThreadCount);
KStdVector<ObjHeader*> globals(kDefaultThreadCount);
KStdVector<ObjHeader*> locals(kDefaultThreadCount);
@@ -849,7 +849,7 @@ TEST_F(SingleThreadMarkAndSweepTest, MultipleMutatorsAllCollect) {
}
}
TEST_F(SingleThreadMarkAndSweepTest, MultipleMutatorsAddToRootSetAfterCollectionRequested) {
TEST_F(SameThreadMarkAndSweepTest, MultipleMutatorsAddToRootSetAfterCollectionRequested) {
KStdVector<Mutator> mutators(kDefaultThreadCount);
KStdVector<ObjHeader*> globals(kDefaultThreadCount);
KStdVector<ObjHeader*> locals(kDefaultThreadCount);
@@ -921,7 +921,7 @@ TEST_F(SingleThreadMarkAndSweepTest, MultipleMutatorsAddToRootSetAfterCollection
}
}
TEST_F(SingleThreadMarkAndSweepTest, CrossThreadReference) {
TEST_F(SameThreadMarkAndSweepTest, CrossThreadReference) {
KStdVector<Mutator> mutators(kDefaultThreadCount);
KStdVector<ObjHeader*> globals(kDefaultThreadCount);
KStdVector<ObjHeader*> locals(kDefaultThreadCount);
@@ -987,7 +987,7 @@ TEST_F(SingleThreadMarkAndSweepTest, CrossThreadReference) {
}
}
TEST_F(SingleThreadMarkAndSweepTest, MultipleMutatorsWeaks) {
TEST_F(SameThreadMarkAndSweepTest, MultipleMutatorsWeaks) {
KStdVector<Mutator> mutators(kDefaultThreadCount);
ObjHeader* globalRoot = nullptr;
WeakCounter* weak = nullptr;