| OLD | NEW |
| 1 // Copyright 2006-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2010 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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 | 406 |
| 407 // ---------------------------------------------------------------------------- | 407 // ---------------------------------------------------------------------------- |
| 408 // All heap objects containing executable code (code objects) must be allocated | 408 // All heap objects containing executable code (code objects) must be allocated |
| 409 // from a 2 GB range of memory, so that they can call each other using 32-bit | 409 // from a 2 GB range of memory, so that they can call each other using 32-bit |
| 410 // displacements. This happens automatically on 32-bit platforms, where 32-bit | 410 // displacements. This happens automatically on 32-bit platforms, where 32-bit |
| 411 // displacements cover the entire 4GB virtual address space. On 64-bit | 411 // displacements cover the entire 4GB virtual address space. On 64-bit |
| 412 // platforms, we support this using the CodeRange object, which reserves and | 412 // platforms, we support this using the CodeRange object, which reserves and |
| 413 // manages a range of virtual memory. | 413 // manages a range of virtual memory. |
| 414 class CodeRange { | 414 class CodeRange { |
| 415 public: | 415 public: |
| 416 explicit CodeRange(Isolate* isolate); |
| 417 |
| 416 // Reserves a range of virtual memory, but does not commit any of it. | 418 // Reserves a range of virtual memory, but does not commit any of it. |
| 417 // Can only be called once, at heap initialization time. | 419 // Can only be called once, at heap initialization time. |
| 418 // Returns false on failure. | 420 // Returns false on failure. |
| 419 bool Setup(const size_t requested_size); | 421 bool Setup(const size_t requested_size); |
| 420 | 422 |
| 421 // Frees the range of virtual memory, and frees the data structures used to | 423 // Frees the range of virtual memory, and frees the data structures used to |
| 422 // manage it. | 424 // manage it. |
| 423 void TearDown(); | 425 void TearDown(); |
| 424 | 426 |
| 425 bool exists() { return code_range_ != NULL; } | 427 bool exists() { return this != NULL && code_range_ != NULL; } |
| 426 bool contains(Address address) { | 428 bool contains(Address address) { |
| 427 if (code_range_ == NULL) return false; | 429 if (this == NULL || code_range_ == NULL) return false; |
| 428 Address start = static_cast<Address>(code_range_->address()); | 430 Address start = static_cast<Address>(code_range_->address()); |
| 429 return start <= address && address < start + code_range_->size(); | 431 return start <= address && address < start + code_range_->size(); |
| 430 } | 432 } |
| 431 | 433 |
| 432 // Allocates a chunk of memory from the large-object portion of | 434 // Allocates a chunk of memory from the large-object portion of |
| 433 // the code range. On platforms with no separate code range, should | 435 // the code range. On platforms with no separate code range, should |
| 434 // not be called. | 436 // not be called. |
| 435 MUST_USE_RESULT void* AllocateRawMemory(const size_t requested, | 437 MUST_USE_RESULT void* AllocateRawMemory(const size_t requested, |
| 436 size_t* allocated); | 438 size_t* allocated); |
| 437 void FreeRawMemory(void* buf, size_t length); | 439 void FreeRawMemory(void* buf, size_t length); |
| 438 | 440 |
| 439 private: | 441 private: |
| 440 CodeRange(); | 442 Isolate* isolate_; |
| 441 | 443 |
| 442 // The reserved range of virtual memory that all code objects are put in. | 444 // The reserved range of virtual memory that all code objects are put in. |
| 443 VirtualMemory* code_range_; | 445 VirtualMemory* code_range_; |
| 444 // Plain old data class, just a struct plus a constructor. | 446 // Plain old data class, just a struct plus a constructor. |
| 445 class FreeBlock { | 447 class FreeBlock { |
| 446 public: | 448 public: |
| 447 FreeBlock(Address start_arg, size_t size_arg) | 449 FreeBlock(Address start_arg, size_t size_arg) |
| 448 : start(start_arg), size(size_arg) {} | 450 : start(start_arg), size(size_arg) {} |
| 449 FreeBlock(void* start_arg, size_t size_arg) | 451 FreeBlock(void* start_arg, size_t size_arg) |
| 450 : start(static_cast<Address>(start_arg)), size(size_arg) {} | 452 : start(static_cast<Address>(start_arg)), size(size_arg) {} |
| (...skipping 13 matching lines...) Expand all Loading... |
| 464 | 466 |
| 465 // Finds a block on the allocation list that contains at least the | 467 // Finds a block on the allocation list that contains at least the |
| 466 // requested amount of memory. If none is found, sorts and merges | 468 // requested amount of memory. If none is found, sorts and merges |
| 467 // the existing free memory blocks, and searches again. | 469 // the existing free memory blocks, and searches again. |
| 468 // If none can be found, terminates V8 with FatalProcessOutOfMemory. | 470 // If none can be found, terminates V8 with FatalProcessOutOfMemory. |
| 469 void GetNextAllocationBlock(size_t requested); | 471 void GetNextAllocationBlock(size_t requested); |
| 470 // Compares the start addresses of two free blocks. | 472 // Compares the start addresses of two free blocks. |
| 471 static int CompareFreeBlockAddress(const FreeBlock* left, | 473 static int CompareFreeBlockAddress(const FreeBlock* left, |
| 472 const FreeBlock* right); | 474 const FreeBlock* right); |
| 473 | 475 |
| 474 friend class Isolate; | |
| 475 | |
| 476 Isolate* isolate_; | |
| 477 | |
| 478 DISALLOW_COPY_AND_ASSIGN(CodeRange); | 476 DISALLOW_COPY_AND_ASSIGN(CodeRange); |
| 479 }; | 477 }; |
| 480 | 478 |
| 481 | 479 |
| 482 // ---------------------------------------------------------------------------- | 480 // ---------------------------------------------------------------------------- |
| 483 // A space acquires chunks of memory from the operating system. The memory | 481 // A space acquires chunks of memory from the operating system. The memory |
| 484 // allocator manages chunks for the paged heap spaces (old space and map | 482 // allocator manages chunks for the paged heap spaces (old space and map |
| 485 // space). A paged chunk consists of pages. Pages in a chunk have contiguous | 483 // space). A paged chunk consists of pages. Pages in a chunk have contiguous |
| 486 // addresses and are linked as a list. | 484 // addresses and are linked as a list. |
| 487 // | 485 // |
| (...skipping 10 matching lines...) Expand all Loading... |
| 498 // | 496 // |
| 499 // The fact that pages for paged spaces are allocated and deallocated in chunks | 497 // The fact that pages for paged spaces are allocated and deallocated in chunks |
| 500 // induces a constraint on the order of pages in a linked lists. We say that | 498 // induces a constraint on the order of pages in a linked lists. We say that |
| 501 // pages are linked in the chunk-order if and only if every two consecutive | 499 // pages are linked in the chunk-order if and only if every two consecutive |
| 502 // pages from the same chunk are consecutive in the linked list. | 500 // pages from the same chunk are consecutive in the linked list. |
| 503 // | 501 // |
| 504 | 502 |
| 505 | 503 |
| 506 class MemoryAllocator { | 504 class MemoryAllocator { |
| 507 public: | 505 public: |
| 506 explicit MemoryAllocator(Isolate* isolate); |
| 507 |
| 508 // Initializes its internal bookkeeping structures. | 508 // Initializes its internal bookkeeping structures. |
| 509 // Max capacity of the total space and executable memory limit. | 509 // Max capacity of the total space and executable memory limit. |
| 510 bool Setup(intptr_t max_capacity, intptr_t capacity_executable); | 510 bool Setup(intptr_t max_capacity, intptr_t capacity_executable); |
| 511 | 511 |
| 512 // Deletes valid chunks. | 512 // Deletes valid chunks. |
| 513 void TearDown(); | 513 void TearDown(); |
| 514 | 514 |
| 515 // Reserves an initial address range of virtual memory to be split between | 515 // Reserves an initial address range of virtual memory to be split between |
| 516 // the two new space semispaces, the old space, and the map space. The | 516 // the two new space semispaces, the old space, and the map space. The |
| 517 // memory is not yet committed or assigned to spaces and split into pages. | 517 // memory is not yet committed or assigned to spaces and split into pages. |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 static const int kChunkTableBitsPerLevel = 12; | 668 static const int kChunkTableBitsPerLevel = 12; |
| 669 #else | 669 #else |
| 670 static const int kPagesPerChunk = 16; | 670 static const int kPagesPerChunk = 16; |
| 671 // On 32 bit the chunk table consists of 2 levels of 256-entry tables. | 671 // On 32 bit the chunk table consists of 2 levels of 256-entry tables. |
| 672 static const int kPagesPerChunkLog2 = 4; | 672 static const int kPagesPerChunkLog2 = 4; |
| 673 static const int kChunkTableLevels = 2; | 673 static const int kChunkTableLevels = 2; |
| 674 static const int kChunkTableBitsPerLevel = 8; | 674 static const int kChunkTableBitsPerLevel = 8; |
| 675 #endif | 675 #endif |
| 676 | 676 |
| 677 private: | 677 private: |
| 678 MemoryAllocator(); | |
| 679 | |
| 680 static const int kChunkSize = kPagesPerChunk * Page::kPageSize; | 678 static const int kChunkSize = kPagesPerChunk * Page::kPageSize; |
| 681 static const int kChunkSizeLog2 = kPagesPerChunkLog2 + kPageSizeBits; | 679 static const int kChunkSizeLog2 = kPagesPerChunkLog2 + kPageSizeBits; |
| 682 | 680 |
| 681 Isolate* isolate_; |
| 682 |
| 683 // Maximum space size in bytes. | 683 // Maximum space size in bytes. |
| 684 intptr_t capacity_; | 684 intptr_t capacity_; |
| 685 // Maximum subset of capacity_ that can be executable | 685 // Maximum subset of capacity_ that can be executable |
| 686 intptr_t capacity_executable_; | 686 intptr_t capacity_executable_; |
| 687 | 687 |
| 688 // Allocated space size in bytes. | 688 // Allocated space size in bytes. |
| 689 intptr_t size_; | 689 intptr_t size_; |
| 690 | 690 |
| 691 // Allocated executable space size in bytes. | 691 // Allocated executable space size in bytes. |
| 692 intptr_t size_executable_; | 692 intptr_t size_executable_; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 // used as a marking stack and its page headers are destroyed. | 765 // used as a marking stack and its page headers are destroyed. |
| 766 Page* InitializePagesInChunk(int chunk_id, int pages_in_chunk, | 766 Page* InitializePagesInChunk(int chunk_id, int pages_in_chunk, |
| 767 PagedSpace* owner); | 767 PagedSpace* owner); |
| 768 | 768 |
| 769 Page* RelinkPagesInChunk(int chunk_id, | 769 Page* RelinkPagesInChunk(int chunk_id, |
| 770 Address chunk_start, | 770 Address chunk_start, |
| 771 size_t chunk_size, | 771 size_t chunk_size, |
| 772 Page* prev, | 772 Page* prev, |
| 773 Page** last_page_in_use); | 773 Page** last_page_in_use); |
| 774 | 774 |
| 775 friend class Isolate; | |
| 776 | |
| 777 Isolate* isolate_; | |
| 778 | |
| 779 DISALLOW_COPY_AND_ASSIGN(MemoryAllocator); | 775 DISALLOW_COPY_AND_ASSIGN(MemoryAllocator); |
| 780 }; | 776 }; |
| 781 | 777 |
| 782 | 778 |
| 783 // ----------------------------------------------------------------------------- | 779 // ----------------------------------------------------------------------------- |
| 784 // Interface for heap object iterator to be implemented by all object space | 780 // Interface for heap object iterator to be implemented by all object space |
| 785 // object iterators. | 781 // object iterators. |
| 786 // | 782 // |
| 787 // NOTE: The space specific object iterators also implements the own next() | 783 // NOTE: The space specific object iterators also implements the own next() |
| 788 // method which is used to avoid using virtual functions | 784 // method which is used to avoid using virtual functions |
| (...skipping 1570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2359 } | 2355 } |
| 2360 // Must be small, since an iteration is used for lookup. | 2356 // Must be small, since an iteration is used for lookup. |
| 2361 static const int kMaxComments = 64; | 2357 static const int kMaxComments = 64; |
| 2362 }; | 2358 }; |
| 2363 #endif | 2359 #endif |
| 2364 | 2360 |
| 2365 | 2361 |
| 2366 } } // namespace v8::internal | 2362 } } // namespace v8::internal |
| 2367 | 2363 |
| 2368 #endif // V8_SPACES_H_ | 2364 #endif // V8_SPACES_H_ |
| OLD | NEW |