src/hotspot/share/gc/shared/space.inline.hpp
author pliden
Wed, 20 Nov 2019 10:37:46 +0100
changeset 59154 0c2e1808f800
parent 57777 90ead0febf56
permissions -rw-r--r--
8234438: Remove some CMS leftovers Reviewed-by: kbarrett, sjohanss
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51332
diff changeset
     2
 * Copyright (c) 2000, 2019, 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: 1374
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1374
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: 1374
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
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51332
diff changeset
    25
#ifndef SHARE_GC_SHARED_SPACE_INLINE_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51332
diff changeset
    26
#define SHARE_GC_SHARED_SPACE_INLINE_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
51037
46d206233051 8207044: minimal vm build fail: missing #include
bulasevich
parents: 50035
diff changeset
    28
#include "gc/shared/blockOffsetTable.inline.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29792
diff changeset
    29
#include "gc/shared/collectedHeap.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29792
diff changeset
    30
#include "gc/shared/generation.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29792
diff changeset
    31
#include "gc/shared/space.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29792
diff changeset
    32
#include "gc/shared/spaceDecorator.hpp"
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
    33
#include "oops/oopsHierarchy.hpp"
49722
a47d1e21b3f1 8199735: Mark word updates need to use Access API
rkennke
parents: 47216
diff changeset
    34
#include "oops/oop.inline.hpp"
24487
71ff0bd674eb 8042737: Introduce umbrella header prefetch.inline.hpp
goetz
parents: 13963
diff changeset
    35
#include "runtime/prefetch.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
#include "runtime/safepoint.hpp"
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49722
diff changeset
    37
#if INCLUDE_SERIALGC
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49722
diff changeset
    38
#include "gc/serial/markSweep.inline.hpp"
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49722
diff changeset
    39
#endif
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    40
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    41
inline HeapWord* Space::block_start(const void* p) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    42
  return block_start_const(p);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    43
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    44
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
inline HeapWord* OffsetTableContigSpace::allocate(size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  HeapWord* res = ContiguousSpace::allocate(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  if (res != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    _offsets.alloc_block(res, size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
// Because of the requirement of keeping "_offsets" up to date with the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
// allocations, we sequentialize these with a lock.  Therefore, best if
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
// this is used for larger LAB allocations only.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
inline HeapWord* OffsetTableContigSpace::par_allocate(size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  MutexLocker x(&_par_alloc_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  // This ought to be just "allocate", because of the lock above, but that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  // ContiguousSpace::allocate asserts that either the allocating thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  // holds the heap lock or it is the VM thread and we're at a safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  // The best I (dld) could figure was to put a field in ContiguousSpace
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  // meaning "locking at safepoint taken care of", and set/reset that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // here.  But this will do for now, especially in light of the comment
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // above.  Perhaps in the future some lock-free manner of keeping the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // coordination.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  HeapWord* res = ContiguousSpace::par_allocate(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  if (res != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    _offsets.alloc_block(res, size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    73
inline HeapWord*
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    74
OffsetTableContigSpace::block_start_const(const void* p) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  return _offsets.block_start(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
35862
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 30764
diff changeset
    78
size_t CompactibleSpace::obj_size(const HeapWord* addr) const {
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 30764
diff changeset
    79
  return oop(addr)->size();
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 30764
diff changeset
    80
}
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 30764
diff changeset
    81
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49722
diff changeset
    82
#if INCLUDE_SERIALGC
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49722
diff changeset
    83
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
    84
class DeadSpacer : StackObj {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
    85
  size_t _allowed_deadspace_words;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
    86
  bool _active;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
    87
  CompactibleSpace* _space;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
    88
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
    89
public:
51332
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 51037
diff changeset
    90
  DeadSpacer(CompactibleSpace* space) : _allowed_deadspace_words(0), _space(space) {
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
    91
    size_t ratio = _space->allowed_dead_ratio();
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
    92
    _active = ratio > 0;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
    93
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
    94
    if (_active) {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
    95
      assert(!UseG1GC, "G1 should not be using dead space");
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
    96
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
    97
      // We allow some amount of garbage towards the bottom of the space, so
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
    98
      // we don't start compacting before there is a significant gain to be made.
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
    99
      // Occasionally, we want to ensure a full compaction, which is determined
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   100
      // by the MarkSweepAlwaysCompactCount parameter.
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   101
      if ((MarkSweep::total_invocations() % MarkSweepAlwaysCompactCount) != 0) {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   102
        _allowed_deadspace_words = (space->capacity() * ratio / 100) / HeapWordSize;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   103
      } else {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   104
        _active = false;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   105
      }
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   106
    }
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   107
  }
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   108
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   109
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   110
  bool insert_deadspace(HeapWord* dead_start, HeapWord* dead_end) {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   111
    if (!_active) {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   112
      return false;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   113
    }
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   114
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   115
    size_t dead_length = pointer_delta(dead_end, dead_start);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   116
    if (_allowed_deadspace_words >= dead_length) {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   117
      _allowed_deadspace_words -= dead_length;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   118
      CollectedHeap::fill_with_object(dead_start, dead_length);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   119
      oop obj = oop(dead_start);
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54786
diff changeset
   120
      obj->set_mark_raw(obj->mark_raw().set_marked());
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   121
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   122
      assert(dead_length == (size_t)obj->size(), "bad filler object size");
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   123
      log_develop_trace(gc, compaction)("Inserting object to dead space: " PTR_FORMAT ", " PTR_FORMAT ", " SIZE_FORMAT "b",
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   124
          p2i(dead_start), p2i(dead_end), dead_length * HeapWordSize);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   125
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   126
      return true;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   127
    } else {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   128
      _active = false;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   129
      return false;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   130
    }
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   131
  }
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   132
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   133
};
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   134
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   135
template <class SpaceType>
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   136
inline void CompactibleSpace::scan_and_forward(SpaceType* space, CompactPoint* cp) {
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   137
  // Compute the new addresses for the live objects and store it in the mark
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   138
  // Used by universe::mark_sweep_phase2()
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   139
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   140
  // We're sure to be here before any objects are compacted into this
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   141
  // space, so this is a good time to initialize this:
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   142
  space->set_compaction_top(space->bottom());
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   143
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   144
  if (cp->space == NULL) {
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   145
    assert(cp->gen != NULL, "need a generation");
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   146
    assert(cp->threshold == NULL, "just checking");
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   147
    assert(cp->gen->first_compaction_space() == space, "just checking");
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   148
    cp->space = cp->gen->first_compaction_space();
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   149
    cp->threshold = cp->space->initialize_threshold();
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   150
    cp->space->set_compaction_top(cp->space->bottom());
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   151
  }
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   152
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   153
  HeapWord* compact_top = cp->space->compaction_top(); // This is where we are currently compacting to.
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   154
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   155
  DeadSpacer dead_spacer(space);
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   156
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   157
  HeapWord*  end_of_live = space->bottom();  // One byte beyond the last byte of the last live object.
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   158
  HeapWord*  first_dead = NULL; // The first dead object.
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   159
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   160
  const intx interval = PrefetchScanIntervalInBytes;
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   161
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   162
  HeapWord* cur_obj = space->bottom();
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   163
  HeapWord* scan_limit = space->scan_limit();
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   164
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   165
  while (cur_obj < scan_limit) {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   166
    assert(!space->scanned_block_is_obj(cur_obj) ||
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54786
diff changeset
   167
           oop(cur_obj)->mark_raw().is_marked() || oop(cur_obj)->mark_raw().is_unlocked() ||
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54786
diff changeset
   168
           oop(cur_obj)->mark_raw().has_bias_pattern(),
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   169
           "these are the only valid states during a mark sweep");
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   170
    if (space->scanned_block_is_obj(cur_obj) && oop(cur_obj)->is_gc_marked()) {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   171
      // prefetch beyond cur_obj
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   172
      Prefetch::write(cur_obj, interval);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   173
      size_t size = space->scanned_block_size(cur_obj);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   174
      compact_top = cp->space->forward(oop(cur_obj), size, cp, compact_top);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   175
      cur_obj += size;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   176
      end_of_live = cur_obj;
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   177
    } else {
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   178
      // run over all the contiguous dead objects
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   179
      HeapWord* end = cur_obj;
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   180
      do {
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   181
        // prefetch beyond end
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   182
        Prefetch::write(end, interval);
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   183
        end += space->scanned_block_size(end);
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   184
      } while (end < scan_limit && (!space->scanned_block_is_obj(end) || !oop(end)->is_gc_marked()));
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   185
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   186
      // see if we might want to pretend this object is alive so that
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   187
      // we don't have to compact quite as often.
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   188
      if (cur_obj == compact_top && dead_spacer.insert_deadspace(cur_obj, end)) {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   189
        oop obj = oop(cur_obj);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   190
        compact_top = cp->space->forward(obj, obj->size(), cp, compact_top);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   191
        end_of_live = end;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   192
      } else {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   193
        // otherwise, it really is a free region.
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   194
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   195
        // cur_obj is a pointer to a dead object. Use this dead memory to store a pointer to the next live object.
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   196
        *(HeapWord**)cur_obj = end;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   197
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   198
        // see if this is the first dead region.
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   199
        if (first_dead == NULL) {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   200
          first_dead = cur_obj;
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   201
        }
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   202
      }
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   203
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   204
      // move on to the next object
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   205
      cur_obj = end;
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   206
    }
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   207
  }
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   208
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   209
  assert(cur_obj == scan_limit, "just checking");
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   210
  space->_end_of_live = end_of_live;
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   211
  if (first_dead != NULL) {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   212
    space->_first_dead = first_dead;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   213
  } else {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   214
    space->_first_dead = end_of_live;
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   215
  }
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   216
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   217
  // save the compaction_top of the compaction space.
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   218
  cp->space->set_compaction_top(compact_top);
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   219
}
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   220
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   221
template <class SpaceType>
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   222
inline void CompactibleSpace::scan_and_adjust_pointers(SpaceType* space) {
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   223
  // adjust all the interior pointers to point at the new locations of objects
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   224
  // Used by MarkSweep::mark_sweep_phase3()
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   225
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   226
  HeapWord* cur_obj = space->bottom();
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   227
  HeapWord* const end_of_live = space->_end_of_live;  // Established by "scan_and_forward".
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   228
  HeapWord* const first_dead = space->_first_dead;    // Established by "scan_and_forward".
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   229
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   230
  assert(first_dead <= end_of_live, "Stands to reason, no?");
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   231
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   232
  const intx interval = PrefetchScanIntervalInBytes;
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   233
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   234
  debug_only(HeapWord* prev_obj = NULL);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   235
  while (cur_obj < end_of_live) {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   236
    Prefetch::write(cur_obj, interval);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   237
    if (cur_obj < first_dead || oop(cur_obj)->is_gc_marked()) {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   238
      // cur_obj is alive
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   239
      // point all the oops to the new location
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   240
      size_t size = MarkSweep::adjust_pointers(oop(cur_obj));
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   241
      size = space->adjust_obj_size(size);
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   242
      debug_only(prev_obj = cur_obj);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   243
      cur_obj += size;
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   244
    } else {
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   245
      debug_only(prev_obj = cur_obj);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   246
      // cur_obj is not a live object, instead it points at the next live object
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   247
      cur_obj = *(HeapWord**)cur_obj;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   248
      assert(cur_obj > prev_obj, "we should be moving forward through memory, cur_obj: " PTR_FORMAT ", prev_obj: " PTR_FORMAT, p2i(cur_obj), p2i(prev_obj));
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   249
    }
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   250
  }
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   251
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   252
  assert(cur_obj == end_of_live, "just checking");
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   253
}
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   254
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   255
#ifdef ASSERT
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   256
template <class SpaceType>
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   257
inline void CompactibleSpace::verify_up_to_first_dead(SpaceType* space) {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   258
  HeapWord* cur_obj = space->bottom();
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   259
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   260
  if (cur_obj < space->_end_of_live && space->_first_dead > cur_obj && !oop(cur_obj)->is_gc_marked()) {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   261
     // we have a chunk of the space which hasn't moved and we've reinitialized
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   262
     // the mark word during the previous pass, so we can't use is_gc_marked for
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   263
     // the traversal.
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   264
     HeapWord* prev_obj = NULL;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   265
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   266
     while (cur_obj < space->_first_dead) {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   267
       size_t size = space->obj_size(cur_obj);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   268
       assert(!oop(cur_obj)->is_gc_marked(), "should be unmarked (special dense prefix handling)");
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   269
       prev_obj = cur_obj;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   270
       cur_obj += size;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   271
     }
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   272
  }
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   273
}
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   274
#endif
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   275
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   276
template <class SpaceType>
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   277
inline void CompactibleSpace::clear_empty_region(SpaceType* space) {
27624
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   278
  // Let's remember if we were empty before we did the compaction.
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   279
  bool was_empty = space->used_region().is_empty();
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   280
  // Reset space after compaction is complete
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   281
  space->reset_after_compaction();
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   282
  // We do this clear, below, since it has overloaded meanings for some
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   283
  // space subtypes.  For example, OffsetTableContigSpace's that were
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   284
  // compacted into will have had their offset table thresholds updated
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   285
  // continuously, but those that weren't need to have their thresholds
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   286
  // re-initialized.  Also mangles unused area for debugging.
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   287
  if (space->used_region().is_empty()) {
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   288
    if (!was_empty) space->clear(SpaceDecorator::Mangle);
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   289
  } else {
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   290
    if (ZapUnusedHeapArea) space->mangle_unused_area();
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   291
  }
fe43edc5046d 8043243: convert SCAN_AND_FORWARD, SCAN_AND_ADJUST_POINTERS, SCAN_AND_COMPACT macros to methods
mlarsson
parents: 24487
diff changeset
   292
}
35862
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 30764
diff changeset
   293
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   294
template <class SpaceType>
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   295
inline void CompactibleSpace::scan_and_compact(SpaceType* space) {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   296
  // Copy all live objects to their new location
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   297
  // Used by MarkSweep::mark_sweep_phase4()
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   298
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   299
  verify_up_to_first_dead(space);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   300
40888
f09b053be364 8155917: Memory access in free regions during G1 full gc causes regressions in SPECjvm2008 scimark.fft,lu,sor,sparse with 9+116 on Linux-x64
tschatzl
parents: 37495
diff changeset
   301
  HeapWord* const bottom = space->bottom();
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   302
  HeapWord* const end_of_live = space->_end_of_live;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   303
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   304
  assert(space->_first_dead <= end_of_live, "Invariant. _first_dead: " PTR_FORMAT " <= end_of_live: " PTR_FORMAT, p2i(space->_first_dead), p2i(end_of_live));
40888
f09b053be364 8155917: Memory access in free regions during G1 full gc causes regressions in SPECjvm2008 scimark.fft,lu,sor,sparse with 9+116 on Linux-x64
tschatzl
parents: 37495
diff changeset
   305
  if (space->_first_dead == end_of_live && (bottom == end_of_live || !oop(bottom)->is_gc_marked())) {
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   306
    // Nothing to compact. The space is either empty or all live object should be left in place.
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   307
    clear_empty_region(space);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   308
    return;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   309
  }
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   310
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   311
  const intx scan_interval = PrefetchScanIntervalInBytes;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   312
  const intx copy_interval = PrefetchCopyIntervalInBytes;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   313
40888
f09b053be364 8155917: Memory access in free regions during G1 full gc causes regressions in SPECjvm2008 scimark.fft,lu,sor,sparse with 9+116 on Linux-x64
tschatzl
parents: 37495
diff changeset
   314
  assert(bottom < end_of_live, "bottom: " PTR_FORMAT " should be < end_of_live: " PTR_FORMAT, p2i(bottom), p2i(end_of_live));
f09b053be364 8155917: Memory access in free regions during G1 full gc causes regressions in SPECjvm2008 scimark.fft,lu,sor,sparse with 9+116 on Linux-x64
tschatzl
parents: 37495
diff changeset
   315
  HeapWord* cur_obj = bottom;
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   316
  if (space->_first_dead > cur_obj && !oop(cur_obj)->is_gc_marked()) {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   317
    // All object before _first_dead can be skipped. They should not be moved.
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   318
    // A pointer to the first live object is stored at the memory location for _first_dead.
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   319
    cur_obj = *(HeapWord**)(space->_first_dead);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   320
  }
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   321
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   322
  debug_only(HeapWord* prev_obj = NULL);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   323
  while (cur_obj < end_of_live) {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   324
    if (!oop(cur_obj)->is_gc_marked()) {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   325
      debug_only(prev_obj = cur_obj);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   326
      // The first word of the dead object contains a pointer to the next live object or end of space.
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   327
      cur_obj = *(HeapWord**)cur_obj;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   328
      assert(cur_obj > prev_obj, "we should be moving forward through memory");
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   329
    } else {
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   330
      // prefetch beyond q
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   331
      Prefetch::read(cur_obj, scan_interval);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   332
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   333
      // size and destination
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   334
      size_t size = space->obj_size(cur_obj);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   335
      HeapWord* compaction_top = (HeapWord*)oop(cur_obj)->forwardee();
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   336
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   337
      // prefetch beyond compaction_top
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   338
      Prefetch::write(compaction_top, copy_interval);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   339
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   340
      // copy object and reinit its mark
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   341
      assert(cur_obj != compaction_top, "everything in this pass should be moving");
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   342
      Copy::aligned_conjoint_words(cur_obj, compaction_top, size);
49722
a47d1e21b3f1 8199735: Mark word updates need to use Access API
rkennke
parents: 47216
diff changeset
   343
      oop(compaction_top)->init_mark_raw();
37495
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   344
      assert(oop(compaction_top)->klass() != NULL, "should have a class");
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   345
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   346
      debug_only(prev_obj = cur_obj);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   347
      cur_obj += size;
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   348
    }
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   349
  }
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   350
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   351
  clear_empty_region(space);
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   352
}
7ef1f23dfc9c 8073321: assert(q > prev_q) failed: we should be moving forward through memory
brutisso
parents: 37238
diff changeset
   353
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49722
diff changeset
   354
#endif // INCLUDE_SERIALGC
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49722
diff changeset
   355
35862
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 30764
diff changeset
   356
size_t ContiguousSpace::scanned_block_size(const HeapWord* addr) const {
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 30764
diff changeset
   357
  return oop(addr)->size();
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 30764
diff changeset
   358
}
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 30764
diff changeset
   359
50034
01a88f825a84 8202641: Replace OOP_SINCE_SAVE_MARKS with templates
stefank
parents: 49982
diff changeset
   360
template <typename OopClosureType>
01a88f825a84 8202641: Replace OOP_SINCE_SAVE_MARKS with templates
stefank
parents: 49982
diff changeset
   361
void ContiguousSpace::oop_since_save_marks_iterate(OopClosureType* blk) {
01a88f825a84 8202641: Replace OOP_SINCE_SAVE_MARKS with templates
stefank
parents: 49982
diff changeset
   362
  HeapWord* t;
01a88f825a84 8202641: Replace OOP_SINCE_SAVE_MARKS with templates
stefank
parents: 49982
diff changeset
   363
  HeapWord* p = saved_mark_word();
01a88f825a84 8202641: Replace OOP_SINCE_SAVE_MARKS with templates
stefank
parents: 49982
diff changeset
   364
  assert(p != NULL, "expected saved mark");
01a88f825a84 8202641: Replace OOP_SINCE_SAVE_MARKS with templates
stefank
parents: 49982
diff changeset
   365
01a88f825a84 8202641: Replace OOP_SINCE_SAVE_MARKS with templates
stefank
parents: 49982
diff changeset
   366
  const intx interval = PrefetchScanIntervalInBytes;
01a88f825a84 8202641: Replace OOP_SINCE_SAVE_MARKS with templates
stefank
parents: 49982
diff changeset
   367
  do {
01a88f825a84 8202641: Replace OOP_SINCE_SAVE_MARKS with templates
stefank
parents: 49982
diff changeset
   368
    t = top();
01a88f825a84 8202641: Replace OOP_SINCE_SAVE_MARKS with templates
stefank
parents: 49982
diff changeset
   369
    while (p < t) {
01a88f825a84 8202641: Replace OOP_SINCE_SAVE_MARKS with templates
stefank
parents: 49982
diff changeset
   370
      Prefetch::write(p, interval);
01a88f825a84 8202641: Replace OOP_SINCE_SAVE_MARKS with templates
stefank
parents: 49982
diff changeset
   371
      debug_only(HeapWord* prev = p);
01a88f825a84 8202641: Replace OOP_SINCE_SAVE_MARKS with templates
stefank
parents: 49982
diff changeset
   372
      oop m = oop(p);
01a88f825a84 8202641: Replace OOP_SINCE_SAVE_MARKS with templates
stefank
parents: 49982
diff changeset
   373
      p += m->oop_iterate_size(blk);
01a88f825a84 8202641: Replace OOP_SINCE_SAVE_MARKS with templates
stefank
parents: 49982
diff changeset
   374
    }
01a88f825a84 8202641: Replace OOP_SINCE_SAVE_MARKS with templates
stefank
parents: 49982
diff changeset
   375
  } while (t < top());
01a88f825a84 8202641: Replace OOP_SINCE_SAVE_MARKS with templates
stefank
parents: 49982
diff changeset
   376
01a88f825a84 8202641: Replace OOP_SINCE_SAVE_MARKS with templates
stefank
parents: 49982
diff changeset
   377
  set_saved_mark_word(p);
01a88f825a84 8202641: Replace OOP_SINCE_SAVE_MARKS with templates
stefank
parents: 49982
diff changeset
   378
}
01a88f825a84 8202641: Replace OOP_SINCE_SAVE_MARKS with templates
stefank
parents: 49982
diff changeset
   379
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51332
diff changeset
   380
#endif // SHARE_GC_SHARED_SPACE_INLINE_HPP