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

Side by Side Diff: src/platform.h

Issue 13852005: Move *BSD and Solaris Sampler implementations into sampler.cc (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Removed class TickSample forward declaration Created 7 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
« no previous file with comments | « src/log.cc ('k') | src/platform-freebsd.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 #endif // _MSC_VER 92 #endif // _MSC_VER
93 93
94 // Random is missing on both Visual Studio and MinGW. 94 // Random is missing on both Visual Studio and MinGW.
95 int random(); 95 int random();
96 96
97 #endif // WIN32 97 #endif // WIN32
98 98
99 #include "atomicops.h" 99 #include "atomicops.h"
100 #include "lazy-instance.h" 100 #include "lazy-instance.h"
101 #include "platform-tls.h" 101 #include "platform-tls.h"
102 #include "sampler.h"
102 #include "utils.h" 103 #include "utils.h"
103 #include "v8globals.h" 104 #include "v8globals.h"
104 105
105 namespace v8 { 106 namespace v8 {
106 namespace internal { 107 namespace internal {
107 108
108 // Use AtomicWord for a machine-sized pointer. It is assumed that
109 // reads and writes of naturally aligned values of this type are atomic.
110 #if defined(__OpenBSD__) && defined(__i386__)
111 typedef Atomic32 AtomicWord;
112 #else
113 typedef intptr_t AtomicWord;
114 #endif
115
116 class Semaphore; 109 class Semaphore;
117 class Mutex; 110 class Mutex;
118 111
119 double ceiling(double x); 112 double ceiling(double x);
120 double modulo(double x, double y); 113 double modulo(double x, double y);
121 114
122 // Custom implementation of math functions. 115 // Custom implementation of math functions.
123 double fast_sin(double input); 116 double fast_sin(double input);
124 double fast_cos(double input); 117 double fast_cos(double input);
125 double fast_tan(double input); 118 double fast_tan(double input);
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 713
721 static bool SetUp(); 714 static bool SetUp();
722 static int LastError(); 715 static int LastError();
723 static uint16_t HToN(uint16_t value); 716 static uint16_t HToN(uint16_t value);
724 static uint16_t NToH(uint16_t value); 717 static uint16_t NToH(uint16_t value);
725 static uint32_t HToN(uint32_t value); 718 static uint32_t HToN(uint32_t value);
726 static uint32_t NToH(uint32_t value); 719 static uint32_t NToH(uint32_t value);
727 }; 720 };
728 721
729 722
730 // ----------------------------------------------------------------------------
731 // Sampler
732 //
733 // A sampler periodically samples the state of the VM and optionally
734 // (if used for profiling) the program counter and stack pointer for
735 // the thread that created it.
736
737 // TickSample captures the information collected for each sample.
738 class TickSample {
739 public:
740 TickSample()
741 : state(OTHER),
742 pc(NULL),
743 sp(NULL),
744 fp(NULL),
745 external_callback(NULL),
746 frames_count(0) {}
747 StateTag state; // The state of the VM.
748 Address pc; // Instruction pointer.
749 Address sp; // Stack pointer.
750 Address fp; // Frame pointer.
751 Address external_callback;
752 static const int kMaxFramesCount = 64;
753 Address stack[kMaxFramesCount]; // Call stack.
754 int frames_count : 8; // Number of captured frames.
755 };
756
757 class Sampler {
758 public:
759 // Initialize sampler.
760 Sampler(Isolate* isolate, int interval);
761 virtual ~Sampler();
762
763 int interval() const { return interval_; }
764
765 // Performs stack sampling.
766 void SampleStack(TickSample* sample) {
767 DoSampleStack(sample);
768 IncSamplesTaken();
769 }
770
771 // This method is called for each sampling period with the current
772 // program counter.
773 virtual void Tick(TickSample* sample) = 0;
774
775 // Start and stop sampler.
776 void Start();
777 void Stop();
778
779 // Is the sampler used for profiling?
780 bool IsProfiling() const { return NoBarrier_Load(&profiling_) > 0; }
781 void IncreaseProfilingDepth() { NoBarrier_AtomicIncrement(&profiling_, 1); }
782 void DecreaseProfilingDepth() { NoBarrier_AtomicIncrement(&profiling_, -1); }
783
784 // Whether the sampler is running (that is, consumes resources).
785 bool IsActive() const { return NoBarrier_Load(&active_); }
786
787 Isolate* isolate() { return isolate_; }
788
789 // Used in tests to make sure that stack sampling is performed.
790 int samples_taken() const { return samples_taken_; }
791 void ResetSamplesTaken() { samples_taken_ = 0; }
792
793 class PlatformData;
794 PlatformData* data() { return data_; }
795
796 PlatformData* platform_data() { return data_; }
797
798 protected:
799 virtual void DoSampleStack(TickSample* sample) = 0;
800
801 private:
802 void SetActive(bool value) { NoBarrier_Store(&active_, value); }
803 void IncSamplesTaken() { if (++samples_taken_ < 0) samples_taken_ = 0; }
804
805 Isolate* isolate_;
806 const int interval_;
807 Atomic32 profiling_;
808 Atomic32 active_;
809 PlatformData* data_; // Platform specific data.
810 int samples_taken_; // Counts stack samples taken.
811 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler);
812 };
813
814
815 } } // namespace v8::internal 723 } } // namespace v8::internal
816 724
817 #endif // V8_PLATFORM_H_ 725 #endif // V8_PLATFORM_H_
OLDNEW
« no previous file with comments | « src/log.cc ('k') | src/platform-freebsd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698