Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1098)

Side by Side Diff: src/platform.h

Issue 6880010: Merge (7265, 7271] from bleeding_edge to experimental/gc branch.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 public: 390 public:
391 // Opaque data type for thread-local storage keys. 391 // Opaque data type for thread-local storage keys.
392 // LOCAL_STORAGE_KEY_MIN_VALUE and LOCAL_STORAGE_KEY_MAX_VALUE are specified 392 // LOCAL_STORAGE_KEY_MIN_VALUE and LOCAL_STORAGE_KEY_MAX_VALUE are specified
393 // to ensure that enumeration type has correct value range (see Issue 830 for 393 // to ensure that enumeration type has correct value range (see Issue 830 for
394 // more details). 394 // more details).
395 enum LocalStorageKey { 395 enum LocalStorageKey {
396 LOCAL_STORAGE_KEY_MIN_VALUE = kMinInt, 396 LOCAL_STORAGE_KEY_MIN_VALUE = kMinInt,
397 LOCAL_STORAGE_KEY_MAX_VALUE = kMaxInt 397 LOCAL_STORAGE_KEY_MAX_VALUE = kMaxInt
398 }; 398 };
399 399
400 // Create new thread. 400 // Create new thread (with a value for storing in the TLS isolate field).
401 Thread(); 401 explicit Thread(Isolate* isolate);
402 explicit Thread(const char* name); 402 Thread(Isolate* isolate, const char* name);
403 virtual ~Thread(); 403 virtual ~Thread();
404 404
405 // Start new thread by calling the Run() method in the new thread. 405 // Start new thread by calling the Run() method in the new thread.
406 void Start(); 406 void Start();
407 407
408 // Wait until thread terminates. 408 // Wait until thread terminates.
409 void Join(); 409 void Join();
410 410
411 inline const char* name() const { 411 inline const char* name() const {
412 return name_; 412 return name_;
(...skipping 13 matching lines...) Expand all
426 static void SetThreadLocalInt(LocalStorageKey key, int value) { 426 static void SetThreadLocalInt(LocalStorageKey key, int value) {
427 SetThreadLocal(key, reinterpret_cast<void*>(static_cast<intptr_t>(value))); 427 SetThreadLocal(key, reinterpret_cast<void*>(static_cast<intptr_t>(value)));
428 } 428 }
429 static bool HasThreadLocal(LocalStorageKey key) { 429 static bool HasThreadLocal(LocalStorageKey key) {
430 return GetThreadLocal(key) != NULL; 430 return GetThreadLocal(key) != NULL;
431 } 431 }
432 432
433 // A hint to the scheduler to let another thread run. 433 // A hint to the scheduler to let another thread run.
434 static void YieldCPU(); 434 static void YieldCPU();
435 435
436 Isolate* isolate() const { return isolate_; }
437
436 // The thread name length is limited to 16 based on Linux's implementation of 438 // The thread name length is limited to 16 based on Linux's implementation of
437 // prctl(). 439 // prctl().
438 static const int kMaxThreadNameLength = 16; 440 static const int kMaxThreadNameLength = 16;
439 private: 441 private:
440 void set_name(const char *name); 442 void set_name(const char *name);
441 443
442 class PlatformData; 444 class PlatformData;
443 PlatformData* data_; 445 PlatformData* data_;
444 446 Isolate* isolate_;
445 char name_[kMaxThreadNameLength]; 447 char name_[kMaxThreadNameLength];
446 448
447 DISALLOW_COPY_AND_ASSIGN(Thread); 449 DISALLOW_COPY_AND_ASSIGN(Thread);
448 }; 450 };
449 451
450 452
451 // ---------------------------------------------------------------------------- 453 // ----------------------------------------------------------------------------
452 // Mutex 454 // Mutex
453 // 455 //
454 // Mutexes are used for serializing access to non-reentrant sections of code. 456 // Mutexes are used for serializing access to non-reentrant sections of code.
(...skipping 13 matching lines...) Expand all
468 // the calling thread on entrance. 470 // the calling thread on entrance.
469 virtual int Unlock() = 0; 471 virtual int Unlock() = 0;
470 472
471 // Tries to lock the given mutex. Returns whether the mutex was 473 // Tries to lock the given mutex. Returns whether the mutex was
472 // successfully locked. 474 // successfully locked.
473 virtual bool TryLock() = 0; 475 virtual bool TryLock() = 0;
474 }; 476 };
475 477
476 478
477 // ---------------------------------------------------------------------------- 479 // ----------------------------------------------------------------------------
478 // ScopedLock 480 // ScopedLock/ScopedUnlock
479 // 481 //
480 // Stack-allocated ScopedLocks provide block-scoped locking and unlocking 482 // Stack-allocated ScopedLocks/ScopedUnlocks provide block-scoped
481 // of a mutex. 483 // locking and unlocking of a mutex.
482 class ScopedLock { 484 class ScopedLock {
483 public: 485 public:
484 explicit ScopedLock(Mutex* mutex): mutex_(mutex) { 486 explicit ScopedLock(Mutex* mutex): mutex_(mutex) {
487 ASSERT(mutex_ != NULL);
485 mutex_->Lock(); 488 mutex_->Lock();
486 } 489 }
487 ~ScopedLock() { 490 ~ScopedLock() {
488 mutex_->Unlock(); 491 mutex_->Unlock();
489 } 492 }
490 493
491 private: 494 private:
492 Mutex* mutex_; 495 Mutex* mutex_;
493 DISALLOW_COPY_AND_ASSIGN(ScopedLock); 496 DISALLOW_COPY_AND_ASSIGN(ScopedLock);
494 }; 497 };
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 Address tos; // Top stack value (*sp). 588 Address tos; // Top stack value (*sp).
586 static const int kMaxFramesCount = 64; 589 static const int kMaxFramesCount = 64;
587 Address stack[kMaxFramesCount]; // Call stack. 590 Address stack[kMaxFramesCount]; // Call stack.
588 int frames_count; // Number of captured frames. 591 int frames_count; // Number of captured frames.
589 }; 592 };
590 593
591 #ifdef ENABLE_LOGGING_AND_PROFILING 594 #ifdef ENABLE_LOGGING_AND_PROFILING
592 class Sampler { 595 class Sampler {
593 public: 596 public:
594 // Initialize sampler. 597 // Initialize sampler.
595 explicit Sampler(int interval); 598 Sampler(Isolate* isolate, int interval);
596 virtual ~Sampler(); 599 virtual ~Sampler();
597 600
601 int interval() const { return interval_; }
602
598 // Performs stack sampling. 603 // Performs stack sampling.
599 void SampleStack(TickSample* sample) { 604 void SampleStack(TickSample* sample) {
600 DoSampleStack(sample); 605 DoSampleStack(sample);
601 IncSamplesTaken(); 606 IncSamplesTaken();
602 } 607 }
603 608
604 // This method is called for each sampling period with the current 609 // This method is called for each sampling period with the current
605 // program counter. 610 // program counter.
606 virtual void Tick(TickSample* sample) = 0; 611 virtual void Tick(TickSample* sample) = 0;
607 612
608 // Start and stop sampler. 613 // Start and stop sampler.
609 void Start(); 614 void Start();
610 void Stop(); 615 void Stop();
611 616
612 // Is the sampler used for profiling? 617 // Is the sampler used for profiling?
613 bool IsProfiling() const { return NoBarrier_Load(&profiling_) > 0; } 618 bool IsProfiling() const { return NoBarrier_Load(&profiling_) > 0; }
614 void IncreaseProfilingDepth() { NoBarrier_AtomicIncrement(&profiling_, 1); } 619 void IncreaseProfilingDepth() { NoBarrier_AtomicIncrement(&profiling_, 1); }
615 void DecreaseProfilingDepth() { NoBarrier_AtomicIncrement(&profiling_, -1); } 620 void DecreaseProfilingDepth() { NoBarrier_AtomicIncrement(&profiling_, -1); }
616 621
617 // Whether the sampler is running (that is, consumes resources). 622 // Whether the sampler is running (that is, consumes resources).
618 bool IsActive() const { return NoBarrier_Load(&active_); } 623 bool IsActive() const { return NoBarrier_Load(&active_); }
619 624
625 Isolate* isolate() { return isolate_; }
626
620 // Used in tests to make sure that stack sampling is performed. 627 // Used in tests to make sure that stack sampling is performed.
621 int samples_taken() const { return samples_taken_; } 628 int samples_taken() const { return samples_taken_; }
622 void ResetSamplesTaken() { samples_taken_ = 0; } 629 void ResetSamplesTaken() { samples_taken_ = 0; }
623 630
624 class PlatformData; 631 class PlatformData;
625 PlatformData* data() { return data_; } 632 PlatformData* data() { return data_; }
626 633
634 PlatformData* platform_data() { return data_; }
635
627 protected: 636 protected:
628 virtual void DoSampleStack(TickSample* sample) = 0; 637 virtual void DoSampleStack(TickSample* sample) = 0;
629 638
630 private: 639 private:
631 void SetActive(bool value) { NoBarrier_Store(&active_, value); } 640 void SetActive(bool value) { NoBarrier_Store(&active_, value); }
632 void IncSamplesTaken() { if (++samples_taken_ < 0) samples_taken_ = 0; } 641 void IncSamplesTaken() { if (++samples_taken_ < 0) samples_taken_ = 0; }
633 642
643 Isolate* isolate_;
634 const int interval_; 644 const int interval_;
635 Atomic32 profiling_; 645 Atomic32 profiling_;
636 Atomic32 active_; 646 Atomic32 active_;
637 PlatformData* data_; // Platform specific data. 647 PlatformData* data_; // Platform specific data.
638 int samples_taken_; // Counts stack samples taken. 648 int samples_taken_; // Counts stack samples taken.
639 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); 649 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler);
640 }; 650 };
641 651
652
642 #endif // ENABLE_LOGGING_AND_PROFILING 653 #endif // ENABLE_LOGGING_AND_PROFILING
643 654
644 } } // namespace v8::internal 655 } } // namespace v8::internal
645 656
646 #endif // V8_PLATFORM_H_ 657 #endif // V8_PLATFORM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698