| 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_BITMAP_H_ | 5 #ifndef VM_BITMAP_H_ |
| 6 #define VM_BITMAP_H_ | 6 #define VM_BITMAP_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/isolate.h" |
| 10 #include "vm/zone.h" |
| 9 | 11 |
| 10 namespace dart { | 12 namespace dart { |
| 11 | 13 |
| 12 // Forward declarations. | 14 // Forward declarations. |
| 13 class RawStackmap; | 15 class RawStackmap; |
| 14 class Stackmap; | 16 class Stackmap; |
| 15 | 17 |
| 16 | 18 |
| 17 // BitmapBuilder is used to build a bitmap. The implementation is optimized for | 19 // BitmapBuilder is used to build a bitmap. The implementation is optimized |
| 18 // a dense set of small bit maps without an upper bound (e.g: a pointer map | 20 // for a dense set of small bit maps without a fixed upper bound (e.g: a |
| 19 // description of a stack). | 21 // pointer map description of a stack). |
| 20 class BitmapBuilder : public ZoneAllocated { | 22 class BitmapBuilder : public ZoneAllocated { |
| 21 public: | 23 public: |
| 22 BitmapBuilder() : size_in_bytes_(kInitialSizeInBytes), | 24 BitmapBuilder() |
| 23 bit_list_(bit_list_data_) { | 25 : length_(0), |
| 24 memset(bit_list_data_, 0, kInitialSizeInBytes); | 26 data_size_in_bytes_(kInitialSizeInBytes), |
| 27 data_(Isolate::Current()->current_zone()->Alloc<uint8_t>( |
| 28 kInitialSizeInBytes)) { |
| 29 memset(data_, 0, kInitialSizeInBytes); |
| 25 } | 30 } |
| 26 | 31 |
| 27 intptr_t SizeInBits() const { return (size_in_bytes_ * kBitsPerByte); } | 32 intptr_t Length() const { return length_; } |
| 28 intptr_t SizeInBytes() const { return size_in_bytes_; } | 33 void SetLength(intptr_t length); |
| 29 | 34 |
| 30 // Get/Set individual bits in the bitmap, set expands the underlying bitmap | 35 // Get/Set individual bits in the bitmap, setting bits beyond the bitmap's |
| 31 // if needed. | 36 // length increases the length and expands the underlying bitmap if |
| 37 // needed. |
| 32 bool Get(intptr_t bit_offset) const; | 38 bool Get(intptr_t bit_offset) const; |
| 33 void Set(intptr_t bit_offset, bool value); | 39 void Set(intptr_t bit_offset, bool value); |
| 34 | 40 |
| 35 // Return the bit offset of the highest bit set. | 41 // Return the bit offset of the highest bit set. |
| 36 intptr_t Maximum() const; | 42 intptr_t Maximum() const; |
| 37 | 43 |
| 38 // Return the bit offset of the lowest bit set. | 44 // Return the bit offset of the lowest bit set. |
| 39 intptr_t Minimum() const; | 45 intptr_t Minimum() const; |
| 40 | 46 |
| 41 // Sets min..max (inclusive) to value. | 47 // Sets min..max (inclusive) to value. |
| 42 void SetRange(intptr_t min, intptr_t max, bool value); | 48 void SetRange(intptr_t min, intptr_t max, bool value); |
| 43 | 49 |
| 44 private: | 50 private: |
| 45 static const intptr_t kInitialSizeInBytes = 16; | 51 static const intptr_t kInitialSizeInBytes = 16; |
| 46 static const intptr_t kIncrementSizeInBytes = 16; | 52 static const intptr_t kIncrementSizeInBytes = 16; |
| 47 | 53 |
| 48 bool InRange(intptr_t offset) const { | 54 bool InRange(intptr_t offset) const { |
| 49 return (offset >= 0) && (offset < SizeInBits()); | 55 return (offset >= 0) && (offset < length_); |
| 50 } | 56 } |
| 51 | 57 |
| 58 // Get/Set a bit that is known to be covered by the backing store. |
| 52 bool GetBit(intptr_t bit_offset) const; | 59 bool GetBit(intptr_t bit_offset) const; |
| 53 void SetBit(intptr_t bit_offset, bool value); | 60 void SetBit(intptr_t bit_offset, bool value); |
| 54 | 61 |
| 55 intptr_t size_in_bytes_; | 62 intptr_t length_; |
| 56 uint8_t bit_list_data_[kInitialSizeInBytes]; | 63 |
| 57 uint8_t* bit_list_; | 64 // Backing store for the bitmap. Reading bits beyond the backing store |
| 65 // (up to length_) is allowed and they are assumed to be false. |
| 66 intptr_t data_size_in_bytes_; |
| 67 uint8_t* data_; |
| 58 | 68 |
| 59 DISALLOW_COPY_AND_ASSIGN(BitmapBuilder); | 69 DISALLOW_COPY_AND_ASSIGN(BitmapBuilder); |
| 60 }; | 70 }; |
| 61 | 71 |
| 62 } // namespace dart | 72 } // namespace dart |
| 63 | 73 |
| 64 #endif // VM_BITMAP_H_ | 74 #endif // VM_BITMAP_H_ |
| OLD | NEW |