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

Unified Diff: runtime/vm/scavenger.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/scavenger.cc
diff --git a/runtime/vm/scavenger.cc b/runtime/vm/scavenger.cc
index 336f9c9cc156b2ab953259ed43561f9e988f8419..bf07ea22962bee8113f14db284c4d9f5972bb796 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,16 +717,28 @@ void Scavenger::ProcessWeakReferences() {
}
}
+uword Scavenger::FindTopOfSpace(Isolate* isolate) const {
+ Thread* current = heap_->isolate()->thread_registry()->active_list();
+ uword furthest_addr = 0;
rmacnak 2017/08/01 21:51:25 If we make all outstanding TLABs walkable, everyth
danunez 2017/08/01 23:25:34 That make sense. However, I am going to split this
+ while (current != NULL) {
+ if (current->HasActiveTLAB() && current->top() > furthest_addr) {
+ furthest_addr = current->top();
+ heap_->FillRemainingTLAB(current);
+ }
+ current = current->next();
+ }
+ return furthest_addr;
+}
+
uword Scavenger::FlushTLS() const {
ASSERT(heap_ != NULL);
rmacnak 2017/08/01 21:51:25 Per comment above, I think this could be replaced
danunez 2017/08/01 23:25:34 Done.
uword saved_top = top_;
- if (heap_->isolate()->IsMutatorThreadScheduled() && !scavenging_) {
+ if (!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());
+ uword furthest_addr = FindTopOfSpace(heap_->isolate());
+ if (furthest_addr > 0) {
+ ASSERT(furthest_addr <= mutator_thread->heap()->new_space()->top());
+ mutator_thread->heap()->new_space()->set_top(furthest_addr);
}
}
return saved_top;
@@ -739,6 +753,14 @@ void Scavenger::UnflushTLS(uword value) const {
}
}
+void Scavenger::AbandonAllTLABs() {
+ Thread* current = heap_->isolate()->thread_registry()->active_list();
+ while (current != NULL) {
+ heap_->AbandonRemainingTLAB(current);
+ current = current->next();
+ }
+}
+
void Scavenger::VisitObjectPointers(ObjectPointerVisitor* visitor) const {
uword saved_top = FlushTLS();
uword cur = FirstObjectStart();
@@ -815,12 +837,9 @@ 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);
- }
- }
+ // TODO(danunez): Abandon all threads' TLABs. Every thread should be stopped
+ // here anyway.
+ AbandonAllTLABs();
// TODO(koda): Make verification more compatible with concurrent sweep.
if (FLAG_verify_before_gc && !FLAG_concurrent_sweep) {
« runtime/vm/heap.cc ('K') | « 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