src/share/vm/gc_implementation/parallelScavenge/psYoungGen.cpp
Print this page
@@ -131,10 +131,13 @@
// is the point where eden reachs its maximum size. At this point,
// the size of a survivor space is max_survivor_size.
max_eden_size = size - 2 * max_survivor_size;
}
+ _max_eden_size = max_eden_size;
+ _max_survivor_size = max_survivor_size;
+
_eden_counters = new SpaceCounters("eden", 0, max_eden_size, _eden_space,
_gen_counters);
_from_counters = new SpaceCounters("s0", 1, max_survivor_size, _from_space,
_gen_counters);
_to_counters = new SpaceCounters("s1", 2, max_survivor_size, _to_space,
@@ -161,10 +164,13 @@
// Now go ahead and set 'em.
set_space_boundaries(eden_size, survivor_size);
space_invariants();
+ _init_survivor_size = survivor_size;
+ _init_eden_size = eden_size;
+
if (UsePerfData) {
_eden_counters->update_capacity();
_from_counters->update_capacity();
_to_counters->update_capacity();
}
@@ -947,5 +953,149 @@
eden_space()->set_top_for_allocations();
from_space()->set_top_for_allocations();
to_space()->set_top_for_allocations();
}
#endif
+
+void PSYoungGen::try_to_expand_by(size_t expand_bytes) {
+ size_t available_bytes = max_size() - capacity_in_bytes();
+ if (available_bytes == 0) {
+ // cannot expand
+ return;
+ }
+ size_t eden_available_bytes = _max_eden_size - eden_space()->used_in_bytes();
+ size_t survivor_available_bytes = _max_survivor_size - from_space()->used_in_bytes();
+ size_t eden_expand_bytes =
+ (size_t) (expand_bytes * ((double) eden_available_bytes / available_bytes));
+ size_t survivor_expand_bytes =
+ (size_t) (expand_bytes * ((double) survivor_available_bytes / available_bytes));
+
+ // Don't expand unless it's significant
+ if (eden_expand_bytes < MinHeapDeltaBytes) {
+ eden_expand_bytes = 0;
+ }
+ if (survivor_expand_bytes < MinHeapDeltaBytes) {
+ survivor_expand_bytes = 0;
+ }
+
+ if (eden_expand_bytes == 0 && survivor_expand_bytes == 0) {
+ return; // no change, so return now
+ }
+
+ size_t eden_desired_capacity =
+ eden_space()->capacity_in_bytes() + eden_expand_bytes;
+ eden_desired_capacity = MIN2(eden_desired_capacity, _max_eden_size);
+ eden_desired_capacity = align_size_down(eden_desired_capacity,
+ virtual_space()->alignment());
+
+ size_t survivor_desired_capacity =
+ from_space()->capacity_in_bytes() + survivor_expand_bytes;
+ survivor_desired_capacity = MIN2(survivor_desired_capacity, _max_survivor_size);
+ survivor_desired_capacity = align_size_down(survivor_desired_capacity,
+ virtual_space()->alignment());
+
+ if (eden_desired_capacity == eden_space()->capacity_in_bytes()
+ && survivor_desired_capacity == from_space()->capacity_in_bytes()) {
+ return; // no change, so return now
+ }
+
+ if (PrintGC) {
+ gclog_or_tty->print_cr(" Resizing young gen. expand_bytes=%d,%d",
+ eden_expand_bytes, survivor_expand_bytes);
+ gclog_or_tty->print("BEFORE: Young Gen: ");
+ gclog_or_tty->print("eden capacity : " SIZE_FORMAT ", ",
+ eden_space()->capacity_in_bytes());
+ gclog_or_tty->print("eden used : " SIZE_FORMAT ", " ,
+ eden_space()->used_in_bytes());
+ gclog_or_tty->print("survivor capacity : " SIZE_FORMAT ", ",
+ from_space()->capacity_in_bytes());
+ gclog_or_tty->print_cr("survivor used : " SIZE_FORMAT ", " ,
+ from_space()->used_in_bytes());
+ }
+
+ resize(eden_desired_capacity, survivor_desired_capacity);
+
+ if (PrintGC) {
+ gclog_or_tty->print("AFTER: Young Gen: ");
+ gclog_or_tty->print("eden capacity : " SIZE_FORMAT ", ",
+ eden_space()->capacity_in_bytes());
+ gclog_or_tty->print("eden used : " SIZE_FORMAT ", " ,
+ eden_space()->used_in_bytes());
+ gclog_or_tty->print("survivor capacity : " SIZE_FORMAT ", ",
+ from_space()->capacity_in_bytes());
+ gclog_or_tty->print_cr("survivor used : " SIZE_FORMAT ", " ,
+ from_space()->used_in_bytes());
+ }
+}
+
+void PSYoungGen::try_to_shrink_by(size_t shrink_bytes) {
+ size_t free_bytes = capacity_in_bytes() - used_in_bytes();
+ if (free_bytes == 0) {
+ // cannot shrink
+ return;
+ }
+ size_t eden_free_bytes = eden_space()->capacity_in_bytes() - eden_space()->used_in_bytes();
+ size_t survivor_free_bytes = from_space()->capacity_in_bytes() - from_space()->used_in_bytes();
+ size_t eden_shrink_bytes =
+ (size_t) (shrink_bytes * ((double) eden_free_bytes / free_bytes));
+ size_t survivor_shrink_bytes =
+ (size_t) (shrink_bytes * ((double) survivor_free_bytes / free_bytes));
+
+ // Don't shrink unless it's significant
+ if (eden_shrink_bytes < MinHeapDeltaBytes) {
+ eden_shrink_bytes = 0;
+ }
+ if (survivor_shrink_bytes < MinHeapDeltaBytes) {
+ survivor_shrink_bytes = 0;
+ }
+
+ if (eden_shrink_bytes == 0 && survivor_shrink_bytes == 0) {
+ return; // no change, so return now
+ }
+
+ size_t eden_desired_capacity =
+ eden_space()->capacity_in_bytes() - eden_shrink_bytes;
+ eden_desired_capacity = MAX2(eden_desired_capacity, _init_eden_size);
+ assert(eden_space()->used_in_bytes() <= eden_desired_capacity, "sanity check");
+ eden_desired_capacity = align_size_down(eden_desired_capacity,
+ virtual_space()->alignment());
+
+ size_t survivor_desired_capacity =
+ from_space()->capacity_in_bytes() - survivor_shrink_bytes;
+ survivor_desired_capacity = MAX2(survivor_desired_capacity, _init_survivor_size);
+ assert(from_space()->used_in_bytes() <= survivor_desired_capacity, "sanity check");
+ survivor_desired_capacity = align_size_down(survivor_desired_capacity,
+ virtual_space()->alignment());
+
+ if (eden_desired_capacity == eden_space()->capacity_in_bytes()
+ && survivor_desired_capacity == from_space()->capacity_in_bytes()) {
+ return; // no change, so return now
+ }
+
+ if (PrintGC) {
+ gclog_or_tty->print_cr(" Resizing young gen. shrink_bytes=%d,%d",
+ eden_shrink_bytes, survivor_shrink_bytes);
+ gclog_or_tty->print("BEFORE: Young Gen: ");
+ gclog_or_tty->print("eden capacity : " SIZE_FORMAT ", ",
+ eden_space()->capacity_in_bytes());
+ gclog_or_tty->print("eden used : " SIZE_FORMAT ", " ,
+ eden_space()->used_in_bytes());
+ gclog_or_tty->print("survivor capacity : " SIZE_FORMAT ", ",
+ from_space()->capacity_in_bytes());
+ gclog_or_tty->print_cr("survivor used : " SIZE_FORMAT ", " ,
+ from_space()->used_in_bytes());
+ }
+
+ resize(eden_desired_capacity, survivor_desired_capacity);
+
+ if (PrintGC) {
+ gclog_or_tty->print("AFTER: Young Gen: ");
+ gclog_or_tty->print("eden capacity : " SIZE_FORMAT ", ",
+ eden_space()->capacity_in_bytes());
+ gclog_or_tty->print("eden used : " SIZE_FORMAT ", " ,
+ eden_space()->used_in_bytes());
+ gclog_or_tty->print("survivor capacity : " SIZE_FORMAT ", ",
+ from_space()->capacity_in_bytes());
+ gclog_or_tty->print_cr("survivor used : " SIZE_FORMAT ", " ,
+ from_space()->used_in_bytes());
+ }
+}