hotspot/src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.cpp
author kvn
Thu, 27 May 2010 18:01:56 -0700
changeset 5694 1e0532a6abff
parent 2105 347008ce7984
child 5547 f4b087cbb361
permissions -rw-r--r--
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb Summary: Added new product ObjectAlignmentInBytes flag to control object alignment. Reviewed-by: twisti, ysr, iveresov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
2105
347008ce7984 6814575: Update copyright year
xdono
parents: 1911
diff changeset
     2
 * Copyright 2003-2009 Sun Microsystems, Inc.  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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_psVirtualspace.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// PSVirtualSpace
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
PSVirtualSpace::PSVirtualSpace(ReservedSpace rs, size_t alignment) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  _alignment(alignment)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  set_reserved(rs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  set_committed(reserved_low_addr(), reserved_low_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  DEBUG_ONLY(verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
PSVirtualSpace::PSVirtualSpace(ReservedSpace rs) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  _alignment(os::vm_page_size())
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  set_reserved(rs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  set_committed(reserved_low_addr(), reserved_low_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  DEBUG_ONLY(verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// Deprecated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
PSVirtualSpace::PSVirtualSpace(): _alignment(os::vm_page_size()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
// Deprecated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
bool PSVirtualSpace::initialize(ReservedSpace rs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
                                size_t commit_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  set_reserved(rs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  set_committed(reserved_low_addr(), reserved_low_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  // Commit to initial size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  assert(commit_size <= rs.size(), "commit_size too big");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  bool result = commit_size > 0 ? expand_by(commit_size) : true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  DEBUG_ONLY(verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
PSVirtualSpace::~PSVirtualSpace() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  release();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
bool PSVirtualSpace::contains(void* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  char* const cp = (char*)p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  return cp >= committed_low_addr() && cp < committed_high_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
void PSVirtualSpace::release() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
823
9a5271881bc0 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 1
diff changeset
    74
  // This may not release memory it didn't reserve.
9a5271881bc0 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 1
diff changeset
    75
  // Use rs.release() to release the underlying memory instead.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  _reserved_low_addr = _reserved_high_addr = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  _committed_low_addr = _committed_high_addr = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  _special = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1217
diff changeset
    81
bool PSVirtualSpace::expand_by(size_t bytes) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  assert(is_aligned(bytes), "arg not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  if (uncommitted_size() < bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  char* const base_addr = committed_high_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  bool result = special() || os::commit_memory(base_addr, bytes, alignment());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  if (result) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    _committed_high_addr += bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
bool PSVirtualSpace::shrink_by(size_t bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  assert(is_aligned(bytes), "arg not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  if (committed_size() < bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  char* const base_addr = committed_high_addr() - bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  bool result = special() || os::uncommit_memory(base_addr, bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  if (result) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    _committed_high_addr -= bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
size_t
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
PSVirtualSpace::expand_into(PSVirtualSpace* other_space, size_t bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  assert(is_aligned(bytes), "arg not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  assert(grows_up(), "this space must grow up");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  assert(other_space->grows_down(), "other space must grow down");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  assert(reserved_high_addr() == other_space->reserved_low_addr(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
         "spaces not contiguous");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  assert(special() == other_space->special(), "one space is special, the other is not");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  DEBUG_ONLY(PSVirtualSpaceVerifier other_verifier(other_space));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  size_t bytes_needed = bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // First use the uncommitted region in this space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  size_t tmp_bytes = MIN2(uncommitted_size(), bytes_needed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  if (tmp_bytes > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    if (expand_by(tmp_bytes)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      bytes_needed -= tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  // Next take from the uncommitted region in the other space, and commit it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  tmp_bytes = MIN2(other_space->uncommitted_size(), bytes_needed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  if (tmp_bytes > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    char* const commit_base = committed_high_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    if (other_space->special() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
        os::commit_memory(commit_base, tmp_bytes, alignment())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      // Reduce the reserved region in the other space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      other_space->set_reserved(other_space->reserved_low_addr() + tmp_bytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
                                other_space->reserved_high_addr(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
                                other_space->special());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
      // Grow both reserved and committed in this space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      _reserved_high_addr += tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
      _committed_high_addr += tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      bytes_needed -= tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
      return bytes - bytes_needed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // Finally take from the already committed region in the other space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  tmp_bytes = bytes_needed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  if (tmp_bytes > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    // Reduce both committed and reserved in the other space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    other_space->set_committed(other_space->committed_low_addr() + tmp_bytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
                               other_space->committed_high_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    other_space->set_reserved(other_space->reserved_low_addr() + tmp_bytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
                              other_space->reserved_high_addr(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
                              other_space->special());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    // Grow both reserved and committed in this space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    _reserved_high_addr += tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    _committed_high_addr += tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  return bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
bool PSVirtualSpace::is_aligned(size_t value, size_t align) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  const size_t tmp_value = value + align - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  const size_t mask = ~(align - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  return (tmp_value & mask) == value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
bool PSVirtualSpace::is_aligned(size_t value) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  return is_aligned(value, alignment());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
bool PSVirtualSpace::is_aligned(char* value) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  return is_aligned((size_t)value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
void PSVirtualSpace::verify() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  assert(is_aligned(alignment(), os::vm_page_size()), "bad alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  assert(is_aligned(reserved_low_addr()), "bad reserved_low_addr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  assert(is_aligned(reserved_high_addr()), "bad reserved_high_addr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  assert(is_aligned(committed_low_addr()), "bad committed_low_addr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  assert(is_aligned(committed_high_addr()), "bad committed_high_addr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  // Reserved region must be non-empty or both addrs must be 0.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  assert(reserved_low_addr() < reserved_high_addr() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
         reserved_low_addr() == NULL && reserved_high_addr() == NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
         "bad reserved addrs");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  assert(committed_low_addr() <= committed_high_addr(), "bad committed addrs");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  if (grows_up()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    assert(reserved_low_addr() == committed_low_addr(), "bad low addrs");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    assert(reserved_high_addr() >= committed_high_addr(), "bad high addrs");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    assert(reserved_high_addr() == committed_high_addr(), "bad high addrs");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    assert(reserved_low_addr() <= committed_low_addr(), "bad low addrs");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
void PSVirtualSpace::print() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  gclog_or_tty->print_cr("virtual space [" PTR_FORMAT "]:  alignment="
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
                         SIZE_FORMAT "K grows %s%s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
                         this, alignment() / K, grows_up() ? "up" : "down",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
                         special() ? " (pinned in memory)" : "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  gclog_or_tty->print_cr("    reserved=" SIZE_FORMAT "K"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
                         " [" PTR_FORMAT "," PTR_FORMAT "]"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
                         " committed=" SIZE_FORMAT "K"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
                         " [" PTR_FORMAT "," PTR_FORMAT "]",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
                         reserved_size() / K,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
                         reserved_low_addr(), reserved_high_addr(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
                         committed_size() / K,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
                         committed_low_addr(), committed_high_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
#endif // #ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
void PSVirtualSpace::print_space_boundaries_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  st->print_cr(" [" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT ")",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
               low_boundary(), high(), high_boundary());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
PSVirtualSpaceHighToLow::PSVirtualSpaceHighToLow(ReservedSpace rs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
                                                 size_t alignment) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  PSVirtualSpace(alignment)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  set_reserved(rs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  set_committed(reserved_high_addr(), reserved_high_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  DEBUG_ONLY(verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
PSVirtualSpaceHighToLow::PSVirtualSpaceHighToLow(ReservedSpace rs) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  set_reserved(rs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  set_committed(reserved_high_addr(), reserved_high_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  DEBUG_ONLY(verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1217
diff changeset
   249
bool PSVirtualSpaceHighToLow::expand_by(size_t bytes) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  assert(is_aligned(bytes), "arg not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  if (uncommitted_size() < bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  char* const base_addr = committed_low_addr() - bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  bool result = special() || os::commit_memory(base_addr, bytes, alignment());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  if (result) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    _committed_low_addr -= bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
bool PSVirtualSpaceHighToLow::shrink_by(size_t bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  assert(is_aligned(bytes), "arg not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  if (committed_size() < bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  char* const base_addr = committed_low_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  bool result = special() || os::uncommit_memory(base_addr, bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  if (result) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    _committed_low_addr += bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
size_t PSVirtualSpaceHighToLow::expand_into(PSVirtualSpace* other_space,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
                                            size_t bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  assert(is_aligned(bytes), "arg not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  assert(grows_down(), "this space must grow down");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  assert(other_space->grows_up(), "other space must grow up");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  assert(reserved_low_addr() == other_space->reserved_high_addr(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
         "spaces not contiguous");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  assert(special() == other_space->special(), "one space is special in memory, the other is not");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  DEBUG_ONLY(PSVirtualSpaceVerifier other_verifier(other_space));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  size_t bytes_needed = bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  // First use the uncommitted region in this space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  size_t tmp_bytes = MIN2(uncommitted_size(), bytes_needed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  if (tmp_bytes > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    if (expand_by(tmp_bytes)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
      bytes_needed -= tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
      return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  // Next take from the uncommitted region in the other space, and commit it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  tmp_bytes = MIN2(other_space->uncommitted_size(), bytes_needed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  if (tmp_bytes > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    char* const commit_base = committed_low_addr() - tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    if (other_space->special() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
        os::commit_memory(commit_base, tmp_bytes, alignment())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
      // Reduce the reserved region in the other space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
      other_space->set_reserved(other_space->reserved_low_addr(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
                                other_space->reserved_high_addr() - tmp_bytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
                                other_space->special());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
      // Grow both reserved and committed in this space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
      _reserved_low_addr -= tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
      _committed_low_addr -= tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
      bytes_needed -= tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
      return bytes - bytes_needed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  // Finally take from the already committed region in the other space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  tmp_bytes = bytes_needed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  if (tmp_bytes > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
    // Reduce both committed and reserved in the other space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    other_space->set_committed(other_space->committed_low_addr(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
                               other_space->committed_high_addr() - tmp_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    other_space->set_reserved(other_space->reserved_low_addr(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
                              other_space->reserved_high_addr() - tmp_bytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
                              other_space->special());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    // Grow both reserved and committed in this space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    _reserved_low_addr -= tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    _committed_low_addr -= tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  return bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
PSVirtualSpaceHighToLow::print_space_boundaries_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  st->print_cr(" (" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT "]",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
               high_boundary(), low(), low_boundary());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
}