hotspot/src/share/vm/gc/parallel/psPromotionLAB.cpp
author stefank
Tue, 11 Apr 2017 23:45:37 +0200
changeset 46565 8dcbf532ea00
parent 30764 fec48bf5a827
permissions -rw-r--r--
8178490: Usages of is_object_aligned with pointers are broken Reviewed-by: tschatzl, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 10676
diff changeset
     2
 * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    26
#include "gc/parallel/mutableSpace.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    27
#include "gc/parallel/parallelScavengeHeap.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    28
#include "gc/parallel/psPromotionLAB.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "oops/oop.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    31
size_t PSPromotionLAB::filler_header_size;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// This is the shared initialization code. It sets up the basic pointers,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// and allows enough extra space for a filler object. We call a virtual
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// method, "lab_is_valid()" to handle the different asserts the old/young
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// labs require.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
void PSPromotionLAB::initialize(MemRegion lab) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  assert(lab_is_valid(lab), "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  HeapWord* bottom = lab.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  HeapWord* end    = lab.end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  set_bottom(bottom);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  set_end(end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  set_top(bottom);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    47
  // Initialize after VM starts up because header_size depends on compressed
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    48
  // oops.
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    49
  filler_header_size = align_object_size(typeArrayOopDesc::header_size(T_INT));
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    50
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  // We can be initialized to a zero size!
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  if (free() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    if (ZapUnusedHeapArea) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
      debug_only(Copy::fill_to_words(top(), free()/HeapWordSize, badHeapWord));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    // NOTE! We need to allow space for a filler object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    assert(lab.word_size() >= filler_header_size, "lab is too small");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    end = end - filler_header_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    set_end(end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    _state = needs_flush;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    _state = zero_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  assert(this->top() <= this->end(), "pointers out of order");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
// Fill all remaining lab space with an unreachable object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
// The goal is to leave a contiguous parseable span of objects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
void PSPromotionLAB::flush() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  assert(_state != flushed, "Attempt to flush PLAB twice");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  assert(top() <= end(), "pointers out of order");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // If we were initialized to a zero sized lab, there is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // nothing to flush
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  if (_state == zero_size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  // PLAB's never allocate the last aligned_header_size
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  // so they can always fill with an array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  HeapWord* tlab_end = end() + filler_header_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  typeArrayOop filler_oop = (typeArrayOop) top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  filler_oop->set_mark(markOopDesc::prototype());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  filler_oop->set_klass(Universe::intArrayKlassObj());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  const size_t array_length =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    pointer_delta(tlab_end, top()) - typeArrayOopDesc::header_size(T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  assert( (array_length * (HeapWordSize/sizeof(jint))) < (size_t)max_jint, "array too big in PSPromotionLAB");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  filler_oop->set_length((int)(array_length * (HeapWordSize/sizeof(jint))));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  // Note that we actually DO NOT want to use the aligned header size!
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  HeapWord* elt_words = ((HeapWord*)filler_oop) + typeArrayOopDesc::header_size(T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  Copy::fill_to_words(elt_words, array_length, 0xDEAABABE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  set_bottom(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  set_end(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  set_top(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  _state = flushed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
10676
1e1510b8031a 7021322: assert(object_end <= top()) failed: Object crosses promotion LAB boundary
stefank
parents: 7397
diff changeset
   105
bool PSPromotionLAB::unallocate_object(HeapWord* obj, size_t obj_size) {
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 10676
diff changeset
   106
  assert(ParallelScavengeHeap::heap()->is_in(obj), "Object outside heap");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  if (contains(obj)) {
10676
1e1510b8031a 7021322: assert(object_end <= top()) failed: Object crosses promotion LAB boundary
stefank
parents: 7397
diff changeset
   109
    HeapWord* object_end = obj + obj_size;
1e1510b8031a 7021322: assert(object_end <= top()) failed: Object crosses promotion LAB boundary
stefank
parents: 7397
diff changeset
   110
    assert(object_end == top(), "Not matching last allocation");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
10676
1e1510b8031a 7021322: assert(object_end <= top()) failed: Object crosses promotion LAB boundary
stefank
parents: 7397
diff changeset
   112
    set_top(obj);
1e1510b8031a 7021322: assert(object_end <= top()) failed: Object crosses promotion LAB boundary
stefank
parents: 7397
diff changeset
   113
    return true;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
// Fill all remaining lab space with an unreachable object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
// The goal is to leave a contiguous parseable span of objects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
void PSOldPromotionLAB::flush() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  assert(_state != flushed, "Attempt to flush PLAB twice");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  assert(top() <= end(), "pointers out of order");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  if (_state == zero_size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  HeapWord* obj = top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  PSPromotionLAB::flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  assert(_start_array != NULL, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  _start_array->allocate_block(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
bool PSYoungPromotionLAB::lab_is_valid(MemRegion lab) {
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 10676
diff changeset
   140
  ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  MutableSpace* to_space = heap->young_gen()->to_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  MemRegion used = to_space->used_region();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  if (used.contains(lab)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
bool PSOldPromotionLAB::lab_is_valid(MemRegion lab) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  assert(_start_array->covered_region().contains(lab), "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 10676
diff changeset
   153
  ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  PSOldGen* old_gen = heap->old_gen();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  MemRegion used = old_gen->object_space()->used_region();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  if (used.contains(lab)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
#endif /* ASSERT */