| OLD | NEW |
| 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" | 10 #include "vm/hash_set.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 // Forward declarations. | 14 // Forward declarations. |
| 15 class Isolate; | 15 class Isolate; |
| 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 StoreBufferBlock() : top_(0) {} |
| 23 | 23 |
| 24 static int top_offset() { return OFFSET_OF(StoreBufferBlock, top_); } | 24 static int top_offset() { return OFFSET_OF(StoreBufferBlock, top_); } |
| 25 static int pointers_offset() { | 25 static int pointers_offset() { |
| 26 return OFFSET_OF(StoreBufferBlock, pointers_); | 26 return OFFSET_OF(StoreBufferBlock, pointers_); |
| 27 } | 27 } |
| 28 | 28 |
| 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 |
| 29 // Add a pointer to the block of pointers. The buffer will be processed if it | 39 // Add a pointer to the block of pointers. The buffer will be processed if it |
| 30 // has been filled by this operation. | 40 // has been filled by this operation. |
| 31 void AddPointer(uword pointer) { | 41 void AddPointer(uword pointer) { |
| 32 ASSERT(top_ < kSize); | 42 ASSERT(top_ < kSize); |
| 33 pointers_[top_++] = pointer; | 43 pointers_[top_++] = pointer; |
| 34 if (top_ == kSize) { | 44 if (top_ == kSize) { |
| 35 ProcessBuffer(); | 45 ProcessBuffer(); |
| 36 } | 46 } |
| 37 } | 47 } |
| 38 | 48 |
| 39 // Process this store buffer and remember its contents in the heap. | 49 // Process this store buffer and remember its contents in the heap. |
| 40 void ProcessBuffer(); | 50 void ProcessBuffer(); |
| 41 void ProcessBuffer(Isolate* isolate); | 51 void ProcessBuffer(Isolate* isolate); |
| 42 | 52 |
| 43 bool Contains(uword pointer); | 53 bool Contains(uword pointer); |
| 44 | 54 |
| 45 private: | 55 private: |
| 46 int32_t top_; | 56 int32_t top_; |
| 47 uword pointers_[kSize]; | 57 uword pointers_[kSize]; |
| 48 | 58 |
| 49 friend class StoreBuffer; | 59 friend class StoreBuffer; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(StoreBufferBlock); |
| 50 }; | 62 }; |
| 51 | 63 |
| 52 | 64 |
| 53 class StoreBuffer { | 65 class StoreBuffer { |
| 54 public: | 66 public: |
| 55 StoreBuffer() : dedup_sets_(new DedupSet()) {} | 67 // Simple linked list element containing a HashSet of old->new pointers. |
| 68 class DedupSet { |
| 69 public: |
| 70 enum { |
| 71 kSetSize = 1024, |
| 72 kFillRatio = 75 |
| 73 }; |
| 74 |
| 75 explicit DedupSet(DedupSet* next) |
| 76 : next_(next), set_(new HashSet(kSetSize, kFillRatio)) {} |
| 77 ~DedupSet() { |
| 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) {} |
| 56 ~StoreBuffer(); | 92 ~StoreBuffer(); |
| 57 | 93 |
| 94 void Reset(); |
| 95 |
| 58 void AddPointer(uword address); | 96 void AddPointer(uword address); |
| 59 | 97 |
| 60 void ProcessBlock(StoreBufferBlock* block); | 98 void ProcessBlock(StoreBufferBlock* block); |
| 61 | 99 |
| 100 DedupSet* DedupSets() { |
| 101 DedupSet* result = dedup_sets_; |
| 102 dedup_sets_ = new DedupSet(NULL); |
| 103 count_ = 1; |
| 104 return result; |
| 105 } |
| 106 |
| 62 private: | 107 private: |
| 63 // Simple linked list element containing a HashSet of old->new pointers. | 108 DedupSet* dedup_sets_; |
| 64 class DedupSet { | 109 intptr_t count_; |
| 65 public: | |
| 66 enum { | |
| 67 kSetSize = 1024, | |
| 68 kFillRatio = 80 | |
| 69 }; | |
| 70 | 110 |
| 71 DedupSet() : next_(NULL), set_(new HashSet(kSetSize, kFillRatio)) {} | 111 DISALLOW_COPY_AND_ASSIGN(StoreBuffer); |
| 72 ~DedupSet() { | |
| 73 delete set_; | |
| 74 } | |
| 75 | |
| 76 DedupSet* next_; | |
| 77 HashSet* set_; | |
| 78 | |
| 79 private: | |
| 80 DISALLOW_COPY_AND_ASSIGN(DedupSet); | |
| 81 }; | |
| 82 | |
| 83 DedupSet* dedup_sets_; | |
| 84 }; | 112 }; |
| 85 | 113 |
| 86 } // namespace dart | 114 } // namespace dart |
| 87 | 115 |
| 88 #endif // VM_STORE_BUFFER_H_ | 116 #endif // VM_STORE_BUFFER_H_ |
| OLD | NEW |