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

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

Issue 14307013: - Remember the fact that an object has been added to the (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/store_buffer.h ('k') | runtime/vm/stub_code_arm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/runtime_entry.h" 8 #include "vm/runtime_entry.h"
9 9
10 namespace dart { 10 namespace dart {
11 11
12 DEFINE_LEAF_RUNTIME_ENTRY(void, StoreBufferBlockProcess, Isolate* isolate) { 12 DEFINE_LEAF_RUNTIME_ENTRY(void, StoreBufferBlockProcess, Isolate* isolate) {
13 isolate->store_buffer_block()->ProcessBuffer(isolate); 13 StoreBuffer* buffer = isolate->store_buffer();
14 buffer->Expand(true);
14 } 15 }
15 END_LEAF_RUNTIME_ENTRY 16 END_LEAF_RUNTIME_ENTRY
16 17
17 18
18 void StoreBufferBlock::ProcessBuffer() { 19 StoreBuffer::~StoreBuffer() {
19 ProcessBuffer(Isolate::Current()); 20 StoreBufferBlock* block = blocks_;
21 blocks_ = NULL;
22 while (block != NULL) {
23 StoreBufferBlock* next = block->next();
24 delete block;
25 block = next;
26 }
20 } 27 }
21 28
22 29
23 void StoreBufferBlock::ProcessBuffer(Isolate* isolate) { 30 void StoreBuffer::Reset() {
24 isolate->store_buffer()->ProcessBlock(this); 31 StoreBufferBlock* block = blocks_->next_;
32 while (block != NULL) {
33 StoreBufferBlock* next = block->next_;
34 delete block;
35 block = next;
36 }
37 blocks_->next_ = NULL;
38 blocks_->top_ = 0;
39 full_count_ = 0;
25 } 40 }
26 41
27 42
28 bool StoreBufferBlock::Contains(uword pointer) { 43 bool StoreBuffer::Contains(RawObject* raw) {
29 for (int32_t i = 0; i < top_; i++) { 44 StoreBufferBlock* block = blocks_;
30 if (pointers_[i] == pointer) { 45 while (block != NULL) {
31 return true; 46 intptr_t count = block->Count();
47 for (intptr_t i = 0; i < count; i++) {
48 if (block->At(i) == raw) {
49 return true;
50 }
32 } 51 }
52 block = block->next_;
33 } 53 }
34 return false; 54 return false;
35 } 55 }
36 56
37 57
38 StoreBuffer::~StoreBuffer() { 58 void StoreBuffer::Expand(bool check) {
39 DedupSet* current = dedup_sets_; 59 ASSERT(blocks_->Count() == StoreBufferBlock::kSize);
40 dedup_sets_ = NULL; 60 blocks_ = new StoreBufferBlock(blocks_);
41 while (current != NULL) { 61 full_count_++;
42 DedupSet* next = current->next(); 62 if (check) {
43 delete current;
44 current = next;
45 }
46 }
47
48
49 void StoreBuffer::Reset() {
50 DedupSet* current = DedupSets();
51 while (current != NULL) {
52 DedupSet* next = current->next();
53 delete current;
54 current = next;
55 }
56 }
57
58
59 bool StoreBuffer::AddPointerInternal(uword address) {
60 ASSERT(dedup_sets_ != NULL);
61 ASSERT(Isolate::Current()->heap()->OldContains(address));
62 ASSERT((address & kSmiTagMask) != kSmiTag);
63 if (!dedup_sets_->set()->Add(address)) {
64 // Add a new DedupSet.
65 dedup_sets_ = new DedupSet(dedup_sets_);
66 count_++;
67 return true;
68 }
69 return false;
70 }
71
72
73 void StoreBuffer::AddPointer(uword address) {
74 if (AddPointerInternal(address)) {
75 // Had to create a new DedupSet.
76 CheckThreshold(); 63 CheckThreshold();
77 } 64 }
78 } 65 }
79 66
80 67
81 bool StoreBuffer::DrainBlock(StoreBufferBlock* block) {
82 const intptr_t old_count = count_;
83 intptr_t entries = block->Count();
84 for (intptr_t i = 0; i < entries; i++) {
85 AddPointerInternal(block->At(i));
86 }
87 block->Reset();
88 return (count_ > old_count);
89 }
90
91
92 void StoreBuffer::CheckThreshold() { 68 void StoreBuffer::CheckThreshold() {
93 // Schedule an interrupt if we have run over the max number of DedupSets. 69 // Schedule an interrupt if we have run over the max number of
70 // StoreBufferBlocks.
94 // TODO(iposva): Fix magic number. 71 // TODO(iposva): Fix magic number.
95 if (count_ > 100) { 72 if (full_count_ > 100) {
96 Isolate::Current()->ScheduleInterrupts(Isolate::kStoreBufferInterrupt); 73 Isolate::Current()->ScheduleInterrupts(Isolate::kStoreBufferInterrupt);
97 } 74 }
98 } 75 }
99 76
100
101 void StoreBuffer::ProcessBlock(StoreBufferBlock* block) {
102 if (DrainBlock(block)) {
103 CheckThreshold();
104 }
105 }
106
107 } // namespace dart 77 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/store_buffer.h ('k') | runtime/vm/stub_code_arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698