| 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. |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 private: | 265 private: |
| 266 static const int msPerSecond = 1000; | 266 static const int msPerSecond = 1000; |
| 267 | 267 |
| 268 #if V8_OS_POSIX | 268 #if V8_OS_POSIX |
| 269 static const char* GetGCFakeMMapFile(); | 269 static const char* GetGCFakeMMapFile(); |
| 270 #endif | 270 #endif |
| 271 | 271 |
| 272 DISALLOW_IMPLICIT_CONSTRUCTORS(OS); | 272 DISALLOW_IMPLICIT_CONSTRUCTORS(OS); |
| 273 }; | 273 }; |
| 274 | 274 |
| 275 |
| 275 // Represents and controls an area of reserved memory. | 276 // Represents and controls an area of reserved memory. |
| 276 // Control of the reserved memory can be assigned to another VirtualMemory | 277 // Control of the reserved memory can be assigned to another VirtualMemory |
| 277 // object by assignment or copy-contructing. This removes the reserved memory | 278 // object by assignment or copy-contructing. This removes the reserved memory |
| 278 // from the original object. | 279 // from the original object. |
| 279 class VirtualMemory { | 280 class VirtualMemory { |
| 280 public: | 281 public: |
| 281 // Empty VirtualMemory object, controlling no reserved memory. | 282 // Empty VirtualMemory object, controlling no reserved memory. |
| 282 VirtualMemory(); | 283 VirtualMemory(); |
| 283 | 284 |
| 284 // Reserves virtual memory with size. | 285 // Reserves virtual memory with size. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 | 323 |
| 323 // Creates a single guard page at the given address. | 324 // Creates a single guard page at the given address. |
| 324 bool Guard(void* address); | 325 bool Guard(void* address); |
| 325 | 326 |
| 326 void Release() { | 327 void Release() { |
| 327 DCHECK(IsReserved()); | 328 DCHECK(IsReserved()); |
| 328 // Notice: Order is important here. The VirtualMemory object might live | 329 // Notice: Order is important here. The VirtualMemory object might live |
| 329 // inside the allocated region. | 330 // inside the allocated region. |
| 330 void* address = address_; | 331 void* address = address_; |
| 331 size_t size = size_; | 332 size_t size = size_; |
| 333 CHECK(InVM(address, size)); |
| 332 Reset(); | 334 Reset(); |
| 333 bool result = ReleaseRegion(address, size); | 335 bool result = ReleaseRegion(address, size); |
| 334 USE(result); | 336 USE(result); |
| 335 DCHECK(result); | 337 DCHECK(result); |
| 336 } | 338 } |
| 337 | 339 |
| 338 // Assign control of the reserved region to a different VirtualMemory object. | 340 // Assign control of the reserved region to a different VirtualMemory object. |
| 339 // The old object is no longer functional (IsReserved() returns false). | 341 // The old object is no longer functional (IsReserved() returns false). |
| 340 void TakeControl(VirtualMemory* from) { | 342 void TakeControl(VirtualMemory* from) { |
| 341 DCHECK(!IsReserved()); | 343 DCHECK(!IsReserved()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 353 // Must be called with a base pointer that has been returned by ReserveRegion | 355 // Must be called with a base pointer that has been returned by ReserveRegion |
| 354 // and the same size it was reserved with. | 356 // and the same size it was reserved with. |
| 355 static bool ReleaseRegion(void* base, size_t size); | 357 static bool ReleaseRegion(void* base, size_t size); |
| 356 | 358 |
| 357 // Returns true if OS performs lazy commits, i.e. the memory allocation call | 359 // Returns true if OS performs lazy commits, i.e. the memory allocation call |
| 358 // defers actual physical memory allocation till the first memory access. | 360 // defers actual physical memory allocation till the first memory access. |
| 359 // Otherwise returns false. | 361 // Otherwise returns false. |
| 360 static bool HasLazyCommits(); | 362 static bool HasLazyCommits(); |
| 361 | 363 |
| 362 private: | 364 private: |
| 365 bool InVM(void* address, size_t size) { |
| 366 return (reinterpret_cast<intptr_t>(address_) <= |
| 367 reinterpret_cast<intptr_t>(address)) && |
| 368 (reinterpret_cast<intptr_t>(address_) + size_ >= |
| 369 reinterpret_cast<intptr_t>(address) + size); |
| 370 } |
| 371 |
| 363 void* address_; // Start address of the virtual memory. | 372 void* address_; // Start address of the virtual memory. |
| 364 size_t size_; // Size of the virtual memory. | 373 size_t size_; // Size of the virtual memory. |
| 365 }; | 374 }; |
| 366 | 375 |
| 367 | 376 |
| 368 // ---------------------------------------------------------------------------- | 377 // ---------------------------------------------------------------------------- |
| 369 // Thread | 378 // Thread |
| 370 // | 379 // |
| 371 // Thread objects are used for creating and running threads. When the start() | 380 // Thread objects are used for creating and running threads. When the start() |
| 372 // method is called the new thread starts running the run() method in the new | 381 // method is called the new thread starts running the run() method in the new |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 char name_[kMaxThreadNameLength]; | 475 char name_[kMaxThreadNameLength]; |
| 467 int stack_size_; | 476 int stack_size_; |
| 468 Semaphore* start_semaphore_; | 477 Semaphore* start_semaphore_; |
| 469 | 478 |
| 470 DISALLOW_COPY_AND_ASSIGN(Thread); | 479 DISALLOW_COPY_AND_ASSIGN(Thread); |
| 471 }; | 480 }; |
| 472 | 481 |
| 473 } } // namespace v8::base | 482 } } // namespace v8::base |
| 474 | 483 |
| 475 #endif // V8_BASE_PLATFORM_PLATFORM_H_ | 484 #endif // V8_BASE_PLATFORM_PLATFORM_H_ |
| OLD | NEW |