| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/stack_frame.h" | 5 #include "vm/stack_frame.h" |
| 6 | 6 |
| 7 #include "vm/assembler_macros.h" |
| 7 #include "vm/isolate.h" | 8 #include "vm/isolate.h" |
| 8 #include "vm/object.h" | 9 #include "vm/object.h" |
| 9 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
| 10 #include "vm/os.h" | 11 #include "vm/os.h" |
| 12 #include "vm/parser.h" |
| 11 #include "vm/raw_object.h" | 13 #include "vm/raw_object.h" |
| 12 #include "vm/stub_code.h" | 14 #include "vm/stub_code.h" |
| 13 #include "vm/visitor.h" | 15 #include "vm/visitor.h" |
| 14 | 16 |
| 15 namespace dart { | 17 namespace dart { |
| 16 | 18 |
| 17 bool StackFrame::FindRawCodeVisitor::FindObject(RawObject* obj) { | 19 |
| 18 return RawInstructions::ContainsPC(obj, pc_); | 20 bool StackFrame::IsStubFrame() const { |
| 21 ASSERT(!(IsEntryFrame() || IsExitFrame())); |
| 22 uword saved_pc = *(reinterpret_cast<uword*>(fp() - kWordSize)); |
| 23 return (saved_pc == 0); |
| 19 } | 24 } |
| 20 | 25 |
| 21 | 26 |
| 22 bool StackFrame::IsStubFrame() const { | |
| 23 if (Dart::vm_isolate()->heap()->StubCodeContains(pc())) { | |
| 24 return true; // Common stub code is generated in the VM heap. | |
| 25 } | |
| 26 if (Isolate::Current()->heap()->StubCodeContains(pc())) { | |
| 27 return true; // Common stub code is generated in the VM heap. | |
| 28 } | |
| 29 return false; | |
| 30 } | |
| 31 | |
| 32 | |
| 33 void StackFrame::Print() const { | 27 void StackFrame::Print() const { |
| 34 OS::Print("[%-8s : sp(%p) ]\n", GetName(), sp()); | 28 OS::Print("[%-8s : sp(%p) ]\n", GetName(), sp()); |
| 35 } | 29 } |
| 36 | 30 |
| 37 | 31 |
| 38 RawCode* StackFrame::LookupCode(Isolate* isolate, uword pc) { | |
| 39 // TODO(asiva): Need to add a data structure for storing a (pc, code | |
| 40 // object) map in order to do a quick lookup and avoid having to | |
| 41 // traverse the code heap. | |
| 42 ASSERT(isolate != NULL); | |
| 43 // We add a no gc scope to ensure that the code below does not trigger | |
| 44 // a GC as we are handling raw object references here. It is possible | |
| 45 // that the code is called while a GC is in progress, that is ok. | |
| 46 NoGCScope no_gc; | |
| 47 FindRawCodeVisitor visitor(pc); | |
| 48 RawInstructions* instr = isolate->heap()->FindObjectInCodeSpace(&visitor); | |
| 49 if (instr != Instructions::null()) { | |
| 50 return instr->ptr()->code_; | |
| 51 } | |
| 52 return Code::null(); | |
| 53 } | |
| 54 | |
| 55 | |
| 56 void ExitFrame::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 32 void ExitFrame::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
| 57 // There are no objects to visit in this frame. | 33 // There are no objects to visit in this frame. |
| 58 } | 34 } |
| 59 | 35 |
| 60 | 36 |
| 61 void EntryFrame::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 37 void EntryFrame::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
| 62 // Visit objects between SP and (FP - callee_save_area). | 38 // Visit objects between SP and (FP - callee_save_area). |
| 63 ASSERT(visitor != NULL); | 39 ASSERT(visitor != NULL); |
| 64 RawObject** start = reinterpret_cast<RawObject**>(sp()); | 40 RawObject** start = reinterpret_cast<RawObject**>(sp()); |
| 65 RawObject** end = reinterpret_cast<RawObject**>( | 41 RawObject** end = reinterpret_cast<RawObject**>( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 96 } | 72 } |
| 97 bit_offset += 1; | 73 bit_offset += 1; |
| 98 } | 74 } |
| 99 return; | 75 return; |
| 100 } | 76 } |
| 101 } | 77 } |
| 102 // No stack maps are present in the code object which means this | 78 // No stack maps are present in the code object which means this |
| 103 // frame relies on tagged pointers and hence we visit each entry | 79 // frame relies on tagged pointers and hence we visit each entry |
| 104 // on the frame between SP and FP. | 80 // on the frame between SP and FP. |
| 105 ASSERT(visitor != NULL); | 81 ASSERT(visitor != NULL); |
| 106 visitor->VisitPointers(reinterpret_cast<RawObject**>(sp()), | 82 RawObject** start = reinterpret_cast<RawObject**>(sp()); |
| 107 reinterpret_cast<RawObject**>(fp() - kWordSize)); | 83 RawObject** end = reinterpret_cast<RawObject**>( |
| 84 fp() + (ParsedFunction::kFirstLocalSlotIndex * kWordSize)); |
| 85 visitor->VisitPointers(start, end); |
| 108 } | 86 } |
| 109 | 87 |
| 110 | 88 |
| 111 RawFunction* StackFrame::LookupDartFunction() const { | 89 RawFunction* StackFrame::LookupDartFunction() const { |
| 112 const Code& code = Code::Handle(LookupDartCode()); | 90 const Code& code = Code::Handle(LookupDartCode()); |
| 113 if (!code.IsNull()) { | 91 if (!code.IsNull()) { |
| 114 return code.function(); | 92 return code.function(); |
| 115 } | 93 } |
| 116 return Function::null(); | 94 return Function::null(); |
| 117 } | 95 } |
| 118 | 96 |
| 119 | 97 |
| 120 RawCode* StackFrame::LookupDartCode() const { | 98 RawCode* StackFrame::LookupDartCode() const { |
| 121 // We add a no gc scope to ensure that the code below does not trigger | 99 // We add a no gc scope to ensure that the code below does not trigger |
| 122 // a GC as we are handling raw object references here. It is possible | 100 // a GC as we are handling raw object references here. It is possible |
| 123 // that the code is called while a GC is in progress, that is ok. | 101 // that the code is called while a GC is in progress, that is ok. |
| 124 NoGCScope no_gc; | 102 NoGCScope no_gc; |
| 125 Isolate* isolate = Isolate::Current(); | 103 RawCode* code = GetCodeObject(); |
| 126 RawCode* code = StackFrame::LookupCode(isolate, pc()); | 104 ASSERT(code == Code::null() || code->ptr()->function_ != Function::null()); |
| 127 if ((code != Code::null()) && (code->ptr()->function_ != Function::null())) { | 105 return code; |
| 128 return code; | 106 } |
| 107 |
| 108 |
| 109 RawCode* StackFrame::GetCodeObject() const { |
| 110 // We add a no gc scope to ensure that the code below does not trigger |
| 111 // a GC as we are handling raw object references here. It is possible |
| 112 // that the code is called while a GC is in progress, that is ok. |
| 113 NoGCScope no_gc; |
| 114 uword saved_pc = *(reinterpret_cast<uword*>(fp() - kWordSize)); |
| 115 if (saved_pc != 0) { |
| 116 uword entry_point = |
| 117 (saved_pc - AssemblerMacros::kOffsetOfSavedPCfromEntrypoint); |
| 118 RawInstructions* instr = Instructions::FromEntryPoint(entry_point); |
| 119 if (instr != Instructions::null()) { |
| 120 return instr->ptr()->code_; |
| 121 } |
| 129 } | 122 } |
| 130 return Code::null(); | 123 return Code::null(); |
| 131 } | 124 } |
| 132 | 125 |
| 133 | 126 |
| 134 bool StackFrame::FindExceptionHandler(uword* handler_pc) const { | 127 bool StackFrame::FindExceptionHandler(uword* handler_pc) const { |
| 135 const Code& code = Code::Handle(LookupDartCode()); | 128 const Code& code = Code::Handle(LookupDartCode()); |
| 136 if (code.IsNull()) { | 129 if (code.IsNull()) { |
| 137 return false; // Stub frames do not have exception handlers. | 130 return false; // Stub frames do not have exception handlers. |
| 138 } | 131 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 161 } | 154 } |
| 162 } | 155 } |
| 163 return false; | 156 return false; |
| 164 } | 157 } |
| 165 | 158 |
| 166 | 159 |
| 167 bool StackFrame::IsValid() const { | 160 bool StackFrame::IsValid() const { |
| 168 if (IsEntryFrame() || IsExitFrame() || IsStubFrame()) { | 161 if (IsEntryFrame() || IsExitFrame() || IsStubFrame()) { |
| 169 return true; | 162 return true; |
| 170 } | 163 } |
| 171 return (StackFrame::LookupCode(Isolate::Current(), pc()) != Code::null()); | 164 return (LookupDartCode() != Code::null()); |
| 172 } | 165 } |
| 173 | 166 |
| 174 | 167 |
| 175 StackFrameIterator::StackFrameIterator(bool validate) | 168 StackFrameIterator::StackFrameIterator(bool validate) |
| 176 : validate_(validate), entry_(), exit_(), current_frame_(NULL) { | 169 : validate_(validate), entry_(), exit_(), current_frame_(NULL) { |
| 177 SetupLastExitFrameData(); // Setup data for last exit frame. | 170 SetupLastExitFrameData(); // Setup data for last exit frame. |
| 178 } | 171 } |
| 179 | 172 |
| 180 | 173 |
| 181 StackFrame* StackFrameIterator::NextFrame() { | 174 StackFrame* StackFrameIterator::NextFrame() { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 EntryFrame* StackFrameIterator::NextEntryFrame() { | 238 EntryFrame* StackFrameIterator::NextEntryFrame() { |
| 246 ASSERT(!frames_.HasNext()); | 239 ASSERT(!frames_.HasNext()); |
| 247 entry_.sp_ = frames_.sp_; | 240 entry_.sp_ = frames_.sp_; |
| 248 entry_.fp_ = frames_.fp_; | 241 entry_.fp_ = frames_.fp_; |
| 249 SetupNextExitFrameData(); // Setup data for next exit frame in chain. | 242 SetupNextExitFrameData(); // Setup data for next exit frame in chain. |
| 250 ASSERT(entry_.IsValid()); | 243 ASSERT(entry_.IsValid()); |
| 251 return &entry_; | 244 return &entry_; |
| 252 } | 245 } |
| 253 | 246 |
| 254 } // namespace dart | 247 } // namespace dart |
| OLD | NEW |