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" | |
29 #include "src/base/build_config.h" | 28 #include "src/base/build_config.h" |
30 #include "src/base/compiler-specific.h" | 29 #include "src/base/compiler-specific.h" |
31 #include "src/base/platform/mutex.h" | 30 #include "src/base/platform/mutex.h" |
32 #include "src/base/platform/semaphore.h" | 31 #include "src/base/platform/semaphore.h" |
33 | 32 |
34 #if V8_OS_QNX | 33 #if V8_OS_QNX |
35 #include "src/base/qnx-math.h" | 34 #include "src/base/qnx-math.h" |
36 #endif | 35 #endif |
37 | 36 |
38 namespace v8 { | 37 namespace v8 { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 class TimezoneCache; | 95 class TimezoneCache; |
97 | 96 |
98 | 97 |
99 // ---------------------------------------------------------------------------- | 98 // ---------------------------------------------------------------------------- |
100 // OS | 99 // OS |
101 // | 100 // |
102 // This class has static methods for the different platform specific | 101 // This class has static methods for the different platform specific |
103 // functions. Add methods here to cope with differences between the | 102 // functions. Add methods here to cope with differences between the |
104 // supported platforms. | 103 // supported platforms. |
105 | 104 |
106 class V8_BASE_EXPORT OS { | 105 class OS { |
107 public: | 106 public: |
108 // Initialize the OS class. | 107 // Initialize the OS class. |
109 // - random_seed: Used for the GetRandomMmapAddress() if non-zero. | 108 // - random_seed: Used for the GetRandomMmapAddress() if non-zero. |
110 // - hard_abort: If true, OS::Abort() will crash instead of aborting. | 109 // - hard_abort: If true, OS::Abort() will crash instead of aborting. |
111 // - gc_fake_mmap: Name of the file for fake gc mmap used in ll_prof. | 110 // - gc_fake_mmap: Name of the file for fake gc mmap used in ll_prof. |
112 static void Initialize(int64_t random_seed, | 111 static void Initialize(int64_t random_seed, |
113 bool hard_abort, | 112 bool hard_abort, |
114 const char* const gc_fake_mmap); | 113 const char* const gc_fake_mmap); |
115 | 114 |
116 // Returns the accumulated user time for thread. This routine | 115 // Returns the accumulated user time for thread. This routine |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 204 |
206 // Walk the stack. | 205 // Walk the stack. |
207 static const int kStackWalkError = -1; | 206 static const int kStackWalkError = -1; |
208 static const int kStackWalkMaxNameLen = 256; | 207 static const int kStackWalkMaxNameLen = 256; |
209 static const int kStackWalkMaxTextLen = 256; | 208 static const int kStackWalkMaxTextLen = 256; |
210 struct StackFrame { | 209 struct StackFrame { |
211 void* address; | 210 void* address; |
212 char text[kStackWalkMaxTextLen]; | 211 char text[kStackWalkMaxTextLen]; |
213 }; | 212 }; |
214 | 213 |
215 class V8_BASE_EXPORT MemoryMappedFile { | 214 class MemoryMappedFile { |
216 public: | 215 public: |
217 virtual ~MemoryMappedFile() {} | 216 virtual ~MemoryMappedFile() {} |
218 virtual void* memory() const = 0; | 217 virtual void* memory() const = 0; |
219 virtual size_t size() const = 0; | 218 virtual size_t size() const = 0; |
220 | 219 |
221 static MemoryMappedFile* open(const char* name); | 220 static MemoryMappedFile* open(const char* name); |
222 static MemoryMappedFile* create(const char* name, size_t size, | 221 static MemoryMappedFile* create(const char* name, size_t size, |
223 void* initial); | 222 void* initial); |
224 }; | 223 }; |
225 | 224 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 #endif | 279 #endif |
281 | 280 |
282 DISALLOW_IMPLICIT_CONSTRUCTORS(OS); | 281 DISALLOW_IMPLICIT_CONSTRUCTORS(OS); |
283 }; | 282 }; |
284 | 283 |
285 | 284 |
286 // Represents and controls an area of reserved memory. | 285 // Represents and controls an area of reserved memory. |
287 // Control of the reserved memory can be assigned to another VirtualMemory | 286 // Control of the reserved memory can be assigned to another VirtualMemory |
288 // object by assignment or copy-contructing. This removes the reserved memory | 287 // object by assignment or copy-contructing. This removes the reserved memory |
289 // from the original object. | 288 // from the original object. |
290 class V8_BASE_EXPORT VirtualMemory { | 289 class VirtualMemory { |
291 public: | 290 public: |
292 // Empty VirtualMemory object, controlling no reserved memory. | 291 // Empty VirtualMemory object, controlling no reserved memory. |
293 VirtualMemory(); | 292 VirtualMemory(); |
294 | 293 |
295 // Reserves virtual memory with size. | 294 // Reserves virtual memory with size. |
296 explicit VirtualMemory(size_t size); | 295 explicit VirtualMemory(size_t size); |
297 | 296 |
298 // Reserves virtual memory containing an area of the given size that | 297 // Reserves virtual memory containing an area of the given size that |
299 // is aligned per alignment. This may not be at the position returned | 298 // is aligned per alignment. This may not be at the position returned |
300 // by address(). | 299 // by address(). |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 | 411 |
413 | 412 |
414 // ---------------------------------------------------------------------------- | 413 // ---------------------------------------------------------------------------- |
415 // Thread | 414 // Thread |
416 // | 415 // |
417 // Thread objects are used for creating and running threads. When the start() | 416 // Thread objects are used for creating and running threads. When the start() |
418 // method is called the new thread starts running the run() method in the new | 417 // method is called the new thread starts running the run() method in the new |
419 // thread. The Thread object should not be deallocated before the thread has | 418 // thread. The Thread object should not be deallocated before the thread has |
420 // terminated. | 419 // terminated. |
421 | 420 |
422 class V8_BASE_EXPORT Thread { | 421 class Thread { |
423 public: | 422 public: |
424 // Opaque data type for thread-local storage keys. | 423 // Opaque data type for thread-local storage keys. |
425 typedef int32_t LocalStorageKey; | 424 typedef int32_t LocalStorageKey; |
426 | 425 |
427 class Options { | 426 class Options { |
428 public: | 427 public: |
429 Options() : name_("v8:<unknown>"), stack_size_(0) {} | 428 Options() : name_("v8:<unknown>"), stack_size_(0) {} |
430 explicit Options(const char* name, int stack_size = 0) | 429 explicit Options(const char* name, int stack_size = 0) |
431 : name_(name), stack_size_(stack_size) {} | 430 : name_(name), stack_size_(stack_size) {} |
432 | 431 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 int stack_size_; | 512 int stack_size_; |
514 Semaphore* start_semaphore_; | 513 Semaphore* start_semaphore_; |
515 | 514 |
516 DISALLOW_COPY_AND_ASSIGN(Thread); | 515 DISALLOW_COPY_AND_ASSIGN(Thread); |
517 }; | 516 }; |
518 | 517 |
519 } // namespace base | 518 } // namespace base |
520 } // namespace v8 | 519 } // namespace v8 |
521 | 520 |
522 #endif // V8_BASE_PLATFORM_PLATFORM_H_ | 521 #endif // V8_BASE_PLATFORM_PLATFORM_H_ |
OLD | NEW |