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

Side by Side Diff: runtime/vm/store_buffer.cc

Issue 1259223005: Safepoint interface and unit tests. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add comment about overflow. Created 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/store_buffer.h" 5 #include "vm/store_buffer.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/lockers.h" 8 #include "vm/lockers.h"
9 #include "vm/runtime_entry.h" 9 #include "vm/runtime_entry.h"
10 10
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 MutexLocker ml(mutex_); 71 MutexLocker ml(mutex_);
72 full_.Push(block); 72 full_.Push(block);
73 } else if (block->IsEmpty()) { 73 } else if (block->IsEmpty()) {
74 MutexLocker ml(global_mutex_); 74 MutexLocker ml(global_mutex_);
75 global_empty_->Push(block); 75 global_empty_->Push(block);
76 TrimGlobalEmpty(); 76 TrimGlobalEmpty();
77 } else { 77 } else {
78 MutexLocker ml(mutex_); 78 MutexLocker ml(mutex_);
79 partial_.Push(block); 79 partial_.Push(block);
80 } 80 }
81 if (check_threshold) { 81 if (check_threshold && Overflowed()) {
82 MutexLocker ml(mutex_); 82 MutexLocker ml(mutex_);
83 CheckThresholdNonEmpty(); 83 Isolate* isolate = Isolate::Current();
84 // Sanity check: it makes no sense to schedule the GC in another isolate.
85 // (If Isolate ever gets multiple store buffers, we should avoid this
86 // coupling by passing in an explicit callback+parameter at construction.)
87 ASSERT(isolate->store_buffer() == this);
88 isolate->ScheduleInterrupts(Isolate::kVMInterrupt);
84 } 89 }
85 } 90 }
86 91
87 92
88 StoreBufferBlock* StoreBuffer::PopBlock() { 93 StoreBufferBlock* StoreBuffer::PopBlock() {
89 { 94 {
90 MutexLocker ml(mutex_); 95 MutexLocker ml(mutex_);
91 if (!partial_.IsEmpty()) { 96 if (!partial_.IsEmpty()) {
92 return partial_.Pop(); 97 return partial_.Pop();
93 } 98 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 137
133 138
134 void StoreBuffer::List::Push(StoreBufferBlock* block) { 139 void StoreBuffer::List::Push(StoreBufferBlock* block) {
135 ASSERT(block->next_ == NULL); 140 ASSERT(block->next_ == NULL);
136 block->next_ = head_; 141 block->next_ = head_;
137 head_ = block; 142 head_ = block;
138 ++length_; 143 ++length_;
139 } 144 }
140 145
141 146
142 void StoreBuffer::CheckThresholdNonEmpty() { 147 bool StoreBuffer::Overflowed() {
143 DEBUG_ASSERT(mutex_->IsOwnedByCurrentThread()); 148 MutexLocker ml(mutex_);
144 if (full_.length() + partial_.length() > kMaxNonEmpty) { 149 return (full_.length() + partial_.length()) > kMaxNonEmpty;
145 Isolate* isolate = Isolate::Current();
146 // Sanity check: it makes no sense to schedule the GC in another isolate.
147 // (If Isolate ever gets multiple store buffers, we should avoid this
148 // coupling by passing in an explicit callback+parameter at construction.)
149 ASSERT(isolate->store_buffer() == this);
150 isolate->ScheduleInterrupts(Isolate::kStoreBufferInterrupt);
151 }
152 } 150 }
153 151
154 152
155 void StoreBuffer::TrimGlobalEmpty() { 153 void StoreBuffer::TrimGlobalEmpty() {
156 DEBUG_ASSERT(global_mutex_->IsOwnedByCurrentThread()); 154 DEBUG_ASSERT(global_mutex_->IsOwnedByCurrentThread());
157 while (global_empty_->length() > kMaxGlobalEmpty) { 155 while (global_empty_->length() > kMaxGlobalEmpty) {
158 delete global_empty_->Pop(); 156 delete global_empty_->Pop();
159 } 157 }
160 } 158 }
161 159
162 } // namespace dart 160 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698