| 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 10680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10691 Stackmap::InstanceSize(length), | 10691 Stackmap::InstanceSize(length), |
| 10692 Heap::kOld); | 10692 Heap::kOld); |
| 10693 NoGCScope no_gc; | 10693 NoGCScope no_gc; |
| 10694 result ^= raw; | 10694 result ^= raw; |
| 10695 result.SetLength(length); | 10695 result.SetLength(length); |
| 10696 } | 10696 } |
| 10697 // When constructing a stackmap we store the pc offset in the stackmap's | 10697 // When constructing a stackmap we store the pc offset in the stackmap's |
| 10698 // PC. StackmapTableBuilder::FinalizeStackmaps will replace it with the pc | 10698 // PC. StackmapTableBuilder::FinalizeStackmaps will replace it with the pc |
| 10699 // address. | 10699 // address. |
| 10700 ASSERT(pc_offset >= 0); | 10700 ASSERT(pc_offset >= 0); |
| 10701 result.SetPC(pc_offset); | 10701 result.SetPcOffset(pc_offset); |
| 10702 for (intptr_t i = 0; i < length; ++i) { | 10702 for (intptr_t i = 0; i < length; ++i) { |
| 10703 result.SetBit(i, bmap->Get(i)); | 10703 result.SetBit(i, bmap->Get(i)); |
| 10704 } | 10704 } |
| 10705 result.SetRegisterBitCount(register_bit_count); | 10705 result.SetRegisterBitCount(register_bit_count); |
| 10706 return result.raw(); | 10706 return result.raw(); |
| 10707 } | 10707 } |
| 10708 | 10708 |
| 10709 | 10709 |
| 10710 const char* Stackmap::ToCString() const { | 10710 const char* Stackmap::ToCString() const { |
| 10711 if (IsNull()) { | 10711 if (IsNull()) { |
| 10712 return "{null}"; | 10712 return "{null}"; |
| 10713 } else { | 10713 } else { |
| 10714 const char* kFormat = "%#" Px ": "; | 10714 const char* kFormat = "%#" Px ": "; |
| 10715 intptr_t fixed_length = OS::SNPrint(NULL, 0, kFormat, PC()) + 1; | 10715 intptr_t fixed_length = OS::SNPrint(NULL, 0, kFormat, PcOffset()) + 1; |
| 10716 Isolate* isolate = Isolate::Current(); | 10716 Isolate* isolate = Isolate::Current(); |
| 10717 // Guard against integer overflow in the computation of alloc_size. | 10717 // Guard against integer overflow in the computation of alloc_size. |
| 10718 // | 10718 // |
| 10719 // TODO(kmillikin): We could just truncate the string if someone | 10719 // TODO(kmillikin): We could just truncate the string if someone |
| 10720 // tries to print a 2 billion plus entry stackmap. | 10720 // tries to print a 2 billion plus entry stackmap. |
| 10721 if (Length() > (kIntptrMax - fixed_length)) { | 10721 if (Length() > (kIntptrMax - fixed_length)) { |
| 10722 FATAL1("Length() is unexpectedly large (%" Pd ")", Length()); | 10722 FATAL1("Length() is unexpectedly large (%" Pd ")", Length()); |
| 10723 } | 10723 } |
| 10724 intptr_t alloc_size = fixed_length + Length(); | 10724 intptr_t alloc_size = fixed_length + Length(); |
| 10725 char* chars = isolate->current_zone()->Alloc<char>(alloc_size); | 10725 char* chars = isolate->current_zone()->Alloc<char>(alloc_size); |
| 10726 intptr_t index = OS::SNPrint(chars, alloc_size, kFormat, PC()); | 10726 intptr_t index = OS::SNPrint(chars, alloc_size, kFormat, PcOffset()); |
| 10727 for (intptr_t i = 0; i < Length(); i++) { | 10727 for (intptr_t i = 0; i < Length(); i++) { |
| 10728 chars[index++] = IsObject(i) ? '1' : '0'; | 10728 chars[index++] = IsObject(i) ? '1' : '0'; |
| 10729 } | 10729 } |
| 10730 chars[index] = '\0'; | 10730 chars[index] = '\0'; |
| 10731 return chars; | 10731 return chars; |
| 10732 } | 10732 } |
| 10733 } | 10733 } |
| 10734 | 10734 |
| 10735 | 10735 |
| 10736 void Stackmap::PrintJSONImpl(JSONStream* stream, bool ref) const { | 10736 void Stackmap::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10787 UNREACHABLE(); | 10787 UNREACHABLE(); |
| 10788 return "Unknown"; | 10788 return "Unknown"; |
| 10789 } | 10789 } |
| 10790 } | 10790 } |
| 10791 | 10791 |
| 10792 | 10792 |
| 10793 static int PrintVarInfo(char* buffer, int len, | 10793 static int PrintVarInfo(char* buffer, int len, |
| 10794 intptr_t i, | 10794 intptr_t i, |
| 10795 const String& var_name, | 10795 const String& var_name, |
| 10796 const RawLocalVarDescriptors::VarInfo& info) { | 10796 const RawLocalVarDescriptors::VarInfo& info) { |
| 10797 if (info.kind == RawLocalVarDescriptors::kContextLevel) { | 10797 const int8_t kind = info.kind(); |
| 10798 const int32_t index = info.index(); |
| 10799 if (kind == RawLocalVarDescriptors::kContextLevel) { |
| 10798 return OS::SNPrint(buffer, len, | 10800 return OS::SNPrint(buffer, len, |
| 10799 "%2" Pd " %-13s level=%-3" Pd " scope=%-3d" | 10801 "%2" Pd " %-13s level=%-3d scope=%-3d" |
| 10800 " begin=%-3" Pd " end=%" Pd "\n", | 10802 " begin=%-3d end=%d\n", |
| 10801 i, | 10803 i, |
| 10802 VarKindString(info.kind), | 10804 VarKindString(kind), |
| 10803 info.index, | 10805 index, |
| 10804 info.scope_id, | 10806 info.scope_id, |
| 10805 info.begin_pos, | 10807 info.begin_pos, |
| 10806 info.end_pos); | 10808 info.end_pos); |
| 10807 } else if (info.kind == RawLocalVarDescriptors::kContextVar) { | 10809 } else if (kind == RawLocalVarDescriptors::kContextVar) { |
| 10808 return OS::SNPrint(buffer, len, | 10810 return OS::SNPrint(buffer, len, |
| 10809 "%2" Pd " %-13s level=%-3d index=%-3" Pd "" | 10811 "%2" Pd " %-13s level=%-3d index=%-3d" |
| 10810 " begin=%-3" Pd " end=%-3" Pd " name=%s\n", | 10812 " begin=%-3d end=%-3d name=%s\n", |
| 10811 i, | 10813 i, |
| 10812 VarKindString(info.kind), | 10814 VarKindString(kind), |
| 10813 info.scope_id, | 10815 info.scope_id, |
| 10814 info.index, | 10816 index, |
| 10815 info.begin_pos, | 10817 info.begin_pos, |
| 10816 info.end_pos, | 10818 info.end_pos, |
| 10817 var_name.ToCString()); | 10819 var_name.ToCString()); |
| 10818 } else { | 10820 } else { |
| 10819 return OS::SNPrint(buffer, len, | 10821 return OS::SNPrint(buffer, len, |
| 10820 "%2" Pd " %-13s scope=%-3d index=%-3" Pd "" | 10822 "%2" Pd " %-13s scope=%-3d index=%-3d" |
| 10821 " begin=%-3" Pd " end=%-3" Pd " name=%s\n", | 10823 " begin=%-3d end=%-3d name=%s\n", |
| 10822 i, | 10824 i, |
| 10823 VarKindString(info.kind), | 10825 VarKindString(kind), |
| 10824 info.scope_id, | 10826 info.scope_id, |
| 10825 info.index, | 10827 index, |
| 10826 info.begin_pos, | 10828 info.begin_pos, |
| 10827 info.end_pos, | 10829 info.end_pos, |
| 10828 var_name.ToCString()); | 10830 var_name.ToCString()); |
| 10829 } | 10831 } |
| 10830 } | 10832 } |
| 10831 | 10833 |
| 10832 | 10834 |
| 10833 const char* LocalVarDescriptors::ToCString() const { | 10835 const char* LocalVarDescriptors::ToCString() const { |
| 10834 if (IsNull()) { | 10836 if (IsNull()) { |
| 10835 return "LocalVarDescriptors(NULL)"; | 10837 return "LocalVarDescriptors(NULL)"; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10879 String& var_name = String::Handle(); | 10881 String& var_name = String::Handle(); |
| 10880 for (intptr_t i = 0; i < Length(); i++) { | 10882 for (intptr_t i = 0; i < Length(); i++) { |
| 10881 RawLocalVarDescriptors::VarInfo info; | 10883 RawLocalVarDescriptors::VarInfo info; |
| 10882 var_name = GetName(i); | 10884 var_name = GetName(i); |
| 10883 if (var_name.IsNull()) { | 10885 if (var_name.IsNull()) { |
| 10884 var_name = Symbols::Empty().raw(); | 10886 var_name = Symbols::Empty().raw(); |
| 10885 } | 10887 } |
| 10886 GetInfo(i, &info); | 10888 GetInfo(i, &info); |
| 10887 JSONObject var(&members); | 10889 JSONObject var(&members); |
| 10888 var.AddProperty("name", var_name.ToCString()); | 10890 var.AddProperty("name", var_name.ToCString()); |
| 10889 var.AddProperty("index", info.index); | 10891 var.AddProperty("index", static_cast<intptr_t>(info.index())); |
| 10890 var.AddProperty("beginPos", info.begin_pos); | 10892 var.AddProperty("beginPos", static_cast<intptr_t>(info.begin_pos)); |
| 10891 var.AddProperty("endPos", info.end_pos); | 10893 var.AddProperty("endPos", static_cast<intptr_t>(info.end_pos)); |
| 10892 var.AddProperty("scopeId", static_cast<intptr_t>(info.scope_id)); | 10894 var.AddProperty("scopeId", static_cast<intptr_t>(info.scope_id)); |
| 10893 var.AddProperty("kind", KindToStr(info.kind)); | 10895 var.AddProperty("kind", KindToStr(info.kind())); |
| 10894 } | 10896 } |
| 10895 } | 10897 } |
| 10896 | 10898 |
| 10897 | 10899 |
| 10898 const char* LocalVarDescriptors::KindToStr(intptr_t kind) { | 10900 const char* LocalVarDescriptors::KindToStr(intptr_t kind) { |
| 10899 switch (kind) { | 10901 switch (kind) { |
| 10900 case RawLocalVarDescriptors::kStackVar: | 10902 case RawLocalVarDescriptors::kStackVar: |
| 10901 return "StackVar"; | 10903 return "StackVar"; |
| 10902 case RawLocalVarDescriptors::kContextVar: | 10904 case RawLocalVarDescriptors::kContextVar: |
| 10903 return "ContextVar"; | 10905 return "ContextVar"; |
| 10904 case RawLocalVarDescriptors::kContextLevel: | 10906 case RawLocalVarDescriptors::kContextLevel: |
| 10905 return "ContextLevel"; | 10907 return "ContextLevel"; |
| 10906 case RawLocalVarDescriptors::kSavedEntryContext: | 10908 case RawLocalVarDescriptors::kSavedEntryContext: |
| 10907 return "SavedEntryContext"; | 10909 return "SavedEntryContext"; |
| 10908 case RawLocalVarDescriptors::kSavedCurrentContext: | 10910 case RawLocalVarDescriptors::kSavedCurrentContext: |
| 10909 return "SavedCurrentContext"; | 10911 return "SavedCurrentContext"; |
| 10910 default: | 10912 default: |
| 10911 UNIMPLEMENTED(); | 10913 UNIMPLEMENTED(); |
| 10912 return NULL; | 10914 return NULL; |
| 10913 } | 10915 } |
| 10914 } | 10916 } |
| 10915 | 10917 |
| 10916 RawLocalVarDescriptors* LocalVarDescriptors::New(intptr_t num_variables) { | 10918 RawLocalVarDescriptors* LocalVarDescriptors::New(intptr_t num_variables) { |
| 10917 ASSERT(Object::var_descriptors_class() != Class::null()); | 10919 ASSERT(Object::var_descriptors_class() != Class::null()); |
| 10918 if (num_variables < 0 || num_variables > kMaxElements) { | 10920 if (num_variables < 0 || num_variables > kMaxElements) { |
| 10919 // This should be caught before we reach here. | 10921 // This should be caught before we reach here. |
| 10920 FATAL1("Fatal error in LocalVarDescriptors::New: " | 10922 FATAL2("Fatal error in LocalVarDescriptors::New: " |
| 10921 "invalid num_variables %" Pd "\n", num_variables); | 10923 "invalid num_variables %" Pd ". Maximum is: %d\n", |
| 10924 num_variables, RawLocalVarDescriptors::kMaxIndex); |
| 10922 } | 10925 } |
| 10923 LocalVarDescriptors& result = LocalVarDescriptors::Handle(); | 10926 LocalVarDescriptors& result = LocalVarDescriptors::Handle(); |
| 10924 { | 10927 { |
| 10925 uword size = LocalVarDescriptors::InstanceSize(num_variables); | 10928 uword size = LocalVarDescriptors::InstanceSize(num_variables); |
| 10926 RawObject* raw = Object::Allocate(LocalVarDescriptors::kClassId, | 10929 RawObject* raw = Object::Allocate(LocalVarDescriptors::kClassId, |
| 10927 size, | 10930 size, |
| 10928 Heap::kOld); | 10931 Heap::kOld); |
| 10929 NoGCScope no_gc; | 10932 NoGCScope no_gc; |
| 10930 result ^= raw; | 10933 result ^= raw; |
| 10931 result.raw_ptr()->length_ = num_variables; | 10934 result.raw_ptr()->length_ = num_variables; |
| (...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12387 ? EntryPoint() + patch_code_pc_offset() : 0; | 12390 ? EntryPoint() + patch_code_pc_offset() : 0; |
| 12388 } | 12391 } |
| 12389 | 12392 |
| 12390 | 12393 |
| 12391 uword Code::GetLazyDeoptPc() const { | 12394 uword Code::GetLazyDeoptPc() const { |
| 12392 return (lazy_deopt_pc_offset() != kInvalidPc) | 12395 return (lazy_deopt_pc_offset() != kInvalidPc) |
| 12393 ? EntryPoint() + lazy_deopt_pc_offset() : 0; | 12396 ? EntryPoint() + lazy_deopt_pc_offset() : 0; |
| 12394 } | 12397 } |
| 12395 | 12398 |
| 12396 | 12399 |
| 12397 RawStackmap* Code::GetStackmap(uword pc, Array* maps, Stackmap* map) const { | 12400 RawStackmap* Code::GetStackmap( |
| 12401 uint32_t pc_offset, Array* maps, Stackmap* map) const { |
| 12398 // This code is used during iterating frames during a GC and hence it | 12402 // This code is used during iterating frames during a GC and hence it |
| 12399 // should not in turn start a GC. | 12403 // should not in turn start a GC. |
| 12400 NoGCScope no_gc; | 12404 NoGCScope no_gc; |
| 12401 if (stackmaps() == Array::null()) { | 12405 if (stackmaps() == Array::null()) { |
| 12402 // No stack maps are present in the code object which means this | 12406 // No stack maps are present in the code object which means this |
| 12403 // frame relies on tagged pointers. | 12407 // frame relies on tagged pointers. |
| 12404 return Stackmap::null(); | 12408 return Stackmap::null(); |
| 12405 } | 12409 } |
| 12406 // A stack map is present in the code object, use the stack map to visit | 12410 // A stack map is present in the code object, use the stack map to visit |
| 12407 // frame slots which are marked as having objects. | 12411 // frame slots which are marked as having objects. |
| 12408 *maps = stackmaps(); | 12412 *maps = stackmaps(); |
| 12409 *map = Stackmap::null(); | 12413 *map = Stackmap::null(); |
| 12410 for (intptr_t i = 0; i < maps->Length(); i++) { | 12414 for (intptr_t i = 0; i < maps->Length(); i++) { |
| 12411 *map ^= maps->At(i); | 12415 *map ^= maps->At(i); |
| 12412 ASSERT(!map->IsNull()); | 12416 ASSERT(!map->IsNull()); |
| 12413 if (map->PC() == pc) { | 12417 if (map->PcOffset() == pc_offset) { |
| 12414 return map->raw(); // We found a stack map for this frame. | 12418 return map->raw(); // We found a stack map for this frame. |
| 12415 } | 12419 } |
| 12416 } | 12420 } |
| 12417 // If the code has stackmaps, it must have them for all safepoints. | 12421 // If the code has stackmaps, it must have them for all safepoints. |
| 12418 UNREACHABLE(); | 12422 UNREACHABLE(); |
| 12419 return Stackmap::null(); | 12423 return Stackmap::null(); |
| 12420 } | 12424 } |
| 12421 | 12425 |
| 12422 | 12426 |
| 12423 RawContext* Context::New(intptr_t num_variables, Heap::Space space) { | 12427 RawContext* Context::New(intptr_t num_variables, Heap::Space space) { |
| (...skipping 7031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19455 | 19459 |
| 19456 RawJSRegExp* JSRegExp::FromDataStartAddress(void* data) { | 19460 RawJSRegExp* JSRegExp::FromDataStartAddress(void* data) { |
| 19457 JSRegExp& regexp = JSRegExp::Handle(); | 19461 JSRegExp& regexp = JSRegExp::Handle(); |
| 19458 intptr_t addr = reinterpret_cast<intptr_t>(data) - sizeof(RawJSRegExp); | 19462 intptr_t addr = reinterpret_cast<intptr_t>(data) - sizeof(RawJSRegExp); |
| 19459 regexp ^= RawObject::FromAddr(addr); | 19463 regexp ^= RawObject::FromAddr(addr); |
| 19460 return regexp.raw(); | 19464 return regexp.raw(); |
| 19461 } | 19465 } |
| 19462 | 19466 |
| 19463 | 19467 |
| 19464 const char* JSRegExp::Flags() const { | 19468 const char* JSRegExp::Flags() const { |
| 19465 switch (raw_ptr()->flags_) { | 19469 switch (flags()) { |
| 19466 case kGlobal | kIgnoreCase | kMultiLine : | 19470 case kGlobal | kIgnoreCase | kMultiLine : |
| 19467 case kIgnoreCase | kMultiLine : | 19471 case kIgnoreCase | kMultiLine : |
| 19468 return "im"; | 19472 return "im"; |
| 19469 case kGlobal | kIgnoreCase : | 19473 case kGlobal | kIgnoreCase : |
| 19470 case kIgnoreCase: | 19474 case kIgnoreCase: |
| 19471 return "i"; | 19475 return "i"; |
| 19472 case kGlobal | kMultiLine : | 19476 case kGlobal | kMultiLine : |
| 19473 case kMultiLine: | 19477 case kMultiLine: |
| 19474 return "m"; | 19478 return "m"; |
| 19475 default: | 19479 default: |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19750 return tag_label.ToCString(); | 19754 return tag_label.ToCString(); |
| 19751 } | 19755 } |
| 19752 | 19756 |
| 19753 | 19757 |
| 19754 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 19758 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 19755 Instance::PrintJSONImpl(stream, ref); | 19759 Instance::PrintJSONImpl(stream, ref); |
| 19756 } | 19760 } |
| 19757 | 19761 |
| 19758 | 19762 |
| 19759 } // namespace dart | 19763 } // namespace dart |
| OLD | NEW |