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 #include "vm/object.h" | 5 #include "vm/object.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 72 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
73 RawClass* Object::field_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 73 RawClass* Object::field_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
74 RawClass* Object::literal_token_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 74 RawClass* Object::literal_token_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
75 RawClass* Object::token_stream_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 75 RawClass* Object::token_stream_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
76 RawClass* Object::script_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 76 RawClass* Object::script_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
77 RawClass* Object::library_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 77 RawClass* Object::library_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
78 RawClass* Object::library_prefix_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 78 RawClass* Object::library_prefix_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
79 RawClass* Object::code_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 79 RawClass* Object::code_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
80 RawClass* Object::instructions_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 80 RawClass* Object::instructions_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
81 RawClass* Object::pc_descriptors_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 81 RawClass* Object::pc_descriptors_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
82 RawClass* Object::bitmap_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | |
82 RawClass* Object::var_descriptors_class_ = | 83 RawClass* Object::var_descriptors_class_ = |
83 reinterpret_cast<RawClass*>(RAW_NULL); | 84 reinterpret_cast<RawClass*>(RAW_NULL); |
84 RawClass* Object::exception_handlers_class_ = | 85 RawClass* Object::exception_handlers_class_ = |
85 reinterpret_cast<RawClass*>(RAW_NULL); | 86 reinterpret_cast<RawClass*>(RAW_NULL); |
86 RawClass* Object::context_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 87 RawClass* Object::context_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
87 RawClass* Object::context_scope_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 88 RawClass* Object::context_scope_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
88 RawClass* Object::icdata_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 89 RawClass* Object::icdata_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
89 RawClass* Object::api_error_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 90 RawClass* Object::api_error_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
90 RawClass* Object::language_error_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 91 RawClass* Object::language_error_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
91 RawClass* Object::unhandled_exception_class_ = | 92 RawClass* Object::unhandled_exception_class_ = |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 } else if (raw_class == library_class()) { | 131 } else if (raw_class == library_class()) { |
131 return kLibraryClass; | 132 return kLibraryClass; |
132 } else if (raw_class == library_prefix_class()) { | 133 } else if (raw_class == library_prefix_class()) { |
133 return kLibraryPrefixClass; | 134 return kLibraryPrefixClass; |
134 } else if (raw_class == code_class()) { | 135 } else if (raw_class == code_class()) { |
135 return kCodeClass; | 136 return kCodeClass; |
136 } else if (raw_class == instructions_class()) { | 137 } else if (raw_class == instructions_class()) { |
137 return kInstructionsClass; | 138 return kInstructionsClass; |
138 } else if (raw_class == pc_descriptors_class()) { | 139 } else if (raw_class == pc_descriptors_class()) { |
139 return kPcDescriptorsClass; | 140 return kPcDescriptorsClass; |
141 } else if (raw_class == bitmap_class()) { | |
142 return kBitmapClass; | |
140 } else if (raw_class == var_descriptors_class()) { | 143 } else if (raw_class == var_descriptors_class()) { |
141 return kLocalVarDescriptorsClass; | 144 return kLocalVarDescriptorsClass; |
142 } else if (raw_class == exception_handlers_class()) { | 145 } else if (raw_class == exception_handlers_class()) { |
143 return kExceptionHandlersClass; | 146 return kExceptionHandlersClass; |
144 } else if (raw_class == context_class()) { | 147 } else if (raw_class == context_class()) { |
145 return kContextClass; | 148 return kContextClass; |
146 } else if (raw_class == context_scope_class()) { | 149 } else if (raw_class == context_scope_class()) { |
147 return kContextScopeClass; | 150 return kContextScopeClass; |
148 } else if (raw_class == icdata_class()) { | 151 } else if (raw_class == icdata_class()) { |
149 return kICDataClass; | 152 return kICDataClass; |
(...skipping 27 matching lines...) Expand all Loading... | |
177 case kFunctionClass: return function_class(); | 180 case kFunctionClass: return function_class(); |
178 case kFieldClass: return field_class(); | 181 case kFieldClass: return field_class(); |
179 case kLiteralTokenClass: return literal_token_class(); | 182 case kLiteralTokenClass: return literal_token_class(); |
180 case kTokenStreamClass: return token_stream_class(); | 183 case kTokenStreamClass: return token_stream_class(); |
181 case kScriptClass: return script_class(); | 184 case kScriptClass: return script_class(); |
182 case kLibraryClass: return library_class(); | 185 case kLibraryClass: return library_class(); |
183 case kLibraryPrefixClass: return library_prefix_class(); | 186 case kLibraryPrefixClass: return library_prefix_class(); |
184 case kCodeClass: return code_class(); | 187 case kCodeClass: return code_class(); |
185 case kInstructionsClass: return instructions_class(); | 188 case kInstructionsClass: return instructions_class(); |
186 case kPcDescriptorsClass: return pc_descriptors_class(); | 189 case kPcDescriptorsClass: return pc_descriptors_class(); |
190 case kBitmapClass: return bitmap_class(); | |
187 case kLocalVarDescriptorsClass: return var_descriptors_class(); | 191 case kLocalVarDescriptorsClass: return var_descriptors_class(); |
188 case kExceptionHandlersClass: return exception_handlers_class(); | 192 case kExceptionHandlersClass: return exception_handlers_class(); |
189 case kContextClass: return context_class(); | 193 case kContextClass: return context_class(); |
190 case kContextScopeClass: return context_scope_class(); | 194 case kContextScopeClass: return context_scope_class(); |
191 case kICDataClass: return icdata_class(); | 195 case kICDataClass: return icdata_class(); |
192 case kApiErrorClass: return api_error_class(); | 196 case kApiErrorClass: return api_error_class(); |
193 case kLanguageErrorClass: return language_error_class(); | 197 case kLanguageErrorClass: return language_error_class(); |
194 case kUnhandledExceptionClass: return unhandled_exception_class(); | 198 case kUnhandledExceptionClass: return unhandled_exception_class(); |
195 case kUnwindErrorClass: return unwind_error_class(); | 199 case kUnwindErrorClass: return unwind_error_class(); |
196 default: break; | 200 default: break; |
(...skipping 18 matching lines...) Expand all Loading... | |
215 case kInstantiatedTypeArgumentsClass: return "InstantiatedTypeArguments"; | 219 case kInstantiatedTypeArgumentsClass: return "InstantiatedTypeArguments"; |
216 case kFunctionClass: return "Function"; | 220 case kFunctionClass: return "Function"; |
217 case kFieldClass: return "Field"; | 221 case kFieldClass: return "Field"; |
218 case kTokenStreamClass: return "TokenStream"; | 222 case kTokenStreamClass: return "TokenStream"; |
219 case kScriptClass: return "Script"; | 223 case kScriptClass: return "Script"; |
220 case kLibraryClass: return "Library"; | 224 case kLibraryClass: return "Library"; |
221 case kLibraryPrefixClass: return "LibraryPrefix"; | 225 case kLibraryPrefixClass: return "LibraryPrefix"; |
222 case kCodeClass: return "Code"; | 226 case kCodeClass: return "Code"; |
223 case kInstructionsClass: return "Instructions"; | 227 case kInstructionsClass: return "Instructions"; |
224 case kPcDescriptorsClass: return "PcDescriptors"; | 228 case kPcDescriptorsClass: return "PcDescriptors"; |
229 case kBitmapClass: return "Bitmap"; | |
225 case kLocalVarDescriptorsClass: return "LocalVarDescriptors"; | 230 case kLocalVarDescriptorsClass: return "LocalVarDescriptors"; |
226 case kExceptionHandlersClass: return "ExceptionHandlers"; | 231 case kExceptionHandlersClass: return "ExceptionHandlers"; |
227 case kContextClass: return "Context"; | 232 case kContextClass: return "Context"; |
228 case kContextScopeClass: return "ContextScope"; | 233 case kContextScopeClass: return "ContextScope"; |
229 case kICDataClass: return "ICData"; | 234 case kICDataClass: return "ICData"; |
230 case kApiErrorClass: return "ApiError"; | 235 case kApiErrorClass: return "ApiError"; |
231 case kLanguageErrorClass: return "LanguageError"; | 236 case kLanguageErrorClass: return "LanguageError"; |
232 case kUnhandledExceptionClass: return "UnhandledException"; | 237 case kUnhandledExceptionClass: return "UnhandledException"; |
233 case kUnwindErrorClass: return "UnwindError"; | 238 case kUnwindErrorClass: return "UnwindError"; |
234 default: break; | 239 default: break; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 | 363 |
359 cls = Class::New<Code>(); | 364 cls = Class::New<Code>(); |
360 code_class_ = cls.raw(); | 365 code_class_ = cls.raw(); |
361 | 366 |
362 cls = Class::New<Instructions>(); | 367 cls = Class::New<Instructions>(); |
363 instructions_class_ = cls.raw(); | 368 instructions_class_ = cls.raw(); |
364 | 369 |
365 cls = Class::New<PcDescriptors>(); | 370 cls = Class::New<PcDescriptors>(); |
366 pc_descriptors_class_ = cls.raw(); | 371 pc_descriptors_class_ = cls.raw(); |
367 | 372 |
373 cls = Class::New<Bitmap>(); | |
374 bitmap_class_ = cls.raw(); | |
375 | |
368 cls = Class::New<LocalVarDescriptors>(); | 376 cls = Class::New<LocalVarDescriptors>(); |
369 var_descriptors_class_ = cls.raw(); | 377 var_descriptors_class_ = cls.raw(); |
370 | 378 |
371 cls = Class::New<ExceptionHandlers>(); | 379 cls = Class::New<ExceptionHandlers>(); |
372 exception_handlers_class_ = cls.raw(); | 380 exception_handlers_class_ = cls.raw(); |
373 | 381 |
374 cls = Class::New<Context>(); | 382 cls = Class::New<Context>(); |
375 context_class_ = cls.raw(); | 383 context_class_ = cls.raw(); |
376 | 384 |
377 cls = Class::New<ContextScope>(); | 385 cls = Class::New<ContextScope>(); |
(...skipping 4995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5373 ASSERT(NodeId(k) != node_id); | 5381 ASSERT(NodeId(k) != node_id); |
5374 } | 5382 } |
5375 ASSERT(pc != PC(k)); | 5383 ASSERT(pc != PC(k)); |
5376 } | 5384 } |
5377 } | 5385 } |
5378 } | 5386 } |
5379 #endif // DEBUG | 5387 #endif // DEBUG |
5380 } | 5388 } |
5381 | 5389 |
5382 | 5390 |
5391 // Return the bit offset of the highest bit set. | |
5392 int32_t Bitmap::Maximum() const { | |
5393 int32_t bound = Size(); | |
5394 for (int32_t i = bound; i >= 0; i--) { | |
5395 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
| |
5396 } | |
5397 return kNoMaximum; | |
5398 } | |
5399 | |
5400 | |
5401 // Return the bit offset of the lowest bit set. | |
5402 int32_t Bitmap::Minimum() const { | |
5403 int32_t bound = Size(); | |
5404 for (int32_t i = 0; i < bound; i++) { | |
5405 if (Get(i)) return i; | |
5406 } | |
5407 return kNoMinimum; | |
5408 } | |
5409 | |
5410 | |
5411 bool Bitmap::GetBit(int32_t bit_offset) const { | |
5412 ASSERT(InRange(bit_offset)); | |
5413 int byte_offset = bit_offset >> kBitsPerByteLog2; | |
5414 int bit_remainder = bit_offset & (kBitsPerByte - 1); | |
5415 uint8_t byte_mask = 1U << bit_remainder; | |
5416 uint8_t byte = raw_ptr()->data_[byte_offset]; | |
5417 return (byte & byte_mask); | |
5418 } | |
5419 | |
5420 | |
5421 void Bitmap::SetBit(int32_t bit_offset, bool value) const { | |
5422 ASSERT(InRange(bit_offset)); | |
5423 int byte_offset = bit_offset >> kBitsPerByteLog2; | |
5424 int bit_remainder = bit_offset & (kBitsPerByte - 1); | |
5425 uint8_t byte_mask = 1U << bit_remainder; | |
5426 uint8_t* byte_addr = &(raw_ptr()->data_[byte_offset]); | |
5427 if (value) { | |
5428 *byte_addr |= byte_mask; | |
5429 } else { | |
5430 *byte_addr &= ~byte_mask; | |
5431 } | |
5432 } | |
5433 | |
5434 | |
5435 RawBitmap* Bitmap::New(intptr_t size) { | |
5436 const Class& cls = Class::Handle(Object::bitmap_class()); | |
5437 ASSERT(!cls.IsNull()); | |
5438 Bitmap& result = Bitmap::Handle(); | |
5439 { | |
5440 // Bitmap data objects are associated with a code object, allocate them | |
5441 // in old generation. | |
5442 RawObject* raw = | |
5443 Object::Allocate(cls, Bitmap::InstanceSize(size), Heap::kOld); | |
5444 NoGCScope no_gc; | |
5445 result ^= raw; | |
5446 result.set_size(size); | |
5447 } | |
5448 return result.raw(); | |
5449 } | |
5450 | |
5451 | |
5452 void Bitmap::set_size(int32_t value) const { | |
5453 // This is only safe because we create a new Smi, which does not cause | |
5454 // heap allocation. | |
5455 raw_ptr()->size_ = Smi::New(value); | |
5456 } | |
5457 | |
5458 | |
5459 const char* Bitmap::ToCString() const { | |
5460 if (IsNull()) { | |
5461 return "{null}"; | |
5462 } else { | |
5463 intptr_t alloc_size = ((Maximum() + 1) * 2) + 4; // "{ 1 0 .... }". | |
5464 Isolate* isolate = Isolate::Current(); | |
5465 char* chars = reinterpret_cast<char*>( | |
5466 isolate->current_zone()->Allocate(alloc_size)); | |
5467 intptr_t index = OS::SNPrint(chars, alloc_size, "{ "); | |
5468 for (intptr_t i = 0; i <= Maximum(); i++) { | |
5469 index += OS::SNPrint((chars + index), | |
5470 (alloc_size - index), | |
5471 "%d ", | |
5472 Get(i) ? 1 : 0); | |
5473 } | |
5474 OS::SNPrint((chars + index), (alloc_size - index), "}"); | |
5475 return chars; | |
5476 } | |
5477 } | |
5478 | |
5479 | |
5383 RawString* LocalVarDescriptors::GetName(intptr_t var_index) const { | 5480 RawString* LocalVarDescriptors::GetName(intptr_t var_index) const { |
5384 ASSERT(var_index < Length()); | 5481 ASSERT(var_index < Length()); |
5385 const Array& names = Array::Handle(raw_ptr()->names_); | 5482 const Array& names = Array::Handle(raw_ptr()->names_); |
5386 ASSERT(Length() == names.Length()); | 5483 ASSERT(Length() == names.Length()); |
5387 const String& name = String::CheckedHandle(names.At(var_index)); | 5484 const String& name = String::CheckedHandle(names.At(var_index)); |
5388 return name.raw(); | 5485 return name.raw(); |
5389 } | 5486 } |
5390 | 5487 |
5391 | 5488 |
5392 void LocalVarDescriptors::GetScopeInfo( | 5489 void LocalVarDescriptors::GetScopeInfo( |
(...skipping 3393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8786 const String& str = String::Handle(pattern()); | 8883 const String& str = String::Handle(pattern()); |
8787 const char* format = "JSRegExp: pattern=%s flags=%s"; | 8884 const char* format = "JSRegExp: pattern=%s flags=%s"; |
8788 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 8885 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
8789 char* chars = reinterpret_cast<char*>( | 8886 char* chars = reinterpret_cast<char*>( |
8790 Isolate::Current()->current_zone()->Allocate(len + 1)); | 8887 Isolate::Current()->current_zone()->Allocate(len + 1)); |
8791 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 8888 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
8792 return chars; | 8889 return chars; |
8793 } | 8890 } |
8794 | 8891 |
8795 } // namespace dart | 8892 } // namespace dart |
OLD | NEW |