OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 virtual void getStatsForTesting(HeapStats&) = 0; | 716 virtual void getStatsForTesting(HeapStats&) = 0; |
717 | 717 |
718 virtual void updateRemainingAllocationSize() = 0; | 718 virtual void updateRemainingAllocationSize() = 0; |
719 | 719 |
720 virtual void prepareHeapForTermination() = 0; | 720 virtual void prepareHeapForTermination() = 0; |
721 | 721 |
722 virtual int normalPageCount() = 0; | 722 virtual int normalPageCount() = 0; |
723 | 723 |
724 virtual PassOwnPtr<BaseHeap> split(int normalPages) = 0; | 724 virtual PassOwnPtr<BaseHeap> split(int normalPages) = 0; |
725 virtual void merge(PassOwnPtr<BaseHeap> other) = 0; | 725 virtual void merge(PassOwnPtr<BaseHeap> other) = 0; |
| 726 }; |
726 | 727 |
| 728 template<typename Header> |
| 729 class FreeList { |
| 730 public: |
| 731 FreeList(); |
| 732 |
| 733 void addToFreeList(Address, size_t); |
| 734 void clear(); |
| 735 |
| 736 private: |
727 // Returns a bucket number for inserting a FreeListEntry of a | 737 // Returns a bucket number for inserting a FreeListEntry of a |
728 // given size. All FreeListEntries in the given bucket, n, have | 738 // given size. All FreeListEntries in the given bucket, n, have |
729 // size >= 2^n. | 739 // size >= 2^n. |
730 static int bucketIndexForSize(size_t); | 740 static int bucketIndexForSize(size_t); |
| 741 |
| 742 int m_biggestFreeListIndex; |
| 743 |
| 744 // All FreeListEntries in the nth list have size >= 2^n. |
| 745 FreeListEntry* m_freeLists[blinkPageSizeLog2]; |
| 746 FreeListEntry* m_lastFreeListEntries[blinkPageSizeLog2]; |
| 747 |
| 748 friend class ThreadHeap<Header>; |
731 }; | 749 }; |
732 | 750 |
733 // Thread heaps represent a part of the per-thread Blink heap. | 751 // Thread heaps represent a part of the per-thread Blink heap. |
734 // | 752 // |
735 // Each Blink thread has a number of thread heaps: one general heap | 753 // Each Blink thread has a number of thread heaps: one general heap |
736 // that contains any type of object and a number of heaps specialized | 754 // that contains any type of object and a number of heaps specialized |
737 // for specific object types (such as Node). | 755 // for specific object types (such as Node). |
738 // | 756 // |
739 // Each thread heap contains the functionality to allocate new objects | 757 // Each thread heap contains the functionality to allocate new objects |
740 // (potentially adding new pages to the heap), to find and mark | 758 // (potentially adding new pages to the heap), to find and mark |
(...skipping 24 matching lines...) Expand all Loading... |
765 #if ENABLE(ASSERT) | 783 #if ENABLE(ASSERT) |
766 virtual bool isConsistentForSweeping() override; | 784 virtual bool isConsistentForSweeping() override; |
767 #endif | 785 #endif |
768 virtual void getStatsForTesting(HeapStats&) override; | 786 virtual void getStatsForTesting(HeapStats&) override; |
769 | 787 |
770 virtual void updateRemainingAllocationSize() override; | 788 virtual void updateRemainingAllocationSize() override; |
771 | 789 |
772 ThreadState* threadState() { return m_threadState; } | 790 ThreadState* threadState() { return m_threadState; } |
773 HeapStats& stats() { return m_threadState->stats(); } | 791 HeapStats& stats() { return m_threadState->stats(); } |
774 | 792 |
| 793 void addToFreeList(Address address, size_t size) |
| 794 { |
| 795 ASSERT(heapPageFromAddress(address)); |
| 796 ASSERT(heapPageFromAddress(address + size - 1)); |
| 797 m_freeList.addToFreeList(address, size); |
| 798 } |
| 799 |
775 inline Address allocate(size_t, const GCInfo*); | 800 inline Address allocate(size_t, const GCInfo*); |
776 void addToFreeList(Address, size_t); | |
777 inline static size_t roundedAllocationSize(size_t size) | 801 inline static size_t roundedAllocationSize(size_t size) |
778 { | 802 { |
779 return allocationSizeFromSize(size) - sizeof(Header); | 803 return allocationSizeFromSize(size) - sizeof(Header); |
780 } | 804 } |
781 | 805 |
782 virtual void prepareHeapForTermination() override; | 806 virtual void prepareHeapForTermination() override; |
783 | 807 |
784 virtual int normalPageCount() override { return m_numberOfNormalPages; } | 808 virtual int normalPageCount() override { return m_numberOfNormalPages; } |
785 | 809 |
786 virtual PassOwnPtr<BaseHeap> split(int numberOfNormalPages) override; | 810 virtual PassOwnPtr<BaseHeap> split(int numberOfNormalPages) override; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 | 851 |
828 HeapPage<Header>* m_firstPage; | 852 HeapPage<Header>* m_firstPage; |
829 LargeHeapObject<Header>* m_firstLargeHeapObject; | 853 LargeHeapObject<Header>* m_firstLargeHeapObject; |
830 | 854 |
831 HeapPage<Header>* m_firstPageAllocatedDuringSweeping; | 855 HeapPage<Header>* m_firstPageAllocatedDuringSweeping; |
832 HeapPage<Header>* m_lastPageAllocatedDuringSweeping; | 856 HeapPage<Header>* m_lastPageAllocatedDuringSweeping; |
833 | 857 |
834 // Merge point for parallel sweep. | 858 // Merge point for parallel sweep. |
835 HeapPage<Header>* m_mergePoint; | 859 HeapPage<Header>* m_mergePoint; |
836 | 860 |
837 int m_biggestFreeListIndex; | |
838 | |
839 ThreadState* m_threadState; | 861 ThreadState* m_threadState; |
840 | 862 |
841 // All FreeListEntries in the nth list have size >= 2^n. | 863 FreeList<Header> m_freeList; |
842 FreeListEntry* m_freeLists[blinkPageSizeLog2]; | |
843 FreeListEntry* m_lastFreeListEntries[blinkPageSizeLog2]; | |
844 | 864 |
845 // Index into the page pools. This is used to ensure that the pages of the | 865 // Index into the page pools. This is used to ensure that the pages of the |
846 // same type go into the correct page pool and thus avoid type confusion. | 866 // same type go into the correct page pool and thus avoid type confusion. |
847 int m_index; | 867 int m_index; |
848 | 868 |
849 int m_numberOfNormalPages; | 869 int m_numberOfNormalPages; |
850 | 870 |
851 // The promptly freed count contains the number of promptly freed objects | 871 // The promptly freed count contains the number of promptly freed objects |
852 // since the last sweep or since it was manually reset to delay coalescing. | 872 // since the last sweep or since it was manually reset to delay coalescing. |
853 size_t m_promptlyFreedCount; | 873 size_t m_promptlyFreedCount; |
(...skipping 1544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2398 }; | 2418 }; |
2399 | 2419 |
2400 template<typename T> | 2420 template<typename T> |
2401 struct IfWeakMember<WeakMember<T> > { | 2421 struct IfWeakMember<WeakMember<T> > { |
2402 static bool isDead(Visitor* visitor, const WeakMember<T>& t) { return !visit
or->isAlive(t.get()); } | 2422 static bool isDead(Visitor* visitor, const WeakMember<T>& t) { return !visit
or->isAlive(t.get()); } |
2403 }; | 2423 }; |
2404 | 2424 |
2405 } | 2425 } |
2406 | 2426 |
2407 #endif // Heap_h | 2427 #endif // Heap_h |
OLD | NEW |