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

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

Issue 11428067: Merge the Merlin heap tracing to top-of-trunk. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address review comments Created 8 years 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/heap_trace_test.cc ('k') | runtime/vm/pages.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_OBJECT_SET_H_ 5 #ifndef VM_OBJECT_SET_H_
6 #define VM_OBJECT_SET_H_ 6 #define VM_OBJECT_SET_H_
7 7
8 #include "platform/utils.h"
8 #include "vm/globals.h" 9 #include "vm/globals.h"
10 #include "vm/raw_object.h"
9 11
10 namespace dart { 12 namespace dart {
11 13
12 class ObjectSet { 14 class ObjectSet {
13 public: 15 public:
14 ObjectSet(uword start, uword end) : start_(start), end_(end) { 16 ObjectSet() {
17 Init(0, 0);
18 }
19
20 ObjectSet(uword start, uword end) {
21 Init(start, end);
22 }
23
24 ~ObjectSet() {
25 delete[] allocation_;
26 }
27
28 void Init(uword start, uword end) {
29 start_ = start;
30 end_ = end;
15 ASSERT(start_ <= end_); 31 ASSERT(start_ <= end_);
16 size_ = SizeFor((end_ - start_) >> kWordSizeLog2); 32 size_ = SizeFor((end_ - start_) >> kWordSizeLog2);
17 allocation_ = new uword[size_]; 33 allocation_ = new uword[size_];
18 data_ = &allocation_[-((start >> kWordSizeLog2) / kBitsPerWord)]; 34 data_ = &allocation_[-((start >> kWordSizeLog2) / kBitsPerWord)];
19 ASSERT(allocation_ == &data_[(start >> kWordSizeLog2) / kBitsPerWord]); 35 ASSERT(allocation_ == &data_[(start >> kWordSizeLog2) / kBitsPerWord]);
20 Clear(); 36 Clear();
21 } 37 }
22 38
23 ~ObjectSet() {
24 delete[] allocation_;
25 }
26
27 bool Contains(RawObject* raw_obj) const { 39 bool Contains(RawObject* raw_obj) const {
28 uword raw_addr = RawObject::ToAddr(raw_obj); 40 uword raw_addr = RawObject::ToAddr(raw_obj);
29 ASSERT(raw_addr >= start_); 41 ASSERT(raw_addr >= start_);
30 ASSERT(raw_addr < end_); 42 ASSERT(raw_addr < end_);
31 uword i = raw_addr >> kWordSizeLog2; 43 uword i = raw_addr >> kWordSizeLog2;
32 uword mask = (static_cast<uword>(1) << (i % kBitsPerWord)); 44 uword mask = (static_cast<uword>(1) << (i % kBitsPerWord));
33 return (data_[i / kBitsPerWord] & mask) != 0; 45 return (data_[i / kBitsPerWord] & mask) != 0;
34 } 46 }
35 47
36 void Add(RawObject* raw_obj) { 48 void Add(RawObject* raw_obj) {
37 uword raw_addr = RawObject::ToAddr(raw_obj); 49 uword raw_addr = RawObject::ToAddr(raw_obj);
38 ASSERT(raw_addr >= start_); 50 ASSERT(raw_addr >= start_);
39 ASSERT(raw_addr < end_); 51 ASSERT(raw_addr < end_);
40 uword i = raw_addr >> kWordSizeLog2; 52 uword i = raw_addr >> kWordSizeLog2;
41 data_[i / kBitsPerWord] |= (static_cast<uword>(1) << (i % kBitsPerWord)); 53 data_[i / kBitsPerWord] |= (static_cast<uword>(1) << (i % kBitsPerWord));
54 min_ = Utils::Minimum(raw_addr, min_);
55 max_ = Utils::Maximum(raw_addr, max_);
56 }
57
58 void Resize(uword start, uword end) {
59 if (start_ != start || end_ != end) {
60 delete[] allocation_;
61 Init(start, end);
62 }
42 } 63 }
43 64
44 void Clear() { 65 void Clear() {
45 memset(allocation_, 0, (size_ * sizeof(allocation_[0]))); 66 memset(allocation_, 0, (size_ * sizeof(allocation_[0])));
67 min_ = end_;
68 max_ = start_;
69 }
70
71 void FastClear() {
72 uword i = min_ >> kWordSizeLog2;
73 memset(&data_[i / kBitsPerWord],
74 0,
75 sizeof(uword) * SizeFor((max_ + 1 - min_) >> kWordSizeLog2));
76 min_ = end_;
77 max_ = start_;
46 } 78 }
47 79
48 private: 80 private:
49 static intptr_t SizeFor(intptr_t length) { 81 static intptr_t SizeFor(intptr_t length) {
50 return 1 + ((length - 1) / kBitsPerWord); 82 return 1 + ((length - 1) / kBitsPerWord);
51 } 83 }
52 84
53 // Biased data pointer aliased to allocation_. This value can be 85 // Biased data pointer aliased to allocation_. This value can be
54 // indexed without adjusting for the starting address of the heap. 86 // indexed without adjusting for the starting address of the heap.
55 uword* data_; 87 uword* data_;
56 88
57 // Allocated data pointer. 89 // Allocated data pointer.
58 uword* allocation_; 90 uword* allocation_;
59 91
60 // Allocation size in uwords. 92 // Allocation size in uwords.
61 intptr_t size_; 93 intptr_t size_;
62 94
63 // Lowest possible heap address, inclusive. 95 // Lowest possible heap address, inclusive.
64 uword start_; 96 uword start_;
65 97
66 // Highest possible heap address, exclusive. 98 // Highest possible heap address, exclusive.
67 uword end_; 99 uword end_;
68 100
69 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectSet); 101 // The inclusive minimum address set in this ObjectMap.
102 // Used by FastClear
103 uword min_;
104
105 // The inclusive maximum address in this ObjectMap.
106 // Used by FastClear
107 uword max_;
108
109 DISALLOW_COPY_AND_ASSIGN(ObjectSet);
70 }; 110 };
71 111
72 } // namespace dart 112 } // namespace dart
73 113
74 #endif // VM_OBJECT_SET_H_ 114 #endif // VM_OBJECT_SET_H_
OLDNEW
« no previous file with comments | « runtime/vm/heap_trace_test.cc ('k') | runtime/vm/pages.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698