Fix race condition new regions in AllocNonVirtual
Fixed a race condition where a thread could race ahead of the
allocating thread in RegionSpace::AllocNonvirtual and fill the region
before the thread that allocated the region managed to allocate it's
object.
Bug: 63153464
Test: test-art-host
Change-Id: Id0d0e0ac7cdbce6f082234fa82068d8c6c3c7c9e
diff --git a/runtime/gc/space/region_space-inl.h b/runtime/gc/space/region_space-inl.h
index 82e8f20..2e67f34 100644
--- a/runtime/gc/space/region_space-inl.h
+++ b/runtime/gc/space/region_space-inl.h
@@ -66,13 +66,15 @@
}
Region* r = AllocateRegion(kForEvac);
if (LIKELY(r != nullptr)) {
+ obj = r->Alloc(num_bytes, bytes_allocated, usable_size, bytes_tl_bulk_allocated);
+ CHECK(obj != nullptr);
+ // Do our allocation before setting the region, this makes sure no threads race ahead
+ // and fill in the region before we allocate the object. b/63153464
if (kForEvac) {
evac_region_ = r;
} else {
current_region_ = r;
}
- obj = r->Alloc(num_bytes, bytes_allocated, usable_size, bytes_tl_bulk_allocated);
- CHECK(obj != nullptr);
return obj;
}
} else {