kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | // This module contains the platform-specific code. This make the rest of the |
| 29 | // code less dependent on operating system, compilers and runtime libraries. |
| 30 | // This module does specifically not deal with differences between different |
| 31 | // processor architecture. |
| 32 | // The platform classes have the same definition for all platforms. The |
| 33 | // implementation for a particular platform is put in platform_<os>.cc. |
| 34 | // The build system then uses the implementation for the target platform. |
| 35 | // |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 36 | // This design has been chosen because it is simple and fast. Alternatively, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 37 | // the platform dependent classes could have been implemented using abstract |
| 38 | // superclasses with virtual methods and having specializations for each |
| 39 | // platform. This design was rejected because it was more complicated and |
| 40 | // slower. It would require factory methods for selecting the right |
| 41 | // implementation and the overhead of virtual methods for performance |
| 42 | // sensitive like mutex locking/unlocking. |
| 43 | |
| 44 | #ifndef V8_PLATFORM_H_ |
| 45 | #define V8_PLATFORM_H_ |
| 46 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 47 | #define V8_INFINITY INFINITY |
| 48 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 49 | // Windows specific stuff. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 50 | #ifdef WIN32 |
| 51 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 52 | // Microsoft Visual C++ specific stuff. |
| 53 | #ifdef _MSC_VER |
| 54 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 55 | enum { |
| 56 | FP_NAN, |
| 57 | FP_INFINITE, |
| 58 | FP_ZERO, |
| 59 | FP_SUBNORMAL, |
| 60 | FP_NORMAL |
| 61 | }; |
| 62 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 63 | #undef V8_INFINITY |
| 64 | #define V8_INFINITY HUGE_VAL |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 65 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 66 | namespace v8 { |
| 67 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 68 | int isfinite(double x); |
| 69 | } } |
| 70 | int isnan(double x); |
| 71 | int isinf(double x); |
| 72 | int isless(double x, double y); |
| 73 | int isgreater(double x, double y); |
| 74 | int fpclassify(double x); |
| 75 | int signbit(double x); |
| 76 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 77 | int strncasecmp(const char* s1, const char* s2, int n); |
| 78 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 79 | #endif // _MSC_VER |
| 80 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 81 | // Random is missing on both Visual Studio and MinGW. |
| 82 | int random(); |
| 83 | |
| 84 | #endif // WIN32 |
| 85 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 86 | |
| 87 | #ifdef __sun |
| 88 | # ifndef signbit |
| 89 | int signbit(double x); |
| 90 | # endif |
| 91 | #endif |
| 92 | |
| 93 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 94 | // GCC specific stuff |
| 95 | #ifdef __GNUC__ |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 96 | |
| 97 | // Needed for va_list on at least MinGW and Android. |
| 98 | #include <stdarg.h> |
| 99 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 100 | #define __GNUC_VERSION__ (__GNUC__ * 10000 + __GNUC_MINOR__ * 100) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 101 | |
| 102 | // Unfortunately, the INFINITY macro cannot be used with the '-pedantic' |
| 103 | // warning flag and certain versions of GCC due to a bug: |
| 104 | // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11931 |
| 105 | // For now, we use the more involved template-based version from <limits>, but |
| 106 | // only when compiling with GCC versions affected by the bug (2.96.x - 4.0.x) |
| 107 | // __GNUC_PREREQ is not defined in GCC for Mac OS X, so we define our own macro |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 108 | #if __GNUC_VERSION__ >= 29600 && __GNUC_VERSION__ < 40100 |
| 109 | #include <limits> |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 110 | #undef V8_INFINITY |
| 111 | #define V8_INFINITY std::numeric_limits<double>::infinity() |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 112 | #endif |
| 113 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 114 | #endif // __GNUC__ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 115 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 116 | #include "atomicops.h" |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 117 | #include "platform-tls.h" |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 118 | #include "utils.h" |
| 119 | #include "v8globals.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 120 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 121 | namespace v8 { |
| 122 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 123 | |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 124 | // Use AtomicWord for a machine-sized pointer. It is assumed that |
| 125 | // reads and writes of naturally aligned values of this type are atomic. |
| 126 | typedef intptr_t AtomicWord; |
| 127 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 128 | class Semaphore; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 129 | class Mutex; |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 130 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 131 | double ceiling(double x); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 132 | double modulo(double x, double y); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 133 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 134 | // Forward declarations. |
| 135 | class Socket; |
| 136 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 137 | // ---------------------------------------------------------------------------- |
| 138 | // OS |
| 139 | // |
| 140 | // This class has static methods for the different platform specific |
| 141 | // functions. Add methods here to cope with differences between the |
| 142 | // supported platforms. |
| 143 | |
| 144 | class OS { |
| 145 | public: |
| 146 | // Initializes the platform OS support. Called once at VM startup. |
| 147 | static void Setup(); |
| 148 | |
| 149 | // Returns the accumulated user time for thread. This routine |
| 150 | // can be used for profiling. The implementation should |
| 151 | // strive for high-precision timer resolution, preferable |
| 152 | // micro-second resolution. |
| 153 | static int GetUserTime(uint32_t* secs, uint32_t* usecs); |
| 154 | |
| 155 | // Get a tick counter normalized to one tick per microsecond. |
| 156 | // Used for calculating time intervals. |
| 157 | static int64_t Ticks(); |
| 158 | |
| 159 | // Returns current time as the number of milliseconds since |
| 160 | // 00:00:00 UTC, January 1, 1970. |
| 161 | static double TimeCurrentMillis(); |
| 162 | |
| 163 | // Returns a string identifying the current time zone. The |
| 164 | // timestamp is used for determining if DST is in effect. |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 165 | static const char* LocalTimezone(double time); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 166 | |
| 167 | // Returns the local time offset in milliseconds east of UTC without |
| 168 | // taking daylight savings time into account. |
| 169 | static double LocalTimeOffset(); |
| 170 | |
| 171 | // Returns the daylight savings offset for the given time. |
| 172 | static double DaylightSavingsOffset(double time); |
| 173 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 174 | // Returns last OS error. |
| 175 | static int GetLastError(); |
| 176 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 177 | static FILE* FOpen(const char* path, const char* mode); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 178 | static bool Remove(const char* path); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 179 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 180 | // Opens a temporary file, the file is auto removed on close. |
| 181 | static FILE* OpenTemporaryFile(); |
| 182 | |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 183 | // Log file open mode is platform-dependent due to line ends issues. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 184 | static const char* const LogFileOpenMode; |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 185 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 186 | // Print output to console. This is mostly used for debugging output. |
| 187 | // On platforms that has standard terminal output, the output |
| 188 | // should go to stdout. |
| 189 | static void Print(const char* format, ...); |
| 190 | static void VPrint(const char* format, va_list args); |
| 191 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 192 | // Print output to a file. This is mostly used for debugging output. |
| 193 | static void FPrint(FILE* out, const char* format, ...); |
| 194 | static void VFPrint(FILE* out, const char* format, va_list args); |
| 195 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 196 | // Print error output to console. This is mostly used for error message |
| 197 | // output. On platforms that has standard terminal output, the output |
| 198 | // should go to stderr. |
| 199 | static void PrintError(const char* format, ...); |
| 200 | static void VPrintError(const char* format, va_list args); |
| 201 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 202 | // Allocate/Free memory used by JS heap. Pages are readable/writable, but |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 203 | // they are not guaranteed to be executable unless 'executable' is true. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 204 | // Returns the address of allocated memory, or NULL if failed. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 205 | static void* Allocate(const size_t requested, |
| 206 | size_t* allocated, |
kasperl@chromium.org | f5aa837 | 2009-03-24 14:47:14 +0000 | [diff] [blame] | 207 | bool is_executable); |
| 208 | static void Free(void* address, const size_t size); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 209 | |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 210 | // Mark code segments non-writable. |
| 211 | static void ProtectCode(void* address, const size_t size); |
| 212 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 213 | // Assign memory as a guard page so that access will cause an exception. |
| 214 | static void Guard(void* address, const size_t size); |
| 215 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 216 | // Get the Alignment guaranteed by Allocate(). |
| 217 | static size_t AllocateAlignment(); |
| 218 | |
| 219 | // Returns an indication of whether a pointer is in a space that |
| 220 | // has been allocated by Allocate(). This method may conservatively |
| 221 | // always return false, but giving more accurate information may |
| 222 | // improve the robustness of the stack dump code in the presence of |
| 223 | // heap corruption. |
| 224 | static bool IsOutsideAllocatedSpace(void* pointer); |
| 225 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 226 | // Sleep for a number of milliseconds. |
| 227 | static void Sleep(const int milliseconds); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 228 | |
| 229 | // Abort the current process. |
| 230 | static void Abort(); |
| 231 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 232 | // Debug break. |
| 233 | static void DebugBreak(); |
| 234 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 235 | // Walk the stack. |
| 236 | static const int kStackWalkError = -1; |
| 237 | static const int kStackWalkMaxNameLen = 256; |
| 238 | static const int kStackWalkMaxTextLen = 256; |
| 239 | struct StackFrame { |
| 240 | void* address; |
| 241 | char text[kStackWalkMaxTextLen]; |
| 242 | }; |
| 243 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 244 | static int StackWalk(Vector<StackFrame> frames); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 245 | |
| 246 | // Factory method for creating platform dependent Mutex. |
| 247 | // Please use delete to reclaim the storage for the returned Mutex. |
| 248 | static Mutex* CreateMutex(); |
| 249 | |
| 250 | // Factory method for creating platform dependent Semaphore. |
| 251 | // Please use delete to reclaim the storage for the returned Semaphore. |
| 252 | static Semaphore* CreateSemaphore(int count); |
| 253 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 254 | // Factory method for creating platform dependent Socket. |
| 255 | // Please use delete to reclaim the storage for the returned Socket. |
| 256 | static Socket* CreateSocket(); |
| 257 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 258 | class MemoryMappedFile { |
| 259 | public: |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 260 | static MemoryMappedFile* open(const char* name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 261 | static MemoryMappedFile* create(const char* name, int size, void* initial); |
| 262 | virtual ~MemoryMappedFile() { } |
| 263 | virtual void* memory() = 0; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 264 | virtual int size() = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 265 | }; |
| 266 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 267 | // Safe formatting print. Ensures that str is always null-terminated. |
| 268 | // Returns the number of chars written, or -1 if output was truncated. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 269 | static int SNPrintF(Vector<char> str, const char* format, ...); |
| 270 | static int VSNPrintF(Vector<char> str, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 271 | const char* format, |
| 272 | va_list args); |
| 273 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 274 | static char* StrChr(char* str, int c); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 275 | static void StrNCpy(Vector<char> dest, const char* src, size_t n); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 276 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 277 | // Support for the profiler. Can do nothing, in which case ticks |
| 278 | // occuring in shared libraries will not be properly accounted for. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 279 | static void LogSharedLibraryAddresses(); |
| 280 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 281 | // Support for the profiler. Notifies the external profiling |
| 282 | // process that a code moving garbage collection starts. Can do |
| 283 | // nothing, in which case the code objects must not move (e.g., by |
| 284 | // using --never-compact) if accurate profiling is desired. |
| 285 | static void SignalCodeMovingGC(); |
| 286 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 287 | // The return value indicates the CPU features we are sure of because of the |
| 288 | // OS. For example MacOSX doesn't run on any x86 CPUs that don't have SSE2 |
| 289 | // instructions. |
| 290 | // This is a little messy because the interpretation is subject to the cross |
| 291 | // of the CPU and the OS. The bits in the answer correspond to the bit |
| 292 | // positions indicated by the members of the CpuFeature enum from globals.h |
| 293 | static uint64_t CpuFeaturesImpliedByPlatform(); |
| 294 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 295 | // Maximum size of the virtual memory. 0 means there is no artificial |
| 296 | // limit. |
| 297 | static intptr_t MaxVirtualMemory(); |
| 298 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 299 | // Returns the double constant NAN |
| 300 | static double nan_value(); |
| 301 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 302 | // Support runtime detection of VFP3 on ARM CPUs. |
| 303 | static bool ArmCpuHasFeature(CpuFeature feature); |
| 304 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 305 | // Support runtime detection of whether the hard float option of the |
| 306 | // EABI is used. |
| 307 | static bool ArmUsingHardFloat(); |
| 308 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 309 | // Support runtime detection of FPU on MIPS CPUs. |
| 310 | static bool MipsCpuHasFeature(CpuFeature feature); |
| 311 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 312 | // Returns the activation frame alignment constraint or zero if |
| 313 | // the platform doesn't care. Guaranteed to be a power of two. |
| 314 | static int ActivationFrameAlignment(); |
| 315 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 316 | static void ReleaseStore(volatile AtomicWord* ptr, AtomicWord value); |
| 317 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 318 | #if defined(V8_TARGET_ARCH_IA32) |
| 319 | // Copy memory area to disjoint memory area. |
| 320 | static void MemCopy(void* dest, const void* src, size_t size); |
| 321 | // Limit below which the extra overhead of the MemCopy function is likely |
| 322 | // to outweigh the benefits of faster copying. |
| 323 | static const int kMinComplexMemCopy = 64; |
| 324 | typedef void (*MemCopyFunction)(void* dest, const void* src, size_t size); |
| 325 | |
| 326 | #else // V8_TARGET_ARCH_IA32 |
| 327 | static void MemCopy(void* dest, const void* src, size_t size) { |
| 328 | memcpy(dest, src, size); |
| 329 | } |
| 330 | static const int kMinComplexMemCopy = 256; |
| 331 | #endif // V8_TARGET_ARCH_IA32 |
| 332 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 333 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 334 | static const int msPerSecond = 1000; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 335 | |
| 336 | DISALLOW_IMPLICIT_CONSTRUCTORS(OS); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 337 | }; |
| 338 | |
| 339 | |
| 340 | class VirtualMemory { |
| 341 | public: |
| 342 | // Reserves virtual memory with size. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 343 | explicit VirtualMemory(size_t size); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 344 | ~VirtualMemory(); |
| 345 | |
| 346 | // Returns whether the memory has been reserved. |
| 347 | bool IsReserved(); |
| 348 | |
| 349 | // Returns the start address of the reserved memory. |
| 350 | void* address() { |
| 351 | ASSERT(IsReserved()); |
| 352 | return address_; |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 353 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 354 | |
| 355 | // Returns the size of the reserved memory. |
| 356 | size_t size() { return size_; } |
| 357 | |
| 358 | // Commits real memory. Returns whether the operation succeeded. |
kasperl@chromium.org | f5aa837 | 2009-03-24 14:47:14 +0000 | [diff] [blame] | 359 | bool Commit(void* address, size_t size, bool is_executable); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 360 | |
| 361 | // Uncommit real memory. Returns whether the operation succeeded. |
| 362 | bool Uncommit(void* address, size_t size); |
| 363 | |
| 364 | private: |
| 365 | void* address_; // Start address of the virtual memory. |
| 366 | size_t size_; // Size of the virtual memory. |
| 367 | }; |
| 368 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 369 | // ---------------------------------------------------------------------------- |
| 370 | // Thread |
| 371 | // |
| 372 | // Thread objects are used for creating and running threads. When the start() |
| 373 | // method is called the new thread starts running the run() method in the new |
| 374 | // thread. The Thread object should not be deallocated before the thread has |
| 375 | // terminated. |
| 376 | |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 377 | class Thread { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 378 | public: |
| 379 | // Opaque data type for thread-local storage keys. |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 380 | // LOCAL_STORAGE_KEY_MIN_VALUE and LOCAL_STORAGE_KEY_MAX_VALUE are specified |
| 381 | // to ensure that enumeration type has correct value range (see Issue 830 for |
| 382 | // more details). |
| 383 | enum LocalStorageKey { |
| 384 | LOCAL_STORAGE_KEY_MIN_VALUE = kMinInt, |
| 385 | LOCAL_STORAGE_KEY_MAX_VALUE = kMaxInt |
| 386 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 387 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 388 | struct Options { |
| 389 | Options() : name("v8:<unknown>"), stack_size(0) {} |
| 390 | |
| 391 | const char* name; |
| 392 | int stack_size; |
| 393 | }; |
| 394 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 395 | // Create new thread. |
| 396 | explicit Thread(const Options& options); |
| 397 | explicit Thread(const char* name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 398 | virtual ~Thread(); |
| 399 | |
| 400 | // Start new thread by calling the Run() method in the new thread. |
| 401 | void Start(); |
| 402 | |
| 403 | // Wait until thread terminates. |
| 404 | void Join(); |
| 405 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 406 | inline const char* name() const { |
| 407 | return name_; |
| 408 | } |
| 409 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 410 | // Abstract method for run handler. |
| 411 | virtual void Run() = 0; |
| 412 | |
| 413 | // Thread-local storage. |
| 414 | static LocalStorageKey CreateThreadLocalKey(); |
| 415 | static void DeleteThreadLocalKey(LocalStorageKey key); |
| 416 | static void* GetThreadLocal(LocalStorageKey key); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 417 | static int GetThreadLocalInt(LocalStorageKey key) { |
| 418 | return static_cast<int>(reinterpret_cast<intptr_t>(GetThreadLocal(key))); |
| 419 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 420 | static void SetThreadLocal(LocalStorageKey key, void* value); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 421 | static void SetThreadLocalInt(LocalStorageKey key, int value) { |
| 422 | SetThreadLocal(key, reinterpret_cast<void*>(static_cast<intptr_t>(value))); |
| 423 | } |
| 424 | static bool HasThreadLocal(LocalStorageKey key) { |
| 425 | return GetThreadLocal(key) != NULL; |
| 426 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 427 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 428 | #ifdef V8_FAST_TLS_SUPPORTED |
| 429 | static inline void* GetExistingThreadLocal(LocalStorageKey key) { |
| 430 | void* result = reinterpret_cast<void*>( |
| 431 | InternalGetExistingThreadLocal(static_cast<intptr_t>(key))); |
| 432 | ASSERT(result == GetThreadLocal(key)); |
| 433 | return result; |
| 434 | } |
| 435 | #else |
| 436 | static inline void* GetExistingThreadLocal(LocalStorageKey key) { |
| 437 | return GetThreadLocal(key); |
| 438 | } |
| 439 | #endif |
| 440 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 441 | // A hint to the scheduler to let another thread run. |
| 442 | static void YieldCPU(); |
| 443 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 444 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 445 | // The thread name length is limited to 16 based on Linux's implementation of |
| 446 | // prctl(). |
| 447 | static const int kMaxThreadNameLength = 16; |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 448 | |
| 449 | class PlatformData; |
| 450 | PlatformData* data() { return data_; } |
| 451 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 452 | private: |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 453 | void set_name(const char *name); |
| 454 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 455 | PlatformData* data_; |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 456 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 457 | char name_[kMaxThreadNameLength]; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 458 | int stack_size_; |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 459 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 460 | DISALLOW_COPY_AND_ASSIGN(Thread); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 461 | }; |
| 462 | |
| 463 | |
| 464 | // ---------------------------------------------------------------------------- |
| 465 | // Mutex |
| 466 | // |
| 467 | // Mutexes are used for serializing access to non-reentrant sections of code. |
| 468 | // The implementations of mutex should allow for nested/recursive locking. |
| 469 | |
| 470 | class Mutex { |
| 471 | public: |
| 472 | virtual ~Mutex() {} |
| 473 | |
| 474 | // Locks the given mutex. If the mutex is currently unlocked, it becomes |
| 475 | // locked and owned by the calling thread, and immediately. If the mutex |
| 476 | // is already locked by another thread, suspends the calling thread until |
| 477 | // the mutex is unlocked. |
| 478 | virtual int Lock() = 0; |
| 479 | |
| 480 | // Unlocks the given mutex. The mutex is assumed to be locked and owned by |
| 481 | // the calling thread on entrance. |
| 482 | virtual int Unlock() = 0; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 483 | |
| 484 | // Tries to lock the given mutex. Returns whether the mutex was |
| 485 | // successfully locked. |
| 486 | virtual bool TryLock() = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 487 | }; |
| 488 | |
| 489 | |
| 490 | // ---------------------------------------------------------------------------- |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 491 | // ScopedLock |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 492 | // |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 493 | // Stack-allocated ScopedLocks provide block-scoped locking and |
| 494 | // unlocking of a mutex. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 495 | class ScopedLock { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 496 | public: |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 497 | explicit ScopedLock(Mutex* mutex): mutex_(mutex) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 498 | ASSERT(mutex_ != NULL); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 499 | mutex_->Lock(); |
| 500 | } |
| 501 | ~ScopedLock() { |
| 502 | mutex_->Unlock(); |
| 503 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 504 | |
| 505 | private: |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 506 | Mutex* mutex_; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 507 | DISALLOW_COPY_AND_ASSIGN(ScopedLock); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 508 | }; |
| 509 | |
| 510 | |
| 511 | // ---------------------------------------------------------------------------- |
| 512 | // Semaphore |
| 513 | // |
| 514 | // A semaphore object is a synchronization object that maintains a count. The |
| 515 | // count is decremented each time a thread completes a wait for the semaphore |
| 516 | // object and incremented each time a thread signals the semaphore. When the |
| 517 | // count reaches zero, threads waiting for the semaphore blocks until the |
| 518 | // count becomes non-zero. |
| 519 | |
| 520 | class Semaphore { |
| 521 | public: |
| 522 | virtual ~Semaphore() {} |
| 523 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 524 | // Suspends the calling thread until the semaphore counter is non zero |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 525 | // and then decrements the semaphore counter. |
| 526 | virtual void Wait() = 0; |
| 527 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 528 | // Suspends the calling thread until the counter is non zero or the timeout |
| 529 | // time has passsed. If timeout happens the return value is false and the |
| 530 | // counter is unchanged. Otherwise the semaphore counter is decremented and |
| 531 | // true is returned. The timeout value is specified in microseconds. |
| 532 | virtual bool Wait(int timeout) = 0; |
| 533 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 534 | // Increments the semaphore counter. |
| 535 | virtual void Signal() = 0; |
| 536 | }; |
| 537 | |
| 538 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 539 | // ---------------------------------------------------------------------------- |
| 540 | // Socket |
| 541 | // |
| 542 | |
| 543 | class Socket { |
| 544 | public: |
| 545 | virtual ~Socket() {} |
| 546 | |
| 547 | // Server initialization. |
| 548 | virtual bool Bind(const int port) = 0; |
| 549 | virtual bool Listen(int backlog) const = 0; |
| 550 | virtual Socket* Accept() const = 0; |
| 551 | |
| 552 | // Client initialization. |
| 553 | virtual bool Connect(const char* host, const char* port) = 0; |
| 554 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 555 | // Shutdown socket for both read and write. This causes blocking Send and |
| 556 | // Receive calls to exit. After Shutdown the Socket object cannot be used for |
| 557 | // any communication. |
| 558 | virtual bool Shutdown() = 0; |
| 559 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 560 | // Data Transimission |
| 561 | virtual int Send(const char* data, int len) const = 0; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 562 | virtual int Receive(char* data, int len) const = 0; |
| 563 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 564 | // Set the value of the SO_REUSEADDR socket option. |
| 565 | virtual bool SetReuseAddress(bool reuse_address) = 0; |
| 566 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 567 | virtual bool IsValid() const = 0; |
| 568 | |
| 569 | static bool Setup(); |
| 570 | static int LastError(); |
| 571 | static uint16_t HToN(uint16_t value); |
| 572 | static uint16_t NToH(uint16_t value); |
| 573 | static uint32_t HToN(uint32_t value); |
| 574 | static uint32_t NToH(uint32_t value); |
| 575 | }; |
| 576 | |
| 577 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 578 | // ---------------------------------------------------------------------------- |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 579 | // Sampler |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 580 | // |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 581 | // A sampler periodically samples the state of the VM and optionally |
| 582 | // (if used for profiling) the program counter and stack pointer for |
| 583 | // the thread that created it. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 584 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 585 | // TickSample captures the information collected for each sample. |
| 586 | class TickSample { |
| 587 | public: |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 588 | TickSample() |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 589 | : state(OTHER), |
| 590 | pc(NULL), |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 591 | sp(NULL), |
| 592 | fp(NULL), |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 593 | tos(NULL), |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 594 | frames_count(0), |
| 595 | has_external_callback(false) {} |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 596 | StateTag state; // The state of the VM. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 597 | Address pc; // Instruction pointer. |
| 598 | Address sp; // Stack pointer. |
| 599 | Address fp; // Frame pointer. |
| 600 | union { |
| 601 | Address tos; // Top stack value (*sp). |
| 602 | Address external_callback; |
| 603 | }; |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 604 | static const int kMaxFramesCount = 64; |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 605 | Address stack[kMaxFramesCount]; // Call stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 606 | int frames_count : 8; // Number of captured frames. |
| 607 | bool has_external_callback : 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 608 | }; |
| 609 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 610 | class Sampler { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 611 | public: |
| 612 | // Initialize sampler. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 613 | Sampler(Isolate* isolate, int interval); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 614 | virtual ~Sampler(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 615 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 616 | int interval() const { return interval_; } |
| 617 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 618 | // Performs stack sampling. |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 619 | void SampleStack(TickSample* sample) { |
| 620 | DoSampleStack(sample); |
| 621 | IncSamplesTaken(); |
| 622 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 623 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 624 | // This method is called for each sampling period with the current |
| 625 | // program counter. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 626 | virtual void Tick(TickSample* sample) = 0; |
| 627 | |
| 628 | // Start and stop sampler. |
| 629 | void Start(); |
| 630 | void Stop(); |
| 631 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 632 | // Is the sampler used for profiling? |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 633 | bool IsProfiling() const { return NoBarrier_Load(&profiling_) > 0; } |
| 634 | void IncreaseProfilingDepth() { NoBarrier_AtomicIncrement(&profiling_, 1); } |
| 635 | void DecreaseProfilingDepth() { NoBarrier_AtomicIncrement(&profiling_, -1); } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 636 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 637 | // Whether the sampler is running (that is, consumes resources). |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 638 | bool IsActive() const { return NoBarrier_Load(&active_); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 639 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 640 | Isolate* isolate() { return isolate_; } |
| 641 | |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 642 | // Used in tests to make sure that stack sampling is performed. |
| 643 | int samples_taken() const { return samples_taken_; } |
| 644 | void ResetSamplesTaken() { samples_taken_ = 0; } |
| 645 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 646 | class PlatformData; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 647 | PlatformData* data() { return data_; } |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 648 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 649 | PlatformData* platform_data() { return data_; } |
| 650 | |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 651 | protected: |
| 652 | virtual void DoSampleStack(TickSample* sample) = 0; |
| 653 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 654 | private: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 655 | void SetActive(bool value) { NoBarrier_Store(&active_, value); } |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 656 | void IncSamplesTaken() { if (++samples_taken_ < 0) samples_taken_ = 0; } |
| 657 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 658 | Isolate* isolate_; |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 659 | const int interval_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 660 | Atomic32 profiling_; |
| 661 | Atomic32 active_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 662 | PlatformData* data_; // Platform specific data. |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 663 | int samples_taken_; // Counts stack samples taken. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 664 | DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 665 | }; |
| 666 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 667 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 668 | } } // namespace v8::internal |
| 669 | |
| 670 | #endif // V8_PLATFORM_H_ |