[K/N] Do not CAS when marking newly allocated object

Merge-request: KT-MR-12038
Merged-by: Alexey Glushko <aleksei.glushko@jetbrains.com>
This commit is contained in:
Aleksei.Glushko
2023-09-09 12:42:54 +00:00
committed by Space Team
parent 2f22b0a6b0
commit 6405a174e2
2 changed files with 10 additions and 3 deletions
@@ -68,8 +68,7 @@ ALWAYS_INLINE void gc::BarriersThreadData::onAllocation(ObjHeader* allocated) {
RuntimeAssert(shouldMark == barriersEnabled, "New allocations marking must happen with and only with weak ref barriers");
if (shouldMark) {
auto& objectData = alloc::objectDataForObject(allocated);
bool wasUnmarked = objectData.tryMark();
RuntimeAssert(wasUnmarked, "No one else could mark this newly allocated object before");
objectData.markUncontended();
markHandle_->addObject();
}
}
@@ -16,8 +16,16 @@
namespace kotlin::gc {
class GC::ObjectData {
static constexpr intptr_t kNoQueueMark = 1;
public:
bool tryMark() noexcept { return trySetNext(reinterpret_cast<ObjectData*>(1)); }
bool tryMark() noexcept { return trySetNext(reinterpret_cast<ObjectData*>(kNoQueueMark)); }
void markUncontended() noexcept {
RuntimeAssert(!marked(), "Must not be marked previously");
auto nextVal = reinterpret_cast<ObjectData*>(kNoQueueMark);
setNext(nextVal);
RuntimeAssert(next() == nextVal, "Non-atomic marking must not be contended");
}
bool marked() const noexcept { return next() != nullptr; }