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 10660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10671 Stackmap::InstanceSize(length), | 10671 Stackmap::InstanceSize(length), |
10672 Heap::kOld); | 10672 Heap::kOld); |
10673 NoGCScope no_gc; | 10673 NoGCScope no_gc; |
10674 result ^= raw; | 10674 result ^= raw; |
10675 result.SetLength(length); | 10675 result.SetLength(length); |
10676 } | 10676 } |
10677 // When constructing a stackmap we store the pc offset in the stackmap's | 10677 // When constructing a stackmap we store the pc offset in the stackmap's |
10678 // PC. StackmapTableBuilder::FinalizeStackmaps will replace it with the pc | 10678 // PC. StackmapTableBuilder::FinalizeStackmaps will replace it with the pc |
10679 // address. | 10679 // address. |
10680 ASSERT(pc_offset >= 0); | 10680 ASSERT(pc_offset >= 0); |
10681 result.SetPC(pc_offset); | 10681 result.SetPcOffset(pc_offset); |
10682 for (intptr_t i = 0; i < length; ++i) { | 10682 for (intptr_t i = 0; i < length; ++i) { |
10683 result.SetBit(i, bmap->Get(i)); | 10683 result.SetBit(i, bmap->Get(i)); |
10684 } | 10684 } |
10685 result.SetRegisterBitCount(register_bit_count); | 10685 result.SetRegisterBitCount(register_bit_count); |
10686 return result.raw(); | 10686 return result.raw(); |
10687 } | 10687 } |
10688 | 10688 |
10689 | 10689 |
10690 const char* Stackmap::ToCString() const { | 10690 const char* Stackmap::ToCString() const { |
10691 if (IsNull()) { | 10691 if (IsNull()) { |
10692 return "{null}"; | 10692 return "{null}"; |
10693 } else { | 10693 } else { |
10694 const char* kFormat = "%#" Px ": "; | 10694 const char* kFormat = "%#" Px ": "; |
10695 intptr_t fixed_length = OS::SNPrint(NULL, 0, kFormat, PC()) + 1; | 10695 intptr_t fixed_length = OS::SNPrint(NULL, 0, kFormat, PcOffset()) + 1; |
10696 Isolate* isolate = Isolate::Current(); | 10696 Isolate* isolate = Isolate::Current(); |
10697 // Guard against integer overflow in the computation of alloc_size. | 10697 // Guard against integer overflow in the computation of alloc_size. |
10698 // | 10698 // |
10699 // TODO(kmillikin): We could just truncate the string if someone | 10699 // TODO(kmillikin): We could just truncate the string if someone |
10700 // tries to print a 2 billion plus entry stackmap. | 10700 // tries to print a 2 billion plus entry stackmap. |
10701 if (Length() > (kIntptrMax - fixed_length)) { | 10701 if (Length() > (kIntptrMax - fixed_length)) { |
10702 FATAL1("Length() is unexpectedly large (%" Pd ")", Length()); | 10702 FATAL1("Length() is unexpectedly large (%" Pd ")", Length()); |
10703 } | 10703 } |
10704 intptr_t alloc_size = fixed_length + Length(); | 10704 intptr_t alloc_size = fixed_length + Length(); |
10705 char* chars = isolate->current_zone()->Alloc<char>(alloc_size); | 10705 char* chars = isolate->current_zone()->Alloc<char>(alloc_size); |
10706 intptr_t index = OS::SNPrint(chars, alloc_size, kFormat, PC()); | 10706 intptr_t index = OS::SNPrint(chars, alloc_size, kFormat, PcOffset()); |
10707 for (intptr_t i = 0; i < Length(); i++) { | 10707 for (intptr_t i = 0; i < Length(); i++) { |
10708 chars[index++] = IsObject(i) ? '1' : '0'; | 10708 chars[index++] = IsObject(i) ? '1' : '0'; |
10709 } | 10709 } |
10710 chars[index] = '\0'; | 10710 chars[index] = '\0'; |
10711 return chars; | 10711 return chars; |
10712 } | 10712 } |
10713 } | 10713 } |
10714 | 10714 |
10715 | 10715 |
10716 void Stackmap::PrintJSONImpl(JSONStream* stream, bool ref) const { | 10716 void Stackmap::PrintJSONImpl(JSONStream* stream, bool ref) const { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10767 UNREACHABLE(); | 10767 UNREACHABLE(); |
10768 return "Unknown"; | 10768 return "Unknown"; |
10769 } | 10769 } |
10770 } | 10770 } |
10771 | 10771 |
10772 | 10772 |
10773 static int PrintVarInfo(char* buffer, int len, | 10773 static int PrintVarInfo(char* buffer, int len, |
10774 intptr_t i, | 10774 intptr_t i, |
10775 const String& var_name, | 10775 const String& var_name, |
10776 const RawLocalVarDescriptors::VarInfo& info) { | 10776 const RawLocalVarDescriptors::VarInfo& info) { |
10777 if (info.kind == RawLocalVarDescriptors::kContextLevel) { | 10777 const int8_t kind = info.kind(); |
| 10778 const int32_t index = info.index(); |
| 10779 if (kind == RawLocalVarDescriptors::kContextLevel) { |
10778 return OS::SNPrint(buffer, len, | 10780 return OS::SNPrint(buffer, len, |
10779 "%2" Pd " %-13s level=%-3" Pd " scope=%-3d" | 10781 "%2" Pd " %-13s level=%-3d scope=%-3d" |
10780 " begin=%-3" Pd " end=%" Pd "\n", | 10782 " begin=%-3d end=%d\n", |
10781 i, | 10783 i, |
10782 VarKindString(info.kind), | 10784 VarKindString(kind), |
10783 info.index, | 10785 index, |
10784 info.scope_id, | 10786 info.scope_id, |
10785 info.begin_pos, | 10787 info.begin_pos, |
10786 info.end_pos); | 10788 info.end_pos); |
10787 } else if (info.kind == RawLocalVarDescriptors::kContextVar) { | 10789 } else if (kind == RawLocalVarDescriptors::kContextVar) { |
10788 return OS::SNPrint(buffer, len, | 10790 return OS::SNPrint(buffer, len, |
10789 "%2" Pd " %-13s level=%-3d index=%-3" Pd "" | 10791 "%2" Pd " %-13s level=%-3d index=%-3d" |
10790 " begin=%-3" Pd " end=%-3" Pd " name=%s\n", | 10792 " begin=%-3d end=%-3d name=%s\n", |
10791 i, | 10793 i, |
10792 VarKindString(info.kind), | 10794 VarKindString(kind), |
10793 info.scope_id, | 10795 info.scope_id, |
10794 info.index, | 10796 index, |
10795 info.begin_pos, | 10797 info.begin_pos, |
10796 info.end_pos, | 10798 info.end_pos, |
10797 var_name.ToCString()); | 10799 var_name.ToCString()); |
10798 } else { | 10800 } else { |
10799 return OS::SNPrint(buffer, len, | 10801 return OS::SNPrint(buffer, len, |
10800 "%2" Pd " %-13s scope=%-3d index=%-3" Pd "" | 10802 "%2" Pd " %-13s scope=%-3d index=%-3d" |
10801 " begin=%-3" Pd " end=%-3" Pd " name=%s\n", | 10803 " begin=%-3d end=%-3d name=%s\n", |
10802 i, | 10804 i, |
10803 VarKindString(info.kind), | 10805 VarKindString(kind), |
10804 info.scope_id, | 10806 info.scope_id, |
10805 info.index, | 10807 index, |
10806 info.begin_pos, | 10808 info.begin_pos, |
10807 info.end_pos, | 10809 info.end_pos, |
10808 var_name.ToCString()); | 10810 var_name.ToCString()); |
10809 } | 10811 } |
10810 } | 10812 } |
10811 | 10813 |
10812 | 10814 |
10813 const char* LocalVarDescriptors::ToCString() const { | 10815 const char* LocalVarDescriptors::ToCString() const { |
10814 if (IsNull()) { | 10816 if (IsNull()) { |
10815 return "LocalVarDescriptors(NULL)"; | 10817 return "LocalVarDescriptors(NULL)"; |
(...skipping 30 matching lines...) Expand all Loading... |
10846 void LocalVarDescriptors::PrintJSONImpl(JSONStream* stream, | 10848 void LocalVarDescriptors::PrintJSONImpl(JSONStream* stream, |
10847 bool ref) const { | 10849 bool ref) const { |
10848 Object::PrintJSONImpl(stream, ref); | 10850 Object::PrintJSONImpl(stream, ref); |
10849 } | 10851 } |
10850 | 10852 |
10851 | 10853 |
10852 RawLocalVarDescriptors* LocalVarDescriptors::New(intptr_t num_variables) { | 10854 RawLocalVarDescriptors* LocalVarDescriptors::New(intptr_t num_variables) { |
10853 ASSERT(Object::var_descriptors_class() != Class::null()); | 10855 ASSERT(Object::var_descriptors_class() != Class::null()); |
10854 if (num_variables < 0 || num_variables > kMaxElements) { | 10856 if (num_variables < 0 || num_variables > kMaxElements) { |
10855 // This should be caught before we reach here. | 10857 // This should be caught before we reach here. |
10856 FATAL1("Fatal error in LocalVarDescriptors::New: " | 10858 FATAL2("Fatal error in LocalVarDescriptors::New: " |
10857 "invalid num_variables %" Pd "\n", num_variables); | 10859 "invalid num_variables %" Pd ". Maximum is: %d\n", |
| 10860 num_variables, RawLocalVarDescriptors::kMaxIndex); |
10858 } | 10861 } |
10859 LocalVarDescriptors& result = LocalVarDescriptors::Handle(); | 10862 LocalVarDescriptors& result = LocalVarDescriptors::Handle(); |
10860 { | 10863 { |
10861 uword size = LocalVarDescriptors::InstanceSize(num_variables); | 10864 uword size = LocalVarDescriptors::InstanceSize(num_variables); |
10862 RawObject* raw = Object::Allocate(LocalVarDescriptors::kClassId, | 10865 RawObject* raw = Object::Allocate(LocalVarDescriptors::kClassId, |
10863 size, | 10866 size, |
10864 Heap::kOld); | 10867 Heap::kOld); |
10865 NoGCScope no_gc; | 10868 NoGCScope no_gc; |
10866 result ^= raw; | 10869 result ^= raw; |
10867 result.raw_ptr()->length_ = num_variables; | 10870 result.raw_ptr()->length_ = num_variables; |
(...skipping 1466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12334 ? EntryPoint() + patch_code_pc_offset() : 0; | 12337 ? EntryPoint() + patch_code_pc_offset() : 0; |
12335 } | 12338 } |
12336 | 12339 |
12337 | 12340 |
12338 uword Code::GetLazyDeoptPc() const { | 12341 uword Code::GetLazyDeoptPc() const { |
12339 return (lazy_deopt_pc_offset() != kInvalidPc) | 12342 return (lazy_deopt_pc_offset() != kInvalidPc) |
12340 ? EntryPoint() + lazy_deopt_pc_offset() : 0; | 12343 ? EntryPoint() + lazy_deopt_pc_offset() : 0; |
12341 } | 12344 } |
12342 | 12345 |
12343 | 12346 |
12344 RawStackmap* Code::GetStackmap(uword pc, Array* maps, Stackmap* map) const { | 12347 RawStackmap* Code::GetStackmap( |
| 12348 uint32_t pc_offset, Array* maps, Stackmap* map) const { |
12345 // This code is used during iterating frames during a GC and hence it | 12349 // This code is used during iterating frames during a GC and hence it |
12346 // should not in turn start a GC. | 12350 // should not in turn start a GC. |
12347 NoGCScope no_gc; | 12351 NoGCScope no_gc; |
12348 if (stackmaps() == Array::null()) { | 12352 if (stackmaps() == Array::null()) { |
12349 // No stack maps are present in the code object which means this | 12353 // No stack maps are present in the code object which means this |
12350 // frame relies on tagged pointers. | 12354 // frame relies on tagged pointers. |
12351 return Stackmap::null(); | 12355 return Stackmap::null(); |
12352 } | 12356 } |
12353 // A stack map is present in the code object, use the stack map to visit | 12357 // A stack map is present in the code object, use the stack map to visit |
12354 // frame slots which are marked as having objects. | 12358 // frame slots which are marked as having objects. |
12355 *maps = stackmaps(); | 12359 *maps = stackmaps(); |
12356 *map = Stackmap::null(); | 12360 *map = Stackmap::null(); |
12357 for (intptr_t i = 0; i < maps->Length(); i++) { | 12361 for (intptr_t i = 0; i < maps->Length(); i++) { |
12358 *map ^= maps->At(i); | 12362 *map ^= maps->At(i); |
12359 ASSERT(!map->IsNull()); | 12363 ASSERT(!map->IsNull()); |
12360 if (map->PC() == pc) { | 12364 if (map->PcOffset() == pc_offset) { |
12361 return map->raw(); // We found a stack map for this frame. | 12365 return map->raw(); // We found a stack map for this frame. |
12362 } | 12366 } |
12363 } | 12367 } |
12364 // If the code has stackmaps, it must have them for all safepoints. | 12368 // If the code has stackmaps, it must have them for all safepoints. |
12365 UNREACHABLE(); | 12369 UNREACHABLE(); |
12366 return Stackmap::null(); | 12370 return Stackmap::null(); |
12367 } | 12371 } |
12368 | 12372 |
12369 | 12373 |
12370 RawContext* Context::New(intptr_t num_variables, Heap::Space space) { | 12374 RawContext* Context::New(intptr_t num_variables, Heap::Space space) { |
(...skipping 6974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19345 | 19349 |
19346 RawJSRegExp* JSRegExp::FromDataStartAddress(void* data) { | 19350 RawJSRegExp* JSRegExp::FromDataStartAddress(void* data) { |
19347 JSRegExp& regexp = JSRegExp::Handle(); | 19351 JSRegExp& regexp = JSRegExp::Handle(); |
19348 intptr_t addr = reinterpret_cast<intptr_t>(data) - sizeof(RawJSRegExp); | 19352 intptr_t addr = reinterpret_cast<intptr_t>(data) - sizeof(RawJSRegExp); |
19349 regexp ^= RawObject::FromAddr(addr); | 19353 regexp ^= RawObject::FromAddr(addr); |
19350 return regexp.raw(); | 19354 return regexp.raw(); |
19351 } | 19355 } |
19352 | 19356 |
19353 | 19357 |
19354 const char* JSRegExp::Flags() const { | 19358 const char* JSRegExp::Flags() const { |
19355 switch (raw_ptr()->flags_) { | 19359 switch (flags()) { |
19356 case kGlobal | kIgnoreCase | kMultiLine : | 19360 case kGlobal | kIgnoreCase | kMultiLine : |
19357 case kIgnoreCase | kMultiLine : | 19361 case kIgnoreCase | kMultiLine : |
19358 return "im"; | 19362 return "im"; |
19359 case kGlobal | kIgnoreCase : | 19363 case kGlobal | kIgnoreCase : |
19360 case kIgnoreCase: | 19364 case kIgnoreCase: |
19361 return "i"; | 19365 return "i"; |
19362 case kGlobal | kMultiLine : | 19366 case kGlobal | kMultiLine : |
19363 case kMultiLine: | 19367 case kMultiLine: |
19364 return "m"; | 19368 return "m"; |
19365 default: | 19369 default: |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19616 return tag_label.ToCString(); | 19620 return tag_label.ToCString(); |
19617 } | 19621 } |
19618 | 19622 |
19619 | 19623 |
19620 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 19624 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
19621 Instance::PrintJSONImpl(stream, ref); | 19625 Instance::PrintJSONImpl(stream, ref); |
19622 } | 19626 } |
19623 | 19627 |
19624 | 19628 |
19625 } // namespace dart | 19629 } // namespace dart |
OLD | NEW |