Changeset 99374 in webkit for trunk/Source/JavaScriptCore/bytecode/SamplingTool.h
- Timestamp:
- Nov 6, 2011, 3:39:12 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/bytecode/SamplingTool.h
r95901 r99374 35 35 #include "SamplingCounter.h" 36 36 #include <wtf/Assertions.h> 37 #include <wtf/Atomics.h> 37 38 #include <wtf/HashMap.h> 39 #include <wtf/MainThread.h> 38 40 #include <wtf/Threading.h> 39 41 … … 93 95 #endif 94 96 }; 97 98 #if ENABLE(SAMPLING_REGIONS) 99 class SamplingRegion { 100 public: 101 // Create a scoped sampling region using a C string constant name that describes 102 // what you are doing. This must be a string constant that persists for the 103 // lifetime of the process and is immutable. 104 SamplingRegion(const char* name) 105 { 106 if (!isMainThread()) { 107 m_name = 0; 108 return; 109 } 110 111 m_name = name; 112 exchangeCurrent(this, &m_previous); 113 ASSERT(!m_previous || m_previous > this); 114 } 115 116 ~SamplingRegion() 117 { 118 if (!m_name) 119 return; 120 121 ASSERT(bitwise_cast<SamplingRegion*>(s_currentOrReserved & ~1) == this); 122 exchangeCurrent(m_previous); 123 } 124 125 static void sample(); 126 127 static void dump(); 128 129 private: 130 const char* m_name; 131 SamplingRegion* m_previous; 132 133 static void exchangeCurrent(SamplingRegion* current, SamplingRegion** previousPtr = 0) 134 { 135 uintptr_t previous; 136 while (true) { 137 previous = s_currentOrReserved; 138 139 // If it's reserved (i.e. sampling thread is reading it), loop around. 140 if (previous & 1) { 141 #if OS(UNIX) 142 sched_yield(); 143 #endif 144 continue; 145 } 146 147 // If we're going to CAS, then make sure previous is set. 148 if (previousPtr) 149 *previousPtr = bitwise_cast<SamplingRegion*>(previous); 150 151 if (WTF::weakCompareAndSwap(&s_currentOrReserved, previous, bitwise_cast<uintptr_t>(current))) 152 break; 153 } 154 } 155 156 static void dumpInternal(); 157 158 class Locker { 159 public: 160 Locker(); 161 ~Locker(); 162 }; 163 164 static volatile uintptr_t s_currentOrReserved; 165 166 // rely on identity hashing of string constants 167 static Spectrum<const char*>* s_spectrum; 168 169 static unsigned long s_noneOfTheAbove; 170 171 static unsigned s_numberOfSamplesSinceDump; 172 }; 173 #else // ENABLE(SAMPLING_REGIONS) 174 class SamplingRegion { 175 public: 176 SamplingRegion(const char*) { } 177 void dump(); 178 }; 179 #endif // ENABLE(SAMPLING_REGIONS) 95 180 96 181 class CodeBlock;
Note:
See TracChangeset
for help on using the changeset viewer.