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

Unified Diff: runtime/vm/scavenger.cc

Issue 2992753002: Prepares allocation for proper sync with mutator and bg threads. (Closed)
Patch Set: Adds thread locking to functions that iterate over threads Created 3 years, 4 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
« no previous file with comments | « runtime/vm/scavenger.h ('k') | runtime/vm/thread_registry.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/scavenger.cc
diff --git a/runtime/vm/scavenger.cc b/runtime/vm/scavenger.cc
index 0a17e7343cf51132d4ab91a596e5ad1082e745e1..380d8234f2e125c76f530a34a990692c68f935eb 100644
--- a/runtime/vm/scavenger.cc
+++ b/runtime/vm/scavenger.cc
@@ -324,7 +324,8 @@ Scavenger::Scavenger(Heap* heap,
gc_time_micros_(0),
collections_(0),
external_size_(0),
- failed_to_promote_(false) {
+ failed_to_promote_(false),
+ space_lock_(new Mutex()) {
// Verify assumptions about the first word in objects which the scavenger is
// going to use for forwarding pointers.
ASSERT(Object::tags_offset() == 0);
@@ -355,6 +356,7 @@ Scavenger::Scavenger(Heap* heap,
Scavenger::~Scavenger() {
ASSERT(!scavenging_);
to_->Delete();
+ delete space_lock_;
}
intptr_t Scavenger::NewSizeInWords(intptr_t old_size_in_words) const {
@@ -715,49 +717,50 @@ void Scavenger::ProcessWeakReferences() {
}
}
-uword Scavenger::FlushTLS() const {
- ASSERT(heap_ != NULL);
- uword saved_top = top_;
- if (heap_->isolate()->IsMutatorThreadScheduled() && !scavenging_) {
- Thread* mutator_thread = heap_->isolate()->mutator_thread();
- saved_top = mutator_thread->heap()->new_space()->top();
- if (mutator_thread->HasActiveTLAB()) {
- ASSERT(mutator_thread->top() <=
- mutator_thread->heap()->new_space()->top());
- mutator_thread->heap()->new_space()->set_top(mutator_thread->top());
+void Scavenger::MakeALLTLABsIterable(Isolate* isolate) const {
rmacnak 2017/08/02 20:50:59 All (lowercase Ls)
+ MonitorLocker ml(isolate->threads_lock(), false);
+ Thread* current = heap_->isolate()->thread_registry()->active_list();
+ while (current != NULL) {
+ if (current->HasActiveTLAB()) {
+ heap_->MakeTLABIterable(current);
}
+ current = current->next();
}
- return saved_top;
}
-void Scavenger::UnflushTLS(uword value) const {
+void Scavenger::FlushTLS() const {
ASSERT(heap_ != NULL);
- if (heap_->isolate()->IsMutatorThreadScheduled() && !scavenging_) {
- Thread* mutator_thread = heap_->isolate()->mutator_thread();
- mutator_thread->heap()->new_space()->set_top(value);
- ASSERT(mutator_thread->top() <= mutator_thread->heap()->new_space()->top());
+ if (!scavenging_) {
+ MakeALLTLABsIterable(heap_->isolate());
+ }
+}
+
+void Scavenger::AbandonAllTLABs(Isolate* isolate) {
+ MonitorLocker ml(isolate->threads_lock(), false);
+ Thread* current = isolate->thread_registry()->active_list();
+ while (current != NULL) {
+ heap_->AbandonRemainingTLAB(current);
+ current = current->next();
}
}
void Scavenger::VisitObjectPointers(ObjectPointerVisitor* visitor) const {
- uword saved_top = FlushTLS();
+ FlushTLS();
uword cur = FirstObjectStart();
while (cur < top_) {
RawObject* raw_obj = RawObject::FromAddr(cur);
cur += raw_obj->VisitPointers(visitor);
}
- UnflushTLS(saved_top);
}
void Scavenger::VisitObjects(ObjectVisitor* visitor) const {
- uword saved_top = FlushTLS();
+ FlushTLS();
uword cur = FirstObjectStart();
while (cur < top_) {
RawObject* raw_obj = RawObject::FromAddr(cur);
visitor->VisitObject(raw_obj);
cur += raw_obj->Size();
}
- UnflushTLS(saved_top);
}
void Scavenger::AddRegionsToObjectSet(ObjectSet* set) const {
@@ -766,21 +769,19 @@ void Scavenger::AddRegionsToObjectSet(ObjectSet* set) const {
RawObject* Scavenger::FindObject(FindObjectVisitor* visitor) const {
ASSERT(!scavenging_);
- uword saved_top = FlushTLS();
+ FlushTLS();
uword cur = FirstObjectStart();
if (visitor->VisitRange(cur, top_)) {
while (cur < top_) {
RawObject* raw_obj = RawObject::FromAddr(cur);
uword next = cur + raw_obj->Size();
if (visitor->VisitRange(cur, next) && raw_obj->FindObject(visitor)) {
- UnflushTLS(saved_top);
return raw_obj; // Found object, return it.
}
cur = next;
}
ASSERT(cur == top_);
}
- UnflushTLS(saved_top);
return Object::null();
}
@@ -815,12 +816,7 @@ void Scavenger::Scavenge(bool invoke_api_callbacks) {
int64_t post_safe_point = OS::GetCurrentMonotonicMicros();
heap_->RecordTime(kSafePoint, post_safe_point - pre_safe_point);
- if (isolate->IsMutatorThreadScheduled()) {
- Thread* mutator_thread = isolate->mutator_thread();
- if (mutator_thread->HasActiveTLAB()) {
- heap_->AbandonRemainingTLAB(mutator_thread);
- }
- }
+ AbandonAllTLABs(isolate);
// TODO(koda): Make verification more compatible with concurrent sweep.
if (FLAG_verify_before_gc && !FLAG_concurrent_sweep) {
@@ -948,10 +944,25 @@ void Scavenger::Evacuate() {
ASSERT((UsedInWords() == 0) || failed_to_promote_);
}
+uword Scavenger::FindTopOfSpace(Isolate* isolate) const {
+ MonitorLocker ml(isolate->threads_lock(), false);
+ Thread* current = heap_->isolate()->thread_registry()->active_list();
+ uword furthest_addr = 0;
+ while (current != NULL) {
+ if (current->HasActiveTLAB() && current->top() > furthest_addr) {
+ furthest_addr = current->top();
+ }
+ current = current->next();
+ }
+ if (furthest_addr == 0) {
+ return top_;
+ }
+ return furthest_addr;
+}
+
int64_t Scavenger::UsedInWords() const {
- uword saved_top = FlushTLS();
- int64_t used_in_words = (top_ - FirstObjectStart()) >> kWordSizeLog2;
- UnflushTLS(saved_top);
+ uword top_of_space = FindTopOfSpace(heap_->isolate());
+ int64_t used_in_words = (top_of_space - FirstObjectStart()) >> kWordSizeLog2;
return used_in_words;
}
« no previous file with comments | « runtime/vm/scavenger.h ('k') | runtime/vm/thread_registry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698