54 // address space (i.e., region(i).end() == region(i+1).bottom().
55 //
56 // We create a HeapRegion when we commit the region's address space
57 // for the first time. When we uncommit the address space of a
58 // region we retain the HeapRegion to be able to re-use it in the
59 // future (in case we recommit it).
60 //
61 // We keep track of three lengths:
62 //
63 // * _num_committed (returned by length()) is the number of currently
64 // committed regions. These may not be contiguous.
65 // * _allocated_heapregions_length (not exposed outside this class) is the
66 // number of regions+1 for which we have HeapRegions.
67 // * max_length() returns the maximum number of regions the heap can have.
68 //
69
70 class HeapRegionManager: public CHeapObj<mtGC> {
71 friend class VMStructs;
72 friend class HeapRegionClaimer;
73
74 protected:
75 G1HeapRegionTable _regions;
76 G1RegionToSpaceMapper* _heap_mapper;
77 private:
78 G1RegionToSpaceMapper* _prev_bitmap_mapper;
79 G1RegionToSpaceMapper* _next_bitmap_mapper;
80 G1RegionToSpaceMapper* _bot_mapper;
81 G1RegionToSpaceMapper* _cardtable_mapper;
82 G1RegionToSpaceMapper* _card_counts_mapper;
83
84 protected:
85 FreeRegionList _free_list;
86 private:
87
88 // Each bit in this bitmap indicates that the corresponding region is available
89 // for allocation.
90 CHeapBitMap _available_map;
91
92 // The number of regions committed in the heap.
93 uint _num_committed;
94
95 // Internal only. The highest heap region +1 we allocated a HeapRegion instance for.
96 uint _allocated_heapregions_length;
97
98 HeapWord* heap_bottom() const { return _regions.bottom_address_mapped(); }
99 HeapWord* heap_end() const {return _regions.end_address_mapped(); }
100
101 protected:
102 void make_regions_available(uint index, uint num_regions = 1, WorkGang* pretouch_gang = NULL);
103 void uncommit_regions(uint index, size_t num_regions = 1);
104 private:
105 // Pass down commit calls to the VirtualSpace.
106 void commit_regions(uint index, size_t num_regions = 1, WorkGang* pretouch_gang = NULL);
107
108 // Notify other data structures about change in the heap layout.
109 void update_committed_space(HeapWord* old_end, HeapWord* new_end);
110
111 // Find a contiguous set of empty or uncommitted regions of length num and return
112 // the index of the first region or G1_NO_HRM_INDEX if the search was unsuccessful.
113 // If only_empty is true, only empty regions are considered.
114 // Searches from bottom to top of the heap, doing a first-fit.
115 uint find_contiguous(size_t num, bool only_empty);
116 // Finds the next sequence of unavailable regions starting from start_idx. Returns the
117 // length of the sequence found. If this result is zero, no such sequence could be found,
118 // otherwise res_idx indicates the start index of these regions.
119 uint find_unavailable_from_idx(uint start_idx, uint* res_idx) const;
120 // Finds the next sequence of empty regions starting from start_idx, going backwards in
121 // the heap. Returns the length of the sequence found. If this value is zero, no
122 // sequence could be found, otherwise res_idx contains the start index of this range.
123 uint find_empty_from_idx_reverse(uint start_idx, uint* res_idx) const;
124 #ifdef ASSERT
125 public:
126 bool is_free(HeapRegion* hr) const;
127 #endif
128 protected:
129 // Allocate a new HeapRegion for the given index.
130 HeapRegion* new_heap_region(uint hrm_index);
131 public:
132 // Empty constructor, we'll initialize it with the initialize() method.
133 HeapRegionManager();
134
135 void initialize(G1RegionToSpaceMapper* heap_storage,
136 G1RegionToSpaceMapper* prev_bitmap,
137 G1RegionToSpaceMapper* next_bitmap,
138 G1RegionToSpaceMapper* bot,
139 G1RegionToSpaceMapper* cardtable,
140 G1RegionToSpaceMapper* card_counts);
141
142 // Return the "dummy" region used for G1AllocRegion. This is currently a hardwired
143 // new HeapRegion that owns HeapRegion at index 0. Since at the moment we commit
144 // the heap from the lowest address, this region (and its associated data
145 // structures) are available and we do not need to check further.
146 virtual HeapRegion* get_dummy_region() { return new_heap_region(0); }
147
148 // Return the HeapRegion at the given index. Assume that the index
149 // is valid.
150 inline HeapRegion* at(uint index) const;
151
152 // Return the HeapRegion at the given index, NULL if the index
153 // is for an unavailable region.
154 inline HeapRegion* at_or_null(uint index) const;
155
156 // Returns whether the given region is available for allocation.
157 bool is_available(uint region) const;
158
159 // Return the next region (by index) that is part of the same
160 // humongous object that hr is part of.
|
54 // address space (i.e., region(i).end() == region(i+1).bottom().
55 //
56 // We create a HeapRegion when we commit the region's address space
57 // for the first time. When we uncommit the address space of a
58 // region we retain the HeapRegion to be able to re-use it in the
59 // future (in case we recommit it).
60 //
61 // We keep track of three lengths:
62 //
63 // * _num_committed (returned by length()) is the number of currently
64 // committed regions. These may not be contiguous.
65 // * _allocated_heapregions_length (not exposed outside this class) is the
66 // number of regions+1 for which we have HeapRegions.
67 // * max_length() returns the maximum number of regions the heap can have.
68 //
69
70 class HeapRegionManager: public CHeapObj<mtGC> {
71 friend class VMStructs;
72 friend class HeapRegionClaimer;
73
74 G1RegionToSpaceMapper* _prev_bitmap_mapper;
75 G1RegionToSpaceMapper* _next_bitmap_mapper;
76 G1RegionToSpaceMapper* _bot_mapper;
77 G1RegionToSpaceMapper* _cardtable_mapper;
78 G1RegionToSpaceMapper* _card_counts_mapper;
79
80 // Each bit in this bitmap indicates that the corresponding region is available
81 // for allocation.
82 CHeapBitMap _available_map;
83
84 // The number of regions committed in the heap.
85 uint _num_committed;
86
87 // Internal only. The highest heap region +1 we allocated a HeapRegion instance for.
88 uint _allocated_heapregions_length;
89
90 HeapWord* heap_bottom() const { return _regions.bottom_address_mapped(); }
91 HeapWord* heap_end() const {return _regions.end_address_mapped(); }
92
93 // Pass down commit calls to the VirtualSpace.
94 void commit_regions(uint index, size_t num_regions = 1, WorkGang* pretouch_gang = NULL);
95
96 // Notify other data structures about change in the heap layout.
97 void update_committed_space(HeapWord* old_end, HeapWord* new_end);
98
99 // Find a contiguous set of empty or uncommitted regions of length num and return
100 // the index of the first region or G1_NO_HRM_INDEX if the search was unsuccessful.
101 // If only_empty is true, only empty regions are considered.
102 // Searches from bottom to top of the heap, doing a first-fit.
103 uint find_contiguous(size_t num, bool only_empty);
104 // Finds the next sequence of unavailable regions starting from start_idx. Returns the
105 // length of the sequence found. If this result is zero, no such sequence could be found,
106 // otherwise res_idx indicates the start index of these regions.
107 uint find_unavailable_from_idx(uint start_idx, uint* res_idx) const;
108 // Finds the next sequence of empty regions starting from start_idx, going backwards in
109 // the heap. Returns the length of the sequence found. If this value is zero, no
110 // sequence could be found, otherwise res_idx contains the start index of this range.
111 uint find_empty_from_idx_reverse(uint start_idx, uint* res_idx) const;
112
113 protected:
114 G1HeapRegionTable _regions;
115 G1RegionToSpaceMapper* _heap_mapper;
116 FreeRegionList _free_list;
117 void make_regions_available(uint index, uint num_regions = 1, WorkGang* pretouch_gang = NULL);
118 void uncommit_regions(uint index, size_t num_regions = 1);
119 // Allocate a new HeapRegion for the given index.
120 HeapRegion* new_heap_region(uint hrm_index);
121 #ifdef ASSERT
122 public:
123 bool is_free(HeapRegion* hr) const;
124 #endif
125 public:
126 // Empty constructor, we'll initialize it with the initialize() method.
127 HeapRegionManager();
128
129 static HeapRegionManager* create_manager(G1CollectedHeap* heap, CollectorPolicy* policy);
130
131 void initialize(G1RegionToSpaceMapper* heap_storage,
132 G1RegionToSpaceMapper* prev_bitmap,
133 G1RegionToSpaceMapper* next_bitmap,
134 G1RegionToSpaceMapper* bot,
135 G1RegionToSpaceMapper* cardtable,
136 G1RegionToSpaceMapper* card_counts);
137
138 // Prepare heap regions before and after full collection.
139 // Nothing to be done in this class.
140 virtual void prepare_for_full_collection_start() {}
141 virtual void prepare_for_full_collection_end() {}
142
143 // Return the "dummy" region used for G1AllocRegion. This is currently a hardwired
144 // new HeapRegion that owns HeapRegion at index 0. Since at the moment we commit
145 // the heap from the lowest address, this region (and its associated data
146 // structures) are available and we do not need to check further.
147 virtual HeapRegion* get_dummy_region() { return new_heap_region(0); }
148
149 // Return the HeapRegion at the given index. Assume that the index
150 // is valid.
151 inline HeapRegion* at(uint index) const;
152
153 // Return the HeapRegion at the given index, NULL if the index
154 // is for an unavailable region.
155 inline HeapRegion* at_or_null(uint index) const;
156
157 // Returns whether the given region is available for allocation.
158 bool is_available(uint region) const;
159
160 // Return the next region (by index) that is part of the same
161 // humongous object that hr is part of.
|