src/share/vm/gc_implementation/parallelScavenge/psYoungGen.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/gc_implementation/parallelScavenge

src/share/vm/gc_implementation/parallelScavenge/psYoungGen.cpp

Print this page




  86   // Allocate the mark sweep views of spaces
  87   _eden_mark_sweep =
  88       new PSMarkSweepDecorator(_eden_space, NULL, MarkSweepDeadRatio);
  89   _from_mark_sweep =
  90       new PSMarkSweepDecorator(_from_space, NULL, MarkSweepDeadRatio);
  91   _to_mark_sweep =
  92       new PSMarkSweepDecorator(_to_space, NULL, MarkSweepDeadRatio);
  93 
  94   if (_eden_mark_sweep == NULL ||
  95       _from_mark_sweep == NULL ||
  96       _to_mark_sweep == NULL) {
  97     vm_exit_during_initialization("Could not complete allocation"
  98                                   " of the young generation");
  99   }
 100 
 101   // Generation Counters - generation 0, 3 subspaces
 102   _gen_counters = new PSGenerationCounters("new", 0, 3, _virtual_space);
 103 
 104   // Compute maximum space sizes for performance counters
 105   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
 106   size_t alignment = heap->intra_heap_alignment();
 107   size_t size = virtual_space()->reserved_size();
 108 
 109   size_t max_survivor_size;
 110   size_t max_eden_size;
 111 
 112   if (UseAdaptiveSizePolicy) {
 113     max_survivor_size = size / MinSurvivorRatio;
 114 
 115     // round the survivor space size down to the nearest alignment
 116     // and make sure its size is greater than 0.
 117     max_survivor_size = align_size_down(max_survivor_size, alignment);
 118     max_survivor_size = MAX2(max_survivor_size, alignment);
 119 
 120     // set the maximum size of eden to be the size of the young gen
 121     // less two times the minimum survivor size. The minimum survivor
 122     // size for UseAdaptiveSizePolicy is one alignment.
 123     max_eden_size = size - 2 * alignment;
 124   } else {
 125     max_survivor_size = size / InitialSurvivorRatio;
 126 


 139     // is the point where eden reachs its maximum size. At this point,
 140     // the size of a survivor space is max_survivor_size.
 141     max_eden_size = size - 2 * max_survivor_size;
 142   }
 143 
 144   _eden_counters = new SpaceCounters("eden", 0, max_eden_size, _eden_space,
 145                                      _gen_counters);
 146   _from_counters = new SpaceCounters("s0", 1, max_survivor_size, _from_space,
 147                                      _gen_counters);
 148   _to_counters = new SpaceCounters("s1", 2, max_survivor_size, _to_space,
 149                                    _gen_counters);
 150 
 151   compute_initial_space_boundaries();
 152 }
 153 
 154 void PSYoungGen::compute_initial_space_boundaries() {
 155   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
 156   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
 157 
 158   // Compute sizes
 159   size_t alignment = heap->intra_heap_alignment();
 160   size_t size = virtual_space()->committed_size();

 161 
 162   size_t survivor_size = size / InitialSurvivorRatio;
 163   survivor_size = align_size_down(survivor_size, alignment);
 164   // ... but never less than an alignment
 165   survivor_size = MAX2(survivor_size, alignment);
 166 
 167   // Young generation is eden + 2 survivor spaces
 168   size_t eden_size = size - (2 * survivor_size);
 169 
 170   // Now go ahead and set 'em.
 171   set_space_boundaries(eden_size, survivor_size);
 172   space_invariants();
 173 
 174   if (UsePerfData) {
 175     _eden_counters->update_capacity();
 176     _from_counters->update_capacity();
 177     _to_counters->update_capacity();
 178   }
 179 }
 180 


 190   char *from_start = to_start   + survivor_size;
 191   char *from_end   = from_start + survivor_size;
 192 
 193   assert(from_end == virtual_space()->high(), "just checking");
 194   assert(is_object_aligned((intptr_t)eden_start), "checking alignment");
 195   assert(is_object_aligned((intptr_t)to_start),   "checking alignment");
 196   assert(is_object_aligned((intptr_t)from_start), "checking alignment");
 197 
 198   MemRegion eden_mr((HeapWord*)eden_start, (HeapWord*)to_start);
 199   MemRegion to_mr  ((HeapWord*)to_start, (HeapWord*)from_start);
 200   MemRegion from_mr((HeapWord*)from_start, (HeapWord*)from_end);
 201 
 202   eden_space()->initialize(eden_mr, true, ZapUnusedHeapArea);
 203     to_space()->initialize(to_mr  , true, ZapUnusedHeapArea);
 204   from_space()->initialize(from_mr, true, ZapUnusedHeapArea);
 205 }
 206 
 207 #ifndef PRODUCT
 208 void PSYoungGen::space_invariants() {
 209   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
 210   const size_t alignment = heap->intra_heap_alignment();
 211 
 212   // Currently, our eden size cannot shrink to zero
 213   guarantee(eden_space()->capacity_in_bytes() >= alignment, "eden too small");
 214   guarantee(from_space()->capacity_in_bytes() >= alignment, "from too small");
 215   guarantee(to_space()->capacity_in_bytes() >= alignment, "to too small");
 216 
 217   // Relationship of spaces to each other
 218   char* eden_start = (char*)eden_space()->bottom();
 219   char* eden_end   = (char*)eden_space()->end();
 220   char* from_start = (char*)from_space()->bottom();
 221   char* from_end   = (char*)from_space()->end();
 222   char* to_start   = (char*)to_space()->bottom();
 223   char* to_end     = (char*)to_space()->end();
 224 
 225   guarantee(eden_start >= virtual_space()->low(), "eden bottom");
 226   guarantee(eden_start < eden_end, "eden space consistency");
 227   guarantee(from_start < from_end, "from space consistency");
 228   guarantee(to_start < to_end, "to space consistency");
 229 
 230   // Check whether from space is below to space


 474   }
 475 
 476   // There's nothing to do if the new sizes are the same as the current
 477   if (requested_survivor_size == to_space()->capacity_in_bytes() &&
 478       requested_survivor_size == from_space()->capacity_in_bytes() &&
 479       requested_eden_size == eden_space()->capacity_in_bytes()) {
 480     if (PrintAdaptiveSizePolicy && Verbose) {
 481       gclog_or_tty->print_cr("    capacities are the right sizes, returning");
 482     }
 483     return;
 484   }
 485 
 486   char* eden_start = (char*)eden_space()->bottom();
 487   char* eden_end   = (char*)eden_space()->end();
 488   char* from_start = (char*)from_space()->bottom();
 489   char* from_end   = (char*)from_space()->end();
 490   char* to_start   = (char*)to_space()->bottom();
 491   char* to_end     = (char*)to_space()->end();
 492 
 493   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
 494   const size_t alignment = heap->intra_heap_alignment();
 495   const bool maintain_minimum =
 496     (requested_eden_size + 2 * requested_survivor_size) <= min_gen_size();
 497 
 498   bool eden_from_to_order = from_start < to_start;
 499   // Check whether from space is below to space
 500   if (eden_from_to_order) {
 501     // Eden, from, to
 502     eden_from_to_order = true;
 503     if (PrintAdaptiveSizePolicy && Verbose) {
 504       gclog_or_tty->print_cr("  Eden, from, to:");
 505     }
 506 
 507     // Set eden
 508     // "requested_eden_size" is a goal for the size of eden
 509     // and may not be attainable.  "eden_size" below is
 510     // calculated based on the location of from-space and
 511     // the goal for the size of eden.  from-space is
 512     // fixed in place because it contains live data.
 513     // The calculation is done this way to avoid 32bit
 514     // overflow (i.e., eden_start + requested_eden_size


 823   ShouldNotReachHere();
 824   return 0;
 825 }
 826 
 827 size_t PSYoungGen::available_for_contraction() {
 828   ShouldNotReachHere();
 829   return 0;
 830 }
 831 
 832 size_t PSYoungGen::available_to_min_gen() {
 833   assert(virtual_space()->committed_size() >= min_gen_size(), "Invariant");
 834   return virtual_space()->committed_size() - min_gen_size();
 835 }
 836 
 837 // This method assumes that from-space has live data and that
 838 // any shrinkage of the young gen is limited by location of
 839 // from-space.
 840 size_t PSYoungGen::available_to_live() {
 841   size_t delta_in_survivor = 0;
 842   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
 843   const size_t space_alignment = heap->intra_heap_alignment();
 844   const size_t gen_alignment = heap->young_gen_alignment();
 845 
 846   MutableSpace* space_shrinking = NULL;
 847   if (from_space()->end() > to_space()->end()) {
 848     space_shrinking = from_space();
 849   } else {
 850     space_shrinking = to_space();
 851   }
 852 
 853   // Include any space that is committed but not included in
 854   // the survivor spaces.
 855   assert(((HeapWord*)virtual_space()->high()) >= space_shrinking->end(),
 856     "Survivor space beyond high end");
 857   size_t unused_committed = pointer_delta(virtual_space()->high(),
 858     space_shrinking->end(), sizeof(char));
 859 
 860   if (space_shrinking->is_empty()) {
 861     // Don't let the space shrink to 0
 862     assert(space_shrinking->capacity_in_bytes() >= space_alignment,
 863       "Space is too small");
 864     delta_in_survivor = space_shrinking->capacity_in_bytes() - space_alignment;




  86   // Allocate the mark sweep views of spaces
  87   _eden_mark_sweep =
  88       new PSMarkSweepDecorator(_eden_space, NULL, MarkSweepDeadRatio);
  89   _from_mark_sweep =
  90       new PSMarkSweepDecorator(_from_space, NULL, MarkSweepDeadRatio);
  91   _to_mark_sweep =
  92       new PSMarkSweepDecorator(_to_space, NULL, MarkSweepDeadRatio);
  93 
  94   if (_eden_mark_sweep == NULL ||
  95       _from_mark_sweep == NULL ||
  96       _to_mark_sweep == NULL) {
  97     vm_exit_during_initialization("Could not complete allocation"
  98                                   " of the young generation");
  99   }
 100 
 101   // Generation Counters - generation 0, 3 subspaces
 102   _gen_counters = new PSGenerationCounters("new", 0, 3, _virtual_space);
 103 
 104   // Compute maximum space sizes for performance counters
 105   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
 106   size_t alignment = heap->space_alignment();
 107   size_t size = virtual_space()->reserved_size();
 108 
 109   size_t max_survivor_size;
 110   size_t max_eden_size;
 111 
 112   if (UseAdaptiveSizePolicy) {
 113     max_survivor_size = size / MinSurvivorRatio;
 114 
 115     // round the survivor space size down to the nearest alignment
 116     // and make sure its size is greater than 0.
 117     max_survivor_size = align_size_down(max_survivor_size, alignment);
 118     max_survivor_size = MAX2(max_survivor_size, alignment);
 119 
 120     // set the maximum size of eden to be the size of the young gen
 121     // less two times the minimum survivor size. The minimum survivor
 122     // size for UseAdaptiveSizePolicy is one alignment.
 123     max_eden_size = size - 2 * alignment;
 124   } else {
 125     max_survivor_size = size / InitialSurvivorRatio;
 126 


 139     // is the point where eden reachs its maximum size. At this point,
 140     // the size of a survivor space is max_survivor_size.
 141     max_eden_size = size - 2 * max_survivor_size;
 142   }
 143 
 144   _eden_counters = new SpaceCounters("eden", 0, max_eden_size, _eden_space,
 145                                      _gen_counters);
 146   _from_counters = new SpaceCounters("s0", 1, max_survivor_size, _from_space,
 147                                      _gen_counters);
 148   _to_counters = new SpaceCounters("s1", 2, max_survivor_size, _to_space,
 149                                    _gen_counters);
 150 
 151   compute_initial_space_boundaries();
 152 }
 153 
 154 void PSYoungGen::compute_initial_space_boundaries() {
 155   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
 156   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
 157 
 158   // Compute sizes
 159   size_t alignment = heap->space_alignment();
 160   size_t size = virtual_space()->committed_size();
 161   assert(size >= 3 * alignment, "Young space is not large enough for eden + 2 survivors");
 162 
 163   size_t survivor_size = size / InitialSurvivorRatio;
 164   survivor_size = align_size_down(survivor_size, alignment);
 165   // ... but never less than an alignment
 166   survivor_size = MAX2(survivor_size, alignment);
 167 
 168   // Young generation is eden + 2 survivor spaces
 169   size_t eden_size = size - (2 * survivor_size);
 170 
 171   // Now go ahead and set 'em.
 172   set_space_boundaries(eden_size, survivor_size);
 173   space_invariants();
 174 
 175   if (UsePerfData) {
 176     _eden_counters->update_capacity();
 177     _from_counters->update_capacity();
 178     _to_counters->update_capacity();
 179   }
 180 }
 181 


 191   char *from_start = to_start   + survivor_size;
 192   char *from_end   = from_start + survivor_size;
 193 
 194   assert(from_end == virtual_space()->high(), "just checking");
 195   assert(is_object_aligned((intptr_t)eden_start), "checking alignment");
 196   assert(is_object_aligned((intptr_t)to_start),   "checking alignment");
 197   assert(is_object_aligned((intptr_t)from_start), "checking alignment");
 198 
 199   MemRegion eden_mr((HeapWord*)eden_start, (HeapWord*)to_start);
 200   MemRegion to_mr  ((HeapWord*)to_start, (HeapWord*)from_start);
 201   MemRegion from_mr((HeapWord*)from_start, (HeapWord*)from_end);
 202 
 203   eden_space()->initialize(eden_mr, true, ZapUnusedHeapArea);
 204     to_space()->initialize(to_mr  , true, ZapUnusedHeapArea);
 205   from_space()->initialize(from_mr, true, ZapUnusedHeapArea);
 206 }
 207 
 208 #ifndef PRODUCT
 209 void PSYoungGen::space_invariants() {
 210   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
 211   const size_t alignment = heap->space_alignment();
 212 
 213   // Currently, our eden size cannot shrink to zero
 214   guarantee(eden_space()->capacity_in_bytes() >= alignment, "eden too small");
 215   guarantee(from_space()->capacity_in_bytes() >= alignment, "from too small");
 216   guarantee(to_space()->capacity_in_bytes() >= alignment, "to too small");
 217 
 218   // Relationship of spaces to each other
 219   char* eden_start = (char*)eden_space()->bottom();
 220   char* eden_end   = (char*)eden_space()->end();
 221   char* from_start = (char*)from_space()->bottom();
 222   char* from_end   = (char*)from_space()->end();
 223   char* to_start   = (char*)to_space()->bottom();
 224   char* to_end     = (char*)to_space()->end();
 225 
 226   guarantee(eden_start >= virtual_space()->low(), "eden bottom");
 227   guarantee(eden_start < eden_end, "eden space consistency");
 228   guarantee(from_start < from_end, "from space consistency");
 229   guarantee(to_start < to_end, "to space consistency");
 230 
 231   // Check whether from space is below to space


 475   }
 476 
 477   // There's nothing to do if the new sizes are the same as the current
 478   if (requested_survivor_size == to_space()->capacity_in_bytes() &&
 479       requested_survivor_size == from_space()->capacity_in_bytes() &&
 480       requested_eden_size == eden_space()->capacity_in_bytes()) {
 481     if (PrintAdaptiveSizePolicy && Verbose) {
 482       gclog_or_tty->print_cr("    capacities are the right sizes, returning");
 483     }
 484     return;
 485   }
 486 
 487   char* eden_start = (char*)eden_space()->bottom();
 488   char* eden_end   = (char*)eden_space()->end();
 489   char* from_start = (char*)from_space()->bottom();
 490   char* from_end   = (char*)from_space()->end();
 491   char* to_start   = (char*)to_space()->bottom();
 492   char* to_end     = (char*)to_space()->end();
 493 
 494   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
 495   const size_t alignment = heap->space_alignment();
 496   const bool maintain_minimum =
 497     (requested_eden_size + 2 * requested_survivor_size) <= min_gen_size();
 498 
 499   bool eden_from_to_order = from_start < to_start;
 500   // Check whether from space is below to space
 501   if (eden_from_to_order) {
 502     // Eden, from, to
 503     eden_from_to_order = true;
 504     if (PrintAdaptiveSizePolicy && Verbose) {
 505       gclog_or_tty->print_cr("  Eden, from, to:");
 506     }
 507 
 508     // Set eden
 509     // "requested_eden_size" is a goal for the size of eden
 510     // and may not be attainable.  "eden_size" below is
 511     // calculated based on the location of from-space and
 512     // the goal for the size of eden.  from-space is
 513     // fixed in place because it contains live data.
 514     // The calculation is done this way to avoid 32bit
 515     // overflow (i.e., eden_start + requested_eden_size


 824   ShouldNotReachHere();
 825   return 0;
 826 }
 827 
 828 size_t PSYoungGen::available_for_contraction() {
 829   ShouldNotReachHere();
 830   return 0;
 831 }
 832 
 833 size_t PSYoungGen::available_to_min_gen() {
 834   assert(virtual_space()->committed_size() >= min_gen_size(), "Invariant");
 835   return virtual_space()->committed_size() - min_gen_size();
 836 }
 837 
 838 // This method assumes that from-space has live data and that
 839 // any shrinkage of the young gen is limited by location of
 840 // from-space.
 841 size_t PSYoungGen::available_to_live() {
 842   size_t delta_in_survivor = 0;
 843   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
 844   const size_t space_alignment = heap->space_alignment();
 845   const size_t gen_alignment = heap->generation_alignment();
 846 
 847   MutableSpace* space_shrinking = NULL;
 848   if (from_space()->end() > to_space()->end()) {
 849     space_shrinking = from_space();
 850   } else {
 851     space_shrinking = to_space();
 852   }
 853 
 854   // Include any space that is committed but not included in
 855   // the survivor spaces.
 856   assert(((HeapWord*)virtual_space()->high()) >= space_shrinking->end(),
 857     "Survivor space beyond high end");
 858   size_t unused_committed = pointer_delta(virtual_space()->high(),
 859     space_shrinking->end(), sizeof(char));
 860 
 861   if (space_shrinking->is_empty()) {
 862     // Don't let the space shrink to 0
 863     assert(space_shrinking->capacity_in_bytes() >= space_alignment,
 864       "Space is too small");
 865     delta_in_survivor = space_shrinking->capacity_in_bytes() - space_alignment;


src/share/vm/gc_implementation/parallelScavenge/psYoungGen.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File