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

Side by Side Diff: runtime/vm/bitmap.cc

Issue 16356009: Fix for issue 4638 in bitmap builder. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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 | « no previous file | no next file » | 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 #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 14 matching lines...) Expand all
25 if (byte_offset < data_size_in_bytes_) { 25 if (byte_offset < data_size_in_bytes_) {
26 memset(&data_[byte_offset], 0, data_size_in_bytes_ - byte_offset); 26 memset(&data_[byte_offset], 0, data_size_in_bytes_ - byte_offset);
27 } 27 }
28 } 28 }
29 } 29 }
30 length_ = new_length; 30 length_ = new_length;
31 } 31 }
32 32
33 33
34 bool BitmapBuilder::Get(intptr_t bit_offset) const { 34 bool BitmapBuilder::Get(intptr_t bit_offset) const {
35 ASSERT(InRange(bit_offset)); 35 if (!InRange(bit_offset)) {
36 return false;
37 }
36 intptr_t byte_offset = bit_offset >> kBitsPerByteLog2; 38 intptr_t byte_offset = bit_offset >> kBitsPerByteLog2;
37 // Bits not covered by the backing store are implicitly false. 39 // Bits not covered by the backing store are implicitly false.
38 return (byte_offset < data_size_in_bytes_) && GetBit(bit_offset); 40 return (byte_offset < data_size_in_bytes_) && GetBit(bit_offset);
39 } 41 }
40 42
41 43
42 void BitmapBuilder::Set(intptr_t bit_offset, bool value) { 44 void BitmapBuilder::Set(intptr_t bit_offset, bool value) {
43 ASSERT(bit_offset >= 0); 45 ASSERT(bit_offset >= 0);
44 if (!InRange(bit_offset)) { 46 if (!InRange(bit_offset)) {
45 length_ = bit_offset + 1; 47 length_ = bit_offset + 1;
46 // Bits not covered by the backing store are implicitly false. 48 // Bits not covered by the backing store are implicitly false.
47 if (!value) return; 49 if (!value) return;
48 // Grow the backing store if necessary. 50 // Grow the backing store if necessary.
49 intptr_t byte_offset = bit_offset >> kBitsPerByteLog2; 51 intptr_t byte_offset = bit_offset >> kBitsPerByteLog2;
52 if (byte_offset > kSmiMax) {
53 FATAL1("Fatal error in BitmapBuilder::Set : invalid bit_offset, %"Pd"\n",
54 bit_offset);
55 }
50 if (byte_offset >= data_size_in_bytes_) { 56 if (byte_offset >= data_size_in_bytes_) {
51 uint8_t* old_data = data_; 57 uint8_t* old_data = data_;
52 intptr_t old_size = data_size_in_bytes_; 58 intptr_t old_size = data_size_in_bytes_;
53 data_size_in_bytes_ = 59 data_size_in_bytes_ =
54 Utils::RoundUp(byte_offset + 1, kIncrementSizeInBytes); 60 Utils::RoundUp(byte_offset + 1, kIncrementSizeInBytes);
55 ASSERT(data_size_in_bytes_ > 0); 61 ASSERT(data_size_in_bytes_ > 0);
56 data_ = Isolate::Current()->current_zone()->Alloc<uint8_t>( 62 data_ = Isolate::Current()->current_zone()->Alloc<uint8_t>(
57 data_size_in_bytes_); 63 data_size_in_bytes_);
58 ASSERT(data_ != NULL); 64 ASSERT(data_ != NULL);
59 memmove(data_, old_data, old_size); 65 memmove(data_, old_data, old_size);
60 memset(&data_[old_size], 0, (data_size_in_bytes_ - old_size)); 66 memset(&data_[old_size], 0, (data_size_in_bytes_ - old_size));
61 } 67 }
62 } 68 }
63 SetBit(bit_offset, value); 69 SetBit(bit_offset, value);
64 } 70 }
65 71
66 72
67 void BitmapBuilder::SetRange(intptr_t min, intptr_t max, bool value) { 73 void BitmapBuilder::SetRange(intptr_t min, intptr_t max, bool value) {
68 for (intptr_t i = min; i <= max; i++) { 74 for (intptr_t i = min; i <= max; i++) {
69 Set(i, value); 75 Set(i, value);
70 } 76 }
71 } 77 }
72 78
73 79
74 bool BitmapBuilder::GetBit(intptr_t bit_offset) const { 80 bool BitmapBuilder::GetBit(intptr_t bit_offset) const {
75 ASSERT(InRange(bit_offset)); 81 if (!InRange(bit_offset)) {
82 return false;
83 }
76 intptr_t byte_offset = bit_offset >> kBitsPerByteLog2; 84 intptr_t byte_offset = bit_offset >> kBitsPerByteLog2;
77 ASSERT(byte_offset < data_size_in_bytes_); 85 ASSERT(byte_offset < data_size_in_bytes_);
78 intptr_t bit_remainder = bit_offset & (kBitsPerByte - 1); 86 intptr_t bit_remainder = bit_offset & (kBitsPerByte - 1);
79 uint8_t mask = 1U << bit_remainder; 87 uint8_t mask = 1U << bit_remainder;
80 ASSERT(data_ != NULL); 88 ASSERT(data_ != NULL);
81 return ((data_[byte_offset] & mask) != 0); 89 return ((data_[byte_offset] & mask) != 0);
82 } 90 }
83 91
84 92
85 void BitmapBuilder::SetBit(intptr_t bit_offset, bool value) { 93 void BitmapBuilder::SetBit(intptr_t bit_offset, bool value) {
86 ASSERT(InRange(bit_offset)); 94 if (!InRange(bit_offset)) {
95 return;
srdjan 2013/06/05 15:57:21 FATAL instead of return
siva 2013/06/05 16:22:09 Done.
96 }
87 int byte_offset = bit_offset >> kBitsPerByteLog2; 97 int byte_offset = bit_offset >> kBitsPerByteLog2;
88 ASSERT(byte_offset < data_size_in_bytes_); 98 ASSERT(byte_offset < data_size_in_bytes_);
89 int bit_remainder = bit_offset & (kBitsPerByte - 1); 99 int bit_remainder = bit_offset & (kBitsPerByte - 1);
90 uint8_t mask = 1U << bit_remainder; 100 uint8_t mask = 1U << bit_remainder;
91 ASSERT(data_ != NULL); 101 ASSERT(data_ != NULL);
92 if (value) { 102 if (value) {
93 data_[byte_offset] |= mask; 103 data_[byte_offset] |= mask;
94 } else { 104 } else {
95 data_[byte_offset] &= ~mask; 105 data_[byte_offset] &= ~mask;
96 } 106 }
97 } 107 }
98 108
99 } // namespace dart 109 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698