OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 while (sampler_->IsActive()) { | 508 while (sampler_->IsActive()) { |
509 TickSample sample; | 509 TickSample sample; |
510 | 510 |
511 // If profiling, we record the pc and sp of the profiled thread. | 511 // If profiling, we record the pc and sp of the profiled thread. |
512 if (sampler_->IsProfiling() | 512 if (sampler_->IsProfiling() |
513 && KERN_SUCCESS == thread_suspend(profiled_thread_)) { | 513 && KERN_SUCCESS == thread_suspend(profiled_thread_)) { |
514 #if V8_HOST_ARCH_X64 | 514 #if V8_HOST_ARCH_X64 |
515 thread_state_flavor_t flavor = x86_THREAD_STATE64; | 515 thread_state_flavor_t flavor = x86_THREAD_STATE64; |
516 x86_thread_state64_t state; | 516 x86_thread_state64_t state; |
517 mach_msg_type_number_t count = x86_THREAD_STATE64_COUNT; | 517 mach_msg_type_number_t count = x86_THREAD_STATE64_COUNT; |
| 518 #if __DARWIN_UNIX03 |
| 519 #define REGISTER_FIELD(name) __r ## name |
| 520 #else |
| 521 #define REGISTER_FIELD(name) r ## name |
| 522 #endif // __DARWIN_UNIX03 |
518 #elif V8_HOST_ARCH_IA32 | 523 #elif V8_HOST_ARCH_IA32 |
519 thread_state_flavor_t flavor = i386_THREAD_STATE; | 524 thread_state_flavor_t flavor = i386_THREAD_STATE; |
520 i386_thread_state_t state; | 525 i386_thread_state_t state; |
521 mach_msg_type_number_t count = i386_THREAD_STATE_COUNT; | 526 mach_msg_type_number_t count = i386_THREAD_STATE_COUNT; |
| 527 #if __DARWIN_UNIX03 |
| 528 #define REGISTER_FIELD(name) __e ## name |
| 529 #else |
| 530 #define REGISTER_FIELD(name) e ## name |
| 531 #endif // __DARWIN_UNIX03 |
522 #else | 532 #else |
523 #error Unsupported Mac OS X host architecture. | 533 #error Unsupported Mac OS X host architecture. |
524 #endif // V8_TARGET_ARCH_IA32 | 534 #endif // V8_HOST_ARCH |
| 535 |
525 if (thread_get_state(profiled_thread_, | 536 if (thread_get_state(profiled_thread_, |
526 flavor, | 537 flavor, |
527 reinterpret_cast<natural_t*>(&state), | 538 reinterpret_cast<natural_t*>(&state), |
528 &count) == KERN_SUCCESS) { | 539 &count) == KERN_SUCCESS) { |
529 #if V8_HOST_ARCH_X64 | 540 sample.pc = state.REGISTER_FIELD(ip); |
530 UNIMPLEMENTED(); | 541 sample.sp = state.REGISTER_FIELD(sp); |
531 sample.pc = 0; | 542 sample.fp = state.REGISTER_FIELD(bp); |
532 sample.sp = 0; | |
533 sample.fp = 0; | |
534 #elif V8_HOST_ARCH_IA32 | |
535 #if __DARWIN_UNIX03 | |
536 sample.pc = state.__eip; | |
537 sample.sp = state.__esp; | |
538 sample.fp = state.__ebp; | |
539 #else // !__DARWIN_UNIX03 | |
540 sample.pc = state.eip; | |
541 sample.sp = state.esp; | |
542 sample.fp = state.ebp; | |
543 #endif // __DARWIN_UNIX03 | |
544 #else | |
545 #error Unsupported Mac OS X host architecture. | |
546 #endif // V8_HOST_ARCH_IA32 | |
547 sampler_->SampleStack(&sample); | 543 sampler_->SampleStack(&sample); |
548 } | 544 } |
549 thread_resume(profiled_thread_); | 545 thread_resume(profiled_thread_); |
550 } | 546 } |
551 | 547 |
552 // We always sample the VM state. | 548 // We always sample the VM state. |
553 sample.state = Logger::state(); | 549 sample.state = Logger::state(); |
554 // Invoke tick handler with program counter and stack pointer. | 550 // Invoke tick handler with program counter and stack pointer. |
555 sampler_->Tick(&sample); | 551 sampler_->Tick(&sample); |
556 | 552 |
557 // Wait until next sampling. | 553 // Wait until next sampling. |
558 usleep(sampler_->interval_ * 1000); | 554 usleep(sampler_->interval_ * 1000); |
559 } | 555 } |
560 } | 556 } |
561 }; | 557 }; |
562 | 558 |
| 559 #undef REGISTER_FIELD |
| 560 |
563 | 561 |
564 // Entry point for sampler thread. | 562 // Entry point for sampler thread. |
565 static void* SamplerEntry(void* arg) { | 563 static void* SamplerEntry(void* arg) { |
566 Sampler::PlatformData* data = | 564 Sampler::PlatformData* data = |
567 reinterpret_cast<Sampler::PlatformData*>(arg); | 565 reinterpret_cast<Sampler::PlatformData*>(arg); |
568 data->Runner(); | 566 data->Runner(); |
569 return 0; | 567 return 0; |
570 } | 568 } |
571 | 569 |
572 | 570 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 | 612 |
615 // Deallocate Mach port for thread. | 613 // Deallocate Mach port for thread. |
616 if (IsProfiling()) { | 614 if (IsProfiling()) { |
617 mach_port_deallocate(data_->task_self_, data_->profiled_thread_); | 615 mach_port_deallocate(data_->task_self_, data_->profiled_thread_); |
618 } | 616 } |
619 } | 617 } |
620 | 618 |
621 #endif // ENABLE_LOGGING_AND_PROFILING | 619 #endif // ENABLE_LOGGING_AND_PROFILING |
622 | 620 |
623 } } // namespace v8::internal | 621 } } // namespace v8::internal |
OLD | NEW |