OLD | NEW |
---|---|
(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_); | |
46 } | |
47 | |
48 private: | |
49 static intptr_t SizeFor(intptr_t length) { | |
50 return 1 + ((length - 1) / kBitsPerWord); | |
51 } | |
52 | |
53 uword* data_; | |
54 uword start_; | |
Ivan Posva
2012/06/29 22:20:41
start_, end_ and to some extent size_ are only nee
cshapiro
2012/07/10 21:48:17
I have sorted these fields in a (hopefully) more l
| |
55 uword end_; | |
56 uword* allocation_; | |
57 intptr_t size_; | |
58 | |
59 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectSet); | |
60 }; | |
61 | |
62 } // namespace dart | |
63 | |
64 #endif // VM_OBJECT_SET_H_ | |
OLD | NEW |