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

Print this page




 116   } else {
 117     max_survivor_size = size / InitialSurvivorRatio;
 118 
 119     // round the survivor space size down to the nearest alignment
 120     // and make sure its size is greater than 0.
 121     max_survivor_size = align_size_down(max_survivor_size, alignment);
 122     max_survivor_size = MAX2(max_survivor_size, alignment);
 123 
 124     // set the maximum size of eden to be the size of the young gen
 125     // less two times the survivor size when the generation is 100%
 126     // committed. The minimum survivor size for -UseAdaptiveSizePolicy
 127     // is dependent on the committed portion (current capacity) of the
 128     // generation - the less space committed, the smaller the survivor
 129     // space, possibly as small as an alignment. However, we are interested
 130     // in the case where the young generation is 100% committed, as this
 131     // is the point where eden reachs its maximum size. At this point,
 132     // the size of a survivor space is max_survivor_size.
 133     max_eden_size = size - 2 * max_survivor_size;
 134   }
 135 



 136   _eden_counters = new SpaceCounters("eden", 0, max_eden_size, _eden_space,
 137                                      _gen_counters);
 138   _from_counters = new SpaceCounters("s0", 1, max_survivor_size, _from_space,
 139                                      _gen_counters);
 140   _to_counters = new SpaceCounters("s1", 2, max_survivor_size, _to_space,
 141                                    _gen_counters);
 142 
 143   compute_initial_space_boundaries();
 144 }
 145 
 146 void PSYoungGen::compute_initial_space_boundaries() {
 147   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
 148   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
 149 
 150   // Compute sizes
 151   size_t alignment = heap->intra_heap_alignment();
 152   size_t size = virtual_space()->committed_size();
 153 
 154   size_t survivor_size = size / InitialSurvivorRatio;
 155   survivor_size = align_size_down(survivor_size, alignment);
 156   // ... but never less than an alignment
 157   survivor_size = MAX2(survivor_size, alignment);
 158 
 159   // Young generation is eden + 2 survivor spaces
 160   size_t eden_size = size - (2 * survivor_size);
 161 
 162   // Now go ahead and set 'em.
 163   set_space_boundaries(eden_size, survivor_size);
 164   space_invariants();
 165 



 166   if (UsePerfData) {
 167     _eden_counters->update_capacity();
 168     _from_counters->update_capacity();
 169     _to_counters->update_capacity();
 170   }
 171 }
 172 
 173 void PSYoungGen::set_space_boundaries(size_t eden_size, size_t survivor_size) {
 174   assert(eden_size < virtual_space()->committed_size(), "just checking");
 175   assert(eden_size > 0  && survivor_size > 0, "just checking");
 176 
 177   // Initial layout is Eden, to, from. After swapping survivor spaces,
 178   // that leaves us with Eden, from, to, which is step one in our two
 179   // step resize-with-live-data procedure.
 180   char *eden_start = virtual_space()->low();
 181   char *to_start   = eden_start + eden_size;
 182   char *from_start = to_start   + survivor_size;
 183   char *from_end   = from_start + survivor_size;
 184 
 185   assert(from_end == virtual_space()->high(), "just checking");


 411     gclog_or_tty->print_cr("    Mangle before: [" PTR_FORMAT ", "
 412       PTR_FORMAT ")  Mangle after: [" PTR_FORMAT ", " PTR_FORMAT ")",
 413       delta1_left.start(), delta1_left.end(), delta1_right.start(),
 414       delta1_right.end());
 415 
 416     // s2
 417     gclog_or_tty->print_cr("Current region: [" PTR_FORMAT ", " PTR_FORMAT ") "
 418       "New region: [" PTR_FORMAT ", " PTR_FORMAT ")",
 419       s2->bottom(), s2->end(), s2MR.start(), s2MR.end());
 420     gclog_or_tty->print_cr("    Mangle before: [" PTR_FORMAT ", "
 421       PTR_FORMAT ")  Mangle after: [" PTR_FORMAT ", " PTR_FORMAT ")",
 422       delta2_left.start(), delta2_left.end(), delta2_right.start(),
 423       delta2_right.end());
 424   }
 425 
 426 }
 427 #endif // NOT PRODUCT
 428 
 429 void PSYoungGen::resize_spaces(size_t requested_eden_size,
 430                                size_t requested_survivor_size) {
 431   assert(UseAdaptiveSizePolicy, "sanity check");
 432   assert(requested_eden_size > 0  && requested_survivor_size > 0,
 433          "just checking");
 434 
 435   // We require eden and to space to be empty
 436   if ((!eden_space()->is_empty()) || (!to_space()->is_empty())) {
 437     return;
 438   }
 439 
 440   if (PrintAdaptiveSizePolicy && Verbose) {
 441     gclog_or_tty->print_cr("PSYoungGen::resize_spaces(requested_eden_size: "
 442                   SIZE_FORMAT
 443                   ", requested_survivor_size: " SIZE_FORMAT ")",
 444                   requested_eden_size, requested_survivor_size);
 445     gclog_or_tty->print_cr("    eden: [" PTR_FORMAT ".." PTR_FORMAT ") "
 446                   SIZE_FORMAT,
 447                   eden_space()->bottom(),
 448                   eden_space()->end(),
 449                   pointer_delta(eden_space()->end(),
 450                                 eden_space()->bottom(),
 451                                 sizeof(char)));


 932     _from_counters->update_all();
 933     _to_counters->update_all();
 934     _gen_counters->update_all();
 935   }
 936 }
 937 
 938 void PSYoungGen::verify(bool allow_dirty) {
 939   eden_space()->verify(allow_dirty);
 940   from_space()->verify(allow_dirty);
 941   to_space()->verify(allow_dirty);
 942 }
 943 
 944 #ifndef PRODUCT
 945 void PSYoungGen::record_spaces_top() {
 946   assert(ZapUnusedHeapArea, "Not mangling unused space");
 947   eden_space()->set_top_for_allocations();
 948   from_space()->set_top_for_allocations();
 949   to_space()->set_top_for_allocations();
 950 }
 951 #endif


















































































































































 116   } else {
 117     max_survivor_size = size / InitialSurvivorRatio;
 118 
 119     // round the survivor space size down to the nearest alignment
 120     // and make sure its size is greater than 0.
 121     max_survivor_size = align_size_down(max_survivor_size, alignment);
 122     max_survivor_size = MAX2(max_survivor_size, alignment);
 123 
 124     // set the maximum size of eden to be the size of the young gen
 125     // less two times the survivor size when the generation is 100%
 126     // committed. The minimum survivor size for -UseAdaptiveSizePolicy
 127     // is dependent on the committed portion (current capacity) of the
 128     // generation - the less space committed, the smaller the survivor
 129     // space, possibly as small as an alignment. However, we are interested
 130     // in the case where the young generation is 100% committed, as this
 131     // is the point where eden reachs its maximum size. At this point,
 132     // the size of a survivor space is max_survivor_size.
 133     max_eden_size = size - 2 * max_survivor_size;
 134   }
 135 
 136   _max_eden_size = max_eden_size;
 137   _max_survivor_size = max_survivor_size;
 138 
 139   _eden_counters = new SpaceCounters("eden", 0, max_eden_size, _eden_space,
 140                                      _gen_counters);
 141   _from_counters = new SpaceCounters("s0", 1, max_survivor_size, _from_space,
 142                                      _gen_counters);
 143   _to_counters = new SpaceCounters("s1", 2, max_survivor_size, _to_space,
 144                                    _gen_counters);
 145 
 146   compute_initial_space_boundaries();
 147 }
 148 
 149 void PSYoungGen::compute_initial_space_boundaries() {
 150   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
 151   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
 152 
 153   // Compute sizes
 154   size_t alignment = heap->intra_heap_alignment();
 155   size_t size = virtual_space()->committed_size();
 156 
 157   size_t survivor_size = size / InitialSurvivorRatio;
 158   survivor_size = align_size_down(survivor_size, alignment);
 159   // ... but never less than an alignment
 160   survivor_size = MAX2(survivor_size, alignment);
 161 
 162   // Young generation is eden + 2 survivor spaces
 163   size_t eden_size = size - (2 * survivor_size);
 164 
 165   // Now go ahead and set 'em.
 166   set_space_boundaries(eden_size, survivor_size);
 167   space_invariants();
 168 
 169   _init_survivor_size = survivor_size;
 170   _init_eden_size = eden_size;
 171 
 172   if (UsePerfData) {
 173     _eden_counters->update_capacity();
 174     _from_counters->update_capacity();
 175     _to_counters->update_capacity();
 176   }
 177 }
 178 
 179 void PSYoungGen::set_space_boundaries(size_t eden_size, size_t survivor_size) {
 180   assert(eden_size < virtual_space()->committed_size(), "just checking");
 181   assert(eden_size > 0  && survivor_size > 0, "just checking");
 182 
 183   // Initial layout is Eden, to, from. After swapping survivor spaces,
 184   // that leaves us with Eden, from, to, which is step one in our two
 185   // step resize-with-live-data procedure.
 186   char *eden_start = virtual_space()->low();
 187   char *to_start   = eden_start + eden_size;
 188   char *from_start = to_start   + survivor_size;
 189   char *from_end   = from_start + survivor_size;
 190 
 191   assert(from_end == virtual_space()->high(), "just checking");


 417     gclog_or_tty->print_cr("    Mangle before: [" PTR_FORMAT ", "
 418       PTR_FORMAT ")  Mangle after: [" PTR_FORMAT ", " PTR_FORMAT ")",
 419       delta1_left.start(), delta1_left.end(), delta1_right.start(),
 420       delta1_right.end());
 421 
 422     // s2
 423     gclog_or_tty->print_cr("Current region: [" PTR_FORMAT ", " PTR_FORMAT ") "
 424       "New region: [" PTR_FORMAT ", " PTR_FORMAT ")",
 425       s2->bottom(), s2->end(), s2MR.start(), s2MR.end());
 426     gclog_or_tty->print_cr("    Mangle before: [" PTR_FORMAT ", "
 427       PTR_FORMAT ")  Mangle after: [" PTR_FORMAT ", " PTR_FORMAT ")",
 428       delta2_left.start(), delta2_left.end(), delta2_right.start(),
 429       delta2_right.end());
 430   }
 431 
 432 }
 433 #endif // NOT PRODUCT
 434 
 435 void PSYoungGen::resize_spaces(size_t requested_eden_size,
 436                                size_t requested_survivor_size) {

 437   assert(requested_eden_size > 0  && requested_survivor_size > 0,
 438          "just checking");
 439 
 440   // We require eden and to space to be empty
 441   if ((!eden_space()->is_empty()) || (!to_space()->is_empty())) {
 442     return;
 443   }
 444 
 445   if (PrintAdaptiveSizePolicy && Verbose) {
 446     gclog_or_tty->print_cr("PSYoungGen::resize_spaces(requested_eden_size: "
 447                   SIZE_FORMAT
 448                   ", requested_survivor_size: " SIZE_FORMAT ")",
 449                   requested_eden_size, requested_survivor_size);
 450     gclog_or_tty->print_cr("    eden: [" PTR_FORMAT ".." PTR_FORMAT ") "
 451                   SIZE_FORMAT,
 452                   eden_space()->bottom(),
 453                   eden_space()->end(),
 454                   pointer_delta(eden_space()->end(),
 455                                 eden_space()->bottom(),
 456                                 sizeof(char)));


 937     _from_counters->update_all();
 938     _to_counters->update_all();
 939     _gen_counters->update_all();
 940   }
 941 }
 942 
 943 void PSYoungGen::verify(bool allow_dirty) {
 944   eden_space()->verify(allow_dirty);
 945   from_space()->verify(allow_dirty);
 946   to_space()->verify(allow_dirty);
 947 }
 948 
 949 #ifndef PRODUCT
 950 void PSYoungGen::record_spaces_top() {
 951   assert(ZapUnusedHeapArea, "Not mangling unused space");
 952   eden_space()->set_top_for_allocations();
 953   from_space()->set_top_for_allocations();
 954   to_space()->set_top_for_allocations();
 955 }
 956 #endif
 957 
 958 void PSYoungGen::try_to_expand_by(size_t expand_bytes) {
 959   size_t available_bytes = max_size() - capacity_in_bytes();
 960   if (available_bytes == 0) {
 961     // cannot expand
 962     return;
 963   }
 964   size_t eden_available_bytes = _max_eden_size - eden_space()->used_in_bytes();
 965   size_t survivor_available_bytes = _max_survivor_size - from_space()->used_in_bytes();
 966   size_t eden_expand_bytes =
 967       (size_t) (expand_bytes * ((double) eden_available_bytes / available_bytes));
 968   size_t survivor_expand_bytes =
 969       (size_t) (expand_bytes * ((double) survivor_available_bytes / available_bytes));
 970 
 971   // Don't expand unless it's significant
 972   if (eden_expand_bytes < MinHeapDeltaBytes) {
 973     eden_expand_bytes = 0;
 974   }
 975   if (survivor_expand_bytes < MinHeapDeltaBytes) {
 976     survivor_expand_bytes = 0;
 977   }
 978 
 979   if (eden_expand_bytes == 0 && survivor_expand_bytes == 0) {
 980     return; // no change, so return now
 981   }
 982 
 983   size_t eden_desired_capacity =
 984       eden_space()->capacity_in_bytes() + eden_expand_bytes;
 985   eden_desired_capacity = MIN2(eden_desired_capacity, _max_eden_size);
 986   eden_desired_capacity = align_size_down(eden_desired_capacity,
 987                                           virtual_space()->alignment());
 988 
 989   size_t survivor_desired_capacity =
 990       from_space()->capacity_in_bytes() + survivor_expand_bytes;
 991   survivor_desired_capacity = MIN2(survivor_desired_capacity, _max_survivor_size);
 992   survivor_desired_capacity = align_size_down(survivor_desired_capacity,
 993                                               virtual_space()->alignment());
 994 
 995   if (eden_desired_capacity == eden_space()->capacity_in_bytes()
 996       && survivor_desired_capacity == from_space()->capacity_in_bytes()) {
 997     return; // no change, so return now
 998   }
 999 
1000   if (PrintGC) {
1001     gclog_or_tty->print_cr(" Resizing young gen. expand_bytes=%d,%d",
1002                            eden_expand_bytes, survivor_expand_bytes);
1003     gclog_or_tty->print("BEFORE: Young Gen: ");
1004     gclog_or_tty->print("eden capacity : " SIZE_FORMAT ", ",
1005                         eden_space()->capacity_in_bytes());
1006     gclog_or_tty->print("eden used : " SIZE_FORMAT ", " ,
1007                         eden_space()->used_in_bytes());
1008     gclog_or_tty->print("survivor capacity : " SIZE_FORMAT ", ",
1009                         from_space()->capacity_in_bytes());
1010     gclog_or_tty->print_cr("survivor used : " SIZE_FORMAT ", " ,
1011                            from_space()->used_in_bytes());
1012   }
1013 
1014   resize(eden_desired_capacity, survivor_desired_capacity);
1015 
1016   if (PrintGC) {
1017     gclog_or_tty->print("AFTER: Young Gen: ");
1018     gclog_or_tty->print("eden capacity : " SIZE_FORMAT ", ",
1019                         eden_space()->capacity_in_bytes());
1020     gclog_or_tty->print("eden used : " SIZE_FORMAT ", " ,
1021                         eden_space()->used_in_bytes());
1022     gclog_or_tty->print("survivor capacity : " SIZE_FORMAT ", ",
1023                         from_space()->capacity_in_bytes());
1024     gclog_or_tty->print_cr("survivor used : " SIZE_FORMAT ", " ,
1025                            from_space()->used_in_bytes());
1026   }
1027 }
1028 
1029 void PSYoungGen::try_to_shrink_by(size_t shrink_bytes) {
1030   size_t free_bytes = capacity_in_bytes() - used_in_bytes();
1031   if (free_bytes == 0) {
1032     // cannot shrink
1033     return;
1034   }
1035   size_t eden_free_bytes = eden_space()->capacity_in_bytes() - eden_space()->used_in_bytes();
1036   size_t survivor_free_bytes = from_space()->capacity_in_bytes() - from_space()->used_in_bytes();
1037   size_t eden_shrink_bytes =
1038       (size_t) (shrink_bytes * ((double) eden_free_bytes / free_bytes));
1039   size_t survivor_shrink_bytes =
1040       (size_t) (shrink_bytes * ((double) survivor_free_bytes / free_bytes));
1041 
1042   // Don't shrink unless it's significant
1043   if (eden_shrink_bytes < MinHeapDeltaBytes) {
1044     eden_shrink_bytes = 0;
1045   }
1046   if (survivor_shrink_bytes < MinHeapDeltaBytes) {
1047     survivor_shrink_bytes = 0;
1048   }
1049 
1050   if (eden_shrink_bytes == 0 && survivor_shrink_bytes == 0) {
1051     return; // no change, so return now
1052   }
1053 
1054   size_t eden_desired_capacity =
1055       eden_space()->capacity_in_bytes() - eden_shrink_bytes;
1056   eden_desired_capacity = MAX2(eden_desired_capacity, _init_eden_size);
1057   assert(eden_space()->used_in_bytes() <= eden_desired_capacity, "sanity check");
1058   eden_desired_capacity = align_size_down(eden_desired_capacity,
1059                                           virtual_space()->alignment());
1060 
1061   size_t survivor_desired_capacity =
1062       from_space()->capacity_in_bytes() - survivor_shrink_bytes;
1063   survivor_desired_capacity = MAX2(survivor_desired_capacity, _init_survivor_size);
1064   assert(from_space()->used_in_bytes() <= survivor_desired_capacity, "sanity check");
1065   survivor_desired_capacity = align_size_down(survivor_desired_capacity,
1066                                               virtual_space()->alignment());
1067 
1068   if (eden_desired_capacity == eden_space()->capacity_in_bytes()
1069       && survivor_desired_capacity == from_space()->capacity_in_bytes()) {
1070     return; // no change, so return now
1071   }
1072 
1073   if (PrintGC) {
1074     gclog_or_tty->print_cr(" Resizing young gen. shrink_bytes=%d,%d",
1075                            eden_shrink_bytes, survivor_shrink_bytes);
1076     gclog_or_tty->print("BEFORE: Young Gen: ");
1077     gclog_or_tty->print("eden capacity : " SIZE_FORMAT ", ",
1078                         eden_space()->capacity_in_bytes());
1079     gclog_or_tty->print("eden used : " SIZE_FORMAT ", " ,
1080                         eden_space()->used_in_bytes());
1081     gclog_or_tty->print("survivor capacity : " SIZE_FORMAT ", ",
1082                         from_space()->capacity_in_bytes());
1083     gclog_or_tty->print_cr("survivor used : " SIZE_FORMAT ", " ,
1084                            from_space()->used_in_bytes());
1085   }
1086 
1087   resize(eden_desired_capacity, survivor_desired_capacity);
1088 
1089   if (PrintGC) {
1090     gclog_or_tty->print("AFTER: Young Gen: ");
1091     gclog_or_tty->print("eden capacity : " SIZE_FORMAT ", ",
1092                         eden_space()->capacity_in_bytes());
1093     gclog_or_tty->print("eden used : " SIZE_FORMAT ", " ,
1094                         eden_space()->used_in_bytes());
1095     gclog_or_tty->print("survivor capacity : " SIZE_FORMAT ", ",
1096                         from_space()->capacity_in_bytes());
1097     gclog_or_tty->print_cr("survivor used : " SIZE_FORMAT ", " ,
1098                            from_space()->used_in_bytes());
1099   }
1100 }