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

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

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/scavenger.cc ('k') | runtime/vm/store_buffer.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 #ifndef VM_STORE_BUFFER_H_ 5 #ifndef VM_STORE_BUFFER_H_
6 #define VM_STORE_BUFFER_H_ 6 #define VM_STORE_BUFFER_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/globals.h" 9 #include "vm/globals.h"
10 #include "vm/hash_set.h"
11 10
12 namespace dart { 11 namespace dart {
13 12
14 // Forward declarations. 13 // Forward declarations.
15 class Isolate; 14 class Isolate;
15 class RawObject;
16 16
17 class StoreBufferBlock { 17 class StoreBufferBlock {
18 public: 18 public:
19 // Each block contains kSize pointers. 19 // Each block contains kSize pointers.
20 static const int32_t kSize = 1024; 20 static const int32_t kSize = 1024;
21 21
22 StoreBufferBlock() : top_(0) {} 22 explicit StoreBufferBlock(StoreBufferBlock* next) : next_(next), top_(0) {}
23
24 void Reset() { top_ = 0; }
25
26 StoreBufferBlock* next() const { return next_; }
27
28 intptr_t Count() const { return top_; }
29
30 RawObject* At(intptr_t i) const {
31 ASSERT(i >= 0);
32 ASSERT(i < top_);
33 return pointers_[i];
34 }
23 35
24 static int top_offset() { return OFFSET_OF(StoreBufferBlock, top_); } 36 static int top_offset() { return OFFSET_OF(StoreBufferBlock, top_); }
25 static int pointers_offset() { 37 static int pointers_offset() {
26 return OFFSET_OF(StoreBufferBlock, pointers_); 38 return OFFSET_OF(StoreBufferBlock, pointers_);
27 } 39 }
28 40
29 void Reset() { top_ = 0; }
30
31 intptr_t Count() const { return top_; }
32
33 uword At(intptr_t i) const {
34 ASSERT(i >= 0);
35 ASSERT(i < top_);
36 return pointers_[i];
37 }
38
39 // Add a pointer to the block of pointers. The buffer will be processed if it
40 // has been filled by this operation.
41 void AddPointer(uword pointer) {
42 ASSERT(top_ < kSize);
43 pointers_[top_++] = pointer;
44 if (top_ == kSize) {
45 ProcessBuffer();
46 }
47 }
48
49 // Process this store buffer and remember its contents in the heap.
50 void ProcessBuffer();
51 void ProcessBuffer(Isolate* isolate);
52
53 bool Contains(uword pointer);
54
55 private: 41 private:
42 StoreBufferBlock* next_;
56 int32_t top_; 43 int32_t top_;
57 uword pointers_[kSize]; 44 RawObject* pointers_[kSize];
58 45
59 friend class StoreBuffer; 46 friend class StoreBuffer;
60 47
61 DISALLOW_COPY_AND_ASSIGN(StoreBufferBlock); 48 DISALLOW_COPY_AND_ASSIGN(StoreBufferBlock);
62 }; 49 };
63 50
64 51
65 class StoreBuffer { 52 class StoreBuffer {
66 public: 53 public:
67 // Simple linked list element containing a HashSet of old->new pointers. 54 StoreBuffer() : blocks_(new StoreBufferBlock(NULL)), full_count_(0) {}
68 class DedupSet { 55 ~StoreBuffer();
69 public:
70 enum {
71 kSetSize = 1024,
72 kFillRatio = 75
73 };
74 56
75 explicit DedupSet(DedupSet* next) 57 intptr_t Count() const {
76 : next_(next), set_(new HashSet(kSetSize, kFillRatio)) {} 58 return blocks_->Count() + (full_count_ * StoreBufferBlock::kSize);
77 ~DedupSet() { 59 }
78 delete set_;
79 }
80
81 DedupSet* next() const { return next_; }
82 HashSet* set() const { return set_; }
83
84 private:
85 DedupSet* next_;
86 HashSet* set_;
87
88 DISALLOW_COPY_AND_ASSIGN(DedupSet);
89 };
90
91 StoreBuffer() : dedup_sets_(new DedupSet(NULL)), count_(1) {}
92 ~StoreBuffer();
93 60
94 void Reset(); 61 void Reset();
95 62
96 void AddPointer(uword address); 63 void AddObject(RawObject* obj) {
64 StoreBufferBlock* block = blocks_;
65 ASSERT(block->top_ < StoreBufferBlock::kSize);
66 block->pointers_[block->top_++] = obj;
67 if (block->top_ == StoreBufferBlock::kSize) {
68 Expand(true);
69 }
70 }
97 71
98 // Drain StoreBufferBlock into deduplication sets. 72 void AddObjectGC(RawObject* obj) {
99 // Returns true if new sets were created. 73 StoreBufferBlock* block = blocks_;
100 bool DrainBlock(StoreBufferBlock* block); 74 ASSERT(block->top_ < StoreBufferBlock::kSize);
75 block->pointers_[block->top_++] = obj;
76 if (block->top_ == StoreBufferBlock::kSize) {
77 Expand(false);
78 }
79 }
101 80
102 // Drain StoreBufferBlock into deduplication sets. 81 StoreBufferBlock* Blocks() {
103 // Schedule an interrupt if we run over the max number of deduplication sets. 82 StoreBufferBlock* result = blocks_;
104 void ProcessBlock(StoreBufferBlock* block); 83 blocks_ = new StoreBufferBlock(NULL);
105 84 full_count_ = 0;
106 DedupSet* DedupSets() {
107 DedupSet* result = dedup_sets_;
108 dedup_sets_ = new DedupSet(NULL);
109 count_ = 1;
110 return result; 85 return result;
111 } 86 }
112 87
88 // Expand the storage and optionally check whethe to schedule an interrupt.
89 void Expand(bool check);
90
91 bool Contains(RawObject* raw);
92
93 static int blocks_offset() { return OFFSET_OF(StoreBuffer, blocks_); }
94
113 private: 95 private:
114 // Add pointer to deduplication sets. Returns true if the current set is full
115 // and a new set was created.
116 bool AddPointerInternal(uword address);
117
118 // Check if we run over the max number of deduplication sets. 96 // Check if we run over the max number of deduplication sets.
119 // If we did schedule an interrupt. 97 // If we did schedule an interrupt.
120 void CheckThreshold(); 98 void CheckThreshold();
121 99
122 DedupSet* dedup_sets_; 100 StoreBufferBlock* blocks_;
123 intptr_t count_; 101 intptr_t full_count_;
124 102
125 DISALLOW_COPY_AND_ASSIGN(StoreBuffer); 103 DISALLOW_COPY_AND_ASSIGN(StoreBuffer);
126 }; 104 };
127 105
128 } // namespace dart 106 } // namespace dart
129 107
130 #endif // VM_STORE_BUFFER_H_ 108 #endif // VM_STORE_BUFFER_H_
OLDNEW
« no previous file with comments | « runtime/vm/scavenger.cc ('k') | runtime/vm/store_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698