| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 // Returns the daylight savings offset for the given time. | 170 // Returns the daylight savings offset for the given time. |
| 171 static double DaylightSavingsOffset(double time); | 171 static double DaylightSavingsOffset(double time); |
| 172 | 172 |
| 173 // Returns last OS error. | 173 // Returns last OS error. |
| 174 static int GetLastError(); | 174 static int GetLastError(); |
| 175 | 175 |
| 176 static FILE* FOpen(const char* path, const char* mode); | 176 static FILE* FOpen(const char* path, const char* mode); |
| 177 static bool Remove(const char* path); | 177 static bool Remove(const char* path); |
| 178 | 178 |
| 179 // Log file open mode is platform-dependent due to line ends issues. | 179 // Log file open mode is platform-dependent due to line ends issues. |
| 180 static const char* LogFileOpenMode; | 180 static const char* const LogFileOpenMode; |
| 181 | 181 |
| 182 // Print output to console. This is mostly used for debugging output. | 182 // Print output to console. This is mostly used for debugging output. |
| 183 // On platforms that has standard terminal output, the output | 183 // On platforms that has standard terminal output, the output |
| 184 // should go to stdout. | 184 // should go to stdout. |
| 185 static void Print(const char* format, ...); | 185 static void Print(const char* format, ...); |
| 186 static void VPrint(const char* format, va_list args); | 186 static void VPrint(const char* format, va_list args); |
| 187 | 187 |
| 188 // Print output to a file. This is mostly used for debugging output. | 188 // Print output to a file. This is mostly used for debugging output. |
| 189 static void FPrint(FILE* out, const char* format, ...); | 189 static void FPrint(FILE* out, const char* format, ...); |
| 190 static void VFPrint(FILE* out, const char* format, va_list args); | 190 static void VFPrint(FILE* out, const char* format, va_list args); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 public: | 381 public: |
| 382 // Opaque data type for thread-local storage keys. | 382 // Opaque data type for thread-local storage keys. |
| 383 // LOCAL_STORAGE_KEY_MIN_VALUE and LOCAL_STORAGE_KEY_MAX_VALUE are specified | 383 // LOCAL_STORAGE_KEY_MIN_VALUE and LOCAL_STORAGE_KEY_MAX_VALUE are specified |
| 384 // to ensure that enumeration type has correct value range (see Issue 830 for | 384 // to ensure that enumeration type has correct value range (see Issue 830 for |
| 385 // more details). | 385 // more details). |
| 386 enum LocalStorageKey { | 386 enum LocalStorageKey { |
| 387 LOCAL_STORAGE_KEY_MIN_VALUE = kMinInt, | 387 LOCAL_STORAGE_KEY_MIN_VALUE = kMinInt, |
| 388 LOCAL_STORAGE_KEY_MAX_VALUE = kMaxInt | 388 LOCAL_STORAGE_KEY_MAX_VALUE = kMaxInt |
| 389 }; | 389 }; |
| 390 | 390 |
| 391 // Create new thread. | 391 // Create new thread (with a value for storing in the TLS isolate field). |
| 392 Thread(); | 392 explicit Thread(Isolate* isolate); |
| 393 explicit Thread(const char* name); | 393 Thread(Isolate* isolate, const char* name); |
| 394 virtual ~Thread(); | 394 virtual ~Thread(); |
| 395 | 395 |
| 396 // Start new thread by calling the Run() method in the new thread. | 396 // Start new thread by calling the Run() method in the new thread. |
| 397 void Start(); | 397 void Start(); |
| 398 | 398 |
| 399 // Wait until thread terminates. | 399 // Wait until thread terminates. |
| 400 void Join(); | 400 void Join(); |
| 401 | 401 |
| 402 inline const char* name() const { | 402 inline const char* name() const { |
| 403 return name_; | 403 return name_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 417 static void SetThreadLocalInt(LocalStorageKey key, int value) { | 417 static void SetThreadLocalInt(LocalStorageKey key, int value) { |
| 418 SetThreadLocal(key, reinterpret_cast<void*>(static_cast<intptr_t>(value))); | 418 SetThreadLocal(key, reinterpret_cast<void*>(static_cast<intptr_t>(value))); |
| 419 } | 419 } |
| 420 static bool HasThreadLocal(LocalStorageKey key) { | 420 static bool HasThreadLocal(LocalStorageKey key) { |
| 421 return GetThreadLocal(key) != NULL; | 421 return GetThreadLocal(key) != NULL; |
| 422 } | 422 } |
| 423 | 423 |
| 424 // A hint to the scheduler to let another thread run. | 424 // A hint to the scheduler to let another thread run. |
| 425 static void YieldCPU(); | 425 static void YieldCPU(); |
| 426 | 426 |
| 427 Isolate* isolate() const { return isolate_; } |
| 428 |
| 427 // The thread name length is limited to 16 based on Linux's implementation of | 429 // The thread name length is limited to 16 based on Linux's implementation of |
| 428 // prctl(). | 430 // prctl(). |
| 429 static const int kMaxThreadNameLength = 16; | 431 static const int kMaxThreadNameLength = 16; |
| 430 private: | 432 private: |
| 431 void set_name(const char *name); | 433 void set_name(const char *name); |
| 432 | 434 |
| 433 class PlatformData; | 435 class PlatformData; |
| 434 PlatformData* data_; | 436 PlatformData* data_; |
| 435 | 437 Isolate* isolate_; |
| 436 char name_[kMaxThreadNameLength]; | 438 char name_[kMaxThreadNameLength]; |
| 437 | 439 |
| 438 DISALLOW_COPY_AND_ASSIGN(Thread); | 440 DISALLOW_COPY_AND_ASSIGN(Thread); |
| 439 }; | 441 }; |
| 440 | 442 |
| 441 | 443 |
| 442 // ---------------------------------------------------------------------------- | 444 // ---------------------------------------------------------------------------- |
| 443 // Mutex | 445 // Mutex |
| 444 // | 446 // |
| 445 // Mutexes are used for serializing access to non-reentrant sections of code. | 447 // Mutexes are used for serializing access to non-reentrant sections of code. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 459 // the calling thread on entrance. | 461 // the calling thread on entrance. |
| 460 virtual int Unlock() = 0; | 462 virtual int Unlock() = 0; |
| 461 | 463 |
| 462 // Tries to lock the given mutex. Returns whether the mutex was | 464 // Tries to lock the given mutex. Returns whether the mutex was |
| 463 // successfully locked. | 465 // successfully locked. |
| 464 virtual bool TryLock() = 0; | 466 virtual bool TryLock() = 0; |
| 465 }; | 467 }; |
| 466 | 468 |
| 467 | 469 |
| 468 // ---------------------------------------------------------------------------- | 470 // ---------------------------------------------------------------------------- |
| 469 // ScopedLock | 471 // ScopedLock/ScopedUnlock |
| 470 // | 472 // |
| 471 // Stack-allocated ScopedLocks provide block-scoped locking and unlocking | 473 // Stack-allocated ScopedLocks/ScopedUnlocks provide block-scoped |
| 472 // of a mutex. | 474 // locking and unlocking of a mutex. |
| 473 class ScopedLock { | 475 class ScopedLock { |
| 474 public: | 476 public: |
| 475 explicit ScopedLock(Mutex* mutex): mutex_(mutex) { | 477 explicit ScopedLock(Mutex* mutex): mutex_(mutex) { |
| 478 ASSERT(mutex_ != NULL); |
| 476 mutex_->Lock(); | 479 mutex_->Lock(); |
| 477 } | 480 } |
| 478 ~ScopedLock() { | 481 ~ScopedLock() { |
| 479 mutex_->Unlock(); | 482 mutex_->Unlock(); |
| 480 } | 483 } |
| 481 | 484 |
| 482 private: | 485 private: |
| 483 Mutex* mutex_; | 486 Mutex* mutex_; |
| 484 DISALLOW_COPY_AND_ASSIGN(ScopedLock); | 487 DISALLOW_COPY_AND_ASSIGN(ScopedLock); |
| 485 }; | 488 }; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 Address tos; // Top stack value (*sp). | 579 Address tos; // Top stack value (*sp). |
| 577 static const int kMaxFramesCount = 64; | 580 static const int kMaxFramesCount = 64; |
| 578 Address stack[kMaxFramesCount]; // Call stack. | 581 Address stack[kMaxFramesCount]; // Call stack. |
| 579 int frames_count; // Number of captured frames. | 582 int frames_count; // Number of captured frames. |
| 580 }; | 583 }; |
| 581 | 584 |
| 582 #ifdef ENABLE_LOGGING_AND_PROFILING | 585 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 583 class Sampler { | 586 class Sampler { |
| 584 public: | 587 public: |
| 585 // Initialize sampler. | 588 // Initialize sampler. |
| 586 explicit Sampler(int interval); | 589 Sampler(Isolate* isolate, int interval); |
| 587 virtual ~Sampler(); | 590 virtual ~Sampler(); |
| 588 | 591 |
| 592 int interval() const { return interval_; } |
| 593 |
| 589 // Performs stack sampling. | 594 // Performs stack sampling. |
| 590 void SampleStack(TickSample* sample) { | 595 void SampleStack(TickSample* sample) { |
| 591 DoSampleStack(sample); | 596 DoSampleStack(sample); |
| 592 IncSamplesTaken(); | 597 IncSamplesTaken(); |
| 593 } | 598 } |
| 594 | 599 |
| 595 // This method is called for each sampling period with the current | 600 // This method is called for each sampling period with the current |
| 596 // program counter. | 601 // program counter. |
| 597 virtual void Tick(TickSample* sample) = 0; | 602 virtual void Tick(TickSample* sample) = 0; |
| 598 | 603 |
| 599 // Start and stop sampler. | 604 // Start and stop sampler. |
| 600 void Start(); | 605 void Start(); |
| 601 void Stop(); | 606 void Stop(); |
| 602 | 607 |
| 603 // Is the sampler used for profiling? | 608 // Is the sampler used for profiling? |
| 604 bool IsProfiling() const { return NoBarrier_Load(&profiling_) > 0; } | 609 bool IsProfiling() const { return NoBarrier_Load(&profiling_) > 0; } |
| 605 void IncreaseProfilingDepth() { NoBarrier_AtomicIncrement(&profiling_, 1); } | 610 void IncreaseProfilingDepth() { NoBarrier_AtomicIncrement(&profiling_, 1); } |
| 606 void DecreaseProfilingDepth() { NoBarrier_AtomicIncrement(&profiling_, -1); } | 611 void DecreaseProfilingDepth() { NoBarrier_AtomicIncrement(&profiling_, -1); } |
| 607 | 612 |
| 608 // Whether the sampler is running (that is, consumes resources). | 613 // Whether the sampler is running (that is, consumes resources). |
| 609 bool IsActive() const { return NoBarrier_Load(&active_); } | 614 bool IsActive() const { return NoBarrier_Load(&active_); } |
| 610 | 615 |
| 616 Isolate* isolate() { return isolate_; } |
| 617 |
| 611 // Used in tests to make sure that stack sampling is performed. | 618 // Used in tests to make sure that stack sampling is performed. |
| 612 int samples_taken() const { return samples_taken_; } | 619 int samples_taken() const { return samples_taken_; } |
| 613 void ResetSamplesTaken() { samples_taken_ = 0; } | 620 void ResetSamplesTaken() { samples_taken_ = 0; } |
| 614 | 621 |
| 615 class PlatformData; | 622 class PlatformData; |
| 616 PlatformData* data() { return data_; } | 623 PlatformData* data() { return data_; } |
| 617 | 624 |
| 625 PlatformData* platform_data() { return data_; } |
| 626 |
| 618 protected: | 627 protected: |
| 619 virtual void DoSampleStack(TickSample* sample) = 0; | 628 virtual void DoSampleStack(TickSample* sample) = 0; |
| 620 | 629 |
| 621 private: | 630 private: |
| 622 void SetActive(bool value) { NoBarrier_Store(&active_, value); } | 631 void SetActive(bool value) { NoBarrier_Store(&active_, value); } |
| 623 void IncSamplesTaken() { if (++samples_taken_ < 0) samples_taken_ = 0; } | 632 void IncSamplesTaken() { if (++samples_taken_ < 0) samples_taken_ = 0; } |
| 624 | 633 |
| 634 Isolate* isolate_; |
| 625 const int interval_; | 635 const int interval_; |
| 626 Atomic32 profiling_; | 636 Atomic32 profiling_; |
| 627 Atomic32 active_; | 637 Atomic32 active_; |
| 628 PlatformData* data_; // Platform specific data. | 638 PlatformData* data_; // Platform specific data. |
| 629 int samples_taken_; // Counts stack samples taken. | 639 int samples_taken_; // Counts stack samples taken. |
| 630 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); | 640 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); |
| 631 }; | 641 }; |
| 632 | 642 |
| 643 |
| 633 #endif // ENABLE_LOGGING_AND_PROFILING | 644 #endif // ENABLE_LOGGING_AND_PROFILING |
| 634 | 645 |
| 635 } } // namespace v8::internal | 646 } } // namespace v8::internal |
| 636 | 647 |
| 637 #endif // V8_PLATFORM_H_ | 648 #endif // V8_PLATFORM_H_ |
| OLD | NEW |