src/hotspot/share/gc/parallel/psMarkSweepDecorator.cpp
author stefank
Tue, 06 Aug 2019 10:48:21 +0200
changeset 57777 90ead0febf56
parent 50752 9d62da00bf15
child 58980 47c20fc6a517
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) 2001, 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: 2105
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
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: 2105
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"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "classfile/systemDictionary.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    27
#include "gc/parallel/objectStartArray.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    28
#include "gc/parallel/parallelScavengeHeap.hpp"
46502
116a09d8f142 8180755: Remove use of bitMap.inline.hpp include from instanceKlass.hpp and c1_ValueSet.hpp
tschatzl
parents: 37238
diff changeset
    29
#include "gc/parallel/parMarkBitMap.inline.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    30
#include "gc/parallel/psMarkSweep.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    31
#include "gc/parallel/psMarkSweepDecorator.hpp"
46502
116a09d8f142 8180755: Remove use of bitMap.inline.hpp include from instanceKlass.hpp and c1_ValueSet.hpp
tschatzl
parents: 37238
diff changeset
    32
#include "gc/parallel/psParallelCompact.inline.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    33
#include "gc/serial/markSweep.inline.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    34
#include "gc/shared/spaceDecorator.hpp"
50752
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49722
diff changeset
    35
#include "memory/iterator.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
#include "oops/oop.inline.hpp"
24487
71ff0bd674eb 8042737: Introduce umbrella header prefetch.inline.hpp
goetz
parents: 22234
diff changeset
    37
#include "runtime/prefetch.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
PSMarkSweepDecorator* PSMarkSweepDecorator::_destination_decorator = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
void PSMarkSweepDecorator::set_destination_decorator_tenured() {
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 29792
diff changeset
    43
  ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  _destination_decorator = heap->old_gen()->object_mark_sweep();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
void PSMarkSweepDecorator::advance_destination_decorator() {
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 29792
diff changeset
    48
  ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  assert(_destination_decorator != NULL, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  PSMarkSweepDecorator* first = heap->old_gen()->object_mark_sweep();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  PSMarkSweepDecorator* second = heap->young_gen()->eden_mark_sweep();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  PSMarkSweepDecorator* third = heap->young_gen()->from_mark_sweep();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  PSMarkSweepDecorator* fourth = heap->young_gen()->to_mark_sweep();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  if ( _destination_decorator == first ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    _destination_decorator = second;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  } else if ( _destination_decorator == second ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    _destination_decorator = third;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  } else if ( _destination_decorator == third ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    _destination_decorator = fourth;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    fatal("PSMarkSweep attempting to advance past last compaction area");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
PSMarkSweepDecorator* PSMarkSweepDecorator::destination_decorator() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  assert(_destination_decorator != NULL, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  return _destination_decorator;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
// FIX ME FIX ME FIX ME FIX ME!!!!!!!!!
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
// The object forwarding code is duplicated. Factor this out!!!!!
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
// This method "precompacts" objects inside its space to dest. It places forwarding
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 50752
diff changeset
    78
// pointers into markWords for use by adjust_pointers. If "dest" should overflow, we
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
// finish by compacting into our own space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
void PSMarkSweepDecorator::precompact() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  // Reset our own compact top.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  set_compaction_top(space()->bottom());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  /* We allow some amount of garbage towards the bottom of the space, so
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
   * we don't start compacting before there is a significant gain to be made.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
   * Occasionally, we want to ensure a full compaction, which is determined
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
   * by the MarkSweepAlwaysCompactCount parameter. This is a significant
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
   * performance improvement!
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
   */
17392
2f967c0e4246 6843347: Boundary values in some public GC options cause crashes
tschatzl
parents: 15088
diff changeset
    91
  bool skip_dead = ((PSMarkSweep::total_invocations() % MarkSweepAlwaysCompactCount) != 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
1557
13878a2edfef 6765804: GC "dead ratios" should be unsigned
jcoomes
parents: 1406
diff changeset
    93
  size_t allowed_deadspace = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  if (skip_dead) {
1557
13878a2edfef 6765804: GC "dead ratios" should be unsigned
jcoomes
parents: 1406
diff changeset
    95
    const size_t ratio = allowed_dead_ratio();
13878a2edfef 6765804: GC "dead ratios" should be unsigned
jcoomes
parents: 1406
diff changeset
    96
    allowed_deadspace = space()->capacity_in_words() * ratio / 100;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // Fetch the current destination decorator
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  PSMarkSweepDecorator* dest = destination_decorator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  ObjectStartArray* start_array = dest->start_array();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  HeapWord* compact_top = dest->compaction_top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  HeapWord* compact_end = dest->space()->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  HeapWord* q = space()->bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  HeapWord* t = space()->top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  HeapWord*  end_of_live= q;    /* One byte beyond the last byte of the last
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
                                   live object. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  HeapWord*  first_dead = space()->end(); /* The first dead object. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  const intx interval = PrefetchScanIntervalInBytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  while (q < t) {
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 50752
diff changeset
   116
    assert(oop(q)->mark_raw().is_marked() || oop(q)->mark_raw().is_unlocked() ||
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 50752
diff changeset
   117
           oop(q)->mark_raw().has_bias_pattern(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
           "these are the only valid states during a mark sweep");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    if (oop(q)->is_gc_marked()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
      /* prefetch beyond q */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      Prefetch::write(q, interval);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
      size_t size = oop(q)->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
      size_t compaction_max_size = pointer_delta(compact_end, compact_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      // This should only happen if a space in the young gen overflows the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      // old gen. If that should happen, we null out the start_array, because
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      // the young spaces are not covered by one.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      while(size > compaction_max_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
        // First record the last compact_top
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
        dest->set_compaction_top(compact_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
        // Advance to the next compaction decorator
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
        advance_destination_decorator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
        dest = destination_decorator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
        // Update compaction info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
        start_array = dest->start_array();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
        compact_top = dest->compaction_top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
        compact_end = dest->space()->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
        assert(compact_top == dest->space()->bottom(), "Advanced to space already in use");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
        assert(compact_end > compact_top, "Must always be space remaining");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
        compaction_max_size =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
          pointer_delta(compact_end, compact_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      // store the forwarding pointer into the mark word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      if (q != compact_top) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
        oop(q)->forward_to(oop(compact_top));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
        assert(oop(q)->is_gc_marked(), "encoding the pointer should preserve the mark");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
      } else {
1406
e5e2b519fc11 6716466: par compact - remove VerifyParallelOldWithMarkSweep code
jcoomes
parents: 977
diff changeset
   152
        // if the object isn't moving we can just set the mark to the default
e5e2b519fc11 6716466: par compact - remove VerifyParallelOldWithMarkSweep code
jcoomes
parents: 977
diff changeset
   153
        // mark and handle it specially later on.
49722
a47d1e21b3f1 8199735: Mark word updates need to use Access API
rkennke
parents: 47216
diff changeset
   154
        oop(q)->init_mark_raw();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
        assert(oop(q)->forwardee() == NULL, "should be forwarded to NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      // Update object start array
1406
e5e2b519fc11 6716466: par compact - remove VerifyParallelOldWithMarkSweep code
jcoomes
parents: 977
diff changeset
   159
      if (start_array) {
e5e2b519fc11 6716466: par compact - remove VerifyParallelOldWithMarkSweep code
jcoomes
parents: 977
diff changeset
   160
        start_array->allocate_block(compact_top);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
      compact_top += size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      assert(compact_top <= dest->space()->end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
        "Exceeding space in destination");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
      q += size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
      end_of_live = q;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      /* run over all the contiguous dead objects */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      HeapWord* end = q;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
        /* prefetch beyond end */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
        Prefetch::write(end, interval);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
        end += oop(end)->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      } while (end < t && (!oop(end)->is_gc_marked()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      /* see if we might want to pretend this object is alive so that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
       * we don't have to compact quite as often.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
       */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
      if (allowed_deadspace > 0 && q == compact_top) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
        size_t sz = pointer_delta(end, q);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
        if (insert_deadspace(allowed_deadspace, q, sz)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
          size_t compaction_max_size = pointer_delta(compact_end, compact_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
          // This should only happen if a space in the young gen overflows the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
          // old gen. If that should happen, we null out the start_array, because
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
          // the young spaces are not covered by one.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
          while (sz > compaction_max_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
            // First record the last compact_top
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
            dest->set_compaction_top(compact_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
            // Advance to the next compaction decorator
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
            advance_destination_decorator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
            dest = destination_decorator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
            // Update compaction info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
            start_array = dest->start_array();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
            compact_top = dest->compaction_top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
            compact_end = dest->space()->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
            assert(compact_top == dest->space()->bottom(), "Advanced to space already in use");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
            assert(compact_end > compact_top, "Must always be space remaining");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
            compaction_max_size =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
              pointer_delta(compact_end, compact_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
          // store the forwarding pointer into the mark word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
          if (q != compact_top) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
            oop(q)->forward_to(oop(compact_top));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
            assert(oop(q)->is_gc_marked(), "encoding the pointer should preserve the mark");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
            // if the object isn't moving we can just set the mark to the default
1406
e5e2b519fc11 6716466: par compact - remove VerifyParallelOldWithMarkSweep code
jcoomes
parents: 977
diff changeset
   213
            // mark and handle it specially later on.
49722
a47d1e21b3f1 8199735: Mark word updates need to use Access API
rkennke
parents: 47216
diff changeset
   214
            oop(q)->init_mark_raw();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
            assert(oop(q)->forwardee() == NULL, "should be forwarded to NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
1406
e5e2b519fc11 6716466: par compact - remove VerifyParallelOldWithMarkSweep code
jcoomes
parents: 977
diff changeset
   218
          // Update object start array
e5e2b519fc11 6716466: par compact - remove VerifyParallelOldWithMarkSweep code
jcoomes
parents: 977
diff changeset
   219
          if (start_array) {
e5e2b519fc11 6716466: par compact - remove VerifyParallelOldWithMarkSweep code
jcoomes
parents: 977
diff changeset
   220
            start_array->allocate_block(compact_top);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
          compact_top += sz;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
          assert(compact_top <= dest->space()->end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
            "Exceeding space in destination");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
          q = end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
          end_of_live = end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
          continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
37238
3d0a96116bff 8153203: Remove liveRange.hpp
brutisso
parents: 30764
diff changeset
   233
      // q is a pointer to a dead object. Use this dead memory to store a pointer to the next live object.
3d0a96116bff 8153203: Remove liveRange.hpp
brutisso
parents: 30764
diff changeset
   234
      (*(HeapWord**)q) = end;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
      /* see if this is the first dead region. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
      if (q < first_dead) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
        first_dead = q;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
      /* move on to the next object */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
      q = end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  assert(q == t, "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  _end_of_live = end_of_live;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  if (end_of_live < first_dead) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    first_dead = end_of_live;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  _first_dead = first_dead;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  // Update compaction top
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  dest->set_compaction_top(compact_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
1557
13878a2edfef 6765804: GC "dead ratios" should be unsigned
jcoomes
parents: 1406
diff changeset
   257
bool PSMarkSweepDecorator::insert_deadspace(size_t& allowed_deadspace_words,
13878a2edfef 6765804: GC "dead ratios" should be unsigned
jcoomes
parents: 1406
diff changeset
   258
                                            HeapWord* q, size_t deadlength) {
13878a2edfef 6765804: GC "dead ratios" should be unsigned
jcoomes
parents: 1406
diff changeset
   259
  if (allowed_deadspace_words >= deadlength) {
13878a2edfef 6765804: GC "dead ratios" should be unsigned
jcoomes
parents: 1406
diff changeset
   260
    allowed_deadspace_words -= deadlength;
1668
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 1557
diff changeset
   261
    CollectedHeap::fill_with_object(q, deadlength);
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 50752
diff changeset
   262
    oop(q)->set_mark_raw(oop(q)->mark_raw().set_marked());
1668
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 1557
diff changeset
   263
    assert((int) deadlength == oop(q)->size(), "bad filler object size");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    // Recall that we required "q == compaction_top".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    allowed_deadspace_words = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
void PSMarkSweepDecorator::adjust_pointers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  // adjust all the interior pointers to point at the new locations of objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  // Used by MarkSweep::mark_sweep_phase3()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  HeapWord* q = space()->bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  HeapWord* t = _end_of_live;  // Established by "prepare_for_compaction".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  assert(_first_dead <= _end_of_live, "Stands to reason, no?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  if (q < t && _first_dead > q &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
      !oop(q)->is_gc_marked()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
    // we have a chunk of the space which hasn't moved and we've
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    // reinitialized the mark word during the previous pass, so we can't
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    // use is_gc_marked for the traversal.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    HeapWord* end = _first_dead;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    while (q < end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
      // point all the oops to the new location
29792
8c6fa07f0869 8075957: Reduce calls to the GC specific object visitors in oopDesc
stefank
parents: 24487
diff changeset
   290
      size_t size = MarkSweep::adjust_pointers(oop(q));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
      q += size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    if (_first_dead == t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
      q = t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    } else {
37238
3d0a96116bff 8153203: Remove liveRange.hpp
brutisso
parents: 30764
diff changeset
   297
      // The first dead object should contain a pointer to the first live object
3d0a96116bff 8153203: Remove liveRange.hpp
brutisso
parents: 30764
diff changeset
   298
      q = *(HeapWord**)_first_dead;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  const intx interval = PrefetchScanIntervalInBytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  debug_only(HeapWord* prev_q = NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  while (q < t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    // prefetch beyond q
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    Prefetch::write(q, interval);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    if (oop(q)->is_gc_marked()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
      // q is alive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
      // point all the oops to the new location
29792
8c6fa07f0869 8075957: Reduce calls to the GC specific object visitors in oopDesc
stefank
parents: 24487
diff changeset
   310
      size_t size = MarkSweep::adjust_pointers(oop(q));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
      debug_only(prev_q = q);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
      q += size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
      debug_only(prev_q = q);
37238
3d0a96116bff 8153203: Remove liveRange.hpp
brutisso
parents: 30764
diff changeset
   315
      // The first dead object is no longer an object. At that memory address,
3d0a96116bff 8153203: Remove liveRange.hpp
brutisso
parents: 30764
diff changeset
   316
      // there is a pointer to the first live object that the previous phase found.
3d0a96116bff 8153203: Remove liveRange.hpp
brutisso
parents: 30764
diff changeset
   317
      q = *(HeapWord**)q;
3d0a96116bff 8153203: Remove liveRange.hpp
brutisso
parents: 30764
diff changeset
   318
      assert(q > prev_q, "we should be moving forward through memory, q: " PTR_FORMAT ", prev_q: " PTR_FORMAT, p2i(q), p2i(prev_q));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  assert(q == t, "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
void PSMarkSweepDecorator::compact(bool mangle_free_space ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  // Copy all live objects to their new location
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  // Used by MarkSweep::mark_sweep_phase4()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  HeapWord*       q = space()->bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  HeapWord* const t = _end_of_live;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  debug_only(HeapWord* prev_q = NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  if (q < t && _first_dead > q &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
      !oop(q)->is_gc_marked()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    // we have a chunk of the space which hasn't moved and we've reinitialized the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    // mark word during the previous pass, so we can't use is_gc_marked for the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    // traversal.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    HeapWord* const end = _first_dead;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
    while (q < end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
      size_t size = oop(q)->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
      assert(!oop(q)->is_gc_marked(), "should be unmarked (special dense prefix handling)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
      debug_only(prev_q = q);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
      q += size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    if (_first_dead == t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
      q = t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
      // $$$ Funky
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 50752
diff changeset
   353
      q = (HeapWord*) oop(_first_dead)->mark_raw().decode_pointer();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  const intx scan_interval = PrefetchScanIntervalInBytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  const intx copy_interval = PrefetchCopyIntervalInBytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  while (q < t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
    if (!oop(q)->is_gc_marked()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
      // mark is pointer to next marked oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
      debug_only(prev_q = q);
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 50752
diff changeset
   364
      q = (HeapWord*) oop(q)->mark_raw().decode_pointer();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
      assert(q > prev_q, "we should be moving forward through memory");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
      // prefetch beyond q
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
      Prefetch::read(q, scan_interval);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
      // size and destination
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
      size_t size = oop(q)->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
      HeapWord* compaction_top = (HeapWord*)oop(q)->forwardee();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
      // prefetch beyond compaction_top
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
      Prefetch::write(compaction_top, copy_interval);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
      // copy object and reinit its mark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
      assert(q != compaction_top, "everything in this pass should be moving");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
      Copy::aligned_conjoint_words(q, compaction_top, size);
49722
a47d1e21b3f1 8199735: Mark word updates need to use Access API
rkennke
parents: 47216
diff changeset
   380
      oop(compaction_top)->init_mark_raw();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
      assert(oop(compaction_top)->klass() != NULL, "should have a class");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
      debug_only(prev_q = q);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
      q += size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  assert(compaction_top() >= space()->bottom() && compaction_top() <= space()->end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
         "should point inside space");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  space()->set_top(compaction_top());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
   392
  if (mangle_free_space) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
   393
    space()->mangle_unused_area();
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
   394
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
}