hotspot/src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.cpp
author dcubed
Thu, 13 Jun 2013 11:16:38 -0700
changeset 18069 e6d4971c8650
parent 10565 dc90c239f4ec
child 22827 07d991d45a51
permissions -rw-r--r--
8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint Summary: Detect mmap() commit failures in Linux and Solaris os::commit_memory() impls and call vm_exit_out_of_memory(). Add os::commit_memory_or_exit(). Also tidy up some NMT accounting and some mmap() return value checking. Reviewed-by: zgu, stefank, dholmes, dsamersoff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
18069
e6d4971c8650 8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents: 10565
diff changeset
     2
 * Copyright (c) 2003, 2013, 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"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "gc_implementation/parallelScavenge/psVirtualspace.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "runtime/os.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "runtime/virtualspace.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#ifdef TARGET_OS_FAMILY_linux
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
# include "os_linux.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#ifdef TARGET_OS_FAMILY_solaris
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
# include "os_solaris.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
#ifdef TARGET_OS_FAMILY_windows
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
# include "os_windows.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    37
#endif
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7397
diff changeset
    38
#ifdef TARGET_OS_FAMILY_bsd
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7397
diff changeset
    39
# include "os_bsd.inline.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7397
diff changeset
    40
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// PSVirtualSpace
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
PSVirtualSpace::PSVirtualSpace(ReservedSpace rs, size_t alignment) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  _alignment(alignment)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  set_reserved(rs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  set_committed(reserved_low_addr(), reserved_low_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  DEBUG_ONLY(verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
PSVirtualSpace::PSVirtualSpace(ReservedSpace rs) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  _alignment(os::vm_page_size())
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  set_reserved(rs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  set_committed(reserved_low_addr(), reserved_low_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  DEBUG_ONLY(verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
// Deprecated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
PSVirtualSpace::PSVirtualSpace(): _alignment(os::vm_page_size()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
// Deprecated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
bool PSVirtualSpace::initialize(ReservedSpace rs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
                                size_t commit_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  set_reserved(rs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  set_committed(reserved_low_addr(), reserved_low_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // Commit to initial size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  assert(commit_size <= rs.size(), "commit_size too big");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  bool result = commit_size > 0 ? expand_by(commit_size) : true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  DEBUG_ONLY(verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
PSVirtualSpace::~PSVirtualSpace() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  release();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
bool PSVirtualSpace::contains(void* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  char* const cp = (char*)p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  return cp >= committed_low_addr() && cp < committed_high_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
void PSVirtualSpace::release() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
823
9a5271881bc0 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 1
diff changeset
    88
  // This may not release memory it didn't reserve.
9a5271881bc0 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 1
diff changeset
    89
  // Use rs.release() to release the underlying memory instead.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  _reserved_low_addr = _reserved_high_addr = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  _committed_low_addr = _committed_high_addr = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  _special = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1217
diff changeset
    95
bool PSVirtualSpace::expand_by(size_t bytes) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  assert(is_aligned(bytes), "arg not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  if (uncommitted_size() < bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  char* const base_addr = committed_high_addr();
18069
e6d4971c8650 8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents: 10565
diff changeset
   104
  bool result = special() ||
e6d4971c8650 8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents: 10565
diff changeset
   105
         os::commit_memory(base_addr, bytes, alignment(), !ExecMem);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  if (result) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    _committed_high_addr += bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
bool PSVirtualSpace::shrink_by(size_t bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  assert(is_aligned(bytes), "arg not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  if (committed_size() < bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  char* const base_addr = committed_high_addr() - bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  bool result = special() || os::uncommit_memory(base_addr, bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  if (result) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    _committed_high_addr -= bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
size_t
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
PSVirtualSpace::expand_into(PSVirtualSpace* other_space, size_t bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  assert(is_aligned(bytes), "arg not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  assert(grows_up(), "this space must grow up");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  assert(other_space->grows_down(), "other space must grow down");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  assert(reserved_high_addr() == other_space->reserved_low_addr(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
         "spaces not contiguous");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  assert(special() == other_space->special(), "one space is special, the other is not");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  DEBUG_ONLY(PSVirtualSpaceVerifier other_verifier(other_space));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  size_t bytes_needed = bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  // First use the uncommitted region in this space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  size_t tmp_bytes = MIN2(uncommitted_size(), bytes_needed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  if (tmp_bytes > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    if (expand_by(tmp_bytes)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      bytes_needed -= tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
      return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // Next take from the uncommitted region in the other space, and commit it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  tmp_bytes = MIN2(other_space->uncommitted_size(), bytes_needed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  if (tmp_bytes > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    char* const commit_base = committed_high_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    if (other_space->special() ||
18069
e6d4971c8650 8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents: 10565
diff changeset
   158
        os::commit_memory(commit_base, tmp_bytes, alignment(), !ExecMem)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      // Reduce the reserved region in the other space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
      other_space->set_reserved(other_space->reserved_low_addr() + tmp_bytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
                                other_space->reserved_high_addr(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
                                other_space->special());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      // Grow both reserved and committed in this space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
      _reserved_high_addr += tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
      _committed_high_addr += tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
      bytes_needed -= tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
      return bytes - bytes_needed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  // Finally take from the already committed region in the other space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  tmp_bytes = bytes_needed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  if (tmp_bytes > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    // Reduce both committed and reserved in the other space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    other_space->set_committed(other_space->committed_low_addr() + tmp_bytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
                               other_space->committed_high_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    other_space->set_reserved(other_space->reserved_low_addr() + tmp_bytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
                              other_space->reserved_high_addr(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
                              other_space->special());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    // Grow both reserved and committed in this space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    _reserved_high_addr += tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    _committed_high_addr += tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  return bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
bool PSVirtualSpace::is_aligned(size_t value, size_t align) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  const size_t tmp_value = value + align - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  const size_t mask = ~(align - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  return (tmp_value & mask) == value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
bool PSVirtualSpace::is_aligned(size_t value) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  return is_aligned(value, alignment());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
bool PSVirtualSpace::is_aligned(char* value) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  return is_aligned((size_t)value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
void PSVirtualSpace::verify() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  assert(is_aligned(alignment(), os::vm_page_size()), "bad alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  assert(is_aligned(reserved_low_addr()), "bad reserved_low_addr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  assert(is_aligned(reserved_high_addr()), "bad reserved_high_addr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  assert(is_aligned(committed_low_addr()), "bad committed_low_addr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  assert(is_aligned(committed_high_addr()), "bad committed_high_addr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  // Reserved region must be non-empty or both addrs must be 0.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  assert(reserved_low_addr() < reserved_high_addr() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
         reserved_low_addr() == NULL && reserved_high_addr() == NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
         "bad reserved addrs");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  assert(committed_low_addr() <= committed_high_addr(), "bad committed addrs");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  if (grows_up()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    assert(reserved_low_addr() == committed_low_addr(), "bad low addrs");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    assert(reserved_high_addr() >= committed_high_addr(), "bad high addrs");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    assert(reserved_high_addr() == committed_high_addr(), "bad high addrs");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    assert(reserved_low_addr() <= committed_low_addr(), "bad low addrs");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
void PSVirtualSpace::print() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  gclog_or_tty->print_cr("virtual space [" PTR_FORMAT "]:  alignment="
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
                         SIZE_FORMAT "K grows %s%s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
                         this, alignment() / K, grows_up() ? "up" : "down",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
                         special() ? " (pinned in memory)" : "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  gclog_or_tty->print_cr("    reserved=" SIZE_FORMAT "K"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
                         " [" PTR_FORMAT "," PTR_FORMAT "]"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
                         " committed=" SIZE_FORMAT "K"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
                         " [" PTR_FORMAT "," PTR_FORMAT "]",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
                         reserved_size() / K,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
                         reserved_low_addr(), reserved_high_addr(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
                         committed_size() / K,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
                         committed_low_addr(), committed_high_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
#endif // #ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
void PSVirtualSpace::print_space_boundaries_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  st->print_cr(" [" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT ")",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
               low_boundary(), high(), high_boundary());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
PSVirtualSpaceHighToLow::PSVirtualSpaceHighToLow(ReservedSpace rs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
                                                 size_t alignment) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  PSVirtualSpace(alignment)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  set_reserved(rs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  set_committed(reserved_high_addr(), reserved_high_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  DEBUG_ONLY(verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
PSVirtualSpaceHighToLow::PSVirtualSpaceHighToLow(ReservedSpace rs) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  set_reserved(rs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  set_committed(reserved_high_addr(), reserved_high_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  DEBUG_ONLY(verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1217
diff changeset
   264
bool PSVirtualSpaceHighToLow::expand_by(size_t bytes) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  assert(is_aligned(bytes), "arg not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  if (uncommitted_size() < bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  char* const base_addr = committed_low_addr() - bytes;
18069
e6d4971c8650 8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents: 10565
diff changeset
   273
  bool result = special() ||
e6d4971c8650 8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents: 10565
diff changeset
   274
         os::commit_memory(base_addr, bytes, alignment(), !ExecMem);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  if (result) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    _committed_low_addr -= bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
bool PSVirtualSpaceHighToLow::shrink_by(size_t bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  assert(is_aligned(bytes), "arg not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  if (committed_size() < bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  char* const base_addr = committed_low_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  bool result = special() || os::uncommit_memory(base_addr, bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  if (result) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    _committed_low_addr += bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
size_t PSVirtualSpaceHighToLow::expand_into(PSVirtualSpace* other_space,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
                                            size_t bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  assert(is_aligned(bytes), "arg not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  assert(grows_down(), "this space must grow down");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  assert(other_space->grows_up(), "other space must grow up");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  assert(reserved_low_addr() == other_space->reserved_high_addr(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
         "spaces not contiguous");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  assert(special() == other_space->special(), "one space is special in memory, the other is not");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  DEBUG_ONLY(PSVirtualSpaceVerifier this_verifier(this));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  DEBUG_ONLY(PSVirtualSpaceVerifier other_verifier(other_space));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  size_t bytes_needed = bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  // First use the uncommitted region in this space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  size_t tmp_bytes = MIN2(uncommitted_size(), bytes_needed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  if (tmp_bytes > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    if (expand_by(tmp_bytes)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
      bytes_needed -= tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
      return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  // Next take from the uncommitted region in the other space, and commit it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  tmp_bytes = MIN2(other_space->uncommitted_size(), bytes_needed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  if (tmp_bytes > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    char* const commit_base = committed_low_addr() - tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    if (other_space->special() ||
18069
e6d4971c8650 8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents: 10565
diff changeset
   327
        os::commit_memory(commit_base, tmp_bytes, alignment(), !ExecMem)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
      // Reduce the reserved region in the other space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
      other_space->set_reserved(other_space->reserved_low_addr(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
                                other_space->reserved_high_addr() - tmp_bytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
                                other_space->special());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
      // Grow both reserved and committed in this space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
      _reserved_low_addr -= tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
      _committed_low_addr -= tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
      bytes_needed -= tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
      return bytes - bytes_needed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  // Finally take from the already committed region in the other space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  tmp_bytes = bytes_needed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  if (tmp_bytes > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    // Reduce both committed and reserved in the other space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    other_space->set_committed(other_space->committed_low_addr(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
                               other_space->committed_high_addr() - tmp_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    other_space->set_reserved(other_space->reserved_low_addr(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
                              other_space->reserved_high_addr() - tmp_bytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
                              other_space->special());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    // Grow both reserved and committed in this space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    _reserved_low_addr -= tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    _committed_low_addr -= tmp_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  return bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
PSVirtualSpaceHighToLow::print_space_boundaries_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  st->print_cr(" (" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT "]",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
               high_boundary(), low(), low_boundary());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
}