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