hotspot/src/share/vm/gc_implementation/shared/mutableSpace.cpp
author goetz
Wed, 04 Jun 2014 11:56:44 +0200
changeset 25351 7c198a690050
parent 24424 2658d7834c6e
child 28208 d67f748ece0a
permissions -rw-r--r--
8044775: Improve usage of umbrella header atomic.inline.hpp. Reviewed-by: stefank, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22234
diff changeset
     2
 * Copyright (c) 2001, 2014, 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"
25351
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24424
diff changeset
    26
#include "runtime/atomic.inline.hpp"
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 13728
diff changeset
    27
#include "utilities/macros.hpp"
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 13728
diff changeset
    28
#if INCLUDE_ALL_GCS
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "gc_implementation/shared/mutableSpace.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "gc_implementation/shared/spaceDecorator.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "oops/oop.inline.hpp"
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"
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 13728
diff changeset
    34
#endif // INCLUDE_ALL_GCS
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22234
diff changeset
    36
PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22234
diff changeset
    37
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    38
MutableSpace::MutableSpace(size_t alignment): ImmutableSpace(), _top(NULL), _alignment(alignment) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    39
  assert(MutableSpace::alignment() >= 0 &&
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    40
         MutableSpace::alignment() % os::vm_page_size() == 0,
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    41
         "Space should be aligned");
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    42
  _mangler = new MutableSpaceMangler(this);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    43
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    44
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    45
MutableSpace::~MutableSpace() {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    46
  delete _mangler;
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    47
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    48
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    49
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
    50
  if (!mr.is_empty()) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    51
    size_t page_size = UseLargePages ? alignment() : os::vm_page_size();
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    52
    HeapWord *start = (HeapWord*)round_to((intptr_t) mr.start(), page_size);
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    53
    HeapWord *end =  (HeapWord*)round_down((intptr_t) mr.end(), page_size);
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    54
    if (end > start) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    55
      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
    56
      if (clear_space) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    57
        // Prefer page reallocation to migration.
11402
739e52129c84 7124829: NUMA: memory leak on Linux with large pages
iveresov
parents: 7397
diff changeset
    58
        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
    59
      }
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    60
      os::numa_make_global((char*)start, size);
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
}
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    64
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    65
void MutableSpace::pretouch_pages(MemRegion mr) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    66
  for (volatile char *p = (char*)mr.start(); p < (char*)mr.end(); p += os::vm_page_size()) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    67
    char t = *p; *p = t;
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
}
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    70
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    71
void MutableSpace::initialize(MemRegion mr,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    72
                              bool clear_space,
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    73
                              bool mangle_space,
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    74
                              bool setup_pages) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    75
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    76
  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
    77
         "invalid space boundaries");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    79
  if (setup_pages && (UseNUMA || AlwaysPreTouch)) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    80
    // 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
    81
    // 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
    82
    MemRegion head, tail;
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    83
    if (last_setup_region().is_empty()) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    84
      // 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
    85
      head = mr;
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    86
      tail = MemRegion(mr.end(), mr.end());
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    87
    } else {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    88
      // Is there an intersection with the address space?
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    89
      MemRegion intersection = last_setup_region().intersection(mr);
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    90
      if (intersection.is_empty()) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    91
        intersection = MemRegion(mr.end(), mr.end());
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    92
      }
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    93
      // All the sizes below are in words.
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    94
      size_t head_size = 0, tail_size = 0;
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    95
      if (mr.start() <= intersection.start()) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    96
        head_size = pointer_delta(intersection.start(), mr.start());
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    97
      }
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    98
      if(intersection.end() <= mr.end()) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
    99
        tail_size = pointer_delta(mr.end(), intersection.end());
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   100
      }
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   101
      // Limit the amount of page manipulation if necessary.
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   102
      if (NUMASpaceResizeRate > 0 && !AlwaysPreTouch) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   103
        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
   104
        const float setup_rate_words = NUMASpaceResizeRate >> LogBytesPerWord;
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   105
        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
   106
                         head_size);
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   107
        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
   108
                         tail_size);
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   109
      }
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   110
      head = MemRegion(intersection.start() - head_size, intersection.start());
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   111
      tail = MemRegion(intersection.end(), intersection.end() + tail_size);
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
    assert(mr.contains(head) && mr.contains(tail), "Sanity");
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
    if (UseNUMA) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   116
      numa_setup_pages(head, clear_space);
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   117
      numa_setup_pages(tail, clear_space);
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   118
    }
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
    if (AlwaysPreTouch) {
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   121
      pretouch_pages(head);
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   122
      pretouch_pages(tail);
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
    // 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
   126
    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
   127
  }
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   128
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   129
  set_bottom(mr.start());
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 977
diff changeset
   130
  set_end(mr.end());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   132
  if (clear_space) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   133
    clear(mangle_space);
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
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
   138
  set_top(bottom());
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   139
  if (ZapUnusedHeapArea && mangle_space) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   140
    mangle_unused_area();
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
}
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
#ifndef PRODUCT
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(HeapWord* limit) {
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(limit);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   147
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   148
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   149
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
   150
  mangler()->check_mangled_unused_area_complete();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   153
// 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
   154
// 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
   155
// mangled.
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() {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   157
  mangler()->mangle_unused_area();
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   158
}
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
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
   161
  mangler()->mangle_unused_area_complete();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   164
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
   165
  SpaceMangler::mangle_region(mr);
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(HeapWord* v) {
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(v);
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
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   172
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
   173
  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
   174
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   175
#endif
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   176
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
// This version requires locking. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
HeapWord* MutableSpace::allocate(size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  assert(Heap_lock->owned_by_self() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
         (SafepointSynchronize::is_at_safepoint() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
          Thread::current()->is_VM_thread()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
         "not locked");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  HeapWord* obj = top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  if (pointer_delta(end(), obj) >= size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    HeapWord* new_top = obj + size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    set_top(new_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
           "checking alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    return obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
// This version is lock-free.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
HeapWord* MutableSpace::cas_allocate(size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    HeapWord* obj = top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    if (pointer_delta(end(), obj) >= size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
      HeapWord* new_top = obj + size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
      HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      // result can be one of two:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
      //  the old top value: the exchange succeeded
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
      //  otherwise: the new value of the top is returned.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
      if (result != obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
        continue; // another thread beat us to the allocation, try again
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
      assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
             "checking alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
      return obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  } while (true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
// Try to deallocate previous allocation. Returns true upon success.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
bool MutableSpace::cas_deallocate(HeapWord *obj, size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  HeapWord* expected_top = obj + size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  return (HeapWord*)Atomic::cmpxchg_ptr(obj, top_addr(), expected_top) == expected_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   223
void MutableSpace::oop_iterate(ExtendedOopClosure* cl) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  HeapWord* obj_addr = bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  HeapWord* t = top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  // Could call objects iterate, but this is easier.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  while (obj_addr < t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    obj_addr += oop(obj_addr)->oop_iterate(cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   232
void MutableSpace::oop_iterate_no_header(OopClosure* cl) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   233
  HeapWord* obj_addr = bottom();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   234
  HeapWord* t = top();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   235
  // Could call objects iterate, but this is easier.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   236
  while (obj_addr < t) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   237
    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
   238
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   239
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   240
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
void MutableSpace::object_iterate(ObjectClosure* cl) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  HeapWord* p = bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  while (p < top()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    cl->do_object(oop(p));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    p += oop(p)->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
void MutableSpace::print_short() const { print_short_on(tty); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
void MutableSpace::print_short_on( outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  st->print(" space " SIZE_FORMAT "K, %d%% used", capacity_in_bytes() / K,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
            (int) ((double) used_in_bytes() * 100 / capacity_in_bytes()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
void MutableSpace::print() const { print_on(tty); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
void MutableSpace::print_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  MutableSpace::print_short_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  st->print_cr(" [" INTPTR_FORMAT "," INTPTR_FORMAT "," INTPTR_FORMAT ")",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
                 bottom(), top(), end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
12379
2cf45b79ce3a 4988100: oop_verify_old_oop appears to be dead
brutisso
parents: 11402
diff changeset
   262
void MutableSpace::verify() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  HeapWord* p = bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  HeapWord* t = top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  HeapWord* prev_p = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  while (p < t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    oop(p)->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    prev_p = p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    p += oop(p)->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  guarantee(p == top(), "end of last object must match end of space");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
}