| 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 "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // they are being used. | 65 // they are being used. |
| 66 #if defined(RAW_NULL) | 66 #if defined(RAW_NULL) |
| 67 #error RAW_NULL should not be defined. | 67 #error RAW_NULL should not be defined. |
| 68 #endif | 68 #endif |
| 69 #define RAW_NULL kHeapObjectTag | 69 #define RAW_NULL kHeapObjectTag |
| 70 Array* Object::empty_array_ = NULL; | 70 Array* Object::empty_array_ = NULL; |
| 71 Instance* Object::sentinel_ = NULL; | 71 Instance* Object::sentinel_ = NULL; |
| 72 Instance* Object::transition_sentinel_ = NULL; | 72 Instance* Object::transition_sentinel_ = NULL; |
| 73 Bool* Object::bool_true_ = NULL; | 73 Bool* Object::bool_true_ = NULL; |
| 74 Bool* Object::bool_false_ = NULL; | 74 Bool* Object::bool_false_ = NULL; |
| 75 LanguageError* Object::snapshot_writer_error_ = NULL; |
| 75 | 76 |
| 76 RawObject* Object::null_ = reinterpret_cast<RawObject*>(RAW_NULL); | 77 RawObject* Object::null_ = reinterpret_cast<RawObject*>(RAW_NULL); |
| 77 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 78 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 78 RawClass* Object::null_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 79 RawClass* Object::null_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 79 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 80 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 80 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 81 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 81 RawClass* Object::unresolved_class_class_ = | 82 RawClass* Object::unresolved_class_class_ = |
| 82 reinterpret_cast<RawClass*>(RAW_NULL); | 83 reinterpret_cast<RawClass*>(RAW_NULL); |
| 83 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 84 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 84 RawClass* Object::instantiated_type_arguments_class_ = | 85 RawClass* Object::instantiated_type_arguments_class_ = |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 | 315 |
| 315 Isolate* isolate = Isolate::Current(); | 316 Isolate* isolate = Isolate::Current(); |
| 316 Heap* heap = isolate->heap(); | 317 Heap* heap = isolate->heap(); |
| 317 | 318 |
| 318 // Allocate the read only object handles here. | 319 // Allocate the read only object handles here. |
| 319 empty_array_ = Array::ReadOnlyHandle(isolate); | 320 empty_array_ = Array::ReadOnlyHandle(isolate); |
| 320 sentinel_ = Instance::ReadOnlyHandle(isolate); | 321 sentinel_ = Instance::ReadOnlyHandle(isolate); |
| 321 transition_sentinel_ = Instance::ReadOnlyHandle(isolate); | 322 transition_sentinel_ = Instance::ReadOnlyHandle(isolate); |
| 322 bool_true_ = Bool::ReadOnlyHandle(isolate); | 323 bool_true_ = Bool::ReadOnlyHandle(isolate); |
| 323 bool_false_ = Bool::ReadOnlyHandle(isolate); | 324 bool_false_ = Bool::ReadOnlyHandle(isolate); |
| 325 snapshot_writer_error_ = LanguageError::ReadOnlyHandle(isolate); |
| 324 | 326 |
| 325 // Allocate and initialize the null instance. | 327 // Allocate and initialize the null instance. |
| 326 // 'null_' must be the first object allocated as it is used in allocation to | 328 // 'null_' must be the first object allocated as it is used in allocation to |
| 327 // clear the object. | 329 // clear the object. |
| 328 { | 330 { |
| 329 uword address = heap->Allocate(Instance::InstanceSize(), Heap::kOld); | 331 uword address = heap->Allocate(Instance::InstanceSize(), Heap::kOld); |
| 330 null_ = reinterpret_cast<RawInstance*>(address + kHeapObjectTag); | 332 null_ = reinterpret_cast<RawInstance*>(address + kHeapObjectTag); |
| 331 // The call below is using 'null_' to initialize itself. | 333 // The call below is using 'null_' to initialize itself. |
| 332 InitializeObject(address, kNullCid, Instance::InstanceSize()); | 334 InitializeObject(address, kNullCid, Instance::InstanceSize()); |
| 333 } | 335 } |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 empty_array_, | 506 empty_array_, |
| 505 reinterpret_cast<RawArray*>(address + kHeapObjectTag)); | 507 reinterpret_cast<RawArray*>(address + kHeapObjectTag)); |
| 506 empty_array_->raw()->ptr()->length_ = Smi::New(0); | 508 empty_array_->raw()->ptr()->length_ = Smi::New(0); |
| 507 } | 509 } |
| 508 | 510 |
| 509 // Allocate and initialize singleton true and false boolean objects. | 511 // Allocate and initialize singleton true and false boolean objects. |
| 510 cls = Class::New<Bool>(); | 512 cls = Class::New<Bool>(); |
| 511 isolate->object_store()->set_bool_class(cls); | 513 isolate->object_store()->set_bool_class(cls); |
| 512 *bool_true_ = Bool::New(true); | 514 *bool_true_ = Bool::New(true); |
| 513 *bool_false_ = Bool::New(false); | 515 *bool_false_ = Bool::New(false); |
| 516 |
| 517 *snapshot_writer_error_ = |
| 518 LanguageError::New(String::Handle(String::New("SnapshotWriter Error"))); |
| 519 |
| 514 ASSERT(!empty_array_->IsSmi()); | 520 ASSERT(!empty_array_->IsSmi()); |
| 515 ASSERT(empty_array_->IsArray()); | 521 ASSERT(empty_array_->IsArray()); |
| 516 ASSERT(!sentinel_->IsSmi()); | 522 ASSERT(!sentinel_->IsSmi()); |
| 517 ASSERT(sentinel_->IsInstance()); | 523 ASSERT(sentinel_->IsInstance()); |
| 518 ASSERT(!transition_sentinel_->IsSmi()); | 524 ASSERT(!transition_sentinel_->IsSmi()); |
| 519 ASSERT(transition_sentinel_->IsInstance()); | 525 ASSERT(transition_sentinel_->IsInstance()); |
| 520 ASSERT(!bool_true_->IsSmi()); | 526 ASSERT(!bool_true_->IsSmi()); |
| 521 ASSERT(bool_true_->IsBool()); | 527 ASSERT(bool_true_->IsBool()); |
| 522 ASSERT(!bool_false_->IsSmi()); | 528 ASSERT(!bool_false_->IsSmi()); |
| 523 ASSERT(bool_false_->IsBool()); | 529 ASSERT(bool_false_->IsBool()); |
| 530 ASSERT(!snapshot_writer_error_->IsSmi()); |
| 531 ASSERT(snapshot_writer_error_->IsLanguageError()); |
| 524 } | 532 } |
| 525 | 533 |
| 526 | 534 |
| 527 #define SET_CLASS_NAME(class_name, name) \ | 535 #define SET_CLASS_NAME(class_name, name) \ |
| 528 cls = class_name##_class(); \ | 536 cls = class_name##_class(); \ |
| 529 cls.set_name(Symbols::name()); \ | 537 cls.set_name(Symbols::name()); \ |
| 530 | 538 |
| 531 void Object::RegisterSingletonClassNames() { | 539 void Object::RegisterSingletonClassNames() { |
| 532 Class& cls = Class::Handle(); | 540 Class& cls = Class::Handle(); |
| 533 | 541 |
| (...skipping 8266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8800 } | 8808 } |
| 8801 | 8809 |
| 8802 | 8810 |
| 8803 void UnhandledException::set_stacktrace(const Instance& stacktrace) const { | 8811 void UnhandledException::set_stacktrace(const Instance& stacktrace) const { |
| 8804 StorePointer(&raw_ptr()->stacktrace_, stacktrace.raw()); | 8812 StorePointer(&raw_ptr()->stacktrace_, stacktrace.raw()); |
| 8805 } | 8813 } |
| 8806 | 8814 |
| 8807 | 8815 |
| 8808 const char* UnhandledException::ToErrorCString() const { | 8816 const char* UnhandledException::ToErrorCString() const { |
| 8809 Isolate* isolate = Isolate::Current(); | 8817 Isolate* isolate = Isolate::Current(); |
| 8818 if (exception() == isolate->object_store()->out_of_memory()) { |
| 8819 return "Unhandled exception:\nOut of memory"; |
| 8820 } |
| 8821 if (exception() == isolate->object_store()->stack_overflow()) { |
| 8822 return "Unhandled exception:\nStack overflow"; |
| 8823 } |
| 8810 HANDLESCOPE(isolate); | 8824 HANDLESCOPE(isolate); |
| 8811 Object& strtmp = Object::Handle(); | 8825 Object& strtmp = Object::Handle(); |
| 8812 | |
| 8813 const Instance& exc = Instance::Handle(exception()); | 8826 const Instance& exc = Instance::Handle(exception()); |
| 8814 strtmp = DartLibraryCalls::ToString(exc); | 8827 strtmp = DartLibraryCalls::ToString(exc); |
| 8815 const char* exc_str = | 8828 const char* exc_str = |
| 8816 "<Received error while converting exception to string>"; | 8829 "<Received error while converting exception to string>"; |
| 8817 if (!strtmp.IsError()) { | 8830 if (!strtmp.IsError()) { |
| 8818 exc_str = strtmp.ToCString(); | 8831 exc_str = strtmp.ToCString(); |
| 8819 } | 8832 } |
| 8820 const Instance& stack = Instance::Handle(stacktrace()); | 8833 const Instance& stack = Instance::Handle(stacktrace()); |
| 8821 strtmp = DartLibraryCalls::ToString(stack); | 8834 strtmp = DartLibraryCalls::ToString(stack); |
| 8822 const char* stack_str = | 8835 const char* stack_str = |
| (...skipping 4310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13133 } | 13146 } |
| 13134 return result.raw(); | 13147 return result.raw(); |
| 13135 } | 13148 } |
| 13136 | 13149 |
| 13137 | 13150 |
| 13138 const char* WeakProperty::ToCString() const { | 13151 const char* WeakProperty::ToCString() const { |
| 13139 return "_WeakProperty"; | 13152 return "_WeakProperty"; |
| 13140 } | 13153 } |
| 13141 | 13154 |
| 13142 } // namespace dart | 13155 } // namespace dart |
| OLD | NEW |