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