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/stack_frame.h" | 5 #include "vm/stack_frame.h" |
6 | 6 |
7 #include "platform/memory_sanitizer.h" | 7 #include "platform/memory_sanitizer.h" |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 #include "vm/deopt_instructions.h" | 9 #include "vm/deopt_instructions.h" |
10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
11 #include "vm/object.h" | 11 #include "vm/object.h" |
12 #include "vm/object_store.h" | 12 #include "vm/object_store.h" |
13 #include "vm/os.h" | 13 #include "vm/os.h" |
14 #include "vm/parser.h" | 14 #include "vm/parser.h" |
15 #include "vm/raw_object.h" | 15 #include "vm/raw_object.h" |
16 #include "vm/reusable_handles.h" | 16 #include "vm/reusable_handles.h" |
17 #include "vm/stub_code.h" | 17 #include "vm/stub_code.h" |
18 #include "vm/visitor.h" | 18 #include "vm/visitor.h" |
19 | 19 |
20 namespace dart { | 20 namespace dart { |
21 | 21 |
22 | 22 |
23 bool StackFrame::IsStubFrame() const { | 23 bool StackFrame::IsStubFrame() const { |
24 ASSERT(!(IsEntryFrame() || IsExitFrame())); | 24 ASSERT(!(IsEntryFrame() || IsExitFrame())); |
25 uword saved_pc = | 25 #if !defined(TARGET_OS_WINDOWS) |
26 *(reinterpret_cast<uword*>(fp() + (kPcMarkerSlotFromFp * kWordSize))); | 26 // On Windows, the profiler calls this from a separate thread where |
27 return (saved_pc == 0); | 27 // Thread::Current() is NULL, so we cannot create a NoSafepointScope. |
| 28 NoSafepointScope no_safepoint; |
| 29 #endif |
| 30 RawCode* code = GetCodeObject(); |
| 31 intptr_t cid = code->ptr()->owner_->GetClassId(); |
| 32 ASSERT(cid == kNullCid || cid == kClassCid || cid == kFunctionCid); |
| 33 return cid == kNullCid || cid == kClassCid; |
28 } | 34 } |
29 | 35 |
30 | 36 |
31 const char* StackFrame::ToCString() const { | 37 const char* StackFrame::ToCString() const { |
32 ASSERT(isolate_ == Isolate::Current()); | 38 ASSERT(isolate_ == Isolate::Current()); |
33 Zone* zone = Thread::Current()->zone(); | 39 Zone* zone = Thread::Current()->zone(); |
34 if (IsDartFrame()) { | 40 if (IsDartFrame()) { |
35 const Code& code = Code::Handle(LookupDartCode()); | 41 const Code& code = Code::Handle(LookupDartCode()); |
36 ASSERT(!code.IsNull()); | 42 ASSERT(!code.IsNull()); |
37 const Object& owner = Object::Handle(code.owner()); | 43 const Object& owner = Object::Handle(code.owner()); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 } | 172 } |
167 return Function::null(); | 173 return Function::null(); |
168 } | 174 } |
169 | 175 |
170 | 176 |
171 RawCode* StackFrame::LookupDartCode() const { | 177 RawCode* StackFrame::LookupDartCode() const { |
172 ASSERT(isolate_ == Isolate::Current()); | 178 ASSERT(isolate_ == Isolate::Current()); |
173 // We add a no gc scope to ensure that the code below does not trigger | 179 // We add a no gc scope to ensure that the code below does not trigger |
174 // a GC as we are handling raw object references here. It is possible | 180 // a GC as we are handling raw object references here. It is possible |
175 // that the code is called while a GC is in progress, that is ok. | 181 // that the code is called while a GC is in progress, that is ok. |
| 182 #if !defined(TARGET_OS_WINDOWS) |
| 183 // On Windows, the profiler calls this from a separate thread where |
| 184 // Thread::Current() is NULL, so we cannot create a NoSafepointScope. |
176 NoSafepointScope no_safepoint; | 185 NoSafepointScope no_safepoint; |
| 186 #endif |
177 RawCode* code = GetCodeObject(); | 187 RawCode* code = GetCodeObject(); |
178 ASSERT(code == Code::null() || code->ptr()->owner_ != Function::null()); | 188 if ((code != Code::null()) && |
179 return code; | 189 (code->ptr()->owner_->GetClassId() == kFunctionCid)) { |
180 } | 190 return code; |
181 | |
182 | |
183 RawCode* StackFrame::GetCodeObject() const { | |
184 // We add a no gc scope to ensure that the code below does not trigger | |
185 // a GC as we are handling raw object references here. It is possible | |
186 // that the code is called while a GC is in progress, that is ok. | |
187 NoSafepointScope no_safepoint; | |
188 const uword pc_marker = | |
189 *(reinterpret_cast<uword*>(fp() + (kPcMarkerSlotFromFp * kWordSize))); | |
190 if (pc_marker != 0) { | |
191 const uword entry_point = | |
192 (pc_marker - Assembler::EntryPointToPcMarkerOffset()); | |
193 RawInstructions* instr = Instructions::FromEntryPoint(entry_point); | |
194 if (instr != Instructions::null()) { | |
195 return instr->ptr()->code_; | |
196 } | |
197 } | 191 } |
198 return Code::null(); | 192 return Code::null(); |
199 } | 193 } |
200 | 194 |
201 | 195 |
| 196 RawCode* StackFrame::GetCodeObject() const { |
| 197 const uword pc_marker = |
| 198 *(reinterpret_cast<uword*>(fp() + (kPcMarkerSlotFromFp * kWordSize))); |
| 199 ASSERT(pc_marker != 0); |
| 200 ASSERT(reinterpret_cast<RawObject*>(pc_marker)->GetClassId() == kCodeCid || |
| 201 reinterpret_cast<RawObject*>(pc_marker) == Object::null()); |
| 202 return reinterpret_cast<RawCode*>(pc_marker); |
| 203 } |
| 204 |
| 205 |
202 bool StackFrame::FindExceptionHandler(Isolate* isolate, | 206 bool StackFrame::FindExceptionHandler(Isolate* isolate, |
203 uword* handler_pc, | 207 uword* handler_pc, |
204 bool* needs_stacktrace, | 208 bool* needs_stacktrace, |
205 bool* has_catch_all) const { | 209 bool* has_catch_all) const { |
206 REUSABLE_CODE_HANDLESCOPE(isolate); | 210 REUSABLE_CODE_HANDLESCOPE(isolate); |
207 Code& code = reused_code_handle.Handle(); | 211 Code& code = reused_code_handle.Handle(); |
208 code = LookupDartCode(); | 212 code = LookupDartCode(); |
209 if (code.IsNull()) { | 213 if (code.IsNull()) { |
210 return false; // Stub frames do not have exception handlers. | 214 return false; // Stub frames do not have exception handlers. |
211 } | 215 } |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 if (deopt_instr->kind() == DeoptInstr::kCallerFp) { | 496 if (deopt_instr->kind() == DeoptInstr::kCallerFp) { |
493 return (index - num_materializations_); | 497 return (index - num_materializations_); |
494 } | 498 } |
495 } | 499 } |
496 UNREACHABLE(); | 500 UNREACHABLE(); |
497 return 0; | 501 return 0; |
498 } | 502 } |
499 | 503 |
500 | 504 |
501 } // namespace dart | 505 } // namespace dart |
OLD | NEW |