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...) 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 | |
357 void Release() { | 340 void Release() { |
358 DCHECK(IsReserved()); | 341 DCHECK(IsReserved()); |
359 // Notice: Order is important here. The VirtualMemory object might live | 342 // Notice: Order is important here. The VirtualMemory object might live |
360 // inside the allocated region. | 343 // inside the allocated region. |
361 void* address = address_; | 344 void* address = address_; |
362 size_t size = size_; | 345 size_t size = size_; |
363 CHECK(InVM(address, size)); | 346 CHECK(InVM(address, size)); |
364 Reset(); | 347 Reset(); |
365 bool result = ReleaseRegion(address, size); | 348 bool result = ReleaseRegion(address, size); |
366 USE(result); | 349 USE(result); |
(...skipping 12 matching lines...) Loading... |
379 static void* ReserveRegion(size_t size); | 362 static void* ReserveRegion(size_t size); |
380 | 363 |
381 static bool CommitRegion(void* base, size_t size, bool is_executable); | 364 static bool CommitRegion(void* base, size_t size, bool is_executable); |
382 | 365 |
383 static bool UncommitRegion(void* base, size_t size); | 366 static bool UncommitRegion(void* base, size_t size); |
384 | 367 |
385 // Must be called with a base pointer that has been returned by ReserveRegion | 368 // Must be called with a base pointer that has been returned by ReserveRegion |
386 // and the same size it was reserved with. | 369 // and the same size it was reserved with. |
387 static bool ReleaseRegion(void* base, size_t size); | 370 static bool ReleaseRegion(void* base, size_t size); |
388 | 371 |
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 | |
395 // Returns true if OS performs lazy commits, i.e. the memory allocation call | 372 // Returns true if OS performs lazy commits, i.e. the memory allocation call |
396 // defers actual physical memory allocation till the first memory access. | 373 // defers actual physical memory allocation till the first memory access. |
397 // Otherwise returns false. | 374 // Otherwise returns false. |
398 static bool HasLazyCommits(); | 375 static bool HasLazyCommits(); |
399 | 376 |
400 private: | 377 private: |
401 bool InVM(void* address, size_t size) { | 378 bool InVM(void* address, size_t size) { |
402 return (reinterpret_cast<uintptr_t>(address_) <= | 379 return (reinterpret_cast<uintptr_t>(address_) <= |
403 reinterpret_cast<uintptr_t>(address)) && | 380 reinterpret_cast<uintptr_t>(address)) && |
404 ((reinterpret_cast<uintptr_t>(address_) + size_) >= | 381 ((reinterpret_cast<uintptr_t>(address_) + size_) >= |
(...skipping 107 matching lines...) Loading... |
512 int stack_size_; | 489 int stack_size_; |
513 Semaphore* start_semaphore_; | 490 Semaphore* start_semaphore_; |
514 | 491 |
515 DISALLOW_COPY_AND_ASSIGN(Thread); | 492 DISALLOW_COPY_AND_ASSIGN(Thread); |
516 }; | 493 }; |
517 | 494 |
518 } // namespace base | 495 } // namespace base |
519 } // namespace v8 | 496 } // namespace v8 |
520 | 497 |
521 #endif // V8_BASE_PLATFORM_PLATFORM_H_ | 498 #endif // V8_BASE_PLATFORM_PLATFORM_H_ |
OLD | NEW |