Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Unified Diff: runtime/vm/heap.cc

Issue 2992753002: Prepares allocation for proper sync with mutator and bg threads. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/vm/heap.cc
diff --git a/runtime/vm/heap.cc b/runtime/vm/heap.cc
index eccf14fe5827583fa16be668d843e1e80dd5a389..ecfd2123b4ac2ec0fd0b14bce1d29982d849b3a9 100644
--- a/runtime/vm/heap.cc
+++ b/runtime/vm/heap.cc
@@ -57,7 +57,7 @@ Heap::~Heap() {
}
}
-void Heap::AbandonRemainingTLAB(Thread* thread) {
+void Heap::FillRemainingTLAB(Thread* thread) {
uword start = thread->top();
uword end = thread->end();
ASSERT(end >= start);
@@ -69,8 +69,11 @@ void Heap::AbandonRemainingTLAB(Thread* thread) {
if (size >= kObjectAlignment) {
FreeListElement::AsElement(start, size);
ASSERT(RawObject::FromAddr(start)->Size() == size);
- ASSERT((start + size) == new_space_.top());
}
+}
+
+void Heap::AbandonRemainingTLAB(Thread* thread) {
+ FillRemainingTLAB(thread);
thread->set_top(0);
thread->set_end(0);
}
@@ -84,6 +87,7 @@ uword Heap::AllocateNew(intptr_t size) {
ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0);
// Currently, only the Dart thread may allocate in new space.
isolate()->AssertCurrentThreadIsMutator();
+ ASSERT(Thread::Current()->IsMutatorThread());
rmacnak 2017/08/01 21:51:25 Isn't this the same as the line above?
danunez 2017/08/01 23:25:34 Yes it is. I will remove it.
Thread* thread = Thread::Current();
uword addr = new_space_.TryAllocateInTLAB(thread, size);
if (addr != 0) {
@@ -96,11 +100,14 @@ uword Heap::AllocateNew(intptr_t size) {
}
AbandonRemainingTLAB(thread);
+
+ // TODO(danunez): Lock for new space here
if (tlab_size > 0) {
uword tlab_top = new_space_.TryAllocateNewTLAB(thread, tlab_size);
if (tlab_top != 0) {
addr = new_space_.TryAllocateInTLAB(thread, size);
ASSERT(addr != 0);
+ // TODO(danunez): Unlock for new space here
return addr;
}
}
@@ -110,9 +117,16 @@ uword Heap::AllocateNew(intptr_t size) {
// This call to CollectGarbage might end up "reusing" a collection spawned
// from a different thread and will be racing to allocate the requested
// memory with other threads being released after the collection.
+
+ // TODO(danunez): Ensure that once we start collecting garbage, everything
+ // stops allocating.
+ // Safepoint should be dealing with this, but we need to make sure somehow.
CollectGarbage(kNew);
tlab_size = CalculateTLABSize();
uword tlab_top = new_space_.TryAllocateNewTLAB(thread, tlab_size);
+
+ // TODO(danunez): Unlock for new space here. Regardless of the outcome, we
+ // don't need the new space.
if (tlab_top != 0) {
addr = new_space_.TryAllocateInTLAB(thread, size);
// It is possible a GC doesn't clear enough space.

Powered by Google App Engine
This is Rietveld 408576698