Chromium Code Reviews| 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 5693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5704 static_str, abstract_str, kind_str, const_str); | 5704 static_str, abstract_str, kind_str, const_str); |
| 5705 return chars; | 5705 return chars; |
| 5706 } | 5706 } |
| 5707 | 5707 |
| 5708 | 5708 |
| 5709 void Function::PrintToJSONStream(JSONStream* stream, bool ref) const { | 5709 void Function::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 5710 const char* internal_function_name = String::Handle(name()).ToCString(); | 5710 const char* internal_function_name = String::Handle(name()).ToCString(); |
| 5711 const char* function_name = | 5711 const char* function_name = |
| 5712 String::Handle(QualifiedUserVisibleName()).ToCString(); | 5712 String::Handle(QualifiedUserVisibleName()).ToCString(); |
| 5713 Class& cls = Class::Handle(Owner()); | 5713 Class& cls = Class::Handle(Owner()); |
| 5714 ASSERT(!cls.IsNull()); | |
| 5714 Error& err = Error::Handle(); | 5715 Error& err = Error::Handle(); |
| 5715 err ^= cls.EnsureIsFinalized(Isolate::Current()); | 5716 err ^= cls.EnsureIsFinalized(Isolate::Current()); |
| 5716 ASSERT(err.IsNull()); | 5717 ASSERT(err.IsNull()); |
| 5717 const Function& func = *this; | 5718 const Function& func = *this; |
| 5718 intptr_t id; | 5719 intptr_t id; |
| 5719 if (IsNonImplicitClosureFunction()) { | 5720 if (IsNonImplicitClosureFunction()) { |
| 5720 id = cls.FindClosureIndex(token_pos()); | 5721 id = cls.FindClosureIndex(token_pos()); |
| 5721 } else { | 5722 } else { |
| 5722 id = cls.FindFunctionIndex(func); | 5723 id = cls.FindFunctionIndex(func); |
| 5723 } | 5724 } |
| 5725 bool object_ref = id < 0; | |
|
Ivan Posva
2013/12/30 23:06:09
Please handle implicit closure functions as discus
| |
| 5726 if (object_ref) { | |
| 5727 // We do not have a stable way of referencing this function, | |
| 5728 // generate a temporary id. | |
| 5729 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | |
| 5730 id = ring->GetIdForObject(raw()); | |
| 5731 } | |
| 5724 ASSERT(id >= 0); | 5732 ASSERT(id >= 0); |
| 5725 intptr_t cid = cls.id(); | 5733 intptr_t cid = cls.id(); |
| 5726 JSONObject jsobj(stream); | 5734 JSONObject jsobj(stream); |
| 5727 jsobj.AddProperty("type", JSONType(ref)); | 5735 jsobj.AddProperty("type", JSONType(ref)); |
| 5728 if (IsNonImplicitClosureFunction()) { | 5736 if (object_ref) { |
| 5737 jsobj.AddPropertyF("id", "objects/%" Pd "", id); | |
| 5738 } else if (IsNonImplicitClosureFunction()) { | |
| 5729 jsobj.AddPropertyF("id", "classes/%" Pd "/closures/%" Pd "", cid, id); | 5739 jsobj.AddPropertyF("id", "classes/%" Pd "/closures/%" Pd "", cid, id); |
| 5730 } else { | 5740 } else { |
| 5731 jsobj.AddPropertyF("id", "classes/%" Pd "/functions/%" Pd "", cid, id); | 5741 jsobj.AddPropertyF("id", "classes/%" Pd "/functions/%" Pd "", cid, id); |
| 5732 } | 5742 } |
| 5733 jsobj.AddProperty("name", internal_function_name); | 5743 jsobj.AddProperty("name", internal_function_name); |
| 5734 jsobj.AddProperty("user_name", function_name); | 5744 jsobj.AddProperty("user_name", function_name); |
| 5735 if (ref) return; | 5745 if (ref) return; |
| 5736 jsobj.AddProperty("is_static", is_static()); | 5746 jsobj.AddProperty("is_static", is_static()); |
| 5737 jsobj.AddProperty("is_const", is_const()); | 5747 jsobj.AddProperty("is_const", is_const()); |
| 5738 jsobj.AddProperty("is_optimizable", is_optimizable()); | 5748 jsobj.AddProperty("is_optimizable", is_optimizable()); |
| (...skipping 3946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9685 ASSERT(i >= 0); | 9695 ASSERT(i >= 0); |
| 9686 const Array& array = | 9696 const Array& array = |
| 9687 Array::Handle(raw_ptr()->static_calls_target_table_); | 9697 Array::Handle(raw_ptr()->static_calls_target_table_); |
| 9688 ASSERT(code.IsNull() || | 9698 ASSERT(code.IsNull() || |
| 9689 (code.function() == array.At(i + kSCallTableFunctionEntry))); | 9699 (code.function() == array.At(i + kSCallTableFunctionEntry))); |
| 9690 array.SetAt(i + kSCallTableCodeEntry, code); | 9700 array.SetAt(i + kSCallTableCodeEntry, code); |
| 9691 } | 9701 } |
| 9692 | 9702 |
| 9693 | 9703 |
| 9694 void Code::Disassemble() const { | 9704 void Code::Disassemble() const { |
| 9705 const bool fix_patch = CodePatcher::CodeIsPatchable(*this) && | |
| 9706 CodePatcher::IsEntryPatched(*this); | |
| 9707 if (fix_patch) { | |
| 9708 // Undo the patch. | |
| 9709 CodePatcher::RestoreEntry(*this); | |
| 9710 } | |
|
srdjan
2013/12/30 17:54:46
Add comment that restore/repatch is necesseary to
Cutch
2013/12/30 21:32:40
Done.
| |
| 9695 const Instructions& instr = Instructions::Handle(instructions()); | 9711 const Instructions& instr = Instructions::Handle(instructions()); |
| 9696 uword start = instr.EntryPoint(); | 9712 uword start = instr.EntryPoint(); |
| 9697 Disassembler::Disassemble(start, start + instr.size(), comments()); | 9713 Disassembler::Disassemble(start, start + instr.size(), comments()); |
| 9714 if (fix_patch) { | |
| 9715 // Redo the patch. | |
| 9716 CodePatcher::PatchEntry(*this); | |
| 9717 } | |
| 9698 } | 9718 } |
| 9699 | 9719 |
| 9700 | 9720 |
| 9721 void Code::Disassemble(DisassemblyFormatter* formatter) const { | |
| 9722 const bool fix_patch = CodePatcher::CodeIsPatchable(*this) && | |
| 9723 CodePatcher::IsEntryPatched(*this); | |
| 9724 if (fix_patch) { | |
| 9725 // Undo the patch. | |
| 9726 CodePatcher::RestoreEntry(*this); | |
| 9727 } | |
| 9728 const Instructions& instr = Instructions::Handle(instructions()); | |
| 9729 uword start = instr.EntryPoint(); | |
| 9730 Disassembler::Disassemble(start, start + instr.size(), formatter, comments()); | |
| 9731 if (fix_patch) { | |
| 9732 // Redo the patch. | |
| 9733 CodePatcher::PatchEntry(*this); | |
| 9734 } | |
| 9735 } | |
| 9736 | |
| 9737 | |
| 9701 const Code::Comments& Code::comments() const { | 9738 const Code::Comments& Code::comments() const { |
| 9702 Comments* comments = new Code::Comments(Array::Handle(raw_ptr()->comments_)); | 9739 Comments* comments = new Code::Comments(Array::Handle(raw_ptr()->comments_)); |
| 9703 return *comments; | 9740 return *comments; |
| 9704 } | 9741 } |
| 9705 | 9742 |
| 9706 | 9743 |
| 9707 void Code::set_comments(const Code::Comments& comments) const { | 9744 void Code::set_comments(const Code::Comments& comments) const { |
| 9708 ASSERT(comments.comments_.IsOld()); | 9745 ASSERT(comments.comments_.IsOld()); |
| 9709 StorePointer(&raw_ptr()->comments_, comments.comments_.raw()); | 9746 StorePointer(&raw_ptr()->comments_, comments.comments_.raw()); |
| 9710 } | 9747 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9869 const char* Code::ToCString() const { | 9906 const char* Code::ToCString() const { |
| 9870 const char* kFormat = "Code entry:%p"; | 9907 const char* kFormat = "Code entry:%p"; |
| 9871 intptr_t len = OS::SNPrint(NULL, 0, kFormat, EntryPoint()) + 1; | 9908 intptr_t len = OS::SNPrint(NULL, 0, kFormat, EntryPoint()) + 1; |
| 9872 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 9909 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 9873 OS::SNPrint(chars, len, kFormat, EntryPoint()); | 9910 OS::SNPrint(chars, len, kFormat, EntryPoint()); |
| 9874 return chars; | 9911 return chars; |
| 9875 } | 9912 } |
| 9876 | 9913 |
| 9877 | 9914 |
| 9878 void Code::PrintToJSONStream(JSONStream* stream, bool ref) const { | 9915 void Code::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 9879 Isolate* isolate = Isolate::Current(); | |
| 9880 ObjectIdRing* ring = isolate->object_id_ring(); | |
| 9881 intptr_t id = ring->GetIdForObject(raw()); | |
| 9882 JSONObject jsobj(stream); | 9916 JSONObject jsobj(stream); |
| 9883 jsobj.AddProperty("type", JSONType(ref)); | 9917 jsobj.AddProperty("type", JSONType(ref)); |
| 9884 jsobj.AddPropertyF("id", "objects/%" Pd "", id); | 9918 jsobj.AddPropertyF("id", "code/%" Px "", EntryPoint()); |
| 9919 jsobj.AddPropertyF("start", "%" Px "", EntryPoint()); | |
| 9920 jsobj.AddPropertyF("end", "%" Px "", EntryPoint() + Size()); | |
| 9885 Function& func = Function::Handle(); | 9921 Function& func = Function::Handle(); |
| 9922 func ^= function(); | |
| 9923 ASSERT(!func.IsNull()); | |
| 9886 String& name = String::Handle(); | 9924 String& name = String::Handle(); |
| 9887 func ^= function(); | |
| 9888 ASSERT(!func.IsNull()); | 9925 ASSERT(!func.IsNull()); |
| 9889 name ^= func.name(); | 9926 name ^= func.name(); |
| 9890 const char* internal_function_name = name.ToCString(); | 9927 const char* internal_function_name = name.ToCString(); |
| 9891 jsobj.AddPropertyF("name", "%s%s", is_optimized() ? "*" : "", | 9928 jsobj.AddPropertyF("name", "%s%s", is_optimized() ? "*" : "", |
| 9892 internal_function_name); | 9929 internal_function_name); |
| 9893 name ^= func.QualifiedUserVisibleName(); | 9930 name ^= func.QualifiedUserVisibleName(); |
| 9894 const char* function_name = name.ToCString(); | 9931 const char* function_name = name.ToCString(); |
| 9895 jsobj.AddPropertyF("user_name", "%s%s", is_optimized() ? "*" : "", | 9932 jsobj.AddPropertyF("user_name", "%s%s", is_optimized() ? "*" : "", |
| 9896 function_name); | 9933 function_name); |
| 9897 if (ref) { | 9934 if (ref) { |
| 9898 return; | 9935 return; |
| 9899 } | 9936 } |
| 9900 jsobj.AddProperty("is_optimized", is_optimized()); | 9937 jsobj.AddProperty("is_optimized", is_optimized()); |
| 9901 jsobj.AddProperty("is_alive", is_alive()); | 9938 jsobj.AddProperty("is_alive", is_alive()); |
| 9902 jsobj.AddProperty("function", Object::Handle(function())); | 9939 jsobj.AddProperty("function", Object::Handle(function())); |
| 9903 JSONArray jsarr(&jsobj, "disassembly"); | 9940 JSONArray jsarr(&jsobj, "disassembly"); |
| 9904 DisassembleToJSONStream formatter(jsarr); | 9941 DisassembleToJSONStream formatter(jsarr); |
| 9905 const Instructions& instr = Instructions::Handle(instructions()); | 9942 Disassemble(&formatter); |
| 9906 uword start = instr.EntryPoint(); | |
| 9907 Disassembler::Disassemble(start, start + instr.size(), &formatter, | |
| 9908 comments()); | |
| 9909 } | 9943 } |
| 9910 | 9944 |
| 9911 | 9945 |
| 9912 uword Code::GetPatchCodePc() const { | 9946 uword Code::GetPatchCodePc() const { |
| 9913 const PcDescriptors& descriptors = PcDescriptors::Handle(pc_descriptors()); | 9947 const PcDescriptors& descriptors = PcDescriptors::Handle(pc_descriptors()); |
| 9914 return descriptors.GetPcForKind(PcDescriptors::kPatchCode); | 9948 return descriptors.GetPcForKind(PcDescriptors::kPatchCode); |
| 9915 } | 9949 } |
| 9916 | 9950 |
| 9917 | 9951 |
| 9918 uword Code::GetLazyDeoptPc() const { | 9952 uword Code::GetLazyDeoptPc() const { |
| (...skipping 6863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 16782 return "_MirrorReference"; | 16816 return "_MirrorReference"; |
| 16783 } | 16817 } |
| 16784 | 16818 |
| 16785 | 16819 |
| 16786 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 16820 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 16787 Instance::PrintToJSONStream(stream, ref); | 16821 Instance::PrintToJSONStream(stream, ref); |
| 16788 } | 16822 } |
| 16789 | 16823 |
| 16790 | 16824 |
| 16791 } // namespace dart | 16825 } // namespace dart |
| OLD | NEW |