src/hotspot/share/gc/parallel/psPromotionLAB.cpp
author stefank
Tue, 06 Aug 2019 10:48:21 +0200
changeset 57777 90ead0febf56
parent 54786 ebf733a324d4
permissions -rw-r--r--
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier Reviewed-by: rkennke, coleenp, kbarrett, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
49722
a47d1e21b3f1 8199735: Mark word updates need to use Access API
rkennke
parents: 47216
diff changeset
     2
 * Copyright (c) 2002, 2018, 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"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 49722
diff changeset
    29
#include "memory/universe.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "oops/oop.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    32
size_t PSPromotionLAB::filler_header_size;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// This is the shared initialization code. It sets up the basic pointers,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// and allows enough extra space for a filler object. We call a virtual
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// method, "lab_is_valid()" to handle the different asserts the old/young
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// labs require.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
void PSPromotionLAB::initialize(MemRegion lab) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  assert(lab_is_valid(lab), "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  HeapWord* bottom = lab.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  HeapWord* end    = lab.end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  set_bottom(bottom);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  set_end(end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  set_top(bottom);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    48
  // 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
    49
  // oops.
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    50
  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
    51
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  // We can be initialized to a zero size!
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  if (free() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    if (ZapUnusedHeapArea) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
      debug_only(Copy::fill_to_words(top(), free()/HeapWordSize, badHeapWord));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    // NOTE! We need to allow space for a filler object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    assert(lab.word_size() >= filler_header_size, "lab is too small");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    end = end - filler_header_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    set_end(end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    _state = needs_flush;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    _state = zero_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  assert(this->top() <= this->end(), "pointers out of order");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
// Fill all remaining lab space with an unreachable object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
// The goal is to leave a contiguous parseable span of objects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
void PSPromotionLAB::flush() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  assert(_state != flushed, "Attempt to flush PLAB twice");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  assert(top() <= end(), "pointers out of order");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // If we were initialized to a zero sized lab, there is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // nothing to flush
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  if (_state == zero_size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  // PLAB's never allocate the last aligned_header_size
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // so they can always fill with an array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  HeapWord* tlab_end = end() + filler_header_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  typeArrayOop filler_oop = (typeArrayOop) top();
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54786
diff changeset
    86
  filler_oop->set_mark_raw(markWord::prototype());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  filler_oop->set_klass(Universe::intArrayKlassObj());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  const size_t array_length =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    pointer_delta(tlab_end, top()) - typeArrayOopDesc::header_size(T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  assert( (array_length * (HeapWordSize/sizeof(jint))) < (size_t)max_jint, "array too big in PSPromotionLAB");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  filler_oop->set_length((int)(array_length * (HeapWordSize/sizeof(jint))));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // Note that we actually DO NOT want to use the aligned header size!
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  HeapWord* elt_words = ((HeapWord*)filler_oop) + typeArrayOopDesc::header_size(T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  Copy::fill_to_words(elt_words, array_length, 0xDEAABABE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  set_bottom(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  set_end(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  set_top(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  _state = flushed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
10676
1e1510b8031a 7021322: assert(object_end <= top()) failed: Object crosses promotion LAB boundary
stefank
parents: 7397
diff changeset
   106
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
   107
  assert(ParallelScavengeHeap::heap()->is_in(obj), "Object outside heap");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  if (contains(obj)) {
10676
1e1510b8031a 7021322: assert(object_end <= top()) failed: Object crosses promotion LAB boundary
stefank
parents: 7397
diff changeset
   110
    HeapWord* object_end = obj + obj_size;
1e1510b8031a 7021322: assert(object_end <= top()) failed: Object crosses promotion LAB boundary
stefank
parents: 7397
diff changeset
   111
    assert(object_end == top(), "Not matching last allocation");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
10676
1e1510b8031a 7021322: assert(object_end <= top()) failed: Object crosses promotion LAB boundary
stefank
parents: 7397
diff changeset
   113
    set_top(obj);
1e1510b8031a 7021322: assert(object_end <= top()) failed: Object crosses promotion LAB boundary
stefank
parents: 7397
diff changeset
   114
    return true;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
// Fill all remaining lab space with an unreachable object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
// The goal is to leave a contiguous parseable span of objects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
void PSOldPromotionLAB::flush() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  assert(_state != flushed, "Attempt to flush PLAB twice");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  assert(top() <= end(), "pointers out of order");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  if (_state == zero_size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  HeapWord* obj = top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  PSPromotionLAB::flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  assert(_start_array != NULL, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  _start_array->allocate_block(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
bool PSYoungPromotionLAB::lab_is_valid(MemRegion lab) {
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 10676
diff changeset
   141
  ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  MutableSpace* to_space = heap->young_gen()->to_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  MemRegion used = to_space->used_region();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  if (used.contains(lab)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
bool PSOldPromotionLAB::lab_is_valid(MemRegion lab) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  assert(_start_array->covered_region().contains(lab), "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 10676
diff changeset
   154
  ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  PSOldGen* old_gen = heap->old_gen();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  MemRegion used = old_gen->object_space()->used_region();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  if (used.contains(lab)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
#endif /* ASSERT */