asPSYoungGen.cpp revision 8413:92457dfb91bd
1193323Sed/*
2193323Sed * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
3193323Sed * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4193323Sed *
5193323Sed * This code is free software; you can redistribute it and/or modify it
6193323Sed * under the terms of the GNU General Public License version 2 only, as
7193323Sed * published by the Free Software Foundation.
8193323Sed *
9193323Sed * This code is distributed in the hope that it will be useful, but WITHOUT
10193323Sed * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11193323Sed * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12193323Sed * version 2 for more details (a copy is included in the LICENSE file that
13193323Sed * accompanied this code).
14193323Sed *
15193323Sed * You should have received a copy of the GNU General Public License version
16193323Sed * 2 along with this work; if not, write to the Free Software Foundation,
17193323Sed * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18193323Sed *
19249423Sdim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20249423Sdim * or visit www.oracle.com if you need additional information or have any
21249423Sdim * questions.
22193323Sed *
23193323Sed */
24193323Sed
25193323Sed#include "precompiled.hpp"
26193323Sed#include "gc/parallel/asPSYoungGen.hpp"
27193323Sed#include "gc/parallel/parallelScavengeHeap.hpp"
28193323Sed#include "gc/parallel/psMarkSweepDecorator.hpp"
29198090Srdivacky#include "gc/parallel/psScavenge.hpp"
30193323Sed#include "gc/parallel/psYoungGen.hpp"
31193323Sed#include "gc/shared/gcUtil.hpp"
32218893Sdim#include "gc/shared/spaceDecorator.hpp"
33218893Sdim#include "oops/oop.inline.hpp"
34218893Sdim#include "runtime/java.hpp"
35239462Sdim
36193323SedASPSYoungGen::ASPSYoungGen(size_t init_byte_size,
37249423Sdim                           size_t minimum_byte_size,
38239462Sdim                           size_t byte_size_limit) :
39249423Sdim  PSYoungGen(init_byte_size, minimum_byte_size, byte_size_limit),
40193323Sed  _gen_size_limit(byte_size_limit) {
41193323Sed}
42212904Sdim
43193323Sed
44193323SedASPSYoungGen::ASPSYoungGen(PSVirtualSpace* vs,
45239462Sdim                           size_t init_byte_size,
46193323Sed                           size_t minimum_byte_size,
47193323Sed                           size_t byte_size_limit) :
48193323Sed  //PSYoungGen(init_byte_size, minimum_byte_size, byte_size_limit),
49193323Sed  PSYoungGen(vs->committed_size(), minimum_byte_size, byte_size_limit),
50193323Sed  _gen_size_limit(byte_size_limit) {
51193323Sed
52249423Sdim  assert(vs->committed_size() == init_byte_size, "Cannot replace with");
53249423Sdim
54249423Sdim  _virtual_space = vs;
55249423Sdim}
56249423Sdim
57249423Sdimvoid ASPSYoungGen::initialize_virtual_space(ReservedSpace rs,
58193323Sed                                            size_t alignment) {
59193323Sed  assert(_init_gen_size != 0, "Should have a finite size");
60239462Sdim  _virtual_space = new PSVirtualSpaceHighToLow(rs, alignment);
61193323Sed  if (!_virtual_space->expand_by(_init_gen_size)) {
62218893Sdim    vm_exit_during_initialization("Could not reserve enough space for "
63218893Sdim                                  "object heap");
64218893Sdim  }
65218893Sdim}
66218893Sdim
67218893Sdimvoid ASPSYoungGen::initialize(ReservedSpace rs, size_t alignment) {
68218893Sdim  initialize_virtual_space(rs, alignment);
69218893Sdim  initialize_work();
70218893Sdim}
71193323Sed
72249423Sdimsize_t ASPSYoungGen::available_for_expansion() {
73193323Sed  size_t current_committed_size = virtual_space()->committed_size();
74193323Sed  assert((gen_size_limit() >= current_committed_size),
75193323Sed    "generation size limit is wrong");
76249423Sdim  ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
77193323Sed  size_t result =  gen_size_limit() - current_committed_size;
78193323Sed  size_t result_aligned = align_size_down(result, heap->generation_alignment());
79249423Sdim  return result_aligned;
80249423Sdim}
81249423Sdim
82198090Srdivacky// Return the number of bytes the young gen is willing give up.
83249423Sdim//
84239462Sdim// Future implementations could check the survivors and if to_space is in the
85193323Sed// right place (below from_space), take a chunk from to_space.
86193323Sedsize_t ASPSYoungGen::available_for_contraction() {
87193323Sed  size_t uncommitted_bytes = virtual_space()->uncommitted_size();
88193323Sed  if (uncommitted_bytes != 0) {
89193323Sed    return uncommitted_bytes;
90193323Sed  }
91249423Sdim
92249423Sdim  if (eden_space()->is_empty()) {
93219077Sdim    // Respect the minimum size for eden and for the young gen as a whole.
94219077Sdim    ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
95219077Sdim    const size_t eden_alignment = heap->space_alignment();
96219077Sdim    const size_t gen_alignment = heap->generation_alignment();
97219077Sdim
98249423Sdim    assert(eden_space()->capacity_in_bytes() >= eden_alignment,
99219077Sdim      "Alignment is wrong");
100219077Sdim    size_t eden_avail = eden_space()->capacity_in_bytes() - eden_alignment;
101219077Sdim    eden_avail = align_size_down(eden_avail, gen_alignment);
102239462Sdim
103249423Sdim    assert(virtual_space()->committed_size() >= min_gen_size(),
104198090Srdivacky      "minimum gen size is wrong");
105193323Sed    size_t gen_avail = virtual_space()->committed_size() - min_gen_size();
106219077Sdim    assert(virtual_space()->is_aligned(gen_avail), "not aligned");
107210299Sed
108193323Sed    const size_t max_contraction = MIN2(eden_avail, gen_avail);
109239462Sdim    // See comment for ASPSOldGen::available_for_contraction()
110193323Sed    // for reasons the "increment" fraction is used.
111193323Sed    PSAdaptiveSizePolicy* policy = heap->size_policy();
112193323Sed    size_t result = policy->eden_increment_aligned_down(max_contraction);
113193323Sed    size_t result_aligned = align_size_down(result, gen_alignment);
114193323Sed    if (PrintAdaptiveSizePolicy && Verbose) {
115193323Sed      gclog_or_tty->print_cr("ASPSYoungGen::available_for_contraction: " SIZE_FORMAT " K",
116193323Sed        result_aligned/K);
117193323Sed      gclog_or_tty->print_cr("  max_contraction " SIZE_FORMAT " K", max_contraction/K);
118193323Sed      gclog_or_tty->print_cr("  eden_avail " SIZE_FORMAT " K", eden_avail/K);
119193323Sed      gclog_or_tty->print_cr("  gen_avail " SIZE_FORMAT " K", gen_avail/K);
120193323Sed    }
121193323Sed    return result_aligned;
122239462Sdim  }
123193323Sed
124193323Sed  return 0;
125193323Sed}
126193323Sed
127239462Sdim// The current implementation only considers to the end of eden.
128193323Sed// If to_space is below from_space, to_space is not considered.
129193323Sed// to_space can be.
130193323Sedsize_t ASPSYoungGen::available_to_live() {
131193323Sed  ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
132249423Sdim  const size_t alignment = heap->space_alignment();
133239462Sdim
134193323Sed  // Include any space that is committed but is not in eden.
135249423Sdim  size_t available = pointer_delta(eden_space()->bottom(),
136193323Sed                                   virtual_space()->low(),
137193323Sed                                   sizeof(char));
138239462Sdim
139199481Srdivacky  const size_t eden_capacity = eden_space()->capacity_in_bytes();
140199481Srdivacky  if (eden_space()->is_empty() && eden_capacity > alignment) {
141199481Srdivacky    available += eden_capacity - alignment;
142199481Srdivacky  }
143193323Sed  return available;
144193323Sed}
145193323Sed
146193323Sed// Similar to PSYoungGen::resize_generation() but
147239462Sdim//  allows sum of eden_size and 2 * survivor_size to exceed _max_gen_size
148193323Sed//  expands at the low end of the virtual space
149193323Sed//  moves the boundary between the generations in order to expand
150239462Sdim//  some additional diagnostics
151193323Sed// If no additional changes are required, this can be deleted
152193323Sed// and the changes factored back into PSYoungGen::resize_generation().
153239462Sdimbool ASPSYoungGen::resize_generation(size_t eden_size, size_t survivor_size) {
154193323Sed  const size_t alignment = virtual_space()->alignment();
155193323Sed  size_t orig_size = virtual_space()->committed_size();
156193323Sed  bool size_changed = false;
157193323Sed
158193323Sed  // There used to be a guarantee here that
159193323Sed  //   (eden_size + 2*survivor_size)  <= _max_gen_size
160239462Sdim  // This requirement is enforced by the calculation of desired_size
161193323Sed  // below.  It may not be true on entry since the size of the
162198090Srdivacky  // eden_size is no bounded by the generation size.
163249423Sdim
164198090Srdivacky  assert(max_size() == reserved().byte_size(), "max gen size problem?");
165239462Sdim  assert(min_gen_size() <= orig_size && orig_size <= max_size(),
166193323Sed         "just checking");
167193323Sed
168249423Sdim  // Adjust new generation size
169198892Srdivacky  const size_t eden_plus_survivors =
170193323Sed    align_size_up(eden_size + 2 * survivor_size, alignment);
171198090Srdivacky  size_t desired_size = MAX2(MIN2(eden_plus_survivors, gen_size_limit()),
172239462Sdim                             min_gen_size());
173193323Sed  assert(desired_size <= gen_size_limit(), "just checking");
174239462Sdim
175249423Sdim  if (desired_size > orig_size) {
176239462Sdim    // Grow the generation
177193323Sed    size_t change = desired_size - orig_size;
178193323Sed    HeapWord* prev_low = (HeapWord*) virtual_space()->low();
179193323Sed    if (!virtual_space()->expand_by(change)) {
180198090Srdivacky      return false;
181198090Srdivacky    }
182198090Srdivacky    if (ZapUnusedHeapArea) {
183198090Srdivacky      // Mangle newly committed space immediately because it
184198892Srdivacky      // can be done here more simply that after the new
185198090Srdivacky      // spaces have been computed.
186193323Sed      HeapWord* new_low = (HeapWord*) virtual_space()->low();
187249423Sdim      assert(new_low < prev_low, "Did not grow");
188193323Sed
189193323Sed      MemRegion mangle_region(new_low, prev_low);
190193323Sed      SpaceMangler::mangle_region(mangle_region);
191193323Sed    }
192249423Sdim    size_changed = true;
193193323Sed  } else if (desired_size < orig_size) {
194249423Sdim    size_t desired_change = orig_size - desired_size;
195224145Sdim
196224145Sdim    // How much is available for shrinking.
197224145Sdim    size_t available_bytes = limit_gen_shrink(desired_change);
198219077Sdim    size_t change = MIN2(desired_change, available_bytes);
199219077Sdim    virtual_space()->shrink_by(change);
200210299Sed    size_changed = true;
201193323Sed  } else {
202239462Sdim    if (Verbose && PrintGC) {
203193323Sed      if (orig_size == gen_size_limit()) {
204193323Sed        gclog_or_tty->print_cr("ASPSYoung generation size at maximum: "
205249423Sdim          SIZE_FORMAT "K", orig_size/K);
206218893Sdim      } else if (orig_size == min_gen_size()) {
207193323Sed        gclog_or_tty->print_cr("ASPSYoung generation size at minium: "
208193323Sed          SIZE_FORMAT "K", orig_size/K);
209193323Sed      }
210193323Sed    }
211218893Sdim  }
212218893Sdim
213193323Sed  if (size_changed) {
214193323Sed    reset_after_change();
215193323Sed    if (Verbose && PrintGC) {
216239462Sdim      size_t current_size  = virtual_space()->committed_size();
217193323Sed      gclog_or_tty->print_cr("ASPSYoung generation size changed: "
218193323Sed        SIZE_FORMAT "K->" SIZE_FORMAT "K",
219193323Sed        orig_size/K, current_size/K);
220193323Sed    }
221193323Sed  }
222193323Sed
223193323Sed  guarantee(eden_plus_survivors <= virtual_space()->committed_size() ||
224239462Sdim            virtual_space()->committed_size() == max_size(), "Sanity");
225193323Sed
226193323Sed  return true;
227193323Sed}
228193323Sed
229193323Sed// Similar to PSYoungGen::resize_spaces() but
230193323Sed//  eden always starts at the low end of the committed virtual space
231193323Sed//  current implementation does not allow holes between the spaces
232193323Sed//  _young_generation_boundary has to be reset because it changes.
233193323Sed//  so additional verification
234193323Sed
235249423Sdimvoid ASPSYoungGen::resize_spaces(size_t requested_eden_size,
236193323Sed                                 size_t requested_survivor_size) {
237193323Sed  assert(UseAdaptiveSizePolicy, "sanity check");
238193323Sed  assert(requested_eden_size > 0 && requested_survivor_size > 0,
239193323Sed         "just checking");
240193323Sed
241239462Sdim  space_invariants();
242193323Sed
243193323Sed  // We require eden and to space to be empty
244193323Sed  if ((!eden_space()->is_empty()) || (!to_space()->is_empty())) {
245198090Srdivacky    return;
246239462Sdim  }
247210299Sed
248239462Sdim  if (PrintAdaptiveSizePolicy && Verbose) {
249198090Srdivacky    gclog_or_tty->print_cr("PSYoungGen::resize_spaces(requested_eden_size: "
250193323Sed                  SIZE_FORMAT
251                  ", requested_survivor_size: " SIZE_FORMAT ")",
252                  requested_eden_size, requested_survivor_size);
253    gclog_or_tty->print_cr("    eden: [" PTR_FORMAT ".." PTR_FORMAT ") "
254                  SIZE_FORMAT,
255                  p2i(eden_space()->bottom()),
256                  p2i(eden_space()->end()),
257                  pointer_delta(eden_space()->end(),
258                                eden_space()->bottom(),
259                                sizeof(char)));
260    gclog_or_tty->print_cr("    from: [" PTR_FORMAT ".." PTR_FORMAT ") "
261                  SIZE_FORMAT,
262                  p2i(from_space()->bottom()),
263                  p2i(from_space()->end()),
264                  pointer_delta(from_space()->end(),
265                                from_space()->bottom(),
266                                sizeof(char)));
267    gclog_or_tty->print_cr("      to: [" PTR_FORMAT ".." PTR_FORMAT ") "
268                  SIZE_FORMAT,
269                  p2i(to_space()->bottom()),
270                  p2i(to_space()->end()),
271                  pointer_delta(  to_space()->end(),
272                                  to_space()->bottom(),
273                                  sizeof(char)));
274  }
275
276  // There's nothing to do if the new sizes are the same as the current
277  if (requested_survivor_size == to_space()->capacity_in_bytes() &&
278      requested_survivor_size == from_space()->capacity_in_bytes() &&
279      requested_eden_size == eden_space()->capacity_in_bytes()) {
280    if (PrintAdaptiveSizePolicy && Verbose) {
281      gclog_or_tty->print_cr("    capacities are the right sizes, returning");
282    }
283    return;
284  }
285
286  char* eden_start = (char*)virtual_space()->low();
287  char* eden_end   = (char*)eden_space()->end();
288  char* from_start = (char*)from_space()->bottom();
289  char* from_end   = (char*)from_space()->end();
290  char* to_start   = (char*)to_space()->bottom();
291  char* to_end     = (char*)to_space()->end();
292
293  assert(eden_start < from_start, "Cannot push into from_space");
294
295  ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
296  const size_t alignment = heap->space_alignment();
297  const bool maintain_minimum =
298    (requested_eden_size + 2 * requested_survivor_size) <= min_gen_size();
299
300  bool eden_from_to_order = from_start < to_start;
301  // Check whether from space is below to space
302  if (eden_from_to_order) {
303    // Eden, from, to
304
305    if (PrintAdaptiveSizePolicy && Verbose) {
306      gclog_or_tty->print_cr("  Eden, from, to:");
307    }
308
309    // Set eden
310    // "requested_eden_size" is a goal for the size of eden
311    // and may not be attainable.  "eden_size" below is
312    // calculated based on the location of from-space and
313    // the goal for the size of eden.  from-space is
314    // fixed in place because it contains live data.
315    // The calculation is done this way to avoid 32bit
316    // overflow (i.e., eden_start + requested_eden_size
317    // may too large for representation in 32bits).
318    size_t eden_size;
319    if (maintain_minimum) {
320      // Only make eden larger than the requested size if
321      // the minimum size of the generation has to be maintained.
322      // This could be done in general but policy at a higher
323      // level is determining a requested size for eden and that
324      // should be honored unless there is a fundamental reason.
325      eden_size = pointer_delta(from_start,
326                                eden_start,
327                                sizeof(char));
328    } else {
329      eden_size = MIN2(requested_eden_size,
330                       pointer_delta(from_start, eden_start, sizeof(char)));
331    }
332
333    eden_end = eden_start + eden_size;
334    assert(eden_end >= eden_start, "addition overflowed");
335
336    // To may resize into from space as long as it is clear of live data.
337    // From space must remain page aligned, though, so we need to do some
338    // extra calculations.
339
340    // First calculate an optimal to-space
341    to_end   = (char*)virtual_space()->high();
342    to_start = (char*)pointer_delta(to_end,
343                                    (char*)requested_survivor_size,
344                                    sizeof(char));
345
346    // Does the optimal to-space overlap from-space?
347    if (to_start < (char*)from_space()->end()) {
348      // Calculate the minimum offset possible for from_end
349      size_t from_size =
350        pointer_delta(from_space()->top(), from_start, sizeof(char));
351
352      // Should we be in this method if from_space is empty? Why not the set_space method? FIX ME!
353      if (from_size == 0) {
354        from_size = alignment;
355      } else {
356        from_size = align_size_up(from_size, alignment);
357      }
358
359      from_end = from_start + from_size;
360      assert(from_end > from_start, "addition overflow or from_size problem");
361
362      guarantee(from_end <= (char*)from_space()->end(),
363        "from_end moved to the right");
364
365      // Now update to_start with the new from_end
366      to_start = MAX2(from_end, to_start);
367    }
368
369    guarantee(to_start != to_end, "to space is zero sized");
370
371    if (PrintAdaptiveSizePolicy && Verbose) {
372      gclog_or_tty->print_cr("    [eden_start .. eden_end): "
373                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
374                    p2i(eden_start),
375                    p2i(eden_end),
376                    pointer_delta(eden_end, eden_start, sizeof(char)));
377      gclog_or_tty->print_cr("    [from_start .. from_end): "
378                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
379                    p2i(from_start),
380                    p2i(from_end),
381                    pointer_delta(from_end, from_start, sizeof(char)));
382      gclog_or_tty->print_cr("    [  to_start ..   to_end): "
383                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
384                    p2i(to_start),
385                    p2i(to_end),
386                    pointer_delta(  to_end,   to_start, sizeof(char)));
387    }
388  } else {
389    // Eden, to, from
390    if (PrintAdaptiveSizePolicy && Verbose) {
391      gclog_or_tty->print_cr("  Eden, to, from:");
392    }
393
394    // To space gets priority over eden resizing. Note that we position
395    // to space as if we were able to resize from space, even though from
396    // space is not modified.
397    // Giving eden priority was tried and gave poorer performance.
398    to_end   = (char*)pointer_delta(virtual_space()->high(),
399                                    (char*)requested_survivor_size,
400                                    sizeof(char));
401    to_end   = MIN2(to_end, from_start);
402    to_start = (char*)pointer_delta(to_end, (char*)requested_survivor_size,
403                                    sizeof(char));
404    // if the space sizes are to be increased by several times then
405    // 'to_start' will point beyond the young generation. In this case
406    // 'to_start' should be adjusted.
407    to_start = MAX2(to_start, eden_start + alignment);
408
409    // Compute how big eden can be, then adjust end.
410    // See  comments above on calculating eden_end.
411    size_t eden_size;
412    if (maintain_minimum) {
413      eden_size = pointer_delta(to_start, eden_start, sizeof(char));
414    } else {
415      eden_size = MIN2(requested_eden_size,
416                       pointer_delta(to_start, eden_start, sizeof(char)));
417    }
418    eden_end = eden_start + eden_size;
419    assert(eden_end >= eden_start, "addition overflowed");
420
421    // Don't let eden shrink down to 0 or less.
422    eden_end = MAX2(eden_end, eden_start + alignment);
423    to_start = MAX2(to_start, eden_end);
424
425    if (PrintAdaptiveSizePolicy && Verbose) {
426      gclog_or_tty->print_cr("    [eden_start .. eden_end): "
427                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
428                    p2i(eden_start),
429                    p2i(eden_end),
430                    pointer_delta(eden_end, eden_start, sizeof(char)));
431      gclog_or_tty->print_cr("    [  to_start ..   to_end): "
432                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
433                    p2i(to_start),
434                    p2i(to_end),
435                    pointer_delta(  to_end,   to_start, sizeof(char)));
436      gclog_or_tty->print_cr("    [from_start .. from_end): "
437                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
438                    p2i(from_start),
439                    p2i(from_end),
440                    pointer_delta(from_end, from_start, sizeof(char)));
441    }
442  }
443
444
445  guarantee((HeapWord*)from_start <= from_space()->bottom(),
446            "from start moved to the right");
447  guarantee((HeapWord*)from_end >= from_space()->top(),
448            "from end moved into live data");
449  assert(is_object_aligned((intptr_t)eden_start), "checking alignment");
450  assert(is_object_aligned((intptr_t)from_start), "checking alignment");
451  assert(is_object_aligned((intptr_t)to_start), "checking alignment");
452
453  MemRegion edenMR((HeapWord*)eden_start, (HeapWord*)eden_end);
454  MemRegion toMR  ((HeapWord*)to_start,   (HeapWord*)to_end);
455  MemRegion fromMR((HeapWord*)from_start, (HeapWord*)from_end);
456
457  // Let's make sure the call to initialize doesn't reset "top"!
458  DEBUG_ONLY(HeapWord* old_from_top = from_space()->top();)
459
460  // For PrintAdaptiveSizePolicy block  below
461  size_t old_from = from_space()->capacity_in_bytes();
462  size_t old_to   = to_space()->capacity_in_bytes();
463
464  if (ZapUnusedHeapArea) {
465    // NUMA is a special case because a numa space is not mangled
466    // in order to not prematurely bind its address to memory to
467    // the wrong memory (i.e., don't want the GC thread to first
468    // touch the memory).  The survivor spaces are not numa
469    // spaces and are mangled.
470    if (UseNUMA) {
471      if (eden_from_to_order) {
472        mangle_survivors(from_space(), fromMR, to_space(), toMR);
473      } else {
474        mangle_survivors(to_space(), toMR, from_space(), fromMR);
475      }
476    }
477
478    // If not mangling the spaces, do some checking to verify that
479    // the spaces are already mangled.
480    // The spaces should be correctly mangled at this point so
481    // do some checking here. Note that they are not being mangled
482    // in the calls to initialize().
483    // Must check mangling before the spaces are reshaped.  Otherwise,
484    // the bottom or end of one space may have moved into an area
485    // covered by another space and a failure of the check may
486    // not correctly indicate which space is not properly mangled.
487
488    HeapWord* limit = (HeapWord*) virtual_space()->high();
489    eden_space()->check_mangled_unused_area(limit);
490    from_space()->check_mangled_unused_area(limit);
491      to_space()->check_mangled_unused_area(limit);
492  }
493  // When an existing space is being initialized, it is not
494  // mangled because the space has been previously mangled.
495  eden_space()->initialize(edenMR,
496                           SpaceDecorator::Clear,
497                           SpaceDecorator::DontMangle);
498    to_space()->initialize(toMR,
499                           SpaceDecorator::Clear,
500                           SpaceDecorator::DontMangle);
501  from_space()->initialize(fromMR,
502                           SpaceDecorator::DontClear,
503                           SpaceDecorator::DontMangle);
504
505  PSScavenge::set_young_generation_boundary(eden_space()->bottom());
506
507  assert(from_space()->top() == old_from_top, "from top changed!");
508
509  if (PrintAdaptiveSizePolicy) {
510    ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
511    gclog_or_tty->print("AdaptiveSizePolicy::survivor space sizes: "
512                  "collection: %d "
513                  "(" SIZE_FORMAT ", " SIZE_FORMAT ") -> "
514                  "(" SIZE_FORMAT ", " SIZE_FORMAT ") ",
515                  heap->total_collections(),
516                  old_from, old_to,
517                  from_space()->capacity_in_bytes(),
518                  to_space()->capacity_in_bytes());
519    gclog_or_tty->cr();
520  }
521  space_invariants();
522}
523void ASPSYoungGen::reset_after_change() {
524  assert_locked_or_safepoint(Heap_lock);
525
526  _reserved = MemRegion((HeapWord*)virtual_space()->low_boundary(),
527                        (HeapWord*)virtual_space()->high_boundary());
528  PSScavenge::reference_processor()->set_span(_reserved);
529
530  HeapWord* new_eden_bottom = (HeapWord*)virtual_space()->low();
531  HeapWord* eden_bottom = eden_space()->bottom();
532  if (new_eden_bottom != eden_bottom) {
533    MemRegion eden_mr(new_eden_bottom, eden_space()->end());
534    eden_space()->initialize(eden_mr,
535                             SpaceDecorator::Clear,
536                             SpaceDecorator::Mangle);
537    PSScavenge::set_young_generation_boundary(eden_space()->bottom());
538  }
539  MemRegion cmr((HeapWord*)virtual_space()->low(),
540                (HeapWord*)virtual_space()->high());
541  ParallelScavengeHeap::heap()->barrier_set()->resize_covered_region(cmr);
542
543  space_invariants();
544}
545