src/share/vm/gc_implementation/g1/heapRegionManager.hpp

Print this page
rev 7056 : [mq]: 8058298
rev 7057 : imported patch review


  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 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONMANAGER_HPP
  26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONMANAGER_HPP
  27 
  28 #include "gc_implementation/g1/g1BiasedArray.hpp"
  29 #include "gc_implementation/g1/g1RegionToSpaceMapper.hpp"
  30 #include "gc_implementation/g1/heapRegionSet.hpp"
  31 
  32 class HeapRegion;
  33 class HeapRegionClosure;

  34 class FreeRegionList;
  35 
  36 class G1HeapRegionTable : public G1BiasedMappedArray<HeapRegion*> {
  37  protected:
  38   virtual HeapRegion* default_value() const { return NULL; }
  39 };
  40 
  41 // This class keeps track of the actual heap memory, auxiliary data
  42 // and its metadata (i.e., HeapRegion instances) and the list of free regions.
  43 //
  44 // This allows maximum flexibility for deciding what to commit or uncommit given
  45 // a request from outside.
  46 //
  47 // HeapRegions are kept in the _regions array in address order. A region's
  48 // index in the array corresponds to its index in the heap (i.e., 0 is the
  49 // region at the bottom of the heap, 1 is the one after it, etc.). Two
  50 // regions that are consecutive in the array should also be adjacent in the
  51 // address space (i.e., region(i).end() == region(i+1).bottom().
  52 //
  53 // We create a HeapRegion when we commit the region's address space


 216   uint find_contiguous_empty_or_unavailable(size_t num) { return find_contiguous(num, false); }
 217 
 218   HeapRegion* next_region_in_heap(const HeapRegion* r) const;
 219 
 220   // Apply blk->doHeapRegion() on all committed regions in address order,
 221   // terminating the iteration early if doHeapRegion() returns true.
 222   void iterate(HeapRegionClosure* blk) const;
 223 
 224   void par_iterate(HeapRegionClosure* blk, uint worker_id, HeapRegionClaimer* hrclaimer) const;
 225 
 226   // Uncommit up to num_regions_to_remove regions that are completely free.
 227   // Return the actual number of uncommitted regions.
 228   uint shrink_by(uint num_regions_to_remove);
 229 
 230   void verify();
 231 
 232   // Do some sanity checking.
 233   void verify_optional() PRODUCT_RETURN;
 234 };
 235 







































 236 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONMANAGER_HPP
 237 


  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 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONMANAGER_HPP
  26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONMANAGER_HPP
  27 
  28 #include "gc_implementation/g1/g1BiasedArray.hpp"
  29 #include "gc_implementation/g1/g1RegionToSpaceMapper.hpp"
  30 #include "gc_implementation/g1/heapRegionSet.hpp"
  31 
  32 class HeapRegion;
  33 class HeapRegionClosure;
  34 class HeapRegionClaimer;
  35 class FreeRegionList;
  36 
  37 class G1HeapRegionTable : public G1BiasedMappedArray<HeapRegion*> {
  38  protected:
  39   virtual HeapRegion* default_value() const { return NULL; }
  40 };
  41 
  42 // This class keeps track of the actual heap memory, auxiliary data
  43 // and its metadata (i.e., HeapRegion instances) and the list of free regions.
  44 //
  45 // This allows maximum flexibility for deciding what to commit or uncommit given
  46 // a request from outside.
  47 //
  48 // HeapRegions are kept in the _regions array in address order. A region's
  49 // index in the array corresponds to its index in the heap (i.e., 0 is the
  50 // region at the bottom of the heap, 1 is the one after it, etc.). Two
  51 // regions that are consecutive in the array should also be adjacent in the
  52 // address space (i.e., region(i).end() == region(i+1).bottom().
  53 //
  54 // We create a HeapRegion when we commit the region's address space


 217   uint find_contiguous_empty_or_unavailable(size_t num) { return find_contiguous(num, false); }
 218 
 219   HeapRegion* next_region_in_heap(const HeapRegion* r) const;
 220 
 221   // Apply blk->doHeapRegion() on all committed regions in address order,
 222   // terminating the iteration early if doHeapRegion() returns true.
 223   void iterate(HeapRegionClosure* blk) const;
 224 
 225   void par_iterate(HeapRegionClosure* blk, uint worker_id, HeapRegionClaimer* hrclaimer) const;
 226 
 227   // Uncommit up to num_regions_to_remove regions that are completely free.
 228   // Return the actual number of uncommitted regions.
 229   uint shrink_by(uint num_regions_to_remove);
 230 
 231   void verify();
 232 
 233   // Do some sanity checking.
 234   void verify_optional() PRODUCT_RETURN;
 235 };
 236 
 237 // The HeapRegionClaimer is used during parallel iteration over heap regions,
 238 // allowing workers to claim heap regions, gaining exclusive rights to these regions.
 239 class HeapRegionClaimer : public StackObj {
 240   uint  _n_workers;
 241   uint  _n_regions;
 242   uint* _claims;
 243 
 244   static const uint Unclaimed = 0;
 245   static const uint Claimed   = 1;
 246 
 247  public:
 248   HeapRegionClaimer() : _n_workers(0), _n_regions(0), _claims(NULL) {}
 249 
 250   HeapRegionClaimer(uint n_workers) : _n_workers(n_workers), _n_regions(0), _claims(NULL) {
 251     initialize(n_workers);
 252   }
 253 
 254   ~HeapRegionClaimer() {
 255     if (_claims != NULL) {
 256       FREE_C_HEAP_ARRAY(uint, _claims, mtGC);
 257     }
 258   }
 259 
 260   inline uint n_regions() const {
 261     return _n_regions;
 262   }
 263 
 264   void initialize(uint n_workers);
 265 
 266   // Calculate the starting region for given worker so
 267   // that they do not all start from the same region.
 268   uint start_region_for_worker(uint worker_id) const;
 269 
 270   // Check if region has been claimed with this HRClaimer.
 271   bool is_region_claimed(uint region_index) const;
 272 
 273   // Claim the given region, returns true if successfully claimed.
 274   bool claim_region(uint region_index);
 275 };
 276 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONMANAGER_HPP
 277