| 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" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| 64 | 64 |
| 65 void ExitFrame::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 65 void ExitFrame::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
| 66 // There are no objects to visit in this frame. | 66 // There are no objects to visit in this frame. |
| 67 } | 67 } |
| 68 | 68 |
| 69 | 69 |
| 70 void EntryFrame::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 70 void EntryFrame::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
| 71 #if !defined(TARGET_ARCH_DBC) |
| 71 ASSERT(thread() == Thread::Current()); | 72 ASSERT(thread() == Thread::Current()); |
| 72 // Visit objects between SP and (FP - callee_save_area). | 73 // Visit objects between SP and (FP - callee_save_area). |
| 73 ASSERT(visitor != NULL); | 74 ASSERT(visitor != NULL); |
| 74 RawObject** first = reinterpret_cast<RawObject**>(sp()); | 75 RawObject** first = reinterpret_cast<RawObject**>(sp()); |
| 75 RawObject** last = reinterpret_cast<RawObject**>( | 76 RawObject** last = reinterpret_cast<RawObject**>( |
| 76 fp() + (kExitLinkSlotFromEntryFp - 1) * kWordSize); | 77 fp() + (kExitLinkSlotFromEntryFp - 1) * kWordSize); |
| 77 visitor->VisitPointers(first, last); | 78 visitor->VisitPointers(first, last); |
| 79 #else |
| 80 // On DBC stack is growing upwards which implies fp() <= sp(). |
| 81 RawObject** first = reinterpret_cast<RawObject**>(fp()); |
| 82 RawObject** last = reinterpret_cast<RawObject**>(sp()); |
| 83 visitor->VisitPointers(first, last); |
| 84 #endif |
| 78 } | 85 } |
| 79 | 86 |
| 80 | 87 |
| 81 void StackFrame::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 88 void StackFrame::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
| 89 #if !defined(TARGET_ARCH_DBC) |
| 82 // NOTE: This code runs while GC is in progress and runs within | 90 // NOTE: This code runs while GC is in progress and runs within |
| 83 // a NoHandleScope block. Hence it is not ok to use regular Zone or | 91 // a NoHandleScope block. Hence it is not ok to use regular Zone or |
| 84 // Scope handles. We use direct stack handles, the raw pointers in | 92 // Scope handles. We use direct stack handles, the raw pointers in |
| 85 // these handles are not traversed. The use of handles is mainly to | 93 // these handles are not traversed. The use of handles is mainly to |
| 86 // be able to reuse the handle based code and avoid having to add | 94 // be able to reuse the handle based code and avoid having to add |
| 87 // helper functions to the raw object interface. | 95 // helper functions to the raw object interface. |
| 88 ASSERT(thread() == Thread::Current()); | 96 ASSERT(thread() == Thread::Current()); |
| 89 ASSERT(visitor != NULL); | 97 ASSERT(visitor != NULL); |
| 90 NoSafepointScope no_safepoint; | 98 NoSafepointScope no_safepoint; |
| 91 Code code; | 99 Code code; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 visitor->VisitPointers(first, last); | 158 visitor->VisitPointers(first, last); |
| 151 return; | 159 return; |
| 152 } | 160 } |
| 153 } | 161 } |
| 154 // For normal unoptimized Dart frames and Stub frames each slot | 162 // For normal unoptimized Dart frames and Stub frames each slot |
| 155 // between the first and last included are tagged objects. | 163 // between the first and last included are tagged objects. |
| 156 RawObject** first = reinterpret_cast<RawObject**>(sp()); | 164 RawObject** first = reinterpret_cast<RawObject**>(sp()); |
| 157 RawObject** last = reinterpret_cast<RawObject**>( | 165 RawObject** last = reinterpret_cast<RawObject**>( |
| 158 fp() + (kFirstObjectSlotFromFp * kWordSize)); | 166 fp() + (kFirstObjectSlotFromFp * kWordSize)); |
| 159 visitor->VisitPointers(first, last); | 167 visitor->VisitPointers(first, last); |
| 168 #else |
| 169 // On DBC stack grows upwards: fp() <= sp(). |
| 170 RawObject** first = reinterpret_cast<RawObject**>( |
| 171 fp() + (kFirstObjectSlotFromFp * kWordSize)); |
| 172 RawObject** last = reinterpret_cast<RawObject**>(sp()); |
| 173 visitor->VisitPointers(first, last); |
| 174 #endif // !defined(TARGET_ARCH_DBC) |
| 160 } | 175 } |
| 161 | 176 |
| 162 | 177 |
| 163 RawFunction* StackFrame::LookupDartFunction() const { | 178 RawFunction* StackFrame::LookupDartFunction() const { |
| 164 const Code& code = Code::Handle(LookupDartCode()); | 179 const Code& code = Code::Handle(LookupDartCode()); |
| 165 if (!code.IsNull()) { | 180 if (!code.IsNull()) { |
| 166 return code.function(); | 181 return code.function(); |
| 167 } | 182 } |
| 168 return Function::null(); | 183 return Function::null(); |
| 169 } | 184 } |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 current_frame_(NULL), | 325 current_frame_(NULL), |
| 311 thread_(thread) { | 326 thread_(thread) { |
| 312 ASSERT((thread_ == Thread::Current()) || | 327 ASSERT((thread_ == Thread::Current()) || |
| 313 OS::AllowStackFrameIteratorFromAnotherThread()); | 328 OS::AllowStackFrameIteratorFromAnotherThread()); |
| 314 frames_.fp_ = last_fp; | 329 frames_.fp_ = last_fp; |
| 315 frames_.sp_ = 0; | 330 frames_.sp_ = 0; |
| 316 frames_.pc_ = 0; | 331 frames_.pc_ = 0; |
| 317 } | 332 } |
| 318 | 333 |
| 319 | 334 |
| 335 #if !defined(TARGET_ARCH_DBC) |
| 320 StackFrameIterator::StackFrameIterator(uword fp, uword sp, uword pc, | 336 StackFrameIterator::StackFrameIterator(uword fp, uword sp, uword pc, |
| 321 bool validate, Thread* thread) | 337 bool validate, Thread* thread) |
| 322 : validate_(validate), | 338 : validate_(validate), |
| 323 entry_(thread), | 339 entry_(thread), |
| 324 exit_(thread), | 340 exit_(thread), |
| 325 frames_(thread), | 341 frames_(thread), |
| 326 current_frame_(NULL), | 342 current_frame_(NULL), |
| 327 thread_(thread) { | 343 thread_(thread) { |
| 328 ASSERT((thread_ == Thread::Current()) || | 344 ASSERT((thread_ == Thread::Current()) || |
| 329 OS::AllowStackFrameIteratorFromAnotherThread()); | 345 OS::AllowStackFrameIteratorFromAnotherThread()); |
| 330 frames_.fp_ = fp; | 346 frames_.fp_ = fp; |
| 331 frames_.sp_ = sp; | 347 frames_.sp_ = sp; |
| 332 frames_.pc_ = pc; | 348 frames_.pc_ = pc; |
| 333 } | 349 } |
| 350 #endif |
| 334 | 351 |
| 335 | 352 |
| 336 StackFrame* StackFrameIterator::NextFrame() { | 353 StackFrame* StackFrameIterator::NextFrame() { |
| 337 // When we are at the start of iteration after having created an | 354 // When we are at the start of iteration after having created an |
| 338 // iterator object, current_frame_ will be NULL as we haven't seen | 355 // iterator object, current_frame_ will be NULL as we haven't seen |
| 339 // any frames yet (unless we start iterating in the simulator from a given | 356 // any frames yet (unless we start iterating in the simulator from a given |
| 340 // triplet of fp, sp, and pc). At this point, if NextFrame is called, it tries | 357 // triplet of fp, sp, and pc). At this point, if NextFrame is called, it tries |
| 341 // to set up the next exit frame by reading the top_exit_frame_info | 358 // to set up the next exit frame by reading the top_exit_frame_info |
| 342 // from the isolate. If we do not have any dart invocations yet, | 359 // from the isolate. If we do not have any dart invocations yet, |
| 343 // top_exit_frame_info will be 0 and so we would return NULL. | 360 // top_exit_frame_info will be 0 and so we would return NULL. |
| 344 | 361 |
| 345 // current_frame_ will also be NULL, when we are at the end of having | 362 // current_frame_ will also be NULL, when we are at the end of having |
| 346 // iterated through all the frames. If NextFrame is called at this | 363 // iterated through all the frames. If NextFrame is called at this |
| 347 // point, we will try and set up the next exit frame, but since we are | 364 // point, we will try and set up the next exit frame, but since we are |
| 348 // at the end of the iteration, fp_ will be 0 and we would return NULL. | 365 // at the end of the iteration, fp_ will be 0 and we would return NULL. |
| 349 if (current_frame_ == NULL) { | 366 if (current_frame_ == NULL) { |
| 350 if (!HasNextFrame()) { | 367 if (!HasNextFrame()) { |
| 351 return NULL; | 368 return NULL; |
| 352 } | 369 } |
| 353 UnpoisonStack(frames_.fp_); | 370 UnpoisonStack(frames_.fp_); |
| 371 #if !defined(TARGET_ARCH_DBC) |
| 354 if (frames_.pc_ == 0) { | 372 if (frames_.pc_ == 0) { |
| 355 // Iteration starts from an exit frame given by its fp. | 373 // Iteration starts from an exit frame given by its fp. |
| 356 current_frame_ = NextExitFrame(); | 374 current_frame_ = NextExitFrame(); |
| 357 } else if (*(reinterpret_cast<uword*>( | 375 } else if (*(reinterpret_cast<uword*>( |
| 358 frames_.fp_ + (kSavedCallerFpSlotFromFp * kWordSize))) == 0) { | 376 frames_.fp_ + (kSavedCallerFpSlotFromFp * kWordSize))) == 0) { |
| 359 // Iteration starts from an entry frame given by its fp, sp, and pc. | 377 // Iteration starts from an entry frame given by its fp, sp, and pc. |
| 360 current_frame_ = NextEntryFrame(); | 378 current_frame_ = NextEntryFrame(); |
| 361 } else { | 379 } else { |
| 362 // Iteration starts from a Dart or stub frame given by its fp, sp, and pc. | 380 // Iteration starts from a Dart or stub frame given by its fp, sp, and pc. |
| 363 current_frame_ = frames_.NextFrame(validate_); | 381 current_frame_ = frames_.NextFrame(validate_); |
| 364 } | 382 } |
| 383 #else |
| 384 // Iteration starts from an exit frame given by its fp. This is the only |
| 385 // mode supported on DBC. |
| 386 ASSERT(frames_.pc_ == 0); |
| 387 current_frame_ = NextExitFrame(); |
| 388 #endif // !defined(TARGET_ARCH_DBC) |
| 365 return current_frame_; | 389 return current_frame_; |
| 366 } | 390 } |
| 367 ASSERT((validate_ == kDontValidateFrames) || current_frame_->IsValid()); | 391 ASSERT((validate_ == kDontValidateFrames) || current_frame_->IsValid()); |
| 368 if (current_frame_->IsEntryFrame()) { | 392 if (current_frame_->IsEntryFrame()) { |
| 369 if (HasNextFrame()) { // We have another chained block. | 393 if (HasNextFrame()) { // We have another chained block. |
| 370 current_frame_ = NextExitFrame(); | 394 current_frame_ = NextExitFrame(); |
| 371 return current_frame_; | 395 return current_frame_; |
| 372 } | 396 } |
| 373 current_frame_ = NULL; // No more frames. | 397 current_frame_ = NULL; // No more frames. |
| 374 return current_frame_; | 398 return current_frame_; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 if (deopt_instr->kind() == DeoptInstr::kCallerFp) { | 514 if (deopt_instr->kind() == DeoptInstr::kCallerFp) { |
| 491 return (index - num_materializations_); | 515 return (index - num_materializations_); |
| 492 } | 516 } |
| 493 } | 517 } |
| 494 UNREACHABLE(); | 518 UNREACHABLE(); |
| 495 return 0; | 519 return 0; |
| 496 } | 520 } |
| 497 | 521 |
| 498 | 522 |
| 499 } // namespace dart | 523 } // namespace dart |
| OLD | NEW |