src/hotspot/share/gc/shared/spaceDecorator.cpp
author eosterlund
Tue, 16 Oct 2018 13:18:22 +0200
changeset 52142 ca0c25e01c5b
parent 47216 71c04702a3d5
child 53792 6fb43030a1b4
permissions -rw-r--r--
8210498: nmethod entry barriers Reviewed-by: kvn, pliden
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
     1
/*
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29800
diff changeset
     2
 * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
     4
 *
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
     8
 *
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    13
 * accompanied this code).
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    14
 *
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1217
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1217
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: 1217
diff changeset
    21
 * questions.
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    22
 *
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    23
 */
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29800
diff changeset
    26
#include "gc/shared/space.inline.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29800
diff changeset
    27
#include "gc/shared/spaceDecorator.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
    28
#include "logging/log.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "utilities/copy.hpp"
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    30
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    31
// Catch-all file for utility classes
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    32
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    33
#ifndef PRODUCT
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    34
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    35
// Returns true is the location q matches the mangling
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    36
// pattern.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    37
bool SpaceMangler::is_mangled(HeapWord* q) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    38
  // This test loses precision but is good enough
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    39
  return badHeapWord == (max_juint & (uintptr_t) q->value());
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    40
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    41
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    42
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    43
void SpaceMangler::set_top_for_allocations(HeapWord* v)  {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    44
  if (v < end()) {
979
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
    45
    assert(!CheckZapUnusedHeapArea || is_mangled(v),
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
    46
      "The high water mark is not mangled");
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    47
  }
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    48
  _top_for_allocations = v;
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    49
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    50
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    51
// Mangle only the unused space that has not previously
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    52
// been mangled and that has not been allocated since being
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    53
// mangled.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    54
void SpaceMangler::mangle_unused_area() {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    55
  assert(ZapUnusedHeapArea, "Mangling should not be in use");
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    56
  // Mangle between top and the high water mark.  Safeguard
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    57
  // against the space changing since top_for_allocations was
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    58
  // set.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    59
  HeapWord* mangled_end = MIN2(top_for_allocations(), end());
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    60
  if (top() < mangled_end) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    61
    MemRegion mangle_mr(top(), mangled_end);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    62
    SpaceMangler::mangle_region(mangle_mr);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    63
    // Light weight check of mangling.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    64
    check_mangled_unused_area(end());
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    65
  }
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    66
  // Complete check of unused area which is functional when
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    67
  // DEBUG_MANGLING is defined.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    68
  check_mangled_unused_area_complete();
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    69
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    70
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    71
// A complete mangle is expected in the
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    72
// exceptional case where top_for_allocations is not
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    73
// properly tracking the high water mark for mangling.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    74
// This can be the case when to-space is being used for
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    75
// scratch space during a mark-sweep-compact.  See
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    76
// contribute_scratch() and PSMarkSweep::allocate_stacks().
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    77
void SpaceMangler::mangle_unused_area_complete() {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    78
  assert(ZapUnusedHeapArea, "Mangling should not be in use");
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    79
  MemRegion mangle_mr(top(), end());
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    80
  SpaceMangler::mangle_region(mangle_mr);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    81
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    82
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    83
// Simply mangle the MemRegion mr.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    84
void SpaceMangler::mangle_region(MemRegion mr) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    85
  assert(ZapUnusedHeapArea, "Mangling should not be in use");
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    86
#ifdef ASSERT
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    87
  Copy::fill_to_words(mr.start(), mr.word_size(), badHeapWord);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    88
#endif
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    89
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    90
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    91
// Check that top, top_for_allocations and the last
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    92
// word of the space are mangled.  In a tight memory
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    93
// situation even this light weight mangling could
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    94
// cause paging by touching the end of the space.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    95
void  SpaceMangler::check_mangled_unused_area(HeapWord* limit) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    96
  if (CheckZapUnusedHeapArea) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    97
    // This method can be called while the spaces are
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    98
    // being reshaped so skip the test if the end of the
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
    99
    // space is beyond the specified limit;
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   100
    if (end() > limit) return;
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   101
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   102
    assert(top() == end() ||
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   103
           (is_mangled(top())), "Top not mangled");
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   104
    assert((top_for_allocations() < top()) ||
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   105
           (top_for_allocations() >= end()) ||
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   106
           (is_mangled(top_for_allocations())),
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   107
           "Older unused not mangled");
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   108
    assert(top() == end() ||
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   109
           (is_mangled(end() - 1)), "End not properly mangled");
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   110
    // Only does checking when DEBUG_MANGLING is defined.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   111
    check_mangled_unused_area_complete();
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   112
  }
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   113
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   114
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   115
#undef DEBUG_MANGLING
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   116
// This should only be used while debugging the mangling
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   117
// because of the high cost of checking the completeness.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   118
void  SpaceMangler::check_mangled_unused_area_complete() {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   119
  if (CheckZapUnusedHeapArea) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   120
    assert(ZapUnusedHeapArea, "Not mangling unused area");
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   121
#ifdef DEBUG_MANGLING
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   122
    HeapWord* q = top();
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   123
    HeapWord* limit = end();
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   124
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   125
    bool passed = true;
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   126
    while (q < limit) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   127
      if (!is_mangled(q)) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   128
        passed = false;
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   129
        break;
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   130
      }
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   131
      q++;
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   132
    }
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   133
    assert(passed, "Mangling is not complete");
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   134
#endif
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   135
  }
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   136
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   137
#undef DEBUG_MANGLING
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents:
diff changeset
   138
#endif // not PRODUCT