Index: vm/object.cc |
=================================================================== |
--- vm/object.cc (revision 5450) |
+++ vm/object.cc (working copy) |
@@ -79,6 +79,7 @@ |
RawClass* Object::code_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
RawClass* Object::instructions_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
RawClass* Object::pc_descriptors_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
+RawClass* Object::bitmap_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
RawClass* Object::var_descriptors_class_ = |
reinterpret_cast<RawClass*>(RAW_NULL); |
RawClass* Object::exception_handlers_class_ = |
@@ -137,6 +138,8 @@ |
return kInstructionsClass; |
} else if (raw_class == pc_descriptors_class()) { |
return kPcDescriptorsClass; |
+ } else if (raw_class == bitmap_class()) { |
+ return kBitmapClass; |
} else if (raw_class == var_descriptors_class()) { |
return kLocalVarDescriptorsClass; |
} else if (raw_class == exception_handlers_class()) { |
@@ -184,6 +187,7 @@ |
case kCodeClass: return code_class(); |
case kInstructionsClass: return instructions_class(); |
case kPcDescriptorsClass: return pc_descriptors_class(); |
+ case kBitmapClass: return bitmap_class(); |
case kLocalVarDescriptorsClass: return var_descriptors_class(); |
case kExceptionHandlersClass: return exception_handlers_class(); |
case kContextClass: return context_class(); |
@@ -222,6 +226,7 @@ |
case kCodeClass: return "Code"; |
case kInstructionsClass: return "Instructions"; |
case kPcDescriptorsClass: return "PcDescriptors"; |
+ case kBitmapClass: return "Bitmap"; |
case kLocalVarDescriptorsClass: return "LocalVarDescriptors"; |
case kExceptionHandlersClass: return "ExceptionHandlers"; |
case kContextClass: return "Context"; |
@@ -365,6 +370,9 @@ |
cls = Class::New<PcDescriptors>(); |
pc_descriptors_class_ = cls.raw(); |
+ cls = Class::New<Bitmap>(); |
+ bitmap_class_ = cls.raw(); |
+ |
cls = Class::New<LocalVarDescriptors>(); |
var_descriptors_class_ = cls.raw(); |
@@ -5380,6 +5388,95 @@ |
} |
+// Return the bit offset of the highest bit set. |
+int32_t Bitmap::Maximum() const { |
+ int32_t bound = Size(); |
+ for (int32_t i = bound; i >= 0; i--) { |
+ if (Get(i)) return i; |
srdjan
2012/03/14 17:31:32
Shouldn't this fail? i is Size() in first iteratio
siva
2012/03/14 22:54:20
Changed to (bound - 1).
Get(i) fails if we access
|
+ } |
+ return kNoMaximum; |
+} |
+ |
+ |
+// Return the bit offset of the lowest bit set. |
+int32_t Bitmap::Minimum() const { |
+ int32_t bound = Size(); |
+ for (int32_t i = 0; i < bound; i++) { |
+ if (Get(i)) return i; |
+ } |
+ return kNoMinimum; |
+} |
+ |
+ |
+bool Bitmap::GetBit(int32_t bit_offset) const { |
+ ASSERT(InRange(bit_offset)); |
+ int byte_offset = bit_offset >> kBitsPerByteLog2; |
+ int bit_remainder = bit_offset & (kBitsPerByte - 1); |
+ uint8_t byte_mask = 1U << bit_remainder; |
+ uint8_t byte = raw_ptr()->data_[byte_offset]; |
+ return (byte & byte_mask); |
+} |
+ |
+ |
+void Bitmap::SetBit(int32_t bit_offset, bool value) const { |
+ ASSERT(InRange(bit_offset)); |
+ int byte_offset = bit_offset >> kBitsPerByteLog2; |
+ int bit_remainder = bit_offset & (kBitsPerByte - 1); |
+ uint8_t byte_mask = 1U << bit_remainder; |
+ uint8_t* byte_addr = &(raw_ptr()->data_[byte_offset]); |
+ if (value) { |
+ *byte_addr |= byte_mask; |
+ } else { |
+ *byte_addr &= ~byte_mask; |
+ } |
+} |
+ |
+ |
+RawBitmap* Bitmap::New(intptr_t size) { |
+ const Class& cls = Class::Handle(Object::bitmap_class()); |
+ ASSERT(!cls.IsNull()); |
+ Bitmap& result = Bitmap::Handle(); |
+ { |
+ // Bitmap data objects are associated with a code object, allocate them |
+ // in old generation. |
+ RawObject* raw = |
+ Object::Allocate(cls, Bitmap::InstanceSize(size), Heap::kOld); |
+ NoGCScope no_gc; |
+ result ^= raw; |
+ result.set_size(size); |
+ } |
+ return result.raw(); |
+} |
+ |
+ |
+void Bitmap::set_size(int32_t value) const { |
+ // This is only safe because we create a new Smi, which does not cause |
+ // heap allocation. |
+ raw_ptr()->size_ = Smi::New(value); |
+} |
+ |
+ |
+const char* Bitmap::ToCString() const { |
+ if (IsNull()) { |
+ return "{null}"; |
+ } else { |
+ intptr_t alloc_size = ((Maximum() + 1) * 2) + 4; // "{ 1 0 .... }". |
+ Isolate* isolate = Isolate::Current(); |
+ char* chars = reinterpret_cast<char*>( |
+ isolate->current_zone()->Allocate(alloc_size)); |
+ intptr_t index = OS::SNPrint(chars, alloc_size, "{ "); |
+ for (intptr_t i = 0; i <= Maximum(); i++) { |
+ index += OS::SNPrint((chars + index), |
+ (alloc_size - index), |
+ "%d ", |
+ Get(i) ? 1 : 0); |
+ } |
+ OS::SNPrint((chars + index), (alloc_size - index), "}"); |
+ return chars; |
+ } |
+} |
+ |
+ |
RawString* LocalVarDescriptors::GetName(intptr_t var_index) const { |
ASSERT(var_index < Length()); |
const Array& names = Array::Handle(raw_ptr()->names_); |