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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 | 330 |
331 // Commits real memory. Returns whether the operation succeeded. | 331 // Commits real memory. Returns whether the operation succeeded. |
332 bool Commit(void* address, size_t size, bool is_executable); | 332 bool Commit(void* address, size_t size, bool is_executable); |
333 | 333 |
334 // Uncommit real memory. Returns whether the operation succeeded. | 334 // Uncommit real memory. Returns whether the operation succeeded. |
335 bool Uncommit(void* address, size_t size); | 335 bool Uncommit(void* address, size_t size); |
336 | 336 |
337 // Creates a single guard page at the given address. | 337 // Creates a single guard page at the given address. |
338 bool Guard(void* address); | 338 bool Guard(void* address); |
339 | 339 |
| 340 // Releases the memory after |free_start|. |
| 341 void ReleasePartial(void* free_start) { |
| 342 DCHECK(IsReserved()); |
| 343 // Notice: Order is important here. The VirtualMemory object might live |
| 344 // inside the allocated region. |
| 345 size_t size = size_ - (reinterpret_cast<size_t>(free_start) - |
| 346 reinterpret_cast<size_t>(address_)); |
| 347 CHECK(InVM(free_start, size)); |
| 348 DCHECK_LT(address_, free_start); |
| 349 DCHECK_LT(free_start, reinterpret_cast<void*>( |
| 350 reinterpret_cast<size_t>(address_) + size_)); |
| 351 bool result = ReleasePartialRegion(address_, size_, free_start, size); |
| 352 USE(result); |
| 353 DCHECK(result); |
| 354 size_ -= size; |
| 355 } |
| 356 |
340 void Release() { | 357 void Release() { |
341 DCHECK(IsReserved()); | 358 DCHECK(IsReserved()); |
342 // Notice: Order is important here. The VirtualMemory object might live | 359 // Notice: Order is important here. The VirtualMemory object might live |
343 // inside the allocated region. | 360 // inside the allocated region. |
344 void* address = address_; | 361 void* address = address_; |
345 size_t size = size_; | 362 size_t size = size_; |
346 CHECK(InVM(address, size)); | 363 CHECK(InVM(address, size)); |
347 Reset(); | 364 Reset(); |
348 bool result = ReleaseRegion(address, size); | 365 bool result = ReleaseRegion(address, size); |
349 USE(result); | 366 USE(result); |
(...skipping 12 matching lines...) Expand all Loading... |
362 static void* ReserveRegion(size_t size); | 379 static void* ReserveRegion(size_t size); |
363 | 380 |
364 static bool CommitRegion(void* base, size_t size, bool is_executable); | 381 static bool CommitRegion(void* base, size_t size, bool is_executable); |
365 | 382 |
366 static bool UncommitRegion(void* base, size_t size); | 383 static bool UncommitRegion(void* base, size_t size); |
367 | 384 |
368 // Must be called with a base pointer that has been returned by ReserveRegion | 385 // Must be called with a base pointer that has been returned by ReserveRegion |
369 // and the same size it was reserved with. | 386 // and the same size it was reserved with. |
370 static bool ReleaseRegion(void* base, size_t size); | 387 static bool ReleaseRegion(void* base, size_t size); |
371 | 388 |
| 389 // Must be called with a base pointer that has been returned by ReserveRegion |
| 390 // and the same size it was reserved with. |
| 391 // [free_start, free_start + free_size] is the memory that will be released. |
| 392 static bool ReleasePartialRegion(void* base, size_t size, void* free_start, |
| 393 size_t free_size); |
| 394 |
372 // Returns true if OS performs lazy commits, i.e. the memory allocation call | 395 // Returns true if OS performs lazy commits, i.e. the memory allocation call |
373 // defers actual physical memory allocation till the first memory access. | 396 // defers actual physical memory allocation till the first memory access. |
374 // Otherwise returns false. | 397 // Otherwise returns false. |
375 static bool HasLazyCommits(); | 398 static bool HasLazyCommits(); |
376 | 399 |
377 private: | 400 private: |
378 bool InVM(void* address, size_t size) { | 401 bool InVM(void* address, size_t size) { |
379 return (reinterpret_cast<uintptr_t>(address_) <= | 402 return (reinterpret_cast<uintptr_t>(address_) <= |
380 reinterpret_cast<uintptr_t>(address)) && | 403 reinterpret_cast<uintptr_t>(address)) && |
381 ((reinterpret_cast<uintptr_t>(address_) + size_) >= | 404 ((reinterpret_cast<uintptr_t>(address_) + size_) >= |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 int stack_size_; | 512 int stack_size_; |
490 Semaphore* start_semaphore_; | 513 Semaphore* start_semaphore_; |
491 | 514 |
492 DISALLOW_COPY_AND_ASSIGN(Thread); | 515 DISALLOW_COPY_AND_ASSIGN(Thread); |
493 }; | 516 }; |
494 | 517 |
495 } // namespace base | 518 } // namespace base |
496 } // namespace v8 | 519 } // namespace v8 |
497 | 520 |
498 #endif // V8_BASE_PLATFORM_PLATFORM_H_ | 521 #endif // V8_BASE_PLATFORM_PLATFORM_H_ |
OLD | NEW |