< prev index next >

src/share/vm/gc/parallel/adjoiningGenerations.cpp

Print this page




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  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/parallel/adjoiningGenerations.hpp"
  27 #include "gc/parallel/adjoiningVirtualSpaces.hpp"
  28 #include "gc/parallel/generationSizer.hpp"
  29 #include "gc/parallel/parallelScavengeHeap.hpp"



  30 
  31 // If boundary moving is being used, create the young gen and old
  32 // gen with ASPSYoungGen and ASPSOldGen, respectively.  Revert to
  33 // the old behavior otherwise (with PSYoungGen and PSOldGen).
  34 
  35 AdjoiningGenerations::AdjoiningGenerations(ReservedSpace old_young_rs,
  36                                            GenerationSizer* policy,
  37                                            size_t alignment) :
  38   _virtual_spaces(old_young_rs, policy->min_old_size(),
  39                   policy->min_young_size(), alignment) {
  40   size_t init_low_byte_size = policy->initial_old_size();
  41   size_t min_low_byte_size = policy->min_old_size();
  42   size_t max_low_byte_size = policy->max_old_size();
  43   size_t init_high_byte_size = policy->initial_young_size();
  44   size_t min_high_byte_size = policy->min_young_size();
  45   size_t max_high_byte_size = policy->max_young_size();
  46 
  47   assert(min_low_byte_size <= init_low_byte_size &&
  48          init_low_byte_size <= max_low_byte_size, "Parameter check");
  49   assert(min_high_byte_size <= init_high_byte_size &&


  99                                 min_high_byte_size,
 100                                 max_high_byte_size);
 101     _old_gen = new PSOldGen(init_low_byte_size,
 102                             min_low_byte_size,
 103                             max_low_byte_size,
 104                             "old", 1);
 105 
 106     // The virtual spaces are created by the initialization of the gens.
 107     _young_gen->initialize(young_rs, alignment);
 108     assert(young_gen()->gen_size_limit() == young_rs.size(),
 109       "Consistency check");
 110     _old_gen->initialize(old_rs, alignment, "old", 1);
 111     assert(old_gen()->gen_size_limit() == old_rs.size(), "Consistency check");
 112   }
 113 }
 114 
 115 size_t AdjoiningGenerations::reserved_byte_size() {
 116   return virtual_spaces()->reserved_space().size();
 117 }
 118 























 119 
 120 // Make checks on the current sizes of the generations and
 121 // the constraints on the sizes of the generations.  Push
 122 // up the boundary within the constraints.  A partial
 123 // push can occur.
 124 void AdjoiningGenerations::request_old_gen_expansion(size_t expand_in_bytes) {
 125   assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check");
 126 
 127   assert_lock_strong(ExpandHeap_lock);
 128   assert_locked_or_safepoint(Heap_lock);
 129 
 130   // These sizes limit the amount the boundaries can move.  Effectively,
 131   // the generation says how much it is willing to yield to the other
 132   // generation.
 133   const size_t young_gen_available = young_gen()->available_for_contraction();
 134   const size_t old_gen_available = old_gen()->available_for_expansion();
 135   const size_t alignment = virtual_spaces()->alignment();
 136   size_t change_in_bytes = MIN3(young_gen_available,
 137                                 old_gen_available,
 138                                 align_size_up_(expand_in_bytes, alignment));
 139 
 140   if (change_in_bytes == 0) {
 141     return;
 142   }
 143 
 144   if (TraceAdaptiveGCBoundary) {
 145     gclog_or_tty->print_cr("Before expansion of old gen with boundary move");
 146     gclog_or_tty->print_cr("  Requested change: " SIZE_FORMAT_HEX
 147                            "  Attempted change: " SIZE_FORMAT_HEX,
 148       expand_in_bytes, change_in_bytes);
 149     if (!PrintHeapAtGC) {
 150       Universe::print_on(gclog_or_tty);
 151     }
 152     gclog_or_tty->print_cr("  PSOldGen max size: " SIZE_FORMAT "K",
 153       old_gen()->max_gen_size()/K);
 154   }
 155 
 156   // Move the boundary between the generations up (smaller young gen).
 157   if (virtual_spaces()->adjust_boundary_up(change_in_bytes)) {
 158     young_gen()->reset_after_change();
 159     old_gen()->reset_after_change();
 160   }
 161 
 162   // The total reserved for the generations should match the sum
 163   // of the two even if the boundary is moving.
 164   assert(reserved_byte_size() ==
 165          old_gen()->max_gen_size() + young_gen()->max_size(),
 166          "Space is missing");
 167   young_gen()->space_invariants();
 168   old_gen()->space_invariants();
 169 
 170   if (TraceAdaptiveGCBoundary) {
 171     gclog_or_tty->print_cr("After expansion of old gen with boundary move");
 172     if (!PrintHeapAtGC) {
 173       Universe::print_on(gclog_or_tty);
 174     }
 175     gclog_or_tty->print_cr("  PSOldGen max size: " SIZE_FORMAT "K",
 176       old_gen()->max_gen_size()/K);
 177   }
 178 }
 179 
 180 // See comments on request_old_gen_expansion()
 181 bool AdjoiningGenerations::request_young_gen_expansion(size_t expand_in_bytes) {
 182   assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check");
 183 
 184   // If eden is not empty, the boundary can be moved but no advantage
 185   // can be made of the move since eden cannot be moved.
 186   if (!young_gen()->eden_space()->is_empty()) {
 187     return false;
 188   }
 189 
 190 
 191   bool result = false;
 192   const size_t young_gen_available = young_gen()->available_for_expansion();
 193   const size_t old_gen_available = old_gen()->available_for_contraction();
 194   const size_t alignment = virtual_spaces()->alignment();
 195   size_t change_in_bytes = MIN3(young_gen_available,
 196                                 old_gen_available,
 197                                 align_size_up_(expand_in_bytes, alignment));
 198 
 199   if (change_in_bytes == 0) {
 200     return false;
 201   }
 202 
 203   if (TraceAdaptiveGCBoundary) {
 204     gclog_or_tty->print_cr("Before expansion of young gen with boundary move");
 205     gclog_or_tty->print_cr("  Requested change: " SIZE_FORMAT_HEX "  Attempted change: " SIZE_FORMAT_HEX,
 206       expand_in_bytes, change_in_bytes);
 207     if (!PrintHeapAtGC) {
 208       Universe::print_on(gclog_or_tty);
 209     }
 210     gclog_or_tty->print_cr("  PSYoungGen max size: " SIZE_FORMAT "K",
 211       young_gen()->max_size()/K);
 212   }
 213 
 214   // Move the boundary between the generations down (smaller old gen).
 215   MutexLocker x(ExpandHeap_lock);
 216   if (virtual_spaces()->adjust_boundary_down(change_in_bytes)) {
 217     young_gen()->reset_after_change();
 218     old_gen()->reset_after_change();
 219     result = true;
 220   }
 221 
 222   // The total reserved for the generations should match the sum
 223   // of the two even if the boundary is moving.
 224   assert(reserved_byte_size() ==
 225          old_gen()->max_gen_size() + young_gen()->max_size(),
 226          "Space is missing");
 227   young_gen()->space_invariants();
 228   old_gen()->space_invariants();
 229 
 230   if (TraceAdaptiveGCBoundary) {
 231     gclog_or_tty->print_cr("After expansion of young gen with boundary move");
 232     if (!PrintHeapAtGC) {
 233       Universe::print_on(gclog_or_tty);
 234     }
 235     gclog_or_tty->print_cr("  PSYoungGen max size: " SIZE_FORMAT "K",
 236       young_gen()->max_size()/K);
 237   }
 238 
 239   return result;
 240 }
 241 
 242 // Additional space is needed in the old generation.  Try to move the boundary
 243 // up to meet the need.  Moves boundary up only
 244 void AdjoiningGenerations::adjust_boundary_for_old_gen_needs(
 245   size_t desired_free_space) {
 246   assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check");
 247 
 248   // Stress testing.
 249   if (PSAdaptiveSizePolicyResizeVirtualSpaceAlot == 1) {
 250     MutexLocker x(ExpandHeap_lock);
 251     request_old_gen_expansion(virtual_spaces()->alignment() * 3 / 2);
 252   }
 253 
 254   // Expand only if the entire generation is already committed.
 255   if (old_gen()->virtual_space()->uncommitted_size() == 0) {
 256     if (old_gen()->free_in_bytes() < desired_free_space) {
 257       MutexLocker x(ExpandHeap_lock);




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  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/parallel/adjoiningGenerations.hpp"
  27 #include "gc/parallel/adjoiningVirtualSpaces.hpp"
  28 #include "gc/parallel/generationSizer.hpp"
  29 #include "gc/parallel/parallelScavengeHeap.hpp"
  30 #include "logging/log.hpp"
  31 #include "memory/resourceArea.hpp"
  32 #include "utilities/ostream.hpp"
  33 
  34 // If boundary moving is being used, create the young gen and old
  35 // gen with ASPSYoungGen and ASPSOldGen, respectively.  Revert to
  36 // the old behavior otherwise (with PSYoungGen and PSOldGen).
  37 
  38 AdjoiningGenerations::AdjoiningGenerations(ReservedSpace old_young_rs,
  39                                            GenerationSizer* policy,
  40                                            size_t alignment) :
  41   _virtual_spaces(old_young_rs, policy->min_old_size(),
  42                   policy->min_young_size(), alignment) {
  43   size_t init_low_byte_size = policy->initial_old_size();
  44   size_t min_low_byte_size = policy->min_old_size();
  45   size_t max_low_byte_size = policy->max_old_size();
  46   size_t init_high_byte_size = policy->initial_young_size();
  47   size_t min_high_byte_size = policy->min_young_size();
  48   size_t max_high_byte_size = policy->max_young_size();
  49 
  50   assert(min_low_byte_size <= init_low_byte_size &&
  51          init_low_byte_size <= max_low_byte_size, "Parameter check");
  52   assert(min_high_byte_size <= init_high_byte_size &&


 102                                 min_high_byte_size,
 103                                 max_high_byte_size);
 104     _old_gen = new PSOldGen(init_low_byte_size,
 105                             min_low_byte_size,
 106                             max_low_byte_size,
 107                             "old", 1);
 108 
 109     // The virtual spaces are created by the initialization of the gens.
 110     _young_gen->initialize(young_rs, alignment);
 111     assert(young_gen()->gen_size_limit() == young_rs.size(),
 112       "Consistency check");
 113     _old_gen->initialize(old_rs, alignment, "old", 1);
 114     assert(old_gen()->gen_size_limit() == old_rs.size(), "Consistency check");
 115   }
 116 }
 117 
 118 size_t AdjoiningGenerations::reserved_byte_size() {
 119   return virtual_spaces()->reserved_space().size();
 120 }
 121 
 122 void log_before_expansion(bool old, size_t expand_in_bytes, size_t change_in_bytes, size_t max_size) {
 123   LogHandle(heap, ergo) log;
 124   if (!log.is_debug()) {
 125    return;
 126   }
 127   log.debug("Before expansion of %s gen with boundary move", old ? "old" : "young");
 128   log.debug("  Requested change: " SIZE_FORMAT_HEX "  Attempted change: " SIZE_FORMAT_HEX,
 129                         expand_in_bytes, change_in_bytes);
 130   ResourceMark rm;
 131   ParallelScavengeHeap::heap()->print_on(log.debug_stream());
 132   log.debug("  PS%sGen max size: " SIZE_FORMAT "K", old ? "Old" : "Young", max_size/K);
 133 }
 134 
 135 void log_after_expansion(bool old, size_t max_size) {
 136   LogHandle(heap, ergo) log;
 137   if (!log.is_debug()) {
 138    return;
 139   }
 140   log.debug("After expansion of %s gen with boundary move", old ? "old" : "young");
 141   ResourceMark rm;
 142   ParallelScavengeHeap::heap()->print_on(log.debug_stream());
 143   log.debug("  PS%sGen max size: " SIZE_FORMAT "K", old ? "Old" : "Young", max_size/K);
 144 }
 145 
 146 // Make checks on the current sizes of the generations and
 147 // the constraints on the sizes of the generations.  Push
 148 // up the boundary within the constraints.  A partial
 149 // push can occur.
 150 void AdjoiningGenerations::request_old_gen_expansion(size_t expand_in_bytes) {
 151   assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check");
 152 
 153   assert_lock_strong(ExpandHeap_lock);
 154   assert_locked_or_safepoint(Heap_lock);
 155 
 156   // These sizes limit the amount the boundaries can move.  Effectively,
 157   // the generation says how much it is willing to yield to the other
 158   // generation.
 159   const size_t young_gen_available = young_gen()->available_for_contraction();
 160   const size_t old_gen_available = old_gen()->available_for_expansion();
 161   const size_t alignment = virtual_spaces()->alignment();
 162   size_t change_in_bytes = MIN3(young_gen_available,
 163                                 old_gen_available,
 164                                 align_size_up_(expand_in_bytes, alignment));
 165 
 166   if (change_in_bytes == 0) {
 167     return;
 168   }
 169 
 170   log_before_expansion(true /* old */, expand_in_bytes, change_in_bytes, old_gen()->max_gen_size());










 171 
 172   // Move the boundary between the generations up (smaller young gen).
 173   if (virtual_spaces()->adjust_boundary_up(change_in_bytes)) {
 174     young_gen()->reset_after_change();
 175     old_gen()->reset_after_change();
 176   }
 177 
 178   // The total reserved for the generations should match the sum
 179   // of the two even if the boundary is moving.
 180   assert(reserved_byte_size() ==
 181          old_gen()->max_gen_size() + young_gen()->max_size(),
 182          "Space is missing");
 183   young_gen()->space_invariants();
 184   old_gen()->space_invariants();
 185 
 186   log_after_expansion(true /* old */, old_gen()->max_gen_size());







 187 }
 188 
 189 // See comments on request_old_gen_expansion()
 190 bool AdjoiningGenerations::request_young_gen_expansion(size_t expand_in_bytes) {
 191   assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check");
 192 
 193   // If eden is not empty, the boundary can be moved but no advantage
 194   // can be made of the move since eden cannot be moved.
 195   if (!young_gen()->eden_space()->is_empty()) {
 196     return false;
 197   }
 198 
 199 
 200   bool result = false;
 201   const size_t young_gen_available = young_gen()->available_for_expansion();
 202   const size_t old_gen_available = old_gen()->available_for_contraction();
 203   const size_t alignment = virtual_spaces()->alignment();
 204   size_t change_in_bytes = MIN3(young_gen_available,
 205                                 old_gen_available,
 206                                 align_size_up_(expand_in_bytes, alignment));
 207 
 208   if (change_in_bytes == 0) {
 209     return false;
 210   }
 211 
 212   log_before_expansion(false /* old */, expand_in_bytes, change_in_bytes, young_gen()->max_size());









 213 
 214   // Move the boundary between the generations down (smaller old gen).
 215   MutexLocker x(ExpandHeap_lock);
 216   if (virtual_spaces()->adjust_boundary_down(change_in_bytes)) {
 217     young_gen()->reset_after_change();
 218     old_gen()->reset_after_change();
 219     result = true;
 220   }
 221 
 222   // The total reserved for the generations should match the sum
 223   // of the two even if the boundary is moving.
 224   assert(reserved_byte_size() ==
 225          old_gen()->max_gen_size() + young_gen()->max_size(),
 226          "Space is missing");
 227   young_gen()->space_invariants();
 228   old_gen()->space_invariants();
 229 
 230   log_after_expansion(false /* old */, young_gen()->max_size());







 231 
 232   return result;
 233 }
 234 
 235 // Additional space is needed in the old generation.  Try to move the boundary
 236 // up to meet the need.  Moves boundary up only
 237 void AdjoiningGenerations::adjust_boundary_for_old_gen_needs(
 238   size_t desired_free_space) {
 239   assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check");
 240 
 241   // Stress testing.
 242   if (PSAdaptiveSizePolicyResizeVirtualSpaceAlot == 1) {
 243     MutexLocker x(ExpandHeap_lock);
 244     request_old_gen_expansion(virtual_spaces()->alignment() * 3 / 2);
 245   }
 246 
 247   // Expand only if the entire generation is already committed.
 248   if (old_gen()->virtual_space()->uncommitted_size() == 0) {
 249     if (old_gen()->free_in_bytes() < desired_free_space) {
 250       MutexLocker x(ExpandHeap_lock);


< prev index next >