| OLD | NEW | 
|---|
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 27 matching lines...) Expand all  Loading... | 
| 38 #include <ucontext.h>  // walkstack(), getcontext() | 38 #include <ucontext.h>  // walkstack(), getcontext() | 
| 39 #include <dlfcn.h>     // dladdr | 39 #include <dlfcn.h>     // dladdr | 
| 40 #include <pthread.h> | 40 #include <pthread.h> | 
| 41 #include <sched.h>  // for sched_yield | 41 #include <sched.h>  // for sched_yield | 
| 42 #include <semaphore.h> | 42 #include <semaphore.h> | 
| 43 #include <time.h> | 43 #include <time.h> | 
| 44 #include <sys/time.h>  // gettimeofday(), timeradd() | 44 #include <sys/time.h>  // gettimeofday(), timeradd() | 
| 45 #include <errno.h> | 45 #include <errno.h> | 
| 46 #include <ieeefp.h>  // finite() | 46 #include <ieeefp.h>  // finite() | 
| 47 #include <signal.h>  // sigemptyset(), etc | 47 #include <signal.h>  // sigemptyset(), etc | 
|  | 48 #include <sys/kdi_regs.h> | 
| 48 | 49 | 
| 49 | 50 | 
| 50 #undef MAP_TYPE | 51 #undef MAP_TYPE | 
| 51 | 52 | 
| 52 #include "v8.h" | 53 #include "v8.h" | 
| 53 | 54 | 
| 54 #include "platform.h" | 55 #include "platform.h" | 
| 55 #include "vm-state-inl.h" | 56 #include "vm-state-inl.h" | 
| 56 | 57 | 
| 57 | 58 | 
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 474     pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); | 475     pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); | 
| 475     pthread_mutex_init(&mutex_, &attr); | 476     pthread_mutex_init(&mutex_, &attr); | 
| 476   } | 477   } | 
| 477 | 478 | 
| 478   ~SolarisMutex() { pthread_mutex_destroy(&mutex_); } | 479   ~SolarisMutex() { pthread_mutex_destroy(&mutex_); } | 
| 479 | 480 | 
| 480   int Lock() { return pthread_mutex_lock(&mutex_); } | 481   int Lock() { return pthread_mutex_lock(&mutex_); } | 
| 481 | 482 | 
| 482   int Unlock() { return pthread_mutex_unlock(&mutex_); } | 483   int Unlock() { return pthread_mutex_unlock(&mutex_); } | 
| 483 | 484 | 
|  | 485   virtual bool TryLock() { | 
|  | 486     int result = pthread_mutex_trylock(&mutex_); | 
|  | 487     // Return false if the lock is busy and locking failed. | 
|  | 488     if (result == EBUSY) { | 
|  | 489       return false; | 
|  | 490     } | 
|  | 491     ASSERT(result == 0);  // Verify no other errors. | 
|  | 492     return true; | 
|  | 493   } | 
|  | 494 | 
| 484  private: | 495  private: | 
| 485   pthread_mutex_t mutex_; | 496   pthread_mutex_t mutex_; | 
| 486 }; | 497 }; | 
| 487 | 498 | 
| 488 | 499 | 
| 489 Mutex* OS::CreateMutex() { | 500 Mutex* OS::CreateMutex() { | 
| 490   return new SolarisMutex(); | 501   return new SolarisMutex(); | 
| 491 } | 502 } | 
| 492 | 503 | 
| 493 | 504 | 
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 565 | 576 | 
| 566 | 577 | 
| 567 Semaphore* OS::CreateSemaphore(int count) { | 578 Semaphore* OS::CreateSemaphore(int count) { | 
| 568   return new SolarisSemaphore(count); | 579   return new SolarisSemaphore(count); | 
| 569 } | 580 } | 
| 570 | 581 | 
| 571 | 582 | 
| 572 #ifdef ENABLE_LOGGING_AND_PROFILING | 583 #ifdef ENABLE_LOGGING_AND_PROFILING | 
| 573 | 584 | 
| 574 static Sampler* active_sampler_ = NULL; | 585 static Sampler* active_sampler_ = NULL; | 
|  | 586 static pthread_t vm_tid_ = 0; | 
|  | 587 | 
| 575 | 588 | 
| 576 static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { | 589 static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { | 
| 577   USE(info); | 590   USE(info); | 
| 578   if (signal != SIGPROF) return; | 591   if (signal != SIGPROF) return; | 
| 579   if (active_sampler_ == NULL) return; | 592   if (active_sampler_ == NULL || !active_sampler_->IsActive()) return; | 
|  | 593   if (vm_tid_ != pthread_self()) return; | 
| 580 | 594 | 
| 581   TickSample sample; | 595   TickSample sample_obj; | 
| 582   sample.pc = 0; | 596   TickSample* sample = CpuProfiler::TickSampleEvent(); | 
| 583   sample.sp = 0; | 597   if (sample == NULL) sample = &sample_obj; | 
| 584   sample.fp = 0; |  | 
| 585 | 598 | 
| 586   // We always sample the VM state. | 599   // Extracting the sample from the context is extremely machine dependent. | 
| 587   sample.state = VMState::current_state(); | 600   ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context); | 
|  | 601   mcontext_t& mcontext = ucontext->uc_mcontext; | 
|  | 602   sample->state = Top::current_vm_state(); | 
| 588 | 603 | 
| 589   active_sampler_->Tick(&sample); | 604 #if V8_HOST_ARCH_IA32 | 
|  | 605   sample->pc = reinterpret_cast<Address>(mcontext.gregs[KDIREG_EIP]); | 
|  | 606   sample->sp = reinterpret_cast<Address>(mcontext.gregs[KDIREG_ESP]); | 
|  | 607   sample->fp = reinterpret_cast<Address>(mcontext.gregs[KDIREG_EBP]); | 
|  | 608 #elif V8_HOST_ARCH_X64 | 
|  | 609   sample->pc = reinterpret_cast<Address>(mcontext.gregs[KDIREG_RIP]); | 
|  | 610   sample->sp = reinterpret_cast<Address>(mcontext.gregs[KDIREG_RSP]); | 
|  | 611   sample->fp = reinterpret_cast<Address>(mcontext.gregs[KDIREG_RBP]); | 
|  | 612 #else | 
|  | 613   UNIMPLEMENTED(); | 
|  | 614 #endif | 
|  | 615   active_sampler_->SampleStack(sample); | 
|  | 616   active_sampler_->Tick(sample); | 
| 590 } | 617 } | 
| 591 | 618 | 
| 592 | 619 | 
| 593 class Sampler::PlatformData : public Malloced { | 620 class Sampler::PlatformData : public Malloced { | 
| 594  public: | 621  public: | 
| 595   PlatformData() { | 622   PlatformData() { | 
| 596     signal_handler_installed_ = false; | 623     signal_handler_installed_ = false; | 
| 597   } | 624   } | 
| 598 | 625 | 
| 599   bool signal_handler_installed_; | 626   bool signal_handler_installed_; | 
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 652   } | 679   } | 
| 653 | 680 | 
| 654   // This sampler is no longer the active sampler. | 681   // This sampler is no longer the active sampler. | 
| 655   active_sampler_ = NULL; | 682   active_sampler_ = NULL; | 
| 656   active_ = false; | 683   active_ = false; | 
| 657 } | 684 } | 
| 658 | 685 | 
| 659 #endif  // ENABLE_LOGGING_AND_PROFILING | 686 #endif  // ENABLE_LOGGING_AND_PROFILING | 
| 660 | 687 | 
| 661 } }  // namespace v8::internal | 688 } }  // namespace v8::internal | 
| OLD | NEW | 
|---|