src/hotspot/share/gc/parallel/mutableSpace.cpp
author stefank
Mon, 25 Nov 2019 12:33:15 +0100
changeset 59252 623722a6aeb9
parent 58980 47c20fc6a517
permissions -rw-r--r--
8234740: Harmonize parameter order in Atomic - cmpxchg Reviewed-by: rehn, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
51268
4ac20e5f96ce 8202171: Some oopDesc functions compare this with NULL
hseigel
parents: 50800
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"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29800
diff changeset
    26
#include "gc/parallel/mutableSpace.hpp"
58980
47c20fc6a517 8189737: Make HeapRegion not derive from Space
tschatzl
parents: 54786
diff changeset
    27
#include "gc/shared/spaceDecorator.inline.hpp"
50752
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 47634
diff changeset
    28
#include "memory/iterator.inline.hpp"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 51332
diff changeset
    29
#include "memory/universe.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29800
diff changeset
    30
#include "oops/oop.inline.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 37046
diff changeset
    31
#include "runtime/atomic.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "runtime/safepoint.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "runtime/thread.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46620
diff changeset
    34
#include "utilities/align.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29800
diff changeset
    35
#include "utilities/macros.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
51332
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 51268
diff changeset
    37
MutableSpace::MutableSpace(size_t alignment): ImmutableSpace(), _alignment(alignment), _top(NULL) {
29580
a67a581cfe11 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents: 28208
diff changeset
    38
  assert(MutableSpace::alignment() % os::vm_page_size() == 0,
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    39
         "Space should be aligned");
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    40
  _mangler = new MutableSpaceMangler(this);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    41
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    42
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    43
MutableSpace::~MutableSpace() {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    44
  delete _mangler;
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    45
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    46
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    47
void MutableSpace::numa_setup_pages(MemRegion mr, bool clear_space) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    48
  if (!mr.is_empty()) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    49
    size_t page_size = UseLargePages ? alignment() : os::vm_page_size();
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46619
diff changeset
    50
    HeapWord *start = align_up(mr.start(), page_size);
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46619
diff changeset
    51
    HeapWord *end =   align_down(mr.end(), page_size);
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    52
    if (end > start) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    53
      size_t size = pointer_delta(end, start, sizeof(char));
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    54
      if (clear_space) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    55
        // Prefer page reallocation to migration.
11402
739e52129c84 7124829: NUMA: memory leak on Linux with large pages
iveresov
parents: 7397
diff changeset
    56
        os::free_memory((char*)start, size, page_size);
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    57
      }
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    58
      os::numa_make_global((char*)start, size);
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    59
    }
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    60
  }
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    61
}
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    62
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    63
void MutableSpace::pretouch_pages(MemRegion mr) {
37046
88fbf4e7b9c6 8151414: os::pretouch_memory should take void* instead of char*
tschatzl
parents: 32606
diff changeset
    64
  os::pretouch_memory(mr.start(), mr.end());
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    65
}
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    66
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    67
void MutableSpace::initialize(MemRegion mr,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    68
                              bool clear_space,
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    69
                              bool mangle_space,
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    70
                              bool setup_pages) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    71
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    72
  assert(Universe::on_page_boundary(mr.start()) && Universe::on_page_boundary(mr.end()),
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    73
         "invalid space boundaries");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    75
  if (setup_pages && (UseNUMA || AlwaysPreTouch)) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    76
    // The space may move left and right or expand/shrink.
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    77
    // We'd like to enforce the desired page placement.
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    78
    MemRegion head, tail;
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    79
    if (last_setup_region().is_empty()) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    80
      // If it's the first initialization don't limit the amount of work.
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    81
      head = mr;
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    82
      tail = MemRegion(mr.end(), mr.end());
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    83
    } else {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    84
      // Is there an intersection with the address space?
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    85
      MemRegion intersection = last_setup_region().intersection(mr);
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    86
      if (intersection.is_empty()) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    87
        intersection = MemRegion(mr.end(), mr.end());
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    88
      }
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    89
      // All the sizes below are in words.
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    90
      size_t head_size = 0, tail_size = 0;
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    91
      if (mr.start() <= intersection.start()) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    92
        head_size = pointer_delta(intersection.start(), mr.start());
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    93
      }
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    94
      if(intersection.end() <= mr.end()) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    95
        tail_size = pointer_delta(mr.end(), intersection.end());
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    96
      }
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    97
      // Limit the amount of page manipulation if necessary.
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    98
      if (NUMASpaceResizeRate > 0 && !AlwaysPreTouch) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    99
        const size_t change_size = head_size + tail_size;
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   100
        const float setup_rate_words = NUMASpaceResizeRate >> LogBytesPerWord;
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   101
        head_size = MIN2((size_t)(setup_rate_words * head_size / change_size),
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   102
                         head_size);
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   103
        tail_size = MIN2((size_t)(setup_rate_words * tail_size / change_size),
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   104
                         tail_size);
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   105
      }
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   106
      head = MemRegion(intersection.start() - head_size, intersection.start());
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   107
      tail = MemRegion(intersection.end(), intersection.end() + tail_size);
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   108
    }
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   109
    assert(mr.contains(head) && mr.contains(tail), "Sanity");
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   110
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   111
    if (UseNUMA) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   112
      numa_setup_pages(head, clear_space);
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   113
      numa_setup_pages(tail, clear_space);
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   114
    }
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   115
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   116
    if (AlwaysPreTouch) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   117
      pretouch_pages(head);
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   118
      pretouch_pages(tail);
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   119
    }
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   120
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   121
    // Remember where we stopped so that we can continue later.
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   122
    set_last_setup_region(MemRegion(head.start(), tail.end()));
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   123
  }
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   124
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   125
  set_bottom(mr.start());
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   126
  set_end(mr.end());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   128
  if (clear_space) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   129
    clear(mangle_space);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   130
  }
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   131
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   132
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   133
void MutableSpace::clear(bool mangle_space) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   134
  set_top(bottom());
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   135
  if (ZapUnusedHeapArea && mangle_space) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   136
    mangle_unused_area();
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   137
  }
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   138
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   139
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   140
#ifndef PRODUCT
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   141
void MutableSpace::check_mangled_unused_area(HeapWord* limit) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   142
  mangler()->check_mangled_unused_area(limit);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   143
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   144
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   145
void MutableSpace::check_mangled_unused_area_complete() {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   146
  mangler()->check_mangled_unused_area_complete();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   149
// 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: 616
diff changeset
   150
// 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: 616
diff changeset
   151
// mangled.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   152
void MutableSpace::mangle_unused_area() {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   153
  mangler()->mangle_unused_area();
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   154
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   155
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   156
void MutableSpace::mangle_unused_area_complete() {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   157
  mangler()->mangle_unused_area_complete();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   160
void MutableSpace::mangle_region(MemRegion mr) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   161
  SpaceMangler::mangle_region(mr);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   162
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   163
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   164
void MutableSpace::set_top_for_allocations(HeapWord* v) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   165
  mangler()->set_top_for_allocations(v);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   166
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   167
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   168
void MutableSpace::set_top_for_allocations() {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   169
  mangler()->set_top_for_allocations(top());
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   170
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   171
#endif
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   172
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
// This version requires locking. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
HeapWord* MutableSpace::allocate(size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  assert(Heap_lock->owned_by_self() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
         (SafepointSynchronize::is_at_safepoint() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
          Thread::current()->is_VM_thread()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
         "not locked");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  HeapWord* obj = top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  if (pointer_delta(end(), obj) >= size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    HeapWord* new_top = obj + size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    set_top(new_top);
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46565
diff changeset
   183
    assert(is_object_aligned(obj) && is_object_aligned(new_top),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
           "checking alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    return obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
// This version is lock-free.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
HeapWord* MutableSpace::cas_allocate(size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    HeapWord* obj = top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    if (pointer_delta(end(), obj) >= size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
      HeapWord* new_top = obj + size;
59252
623722a6aeb9 8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents: 58980
diff changeset
   197
      HeapWord* result = Atomic::cmpxchg(top_addr(), obj, new_top);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
      // result can be one of two:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
      //  the old top value: the exchange succeeded
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
      //  otherwise: the new value of the top is returned.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
      if (result != obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
        continue; // another thread beat us to the allocation, try again
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
      }
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46565
diff changeset
   204
      assert(is_object_aligned(obj) && is_object_aligned(new_top),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
             "checking alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
      return obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  } while (true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
// Try to deallocate previous allocation. Returns true upon success.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
bool MutableSpace::cas_deallocate(HeapWord *obj, size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  HeapWord* expected_top = obj + size;
59252
623722a6aeb9 8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents: 58980
diff changeset
   216
  return Atomic::cmpxchg(top_addr(), expected_top, obj) == expected_top;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
50800
6da12aa23b88 8205607: Use oop_iterate instead of oop_iterate_no_header
stefank
parents: 50752
diff changeset
   219
void MutableSpace::oop_iterate(OopIterateClosure* cl) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   220
  HeapWord* obj_addr = bottom();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   221
  HeapWord* t = top();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   222
  // Could call objects iterate, but this is easier.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   223
  while (obj_addr < t) {
50800
6da12aa23b88 8205607: Use oop_iterate instead of oop_iterate_no_header
stefank
parents: 50752
diff changeset
   224
    obj_addr += oop(obj_addr)->oop_iterate_size(cl);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   225
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   226
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   227
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
void MutableSpace::object_iterate(ObjectClosure* cl) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  HeapWord* p = bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  while (p < top()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    cl->do_object(oop(p));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    p += oop(p)->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
void MutableSpace::print_short() const { print_short_on(tty); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
void MutableSpace::print_short_on( outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  st->print(" space " SIZE_FORMAT "K, %d%% used", capacity_in_bytes() / K,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
            (int) ((double) used_in_bytes() * 100 / capacity_in_bytes()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
void MutableSpace::print() const { print_on(tty); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
void MutableSpace::print_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  MutableSpace::print_short_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  st->print_cr(" [" INTPTR_FORMAT "," INTPTR_FORMAT "," INTPTR_FORMAT ")",
29800
fa5f7a2bf717 8076073: shared: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 29580
diff changeset
   246
                 p2i(bottom()), p2i(top()), p2i(end()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
12379
2cf45b79ce3a 4988100: oop_verify_old_oop appears to be dead
brutisso
parents: 11402
diff changeset
   249
void MutableSpace::verify() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  HeapWord* p = bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  HeapWord* t = top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  HeapWord* prev_p = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  while (p < t) {
51268
4ac20e5f96ce 8202171: Some oopDesc functions compare this with NULL
hseigel
parents: 50800
diff changeset
   254
    oopDesc::verify(oop(p));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    prev_p = p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    p += oop(p)->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  guarantee(p == top(), "end of last object must match end of space");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
}