| 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 7925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7936 return result.raw(); | 7936 return result.raw(); |
| 7937 } | 7937 } |
| 7938 | 7938 |
| 7939 | 7939 |
| 7940 const char* TokenStream::ToCString() const { | 7940 const char* TokenStream::ToCString() const { |
| 7941 return "TokenStream"; | 7941 return "TokenStream"; |
| 7942 } | 7942 } |
| 7943 | 7943 |
| 7944 | 7944 |
| 7945 void TokenStream::PrintJSONImpl(JSONStream* stream, bool ref) const { | 7945 void TokenStream::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 7946 Object::PrintJSONImpl(stream, ref); | 7946 JSONObject jsobj(stream); |
| 7947 jsobj.AddProperty("type", JSONType(ref)); |
| 7948 // TODO(johnmccutchan): Generate a stable id. TokenStreams hang off |
| 7949 // a Script object but do not have a back reference to generate a stable id. |
| 7950 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
| 7951 const intptr_t id = ring->GetIdForObject(raw()); |
| 7952 jsobj.AddPropertyF("id", "objects/%" Pd "", id); |
| 7953 if (ref) { |
| 7954 return; |
| 7955 } |
| 7956 const String& private_key = String::Handle(PrivateKey()); |
| 7957 jsobj.AddProperty("privateKey", private_key); |
| 7958 // TODO(johnmccutchan): Add support for printing LiteralTokens and add |
| 7959 // them to members array. |
| 7960 JSONArray members(&jsobj, "members"); |
| 7947 } | 7961 } |
| 7948 | 7962 |
| 7949 | 7963 |
| 7950 TokenStream::Iterator::Iterator(const TokenStream& tokens, | 7964 TokenStream::Iterator::Iterator(const TokenStream& tokens, |
| 7951 intptr_t token_pos, | 7965 intptr_t token_pos, |
| 7952 Iterator::StreamType stream_type) | 7966 Iterator::StreamType stream_type) |
| 7953 : tokens_(TokenStream::Handle(tokens.raw())), | 7967 : tokens_(TokenStream::Handle(tokens.raw())), |
| 7954 data_(ExternalTypedData::Handle(tokens.GetStream())), | 7968 data_(ExternalTypedData::Handle(tokens.GetStream())), |
| 7955 stream_(reinterpret_cast<uint8_t*>(data_.DataAddr(0)), data_.Length()), | 7969 stream_(reinterpret_cast<uint8_t*>(data_.DataAddr(0)), data_.Length()), |
| 7956 token_objects_(Array::Handle(tokens.TokenObjects())), | 7970 token_objects_(Array::Handle(tokens.TokenObjects())), |
| (...skipping 2588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10545 iter.Pc(), | 10559 iter.Pc(), |
| 10546 KindAsStr(iter.Kind()), | 10560 KindAsStr(iter.Kind()), |
| 10547 iter.DeoptId(), | 10561 iter.DeoptId(), |
| 10548 iter.TokenPos(), | 10562 iter.TokenPos(), |
| 10549 iter.TryIndex()); | 10563 iter.TryIndex()); |
| 10550 } | 10564 } |
| 10551 return buffer; | 10565 return buffer; |
| 10552 } | 10566 } |
| 10553 | 10567 |
| 10554 | 10568 |
| 10555 void PcDescriptors::PrintToJSONObject(JSONObject* jsobj) const { | 10569 void PcDescriptors::PrintToJSONObject(JSONObject* jsobj, bool ref) const { |
| 10556 jsobj->AddProperty("type", JSONType(false)); | 10570 jsobj->AddProperty("type", JSONType(ref)); |
| 10557 // TODO(johnmccutchan): Generate a valid ID. | 10571 // TODO(johnmccutchan): Generate a stable id. PcDescriptors hang off a Code |
| 10558 // PcDescriptors hang off a Code object but do not have a back reference to | 10572 // object but do not have a back reference to generate an ID. |
| 10559 // generate an ID. Currently we only print PcDescriptors inline with a Code. | 10573 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
| 10560 jsobj->AddProperty("id", ""); | 10574 const intptr_t id = ring->GetIdForObject(raw()); |
| 10575 jsobj->AddPropertyF("id", "objects/%" Pd "", id); |
| 10576 if (ref) { |
| 10577 return; |
| 10578 } |
| 10561 JSONArray members(jsobj, "members"); | 10579 JSONArray members(jsobj, "members"); |
| 10562 Iterator iter(*this, RawPcDescriptors::kAnyKind); | 10580 Iterator iter(*this, RawPcDescriptors::kAnyKind); |
| 10563 while (iter.MoveNext()) { | 10581 while (iter.MoveNext()) { |
| 10564 JSONObject descriptor(&members); | 10582 JSONObject descriptor(&members); |
| 10565 descriptor.AddPropertyF("pc", "%" Px "", iter.Pc()); | 10583 descriptor.AddPropertyF("pc", "%" Px "", iter.Pc()); |
| 10566 descriptor.AddProperty("kind", KindAsStr(iter.Kind())); | 10584 descriptor.AddProperty("kind", KindAsStr(iter.Kind())); |
| 10567 descriptor.AddProperty("deoptId", iter.DeoptId()); | 10585 descriptor.AddProperty("deoptId", iter.DeoptId()); |
| 10568 descriptor.AddProperty("tokenPos", iter.TokenPos()); | 10586 descriptor.AddProperty("tokenPos", iter.TokenPos()); |
| 10569 descriptor.AddProperty("tryIndex", iter.TryIndex()); | 10587 descriptor.AddProperty("tryIndex", iter.TryIndex()); |
| 10570 } | 10588 } |
| 10571 } | 10589 } |
| 10572 | 10590 |
| 10573 | 10591 |
| 10574 void PcDescriptors::PrintJSONImpl(JSONStream* stream, bool ref) const { | 10592 void PcDescriptors::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 10575 JSONObject jsobj(stream); | 10593 JSONObject jsobj(stream); |
| 10576 PrintToJSONObject(&jsobj); | 10594 PrintToJSONObject(&jsobj, ref); |
| 10577 } | 10595 } |
| 10578 | 10596 |
| 10579 | 10597 |
| 10580 // Verify assumptions (in debug mode only). | 10598 // Verify assumptions (in debug mode only). |
| 10581 // - No two deopt descriptors have the same deoptimization id. | 10599 // - No two deopt descriptors have the same deoptimization id. |
| 10582 // - No two ic-call descriptors have the same deoptimization id (type feedback). | 10600 // - No two ic-call descriptors have the same deoptimization id (type feedback). |
| 10583 // A function without unique ids is marked as non-optimizable (e.g., because of | 10601 // A function without unique ids is marked as non-optimizable (e.g., because of |
| 10584 // finally blocks). | 10602 // finally blocks). |
| 10585 void PcDescriptors::Verify(const Function& function) const { | 10603 void PcDescriptors::Verify(const Function& function) const { |
| 10586 #if defined(DEBUG) | 10604 #if defined(DEBUG) |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10840 num_chars += PrintVarInfo((buffer + num_chars), | 10858 num_chars += PrintVarInfo((buffer + num_chars), |
| 10841 (len - num_chars), | 10859 (len - num_chars), |
| 10842 i, var_name, info); | 10860 i, var_name, info); |
| 10843 } | 10861 } |
| 10844 return buffer; | 10862 return buffer; |
| 10845 } | 10863 } |
| 10846 | 10864 |
| 10847 | 10865 |
| 10848 void LocalVarDescriptors::PrintJSONImpl(JSONStream* stream, | 10866 void LocalVarDescriptors::PrintJSONImpl(JSONStream* stream, |
| 10849 bool ref) const { | 10867 bool ref) const { |
| 10850 Object::PrintJSONImpl(stream, ref); | 10868 JSONObject jsobj(stream); |
| 10869 jsobj.AddProperty("type", JSONType(ref)); |
| 10870 // TODO(johnmccutchan): Generate a stable id. LocalVarDescriptors hang off |
| 10871 // a Code object but do not have a back reference to generate an ID. |
| 10872 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
| 10873 const intptr_t id = ring->GetIdForObject(raw()); |
| 10874 jsobj.AddPropertyF("id", "objects/%" Pd "", id); |
| 10875 if (ref) { |
| 10876 return; |
| 10877 } |
| 10878 JSONArray members(&jsobj, "members"); |
| 10879 String& var_name = String::Handle(); |
| 10880 for (intptr_t i = 0; i < Length(); i++) { |
| 10881 RawLocalVarDescriptors::VarInfo info; |
| 10882 var_name = GetName(i); |
| 10883 if (var_name.IsNull()) { |
| 10884 var_name = Symbols::Empty().raw(); |
| 10885 } |
| 10886 GetInfo(i, &info); |
| 10887 JSONObject var(&members); |
| 10888 var.AddProperty("name", var_name.ToCString()); |
| 10889 var.AddProperty("index", info.index); |
| 10890 var.AddProperty("beginPos", info.begin_pos); |
| 10891 var.AddProperty("endPos", info.end_pos); |
| 10892 var.AddProperty("scopeId", static_cast<intptr_t>(info.scope_id)); |
| 10893 var.AddProperty("kind", KindToStr(info.kind)); |
| 10894 } |
| 10851 } | 10895 } |
| 10852 | 10896 |
| 10853 | 10897 |
| 10898 const char* LocalVarDescriptors::KindToStr(intptr_t kind) { |
| 10899 switch (kind) { |
| 10900 case RawLocalVarDescriptors::kStackVar: |
| 10901 return "StackVar"; |
| 10902 case RawLocalVarDescriptors::kContextVar: |
| 10903 return "ContextVar"; |
| 10904 case RawLocalVarDescriptors::kContextLevel: |
| 10905 return "ContextLevel"; |
| 10906 case RawLocalVarDescriptors::kSavedEntryContext: |
| 10907 return "SavedEntryContext"; |
| 10908 case RawLocalVarDescriptors::kSavedCurrentContext: |
| 10909 return "SavedCurrentContext"; |
| 10910 default: |
| 10911 UNIMPLEMENTED(); |
| 10912 return NULL; |
| 10913 } |
| 10914 } |
| 10915 |
| 10854 RawLocalVarDescriptors* LocalVarDescriptors::New(intptr_t num_variables) { | 10916 RawLocalVarDescriptors* LocalVarDescriptors::New(intptr_t num_variables) { |
| 10855 ASSERT(Object::var_descriptors_class() != Class::null()); | 10917 ASSERT(Object::var_descriptors_class() != Class::null()); |
| 10856 if (num_variables < 0 || num_variables > kMaxElements) { | 10918 if (num_variables < 0 || num_variables > kMaxElements) { |
| 10857 // This should be caught before we reach here. | 10919 // This should be caught before we reach here. |
| 10858 FATAL1("Fatal error in LocalVarDescriptors::New: " | 10920 FATAL1("Fatal error in LocalVarDescriptors::New: " |
| 10859 "invalid num_variables %" Pd "\n", num_variables); | 10921 "invalid num_variables %" Pd "\n", num_variables); |
| 10860 } | 10922 } |
| 10861 LocalVarDescriptors& result = LocalVarDescriptors::Handle(); | 10923 LocalVarDescriptors& result = LocalVarDescriptors::Handle(); |
| 10862 { | 10924 { |
| 10863 uword size = LocalVarDescriptors::InstanceSize(num_variables); | 10925 uword size = LocalVarDescriptors::InstanceSize(num_variables); |
| (...skipping 1438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12302 JSONArray jsarr(&jsobj, "disassembly"); | 12364 JSONArray jsarr(&jsobj, "disassembly"); |
| 12303 if (is_alive()) { | 12365 if (is_alive()) { |
| 12304 // Only disassemble alive code objects. | 12366 // Only disassemble alive code objects. |
| 12305 DisassembleToJSONStream formatter(jsarr); | 12367 DisassembleToJSONStream formatter(jsarr); |
| 12306 Disassemble(&formatter); | 12368 Disassemble(&formatter); |
| 12307 } | 12369 } |
| 12308 } | 12370 } |
| 12309 const PcDescriptors& descriptors = PcDescriptors::Handle(pc_descriptors()); | 12371 const PcDescriptors& descriptors = PcDescriptors::Handle(pc_descriptors()); |
| 12310 if (!descriptors.IsNull()) { | 12372 if (!descriptors.IsNull()) { |
| 12311 JSONObject desc(&jsobj, "descriptors"); | 12373 JSONObject desc(&jsobj, "descriptors"); |
| 12312 descriptors.PrintToJSONObject(&desc); | 12374 descriptors.PrintToJSONObject(&desc, false); |
| 12313 } | 12375 } |
| 12314 } | 12376 } |
| 12315 | 12377 |
| 12316 | 12378 |
| 12317 uword Code::GetEntryPatchPc() const { | 12379 uword Code::GetEntryPatchPc() const { |
| 12318 return (entry_patch_pc_offset() != kInvalidPc) | 12380 return (entry_patch_pc_offset() != kInvalidPc) |
| 12319 ? EntryPoint() + entry_patch_pc_offset() : 0; | 12381 ? EntryPoint() + entry_patch_pc_offset() : 0; |
| 12320 } | 12382 } |
| 12321 | 12383 |
| 12322 | 12384 |
| (...skipping 7365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19688 return tag_label.ToCString(); | 19750 return tag_label.ToCString(); |
| 19689 } | 19751 } |
| 19690 | 19752 |
| 19691 | 19753 |
| 19692 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 19754 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 19693 Instance::PrintJSONImpl(stream, ref); | 19755 Instance::PrintJSONImpl(stream, ref); |
| 19694 } | 19756 } |
| 19695 | 19757 |
| 19696 | 19758 |
| 19697 } // namespace dart | 19759 } // namespace dart |
| OLD | NEW |