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

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

Issue 10696029: Implement a 2-pass heap verification algorithm. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase Created 8 years, 5 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/heap_profiler.h ('k') | runtime/vm/pages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #ifndef VM_OBJECT_SET_H_
6 #define VM_OBJECT_SET_H_
7
8 #include "vm/globals.h"
9
10 namespace dart {
11
12 class ObjectSet {
13 public:
14 ObjectSet(uword start, uword end) : start_(start), end_(end) {
15 ASSERT(start_ <= end_);
16 size_ = SizeFor((end_ - start_) >> kWordSizeLog2);
17 allocation_ = new uword[size_];
18 data_ = &allocation_[-((start >> kWordSizeLog2) / kBitsPerWord)];
19 ASSERT(allocation_ == &data_[(start >> kWordSizeLog2) / kBitsPerWord]);
20 Clear();
21 }
22
23 ~ObjectSet() {
24 delete[] allocation_;
25 }
26
27 bool Contains(RawObject* raw_obj) const {
28 uword raw_addr = RawObject::ToAddr(raw_obj);
29 ASSERT(raw_addr >= start_);
30 ASSERT(raw_addr < end_);
31 uword i = raw_addr >> kWordSizeLog2;
32 uword mask = (static_cast<uword>(1) << (i % kBitsPerWord));
33 return (data_[i / kBitsPerWord] & mask) != 0;
34 }
35
36 void Add(RawObject* raw_obj) {
37 uword raw_addr = RawObject::ToAddr(raw_obj);
38 ASSERT(raw_addr >= start_);
39 ASSERT(raw_addr < end_);
40 uword i = raw_addr >> kWordSizeLog2;
41 data_[i / kBitsPerWord] |= (static_cast<uword>(1) << (i % kBitsPerWord));
42 }
43
44 void Clear() {
45 memset(allocation_, 0, (size_ * sizeof(allocation_[0])));
46 }
47
48 private:
49 static intptr_t SizeFor(intptr_t length) {
50 return 1 + ((length - 1) / kBitsPerWord);
51 }
52
53 // Biased data pointer aliased to allocation_. This value can be
54 // indexed without adjusting for the starting address of the heap.
55 uword* data_;
56
57 // Allocated data pointer.
58 uword* allocation_;
59
60 // Allocation size in uwords.
61 intptr_t size_;
62
63 // Lowest possible heap address, inclusive.
64 uword start_;
65
66 // Highest possible heap address, exclusive.
67 uword end_;
68
69 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectSet);
70 };
71
72 } // namespace dart
73
74 #endif // VM_OBJECT_SET_H_
OLDNEW
« no previous file with comments | « runtime/vm/heap_profiler.h ('k') | runtime/vm/pages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698