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 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 static const intptr_t kSizeOffset = kPointerSize + kPointerSize; | 482 static const intptr_t kSizeOffset = kPointerSize + kPointerSize; |
483 | 483 |
484 static const intptr_t kLiveBytesOffset = | 484 static const intptr_t kLiveBytesOffset = |
485 kSizeOffset + kPointerSize + kPointerSize + kPointerSize + | 485 kSizeOffset + kPointerSize + kPointerSize + kPointerSize + |
486 kPointerSize + kPointerSize + | 486 kPointerSize + kPointerSize + |
487 kPointerSize + kPointerSize + kPointerSize + kIntSize; | 487 kPointerSize + kPointerSize + kPointerSize + kIntSize; |
488 | 488 |
489 static const size_t kSlotsBufferOffset = kLiveBytesOffset + kIntSize; | 489 static const size_t kSlotsBufferOffset = kLiveBytesOffset + kIntSize; |
490 | 490 |
491 static const size_t kHeaderSize = | 491 static const size_t kHeaderSize = |
492 kSlotsBufferOffset + kPointerSize + kPointerSize; | 492 kSlotsBufferOffset + kPointerSize + kPointerSize + kPointerSize; |
493 | 493 |
494 static const int kBodyOffset = | 494 static const int kBodyOffset = |
495 CODE_POINTER_ALIGN(MAP_POINTER_ALIGN(kHeaderSize + Bitmap::kSize)); | 495 CODE_POINTER_ALIGN(MAP_POINTER_ALIGN(kHeaderSize + Bitmap::kSize)); |
496 | 496 |
497 // The start offset of the object area in a page. Aligned to both maps and | 497 // The start offset of the object area in a page. Aligned to both maps and |
498 // code alignment to be suitable for both. Also aligned to 32 words because | 498 // code alignment to be suitable for both. Also aligned to 32 words because |
499 // the marking bitmap is arranged in 32 bit chunks. | 499 // the marking bitmap is arranged in 32 bit chunks. |
500 static const int kObjectStartAlignment = 32 * kPointerSize; | 500 static const int kObjectStartAlignment = 32 * kPointerSize; |
501 static const int kObjectStartOffset = kBodyOffset - 1 + | 501 static const int kObjectStartOffset = kBodyOffset - 1 + |
502 (kObjectStartAlignment - (kBodyOffset - 1) % kObjectStartAlignment); | 502 (kObjectStartAlignment - (kBodyOffset - 1) % kObjectStartAlignment); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 ASSERT(slots_buffer_ == NULL); | 594 ASSERT(slots_buffer_ == NULL); |
595 ClearFlag(EVACUATION_CANDIDATE); | 595 ClearFlag(EVACUATION_CANDIDATE); |
596 } | 596 } |
597 | 597 |
598 Address area_start() { return area_start_; } | 598 Address area_start() { return area_start_; } |
599 Address area_end() { return area_end_; } | 599 Address area_end() { return area_end_; } |
600 int area_size() { | 600 int area_size() { |
601 return static_cast<int>(area_end() - area_start()); | 601 return static_cast<int>(area_end() - area_start()); |
602 } | 602 } |
603 | 603 |
| 604 // Approximate amount of physical memory committed for this chunk. |
| 605 size_t CommittedPhysicalMemory() { |
| 606 return high_water_mark_; |
| 607 } |
| 608 |
| 609 static inline void UpdateHighWaterMark(Address mark); |
| 610 |
604 protected: | 611 protected: |
605 MemoryChunk* next_chunk_; | 612 MemoryChunk* next_chunk_; |
606 MemoryChunk* prev_chunk_; | 613 MemoryChunk* prev_chunk_; |
607 size_t size_; | 614 size_t size_; |
608 intptr_t flags_; | 615 intptr_t flags_; |
609 | 616 |
610 // Start and end of allocatable memory on this chunk. | 617 // Start and end of allocatable memory on this chunk. |
611 Address area_start_; | 618 Address area_start_; |
612 Address area_end_; | 619 Address area_end_; |
613 | 620 |
614 // If the chunk needs to remember its memory reservation, it is stored here. | 621 // If the chunk needs to remember its memory reservation, it is stored here. |
615 VirtualMemory reservation_; | 622 VirtualMemory reservation_; |
616 // The identity of the owning space. This is tagged as a failure pointer, but | 623 // The identity of the owning space. This is tagged as a failure pointer, but |
617 // no failure can be in an object, so this can be distinguished from any entry | 624 // no failure can be in an object, so this can be distinguished from any entry |
618 // in a fixed array. | 625 // in a fixed array. |
619 Address owner_; | 626 Address owner_; |
620 Heap* heap_; | 627 Heap* heap_; |
621 // Used by the store buffer to keep track of which pages to mark scan-on- | 628 // Used by the store buffer to keep track of which pages to mark scan-on- |
622 // scavenge. | 629 // scavenge. |
623 int store_buffer_counter_; | 630 int store_buffer_counter_; |
624 // Count of bytes marked black on page. | 631 // Count of bytes marked black on page. |
625 int live_byte_count_; | 632 int live_byte_count_; |
626 SlotsBuffer* slots_buffer_; | 633 SlotsBuffer* slots_buffer_; |
627 SkipList* skip_list_; | 634 SkipList* skip_list_; |
| 635 // Assuming the initial allocation on a page is sequential, |
| 636 // count highest number of bytes ever allocated on the page. |
| 637 int high_water_mark_; |
628 | 638 |
629 static MemoryChunk* Initialize(Heap* heap, | 639 static MemoryChunk* Initialize(Heap* heap, |
630 Address base, | 640 Address base, |
631 size_t size, | 641 size_t size, |
632 Address area_start, | 642 Address area_start, |
633 Address area_end, | 643 Address area_end, |
634 Executability executable, | 644 Executability executable, |
635 Space* owner); | 645 Space* owner); |
636 | 646 |
637 friend class MemoryAllocator; | 647 friend class MemoryAllocator; |
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1467 // Prepares for a mark-compact GC. | 1477 // Prepares for a mark-compact GC. |
1468 virtual void PrepareForMarkCompact(); | 1478 virtual void PrepareForMarkCompact(); |
1469 | 1479 |
1470 // Current capacity without growing (Size() + Available()). | 1480 // Current capacity without growing (Size() + Available()). |
1471 intptr_t Capacity() { return accounting_stats_.Capacity(); } | 1481 intptr_t Capacity() { return accounting_stats_.Capacity(); } |
1472 | 1482 |
1473 // Total amount of memory committed for this space. For paged | 1483 // Total amount of memory committed for this space. For paged |
1474 // spaces this equals the capacity. | 1484 // spaces this equals the capacity. |
1475 intptr_t CommittedMemory() { return Capacity(); } | 1485 intptr_t CommittedMemory() { return Capacity(); } |
1476 | 1486 |
| 1487 // Approximate amount of physical memory committed for this space. |
| 1488 size_t CommittedPhysicalMemory(); |
| 1489 |
1477 // Sets the capacity, the available space and the wasted space to zero. | 1490 // Sets the capacity, the available space and the wasted space to zero. |
1478 // The stats are rebuilt during sweeping by adding each page to the | 1491 // The stats are rebuilt during sweeping by adding each page to the |
1479 // capacity and the size when it is encountered. As free spaces are | 1492 // capacity and the size when it is encountered. As free spaces are |
1480 // discovered during the sweeping they are subtracted from the size and added | 1493 // discovered during the sweeping they are subtracted from the size and added |
1481 // to the available and wasted totals. | 1494 // to the available and wasted totals. |
1482 void ClearStats() { | 1495 void ClearStats() { |
1483 accounting_stats_.ClearSizeWaste(); | 1496 accounting_stats_.ClearSizeWaste(); |
1484 } | 1497 } |
1485 | 1498 |
1486 // Available bytes without growing. These are the bytes on the free list. | 1499 // Available bytes without growing. These are the bytes on the free list. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1527 } | 1540 } |
1528 | 1541 |
1529 void ResetFreeList() { | 1542 void ResetFreeList() { |
1530 free_list_.Reset(); | 1543 free_list_.Reset(); |
1531 } | 1544 } |
1532 | 1545 |
1533 // Set space allocation info. | 1546 // Set space allocation info. |
1534 void SetTop(Address top, Address limit) { | 1547 void SetTop(Address top, Address limit) { |
1535 ASSERT(top == limit || | 1548 ASSERT(top == limit || |
1536 Page::FromAddress(top) == Page::FromAddress(limit - 1)); | 1549 Page::FromAddress(top) == Page::FromAddress(limit - 1)); |
| 1550 MemoryChunk::UpdateHighWaterMark(allocation_info_.top); |
1537 allocation_info_.top = top; | 1551 allocation_info_.top = top; |
1538 allocation_info_.limit = limit; | 1552 allocation_info_.limit = limit; |
1539 } | 1553 } |
1540 | 1554 |
1541 void Allocate(int bytes) { | 1555 void Allocate(int bytes) { |
1542 accounting_stats_.AllocateBytes(bytes); | 1556 accounting_stats_.AllocateBytes(bytes); |
1543 } | 1557 } |
1544 | 1558 |
1545 void IncreaseCapacity(int size) { | 1559 void IncreaseCapacity(int size) { |
1546 accounting_stats_.ExpandSpace(size); | 1560 accounting_stats_.ExpandSpace(size); |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1933 // Returns the maximum capacity of the semi space. | 1947 // Returns the maximum capacity of the semi space. |
1934 int MaximumCapacity() { return maximum_capacity_; } | 1948 int MaximumCapacity() { return maximum_capacity_; } |
1935 | 1949 |
1936 // Returns the initial capacity of the semi space. | 1950 // Returns the initial capacity of the semi space. |
1937 int InitialCapacity() { return initial_capacity_; } | 1951 int InitialCapacity() { return initial_capacity_; } |
1938 | 1952 |
1939 SemiSpaceId id() { return id_; } | 1953 SemiSpaceId id() { return id_; } |
1940 | 1954 |
1941 static void Swap(SemiSpace* from, SemiSpace* to); | 1955 static void Swap(SemiSpace* from, SemiSpace* to); |
1942 | 1956 |
| 1957 // Approximate amount of physical memory committed for this space. |
| 1958 size_t CommittedPhysicalMemory(); |
| 1959 |
1943 private: | 1960 private: |
1944 // Flips the semispace between being from-space and to-space. | 1961 // Flips the semispace between being from-space and to-space. |
1945 // Copies the flags into the masked positions on all pages in the space. | 1962 // Copies the flags into the masked positions on all pages in the space. |
1946 void FlipPages(intptr_t flags, intptr_t flag_mask); | 1963 void FlipPages(intptr_t flags, intptr_t flag_mask); |
1947 | 1964 |
1948 NewSpacePage* anchor() { return &anchor_; } | 1965 NewSpacePage* anchor() { return &anchor_; } |
1949 | 1966 |
1950 // The current and maximum capacity of the space. | 1967 // The current and maximum capacity of the space. |
1951 int capacity_; | 1968 int capacity_; |
1952 int maximum_capacity_; | 1969 int maximum_capacity_; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2130 ASSERT(to_space_.Capacity() == from_space_.Capacity()); | 2147 ASSERT(to_space_.Capacity() == from_space_.Capacity()); |
2131 return to_space_.Capacity(); | 2148 return to_space_.Capacity(); |
2132 } | 2149 } |
2133 | 2150 |
2134 // Return the total amount of memory committed for new space. | 2151 // Return the total amount of memory committed for new space. |
2135 intptr_t CommittedMemory() { | 2152 intptr_t CommittedMemory() { |
2136 if (from_space_.is_committed()) return 2 * Capacity(); | 2153 if (from_space_.is_committed()) return 2 * Capacity(); |
2137 return Capacity(); | 2154 return Capacity(); |
2138 } | 2155 } |
2139 | 2156 |
| 2157 // Approximate amount of physical memory committed for this space. |
| 2158 size_t CommittedPhysicalMemory(); |
| 2159 |
2140 // Return the available bytes without growing. | 2160 // Return the available bytes without growing. |
2141 intptr_t Available() { | 2161 intptr_t Available() { |
2142 return Capacity() - Size(); | 2162 return Capacity() - Size(); |
2143 } | 2163 } |
2144 | 2164 |
2145 // Return the maximum capacity of a semispace. | 2165 // Return the maximum capacity of a semispace. |
2146 int MaximumCapacity() { | 2166 int MaximumCapacity() { |
2147 ASSERT(to_space_.MaximumCapacity() == from_space_.MaximumCapacity()); | 2167 ASSERT(to_space_.MaximumCapacity() == from_space_.MaximumCapacity()); |
2148 return to_space_.MaximumCapacity(); | 2168 return to_space_.MaximumCapacity(); |
2149 } | 2169 } |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2497 } | 2517 } |
2498 | 2518 |
2499 virtual intptr_t SizeOfObjects() { | 2519 virtual intptr_t SizeOfObjects() { |
2500 return objects_size_; | 2520 return objects_size_; |
2501 } | 2521 } |
2502 | 2522 |
2503 intptr_t CommittedMemory() { | 2523 intptr_t CommittedMemory() { |
2504 return Size(); | 2524 return Size(); |
2505 } | 2525 } |
2506 | 2526 |
| 2527 // Approximate amount of physical memory committed for this space. |
| 2528 size_t CommittedPhysicalMemory(); |
| 2529 |
2507 int PageCount() { | 2530 int PageCount() { |
2508 return page_count_; | 2531 return page_count_; |
2509 } | 2532 } |
2510 | 2533 |
2511 // Finds an object for a given address, returns Failure::Exception() | 2534 // Finds an object for a given address, returns Failure::Exception() |
2512 // if it is not found. The function iterates through all objects in this | 2535 // if it is not found. The function iterates through all objects in this |
2513 // space, may be slow. | 2536 // space, may be slow. |
2514 MaybeObject* FindObject(Address a); | 2537 MaybeObject* FindObject(Address a); |
2515 | 2538 |
2516 // Finds a large object page containing the given address, returns NULL | 2539 // Finds a large object page containing the given address, returns NULL |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2649 } | 2672 } |
2650 // Must be small, since an iteration is used for lookup. | 2673 // Must be small, since an iteration is used for lookup. |
2651 static const int kMaxComments = 64; | 2674 static const int kMaxComments = 64; |
2652 }; | 2675 }; |
2653 #endif | 2676 #endif |
2654 | 2677 |
2655 | 2678 |
2656 } } // namespace v8::internal | 2679 } } // namespace v8::internal |
2657 | 2680 |
2658 #endif // V8_SPACES_H_ | 2681 #endif // V8_SPACES_H_ |
OLD | NEW |