src/hotspot/share/gc/g1/heapRegionManager.cpp
changeset 59060 fce1fa1bdc91
parent 58084 cddef3bde924
child 59062 6530de931b8e
equal deleted inserted replaced
59059:27a266d5fb13 59060:fce1fa1bdc91
    28 #include "gc/g1/g1ConcurrentRefine.hpp"
    28 #include "gc/g1/g1ConcurrentRefine.hpp"
    29 #include "gc/g1/heapRegion.hpp"
    29 #include "gc/g1/heapRegion.hpp"
    30 #include "gc/g1/heapRegionManager.inline.hpp"
    30 #include "gc/g1/heapRegionManager.inline.hpp"
    31 #include "gc/g1/heapRegionSet.inline.hpp"
    31 #include "gc/g1/heapRegionSet.inline.hpp"
    32 #include "gc/g1/heterogeneousHeapRegionManager.hpp"
    32 #include "gc/g1/heterogeneousHeapRegionManager.hpp"
       
    33 #include "logging/logStream.hpp"
    33 #include "memory/allocation.hpp"
    34 #include "memory/allocation.hpp"
    34 #include "utilities/bitMap.inline.hpp"
    35 #include "utilities/bitMap.inline.hpp"
    35 
    36 
    36 class MasterFreeRegionListChecker : public HeapRegionSetChecker {
    37 class MasterFreeRegionListChecker : public HeapRegionSetChecker {
    37 public:
    38 public:
   101 
   102 
   102 bool HeapRegionManager::is_available(uint region) const {
   103 bool HeapRegionManager::is_available(uint region) const {
   103   return _available_map.at(region);
   104   return _available_map.at(region);
   104 }
   105 }
   105 
   106 
       
   107 HeapRegion* HeapRegionManager::allocate_free_region(HeapRegionType type, uint requested_node_index) {
       
   108   HeapRegion* hr = NULL;
       
   109   bool from_head = !type.is_young();
       
   110 
       
   111   if (requested_node_index != G1NUMA::AnyNodeIndex && G1NUMA::numa()->is_enabled()) {
       
   112     // Try to allocate with requested node index.
       
   113     hr = _free_list.remove_region_with_node_index(from_head, requested_node_index, NULL);
       
   114   }
       
   115 
       
   116   if (hr == NULL) {
       
   117     // If there's a single active node or we did not get a region from our requested node,
       
   118     // try without requested node index.
       
   119     hr = _free_list.remove_region(from_head);
       
   120   }
       
   121 
       
   122   if (hr != NULL) {
       
   123     assert(hr->next() == NULL, "Single region should not have next");
       
   124     assert(is_available(hr->hrm_index()), "Must be committed");
       
   125   }
       
   126 
       
   127   return hr;
       
   128 }
       
   129 
   106 #ifdef ASSERT
   130 #ifdef ASSERT
   107 bool HeapRegionManager::is_free(HeapRegion* hr) const {
   131 bool HeapRegionManager::is_free(HeapRegion* hr) const {
   108   return _free_list.contains(hr);
   132   return _free_list.contains(hr);
   109 }
   133 }
   110 #endif
   134 #endif
   136 }
   160 }
   137 
   161 
   138 void HeapRegionManager::uncommit_regions(uint start, size_t num_regions) {
   162 void HeapRegionManager::uncommit_regions(uint start, size_t num_regions) {
   139   guarantee(num_regions >= 1, "Need to specify at least one region to uncommit, tried to uncommit zero regions at %u", start);
   163   guarantee(num_regions >= 1, "Need to specify at least one region to uncommit, tried to uncommit zero regions at %u", start);
   140   guarantee(_num_committed >= num_regions, "pre-condition");
   164   guarantee(_num_committed >= num_regions, "pre-condition");
       
   165 
       
   166   // Reset node index to distinguish with committed regions.
       
   167   for (uint i = start; i < start + num_regions; i++) {
       
   168     at(i)->set_node_index(G1NUMA::UnknownNodeIndex);
       
   169   }
   141 
   170 
   142   // Print before uncommitting.
   171   // Print before uncommitting.
   143   if (G1CollectedHeap::heap()->hr_printer()->is_active()) {
   172   if (G1CollectedHeap::heap()->hr_printer()->is_active()) {
   144     for (uint i = start; i < start + num_regions; i++) {
   173     for (uint i = start; i < start + num_regions; i++) {
   145       HeapRegion* hr = at(i);
   174       HeapRegion* hr = at(i);
   184     }
   213     }
   185     HeapWord* bottom = G1CollectedHeap::heap()->bottom_addr_for_region(i);
   214     HeapWord* bottom = G1CollectedHeap::heap()->bottom_addr_for_region(i);
   186     MemRegion mr(bottom, bottom + HeapRegion::GrainWords);
   215     MemRegion mr(bottom, bottom + HeapRegion::GrainWords);
   187 
   216 
   188     hr->initialize(mr);
   217     hr->initialize(mr);
       
   218     hr->set_node_index(G1NUMA::numa()->index_for_region(hr));
   189     insert_into_free_list(at(i));
   219     insert_into_free_list(at(i));
   190   }
   220   }
   191 }
   221 }
   192 
   222 
   193 MemoryUsage HeapRegionManager::get_auxiliary_data_memory_usage() const {
   223 MemoryUsage HeapRegionManager::get_auxiliary_data_memory_usage() const {
   231     cur = idx_last_found + num_last_found + 1;
   261     cur = idx_last_found + num_last_found + 1;
   232   }
   262   }
   233 
   263 
   234   verify_optional();
   264   verify_optional();
   235   return expanded;
   265   return expanded;
       
   266 }
       
   267 
       
   268 uint HeapRegionManager::expand_on_preferred_node(uint preferred_index) {
       
   269   uint expand_candidate = UINT_MAX;
       
   270   for (uint i = 0; i < max_length(); i++) {
       
   271     if (is_available(i)) {
       
   272       // Already in use continue
       
   273       continue;
       
   274     }
       
   275     // Always save the candidate so we can expand later on.
       
   276     expand_candidate = i;
       
   277     if (is_on_preferred_index(expand_candidate, preferred_index)) {
       
   278       // We have found a candidate on the preffered node, break.
       
   279       break;
       
   280     }
       
   281   }
       
   282 
       
   283   if (expand_candidate == UINT_MAX) {
       
   284      // No regions left, expand failed.
       
   285     return 0;
       
   286   }
       
   287 
       
   288   make_regions_available(expand_candidate, 1, NULL);
       
   289   return 1;
       
   290 }
       
   291 
       
   292 bool HeapRegionManager::is_on_preferred_index(uint region_index, uint preferred_node_index) {
       
   293   uint region_node_index = G1NUMA::numa()->preferred_node_index_for_index(region_index);
       
   294   return region_node_index == preferred_node_index;
   236 }
   295 }
   237 
   296 
   238 uint HeapRegionManager::find_contiguous(size_t num, bool empty_only) {
   297 uint HeapRegionManager::find_contiguous(size_t num, bool empty_only) {
   239   uint found = 0;
   298   uint found = 0;
   240   size_t length_found = 0;
   299   size_t length_found = 0;