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

Side by Side Diff: vm/bitmap.cc

Issue 9701010: First step towards implementing stack map descriptions for the optimizing compiler. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 9 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 | « vm/bitmap.h ('k') | vm/bitmap_test.cc » ('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 #include "vm/bitmap.h"
6
7 #include "platform/assert.h"
8 #include "vm/object.h"
9
10 namespace dart {
11
12 bool BitmapBuilder::Get(intptr_t bit_offset) const {
13 if (!InRange(bit_offset)) {
14 return false;
15 }
16 return GetBit(bit_offset);
17 }
18
19
20 void BitmapBuilder::Set(intptr_t bit_offset, bool value) {
21 while (!InRange(bit_offset)) {
22 intptr_t new_size = size_in_bytes_ + kIncrementSizeInBytes;
23 ASSERT(new_size > size_in_bytes_);
24 uint8_t* new_bit_list = reinterpret_cast<uint8_t*>(
25 Isolate::Current()->current_zone()->Allocate(new_size));
26 ASSERT(new_bit_list != NULL);
27 ASSERT(bit_list_ != NULL);
28 uint8_t* old_bit_list = bit_list_;
29 memmove(new_bit_list, old_bit_list, size_in_bytes_);
30 memset((new_bit_list + size_in_bytes_), 0, kIncrementSizeInBytes);
31 size_in_bytes_ = new_size;
32 bit_list_ = new_bit_list;
33 }
34 SetBit(bit_offset, value);
35 }
36
37
38 // Return the bit offset of the highest bit set.
39 intptr_t BitmapBuilder::Maximum() const {
40 intptr_t bound = SizeInBits();
41 for (intptr_t i = (bound - 1); i >= 0; i--) {
42 if (Get(i)) return i;
43 }
44 return Stackmap::kNoMaximum;
45 }
46
47
48 // Return the bit offset of the lowest bit set.
49 intptr_t BitmapBuilder::Minimum() const {
50 intptr_t bound = SizeInBits();
51 for (intptr_t i = 0; i < bound; i++) {
52 if (Get(i)) return i;
53 }
54 return Stackmap::kNoMinimum;
55 }
56
57
58 void BitmapBuilder::SetRange(intptr_t min, intptr_t max, bool value) {
59 for (intptr_t i = min; i <= max; i++) {
60 Set(i, value);
61 }
62 }
63
64
65 void BitmapBuilder::SetBits(const Stackmap& bitmap) {
66 intptr_t min = bitmap.Minimum();
67 intptr_t max = bitmap.Maximum();
68 if (min == Stackmap::kNoMinimum || max == Stackmap::kNoMaximum) {
69 return;
70 }
71 for (intptr_t i = 0; i < min; i++) {
72 Set(i, false);
73 }
74 for (intptr_t i = min; i <= max; i++) {
75 Set(i, bitmap.IsObject(i));
76 }
77 intptr_t bound = SizeInBits();
78 for (intptr_t i = (max + 1); i < bound; i++) {
79 Set(i, false);
80 }
81 }
82
83
84 bool BitmapBuilder::GetBit(intptr_t bit_offset) const {
85 ASSERT(InRange(bit_offset));
86 int byte_offset = bit_offset >> kBitsPerByteLog2;
87 int bit_remainder = bit_offset & (kBitsPerByte - 1);
88 uint8_t mask = 1U << bit_remainder;
89 ASSERT(bit_list_ != NULL);
90 return ((bit_list_[byte_offset] & mask) != 0);
91 }
92
93
94 void BitmapBuilder::SetBit(intptr_t bit_offset, bool value) {
95 ASSERT(InRange(bit_offset));
96 int byte_offset = bit_offset >> kBitsPerByteLog2;
97 int bit_remainder = bit_offset & (kBitsPerByte - 1);
98 uint8_t mask = 1U << bit_remainder;
99 uint8_t* byte_addr;
100 ASSERT(bit_list_ != NULL);
101 byte_addr = &(bit_list_[byte_offset]);
102 if (value) {
103 *byte_addr |= mask;
104 } else {
105 *byte_addr &= ~mask;
106 }
107 }
108
109 } // namespace dart
OLDNEW
« no previous file with comments | « vm/bitmap.h ('k') | vm/bitmap_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698