| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This module contains the platform-specific code. This make the rest of the | 5 // This module contains the platform-specific code. This make the rest of the |
| 6 // code less dependent on operating system, compilers and runtime libraries. | 6 // code less dependent on operating system, compilers and runtime libraries. |
| 7 // This module does specifically not deal with differences between different | 7 // This module does specifically not deal with differences between different |
| 8 // processor architecture. | 8 // processor architecture. |
| 9 // The platform classes have the same definition for all platforms. The | 9 // The platform classes have the same definition for all platforms. The |
| 10 // implementation for a particular platform is put in platform_<os>.cc. | 10 // implementation for a particular platform is put in platform_<os>.cc. |
| 11 // The build system then uses the implementation for the target platform. | 11 // The build system then uses the implementation for the target platform. |
| 12 // | 12 // |
| 13 // This design has been chosen because it is simple and fast. Alternatively, | 13 // This design has been chosen because it is simple and fast. Alternatively, |
| 14 // the platform dependent classes could have been implemented using abstract | 14 // the platform dependent classes could have been implemented using abstract |
| 15 // superclasses with virtual methods and having specializations for each | 15 // superclasses with virtual methods and having specializations for each |
| 16 // platform. This design was rejected because it was more complicated and | 16 // platform. This design was rejected because it was more complicated and |
| 17 // slower. It would require factory methods for selecting the right | 17 // slower. It would require factory methods for selecting the right |
| 18 // implementation and the overhead of virtual methods for performance | 18 // implementation and the overhead of virtual methods for performance |
| 19 // sensitive like mutex locking/unlocking. | 19 // sensitive like mutex locking/unlocking. |
| 20 | 20 |
| 21 #ifndef V8_BASE_PLATFORM_PLATFORM_H_ | 21 #ifndef V8_BASE_PLATFORM_PLATFORM_H_ |
| 22 #define V8_BASE_PLATFORM_PLATFORM_H_ | 22 #define V8_BASE_PLATFORM_PLATFORM_H_ |
| 23 | 23 |
| 24 #include <cstdarg> | 24 #include <cstdarg> |
| 25 #include <string> | 25 #include <string> |
| 26 #include <vector> | 26 #include <vector> |
| 27 | 27 |
| 28 #include "src/base/base-export.h" |
| 28 #include "src/base/build_config.h" | 29 #include "src/base/build_config.h" |
| 29 #include "src/base/compiler-specific.h" | 30 #include "src/base/compiler-specific.h" |
| 30 #include "src/base/platform/mutex.h" | 31 #include "src/base/platform/mutex.h" |
| 31 #include "src/base/platform/semaphore.h" | 32 #include "src/base/platform/semaphore.h" |
| 32 | 33 |
| 33 #if V8_OS_QNX | 34 #if V8_OS_QNX |
| 34 #include "src/base/qnx-math.h" | 35 #include "src/base/qnx-math.h" |
| 35 #endif | 36 #endif |
| 36 | 37 |
| 37 namespace v8 { | 38 namespace v8 { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 62 intptr_t extra = static_cast<intptr_t>(__readfsdword(kTibExtraTlsOffset)); | 63 intptr_t extra = static_cast<intptr_t>(__readfsdword(kTibExtraTlsOffset)); |
| 63 DCHECK(extra != 0); | 64 DCHECK(extra != 0); |
| 64 return *reinterpret_cast<intptr_t*>(extra + | 65 return *reinterpret_cast<intptr_t*>(extra + |
| 65 kPointerSize * (index - kMaxInlineSlots)); | 66 kPointerSize * (index - kMaxInlineSlots)); |
| 66 } | 67 } |
| 67 | 68 |
| 68 #elif defined(__APPLE__) && (V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64) | 69 #elif defined(__APPLE__) && (V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64) |
| 69 | 70 |
| 70 #define V8_FAST_TLS_SUPPORTED 1 | 71 #define V8_FAST_TLS_SUPPORTED 1 |
| 71 | 72 |
| 72 extern intptr_t kMacTlsBaseOffset; | 73 extern V8_BASE_EXPORT intptr_t kMacTlsBaseOffset; |
| 73 | 74 |
| 74 INLINE(intptr_t InternalGetExistingThreadLocal(intptr_t index)); | 75 INLINE(intptr_t InternalGetExistingThreadLocal(intptr_t index)); |
| 75 | 76 |
| 76 inline intptr_t InternalGetExistingThreadLocal(intptr_t index) { | 77 inline intptr_t InternalGetExistingThreadLocal(intptr_t index) { |
| 77 intptr_t result; | 78 intptr_t result; |
| 78 #if V8_HOST_ARCH_IA32 | 79 #if V8_HOST_ARCH_IA32 |
| 79 asm("movl %%gs:(%1,%2,4), %0;" | 80 asm("movl %%gs:(%1,%2,4), %0;" |
| 80 :"=r"(result) // Output must be a writable register. | 81 :"=r"(result) // Output must be a writable register. |
| 81 :"r"(kMacTlsBaseOffset), "r"(index)); | 82 :"r"(kMacTlsBaseOffset), "r"(index)); |
| 82 #else | 83 #else |
| (...skipping 12 matching lines...) Expand all Loading... |
| 95 class TimezoneCache; | 96 class TimezoneCache; |
| 96 | 97 |
| 97 | 98 |
| 98 // ---------------------------------------------------------------------------- | 99 // ---------------------------------------------------------------------------- |
| 99 // OS | 100 // OS |
| 100 // | 101 // |
| 101 // This class has static methods for the different platform specific | 102 // This class has static methods for the different platform specific |
| 102 // functions. Add methods here to cope with differences between the | 103 // functions. Add methods here to cope with differences between the |
| 103 // supported platforms. | 104 // supported platforms. |
| 104 | 105 |
| 105 class OS { | 106 class V8_BASE_EXPORT OS { |
| 106 public: | 107 public: |
| 107 // Initialize the OS class. | 108 // Initialize the OS class. |
| 108 // - random_seed: Used for the GetRandomMmapAddress() if non-zero. | 109 // - random_seed: Used for the GetRandomMmapAddress() if non-zero. |
| 109 // - hard_abort: If true, OS::Abort() will crash instead of aborting. | 110 // - hard_abort: If true, OS::Abort() will crash instead of aborting. |
| 110 // - gc_fake_mmap: Name of the file for fake gc mmap used in ll_prof. | 111 // - gc_fake_mmap: Name of the file for fake gc mmap used in ll_prof. |
| 111 static void Initialize(int64_t random_seed, | 112 static void Initialize(int64_t random_seed, |
| 112 bool hard_abort, | 113 bool hard_abort, |
| 113 const char* const gc_fake_mmap); | 114 const char* const gc_fake_mmap); |
| 114 | 115 |
| 115 // Returns the accumulated user time for thread. This routine | 116 // Returns the accumulated user time for thread. This routine |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 205 |
| 205 // Walk the stack. | 206 // Walk the stack. |
| 206 static const int kStackWalkError = -1; | 207 static const int kStackWalkError = -1; |
| 207 static const int kStackWalkMaxNameLen = 256; | 208 static const int kStackWalkMaxNameLen = 256; |
| 208 static const int kStackWalkMaxTextLen = 256; | 209 static const int kStackWalkMaxTextLen = 256; |
| 209 struct StackFrame { | 210 struct StackFrame { |
| 210 void* address; | 211 void* address; |
| 211 char text[kStackWalkMaxTextLen]; | 212 char text[kStackWalkMaxTextLen]; |
| 212 }; | 213 }; |
| 213 | 214 |
| 214 class MemoryMappedFile { | 215 class V8_BASE_EXPORT MemoryMappedFile { |
| 215 public: | 216 public: |
| 216 virtual ~MemoryMappedFile() {} | 217 virtual ~MemoryMappedFile() {} |
| 217 virtual void* memory() const = 0; | 218 virtual void* memory() const = 0; |
| 218 virtual size_t size() const = 0; | 219 virtual size_t size() const = 0; |
| 219 | 220 |
| 220 static MemoryMappedFile* open(const char* name); | 221 static MemoryMappedFile* open(const char* name); |
| 221 static MemoryMappedFile* create(const char* name, size_t size, | 222 static MemoryMappedFile* create(const char* name, size_t size, |
| 222 void* initial); | 223 void* initial); |
| 223 }; | 224 }; |
| 224 | 225 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 #endif | 280 #endif |
| 280 | 281 |
| 281 DISALLOW_IMPLICIT_CONSTRUCTORS(OS); | 282 DISALLOW_IMPLICIT_CONSTRUCTORS(OS); |
| 282 }; | 283 }; |
| 283 | 284 |
| 284 | 285 |
| 285 // Represents and controls an area of reserved memory. | 286 // Represents and controls an area of reserved memory. |
| 286 // Control of the reserved memory can be assigned to another VirtualMemory | 287 // Control of the reserved memory can be assigned to another VirtualMemory |
| 287 // object by assignment or copy-contructing. This removes the reserved memory | 288 // object by assignment or copy-contructing. This removes the reserved memory |
| 288 // from the original object. | 289 // from the original object. |
| 289 class VirtualMemory { | 290 class V8_BASE_EXPORT VirtualMemory { |
| 290 public: | 291 public: |
| 291 // Empty VirtualMemory object, controlling no reserved memory. | 292 // Empty VirtualMemory object, controlling no reserved memory. |
| 292 VirtualMemory(); | 293 VirtualMemory(); |
| 293 | 294 |
| 294 // Reserves virtual memory with size. | 295 // Reserves virtual memory with size. |
| 295 explicit VirtualMemory(size_t size); | 296 explicit VirtualMemory(size_t size); |
| 296 | 297 |
| 297 // Reserves virtual memory containing an area of the given size that | 298 // Reserves virtual memory containing an area of the given size that |
| 298 // is aligned per alignment. This may not be at the position returned | 299 // is aligned per alignment. This may not be at the position returned |
| 299 // by address(). | 300 // by address(). |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 | 412 |
| 412 | 413 |
| 413 // ---------------------------------------------------------------------------- | 414 // ---------------------------------------------------------------------------- |
| 414 // Thread | 415 // Thread |
| 415 // | 416 // |
| 416 // Thread objects are used for creating and running threads. When the start() | 417 // Thread objects are used for creating and running threads. When the start() |
| 417 // method is called the new thread starts running the run() method in the new | 418 // method is called the new thread starts running the run() method in the new |
| 418 // thread. The Thread object should not be deallocated before the thread has | 419 // thread. The Thread object should not be deallocated before the thread has |
| 419 // terminated. | 420 // terminated. |
| 420 | 421 |
| 421 class Thread { | 422 class V8_BASE_EXPORT Thread { |
| 422 public: | 423 public: |
| 423 // Opaque data type for thread-local storage keys. | 424 // Opaque data type for thread-local storage keys. |
| 424 typedef int32_t LocalStorageKey; | 425 typedef int32_t LocalStorageKey; |
| 425 | 426 |
| 426 class Options { | 427 class Options { |
| 427 public: | 428 public: |
| 428 Options() : name_("v8:<unknown>"), stack_size_(0) {} | 429 Options() : name_("v8:<unknown>"), stack_size_(0) {} |
| 429 explicit Options(const char* name, int stack_size = 0) | 430 explicit Options(const char* name, int stack_size = 0) |
| 430 : name_(name), stack_size_(stack_size) {} | 431 : name_(name), stack_size_(stack_size) {} |
| 431 | 432 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 int stack_size_; | 513 int stack_size_; |
| 513 Semaphore* start_semaphore_; | 514 Semaphore* start_semaphore_; |
| 514 | 515 |
| 515 DISALLOW_COPY_AND_ASSIGN(Thread); | 516 DISALLOW_COPY_AND_ASSIGN(Thread); |
| 516 }; | 517 }; |
| 517 | 518 |
| 518 } // namespace base | 519 } // namespace base |
| 519 } // namespace v8 | 520 } // namespace v8 |
| 520 | 521 |
| 521 #endif // V8_BASE_PLATFORM_PLATFORM_H_ | 522 #endif // V8_BASE_PLATFORM_PLATFORM_H_ |
| OLD | NEW |