| 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 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 InitializeObject(address, kPcDescriptorsCid, | 662 InitializeObject(address, kPcDescriptorsCid, |
| 663 PcDescriptors::InstanceSize(0, RawPcDescriptors::kCompressedRecSize)); | 663 PcDescriptors::InstanceSize(0, RawPcDescriptors::kCompressedRecSize)); |
| 664 PcDescriptors::initializeHandle( | 664 PcDescriptors::initializeHandle( |
| 665 empty_descriptors_, | 665 empty_descriptors_, |
| 666 reinterpret_cast<RawPcDescriptors*>(address + kHeapObjectTag)); | 666 reinterpret_cast<RawPcDescriptors*>(address + kHeapObjectTag)); |
| 667 empty_descriptors_->raw_ptr()->length_ = 0; | 667 empty_descriptors_->raw_ptr()->length_ = 0; |
| 668 } | 668 } |
| 669 | 669 |
| 670 // Allocate and initialize the canonical empty variable descriptor object. | 670 // Allocate and initialize the canonical empty variable descriptor object. |
| 671 { | 671 { |
| 672 uword address = heap->Allocate( | 672 uword address = |
| 673 LocalVarDescriptors::InstanceSize(0), Heap::kOld); | 673 heap->Allocate(LocalVarDescriptors::InstanceSize(0), Heap::kOld); |
| 674 InitializeObject(address, kLocalVarDescriptorsCid, | 674 InitializeObject(address, |
| 675 LocalVarDescriptors::InstanceSize(0)); | 675 kLocalVarDescriptorsCid, |
| 676 LocalVarDescriptors::InstanceSize(0)); |
| 676 LocalVarDescriptors::initializeHandle( | 677 LocalVarDescriptors::initializeHandle( |
| 677 empty_var_descriptors_, | 678 empty_var_descriptors_, |
| 678 reinterpret_cast<RawLocalVarDescriptors*>(address + kHeapObjectTag)); | 679 reinterpret_cast<RawLocalVarDescriptors*>(address + kHeapObjectTag)); |
| 679 empty_var_descriptors_->raw_ptr()->length_ = 0; | 680 empty_var_descriptors_->raw_ptr()->num_entries_ = 0; |
| 680 // Can't use instance mentod StorePointer() here, but this pointer | |
| 681 // assignment is safe (from old space to old space). | |
| 682 empty_var_descriptors_->raw_ptr()->names_ = empty_array_->raw_ptr(); | |
| 683 } | 681 } |
| 684 | 682 |
| 685 cls = Class::New<Instance>(kDynamicCid); | 683 cls = Class::New<Instance>(kDynamicCid); |
| 686 cls.set_is_abstract(); | 684 cls.set_is_abstract(); |
| 687 cls.set_num_type_arguments(0); | 685 cls.set_num_type_arguments(0); |
| 688 cls.set_num_own_type_arguments(0); | 686 cls.set_num_own_type_arguments(0); |
| 689 cls.set_is_type_finalized(); | 687 cls.set_is_type_finalized(); |
| 690 cls.set_is_finalized(); | 688 cls.set_is_finalized(); |
| 691 dynamic_class_ = cls.raw(); | 689 dynamic_class_ = cls.raw(); |
| 692 | 690 |
| (...skipping 10100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10793 } | 10791 } |
| 10794 | 10792 |
| 10795 | 10793 |
| 10796 void Stackmap::PrintJSONImpl(JSONStream* stream, bool ref) const { | 10794 void Stackmap::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 10797 Object::PrintJSONImpl(stream, ref); | 10795 Object::PrintJSONImpl(stream, ref); |
| 10798 } | 10796 } |
| 10799 | 10797 |
| 10800 | 10798 |
| 10801 RawString* LocalVarDescriptors::GetName(intptr_t var_index) const { | 10799 RawString* LocalVarDescriptors::GetName(intptr_t var_index) const { |
| 10802 ASSERT(var_index < Length()); | 10800 ASSERT(var_index < Length()); |
| 10803 const Array& names = Array::Handle(raw_ptr()->names_); | 10801 ASSERT(Object::Handle(*raw()->nameAddrAt(var_index)).IsString()); |
| 10804 ASSERT(Length() == names.Length()); | 10802 return *raw()->nameAddrAt(var_index); |
| 10805 String& name = String::Handle(); | |
| 10806 name ^= names.At(var_index); | |
| 10807 return name.raw(); | |
| 10808 } | 10803 } |
| 10809 | 10804 |
| 10810 | 10805 |
| 10811 void LocalVarDescriptors::SetVar(intptr_t var_index, | 10806 void LocalVarDescriptors::SetVar(intptr_t var_index, |
| 10812 const String& name, | 10807 const String& name, |
| 10813 RawLocalVarDescriptors::VarInfo* info) const { | 10808 RawLocalVarDescriptors::VarInfo* info) const { |
| 10814 ASSERT(var_index < Length()); | 10809 ASSERT(var_index < Length()); |
| 10815 const Array& names = Array::Handle(raw_ptr()->names_); | 10810 ASSERT(!name.IsNull()); |
| 10816 ASSERT(Length() == names.Length()); | 10811 StorePointer(raw()->nameAddrAt(var_index), name.raw()); |
| 10817 names.SetAt(var_index, name); | 10812 raw()->data()[var_index] = *info; |
| 10818 raw_ptr()->data()[var_index] = *info; | |
| 10819 } | 10813 } |
| 10820 | 10814 |
| 10821 | 10815 |
| 10822 void LocalVarDescriptors::GetInfo(intptr_t var_index, | 10816 void LocalVarDescriptors::GetInfo(intptr_t var_index, |
| 10823 RawLocalVarDescriptors::VarInfo* info) const { | 10817 RawLocalVarDescriptors::VarInfo* info) const { |
| 10824 ASSERT(var_index < Length()); | 10818 ASSERT(var_index < Length()); |
| 10825 *info = raw_ptr()->data()[var_index]; | 10819 *info = raw()->data()[var_index]; |
| 10826 } | 10820 } |
| 10827 | 10821 |
| 10828 | 10822 |
| 10829 static const char* VarKindString(int kind) { | 10823 static const char* VarKindString(int kind) { |
| 10830 switch (kind) { | 10824 switch (kind) { |
| 10831 case RawLocalVarDescriptors::kStackVar: | 10825 case RawLocalVarDescriptors::kStackVar: |
| 10832 return "StackVar"; | 10826 return "StackVar"; |
| 10833 break; | 10827 break; |
| 10834 case RawLocalVarDescriptors::kContextVar: | 10828 case RawLocalVarDescriptors::kContextVar: |
| 10835 return "ContextVar"; | 10829 return "ContextVar"; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10894 | 10888 |
| 10895 const char* LocalVarDescriptors::ToCString() const { | 10889 const char* LocalVarDescriptors::ToCString() const { |
| 10896 if (IsNull()) { | 10890 if (IsNull()) { |
| 10897 return "LocalVarDescriptors(NULL)"; | 10891 return "LocalVarDescriptors(NULL)"; |
| 10898 } | 10892 } |
| 10899 intptr_t len = 1; // Trailing '\0'. | 10893 intptr_t len = 1; // Trailing '\0'. |
| 10900 String& var_name = String::Handle(); | 10894 String& var_name = String::Handle(); |
| 10901 for (intptr_t i = 0; i < Length(); i++) { | 10895 for (intptr_t i = 0; i < Length(); i++) { |
| 10902 RawLocalVarDescriptors::VarInfo info; | 10896 RawLocalVarDescriptors::VarInfo info; |
| 10903 var_name = GetName(i); | 10897 var_name = GetName(i); |
| 10904 if (var_name.IsNull()) { | |
| 10905 var_name = Symbols::Empty().raw(); | |
| 10906 } | |
| 10907 GetInfo(i, &info); | 10898 GetInfo(i, &info); |
| 10908 len += PrintVarInfo(NULL, 0, i, var_name, info); | 10899 len += PrintVarInfo(NULL, 0, i, var_name, info); |
| 10909 } | 10900 } |
| 10910 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len + 1); | 10901 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len + 1); |
| 10911 buffer[0] = '\0'; | 10902 buffer[0] = '\0'; |
| 10912 intptr_t num_chars = 0; | 10903 intptr_t num_chars = 0; |
| 10913 for (intptr_t i = 0; i < Length(); i++) { | 10904 for (intptr_t i = 0; i < Length(); i++) { |
| 10914 RawLocalVarDescriptors::VarInfo info; | 10905 RawLocalVarDescriptors::VarInfo info; |
| 10915 var_name = GetName(i); | 10906 var_name = GetName(i); |
| 10916 if (var_name.IsNull()) { | |
| 10917 var_name = Symbols::Empty().raw(); | |
| 10918 } | |
| 10919 GetInfo(i, &info); | 10907 GetInfo(i, &info); |
| 10920 num_chars += PrintVarInfo((buffer + num_chars), | 10908 num_chars += PrintVarInfo((buffer + num_chars), |
| 10921 (len - num_chars), | 10909 (len - num_chars), |
| 10922 i, var_name, info); | 10910 i, var_name, info); |
| 10923 } | 10911 } |
| 10924 return buffer; | 10912 return buffer; |
| 10925 } | 10913 } |
| 10926 | 10914 |
| 10927 | 10915 |
| 10928 void LocalVarDescriptors::PrintJSONImpl(JSONStream* stream, | 10916 void LocalVarDescriptors::PrintJSONImpl(JSONStream* stream, |
| 10929 bool ref) const { | 10917 bool ref) const { |
| 10930 JSONObject jsobj(stream); | 10918 JSONObject jsobj(stream); |
| 10931 AddTypeProperties(&jsobj, "Object", JSONType(), ref); | 10919 AddTypeProperties(&jsobj, "Object", JSONType(), ref); |
| 10932 // TODO(johnmccutchan): Generate a stable id. LocalVarDescriptors hang off | 10920 // TODO(johnmccutchan): Generate a stable id. LocalVarDescriptors hang off |
| 10933 // a Code object but do not have a back reference to generate an ID. | 10921 // a Code object but do not have a back reference to generate an ID. |
| 10934 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | 10922 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
| 10935 const intptr_t id = ring->GetIdForObject(raw()); | 10923 const intptr_t id = ring->GetIdForObject(raw()); |
| 10936 jsobj.AddPropertyF("id", "objects/%" Pd "", id); | 10924 jsobj.AddPropertyF("id", "objects/%" Pd "", id); |
| 10937 if (ref) { | 10925 if (ref) { |
| 10938 return; | 10926 return; |
| 10939 } | 10927 } |
| 10940 Class& cls = Class::Handle(this->clazz()); | 10928 Class& cls = Class::Handle(this->clazz()); |
| 10941 jsobj.AddProperty("class", cls); | 10929 jsobj.AddProperty("class", cls); |
| 10942 jsobj.AddProperty("size", raw()->Size()); | 10930 jsobj.AddProperty("size", raw()->Size()); |
| 10943 JSONArray members(&jsobj, "members"); | 10931 JSONArray members(&jsobj, "members"); |
| 10944 String& var_name = String::Handle(); | 10932 String& var_name = String::Handle(); |
| 10945 for (intptr_t i = 0; i < Length(); i++) { | 10933 for (intptr_t i = 0; i < Length(); i++) { |
| 10946 RawLocalVarDescriptors::VarInfo info; | 10934 RawLocalVarDescriptors::VarInfo info; |
| 10947 var_name = GetName(i); | 10935 var_name = GetName(i); |
| 10948 if (var_name.IsNull()) { | |
| 10949 var_name = Symbols::Empty().raw(); | |
| 10950 } | |
| 10951 GetInfo(i, &info); | 10936 GetInfo(i, &info); |
| 10952 JSONObject var(&members); | 10937 JSONObject var(&members); |
| 10953 var.AddProperty("name", var_name.ToCString()); | 10938 var.AddProperty("name", var_name.ToCString()); |
| 10954 var.AddProperty("index", static_cast<intptr_t>(info.index())); | 10939 var.AddProperty("index", static_cast<intptr_t>(info.index())); |
| 10955 var.AddProperty("beginPos", static_cast<intptr_t>(info.begin_pos)); | 10940 var.AddProperty("beginPos", static_cast<intptr_t>(info.begin_pos)); |
| 10956 var.AddProperty("endPos", static_cast<intptr_t>(info.end_pos)); | 10941 var.AddProperty("endPos", static_cast<intptr_t>(info.end_pos)); |
| 10957 var.AddProperty("scopeId", static_cast<intptr_t>(info.scope_id)); | 10942 var.AddProperty("scopeId", static_cast<intptr_t>(info.scope_id)); |
| 10958 var.AddProperty("kind", KindToStr(info.kind())); | 10943 var.AddProperty("kind", KindToStr(info.kind())); |
| 10959 } | 10944 } |
| 10960 } | 10945 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 10987 num_variables, RawLocalVarDescriptors::kMaxIndex); | 10972 num_variables, RawLocalVarDescriptors::kMaxIndex); |
| 10988 } | 10973 } |
| 10989 LocalVarDescriptors& result = LocalVarDescriptors::Handle(); | 10974 LocalVarDescriptors& result = LocalVarDescriptors::Handle(); |
| 10990 { | 10975 { |
| 10991 uword size = LocalVarDescriptors::InstanceSize(num_variables); | 10976 uword size = LocalVarDescriptors::InstanceSize(num_variables); |
| 10992 RawObject* raw = Object::Allocate(LocalVarDescriptors::kClassId, | 10977 RawObject* raw = Object::Allocate(LocalVarDescriptors::kClassId, |
| 10993 size, | 10978 size, |
| 10994 Heap::kOld); | 10979 Heap::kOld); |
| 10995 NoGCScope no_gc; | 10980 NoGCScope no_gc; |
| 10996 result ^= raw; | 10981 result ^= raw; |
| 10997 result.raw_ptr()->length_ = num_variables; | 10982 result.raw_ptr()->num_entries_ = num_variables; |
| 10998 } | 10983 } |
| 10999 const Array& names = (num_variables == 0) ? Object::empty_array() : | |
| 11000 Array::Handle(Array::New(num_variables, Heap::kOld)); | |
| 11001 result.raw_ptr()->names_ = names.raw(); | |
| 11002 return result.raw(); | 10984 return result.raw(); |
| 11003 } | 10985 } |
| 11004 | 10986 |
| 11005 | 10987 |
| 11006 intptr_t LocalVarDescriptors::Length() const { | 10988 intptr_t LocalVarDescriptors::Length() const { |
| 11007 return raw_ptr()->length_; | 10989 return raw_ptr()->num_entries_; |
| 11008 } | 10990 } |
| 11009 | 10991 |
| 11010 | 10992 |
| 11011 intptr_t ExceptionHandlers::Length() const { | 10993 intptr_t ExceptionHandlers::Length() const { |
| 11012 return raw_ptr()->length_; | 10994 return raw_ptr()->length_; |
| 11013 } | 10995 } |
| 11014 | 10996 |
| 11015 | 10997 |
| 11016 void ExceptionHandlers::SetHandlerInfo(intptr_t try_index, | 10998 void ExceptionHandlers::SetHandlerInfo(intptr_t try_index, |
| 11017 intptr_t outer_try_index, | 10999 intptr_t outer_try_index, |
| (...skipping 9334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20352 return tag_label.ToCString(); | 20334 return tag_label.ToCString(); |
| 20353 } | 20335 } |
| 20354 | 20336 |
| 20355 | 20337 |
| 20356 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20338 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 20357 Instance::PrintJSONImpl(stream, ref); | 20339 Instance::PrintJSONImpl(stream, ref); |
| 20358 } | 20340 } |
| 20359 | 20341 |
| 20360 | 20342 |
| 20361 } // namespace dart | 20343 } // namespace dart |
| OLD | NEW |