| 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 1665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1676 bool Contains(HeapObject* o) { return Contains(o->address()); } | 1676 bool Contains(HeapObject* o) { return Contains(o->address()); } |
| 1677 | 1677 |
| 1678 // Given an address occupied by a live object, return that object if it is | 1678 // Given an address occupied by a live object, return that object if it is |
| 1679 // in this space, or Failure::Exception() if it is not. The implementation | 1679 // in this space, or Failure::Exception() if it is not. The implementation |
| 1680 // iterates over objects in the page containing the address, the cost is | 1680 // iterates over objects in the page containing the address, the cost is |
| 1681 // linear in the number of objects in the page. It may be slow. | 1681 // linear in the number of objects in the page. It may be slow. |
| 1682 MUST_USE_RESULT MaybeObject* FindObject(Address addr); | 1682 MUST_USE_RESULT MaybeObject* FindObject(Address addr); |
| 1683 | 1683 |
| 1684 // During boot the free_space_map is created, and afterwards we may need | 1684 // During boot the free_space_map is created, and afterwards we may need |
| 1685 // to write it into the free list nodes that were already created. | 1685 // to write it into the free list nodes that were already created. |
| 1686 virtual void RepairFreeListsAfterBoot(); | 1686 void RepairFreeListsAfterBoot(); |
| 1687 | 1687 |
| 1688 // Prepares for a mark-compact GC. | 1688 // Prepares for a mark-compact GC. |
| 1689 virtual void PrepareForMarkCompact(); | 1689 void PrepareForMarkCompact(); |
| 1690 | 1690 |
| 1691 // Current capacity without growing (Size() + Available()). | 1691 // Current capacity without growing (Size() + Available()). |
| 1692 intptr_t Capacity() { return accounting_stats_.Capacity(); } | 1692 intptr_t Capacity() { return accounting_stats_.Capacity(); } |
| 1693 | 1693 |
| 1694 // Total amount of memory committed for this space. For paged | 1694 // Total amount of memory committed for this space. For paged |
| 1695 // spaces this equals the capacity. | 1695 // spaces this equals the capacity. |
| 1696 intptr_t CommittedMemory() { return Capacity(); } | 1696 intptr_t CommittedMemory() { return Capacity(); } |
| 1697 | 1697 |
| 1698 // The maximum amount of memory ever committed for this space. | 1698 // The maximum amount of memory ever committed for this space. |
| 1699 intptr_t MaximumCommittedMemory() { return accounting_stats_.MaxCapacity(); } | 1699 intptr_t MaximumCommittedMemory() { return accounting_stats_.MaxCapacity(); } |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1905 | 1905 |
| 1906 // The dummy page that anchors the double linked list of pages. | 1906 // The dummy page that anchors the double linked list of pages. |
| 1907 Page anchor_; | 1907 Page anchor_; |
| 1908 | 1908 |
| 1909 // The space's free list. | 1909 // The space's free list. |
| 1910 FreeList free_list_; | 1910 FreeList free_list_; |
| 1911 | 1911 |
| 1912 // Normal allocation information. | 1912 // Normal allocation information. |
| 1913 AllocationInfo allocation_info_; | 1913 AllocationInfo allocation_info_; |
| 1914 | 1914 |
| 1915 // Bytes of each page that cannot be allocated. Possibly non-zero | |
| 1916 // for pages in spaces with only fixed-size objects. Always zero | |
| 1917 // for pages in spaces with variable sized objects (those pages are | |
| 1918 // padded with free-list nodes). | |
| 1919 int page_extra_; | |
| 1920 | |
| 1921 bool was_swept_conservatively_; | 1915 bool was_swept_conservatively_; |
| 1922 | 1916 |
| 1923 // The first page to be swept when the lazy sweeper advances. Is set | 1917 // The first page to be swept when the lazy sweeper advances. Is set |
| 1924 // to NULL when all pages have been swept. | 1918 // to NULL when all pages have been swept. |
| 1925 Page* first_unswept_page_; | 1919 Page* first_unswept_page_; |
| 1926 | 1920 |
| 1927 // The number of free bytes which could be reclaimed by advancing the | 1921 // The number of free bytes which could be reclaimed by advancing the |
| 1928 // lazy sweeper. This is only an estimation because lazy sweeping is | 1922 // lazy sweeper. This is only an estimation because lazy sweeping is |
| 1929 // done conservatively. | 1923 // done conservatively. |
| 1930 intptr_t unswept_free_bytes_; | 1924 intptr_t unswept_free_bytes_; |
| (...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2616 | 2610 |
| 2617 class OldSpace : public PagedSpace { | 2611 class OldSpace : public PagedSpace { |
| 2618 public: | 2612 public: |
| 2619 // Creates an old space object with a given maximum capacity. | 2613 // Creates an old space object with a given maximum capacity. |
| 2620 // The constructor does not allocate pages from OS. | 2614 // The constructor does not allocate pages from OS. |
| 2621 OldSpace(Heap* heap, | 2615 OldSpace(Heap* heap, |
| 2622 intptr_t max_capacity, | 2616 intptr_t max_capacity, |
| 2623 AllocationSpace id, | 2617 AllocationSpace id, |
| 2624 Executability executable) | 2618 Executability executable) |
| 2625 : PagedSpace(heap, max_capacity, id, executable) { | 2619 : PagedSpace(heap, max_capacity, id, executable) { |
| 2626 page_extra_ = 0; | |
| 2627 } | |
| 2628 | |
| 2629 // The limit of allocation for a page in this space. | |
| 2630 virtual Address PageAllocationLimit(Page* page) { | |
| 2631 return page->area_end(); | |
| 2632 } | 2620 } |
| 2633 | 2621 |
| 2634 public: | 2622 public: |
| 2635 TRACK_MEMORY("OldSpace") | 2623 TRACK_MEMORY("OldSpace") |
| 2636 }; | 2624 }; |
| 2637 | 2625 |
| 2638 | 2626 |
| 2639 // For contiguous spaces, top should be in the space (or at the end) and limit | 2627 // For contiguous spaces, top should be in the space (or at the end) and limit |
| 2640 // should be the end of the space. | 2628 // should be the end of the space. |
| 2641 #define ASSERT_SEMISPACE_ALLOCATION_INFO(info, space) \ | 2629 #define ASSERT_SEMISPACE_ALLOCATION_INFO(info, space) \ |
| 2642 SLOW_ASSERT((space).page_low() <= (info).top() \ | 2630 SLOW_ASSERT((space).page_low() <= (info).top() \ |
| 2643 && (info).top() <= (space).page_high() \ | 2631 && (info).top() <= (space).page_high() \ |
| 2644 && (info).limit() <= (space).page_high()) | 2632 && (info).limit() <= (space).page_high()) |
| 2645 | 2633 |
| 2646 | 2634 |
| 2647 // ----------------------------------------------------------------------------- | 2635 // ----------------------------------------------------------------------------- |
| 2648 // Old space for objects of a fixed size | |
| 2649 | |
| 2650 class FixedSpace : public PagedSpace { | |
| 2651 public: | |
| 2652 FixedSpace(Heap* heap, | |
| 2653 intptr_t max_capacity, | |
| 2654 AllocationSpace id, | |
| 2655 int object_size_in_bytes) | |
| 2656 : PagedSpace(heap, max_capacity, id, NOT_EXECUTABLE), | |
| 2657 object_size_in_bytes_(object_size_in_bytes) { | |
| 2658 page_extra_ = Page::kNonCodeObjectAreaSize % object_size_in_bytes; | |
| 2659 } | |
| 2660 | |
| 2661 // The limit of allocation for a page in this space. | |
| 2662 virtual Address PageAllocationLimit(Page* page) { | |
| 2663 return page->area_end() - page_extra_; | |
| 2664 } | |
| 2665 | |
| 2666 int object_size_in_bytes() { return object_size_in_bytes_; } | |
| 2667 | |
| 2668 // Prepares for a mark-compact GC. | |
| 2669 virtual void PrepareForMarkCompact(); | |
| 2670 | |
| 2671 private: | |
| 2672 // The size of objects in this space. | |
| 2673 int object_size_in_bytes_; | |
| 2674 }; | |
| 2675 | |
| 2676 | |
| 2677 // ----------------------------------------------------------------------------- | |
| 2678 // Old space for all map objects | 2636 // Old space for all map objects |
| 2679 | 2637 |
| 2680 class MapSpace : public FixedSpace { | 2638 class MapSpace : public PagedSpace { |
| 2681 public: | 2639 public: |
| 2682 // Creates a map space object with a maximum capacity. | 2640 // Creates a map space object with a maximum capacity. |
| 2683 MapSpace(Heap* heap, intptr_t max_capacity, AllocationSpace id) | 2641 MapSpace(Heap* heap, intptr_t max_capacity, AllocationSpace id) |
| 2684 : FixedSpace(heap, max_capacity, id, Map::kSize), | 2642 : PagedSpace(heap, max_capacity, id, NOT_EXECUTABLE), |
| 2685 max_map_space_pages_(kMaxMapPageIndex - 1) { | 2643 max_map_space_pages_(kMaxMapPageIndex - 1) { |
| 2686 } | 2644 } |
| 2687 | 2645 |
| 2688 // Given an index, returns the page address. | 2646 // Given an index, returns the page address. |
| 2689 // TODO(1600): this limit is artifical just to keep code compilable | 2647 // TODO(1600): this limit is artifical just to keep code compilable |
| 2690 static const int kMaxMapPageIndex = 1 << 16; | 2648 static const int kMaxMapPageIndex = 1 << 16; |
| 2691 | 2649 |
| 2692 virtual int RoundSizeDownToObjectAlignment(int size) { | 2650 virtual int RoundSizeDownToObjectAlignment(int size) { |
| 2693 if (IsPowerOf2(Map::kSize)) { | 2651 if (IsPowerOf2(Map::kSize)) { |
| 2694 return RoundDown(size, Map::kSize); | 2652 return RoundDown(size, Map::kSize); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2711 const int max_map_space_pages_; | 2669 const int max_map_space_pages_; |
| 2712 | 2670 |
| 2713 public: | 2671 public: |
| 2714 TRACK_MEMORY("MapSpace") | 2672 TRACK_MEMORY("MapSpace") |
| 2715 }; | 2673 }; |
| 2716 | 2674 |
| 2717 | 2675 |
| 2718 // ----------------------------------------------------------------------------- | 2676 // ----------------------------------------------------------------------------- |
| 2719 // Old space for simple property cell objects | 2677 // Old space for simple property cell objects |
| 2720 | 2678 |
| 2721 class CellSpace : public FixedSpace { | 2679 class CellSpace : public PagedSpace { |
| 2722 public: | 2680 public: |
| 2723 // Creates a property cell space object with a maximum capacity. | 2681 // Creates a property cell space object with a maximum capacity. |
| 2724 CellSpace(Heap* heap, intptr_t max_capacity, AllocationSpace id) | 2682 CellSpace(Heap* heap, intptr_t max_capacity, AllocationSpace id) |
| 2725 : FixedSpace(heap, max_capacity, id, Cell::kSize) | 2683 : PagedSpace(heap, max_capacity, id, NOT_EXECUTABLE) { |
| 2726 {} | 2684 } |
| 2727 | 2685 |
| 2728 virtual int RoundSizeDownToObjectAlignment(int size) { | 2686 virtual int RoundSizeDownToObjectAlignment(int size) { |
| 2729 if (IsPowerOf2(Cell::kSize)) { | 2687 if (IsPowerOf2(Cell::kSize)) { |
| 2730 return RoundDown(size, Cell::kSize); | 2688 return RoundDown(size, Cell::kSize); |
| 2731 } else { | 2689 } else { |
| 2732 return (size / Cell::kSize) * Cell::kSize; | 2690 return (size / Cell::kSize) * Cell::kSize; |
| 2733 } | 2691 } |
| 2734 } | 2692 } |
| 2735 | 2693 |
| 2736 protected: | 2694 protected: |
| 2737 virtual void VerifyObject(HeapObject* obj); | 2695 virtual void VerifyObject(HeapObject* obj); |
| 2738 | 2696 |
| 2739 public: | 2697 public: |
| 2740 TRACK_MEMORY("CellSpace") | 2698 TRACK_MEMORY("CellSpace") |
| 2741 }; | 2699 }; |
| 2742 | 2700 |
| 2743 | 2701 |
| 2744 // ----------------------------------------------------------------------------- | 2702 // ----------------------------------------------------------------------------- |
| 2745 // Old space for all global object property cell objects | 2703 // Old space for all global object property cell objects |
| 2746 | 2704 |
| 2747 class PropertyCellSpace : public FixedSpace { | 2705 class PropertyCellSpace : public PagedSpace { |
| 2748 public: | 2706 public: |
| 2749 // Creates a property cell space object with a maximum capacity. | 2707 // Creates a property cell space object with a maximum capacity. |
| 2750 PropertyCellSpace(Heap* heap, intptr_t max_capacity, | 2708 PropertyCellSpace(Heap* heap, intptr_t max_capacity, |
| 2751 AllocationSpace id) | 2709 AllocationSpace id) |
| 2752 : FixedSpace(heap, max_capacity, id, PropertyCell::kSize) | 2710 : PagedSpace(heap, max_capacity, id, NOT_EXECUTABLE) { |
| 2753 {} | 2711 } |
| 2754 | 2712 |
| 2755 virtual int RoundSizeDownToObjectAlignment(int size) { | 2713 virtual int RoundSizeDownToObjectAlignment(int size) { |
| 2756 if (IsPowerOf2(PropertyCell::kSize)) { | 2714 if (IsPowerOf2(PropertyCell::kSize)) { |
| 2757 return RoundDown(size, PropertyCell::kSize); | 2715 return RoundDown(size, PropertyCell::kSize); |
| 2758 } else { | 2716 } else { |
| 2759 return (size / PropertyCell::kSize) * PropertyCell::kSize; | 2717 return (size / PropertyCell::kSize) * PropertyCell::kSize; |
| 2760 } | 2718 } |
| 2761 } | 2719 } |
| 2762 | 2720 |
| 2763 protected: | 2721 protected: |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2962 } | 2920 } |
| 2963 // Must be small, since an iteration is used for lookup. | 2921 // Must be small, since an iteration is used for lookup. |
| 2964 static const int kMaxComments = 64; | 2922 static const int kMaxComments = 64; |
| 2965 }; | 2923 }; |
| 2966 #endif | 2924 #endif |
| 2967 | 2925 |
| 2968 | 2926 |
| 2969 } } // namespace v8::internal | 2927 } } // namespace v8::internal |
| 2970 | 2928 |
| 2971 #endif // V8_SPACES_H_ | 2929 #endif // V8_SPACES_H_ |
| OLD | NEW |