src/hotspot/share/gc/cms/promotionInfo.cpp
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 57812 9bb28ccc6106
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5434
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
     1
/*
49722
a47d1e21b3f1 8199735: Mark word updates need to use Access API
rkennke
parents: 49592
diff changeset
     2
 * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
5434
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
     4
 *
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
     8
 *
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    13
 * accompanied this code).
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    14
 *
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5541
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5541
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: 5541
diff changeset
    21
 * questions.
5434
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    22
 *
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    23
 */
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6447
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30150
diff changeset
    26
#include "gc/cms/compactibleFreeListSpace.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30150
diff changeset
    27
#include "gc/cms/promotionInfo.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30150
diff changeset
    28
#include "gc/shared/genOopClosures.hpp"
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 47216
diff changeset
    29
#include "oops/compressedOops.inline.hpp"
57811
947252a54b98 8229838: Rename markOop files to markWord
stefank
parents: 57777
diff changeset
    30
#include "oops/markWord.inline.hpp"
57812
9bb28ccc6106 8229839: Break circular dependency between oop.inline.hpp and markWord.inline.hpp
stefank
parents: 57811
diff changeset
    31
#include "oops/oop.inline.hpp"
5434
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    32
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    33
/////////////////////////////////////////////////////////////////////////
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    34
//// PromotionInfo
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    35
/////////////////////////////////////////////////////////////////////////
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    36
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    37
35862
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    38
PromotedObject* PromotedObject::next() const {
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    39
  assert(!((FreeChunk*)this)->is_free(), "Error");
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    40
  PromotedObject* res;
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    41
  if (UseCompressedOops) {
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    42
    // The next pointer is a compressed oop stored in the top 32 bits
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 47216
diff changeset
    43
    res = (PromotedObject*)CompressedOops::decode(_data._narrow_next);
35862
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    44
  } else {
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    45
    res = (PromotedObject*)(_next & next_mask);
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    46
  }
46968
9119841280f4 8160399: is_oop_or_null involves undefined behavior
coleenp
parents: 38198
diff changeset
    47
  assert(oopDesc::is_oop_or_null(oop(res), true /* ignore mark word */), "Expected an oop or NULL at " PTR_FORMAT, p2i(oop(res)));
35862
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    48
  return res;
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    49
}
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    50
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    51
inline void PromotedObject::setNext(PromotedObject* x) {
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    52
  assert(((intptr_t)x & ~next_mask) == 0, "Conflict in bit usage, "
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    53
         "or insufficient alignment of objects");
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    54
  if (UseCompressedOops) {
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    55
    assert(_data._narrow_next == 0, "Overwrite?");
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 47216
diff changeset
    56
    _data._narrow_next = CompressedOops::encode(oop(x));
35862
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    57
  } else {
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    58
    _next |= (intptr_t)x;
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    59
  }
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    60
  assert(!((FreeChunk*)this)->is_free(), "Error");
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    61
}
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 34129
diff changeset
    62
5434
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    63
// Return the next displaced header, incrementing the pointer and
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    64
// recycling spool area as necessary.
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 50034
diff changeset
    65
markWord PromotionInfo::nextDisplacedHeader() {
5434
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    66
  assert(_spoolHead != NULL, "promotionInfo inconsistency");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    67
  assert(_spoolHead != _spoolTail || _firstIndex < _nextIndex,
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    68
         "Empty spool space: no displaced header can be fetched");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    69
  assert(_spoolHead->bufferSize > _firstIndex, "Off by one error at head?");
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 50034
diff changeset
    70
  markWord hdr = _spoolHead->displacedHdr[_firstIndex];
5434
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    71
  // Spool forward
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    72
  if (++_firstIndex == _spoolHead->bufferSize) { // last location in this block
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    73
    // forward to next block, recycling this block into spare spool buffer
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    74
    SpoolBlock* tmp = _spoolHead->nextSpoolBlock;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    75
    assert(_spoolHead != _spoolTail, "Spooling storage mix-up");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    76
    _spoolHead->nextSpoolBlock = _spareSpool;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    77
    _spareSpool = _spoolHead;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    78
    _spoolHead = tmp;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    79
    _firstIndex = 1;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    80
    NOT_PRODUCT(
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    81
      if (_spoolHead == NULL) {  // all buffers fully consumed
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    82
        assert(_spoolTail == NULL && _nextIndex == 1,
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    83
               "spool buffers processing inconsistency");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    84
      }
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    85
    )
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    86
  }
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    87
  return hdr;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    88
}
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    89
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    90
void PromotionInfo::track(PromotedObject* trackOop) {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    91
  track(trackOop, oop(trackOop)->klass());
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    92
}
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    93
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12509
diff changeset
    94
void PromotionInfo::track(PromotedObject* trackOop, Klass* klassOfOop) {
5434
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    95
  // make a copy of header as it may need to be spooled
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 50034
diff changeset
    96
  markWord mark = oop(trackOop)->mark_raw();
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 7397
diff changeset
    97
  trackOop->clear_next();
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 50034
diff changeset
    98
  if (mark.must_be_preserved_for_cms_scavenge(klassOfOop)) {
5434
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
    99
    // save non-prototypical header, and mark oop
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   100
    saveDisplacedHeader(mark);
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   101
    trackOop->setDisplacedMark();
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   102
  } else {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   103
    // we'd like to assert something like the following:
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 50034
diff changeset
   104
    // assert(mark == markWord::prototype(), "consistency check");
5434
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   105
    // ... but the above won't work because the age bits have not (yet) been
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   106
    // cleared. The remainder of the check would be identical to the
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   107
    // condition checked in must_be_preserved() above, so we don't really
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   108
    // have anything useful to check here!
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   109
  }
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   110
  if (_promoTail != NULL) {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   111
    assert(_promoHead != NULL, "List consistency");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   112
    _promoTail->setNext(trackOop);
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   113
    _promoTail = trackOop;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   114
  } else {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   115
    assert(_promoHead == NULL, "List consistency");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   116
    _promoHead = _promoTail = trackOop;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   117
  }
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   118
  // Mask as newly promoted, so we can skip over such objects
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   119
  // when scanning dirty cards
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   120
  assert(!trackOop->hasPromotedMark(), "Should not have been marked");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   121
  trackOop->setPromotedMark();
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   122
}
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   123
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   124
// Save the given displaced header, incrementing the pointer and
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   125
// obtaining more spool area as necessary.
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 50034
diff changeset
   126
void PromotionInfo::saveDisplacedHeader(markWord hdr) {
5434
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   127
  assert(_spoolHead != NULL && _spoolTail != NULL,
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   128
         "promotionInfo inconsistency");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   129
  assert(_spoolTail->bufferSize > _nextIndex, "Off by one error at tail?");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   130
  _spoolTail->displacedHdr[_nextIndex] = hdr;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   131
  // Spool forward
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   132
  if (++_nextIndex == _spoolTail->bufferSize) { // last location in this block
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   133
    // get a new spooling block
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   134
    assert(_spoolTail->nextSpoolBlock == NULL, "tail should terminate spool list");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   135
    _splice_point = _spoolTail;                   // save for splicing
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   136
    _spoolTail->nextSpoolBlock = getSpoolBlock(); // might fail
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   137
    _spoolTail = _spoolTail->nextSpoolBlock;      // might become NULL ...
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   138
    // ... but will attempt filling before next promotion attempt
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   139
    _nextIndex = 1;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   140
  }
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   141
}
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   142
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   143
// Ensure that spooling space exists. Return false if spooling space
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   144
// could not be obtained.
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   145
bool PromotionInfo::ensure_spooling_space_work() {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   146
  assert(!has_spooling_space(), "Only call when there is no spooling space");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   147
  // Try and obtain more spooling space
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   148
  SpoolBlock* newSpool = getSpoolBlock();
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   149
  assert(newSpool == NULL ||
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   150
         (newSpool->bufferSize != 0 && newSpool->nextSpoolBlock == NULL),
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   151
        "getSpoolBlock() sanity check");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   152
  if (newSpool == NULL) {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   153
    return false;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   154
  }
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   155
  _nextIndex = 1;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   156
  if (_spoolTail == NULL) {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   157
    _spoolTail = newSpool;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   158
    if (_spoolHead == NULL) {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   159
      _spoolHead = newSpool;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   160
      _firstIndex = 1;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   161
    } else {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   162
      assert(_splice_point != NULL && _splice_point->nextSpoolBlock == NULL,
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   163
             "Splice point invariant");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   164
      // Extra check that _splice_point is connected to list
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   165
      #ifdef ASSERT
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   166
      {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   167
        SpoolBlock* blk = _spoolHead;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   168
        for (; blk->nextSpoolBlock != NULL;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   169
             blk = blk->nextSpoolBlock);
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   170
        assert(blk != NULL && blk == _splice_point,
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   171
               "Splice point incorrect");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   172
      }
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   173
      #endif // ASSERT
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   174
      _splice_point->nextSpoolBlock = newSpool;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   175
    }
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   176
  } else {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   177
    assert(_spoolHead != NULL, "spool list consistency");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   178
    _spoolTail->nextSpoolBlock = newSpool;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   179
    _spoolTail = newSpool;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   180
  }
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   181
  return true;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   182
}
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   183
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   184
// Get a free spool buffer from the free pool, getting a new block
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   185
// from the heap if necessary.
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   186
SpoolBlock* PromotionInfo::getSpoolBlock() {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   187
  SpoolBlock* res;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   188
  if ((res = _spareSpool) != NULL) {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   189
    _spareSpool = _spareSpool->nextSpoolBlock;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   190
    res->nextSpoolBlock = NULL;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   191
  } else {  // spare spool exhausted, get some from heap
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   192
    res = (SpoolBlock*)(space()->allocateScratch(refillSize()));
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   193
    if (res != NULL) {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   194
      res->init();
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   195
    }
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   196
  }
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   197
  assert(res == NULL || res->nextSpoolBlock == NULL, "postcondition");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   198
  return res;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   199
}
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   200
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   201
void PromotionInfo::startTrackingPromotions() {
38198
8144ec8f789e 8155257: ParNew/CMS: Clean up promoted object tracking
tonyp
parents: 35862
diff changeset
   202
  assert(noPromotions(), "sanity");
5434
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   203
  assert(_spoolHead == _spoolTail && _firstIndex == _nextIndex,
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   204
         "spooling inconsistency?");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   205
  _firstIndex = _nextIndex = 1;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   206
  _tracking = true;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   207
}
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   208
38198
8144ec8f789e 8155257: ParNew/CMS: Clean up promoted object tracking
tonyp
parents: 35862
diff changeset
   209
void PromotionInfo::stopTrackingPromotions() {
8144ec8f789e 8155257: ParNew/CMS: Clean up promoted object tracking
tonyp
parents: 35862
diff changeset
   210
  assert(noPromotions(), "we should have torn down the lists by now");
5434
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   211
  assert(_spoolHead == _spoolTail && _firstIndex == _nextIndex,
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   212
         "spooling inconsistency?");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   213
  _firstIndex = _nextIndex = 1;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   214
  _tracking = false;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   215
}
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   216
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   217
// When _spoolTail is not NULL, then the slot <_spoolTail, _nextIndex>
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   218
// points to the next slot available for filling.
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   219
// The set of slots holding displaced headers are then all those in the
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   220
// right-open interval denoted by:
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   221
//
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   222
//    [ <_spoolHead, _firstIndex>, <_spoolTail, _nextIndex> )
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   223
//
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   224
// When _spoolTail is NULL, then the set of slots with displaced headers
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   225
// is all those starting at the slot <_spoolHead, _firstIndex> and
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   226
// going up to the last slot of last block in the linked list.
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 13728
diff changeset
   227
// In this latter case, _splice_point points to the tail block of
5434
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   228
// this linked list of blocks holding displaced headers.
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   229
void PromotionInfo::verify() const {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   230
  // Verify the following:
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   231
  // 1. the number of displaced headers matches the number of promoted
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   232
  //    objects that have displaced headers
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   233
  // 2. each promoted object lies in this space
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   234
  debug_only(
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   235
    PromotedObject* junk = NULL;
49722
a47d1e21b3f1 8199735: Mark word updates need to use Access API
rkennke
parents: 49592
diff changeset
   236
    assert(junk->next_addr() == (void*)(oop(junk)->mark_addr_raw()),
5434
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   237
           "Offset of PromotedObject::_next is expected to align with "
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   238
           "  the OopDesc::_mark within OopDesc");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   239
  )
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   240
  // FIXME: guarantee????
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   241
  guarantee(_spoolHead == NULL || _spoolTail != NULL ||
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   242
            _splice_point != NULL, "list consistency");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   243
  guarantee(_promoHead == NULL || _promoTail != NULL, "list consistency");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   244
  // count the number of objects with displaced headers
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   245
  size_t numObjsWithDisplacedHdrs = 0;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   246
  for (PromotedObject* curObj = _promoHead; curObj != NULL; curObj = curObj->next()) {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   247
    guarantee(space()->is_in_reserved((HeapWord*)curObj), "Containment");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   248
    // the last promoted object may fail the mark() != NULL test of is_oop().
46968
9119841280f4 8160399: is_oop_or_null involves undefined behavior
coleenp
parents: 38198
diff changeset
   249
    guarantee(curObj->next() == NULL || oopDesc::is_oop(oop(curObj)), "must be an oop");
5434
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   250
    if (curObj->hasDisplacedMark()) {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   251
      numObjsWithDisplacedHdrs++;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   252
    }
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   253
  }
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   254
  // Count the number of displaced headers
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   255
  size_t numDisplacedHdrs = 0;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   256
  for (SpoolBlock* curSpool = _spoolHead;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   257
       curSpool != _spoolTail && curSpool != NULL;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   258
       curSpool = curSpool->nextSpoolBlock) {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   259
    // the first entry is just a self-pointer; indices 1 through
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   260
    // bufferSize - 1 are occupied (thus, bufferSize - 1 slots).
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   261
    guarantee((void*)curSpool->displacedHdr == (void*)&curSpool->displacedHdr,
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   262
              "first entry of displacedHdr should be self-referential");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   263
    numDisplacedHdrs += curSpool->bufferSize - 1;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   264
  }
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   265
  guarantee((_spoolHead == _spoolTail) == (numDisplacedHdrs == 0),
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   266
            "internal consistency");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   267
  guarantee(_spoolTail != NULL || _nextIndex == 1,
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   268
            "Inconsistency between _spoolTail and _nextIndex");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   269
  // We overcounted (_firstIndex-1) worth of slots in block
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   270
  // _spoolHead and we undercounted (_nextIndex-1) worth of
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   271
  // slots in block _spoolTail. We make an appropriate
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   272
  // adjustment by subtracting the first and adding the
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   273
  // second:  - (_firstIndex - 1) + (_nextIndex - 1)
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   274
  numDisplacedHdrs += (_nextIndex - _firstIndex);
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   275
  guarantee(numDisplacedHdrs == numObjsWithDisplacedHdrs, "Displaced hdr count");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   276
}
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   277
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   278
void PromotionInfo::print_on(outputStream* st) const {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   279
  SpoolBlock* curSpool = NULL;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   280
  size_t i = 0;
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   281
  st->print_cr(" start & end indices: [" SIZE_FORMAT ", " SIZE_FORMAT ")",
5434
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   282
               _firstIndex, _nextIndex);
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   283
  for (curSpool = _spoolHead; curSpool != _spoolTail && curSpool != NULL;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   284
       curSpool = curSpool->nextSpoolBlock) {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   285
    curSpool->print_on(st);
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   286
    st->print_cr(" active ");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   287
    i++;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   288
  }
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   289
  for (curSpool = _spoolTail; curSpool != NULL;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   290
       curSpool = curSpool->nextSpoolBlock) {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   291
    curSpool->print_on(st);
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   292
    st->print_cr(" inactive ");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   293
    i++;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   294
  }
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   295
  for (curSpool = _spareSpool; curSpool != NULL;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   296
       curSpool = curSpool->nextSpoolBlock) {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   297
    curSpool->print_on(st);
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   298
    st->print_cr(" free ");
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   299
    i++;
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   300
  }
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   301
  st->print_cr("  " SIZE_FORMAT " header spooling blocks", i);
5434
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   302
}
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   303
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   304
void SpoolBlock::print_on(outputStream* st) const {
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   305
  st->print("[" PTR_FORMAT "," PTR_FORMAT "), " SIZE_FORMAT " HeapWords -> " PTR_FORMAT,
29797
4d360e3ddebf 8076055: cms: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 24424
diff changeset
   306
            p2i(this), p2i((HeapWord*)displacedHdr + bufferSize),
4d360e3ddebf 8076055: cms: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 24424
diff changeset
   307
            bufferSize, p2i(nextSpoolBlock));
5434
a2e785749780 6951188: CMS: move PromotionInfo into its own file
ysr
parents:
diff changeset
   308
}