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 #include "vm/bitmap.h" | 5 #include "vm/bitmap.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/object.h" | 8 #include "vm/object.h" |
9 | 9 |
10 namespace dart { | 10 namespace dart { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // Bits not covered by the backing store are implicitly false. | 47 // Bits not covered by the backing store are implicitly false. |
48 if (!value) return; | 48 if (!value) return; |
49 // Grow the backing store if necessary. | 49 // Grow the backing store if necessary. |
50 intptr_t byte_offset = bit_offset >> kBitsPerByteLog2; | 50 intptr_t byte_offset = bit_offset >> kBitsPerByteLog2; |
51 if (byte_offset >= data_size_in_bytes_) { | 51 if (byte_offset >= data_size_in_bytes_) { |
52 uint8_t* old_data = data_; | 52 uint8_t* old_data = data_; |
53 intptr_t old_size = data_size_in_bytes_; | 53 intptr_t old_size = data_size_in_bytes_; |
54 data_size_in_bytes_ = | 54 data_size_in_bytes_ = |
55 Utils::RoundUp(byte_offset + 1, kIncrementSizeInBytes); | 55 Utils::RoundUp(byte_offset + 1, kIncrementSizeInBytes); |
56 ASSERT(data_size_in_bytes_ > 0); | 56 ASSERT(data_size_in_bytes_ > 0); |
57 data_ = Thread::Current()->zone()->Alloc<uint8_t>( | 57 data_ = Thread::Current()->zone()->Alloc<uint8_t>(data_size_in_bytes_); |
58 data_size_in_bytes_); | |
59 ASSERT(data_ != NULL); | 58 ASSERT(data_ != NULL); |
60 memmove(data_, old_data, old_size); | 59 memmove(data_, old_data, old_size); |
61 memset(&data_[old_size], 0, (data_size_in_bytes_ - old_size)); | 60 memset(&data_[old_size], 0, (data_size_in_bytes_ - old_size)); |
62 } | 61 } |
63 } | 62 } |
64 SetBit(bit_offset, value); | 63 SetBit(bit_offset, value); |
65 } | 64 } |
66 | 65 |
67 | 66 |
68 void BitmapBuilder::SetRange(intptr_t min, intptr_t max, bool value) { | 67 void BitmapBuilder::SetRange(intptr_t min, intptr_t max, bool value) { |
(...skipping 22 matching lines...) Expand all Loading... |
91 ASSERT(byte_offset < data_size_in_bytes_); | 90 ASSERT(byte_offset < data_size_in_bytes_); |
92 intptr_t bit_remainder = bit_offset & (kBitsPerByte - 1); | 91 intptr_t bit_remainder = bit_offset & (kBitsPerByte - 1); |
93 uint8_t mask = 1U << bit_remainder; | 92 uint8_t mask = 1U << bit_remainder; |
94 ASSERT(data_ != NULL); | 93 ASSERT(data_ != NULL); |
95 return ((data_[byte_offset] & mask) != 0); | 94 return ((data_[byte_offset] & mask) != 0); |
96 } | 95 } |
97 | 96 |
98 | 97 |
99 void BitmapBuilder::SetBit(intptr_t bit_offset, bool value) { | 98 void BitmapBuilder::SetBit(intptr_t bit_offset, bool value) { |
100 if (!InRange(bit_offset)) { | 99 if (!InRange(bit_offset)) { |
101 FATAL1("Fatal error in BitmapBuilder::SetBit :" | 100 FATAL1( |
102 " invalid bit_offset, %" Pd "\n", bit_offset); | 101 "Fatal error in BitmapBuilder::SetBit :" |
| 102 " invalid bit_offset, %" Pd "\n", |
| 103 bit_offset); |
103 } | 104 } |
104 intptr_t byte_offset = bit_offset >> kBitsPerByteLog2; | 105 intptr_t byte_offset = bit_offset >> kBitsPerByteLog2; |
105 ASSERT(byte_offset < data_size_in_bytes_); | 106 ASSERT(byte_offset < data_size_in_bytes_); |
106 intptr_t bit_remainder = bit_offset & (kBitsPerByte - 1); | 107 intptr_t bit_remainder = bit_offset & (kBitsPerByte - 1); |
107 uint8_t mask = 1U << bit_remainder; | 108 uint8_t mask = 1U << bit_remainder; |
108 ASSERT(data_ != NULL); | 109 ASSERT(data_ != NULL); |
109 if (value) { | 110 if (value) { |
110 data_[byte_offset] |= mask; | 111 data_[byte_offset] |= mask; |
111 } else { | 112 } else { |
112 data_[byte_offset] &= ~mask; | 113 data_[byte_offset] &= ~mask; |
113 } | 114 } |
114 } | 115 } |
115 | 116 |
116 } // namespace dart | 117 } // namespace dart |
OLD | NEW |