hotspot/src/share/vm/gc/g1/g1PageBasedVirtualSpace.cpp
author kbarrett
Tue, 30 Aug 2016 23:48:16 -0400
changeset 40892 330a02d935ad
parent 40010 e32d5e545789
child 41178 e567be097315
permissions -rw-r--r--
8156500: Move Reference pending list into VM to prevent deadlocks Summary: Move reference pending list and locking into VM Reviewed-by: coleenp, dholmes, dcubed, mchung, plevart Contributed-by: kim.barrett@oracle.com, per.liden@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     1
/*
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 38177
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     4
 *
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     7
 * published by the Free Software Foundation.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     8
 *
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    13
 * accompanied this code).
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    14
 *
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    18
 *
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    21
 * questions.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    22
 *
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    23
 */
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    24
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30158
diff changeset
    26
#include "gc/g1/g1PageBasedVirtualSpace.hpp"
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    27
#include "oops/markOop.hpp"
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    28
#include "oops/oop.inline.hpp"
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 38177
diff changeset
    29
#include "runtime/os.inline.hpp"
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    30
#include "services/memTracker.hpp"
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    31
#include "utilities/bitMap.inline.hpp"
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    32
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    33
G1PageBasedVirtualSpace::G1PageBasedVirtualSpace(ReservedSpace rs, size_t used_size, size_t page_size) :
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    34
  _low_boundary(NULL), _high_boundary(NULL), _committed(), _page_size(0), _special(false),
28482
e1a8d03c342f 8062063: Usage of UseHugeTLBFS, UseLargePagesInMetaspace and huge SurvivorAlignmentInBytes cause crashes in CMBitMapClosure::do_bit
sjohanss
parents: 28208
diff changeset
    35
  _dirty(), _executable(false) {
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    36
  initialize_with_page_size(rs, used_size, page_size);
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    37
}
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    38
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    39
void G1PageBasedVirtualSpace::initialize_with_page_size(ReservedSpace rs, size_t used_size, size_t page_size) {
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    40
  guarantee(rs.is_reserved(), "Given reserved space must have been reserved already.");
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    41
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    42
  vmassert(_low_boundary == NULL, "VirtualSpace already initialized");
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    43
  vmassert(page_size > 0, "Page size must be non-zero.");
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    44
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    45
  guarantee(is_ptr_aligned(rs.base(), page_size),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
    46
            "Reserved space base " PTR_FORMAT " is not aligned to requested page size " SIZE_FORMAT, p2i(rs.base()), page_size);
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    47
  guarantee(is_size_aligned(used_size, os::vm_page_size()),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
    48
            "Given used reserved space size needs to be OS page size aligned (%d bytes) but is " SIZE_FORMAT, os::vm_page_size(), used_size);
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    49
  guarantee(used_size <= rs.size(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
    50
            "Used size of reserved space " SIZE_FORMAT " bytes is smaller than reservation at " SIZE_FORMAT " bytes", used_size, rs.size());
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    51
  guarantee(is_size_aligned(rs.size(), page_size),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
    52
            "Expected that the virtual space is size aligned, but " SIZE_FORMAT " is not aligned to page size " SIZE_FORMAT, rs.size(), page_size);
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    53
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    54
  _low_boundary  = rs.base();
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    55
  _high_boundary = _low_boundary + used_size;
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    56
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    57
  _special = rs.special();
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    58
  _executable = rs.executable();
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    59
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    60
  _page_size = page_size;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    61
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    62
  vmassert(_committed.size() == 0, "virtual space initialized more than once");
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    63
  BitMap::idx_t size_in_pages = rs.size() / page_size;
38177
b0c9cb06506b 8141501: Problems with BitMap buffer management
stefank
parents: 33105
diff changeset
    64
  _committed.initialize(size_in_pages);
28482
e1a8d03c342f 8062063: Usage of UseHugeTLBFS, UseLargePagesInMetaspace and huge SurvivorAlignmentInBytes cause crashes in CMBitMapClosure::do_bit
sjohanss
parents: 28208
diff changeset
    65
  if (_special) {
38177
b0c9cb06506b 8141501: Problems with BitMap buffer management
stefank
parents: 33105
diff changeset
    66
    _dirty.initialize(size_in_pages);
28482
e1a8d03c342f 8062063: Usage of UseHugeTLBFS, UseLargePagesInMetaspace and huge SurvivorAlignmentInBytes cause crashes in CMBitMapClosure::do_bit
sjohanss
parents: 28208
diff changeset
    67
  }
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    68
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    69
  _tail_size = used_size % _page_size;
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    70
}
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    71
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    72
G1PageBasedVirtualSpace::~G1PageBasedVirtualSpace() {
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    73
  // This does not release memory it never reserved.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    74
  // Caller must release via rs.release();
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    75
  _low_boundary           = NULL;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    76
  _high_boundary          = NULL;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    77
  _special                = false;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    78
  _executable             = false;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    79
  _page_size              = 0;
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    80
  _tail_size              = 0;
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    81
}
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    82
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    83
size_t G1PageBasedVirtualSpace::committed_size() const {
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    84
  size_t result = _committed.count_one_bits() * _page_size;
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    85
  // The last page might not be in full.
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    86
  if (is_last_page_partial() && _committed.at(_committed.size() - 1)) {
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    87
    result -= _page_size - _tail_size;
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    88
  }
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    89
  return result;
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    90
}
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    91
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    92
size_t G1PageBasedVirtualSpace::reserved_size() const {
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    93
  return pointer_delta(_high_boundary, _low_boundary, sizeof(char));
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    94
}
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    95
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    96
size_t G1PageBasedVirtualSpace::uncommitted_size()  const {
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    97
  return reserved_size() - committed_size();
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    98
}
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    99
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   100
size_t G1PageBasedVirtualSpace::addr_to_page_index(char* addr) const {
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   101
  return (addr - _low_boundary) / _page_size;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   102
}
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   103
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   104
bool G1PageBasedVirtualSpace::is_area_committed(size_t start_page, size_t size_in_pages) const {
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   105
  size_t end_page = start_page + size_in_pages;
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   106
  return _committed.get_next_zero_offset(start_page, end_page) >= end_page;
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   107
}
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   108
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   109
bool G1PageBasedVirtualSpace::is_area_uncommitted(size_t start_page, size_t size_in_pages) const {
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   110
  size_t end_page = start_page + size_in_pages;
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   111
  return _committed.get_next_one_offset(start_page, end_page) >= end_page;
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   112
}
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   113
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   114
char* G1PageBasedVirtualSpace::page_start(size_t index) const {
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   115
  return _low_boundary + index * _page_size;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   116
}
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   117
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   118
bool G1PageBasedVirtualSpace::is_after_last_page(size_t index) const {
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   119
  guarantee(index <= _committed.size(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   120
            "Given boundary page " SIZE_FORMAT " is beyond managed page count " SIZE_FORMAT, index, _committed.size());
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   121
  return index == _committed.size();
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   122
}
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   123
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   124
void G1PageBasedVirtualSpace::commit_preferred_pages(size_t start, size_t num_pages) {
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   125
  vmassert(num_pages > 0, "No full pages to commit");
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   126
  vmassert(start + num_pages <= _committed.size(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   127
           "Tried to commit area from page " SIZE_FORMAT " to page " SIZE_FORMAT " "
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   128
           "that is outside of managed space of " SIZE_FORMAT " pages",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   129
           start, start + num_pages, _committed.size());
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   130
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   131
  char* start_addr = page_start(start);
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   132
  size_t size = num_pages * _page_size;
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   133
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   134
  os::commit_memory_or_exit(start_addr, size, _page_size, _executable,
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   135
                            err_msg("Failed to commit area from " PTR_FORMAT " to " PTR_FORMAT " of length " SIZE_FORMAT ".",
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   136
                            p2i(start_addr), p2i(start_addr + size), size));
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   137
}
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   138
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   139
void G1PageBasedVirtualSpace::commit_tail() {
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   140
  vmassert(_tail_size > 0, "The size of the tail area must be > 0 when reaching here");
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   141
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   142
  char* const aligned_end_address = (char*)align_ptr_down(_high_boundary, _page_size);
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   143
  os::commit_memory_or_exit(aligned_end_address, _tail_size, os::vm_page_size(), _executable,
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   144
                            err_msg("Failed to commit tail area from " PTR_FORMAT " to " PTR_FORMAT " of length " SIZE_FORMAT ".",
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   145
                            p2i(aligned_end_address), p2i(_high_boundary), _tail_size));
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   146
}
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   147
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   148
void G1PageBasedVirtualSpace::commit_internal(size_t start_page, size_t end_page) {
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   149
  guarantee(start_page < end_page,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   150
            "Given start page " SIZE_FORMAT " is larger or equal to end page " SIZE_FORMAT, start_page, end_page);
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   151
  guarantee(end_page <= _committed.size(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   152
            "Given end page " SIZE_FORMAT " is beyond end of managed page amount of " SIZE_FORMAT, end_page, _committed.size());
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   153
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   154
  size_t pages = end_page - start_page;
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   155
  bool need_to_commit_tail = is_after_last_page(end_page) && is_last_page_partial();
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   156
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   157
  // If we have to commit some (partial) tail area, decrease the amount of pages to avoid
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   158
  // committing that in the full-page commit code.
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   159
  if (need_to_commit_tail) {
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   160
    pages--;
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   161
  }
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   162
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   163
  if (pages > 0) {
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   164
    commit_preferred_pages(start_page, pages);
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   165
  }
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   166
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   167
  if (need_to_commit_tail) {
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   168
    commit_tail();
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   169
  }
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   170
}
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   171
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   172
char* G1PageBasedVirtualSpace::bounded_end_addr(size_t end_page) const {
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   173
  return MIN2(_high_boundary, page_start(end_page));
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   174
}
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   175
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   176
void G1PageBasedVirtualSpace::pretouch_internal(size_t start_page, size_t end_page) {
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   177
  guarantee(start_page < end_page,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   178
            "Given start page " SIZE_FORMAT " is larger or equal to end page " SIZE_FORMAT, start_page, end_page);
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   179
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   180
  os::pretouch_memory(page_start(start_page), bounded_end_addr(end_page));
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   181
}
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   182
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   183
bool G1PageBasedVirtualSpace::commit(size_t start_page, size_t size_in_pages) {
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   184
  // We need to make sure to commit all pages covered by the given area.
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   185
  guarantee(is_area_uncommitted(start_page, size_in_pages), "Specified area is not uncommitted");
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   186
28482
e1a8d03c342f 8062063: Usage of UseHugeTLBFS, UseLargePagesInMetaspace and huge SurvivorAlignmentInBytes cause crashes in CMBitMapClosure::do_bit
sjohanss
parents: 28208
diff changeset
   187
  bool zero_filled = true;
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   188
  size_t end_page = start_page + size_in_pages;
28482
e1a8d03c342f 8062063: Usage of UseHugeTLBFS, UseLargePagesInMetaspace and huge SurvivorAlignmentInBytes cause crashes in CMBitMapClosure::do_bit
sjohanss
parents: 28208
diff changeset
   189
e1a8d03c342f 8062063: Usage of UseHugeTLBFS, UseLargePagesInMetaspace and huge SurvivorAlignmentInBytes cause crashes in CMBitMapClosure::do_bit
sjohanss
parents: 28208
diff changeset
   190
  if (_special) {
e1a8d03c342f 8062063: Usage of UseHugeTLBFS, UseLargePagesInMetaspace and huge SurvivorAlignmentInBytes cause crashes in CMBitMapClosure::do_bit
sjohanss
parents: 28208
diff changeset
   191
    // Check for dirty pages and update zero_filled if any found.
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   192
    if (_dirty.get_next_one_offset(start_page, end_page) < end_page) {
28482
e1a8d03c342f 8062063: Usage of UseHugeTLBFS, UseLargePagesInMetaspace and huge SurvivorAlignmentInBytes cause crashes in CMBitMapClosure::do_bit
sjohanss
parents: 28208
diff changeset
   193
      zero_filled = false;
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   194
      _dirty.clear_range(start_page, end_page);
28482
e1a8d03c342f 8062063: Usage of UseHugeTLBFS, UseLargePagesInMetaspace and huge SurvivorAlignmentInBytes cause crashes in CMBitMapClosure::do_bit
sjohanss
parents: 28208
diff changeset
   195
    }
e1a8d03c342f 8062063: Usage of UseHugeTLBFS, UseLargePagesInMetaspace and huge SurvivorAlignmentInBytes cause crashes in CMBitMapClosure::do_bit
sjohanss
parents: 28208
diff changeset
   196
  } else {
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   197
    commit_internal(start_page, end_page);
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   198
  }
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   199
  _committed.set_range(start_page, end_page);
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   200
28208
d67f748ece0a 8067469: G1 ignores AlwaysPreTouch
tschatzl
parents: 26162
diff changeset
   201
  if (AlwaysPreTouch) {
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   202
    pretouch_internal(start_page, end_page);
28208
d67f748ece0a 8067469: G1 ignores AlwaysPreTouch
tschatzl
parents: 26162
diff changeset
   203
  }
28482
e1a8d03c342f 8062063: Usage of UseHugeTLBFS, UseLargePagesInMetaspace and huge SurvivorAlignmentInBytes cause crashes in CMBitMapClosure::do_bit
sjohanss
parents: 28208
diff changeset
   204
  return zero_filled;
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   205
}
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   206
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   207
void G1PageBasedVirtualSpace::uncommit_internal(size_t start_page, size_t end_page) {
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   208
  guarantee(start_page < end_page,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   209
            "Given start page " SIZE_FORMAT " is larger or equal to end page " SIZE_FORMAT, start_page, end_page);
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   210
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   211
  char* start_addr = page_start(start_page);
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   212
  os::uncommit_memory(start_addr, pointer_delta(bounded_end_addr(end_page), start_addr, sizeof(char)));
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   213
}
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   214
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   215
void G1PageBasedVirtualSpace::uncommit(size_t start_page, size_t size_in_pages) {
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   216
  guarantee(is_area_committed(start_page, size_in_pages), "checking");
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   217
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   218
  size_t end_page = start_page + size_in_pages;
28482
e1a8d03c342f 8062063: Usage of UseHugeTLBFS, UseLargePagesInMetaspace and huge SurvivorAlignmentInBytes cause crashes in CMBitMapClosure::do_bit
sjohanss
parents: 28208
diff changeset
   219
  if (_special) {
e1a8d03c342f 8062063: Usage of UseHugeTLBFS, UseLargePagesInMetaspace and huge SurvivorAlignmentInBytes cause crashes in CMBitMapClosure::do_bit
sjohanss
parents: 28208
diff changeset
   220
    // Mark that memory is dirty. If committed again the memory might
e1a8d03c342f 8062063: Usage of UseHugeTLBFS, UseLargePagesInMetaspace and huge SurvivorAlignmentInBytes cause crashes in CMBitMapClosure::do_bit
sjohanss
parents: 28208
diff changeset
   221
    // need to be cleared explicitly.
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   222
    _dirty.set_range(start_page, end_page);
28482
e1a8d03c342f 8062063: Usage of UseHugeTLBFS, UseLargePagesInMetaspace and huge SurvivorAlignmentInBytes cause crashes in CMBitMapClosure::do_bit
sjohanss
parents: 28208
diff changeset
   223
  } else {
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   224
    uncommit_internal(start_page, end_page);
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   225
  }
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   226
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   227
  _committed.clear_range(start_page, end_page);
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   228
}
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   229
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   230
bool G1PageBasedVirtualSpace::contains(const void* p) const {
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   231
  return _low_boundary <= (const char*) p && (const char*) p < _high_boundary;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   232
}
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   233
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   234
#ifndef PRODUCT
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   235
void G1PageBasedVirtualSpace::print_on(outputStream* out) {
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   236
  out->print   ("Virtual space:");
28482
e1a8d03c342f 8062063: Usage of UseHugeTLBFS, UseLargePagesInMetaspace and huge SurvivorAlignmentInBytes cause crashes in CMBitMapClosure::do_bit
sjohanss
parents: 28208
diff changeset
   237
  if (_special) out->print(" (pinned in memory)");
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   238
  out->cr();
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   239
  out->print_cr(" - committed: " SIZE_FORMAT, committed_size());
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   240
  out->print_cr(" - reserved:  " SIZE_FORMAT, reserved_size());
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   241
  out->print_cr(" - preferred page size: " SIZE_FORMAT, _page_size);
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   242
  out->print_cr(" - [low_b, high_b]: [" PTR_FORMAT ", " PTR_FORMAT "]",  p2i(_low_boundary), p2i(_high_boundary));
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   243
}
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   244
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   245
void G1PageBasedVirtualSpace::print() {
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   246
  print_on(tty);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   247
}
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   248
#endif