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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « vm/bitmap.h ('k') | vm/bitmap_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: vm/bitmap.cc
===================================================================
--- vm/bitmap.cc (revision 0)
+++ vm/bitmap.cc (revision 0)
@@ -0,0 +1,109 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#include "vm/bitmap.h"
+
+#include "platform/assert.h"
+#include "vm/object.h"
+
+namespace dart {
+
+bool BitmapBuilder::Get(intptr_t bit_offset) const {
+ if (!InRange(bit_offset)) {
+ return false;
+ }
+ return GetBit(bit_offset);
+}
+
+
+void BitmapBuilder::Set(intptr_t bit_offset, bool value) {
+ while (!InRange(bit_offset)) {
+ intptr_t new_size = size_in_bytes_ + kIncrementSizeInBytes;
+ ASSERT(new_size > size_in_bytes_);
+ uint8_t* new_bit_list = reinterpret_cast<uint8_t*>(
+ Isolate::Current()->current_zone()->Allocate(new_size));
+ ASSERT(new_bit_list != NULL);
+ ASSERT(bit_list_ != NULL);
+ uint8_t* old_bit_list = bit_list_;
+ memmove(new_bit_list, old_bit_list, size_in_bytes_);
+ memset((new_bit_list + size_in_bytes_), 0, kIncrementSizeInBytes);
+ size_in_bytes_ = new_size;
+ bit_list_ = new_bit_list;
+ }
+ SetBit(bit_offset, value);
+}
+
+
+// Return the bit offset of the highest bit set.
+intptr_t BitmapBuilder::Maximum() const {
+ intptr_t bound = SizeInBits();
+ for (intptr_t i = (bound - 1); i >= 0; i--) {
+ if (Get(i)) return i;
+ }
+ return Stackmap::kNoMaximum;
+}
+
+
+// Return the bit offset of the lowest bit set.
+intptr_t BitmapBuilder::Minimum() const {
+ intptr_t bound = SizeInBits();
+ for (intptr_t i = 0; i < bound; i++) {
+ if (Get(i)) return i;
+ }
+ return Stackmap::kNoMinimum;
+}
+
+
+void BitmapBuilder::SetRange(intptr_t min, intptr_t max, bool value) {
+ for (intptr_t i = min; i <= max; i++) {
+ Set(i, value);
+ }
+}
+
+
+void BitmapBuilder::SetBits(const Stackmap& bitmap) {
+ intptr_t min = bitmap.Minimum();
+ intptr_t max = bitmap.Maximum();
+ if (min == Stackmap::kNoMinimum || max == Stackmap::kNoMaximum) {
+ return;
+ }
+ for (intptr_t i = 0; i < min; i++) {
+ Set(i, false);
+ }
+ for (intptr_t i = min; i <= max; i++) {
+ Set(i, bitmap.IsObject(i));
+ }
+ intptr_t bound = SizeInBits();
+ for (intptr_t i = (max + 1); i < bound; i++) {
+ Set(i, false);
+ }
+}
+
+
+bool BitmapBuilder::GetBit(intptr_t bit_offset) const {
+ ASSERT(InRange(bit_offset));
+ int byte_offset = bit_offset >> kBitsPerByteLog2;
+ int bit_remainder = bit_offset & (kBitsPerByte - 1);
+ uint8_t mask = 1U << bit_remainder;
+ ASSERT(bit_list_ != NULL);
+ return ((bit_list_[byte_offset] & mask) != 0);
+}
+
+
+void BitmapBuilder::SetBit(intptr_t bit_offset, bool value) {
+ ASSERT(InRange(bit_offset));
+ int byte_offset = bit_offset >> kBitsPerByteLog2;
+ int bit_remainder = bit_offset & (kBitsPerByte - 1);
+ uint8_t mask = 1U << bit_remainder;
+ uint8_t* byte_addr;
+ ASSERT(bit_list_ != NULL);
+ byte_addr = &(bit_list_[byte_offset]);
+ if (value) {
+ *byte_addr |= mask;
+ } else {
+ *byte_addr &= ~mask;
+ }
+}
+
+} // namespace dart
« 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