[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:
committed by
Space Team
parent
2f22b0a6b0
commit
6405a174e2
@@ -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; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user