| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 #define RAW_NULL kHeapObjectTag | 92 #define RAW_NULL kHeapObjectTag |
| 93 Object* Object::null_object_ = NULL; | 93 Object* Object::null_object_ = NULL; |
| 94 Array* Object::null_array_ = NULL; | 94 Array* Object::null_array_ = NULL; |
| 95 String* Object::null_string_ = NULL; | 95 String* Object::null_string_ = NULL; |
| 96 Instance* Object::null_instance_ = NULL; | 96 Instance* Object::null_instance_ = NULL; |
| 97 TypeArguments* Object::null_type_arguments_ = NULL; | 97 TypeArguments* Object::null_type_arguments_ = NULL; |
| 98 Array* Object::empty_array_ = NULL; | 98 Array* Object::empty_array_ = NULL; |
| 99 Array* Object::zero_array_ = NULL; | 99 Array* Object::zero_array_ = NULL; |
| 100 PcDescriptors* Object::empty_descriptors_ = NULL; | 100 PcDescriptors* Object::empty_descriptors_ = NULL; |
| 101 LocalVarDescriptors* Object::empty_var_descriptors_ = NULL; | 101 LocalVarDescriptors* Object::empty_var_descriptors_ = NULL; |
| 102 ExceptionHandlers* Object::empty_exception_handlers_ = NULL; |
| 102 Instance* Object::sentinel_ = NULL; | 103 Instance* Object::sentinel_ = NULL; |
| 103 Instance* Object::transition_sentinel_ = NULL; | 104 Instance* Object::transition_sentinel_ = NULL; |
| 104 Instance* Object::unknown_constant_ = NULL; | 105 Instance* Object::unknown_constant_ = NULL; |
| 105 Instance* Object::non_constant_ = NULL; | 106 Instance* Object::non_constant_ = NULL; |
| 106 Bool* Object::bool_true_ = NULL; | 107 Bool* Object::bool_true_ = NULL; |
| 107 Bool* Object::bool_false_ = NULL; | 108 Bool* Object::bool_false_ = NULL; |
| 108 Smi* Object::smi_illegal_cid_ = NULL; | 109 Smi* Object::smi_illegal_cid_ = NULL; |
| 109 LanguageError* Object::snapshot_writer_error_ = NULL; | 110 LanguageError* Object::snapshot_writer_error_ = NULL; |
| 110 LanguageError* Object::branch_offset_error_ = NULL; | 111 LanguageError* Object::branch_offset_error_ = NULL; |
| 111 | 112 |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 // Allocate the read only object handles here. | 431 // Allocate the read only object handles here. |
| 431 null_object_ = Object::ReadOnlyHandle(); | 432 null_object_ = Object::ReadOnlyHandle(); |
| 432 null_array_ = Array::ReadOnlyHandle(); | 433 null_array_ = Array::ReadOnlyHandle(); |
| 433 null_string_ = String::ReadOnlyHandle(); | 434 null_string_ = String::ReadOnlyHandle(); |
| 434 null_instance_ = Instance::ReadOnlyHandle(); | 435 null_instance_ = Instance::ReadOnlyHandle(); |
| 435 null_type_arguments_ = TypeArguments::ReadOnlyHandle(); | 436 null_type_arguments_ = TypeArguments::ReadOnlyHandle(); |
| 436 empty_array_ = Array::ReadOnlyHandle(); | 437 empty_array_ = Array::ReadOnlyHandle(); |
| 437 zero_array_ = Array::ReadOnlyHandle(); | 438 zero_array_ = Array::ReadOnlyHandle(); |
| 438 empty_descriptors_ = PcDescriptors::ReadOnlyHandle(); | 439 empty_descriptors_ = PcDescriptors::ReadOnlyHandle(); |
| 439 empty_var_descriptors_ = LocalVarDescriptors::ReadOnlyHandle(); | 440 empty_var_descriptors_ = LocalVarDescriptors::ReadOnlyHandle(); |
| 441 empty_exception_handlers_ = ExceptionHandlers::ReadOnlyHandle(); |
| 440 sentinel_ = Instance::ReadOnlyHandle(); | 442 sentinel_ = Instance::ReadOnlyHandle(); |
| 441 transition_sentinel_ = Instance::ReadOnlyHandle(); | 443 transition_sentinel_ = Instance::ReadOnlyHandle(); |
| 442 unknown_constant_ = Instance::ReadOnlyHandle(); | 444 unknown_constant_ = Instance::ReadOnlyHandle(); |
| 443 non_constant_ = Instance::ReadOnlyHandle(); | 445 non_constant_ = Instance::ReadOnlyHandle(); |
| 444 bool_true_ = Bool::ReadOnlyHandle(); | 446 bool_true_ = Bool::ReadOnlyHandle(); |
| 445 bool_false_ = Bool::ReadOnlyHandle(); | 447 bool_false_ = Bool::ReadOnlyHandle(); |
| 446 smi_illegal_cid_ = Smi::ReadOnlyHandle(); | 448 smi_illegal_cid_ = Smi::ReadOnlyHandle(); |
| 447 snapshot_writer_error_ = LanguageError::ReadOnlyHandle(); | 449 snapshot_writer_error_ = LanguageError::ReadOnlyHandle(); |
| 448 branch_offset_error_ = LanguageError::ReadOnlyHandle(); | 450 branch_offset_error_ = LanguageError::ReadOnlyHandle(); |
| 449 | 451 |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 heap->Allocate(LocalVarDescriptors::InstanceSize(0), Heap::kOld); | 675 heap->Allocate(LocalVarDescriptors::InstanceSize(0), Heap::kOld); |
| 674 InitializeObject(address, | 676 InitializeObject(address, |
| 675 kLocalVarDescriptorsCid, | 677 kLocalVarDescriptorsCid, |
| 676 LocalVarDescriptors::InstanceSize(0)); | 678 LocalVarDescriptors::InstanceSize(0)); |
| 677 LocalVarDescriptors::initializeHandle( | 679 LocalVarDescriptors::initializeHandle( |
| 678 empty_var_descriptors_, | 680 empty_var_descriptors_, |
| 679 reinterpret_cast<RawLocalVarDescriptors*>(address + kHeapObjectTag)); | 681 reinterpret_cast<RawLocalVarDescriptors*>(address + kHeapObjectTag)); |
| 680 empty_var_descriptors_->raw_ptr()->num_entries_ = 0; | 682 empty_var_descriptors_->raw_ptr()->num_entries_ = 0; |
| 681 } | 683 } |
| 682 | 684 |
| 685 // Allocate and initialize the canonical empty exception handler info object. |
| 686 // The vast majority of all functions do not contain an exception handler |
| 687 // and can share this canonical descriptor. |
| 688 { |
| 689 uword address = |
| 690 heap->Allocate(ExceptionHandlers::InstanceSize(0), Heap::kOld); |
| 691 InitializeObject(address, |
| 692 kExceptionHandlersCid, |
| 693 ExceptionHandlers::InstanceSize(0)); |
| 694 ExceptionHandlers::initializeHandle( |
| 695 empty_exception_handlers_, |
| 696 reinterpret_cast<RawExceptionHandlers*>(address + kHeapObjectTag)); |
| 697 empty_exception_handlers_->raw_ptr()->num_entries_ = 0; |
| 698 } |
| 699 |
| 683 cls = Class::New<Instance>(kDynamicCid); | 700 cls = Class::New<Instance>(kDynamicCid); |
| 684 cls.set_is_abstract(); | 701 cls.set_is_abstract(); |
| 685 cls.set_num_type_arguments(0); | 702 cls.set_num_type_arguments(0); |
| 686 cls.set_num_own_type_arguments(0); | 703 cls.set_num_own_type_arguments(0); |
| 687 cls.set_is_type_finalized(); | 704 cls.set_is_type_finalized(); |
| 688 cls.set_is_finalized(); | 705 cls.set_is_finalized(); |
| 689 dynamic_class_ = cls.raw(); | 706 dynamic_class_ = cls.raw(); |
| 690 | 707 |
| 691 cls = Class::New<Instance>(kVoidCid); | 708 cls = Class::New<Instance>(kVoidCid); |
| 692 cls.set_num_type_arguments(0); | 709 cls.set_num_type_arguments(0); |
| (...skipping 10290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10983 } | 11000 } |
| 10984 return result.raw(); | 11001 return result.raw(); |
| 10985 } | 11002 } |
| 10986 | 11003 |
| 10987 | 11004 |
| 10988 intptr_t LocalVarDescriptors::Length() const { | 11005 intptr_t LocalVarDescriptors::Length() const { |
| 10989 return raw_ptr()->num_entries_; | 11006 return raw_ptr()->num_entries_; |
| 10990 } | 11007 } |
| 10991 | 11008 |
| 10992 | 11009 |
| 10993 intptr_t ExceptionHandlers::Length() const { | 11010 intptr_t ExceptionHandlers::num_entries() const { |
| 10994 return raw_ptr()->length_; | 11011 return raw_ptr()->num_entries_; |
| 10995 } | 11012 } |
| 10996 | 11013 |
| 10997 | 11014 |
| 10998 void ExceptionHandlers::SetHandlerInfo(intptr_t try_index, | 11015 void ExceptionHandlers::SetHandlerInfo(intptr_t try_index, |
| 10999 intptr_t outer_try_index, | 11016 intptr_t outer_try_index, |
| 11000 intptr_t handler_pc, | 11017 intptr_t handler_pc, |
| 11001 bool needs_stacktrace, | 11018 bool needs_stacktrace, |
| 11002 bool has_catch_all) const { | 11019 bool has_catch_all) const { |
| 11003 ASSERT((try_index >= 0) && (try_index < Length())); | 11020 ASSERT((try_index >= 0) && (try_index < num_entries())); |
| 11004 RawExceptionHandlers::HandlerInfo* info = &raw_ptr()->data()[try_index]; | 11021 RawExceptionHandlers::HandlerInfo* info = &raw_ptr()->data()[try_index]; |
| 11005 info->outer_try_index = outer_try_index; | 11022 info->outer_try_index = outer_try_index; |
| 11006 info->handler_pc = handler_pc; | 11023 info->handler_pc = handler_pc; |
| 11007 info->needs_stacktrace = needs_stacktrace; | 11024 info->needs_stacktrace = needs_stacktrace; |
| 11008 info->has_catch_all = has_catch_all; | 11025 info->has_catch_all = has_catch_all; |
| 11009 } | 11026 } |
| 11010 | 11027 |
| 11011 void ExceptionHandlers::GetHandlerInfo( | 11028 void ExceptionHandlers::GetHandlerInfo( |
| 11012 intptr_t try_index, | 11029 intptr_t try_index, |
| 11013 RawExceptionHandlers::HandlerInfo* info) const { | 11030 RawExceptionHandlers::HandlerInfo* info) const { |
| 11014 ASSERT((try_index >= 0) && (try_index < Length())); | 11031 ASSERT((try_index >= 0) && (try_index < num_entries())); |
| 11015 ASSERT(info != NULL); | 11032 ASSERT(info != NULL); |
| 11016 *info = raw_ptr()->data()[try_index]; | 11033 *info = raw_ptr()->data()[try_index]; |
| 11017 } | 11034 } |
| 11018 | 11035 |
| 11019 | 11036 |
| 11020 intptr_t ExceptionHandlers::HandlerPC(intptr_t try_index) const { | 11037 intptr_t ExceptionHandlers::HandlerPC(intptr_t try_index) const { |
| 11021 ASSERT((try_index >= 0) && (try_index < Length())); | 11038 ASSERT((try_index >= 0) && (try_index < num_entries())); |
| 11022 return raw_ptr()->data()[try_index].handler_pc; | 11039 return raw_ptr()->data()[try_index].handler_pc; |
| 11023 } | 11040 } |
| 11024 | 11041 |
| 11025 | 11042 |
| 11026 intptr_t ExceptionHandlers::OuterTryIndex(intptr_t try_index) const { | 11043 intptr_t ExceptionHandlers::OuterTryIndex(intptr_t try_index) const { |
| 11027 ASSERT((try_index >= 0) && (try_index < Length())); | 11044 ASSERT((try_index >= 0) && (try_index < num_entries())); |
| 11028 return raw_ptr()->data()[try_index].outer_try_index; | 11045 return raw_ptr()->data()[try_index].outer_try_index; |
| 11029 } | 11046 } |
| 11030 | 11047 |
| 11031 | 11048 |
| 11032 bool ExceptionHandlers::NeedsStacktrace(intptr_t try_index) const { | 11049 bool ExceptionHandlers::NeedsStacktrace(intptr_t try_index) const { |
| 11033 ASSERT((try_index >= 0) && (try_index < Length())); | 11050 ASSERT((try_index >= 0) && (try_index < num_entries())); |
| 11034 return raw_ptr()->data()[try_index].needs_stacktrace; | 11051 return raw_ptr()->data()[try_index].needs_stacktrace; |
| 11035 } | 11052 } |
| 11036 | 11053 |
| 11037 | 11054 |
| 11038 bool ExceptionHandlers::HasCatchAll(intptr_t try_index) const { | 11055 bool ExceptionHandlers::HasCatchAll(intptr_t try_index) const { |
| 11039 ASSERT((try_index >= 0) && (try_index < Length())); | 11056 ASSERT((try_index >= 0) && (try_index < num_entries())); |
| 11040 return raw_ptr()->data()[try_index].has_catch_all; | 11057 return raw_ptr()->data()[try_index].has_catch_all; |
| 11041 } | 11058 } |
| 11042 | 11059 |
| 11043 | 11060 |
| 11044 void ExceptionHandlers::SetHandledTypes(intptr_t try_index, | 11061 void ExceptionHandlers::SetHandledTypes(intptr_t try_index, |
| 11045 const Array& handled_types) const { | 11062 const Array& handled_types) const { |
| 11046 ASSERT((try_index >= 0) && (try_index < Length())); | 11063 ASSERT((try_index >= 0) && (try_index < num_entries())); |
| 11047 const Array& handled_types_data = | 11064 const Array& handled_types_data = |
| 11048 Array::Handle(raw_ptr()->handled_types_data_); | 11065 Array::Handle(raw_ptr()->handled_types_data_); |
| 11049 handled_types_data.SetAt(try_index, handled_types); | 11066 handled_types_data.SetAt(try_index, handled_types); |
| 11050 } | 11067 } |
| 11051 | 11068 |
| 11052 | 11069 |
| 11053 RawArray* ExceptionHandlers::GetHandledTypes(intptr_t try_index) const { | 11070 RawArray* ExceptionHandlers::GetHandledTypes(intptr_t try_index) const { |
| 11054 ASSERT((try_index >= 0) && (try_index < Length())); | 11071 ASSERT((try_index >= 0) && (try_index < num_entries())); |
| 11055 Array& array = Array::Handle(raw_ptr()->handled_types_data_); | 11072 Array& array = Array::Handle(raw_ptr()->handled_types_data_); |
| 11056 array ^= array.At(try_index); | 11073 array ^= array.At(try_index); |
| 11057 return array.raw(); | 11074 return array.raw(); |
| 11058 } | 11075 } |
| 11059 | 11076 |
| 11060 | 11077 |
| 11061 void ExceptionHandlers::set_handled_types_data(const Array& value) const { | 11078 void ExceptionHandlers::set_handled_types_data(const Array& value) const { |
| 11062 StorePointer(&raw_ptr()->handled_types_data_, value.raw()); | 11079 StorePointer(&raw_ptr()->handled_types_data_, value.raw()); |
| 11063 } | 11080 } |
| 11064 | 11081 |
| 11065 | 11082 |
| 11066 RawExceptionHandlers* ExceptionHandlers::New(intptr_t num_handlers) { | 11083 RawExceptionHandlers* ExceptionHandlers::New(intptr_t num_handlers) { |
| 11067 ASSERT(Object::exception_handlers_class() != Class::null()); | 11084 ASSERT(Object::exception_handlers_class() != Class::null()); |
| 11068 if ((num_handlers < 0) || (num_handlers >= kMaxHandlers)) { | 11085 if ((num_handlers < 0) || (num_handlers >= kMaxHandlers)) { |
| 11069 FATAL1("Fatal error in ExceptionHandlers::New(): " | 11086 FATAL1("Fatal error in ExceptionHandlers::New(): " |
| 11070 "invalid num_handlers %" Pd "\n", | 11087 "invalid num_handlers %" Pd "\n", |
| 11071 num_handlers); | 11088 num_handlers); |
| 11072 } | 11089 } |
| 11073 ExceptionHandlers& result = ExceptionHandlers::Handle(); | 11090 ExceptionHandlers& result = ExceptionHandlers::Handle(); |
| 11074 { | 11091 { |
| 11075 uword size = ExceptionHandlers::InstanceSize(num_handlers); | 11092 uword size = ExceptionHandlers::InstanceSize(num_handlers); |
| 11076 RawObject* raw = Object::Allocate(ExceptionHandlers::kClassId, | 11093 RawObject* raw = Object::Allocate(ExceptionHandlers::kClassId, |
| 11077 size, | 11094 size, |
| 11078 Heap::kOld); | 11095 Heap::kOld); |
| 11079 NoGCScope no_gc; | 11096 NoGCScope no_gc; |
| 11080 result ^= raw; | 11097 result ^= raw; |
| 11081 result.raw_ptr()->length_ = num_handlers; | 11098 result.raw_ptr()->num_entries_ = num_handlers; |
| 11082 } | 11099 } |
| 11083 const Array& handled_types_data = (num_handlers == 0) ? | 11100 const Array& handled_types_data = (num_handlers == 0) ? |
| 11084 Object::empty_array() : | 11101 Object::empty_array() : |
| 11085 Array::Handle(Array::New(num_handlers)); | 11102 Array::Handle(Array::New(num_handlers)); |
| 11086 result.set_handled_types_data(handled_types_data); | 11103 result.set_handled_types_data(handled_types_data); |
| 11087 return result.raw(); | 11104 return result.raw(); |
| 11088 } | 11105 } |
| 11089 | 11106 |
| 11090 | 11107 |
| 11091 const char* ExceptionHandlers::ToCString() const { | 11108 const char* ExceptionHandlers::ToCString() const { |
| 11092 if (Length() == 0) { | 11109 if (num_entries() == 0) { |
| 11093 return "No exception handlers\n"; | 11110 return "No exception handlers\n"; |
| 11094 } | 11111 } |
| 11095 Array& handled_types = Array::Handle(); | 11112 Array& handled_types = Array::Handle(); |
| 11096 Type& type = Type::Handle(); | 11113 Type& type = Type::Handle(); |
| 11097 RawExceptionHandlers::HandlerInfo info; | 11114 RawExceptionHandlers::HandlerInfo info; |
| 11098 // First compute the buffer size required. | 11115 // First compute the buffer size required. |
| 11099 const char* kFormat = "%" Pd " => %#" Px " (%" Pd | 11116 const char* kFormat = "%" Pd " => %#" Px " (%" Pd |
| 11100 " types) (outer %" Pd ")\n"; | 11117 " types) (outer %" Pd ")\n"; |
| 11101 const char* kFormat2 = " %d. %s\n"; | 11118 const char* kFormat2 = " %d. %s\n"; |
| 11102 intptr_t len = 1; // Trailing '\0'. | 11119 intptr_t len = 1; // Trailing '\0'. |
| 11103 for (intptr_t i = 0; i < Length(); i++) { | 11120 for (intptr_t i = 0; i < num_entries(); i++) { |
| 11104 GetHandlerInfo(i, &info); | 11121 GetHandlerInfo(i, &info); |
| 11105 handled_types = GetHandledTypes(i); | 11122 handled_types = GetHandledTypes(i); |
| 11106 ASSERT(!handled_types.IsNull()); | 11123 ASSERT(!handled_types.IsNull()); |
| 11107 const intptr_t num_types = handled_types.Length(); | 11124 const intptr_t num_types = handled_types.Length(); |
| 11108 len += OS::SNPrint(NULL, 0, kFormat, | 11125 len += OS::SNPrint(NULL, 0, kFormat, |
| 11109 i, | 11126 i, |
| 11110 info.handler_pc, | 11127 info.handler_pc, |
| 11111 num_types, | 11128 num_types, |
| 11112 info.outer_try_index); | 11129 info.outer_try_index); |
| 11113 for (int k = 0; k < num_types; k++) { | 11130 for (int k = 0; k < num_types; k++) { |
| 11114 type ^= handled_types.At(k); | 11131 type ^= handled_types.At(k); |
| 11115 ASSERT(!type.IsNull()); | 11132 ASSERT(!type.IsNull()); |
| 11116 len += OS::SNPrint(NULL, 0, kFormat2, k, type.ToCString()); | 11133 len += OS::SNPrint(NULL, 0, kFormat2, k, type.ToCString()); |
| 11117 } | 11134 } |
| 11118 } | 11135 } |
| 11119 // Allocate the buffer. | 11136 // Allocate the buffer. |
| 11120 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len); | 11137 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 11121 // Layout the fields in the buffer. | 11138 // Layout the fields in the buffer. |
| 11122 intptr_t num_chars = 0; | 11139 intptr_t num_chars = 0; |
| 11123 for (intptr_t i = 0; i < Length(); i++) { | 11140 for (intptr_t i = 0; i < num_entries(); i++) { |
| 11124 GetHandlerInfo(i, &info); | 11141 GetHandlerInfo(i, &info); |
| 11125 handled_types = GetHandledTypes(i); | 11142 handled_types = GetHandledTypes(i); |
| 11126 const intptr_t num_types = handled_types.Length(); | 11143 const intptr_t num_types = handled_types.Length(); |
| 11127 num_chars += OS::SNPrint((buffer + num_chars), | 11144 num_chars += OS::SNPrint((buffer + num_chars), |
| 11128 (len - num_chars), | 11145 (len - num_chars), |
| 11129 kFormat, | 11146 kFormat, |
| 11130 i, | 11147 i, |
| 11131 info.handler_pc, | 11148 info.handler_pc, |
| 11132 num_types, | 11149 num_types, |
| 11133 info.outer_try_index); | 11150 info.outer_try_index); |
| (...skipping 9200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20334 return tag_label.ToCString(); | 20351 return tag_label.ToCString(); |
| 20335 } | 20352 } |
| 20336 | 20353 |
| 20337 | 20354 |
| 20338 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20355 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 20339 Instance::PrintJSONImpl(stream, ref); | 20356 Instance::PrintJSONImpl(stream, ref); |
| 20340 } | 20357 } |
| 20341 | 20358 |
| 20342 | 20359 |
| 20343 } // namespace dart | 20360 } // namespace dart |
| OLD | NEW |