| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 } | 329 } |
| 330 static const int kMinComplexMemCopy = 256; | 330 static const int kMinComplexMemCopy = 256; |
| 331 #endif // V8_TARGET_ARCH_IA32 | 331 #endif // V8_TARGET_ARCH_IA32 |
| 332 | 332 |
| 333 private: | 333 private: |
| 334 static const int msPerSecond = 1000; | 334 static const int msPerSecond = 1000; |
| 335 | 335 |
| 336 DISALLOW_IMPLICIT_CONSTRUCTORS(OS); | 336 DISALLOW_IMPLICIT_CONSTRUCTORS(OS); |
| 337 }; | 337 }; |
| 338 | 338 |
| 339 | 339 // Represents and controls an area of reserved memory. |
| 340 // Control of the reserved memory can be assigned to another VirtualMemory |
| 341 // object by assignment or copy-contructing. This removes the reserved memory |
| 342 // from the original object. |
| 340 class VirtualMemory { | 343 class VirtualMemory { |
| 341 public: | 344 public: |
| 345 // Empty VirtualMemory object, controlling no reserved memory. |
| 346 VirtualMemory(); |
| 347 |
| 342 // Reserves virtual memory with size. | 348 // Reserves virtual memory with size. |
| 343 explicit VirtualMemory(size_t size); | 349 explicit VirtualMemory(size_t size); |
| 350 |
| 351 // Reserves virtual memory containing an area of the given size that |
| 352 // is aligned per alignment. This may not be at the position returned |
| 353 // by address(). |
| 354 VirtualMemory(size_t size, size_t alignment); |
| 355 |
| 356 // Releases the reserved memory, if any, controlled by this VirtualMemory |
| 357 // object. |
| 344 ~VirtualMemory(); | 358 ~VirtualMemory(); |
| 345 | 359 |
| 346 // Returns whether the memory has been reserved. | 360 // Returns whether the memory has been reserved. |
| 347 bool IsReserved(); | 361 bool IsReserved(); |
| 348 | 362 |
| 363 // Initialize or resets an embedded VirtualMemory object. |
| 364 void Reset(); |
| 365 |
| 349 // Returns the start address of the reserved memory. | 366 // Returns the start address of the reserved memory. |
| 367 // If the memory was reserved with an alignment, this address is not |
| 368 // necessarily aligned. The user might need to round it up to a multiple of |
| 369 // the alignment to get the start of the aligned block. |
| 350 void* address() { | 370 void* address() { |
| 351 ASSERT(IsReserved()); | 371 ASSERT(IsReserved()); |
| 352 return address_; | 372 return address_; |
| 353 } | 373 } |
| 354 | 374 |
| 355 // Returns the size of the reserved memory. | 375 // Returns the size of the reserved memory. The returned value is only |
| 376 // meaningful when IsReserved() returns true. |
| 377 // If the memory was reserved with an alignment, this size may be larger |
| 378 // than the requested size. |
| 356 size_t size() { return size_; } | 379 size_t size() { return size_; } |
| 357 | 380 |
| 358 // Commits real memory. Returns whether the operation succeeded. | 381 // Commits real memory. Returns whether the operation succeeded. |
| 359 bool Commit(void* address, size_t size, bool is_executable); | 382 bool Commit(void* address, size_t size, bool is_executable); |
| 360 | 383 |
| 361 // Uncommit real memory. Returns whether the operation succeeded. | 384 // Uncommit real memory. Returns whether the operation succeeded. |
| 362 bool Uncommit(void* address, size_t size); | 385 bool Uncommit(void* address, size_t size); |
| 363 | 386 |
| 387 void Release() { |
| 388 ASSERT(IsReserved()); |
| 389 // Notice: Order is somportant here. The VirtualMemory object might live |
| 390 // inside the allocated region. |
| 391 void* address = address_; |
| 392 size_t size = size_; |
| 393 Reset(); |
| 394 ReleaseRegion(address, size); |
| 395 } |
| 396 |
| 397 // Assign control of the reserved region to a different VirtualMemory object. |
| 398 // The old object is no longer functional (IsReserved() returns false). |
| 399 void TakeControl(VirtualMemory* from) { |
| 400 ASSERT(!IsReserved()); |
| 401 address_ = from->address_; |
| 402 size_ = from->size_; |
| 403 from->Reset(); |
| 404 } |
| 405 |
| 364 static void* ReserveRegion(size_t size); | 406 static void* ReserveRegion(size_t size); |
| 365 | 407 |
| 366 static bool CommitRegion(void* base, size_t size, bool is_executable); | 408 static bool CommitRegion(void* base, size_t size, bool is_executable); |
| 367 | 409 |
| 368 static bool UncommitRegion(void* base, size_t size); | 410 static bool UncommitRegion(void* base, size_t size); |
| 369 | 411 |
| 412 // Must be called with a base pointer that has been returned by ReserveRegion |
| 413 // and the same size it was reserved with. |
| 370 static bool ReleaseRegion(void* base, size_t size); | 414 static bool ReleaseRegion(void* base, size_t size); |
| 371 | 415 |
| 372 private: | 416 private: |
| 373 void* address_; // Start address of the virtual memory. | 417 void* address_; // Start address of the virtual memory. |
| 374 size_t size_; // Size of the virtual memory. | 418 size_t size_; // Size of the virtual memory. |
| 375 }; | 419 }; |
| 376 | 420 |
| 421 |
| 377 // ---------------------------------------------------------------------------- | 422 // ---------------------------------------------------------------------------- |
| 378 // Thread | 423 // Thread |
| 379 // | 424 // |
| 380 // Thread objects are used for creating and running threads. When the start() | 425 // Thread objects are used for creating and running threads. When the start() |
| 381 // method is called the new thread starts running the run() method in the new | 426 // method is called the new thread starts running the run() method in the new |
| 382 // thread. The Thread object should not be deallocated before the thread has | 427 // thread. The Thread object should not be deallocated before the thread has |
| 383 // terminated. | 428 // terminated. |
| 384 | 429 |
| 385 class Thread { | 430 class Thread { |
| 386 public: | 431 public: |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 Atomic32 active_; | 714 Atomic32 active_; |
| 670 PlatformData* data_; // Platform specific data. | 715 PlatformData* data_; // Platform specific data. |
| 671 int samples_taken_; // Counts stack samples taken. | 716 int samples_taken_; // Counts stack samples taken. |
| 672 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); | 717 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); |
| 673 }; | 718 }; |
| 674 | 719 |
| 675 | 720 |
| 676 } } // namespace v8::internal | 721 } } // namespace v8::internal |
| 677 | 722 |
| 678 #endif // V8_PLATFORM_H_ | 723 #endif // V8_PLATFORM_H_ |
| OLD | NEW |