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