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