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

changeset 0
f90c822e73f8
child 1
2d8a650513c2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/parallelScavenge/psPromotionLAB.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,167 @@
     1.4 +/*
     1.5 + * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "precompiled.hpp"
    1.29 +#include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
    1.30 +#include "gc_implementation/parallelScavenge/psPromotionLAB.hpp"
    1.31 +#include "gc_implementation/shared/mutableSpace.hpp"
    1.32 +#include "oops/oop.inline.hpp"
    1.33 +
    1.34 +size_t PSPromotionLAB::filler_header_size;
    1.35 +
    1.36 +// This is the shared initialization code. It sets up the basic pointers,
    1.37 +// and allows enough extra space for a filler object. We call a virtual
    1.38 +// method, "lab_is_valid()" to handle the different asserts the old/young
    1.39 +// labs require.
    1.40 +void PSPromotionLAB::initialize(MemRegion lab) {
    1.41 +  assert(lab_is_valid(lab), "Sanity");
    1.42 +
    1.43 +  HeapWord* bottom = lab.start();
    1.44 +  HeapWord* end    = lab.end();
    1.45 +
    1.46 +  set_bottom(bottom);
    1.47 +  set_end(end);
    1.48 +  set_top(bottom);
    1.49 +
    1.50 +  // Initialize after VM starts up because header_size depends on compressed
    1.51 +  // oops.
    1.52 +  filler_header_size = align_object_size(typeArrayOopDesc::header_size(T_INT));
    1.53 +
    1.54 +  // We can be initialized to a zero size!
    1.55 +  if (free() > 0) {
    1.56 +    if (ZapUnusedHeapArea) {
    1.57 +      debug_only(Copy::fill_to_words(top(), free()/HeapWordSize, badHeapWord));
    1.58 +    }
    1.59 +
    1.60 +    // NOTE! We need to allow space for a filler object.
    1.61 +    assert(lab.word_size() >= filler_header_size, "lab is too small");
    1.62 +    end = end - filler_header_size;
    1.63 +    set_end(end);
    1.64 +
    1.65 +    _state = needs_flush;
    1.66 +  } else {
    1.67 +    _state = zero_size;
    1.68 +  }
    1.69 +
    1.70 +  assert(this->top() <= this->end(), "pointers out of order");
    1.71 +}
    1.72 +
    1.73 +// Fill all remaining lab space with an unreachable object.
    1.74 +// The goal is to leave a contiguous parseable span of objects.
    1.75 +void PSPromotionLAB::flush() {
    1.76 +  assert(_state != flushed, "Attempt to flush PLAB twice");
    1.77 +  assert(top() <= end(), "pointers out of order");
    1.78 +
    1.79 +  // If we were initialized to a zero sized lab, there is
    1.80 +  // nothing to flush
    1.81 +  if (_state == zero_size)
    1.82 +    return;
    1.83 +
    1.84 +  // PLAB's never allocate the last aligned_header_size
    1.85 +  // so they can always fill with an array.
    1.86 +  HeapWord* tlab_end = end() + filler_header_size;
    1.87 +  typeArrayOop filler_oop = (typeArrayOop) top();
    1.88 +  filler_oop->set_mark(markOopDesc::prototype());
    1.89 +  filler_oop->set_klass(Universe::intArrayKlassObj());
    1.90 +  const size_t array_length =
    1.91 +    pointer_delta(tlab_end, top()) - typeArrayOopDesc::header_size(T_INT);
    1.92 +  assert( (array_length * (HeapWordSize/sizeof(jint))) < (size_t)max_jint, "array too big in PSPromotionLAB");
    1.93 +  filler_oop->set_length((int)(array_length * (HeapWordSize/sizeof(jint))));
    1.94 +
    1.95 +#ifdef ASSERT
    1.96 +  // Note that we actually DO NOT want to use the aligned header size!
    1.97 +  HeapWord* elt_words = ((HeapWord*)filler_oop) + typeArrayOopDesc::header_size(T_INT);
    1.98 +  Copy::fill_to_words(elt_words, array_length, 0xDEAABABE);
    1.99 +#endif
   1.100 +
   1.101 +  set_bottom(NULL);
   1.102 +  set_end(NULL);
   1.103 +  set_top(NULL);
   1.104 +
   1.105 +  _state = flushed;
   1.106 +}
   1.107 +
   1.108 +bool PSPromotionLAB::unallocate_object(HeapWord* obj, size_t obj_size) {
   1.109 +  assert(Universe::heap()->is_in(obj), "Object outside heap");
   1.110 +
   1.111 +  if (contains(obj)) {
   1.112 +    HeapWord* object_end = obj + obj_size;
   1.113 +    assert(object_end == top(), "Not matching last allocation");
   1.114 +
   1.115 +    set_top(obj);
   1.116 +    return true;
   1.117 +  }
   1.118 +
   1.119 +  return false;
   1.120 +}
   1.121 +
   1.122 +// Fill all remaining lab space with an unreachable object.
   1.123 +// The goal is to leave a contiguous parseable span of objects.
   1.124 +void PSOldPromotionLAB::flush() {
   1.125 +  assert(_state != flushed, "Attempt to flush PLAB twice");
   1.126 +  assert(top() <= end(), "pointers out of order");
   1.127 +
   1.128 +  if (_state == zero_size)
   1.129 +    return;
   1.130 +
   1.131 +  HeapWord* obj = top();
   1.132 +
   1.133 +  PSPromotionLAB::flush();
   1.134 +
   1.135 +  assert(_start_array != NULL, "Sanity");
   1.136 +
   1.137 +  _start_array->allocate_block(obj);
   1.138 +}
   1.139 +
   1.140 +#ifdef ASSERT
   1.141 +
   1.142 +bool PSYoungPromotionLAB::lab_is_valid(MemRegion lab) {
   1.143 +  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
   1.144 +  assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
   1.145 +
   1.146 +  MutableSpace* to_space = heap->young_gen()->to_space();
   1.147 +  MemRegion used = to_space->used_region();
   1.148 +  if (used.contains(lab)) {
   1.149 +    return true;
   1.150 +  }
   1.151 +
   1.152 +  return false;
   1.153 +}
   1.154 +
   1.155 +bool PSOldPromotionLAB::lab_is_valid(MemRegion lab) {
   1.156 +  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
   1.157 +  assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
   1.158 +  assert(_start_array->covered_region().contains(lab), "Sanity");
   1.159 +
   1.160 +  PSOldGen* old_gen = heap->old_gen();
   1.161 +  MemRegion used = old_gen->object_space()->used_region();
   1.162 +
   1.163 +  if (used.contains(lab)) {
   1.164 +    return true;
   1.165 +  }
   1.166 +
   1.167 +  return false;
   1.168 +}
   1.169 +
   1.170 +#endif /* ASSERT */

mercurial