13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "gc/cms/cmsHeap.hpp" 27 #include "gc/cms/cmsLockVerifier.hpp" 28 #include "gc/cms/compactibleFreeListSpace.hpp" 29 #include "gc/cms/concurrentMarkSweepGeneration.inline.hpp" 30 #include "gc/cms/concurrentMarkSweepThread.hpp" 31 #include "gc/shared/blockOffsetTable.inline.hpp" 32 #include "gc/shared/collectedHeap.inline.hpp" 33 #include "gc/shared/space.inline.hpp" 34 #include "gc/shared/spaceDecorator.hpp" 35 #include "logging/log.hpp" 36 #include "logging/logStream.hpp" 37 #include "memory/allocation.inline.hpp" 38 #include "memory/binaryTreeDictionary.inline.hpp" 39 #include "memory/resourceArea.hpp" 40 #include "memory/universe.hpp" 41 #include "oops/access.inline.hpp" 42 #include "oops/compressedOops.inline.hpp" 43 #include "oops/oop.inline.hpp" 44 #include "runtime/globals.hpp" 45 #include "runtime/handles.inline.hpp" 46 #include "runtime/init.hpp" 47 #include "runtime/java.hpp" 48 #include "runtime/orderAccess.hpp" 49 #include "runtime/vmThread.hpp" 50 #include "utilities/align.hpp" 51 #include "utilities/copy.hpp" 52 53 // Specialize for AdaptiveFreeList which tries to avoid 54 // splitting a chunk of a size that is under populated in favor of 55 // an over populated size. The general get_better_list() just returns 56 // the current list. 57 template <> 58 TreeList<FreeChunk, AdaptiveFreeList<FreeChunk> >* 826 } 827 } 828 } 829 830 class FreeListSpaceDCTOC : public FilteringDCTOC { 831 CompactibleFreeListSpace* _cfls; 832 CMSCollector* _collector; 833 bool _parallel; 834 protected: 835 // Override. 836 #define walk_mem_region_with_cl_DECL(ClosureType) \ 837 virtual void walk_mem_region_with_cl(MemRegion mr, \ 838 HeapWord* bottom, HeapWord* top, \ 839 ClosureType* cl); \ 840 void walk_mem_region_with_cl_par(MemRegion mr, \ 841 HeapWord* bottom, HeapWord* top, \ 842 ClosureType* cl); \ 843 void walk_mem_region_with_cl_nopar(MemRegion mr, \ 844 HeapWord* bottom, HeapWord* top, \ 845 ClosureType* cl) 846 walk_mem_region_with_cl_DECL(ExtendedOopClosure); 847 walk_mem_region_with_cl_DECL(FilteringClosure); 848 849 public: 850 FreeListSpaceDCTOC(CompactibleFreeListSpace* sp, 851 CMSCollector* collector, 852 ExtendedOopClosure* cl, 853 CardTable::PrecisionStyle precision, 854 HeapWord* boundary, 855 bool parallel) : 856 FilteringDCTOC(sp, cl, precision, boundary), 857 _cfls(sp), _collector(collector), _parallel(parallel) {} 858 }; 859 860 // We de-virtualize the block-related calls below, since we know that our 861 // space is a CompactibleFreeListSpace. 862 863 #define FreeListSpaceDCTOC__walk_mem_region_with_cl_DEFN(ClosureType) \ 864 void FreeListSpaceDCTOC::walk_mem_region_with_cl(MemRegion mr, \ 865 HeapWord* bottom, \ 866 HeapWord* top, \ 867 ClosureType* cl) { \ 868 if (_parallel) { \ 869 walk_mem_region_with_cl_par(mr, bottom, top, cl); \ 870 } else { \ 871 walk_mem_region_with_cl_nopar(mr, bottom, top, cl); \ 872 } \ 912 bot_size = _cfls->CompactibleFreeListSpace::block_size_nopar(bottom); \ 913 next = bottom + bot_size; \ 914 } \ 915 \ 916 while (bottom < top) { \ 917 if (_cfls->CompactibleFreeListSpace::block_is_obj_nopar(bottom) && \ 918 !_cfls->CompactibleFreeListSpace::obj_allocated_since_save_marks( \ 919 oop(bottom)) && \ 920 !_collector->CMSCollector::is_dead_obj(oop(bottom))) { \ 921 size_t word_sz = oop(bottom)->oop_iterate_size(cl, mr); \ 922 bottom += _cfls->adjustObjectSize(word_sz); \ 923 } else { \ 924 bottom += _cfls->CompactibleFreeListSpace::block_size_nopar(bottom); \ 925 } \ 926 } \ 927 } 928 929 // (There are only two of these, rather than N, because the split is due 930 // only to the introduction of the FilteringClosure, a local part of the 931 // impl of this abstraction.) 932 FreeListSpaceDCTOC__walk_mem_region_with_cl_DEFN(ExtendedOopClosure) 933 FreeListSpaceDCTOC__walk_mem_region_with_cl_DEFN(FilteringClosure) 934 935 DirtyCardToOopClosure* 936 CompactibleFreeListSpace::new_dcto_cl(ExtendedOopClosure* cl, 937 CardTable::PrecisionStyle precision, 938 HeapWord* boundary, 939 bool parallel) { 940 return new FreeListSpaceDCTOC(this, _collector, cl, precision, boundary, parallel); 941 } 942 943 944 // Note on locking for the space iteration functions: 945 // since the collector's iteration activities are concurrent with 946 // allocation activities by mutators, absent a suitable mutual exclusion 947 // mechanism the iterators may go awry. For instance a block being iterated 948 // may suddenly be allocated or divided up and part of it allocated and 949 // so on. 950 951 // Apply the given closure to each block in the space. 952 void CompactibleFreeListSpace::blk_iterate_careful(BlkClosureCareful* cl) { 953 assert_lock_strong(freelistLock()); 954 HeapWord *cur, *limit; 955 for (cur = bottom(), limit = end(); cur < limit; 956 cur += cl->do_blk_careful(cur)); 957 } 958 959 // Apply the given closure to each block in the space. 960 void CompactibleFreeListSpace::blk_iterate(BlkClosure* cl) { 961 assert_lock_strong(freelistLock()); 962 HeapWord *cur, *limit; 963 for (cur = bottom(), limit = end(); cur < limit; 964 cur += cl->do_blk(cur)); 965 } 966 967 // Apply the given closure to each oop in the space. 968 void CompactibleFreeListSpace::oop_iterate(ExtendedOopClosure* cl) { 969 assert_lock_strong(freelistLock()); 970 HeapWord *cur, *limit; 971 size_t curSize; 972 for (cur = bottom(), limit = end(); cur < limit; 973 cur += curSize) { 974 curSize = block_size(cur); 975 if (block_is_obj(cur)) { 976 oop(cur)->oop_iterate(cl); 977 } 978 } 979 } 980 981 // NOTE: In the following methods, in order to safely be able to 982 // apply the closure to an object, we need to be sure that the 983 // object has been initialized. We are guaranteed that an object 984 // is initialized if we are holding the Heap_lock with the 985 // world stopped. 986 void CompactibleFreeListSpace::verify_objects_initialized() const { 987 if (is_init_completed()) { 988 assert_locked_or_safepoint(Heap_lock); | 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "gc/cms/cmsHeap.hpp" 27 #include "gc/cms/cmsLockVerifier.hpp" 28 #include "gc/cms/compactibleFreeListSpace.hpp" 29 #include "gc/cms/concurrentMarkSweepGeneration.inline.hpp" 30 #include "gc/cms/concurrentMarkSweepThread.hpp" 31 #include "gc/shared/blockOffsetTable.inline.hpp" 32 #include "gc/shared/collectedHeap.inline.hpp" 33 #include "gc/shared/genOopClosures.inline.hpp" 34 #include "gc/shared/space.inline.hpp" 35 #include "gc/shared/spaceDecorator.hpp" 36 #include "logging/log.hpp" 37 #include "logging/logStream.hpp" 38 #include "memory/allocation.inline.hpp" 39 #include "memory/binaryTreeDictionary.inline.hpp" 40 #include "memory/iterator.inline.hpp" 41 #include "memory/resourceArea.hpp" 42 #include "memory/universe.hpp" 43 #include "oops/access.inline.hpp" 44 #include "oops/compressedOops.inline.hpp" 45 #include "oops/oop.inline.hpp" 46 #include "runtime/globals.hpp" 47 #include "runtime/handles.inline.hpp" 48 #include "runtime/init.hpp" 49 #include "runtime/java.hpp" 50 #include "runtime/orderAccess.hpp" 51 #include "runtime/vmThread.hpp" 52 #include "utilities/align.hpp" 53 #include "utilities/copy.hpp" 54 55 // Specialize for AdaptiveFreeList which tries to avoid 56 // splitting a chunk of a size that is under populated in favor of 57 // an over populated size. The general get_better_list() just returns 58 // the current list. 59 template <> 60 TreeList<FreeChunk, AdaptiveFreeList<FreeChunk> >* 828 } 829 } 830 } 831 832 class FreeListSpaceDCTOC : public FilteringDCTOC { 833 CompactibleFreeListSpace* _cfls; 834 CMSCollector* _collector; 835 bool _parallel; 836 protected: 837 // Override. 838 #define walk_mem_region_with_cl_DECL(ClosureType) \ 839 virtual void walk_mem_region_with_cl(MemRegion mr, \ 840 HeapWord* bottom, HeapWord* top, \ 841 ClosureType* cl); \ 842 void walk_mem_region_with_cl_par(MemRegion mr, \ 843 HeapWord* bottom, HeapWord* top, \ 844 ClosureType* cl); \ 845 void walk_mem_region_with_cl_nopar(MemRegion mr, \ 846 HeapWord* bottom, HeapWord* top, \ 847 ClosureType* cl) 848 walk_mem_region_with_cl_DECL(OopIterateClosure); 849 walk_mem_region_with_cl_DECL(FilteringClosure); 850 851 public: 852 FreeListSpaceDCTOC(CompactibleFreeListSpace* sp, 853 CMSCollector* collector, 854 OopIterateClosure* cl, 855 CardTable::PrecisionStyle precision, 856 HeapWord* boundary, 857 bool parallel) : 858 FilteringDCTOC(sp, cl, precision, boundary), 859 _cfls(sp), _collector(collector), _parallel(parallel) {} 860 }; 861 862 // We de-virtualize the block-related calls below, since we know that our 863 // space is a CompactibleFreeListSpace. 864 865 #define FreeListSpaceDCTOC__walk_mem_region_with_cl_DEFN(ClosureType) \ 866 void FreeListSpaceDCTOC::walk_mem_region_with_cl(MemRegion mr, \ 867 HeapWord* bottom, \ 868 HeapWord* top, \ 869 ClosureType* cl) { \ 870 if (_parallel) { \ 871 walk_mem_region_with_cl_par(mr, bottom, top, cl); \ 872 } else { \ 873 walk_mem_region_with_cl_nopar(mr, bottom, top, cl); \ 874 } \ 914 bot_size = _cfls->CompactibleFreeListSpace::block_size_nopar(bottom); \ 915 next = bottom + bot_size; \ 916 } \ 917 \ 918 while (bottom < top) { \ 919 if (_cfls->CompactibleFreeListSpace::block_is_obj_nopar(bottom) && \ 920 !_cfls->CompactibleFreeListSpace::obj_allocated_since_save_marks( \ 921 oop(bottom)) && \ 922 !_collector->CMSCollector::is_dead_obj(oop(bottom))) { \ 923 size_t word_sz = oop(bottom)->oop_iterate_size(cl, mr); \ 924 bottom += _cfls->adjustObjectSize(word_sz); \ 925 } else { \ 926 bottom += _cfls->CompactibleFreeListSpace::block_size_nopar(bottom); \ 927 } \ 928 } \ 929 } 930 931 // (There are only two of these, rather than N, because the split is due 932 // only to the introduction of the FilteringClosure, a local part of the 933 // impl of this abstraction.) 934 FreeListSpaceDCTOC__walk_mem_region_with_cl_DEFN(OopIterateClosure) 935 FreeListSpaceDCTOC__walk_mem_region_with_cl_DEFN(FilteringClosure) 936 937 DirtyCardToOopClosure* 938 CompactibleFreeListSpace::new_dcto_cl(OopIterateClosure* cl, 939 CardTable::PrecisionStyle precision, 940 HeapWord* boundary, 941 bool parallel) { 942 return new FreeListSpaceDCTOC(this, _collector, cl, precision, boundary, parallel); 943 } 944 945 946 // Note on locking for the space iteration functions: 947 // since the collector's iteration activities are concurrent with 948 // allocation activities by mutators, absent a suitable mutual exclusion 949 // mechanism the iterators may go awry. For instance a block being iterated 950 // may suddenly be allocated or divided up and part of it allocated and 951 // so on. 952 953 // Apply the given closure to each block in the space. 954 void CompactibleFreeListSpace::blk_iterate_careful(BlkClosureCareful* cl) { 955 assert_lock_strong(freelistLock()); 956 HeapWord *cur, *limit; 957 for (cur = bottom(), limit = end(); cur < limit; 958 cur += cl->do_blk_careful(cur)); 959 } 960 961 // Apply the given closure to each block in the space. 962 void CompactibleFreeListSpace::blk_iterate(BlkClosure* cl) { 963 assert_lock_strong(freelistLock()); 964 HeapWord *cur, *limit; 965 for (cur = bottom(), limit = end(); cur < limit; 966 cur += cl->do_blk(cur)); 967 } 968 969 // Apply the given closure to each oop in the space. 970 void CompactibleFreeListSpace::oop_iterate(OopIterateClosure* cl) { 971 assert_lock_strong(freelistLock()); 972 HeapWord *cur, *limit; 973 size_t curSize; 974 for (cur = bottom(), limit = end(); cur < limit; 975 cur += curSize) { 976 curSize = block_size(cur); 977 if (block_is_obj(cur)) { 978 oop(cur)->oop_iterate(cl); 979 } 980 } 981 } 982 983 // NOTE: In the following methods, in order to safely be able to 984 // apply the closure to an object, we need to be sure that the 985 // object has been initialized. We are guaranteed that an object 986 // is initialized if we are holding the Heap_lock with the 987 // world stopped. 988 void CompactibleFreeListSpace::verify_objects_initialized() const { 989 if (is_init_completed()) { 990 assert_locked_or_safepoint(Heap_lock); |