129 // and after the call to save marks. |
129 // and after the call to save marks. |
130 virtual MemRegion used_region_at_save_marks() const { |
130 virtual MemRegion used_region_at_save_marks() const { |
131 return MemRegion(bottom(), saved_mark_word()); |
131 return MemRegion(bottom(), saved_mark_word()); |
132 } |
132 } |
133 |
133 |
134 // Initialization |
134 // Initialization. These may be run to reset an existing |
135 virtual void initialize(MemRegion mr, bool clear_space); |
135 // Space. |
136 virtual void clear(); |
136 virtual void initialize(MemRegion mr, bool clear_space, bool mangle_space); |
|
137 virtual void clear(bool mangle_space); |
137 |
138 |
138 // For detecting GC bugs. Should only be called at GC boundaries, since |
139 // For detecting GC bugs. Should only be called at GC boundaries, since |
139 // some unused space may be used as scratch space during GC's. |
140 // some unused space may be used as scratch space during GC's. |
140 // Default implementation does nothing. We also call this when expanding |
141 // Default implementation does nothing. We also call this when expanding |
141 // a space to satisfy an allocation request. See bug #4668531 |
142 // a space to satisfy an allocation request. See bug #4668531 |
142 virtual void mangle_unused_area() {} |
143 virtual void mangle_unused_area() {} |
|
144 virtual void mangle_unused_area_complete() {} |
143 virtual void mangle_region(MemRegion mr) {} |
145 virtual void mangle_region(MemRegion mr) {} |
144 |
146 |
145 // Testers |
147 // Testers |
146 bool is_empty() const { return used() == 0; } |
148 bool is_empty() const { return used() == 0; } |
147 bool not_empty() const { return used() > 0; } |
149 bool not_empty() const { return used() > 0; } |
722 /* space subtypes. For example, OffsetTableContigSpace's that were */ \ |
724 /* space subtypes. For example, OffsetTableContigSpace's that were */ \ |
723 /* compacted into will have had their offset table thresholds updated */ \ |
725 /* compacted into will have had their offset table thresholds updated */ \ |
724 /* continuously, but those that weren't need to have their thresholds */ \ |
726 /* continuously, but those that weren't need to have their thresholds */ \ |
725 /* re-initialized. Also mangles unused area for debugging. */ \ |
727 /* re-initialized. Also mangles unused area for debugging. */ \ |
726 if (is_empty()) { \ |
728 if (is_empty()) { \ |
727 clear(); \ |
729 clear(SpaceDecorator::Mangle); \ |
728 } else { \ |
730 } else { \ |
729 if (ZapUnusedHeapArea) mangle_unused_area(); \ |
731 if (ZapUnusedHeapArea) mangle_unused_area(); \ |
730 } \ |
732 } \ |
731 } |
733 } |
|
734 |
|
735 class GenSpaceMangler; |
732 |
736 |
733 // A space in which the free area is contiguous. It therefore supports |
737 // A space in which the free area is contiguous. It therefore supports |
734 // faster allocation, and compaction. |
738 // faster allocation, and compaction. |
735 class ContiguousSpace: public CompactibleSpace { |
739 class ContiguousSpace: public CompactibleSpace { |
736 friend class OneContigSpaceCardGeneration; |
740 friend class OneContigSpaceCardGeneration; |
737 friend class VMStructs; |
741 friend class VMStructs; |
738 protected: |
742 protected: |
739 HeapWord* _top; |
743 HeapWord* _top; |
740 HeapWord* _concurrent_iteration_safe_limit; |
744 HeapWord* _concurrent_iteration_safe_limit; |
|
745 // A helper for mangling the unused area of the space in debug builds. |
|
746 GenSpaceMangler* _mangler; |
|
747 |
|
748 GenSpaceMangler* mangler() { return _mangler; } |
741 |
749 |
742 // Allocation helpers (return NULL if full). |
750 // Allocation helpers (return NULL if full). |
743 inline HeapWord* allocate_impl(size_t word_size, HeapWord* end_value); |
751 inline HeapWord* allocate_impl(size_t word_size, HeapWord* end_value); |
744 inline HeapWord* par_allocate_impl(size_t word_size, HeapWord* end_value); |
752 inline HeapWord* par_allocate_impl(size_t word_size, HeapWord* end_value); |
745 |
753 |
746 public: |
754 public: |
747 virtual void initialize(MemRegion mr, bool clear_space); |
755 |
|
756 ContiguousSpace(); |
|
757 ~ContiguousSpace(); |
|
758 |
|
759 virtual void initialize(MemRegion mr, bool clear_space, bool mangle_space); |
748 |
760 |
749 // Accessors |
761 // Accessors |
750 HeapWord* top() const { return _top; } |
762 HeapWord* top() const { return _top; } |
751 void set_top(HeapWord* value) { _top = value; } |
763 void set_top(HeapWord* value) { _top = value; } |
752 |
764 |
753 void set_saved_mark() { _saved_mark_word = top(); } |
765 void set_saved_mark() { _saved_mark_word = top(); } |
754 void reset_saved_mark() { _saved_mark_word = bottom(); } |
766 void reset_saved_mark() { _saved_mark_word = bottom(); } |
755 |
767 |
756 virtual void clear(); |
768 virtual void clear(bool mangle_space); |
757 |
769 |
758 WaterMark bottom_mark() { return WaterMark(this, bottom()); } |
770 WaterMark bottom_mark() { return WaterMark(this, bottom()); } |
759 WaterMark top_mark() { return WaterMark(this, top()); } |
771 WaterMark top_mark() { return WaterMark(this, top()); } |
760 WaterMark saved_mark() { return WaterMark(this, saved_mark_word()); } |
772 WaterMark saved_mark() { return WaterMark(this, saved_mark_word()); } |
761 bool saved_mark_at_top() const { return saved_mark_word() == top(); } |
773 bool saved_mark_at_top() const { return saved_mark_word() == top(); } |
762 |
774 |
763 void mangle_unused_area(); |
775 // In debug mode mangle (write it with a particular bit |
764 void mangle_region(MemRegion mr); |
776 // pattern) the unused part of a space. |
|
777 |
|
778 // Used to save the an address in a space for later use during mangling. |
|
779 void set_top_for_allocations(HeapWord* v) PRODUCT_RETURN; |
|
780 // Used to save the space's current top for later use during mangling. |
|
781 void set_top_for_allocations() PRODUCT_RETURN; |
|
782 |
|
783 // Mangle regions in the space from the current top up to the |
|
784 // previously mangled part of the space. |
|
785 void mangle_unused_area() PRODUCT_RETURN; |
|
786 // Mangle [top, end) |
|
787 void mangle_unused_area_complete() PRODUCT_RETURN; |
|
788 // Mangle the given MemRegion. |
|
789 void mangle_region(MemRegion mr) PRODUCT_RETURN; |
|
790 |
|
791 // Do some sparse checking on the area that should have been mangled. |
|
792 void check_mangled_unused_area(HeapWord* limit) PRODUCT_RETURN; |
|
793 // Check the complete area that should have been mangled. |
|
794 // This code may be NULL depending on the macro DEBUG_MANGLING. |
|
795 void check_mangled_unused_area_complete() PRODUCT_RETURN; |
765 |
796 |
766 // Size computations: sizes in bytes. |
797 // Size computations: sizes in bytes. |
767 size_t capacity() const { return byte_size(bottom(), end()); } |
798 size_t capacity() const { return byte_size(bottom(), end()); } |
768 size_t used() const { return byte_size(bottom(), top()); } |
799 size_t used() const { return byte_size(bottom(), top()); } |
769 size_t free() const { return byte_size(top(), end()); } |
800 size_t free() const { return byte_size(top(), end()); } |