src/hotspot/share/memory/virtualspace.cpp
author iklam
Tue, 28 Aug 2018 16:01:01 -0700
changeset 51557 0369fe9ae26f
parent 51334 cc2c79d22508
child 52396 e292e94b448a
permissions -rw-r--r--
8210043: Invalid assert(HeapBaseMinAddress > 0) in ReservedHeapSpace::initialize_compressed_heap Summary: Removed the assert Reviewed-by: ccheung, jiangli
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
49593
4dd58ecc9912 8200105: Remove cyclic dependency between oop.inline.hpp and collectedHeap.inline.hpp
stefank
parents: 48153
diff changeset
     2
 * Copyright (c) 1997, 2018, 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: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
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: 3261
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: 5898
diff changeset
    25
#include "precompiled.hpp"
37428
6e724f3d488b 8152896: Convert PrintCompressedOopsMode to Unified Logging
rprotacio
parents: 35898
diff changeset
    26
#include "logging/log.hpp"
6e724f3d488b 8152896: Convert PrintCompressedOopsMode to Unified Logging
rprotacio
parents: 35898
diff changeset
    27
#include "memory/resourceArea.hpp"
30291
54cdc5c1a9cb 8068352: Move virtualspace.* out of src/share/vm/runtime to memory directory
coleenp
parents: 30166
diff changeset
    28
#include "memory/virtualspace.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5898
diff changeset
    29
#include "oops/markOop.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5898
diff changeset
    30
#include "oops/oop.inline.hpp"
49593
4dd58ecc9912 8200105: Remove cyclic dependency between oop.inline.hpp and collectedHeap.inline.hpp
stefank
parents: 48153
diff changeset
    31
#include "runtime/os.inline.hpp"
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11778
diff changeset
    32
#include "services/memTracker.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46620
diff changeset
    33
#include "utilities/align.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// ReservedSpace
19546
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
    36
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
    37
// Dummy constructor
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
    38
ReservedSpace::ReservedSpace() : _base(NULL), _size(0), _noaccess_prefix(0),
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 51070
diff changeset
    39
    _alignment(0), _special(false), _fd_for_heap(-1), _executable(false) {
19546
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
    40
}
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
    41
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
    42
ReservedSpace::ReservedSpace(size_t size, size_t preferred_page_size) : _fd_for_heap(-1) {
30166
a85188117643 8077255: TracePageSizes output reports wrong page size on Windows with G1
tschatzl
parents: 30158
diff changeset
    43
  bool has_preferred_page_size = preferred_page_size != 0;
28631
a56cae1b428d 8066875: VirtualSpace does not use large pages
ehelin
parents: 28372
diff changeset
    44
  // Want to use large pages where possible and pad with small pages.
30166
a85188117643 8077255: TracePageSizes output reports wrong page size on Windows with G1
tschatzl
parents: 30158
diff changeset
    45
  size_t page_size = has_preferred_page_size ? preferred_page_size : os::page_size_for_region_unaligned(size, 1);
19546
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
    46
  bool large_pages = page_size != (size_t)os::vm_page_size();
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 29580
diff changeset
    47
  size_t alignment;
30166
a85188117643 8077255: TracePageSizes output reports wrong page size on Windows with G1
tschatzl
parents: 30158
diff changeset
    48
  if (large_pages && has_preferred_page_size) {
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 29580
diff changeset
    49
    alignment = MAX2(page_size, (size_t)os::vm_allocation_granularity());
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 29580
diff changeset
    50
    // ReservedSpace initialization requires size to be aligned to the given
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 29580
diff changeset
    51
    // alignment. Align the size up.
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
    52
    size = align_up(size, alignment);
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 29580
diff changeset
    53
  } else {
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 29580
diff changeset
    54
    // Don't force the alignment to be large page aligned,
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 29580
diff changeset
    55
    // since that will waste memory.
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 29580
diff changeset
    56
    alignment = os::vm_allocation_granularity();
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 29580
diff changeset
    57
  }
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
    58
  initialize(size, alignment, large_pages, NULL, false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
ReservedSpace::ReservedSpace(size_t size, size_t alignment,
823
9a5271881bc0 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 1
diff changeset
    62
                             bool large,
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
    63
                             char* requested_address) : _fd_for_heap(-1) {
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
    64
  initialize(size, alignment, large, requested_address, false);
2268
bea8be80ec88 6541756: Reduce executable C-heap
coleenp
parents: 2254
diff changeset
    65
}
bea8be80ec88 6541756: Reduce executable C-heap
coleenp
parents: 2254
diff changeset
    66
bea8be80ec88 6541756: Reduce executable C-heap
coleenp
parents: 2254
diff changeset
    67
ReservedSpace::ReservedSpace(size_t size, size_t alignment,
bea8be80ec88 6541756: Reduce executable C-heap
coleenp
parents: 2254
diff changeset
    68
                             bool large,
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
    69
                             bool executable) : _fd_for_heap(-1) {
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
    70
  initialize(size, alignment, large, NULL, executable);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
51070
2f4c3cac8556 8206977: Minor improvements of runtime code.
goetz
parents: 49593
diff changeset
    73
ReservedSpace::ReservedSpace(char* base, size_t size, size_t alignment,
2f4c3cac8556 8206977: Minor improvements of runtime code.
goetz
parents: 49593
diff changeset
    74
                             bool special, bool executable) : _fd_for_heap(-1) {
2f4c3cac8556 8206977: Minor improvements of runtime code.
goetz
parents: 49593
diff changeset
    75
  assert((size % os::vm_allocation_granularity()) == 0,
2f4c3cac8556 8206977: Minor improvements of runtime code.
goetz
parents: 49593
diff changeset
    76
         "size not allocation aligned");
2f4c3cac8556 8206977: Minor improvements of runtime code.
goetz
parents: 49593
diff changeset
    77
  _base = base;
2f4c3cac8556 8206977: Minor improvements of runtime code.
goetz
parents: 49593
diff changeset
    78
  _size = size;
2f4c3cac8556 8206977: Minor improvements of runtime code.
goetz
parents: 49593
diff changeset
    79
  _alignment = alignment;
2f4c3cac8556 8206977: Minor improvements of runtime code.
goetz
parents: 49593
diff changeset
    80
  _noaccess_prefix = 0;
2f4c3cac8556 8206977: Minor improvements of runtime code.
goetz
parents: 49593
diff changeset
    81
  _special = special;
2f4c3cac8556 8206977: Minor improvements of runtime code.
goetz
parents: 49593
diff changeset
    82
  _executable = executable;
2f4c3cac8556 8206977: Minor improvements of runtime code.
goetz
parents: 49593
diff changeset
    83
}
2f4c3cac8556 8206977: Minor improvements of runtime code.
goetz
parents: 49593
diff changeset
    84
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
    85
// Helper method
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
    86
static void unmap_or_release_memory(char* base, size_t size, bool is_file_mapped) {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
    87
  if (is_file_mapped) {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
    88
    if (!os::unmap_memory(base, size)) {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
    89
      fatal("os::unmap_memory failed");
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
    90
    }
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
    91
  } else if (!os::release_memory(base, size)) {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
    92
    fatal("os::release_memory failed");
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
    93
  }
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
    94
}
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
    95
5898
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
    96
// Helper method.
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
    97
static bool failed_to_reserve_as_requested(char* base, char* requested_address,
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
    98
                                           const size_t size, bool special, bool is_file_mapped = false)
5898
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
    99
{
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   100
  if (base == requested_address || requested_address == NULL)
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   101
    return false; // did not fail
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   102
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   103
  if (base != NULL) {
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   104
    // Different reserve address may be acceptable in other cases
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   105
    // but for compressed oops heap should be at requested address.
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   106
    assert(UseCompressedOops, "currently requested address used only for compressed oops");
37428
6e724f3d488b 8152896: Convert PrintCompressedOopsMode to Unified Logging
rprotacio
parents: 35898
diff changeset
   107
    log_debug(gc, heap, coops)("Reserved memory not at requested address: " PTR_FORMAT " vs " PTR_FORMAT, p2i(base), p2i(requested_address));
5898
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   108
    // OS ignored requested address. Try different address.
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   109
    if (special) {
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   110
      if (!os::release_memory_special(base, size)) {
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   111
        fatal("os::release_memory_special failed");
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   112
      }
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   113
    } else {
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   114
      unmap_or_release_memory(base, size, is_file_mapped);
5898
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   115
    }
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   116
  }
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   117
  return true;
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   118
}
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   119
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
void ReservedSpace::initialize(size_t size, size_t alignment, bool large,
823
9a5271881bc0 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 1
diff changeset
   121
                               char* requested_address,
2268
bea8be80ec88 6541756: Reduce executable C-heap
coleenp
parents: 2254
diff changeset
   122
                               bool executable) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  const size_t granularity = os::vm_allocation_granularity();
10237
df347ffafa0d 7069863: G1: SIGSEGV running SPECjbb2011 and -UseBiasedLocking
johnc
parents: 7397
diff changeset
   124
  assert((size & (granularity - 1)) == 0,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
         "size not aligned to os::vm_allocation_granularity()");
10237
df347ffafa0d 7069863: G1: SIGSEGV running SPECjbb2011 and -UseBiasedLocking
johnc
parents: 7397
diff changeset
   126
  assert((alignment & (granularity - 1)) == 0,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
         "alignment not aligned to os::vm_allocation_granularity()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  assert(alignment == 0 || is_power_of_2((intptr_t)alignment),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
         "not a power of 2");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
10237
df347ffafa0d 7069863: G1: SIGSEGV running SPECjbb2011 and -UseBiasedLocking
johnc
parents: 7397
diff changeset
   131
  alignment = MAX2(alignment, (size_t)os::vm_page_size());
df347ffafa0d 7069863: G1: SIGSEGV running SPECjbb2011 and -UseBiasedLocking
johnc
parents: 7397
diff changeset
   132
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  _base = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  _size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  _special = false;
2268
bea8be80ec88 6541756: Reduce executable C-heap
coleenp
parents: 2254
diff changeset
   136
  _executable = executable;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  _alignment = 0;
823
9a5271881bc0 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 1
diff changeset
   138
  _noaccess_prefix = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  if (size == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  // If OS doesn't support demand paging for large page memory, we need
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // to use reserve_memory_special() to reserve and pin the entire region.
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   145
  // If there is a backing file directory for this space then whether
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   146
  // large pages are allocated is up to the filesystem of the backing file.
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   147
  // So we ignore the UseLargePages flag in this case.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  bool special = large && !os::can_commit_large_page_memory();
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   149
  if (special && _fd_for_heap != -1) {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   150
    special = false;
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   151
    if (UseLargePages && (!FLAG_IS_DEFAULT(UseLargePages) ||
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   152
      !FLAG_IS_DEFAULT(LargePageSizeInBytes))) {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   153
      log_debug(gc, heap)("Ignoring UseLargePages since large page support is up to the file system of the backing file for Java heap");
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   154
    }
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   155
  }
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   156
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  char* base = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  if (special) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
19546
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
   161
    base = os::reserve_memory_special(size, alignment, requested_address, executable);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    if (base != NULL) {
5898
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   164
      if (failed_to_reserve_as_requested(base, requested_address, size, true)) {
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   165
        // OS ignored requested address. Try different address.
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   166
        return;
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   167
      }
19546
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
   168
      // Check alignment constraints.
10237
df347ffafa0d 7069863: G1: SIGSEGV running SPECjbb2011 and -UseBiasedLocking
johnc
parents: 7397
diff changeset
   169
      assert((uintptr_t) base % alignment == 0,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31620
diff changeset
   170
             "Large pages returned a non-aligned address, base: "
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 33105
diff changeset
   171
             PTR_FORMAT " alignment: " SIZE_FORMAT_HEX,
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 33105
diff changeset
   172
             p2i(base), alignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      _special = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
      // failed; try to reserve regular memory below
5898
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   176
      if (UseLargePages && (!FLAG_IS_DEFAULT(UseLargePages) ||
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   177
                            !FLAG_IS_DEFAULT(LargePageSizeInBytes))) {
37428
6e724f3d488b 8152896: Convert PrintCompressedOopsMode to Unified Logging
rprotacio
parents: 35898
diff changeset
   178
        log_debug(gc, heap, coops)("Reserve regular memory without large pages");
5898
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   179
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  if (base == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    // Optimistically assume that the OSes returns an aligned base pointer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    // When reserving a large address range, most OSes seem to align to at
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    // least 64K.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    // If the memory was requested at a particular address, use
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    // os::attempt_reserve_memory_at() to avoid over mapping something
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    // important.  If available space is not detected, return NULL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    if (requested_address != 0) {
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   193
      base = os::attempt_reserve_memory_at(size, requested_address, _fd_for_heap);
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   194
      if (failed_to_reserve_as_requested(base, requested_address, size, false, _fd_for_heap != -1)) {
5898
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   195
        // OS ignored requested address. Try different address.
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   196
        base = NULL;
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   197
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    } else {
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   199
      base = os::reserve_memory(size, NULL, alignment, _fd_for_heap);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    if (base == NULL) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    // Check alignment constraints
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   205
    if ((((size_t)base) & (alignment - 1)) != 0) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
      // Base not aligned, retry
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   207
      unmap_or_release_memory(base, size, _fd_for_heap != -1 /*is_file_mapped*/);
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   208
14840
8994c2377547 7173959: Jvm crashed during coherence exabus (tmb) testing
brutisso
parents: 13728
diff changeset
   209
      // Make sure that size is aligned
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   210
      size = align_up(size, alignment);
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   211
      base = os::reserve_memory_aligned(size, alignment, _fd_for_heap);
10237
df347ffafa0d 7069863: G1: SIGSEGV running SPECjbb2011 and -UseBiasedLocking
johnc
parents: 7397
diff changeset
   212
df347ffafa0d 7069863: G1: SIGSEGV running SPECjbb2011 and -UseBiasedLocking
johnc
parents: 7397
diff changeset
   213
      if (requested_address != 0 &&
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   214
          failed_to_reserve_as_requested(base, requested_address, size, false, _fd_for_heap != -1)) {
10237
df347ffafa0d 7069863: G1: SIGSEGV running SPECjbb2011 and -UseBiasedLocking
johnc
parents: 7397
diff changeset
   215
        // As a result of the alignment constraints, the allocated base differs
df347ffafa0d 7069863: G1: SIGSEGV running SPECjbb2011 and -UseBiasedLocking
johnc
parents: 7397
diff changeset
   216
        // from the requested address. Return back to the caller who can
df347ffafa0d 7069863: G1: SIGSEGV running SPECjbb2011 and -UseBiasedLocking
johnc
parents: 7397
diff changeset
   217
        // take remedial action (like try again without a requested address).
df347ffafa0d 7069863: G1: SIGSEGV running SPECjbb2011 and -UseBiasedLocking
johnc
parents: 7397
diff changeset
   218
        assert(_base == NULL, "should be");
df347ffafa0d 7069863: G1: SIGSEGV running SPECjbb2011 and -UseBiasedLocking
johnc
parents: 7397
diff changeset
   219
        return;
df347ffafa0d 7069863: G1: SIGSEGV running SPECjbb2011 and -UseBiasedLocking
johnc
parents: 7397
diff changeset
   220
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  // Done
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  _base = base;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  _size = size;
10237
df347ffafa0d 7069863: G1: SIGSEGV running SPECjbb2011 and -UseBiasedLocking
johnc
parents: 7397
diff changeset
   226
  _alignment = alignment;
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   227
  // If heap is reserved with a backing file, the entire space has been committed. So set the _special flag to true
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   228
  if (_fd_for_heap != -1) {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   229
    _special = true;
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   230
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
ReservedSpace ReservedSpace::first_part(size_t partition_size, size_t alignment,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
                                        bool split, bool realloc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  assert(partition_size <= size(), "partition failed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  if (split) {
2268
bea8be80ec88 6541756: Reduce executable C-heap
coleenp
parents: 2254
diff changeset
   237
    os::split_reserved_memory(base(), size(), partition_size, realloc);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  }
2268
bea8be80ec88 6541756: Reduce executable C-heap
coleenp
parents: 2254
diff changeset
   239
  ReservedSpace result(base(), partition_size, alignment, special(),
bea8be80ec88 6541756: Reduce executable C-heap
coleenp
parents: 2254
diff changeset
   240
                       executable());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
ReservedSpace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
ReservedSpace::last_part(size_t partition_size, size_t alignment) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  assert(partition_size <= size(), "partition failed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  ReservedSpace result(base() + partition_size, size() - partition_size,
2268
bea8be80ec88 6541756: Reduce executable C-heap
coleenp
parents: 2254
diff changeset
   249
                       alignment, special(), executable());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
size_t ReservedSpace::page_align_size_up(size_t size) {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   255
  return align_up(size, os::vm_page_size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
size_t ReservedSpace::page_align_size_down(size_t size) {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   260
  return align_down(size, os::vm_page_size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
size_t ReservedSpace::allocation_align_size_up(size_t size) {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   265
  return align_up(size, os::vm_allocation_granularity());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
size_t ReservedSpace::allocation_align_size_down(size_t size) {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   270
  return align_down(size, os::vm_allocation_granularity());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
void ReservedSpace::release() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  if (is_reserved()) {
823
9a5271881bc0 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 1
diff changeset
   276
    char *real_base = _base - _noaccess_prefix;
9a5271881bc0 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 1
diff changeset
   277
    const size_t real_size = _size + _noaccess_prefix;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    if (special()) {
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   279
      if (_fd_for_heap != -1) {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   280
        os::unmap_memory(real_base, real_size);
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   281
      } else {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   282
        os::release_memory_special(real_base, real_size);
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   283
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    } else{
823
9a5271881bc0 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 1
diff changeset
   285
      os::release_memory(real_base, real_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    _base = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    _size = 0;
823
9a5271881bc0 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 1
diff changeset
   289
    _noaccess_prefix = 0;
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   290
    _alignment = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    _special = false;
2268
bea8be80ec88 6541756: Reduce executable C-heap
coleenp
parents: 2254
diff changeset
   292
    _executable = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   296
static size_t noaccess_prefix_size(size_t alignment) {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   297
  return lcm(os::vm_page_size(), alignment);
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   298
}
5898
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   299
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   300
void ReservedHeapSpace::establish_noaccess_prefix() {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   301
  assert(_alignment >= (size_t)os::vm_page_size(), "must be at least page size big");
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   302
  _noaccess_prefix = noaccess_prefix_size(_alignment);
823
9a5271881bc0 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 1
diff changeset
   303
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   304
  if (base() && base() + _size > (char *)OopEncodingHeapMax) {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   305
    if (true
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   306
        WIN64_ONLY(&& !UseLargePages)
42061
67176803a846 8168490: Use the LL/ULL suffixes to define 64-bit integer literals on Windows
simonis
parents: 39966
diff changeset
   307
        AIX_ONLY(&& os::vm_page_size() != 64*K)) {
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   308
      // Protect memory at the base of the allocated region.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   309
      // If special, the page was committed (only matters on windows)
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   310
      if (!os::protect_memory(_base, _noaccess_prefix, os::MEM_PROT_NONE, _special)) {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   311
        fatal("cannot protect protection page");
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   312
      }
37428
6e724f3d488b 8152896: Convert PrintCompressedOopsMode to Unified Logging
rprotacio
parents: 35898
diff changeset
   313
      log_debug(gc, heap, coops)("Protected page at the reserved heap base: "
6e724f3d488b 8152896: Convert PrintCompressedOopsMode to Unified Logging
rprotacio
parents: 35898
diff changeset
   314
                                 PTR_FORMAT " / " INTX_FORMAT " bytes",
6e724f3d488b 8152896: Convert PrintCompressedOopsMode to Unified Logging
rprotacio
parents: 35898
diff changeset
   315
                                 p2i(_base),
6e724f3d488b 8152896: Convert PrintCompressedOopsMode to Unified Logging
rprotacio
parents: 35898
diff changeset
   316
                                 _noaccess_prefix);
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   317
      assert(Universe::narrow_oop_use_implicit_null_checks() == true, "not initialized?");
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   318
    } else {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   319
      Universe::set_narrow_oop_use_implicit_null_checks(false);
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   320
    }
5898
7f882d601e07 6947341: JVM Crash running Oracle ATG CRMDemo
kvn
parents: 5547
diff changeset
   321
  }
823
9a5271881bc0 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 1
diff changeset
   322
9a5271881bc0 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 1
diff changeset
   323
  _base += _noaccess_prefix;
9a5271881bc0 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 1
diff changeset
   324
  _size -= _noaccess_prefix;
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   325
  assert(((uintptr_t)_base % _alignment == 0), "must be exactly of required alignment");
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   326
}
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   327
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   328
// Tries to allocate memory of size 'size' at address requested_address with alignment 'alignment'.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   329
// Does not check whether the reserved memory actually is at requested_address, as the memory returned
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   330
// might still fulfill the wishes of the caller.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   331
// Assures the memory is aligned to 'alignment'.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   332
// NOTE: If ReservedHeapSpace already points to some reserved memory this is freed, first.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   333
void ReservedHeapSpace::try_reserve_heap(size_t size,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   334
                                         size_t alignment,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   335
                                         bool large,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   336
                                         char* requested_address) {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   337
  if (_base != NULL) {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   338
    // We tried before, but we didn't like the address delivered.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   339
    release();
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   340
  }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   341
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   342
  // If OS doesn't support demand paging for large page memory, we need
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   343
  // to use reserve_memory_special() to reserve and pin the entire region.
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   344
  // If there is a backing file directory for this space then whether
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   345
  // large pages are allocated is up to the filesystem of the backing file.
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   346
  // So we ignore the UseLargePages flag in this case.
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   347
  bool special = large && !os::can_commit_large_page_memory();
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   348
  if (special && _fd_for_heap != -1) {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   349
    special = false;
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   350
    if (UseLargePages && (!FLAG_IS_DEFAULT(UseLargePages) ||
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   351
                          !FLAG_IS_DEFAULT(LargePageSizeInBytes))) {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   352
      log_debug(gc, heap)("Cannot allocate large pages for Java Heap when AllocateHeapAt option is set.");
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   353
    }
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   354
  }
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   355
  char* base = NULL;
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   356
37428
6e724f3d488b 8152896: Convert PrintCompressedOopsMode to Unified Logging
rprotacio
parents: 35898
diff changeset
   357
  log_trace(gc, heap, coops)("Trying to allocate at address " PTR_FORMAT
6e724f3d488b 8152896: Convert PrintCompressedOopsMode to Unified Logging
rprotacio
parents: 35898
diff changeset
   358
                             " heap of size " SIZE_FORMAT_HEX,
6e724f3d488b 8152896: Convert PrintCompressedOopsMode to Unified Logging
rprotacio
parents: 35898
diff changeset
   359
                             p2i(requested_address),
6e724f3d488b 8152896: Convert PrintCompressedOopsMode to Unified Logging
rprotacio
parents: 35898
diff changeset
   360
                             size);
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   361
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   362
  if (special) {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   363
    base = os::reserve_memory_special(size, alignment, requested_address, false);
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   364
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   365
    if (base != NULL) {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   366
      // Check alignment constraints.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   367
      assert((uintptr_t) base % alignment == 0,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31620
diff changeset
   368
             "Large pages returned a non-aligned address, base: "
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 33105
diff changeset
   369
             PTR_FORMAT " alignment: " SIZE_FORMAT_HEX,
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 33105
diff changeset
   370
             p2i(base), alignment);
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   371
      _special = true;
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   372
    }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   373
  }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   374
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   375
  if (base == NULL) {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   376
    // Failed; try to reserve regular memory below
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   377
    if (UseLargePages && (!FLAG_IS_DEFAULT(UseLargePages) ||
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   378
                          !FLAG_IS_DEFAULT(LargePageSizeInBytes))) {
37428
6e724f3d488b 8152896: Convert PrintCompressedOopsMode to Unified Logging
rprotacio
parents: 35898
diff changeset
   379
      log_debug(gc, heap, coops)("Reserve regular memory without large pages");
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   380
    }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   381
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   382
    // Optimistically assume that the OSes returns an aligned base pointer.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   383
    // When reserving a large address range, most OSes seem to align to at
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   384
    // least 64K.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   385
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   386
    // If the memory was requested at a particular address, use
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   387
    // os::attempt_reserve_memory_at() to avoid over mapping something
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   388
    // important.  If available space is not detected, return NULL.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   389
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   390
    if (requested_address != 0) {
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   391
      base = os::attempt_reserve_memory_at(size, requested_address, _fd_for_heap);
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   392
    } else {
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   393
      base = os::reserve_memory(size, NULL, alignment, _fd_for_heap);
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   394
    }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   395
  }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   396
  if (base == NULL) { return; }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   397
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   398
  // Done
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   399
  _base = base;
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   400
  _size = size;
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   401
  _alignment = alignment;
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   402
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   403
  // If heap is reserved with a backing file, the entire space has been committed. So set the _special flag to true
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   404
  if (_fd_for_heap != -1) {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   405
    _special = true;
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   406
  }
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   407
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   408
  // Check alignment constraints
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   409
  if ((((size_t)base) & (alignment - 1)) != 0) {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   410
    // Base not aligned, retry.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   411
    release();
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   412
  }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   413
}
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   414
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   415
void ReservedHeapSpace::try_reserve_range(char *highest_start,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   416
                                          char *lowest_start,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   417
                                          size_t attach_point_alignment,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   418
                                          char *aligned_heap_base_min_address,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   419
                                          char *upper_bound,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   420
                                          size_t size,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   421
                                          size_t alignment,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   422
                                          bool large) {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   423
  const size_t attach_range = highest_start - lowest_start;
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   424
  // Cap num_attempts at possible number.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   425
  // At least one is possible even for 0 sized attach range.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   426
  const uint64_t num_attempts_possible = (attach_range / attach_point_alignment) + 1;
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   427
  const uint64_t num_attempts_to_try   = MIN2((uint64_t)HeapSearchSteps, num_attempts_possible);
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   428
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   429
  const size_t stepsize = (attach_range == 0) ? // Only one try.
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   430
    (size_t) highest_start : align_up(attach_range / num_attempts_to_try, attach_point_alignment);
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   431
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   432
  // Try attach points from top to bottom.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   433
  char* attach_point = highest_start;
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   434
  while (attach_point >= lowest_start  &&
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   435
         attach_point <= highest_start &&  // Avoid wrap around.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   436
         ((_base == NULL) ||
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   437
          (_base < aligned_heap_base_min_address || _base + size > upper_bound))) {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   438
    try_reserve_heap(size, alignment, large, attach_point);
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   439
    attach_point -= stepsize;
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   440
  }
823
9a5271881bc0 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 1
diff changeset
   441
}
9a5271881bc0 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 1
diff changeset
   442
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   443
#define SIZE_64K  ((uint64_t) UCONST64(      0x10000))
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   444
#define SIZE_256M ((uint64_t) UCONST64(   0x10000000))
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   445
#define SIZE_32G  ((uint64_t) UCONST64(  0x800000000))
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   446
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   447
// Helper for heap allocation. Returns an array with addresses
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   448
// (OS-specific) which are suited for disjoint base mode. Array is
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   449
// NULL terminated.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   450
static char** get_attach_addresses_for_disjoint_mode() {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   451
  static uint64_t addresses[] = {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   452
     2 * SIZE_32G,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   453
     3 * SIZE_32G,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   454
     4 * SIZE_32G,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   455
     8 * SIZE_32G,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   456
    10 * SIZE_32G,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   457
     1 * SIZE_64K * SIZE_32G,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   458
     2 * SIZE_64K * SIZE_32G,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   459
     3 * SIZE_64K * SIZE_32G,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   460
     4 * SIZE_64K * SIZE_32G,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   461
    16 * SIZE_64K * SIZE_32G,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   462
    32 * SIZE_64K * SIZE_32G,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   463
    34 * SIZE_64K * SIZE_32G,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   464
    0
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   465
  };
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   466
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   467
  // Sort out addresses smaller than HeapBaseMinAddress. This assumes
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   468
  // the array is sorted.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   469
  uint i = 0;
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   470
  while (addresses[i] != 0 &&
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   471
         (addresses[i] < OopEncodingHeapMax || addresses[i] < HeapBaseMinAddress)) {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   472
    i++;
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   473
  }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   474
  uint start = i;
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   475
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   476
  // Avoid more steps than requested.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   477
  i = 0;
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   478
  while (addresses[start+i] != 0) {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   479
    if (i == HeapSearchSteps) {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   480
      addresses[start+i] = 0;
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   481
      break;
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   482
    }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   483
    i++;
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   484
  }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   485
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   486
  return (char**) &addresses[start];
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   487
}
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   488
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   489
void ReservedHeapSpace::initialize_compressed_heap(const size_t size, size_t alignment, bool large) {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   490
  guarantee(size + noaccess_prefix_size(alignment) <= OopEncodingHeapMax,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   491
            "can not allocate compressed oop heap for this size");
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   492
  guarantee(alignment == MAX2(alignment, (size_t)os::vm_page_size()), "alignment too small");
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   493
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   494
  const size_t granularity = os::vm_allocation_granularity();
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   495
  assert((size & (granularity - 1)) == 0,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   496
         "size not aligned to os::vm_allocation_granularity()");
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   497
  assert((alignment & (granularity - 1)) == 0,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   498
         "alignment not aligned to os::vm_allocation_granularity()");
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   499
  assert(alignment == 0 || is_power_of_2((intptr_t)alignment),
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   500
         "not a power of 2");
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   501
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   502
  // The necessary attach point alignment for generated wish addresses.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   503
  // This is needed to increase the chance of attaching for mmap and shmat.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   504
  const size_t os_attach_point_alignment =
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   505
    AIX_ONLY(SIZE_256M)  // Known shm boundary alignment.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   506
    NOT_AIX(os::vm_allocation_granularity());
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   507
  const size_t attach_point_alignment = lcm(alignment, os_attach_point_alignment);
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   508
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   509
  char *aligned_heap_base_min_address = (char *)align_up((void *)HeapBaseMinAddress, alignment);
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   510
  size_t noaccess_prefix = ((aligned_heap_base_min_address + size) > (char*)OopEncodingHeapMax) ?
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   511
    noaccess_prefix_size(alignment) : 0;
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   512
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   513
  // Attempt to alloc at user-given address.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   514
  if (!FLAG_IS_DEFAULT(HeapBaseMinAddress)) {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   515
    try_reserve_heap(size + noaccess_prefix, alignment, large, aligned_heap_base_min_address);
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   516
    if (_base != aligned_heap_base_min_address) { // Enforce this exact address.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   517
      release();
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   518
    }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   519
  }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   520
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   521
  // Keep heap at HeapBaseMinAddress.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   522
  if (_base == NULL) {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   523
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   524
    // Try to allocate the heap at addresses that allow efficient oop compression.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   525
    // Different schemes are tried, in order of decreasing optimization potential.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   526
    //
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   527
    // For this, try_reserve_heap() is called with the desired heap base addresses.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   528
    // A call into the os layer to allocate at a given address can return memory
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   529
    // at a different address than requested.  Still, this might be memory at a useful
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   530
    // address. try_reserve_heap() always returns this allocated memory, as only here
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   531
    // the criteria for a good heap are checked.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   532
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   533
    // Attempt to allocate so that we can run without base and scale (32-Bit unscaled compressed oops).
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   534
    // Give it several tries from top of range to bottom.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   535
    if (aligned_heap_base_min_address + size <= (char *)UnscaledOopHeapMax) {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   536
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   537
      // Calc address range within we try to attach (range of possible start addresses).
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   538
      char* const highest_start = align_down((char *)UnscaledOopHeapMax - size, attach_point_alignment);
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   539
      char* const lowest_start  = align_up(aligned_heap_base_min_address, attach_point_alignment);
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   540
      try_reserve_range(highest_start, lowest_start, attach_point_alignment,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   541
                        aligned_heap_base_min_address, (char *)UnscaledOopHeapMax, size, alignment, large);
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   542
    }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   543
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   544
    // zerobased: Attempt to allocate in the lower 32G.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   545
    // But leave room for the compressed class pointers, which is allocated above
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   546
    // the heap.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   547
    char *zerobased_max = (char *)OopEncodingHeapMax;
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   548
    const size_t class_space = align_up(CompressedClassSpaceSize, alignment);
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   549
    // For small heaps, save some space for compressed class pointer
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   550
    // space so it can be decoded with no base.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   551
    if (UseCompressedClassPointers && !UseSharedSpaces &&
28946
24261e03ba4c 8072434: 8064457: introduces performance regressions in 9-b47
goetz
parents: 28631
diff changeset
   552
        OopEncodingHeapMax <= KlassEncodingMetaspaceMax &&
24261e03ba4c 8072434: 8064457: introduces performance regressions in 9-b47
goetz
parents: 28631
diff changeset
   553
        (uint64_t)(aligned_heap_base_min_address + size + class_space) <= KlassEncodingMetaspaceMax) {
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   554
      zerobased_max = (char *)OopEncodingHeapMax - class_space;
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   555
    }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   556
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   557
    // Give it several tries from top of range to bottom.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   558
    if (aligned_heap_base_min_address + size <= zerobased_max &&    // Zerobased theoretical possible.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   559
        ((_base == NULL) ||                        // No previous try succeeded.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   560
         (_base + size > zerobased_max))) {        // Unscaled delivered an arbitrary address.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   561
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   562
      // Calc address range within we try to attach (range of possible start addresses).
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   563
      char *const highest_start = align_down(zerobased_max - size, attach_point_alignment);
29580
a67a581cfe11 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents: 28946
diff changeset
   564
      // Need to be careful about size being guaranteed to be less
a67a581cfe11 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents: 28946
diff changeset
   565
      // than UnscaledOopHeapMax due to type constraints.
a67a581cfe11 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents: 28946
diff changeset
   566
      char *lowest_start = aligned_heap_base_min_address;
a67a581cfe11 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents: 28946
diff changeset
   567
      uint64_t unscaled_end = UnscaledOopHeapMax - size;
a67a581cfe11 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents: 28946
diff changeset
   568
      if (unscaled_end < UnscaledOopHeapMax) { // unscaled_end wrapped if size is large
a67a581cfe11 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents: 28946
diff changeset
   569
        lowest_start = MAX2(lowest_start, (char*)unscaled_end);
a67a581cfe11 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents: 28946
diff changeset
   570
      }
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   571
      lowest_start = align_up(lowest_start, attach_point_alignment);
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   572
      try_reserve_range(highest_start, lowest_start, attach_point_alignment,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   573
                        aligned_heap_base_min_address, zerobased_max, size, alignment, large);
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   574
    }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   575
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   576
    // Now we go for heaps with base != 0.  We need a noaccess prefix to efficiently
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   577
    // implement null checks.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   578
    noaccess_prefix = noaccess_prefix_size(alignment);
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   579
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   580
    // Try to attach at addresses that are aligned to OopEncodingHeapMax. Disjointbase mode.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   581
    char** addresses = get_attach_addresses_for_disjoint_mode();
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   582
    int i = 0;
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   583
    while (addresses[i] &&                                 // End of array not yet reached.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   584
           ((_base == NULL) ||                             // No previous try succeeded.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   585
            (_base + size >  (char *)OopEncodingHeapMax && // Not zerobased or unscaled address.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   586
             !Universe::is_disjoint_heap_base_address((address)_base)))) {  // Not disjoint address.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   587
      char* const attach_point = addresses[i];
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   588
      assert(attach_point >= aligned_heap_base_min_address, "Flag support broken");
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   589
      try_reserve_heap(size + noaccess_prefix, alignment, large, attach_point);
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   590
      i++;
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   591
    }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   592
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   593
    // Last, desperate try without any placement.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   594
    if (_base == NULL) {
37428
6e724f3d488b 8152896: Convert PrintCompressedOopsMode to Unified Logging
rprotacio
parents: 35898
diff changeset
   595
      log_trace(gc, heap, coops)("Trying to allocate at address NULL heap of size " SIZE_FORMAT_HEX, size + noaccess_prefix);
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   596
      initialize(size + noaccess_prefix, alignment, large, NULL, false);
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   597
    }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   598
  }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   599
}
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   600
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   601
ReservedHeapSpace::ReservedHeapSpace(size_t size, size_t alignment, bool large, const char* heap_allocation_directory) : ReservedSpace() {
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   602
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   603
  if (size == 0) {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   604
    return;
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   605
  }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   606
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   607
  if (heap_allocation_directory != NULL) {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   608
    _fd_for_heap = os::create_file_for_heap(heap_allocation_directory);
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   609
    if (_fd_for_heap == -1) {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   610
      vm_exit_during_initialization(
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   611
        err_msg("Could not create file for Heap at location %s", heap_allocation_directory));
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   612
    }
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   613
  }
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   614
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   615
  // Heap size should be aligned to alignment, too.
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   616
  guarantee(is_aligned(size, alignment), "set by caller");
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   617
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   618
  if (UseCompressedOops) {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   619
    initialize_compressed_heap(size, alignment, large);
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   620
    if (_size > size) {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   621
      // We allocated heap with noaccess prefix.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   622
      // It can happen we get a zerobased/unscaled heap with noaccess prefix,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   623
      // if we had to try at arbitrary address.
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   624
      establish_noaccess_prefix();
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   625
    }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   626
  } else {
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   627
    initialize(size, alignment, large, NULL, false);
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   628
  }
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   629
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   630
  assert(markOopDesc::encode_pointer_as_mark(_base)->decode_pointer() == _base,
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   631
         "area must be distinguishable from marks for mark-sweep");
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   632
  assert(markOopDesc::encode_pointer_as_mark(&_base[size])->decode_pointer() == &_base[size],
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   633
         "area must be distinguishable from marks for mark-sweep");
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
   634
46983
1c9cefa2a443 8174050: Compilation errors with clang-4.0
martin
parents: 46625
diff changeset
   635
  if (base() != NULL) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11778
diff changeset
   636
    MemTracker::record_virtual_memory_type((address)base(), mtJavaHeap);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11778
diff changeset
   637
  }
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   638
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   639
  if (_fd_for_heap != -1) {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   640
    os::close(_fd_for_heap);
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents: 47216
diff changeset
   641
  }
823
9a5271881bc0 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 1
diff changeset
   642
}
9a5271881bc0 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 1
diff changeset
   643
2268
bea8be80ec88 6541756: Reduce executable C-heap
coleenp
parents: 2254
diff changeset
   644
// Reserve space for code segment.  Same as Java heap only we mark this as
bea8be80ec88 6541756: Reduce executable C-heap
coleenp
parents: 2254
diff changeset
   645
// executable.
bea8be80ec88 6541756: Reduce executable C-heap
coleenp
parents: 2254
diff changeset
   646
ReservedCodeSpace::ReservedCodeSpace(size_t r_size,
bea8be80ec88 6541756: Reduce executable C-heap
coleenp
parents: 2254
diff changeset
   647
                                     size_t rs_align,
bea8be80ec88 6541756: Reduce executable C-heap
coleenp
parents: 2254
diff changeset
   648
                                     bool large) :
42664
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents: 42061
diff changeset
   649
  ReservedSpace(r_size, rs_align, large, /*executable*/ true) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11778
diff changeset
   650
  MemTracker::record_virtual_memory_type((address)base(), mtCode);
2268
bea8be80ec88 6541756: Reduce executable C-heap
coleenp
parents: 2254
diff changeset
   651
}
bea8be80ec88 6541756: Reduce executable C-heap
coleenp
parents: 2254
diff changeset
   652
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
// VirtualSpace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
VirtualSpace::VirtualSpace() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
  _low_boundary           = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
  _high_boundary          = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
  _low                    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
  _high                   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
  _lower_high             = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
  _middle_high            = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  _upper_high             = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
  _lower_high_boundary    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
  _middle_high_boundary   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
  _upper_high_boundary    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
  _lower_alignment        = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
  _middle_alignment       = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
  _upper_alignment        = 0;
823
9a5271881bc0 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 1
diff changeset
   669
  _special                = false;
2268
bea8be80ec88 6541756: Reduce executable C-heap
coleenp
parents: 2254
diff changeset
   670
  _executable             = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
bool VirtualSpace::initialize(ReservedSpace rs, size_t committed_size) {
28631
a56cae1b428d 8066875: VirtualSpace does not use large pages
ehelin
parents: 28372
diff changeset
   675
  const size_t max_commit_granularity = os::page_size_for_region_unaligned(rs.size(), 1);
20402
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
   676
  return initialize_with_granularity(rs, committed_size, max_commit_granularity);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
   677
}
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
   678
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
   679
bool VirtualSpace::initialize_with_granularity(ReservedSpace rs, size_t committed_size, size_t max_commit_granularity) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
  if(!rs.is_reserved()) return false;  // allocation failed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
  assert(_low_boundary == NULL, "VirtualSpace already initialized");
20402
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
   682
  assert(max_commit_granularity > 0, "Granularity must be non-zero.");
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
   683
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
  _low_boundary  = rs.base();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
  _high_boundary = low_boundary() + rs.size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
  _low = low_boundary();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
  _high = low();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
  _special = rs.special();
2268
bea8be80ec88 6541756: Reduce executable C-heap
coleenp
parents: 2254
diff changeset
   691
  _executable = rs.executable();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
  // When a VirtualSpace begins life at a large size, make all future expansion
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
  // and shrinking occur aligned to a granularity of large pages.  This avoids
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
  // fragmentation of physical addresses that inhibits the use of large pages
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
  // by the OS virtual memory system.  Empirically,  we see that with a 4MB
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
  // page size, the only spaces that get handled this way are codecache and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
  // the heap itself, both of which provide a substantial performance
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
  // boost in many benchmarks when covered by large pages.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
  // No attempt is made to force large page alignment at the very top and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
  // bottom of the space if they are not aligned so already.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
  _lower_alignment  = os::vm_page_size();
20402
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
   704
  _middle_alignment = max_commit_granularity;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
  _upper_alignment  = os::vm_page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
  // End of each region
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46619
diff changeset
   708
  _lower_high_boundary = align_up(low_boundary(), middle_alignment());
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46619
diff changeset
   709
  _middle_high_boundary = align_down(high_boundary(), middle_alignment());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
  _upper_high_boundary = high_boundary();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
  // High address of each region
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
  _lower_high = low_boundary();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
  _middle_high = lower_high_boundary();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
  _upper_high = middle_high_boundary();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
  // commit to initial size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
  if (committed_size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
    if (!expand_by(committed_size)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
VirtualSpace::~VirtualSpace() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
  release();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
void VirtualSpace::release() {
39966
43c7f35b800e 8160897: Concurrent mark mark stack memory allocation leaks memory
tschatzl
parents: 38009
diff changeset
   733
  // This does not release memory it reserved.
823
9a5271881bc0 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 1
diff changeset
   734
  // Caller must release via rs.release();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
  _low_boundary           = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
  _high_boundary          = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
  _low                    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
  _high                   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  _lower_high             = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
  _middle_high            = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
  _upper_high             = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
  _lower_high_boundary    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
  _middle_high_boundary   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
  _upper_high_boundary    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
  _lower_alignment        = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
  _middle_alignment       = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
  _upper_alignment        = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
  _special                = false;
2268
bea8be80ec88 6541756: Reduce executable C-heap
coleenp
parents: 2254
diff changeset
   749
  _executable             = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
size_t VirtualSpace::committed_size() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
  return pointer_delta(high(), low(), sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
size_t VirtualSpace::reserved_size() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
  return pointer_delta(high_boundary(), low_boundary(), sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
size_t VirtualSpace::uncommitted_size()  const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
  return reserved_size() - committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   767
size_t VirtualSpace::actual_committed_size() const {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   768
  // Special VirtualSpaces commit all reserved space up front.
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   769
  if (special()) {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   770
    return reserved_size();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   771
  }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   772
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   773
  size_t committed_low    = pointer_delta(_lower_high,  _low_boundary,         sizeof(char));
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   774
  size_t committed_middle = pointer_delta(_middle_high, _lower_high_boundary,  sizeof(char));
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   775
  size_t committed_high   = pointer_delta(_upper_high,  _middle_high_boundary, sizeof(char));
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   776
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   777
#ifdef ASSERT
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   778
  size_t lower  = pointer_delta(_lower_high_boundary,  _low_boundary,         sizeof(char));
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   779
  size_t middle = pointer_delta(_middle_high_boundary, _lower_high_boundary,  sizeof(char));
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   780
  size_t upper  = pointer_delta(_upper_high_boundary,  _middle_high_boundary, sizeof(char));
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   781
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   782
  if (committed_high > 0) {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   783
    assert(committed_low == lower, "Must be");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   784
    assert(committed_middle == middle, "Must be");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   785
  }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   786
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   787
  if (committed_middle > 0) {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   788
    assert(committed_low == lower, "Must be");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   789
  }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   790
  if (committed_middle < middle) {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   791
    assert(committed_high == 0, "Must be");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   792
  }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   793
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   794
  if (committed_low < lower) {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   795
    assert(committed_high == 0, "Must be");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   796
    assert(committed_middle == 0, "Must be");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   797
  }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   798
#endif
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   799
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   800
  return committed_low + committed_middle + committed_high;
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   801
}
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
   802
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
bool VirtualSpace::contains(const void* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
  return low() <= (const char*) p && (const char*) p < high();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
37984
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   808
static void pretouch_expanded_memory(void* start, void* end) {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   809
  assert(is_aligned(start, os::vm_page_size()), "Unexpected alignment");
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   810
  assert(is_aligned(end,   os::vm_page_size()), "Unexpected alignment");
37984
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   811
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   812
  os::pretouch_memory(start, end);
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   813
}
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   814
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   815
static bool commit_expanded(char* start, size_t size, size_t alignment, bool pre_touch, bool executable) {
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   816
  if (os::commit_memory(start, size, alignment, executable)) {
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   817
    if (pre_touch || AlwaysPreTouch) {
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   818
      pretouch_expanded_memory(start, start + size);
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   819
    }
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   820
    return true;
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   821
  }
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   822
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   823
  debug_only(warning(
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   824
      "INFO: os::commit_memory(" PTR_FORMAT ", " PTR_FORMAT
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   825
      " size=" SIZE_FORMAT ", executable=%d) failed",
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   826
      p2i(start), p2i(start + size), size, executable);)
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   827
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   828
  return false;
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   829
}
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   830
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
   First we need to determine if a particular virtual space is using large
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
   pages.  This is done at the initialize function and only virtual spaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
   that are larger than LargePageSizeInBytes use large pages.  Once we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
   have determined this, all expand_by and shrink_by calls must grow and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
   shrink by large page size chunks.  If a particular request
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
   is within the current large page, the call to commit and uncommit memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
   can be ignored.  In the case that the low and high boundaries of this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
   space is not large page aligned, the pages leading to the first large
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
   page address and the pages after the last large page address must be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
   allocated with default pages.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
*/
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
bool VirtualSpace::expand_by(size_t bytes, bool pre_touch) {
37984
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   844
  if (uncommitted_size() < bytes) {
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   845
    return false;
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   846
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
  if (special()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
    // don't commit memory if the entire space is pinned in memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
    _high += bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
  char* previous_high = high();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
  char* unaligned_new_high = high() + bytes;
37984
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   856
  assert(unaligned_new_high <= high_boundary(), "cannot expand by more than upper boundary");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
  // Calculate where the new high for each of the regions should be.  If
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
  // the low_boundary() and high_boundary() are LargePageSizeInBytes aligned
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
  // then the unaligned lower and upper new highs would be the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
  // lower_high() and upper_high() respectively.
37984
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   862
  char* unaligned_lower_new_high =  MIN2(unaligned_new_high, lower_high_boundary());
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   863
  char* unaligned_middle_new_high = MIN2(unaligned_new_high, middle_high_boundary());
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   864
  char* unaligned_upper_new_high =  MIN2(unaligned_new_high, upper_high_boundary());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
  // Align the new highs based on the regions alignment.  lower and upper
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
  // alignment will always be default page size.  middle alignment will be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
  // LargePageSizeInBytes if the actual size of the virtual space is in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
  // fact larger than LargePageSizeInBytes.
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46619
diff changeset
   870
  char* aligned_lower_new_high =  align_up(unaligned_lower_new_high, lower_alignment());
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46619
diff changeset
   871
  char* aligned_middle_new_high = align_up(unaligned_middle_new_high, middle_alignment());
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46619
diff changeset
   872
  char* aligned_upper_new_high =  align_up(unaligned_upper_new_high, upper_alignment());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
  // Determine which regions need to grow in this expand_by call.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
  // If you are growing in the lower region, high() must be in that
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 20402
diff changeset
   876
  // region so calculate the size based on high().  For the middle and
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
  // upper regions, determine the starting point of growth based on the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
  // location of high().  By getting the MAX of the region's low address
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 20402
diff changeset
   879
  // (or the previous region's high address) and high(), we can tell if it
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
  // is an intra or inter region growth.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
  size_t lower_needs = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
  if (aligned_lower_new_high > lower_high()) {
37984
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   883
    lower_needs = pointer_delta(aligned_lower_new_high, lower_high(), sizeof(char));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
  size_t middle_needs = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
  if (aligned_middle_new_high > middle_high()) {
37984
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   887
    middle_needs = pointer_delta(aligned_middle_new_high, middle_high(), sizeof(char));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
  size_t upper_needs = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
  if (aligned_upper_new_high > upper_high()) {
37984
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   891
    upper_needs = pointer_delta(aligned_upper_new_high, upper_high(), sizeof(char));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
  // Check contiguity.
37984
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   895
  assert(low_boundary() <= lower_high() && lower_high() <= lower_high_boundary(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
         "high address must be contained within the region");
37984
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   897
  assert(lower_high_boundary() <= middle_high() && middle_high() <= middle_high_boundary(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
         "high address must be contained within the region");
37984
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   899
  assert(middle_high_boundary() <= upper_high() && upper_high() <= upper_high_boundary(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
         "high address must be contained within the region");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
  // Commit regions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
  if (lower_needs > 0) {
37984
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   904
    assert(lower_high() + lower_needs <= lower_high_boundary(), "must not expand beyond region");
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   905
    if (!commit_expanded(lower_high(), lower_needs, _lower_alignment, pre_touch, _executable)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
      return false;
18069
e6d4971c8650 8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents: 17113
diff changeset
   907
    }
37984
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   908
    _lower_high += lower_needs;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
  }
37984
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   910
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
  if (middle_needs > 0) {
37984
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   912
    assert(middle_high() + middle_needs <= middle_high_boundary(), "must not expand beyond region");
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   913
    if (!commit_expanded(middle_high(), middle_needs, _middle_alignment, pre_touch, _executable)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
    _middle_high += middle_needs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
  }
37984
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   918
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
  if (upper_needs > 0) {
37984
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   920
    assert(upper_high() + upper_needs <= upper_high_boundary(), "must not expand beyond region");
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   921
    if (!commit_expanded(upper_high(), upper_needs, _upper_alignment, pre_touch, _executable)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
    }
37984
5e9b81de0fce 8067785: Using AlwaysPreTouch does not always touch all pages
stefank
parents: 37428
diff changeset
   924
    _upper_high += upper_needs;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
  _high += bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
// A page is uncommitted if the contents of the entire page is deemed unusable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
// Continue to decrement the high() pointer until it reaches a page boundary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
// in which case that particular page can now be uncommitted.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
void VirtualSpace::shrink_by(size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
  if (committed_size() < size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
    fatal("Cannot shrink virtual space to negative size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
  if (special()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
    // don't uncommit if the entire space is pinned in memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
    _high -= size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
  char* unaligned_new_high = high() - size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
  assert(unaligned_new_high >= low_boundary(), "cannot shrink past lower boundary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
  // Calculate new unaligned address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
  char* unaligned_upper_new_high =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
    MAX2(unaligned_new_high, middle_high_boundary());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
  char* unaligned_middle_new_high =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
    MAX2(unaligned_new_high, lower_high_boundary());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
  char* unaligned_lower_new_high =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
    MAX2(unaligned_new_high, low_boundary());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
  // Align address to region's alignment
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46619
diff changeset
   956
  char* aligned_upper_new_high =  align_up(unaligned_upper_new_high, upper_alignment());
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46619
diff changeset
   957
  char* aligned_middle_new_high = align_up(unaligned_middle_new_high, middle_alignment());
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46619
diff changeset
   958
  char* aligned_lower_new_high =  align_up(unaligned_lower_new_high, lower_alignment());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
  // Determine which regions need to shrink
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
  size_t upper_needs = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
  if (aligned_upper_new_high < upper_high()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
    upper_needs =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
      pointer_delta(upper_high(), aligned_upper_new_high, sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
  size_t middle_needs = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
  if (aligned_middle_new_high < middle_high()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
    middle_needs =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
      pointer_delta(middle_high(), aligned_middle_new_high, sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
  size_t lower_needs = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
  if (aligned_lower_new_high < lower_high()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
    lower_needs =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
      pointer_delta(lower_high(), aligned_lower_new_high, sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
  // Check contiguity.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
  assert(middle_high_boundary() <= upper_high() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
         upper_high() <= upper_high_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
         "high address must be contained within the region");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
  assert(lower_high_boundary() <= middle_high() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
         middle_high() <= middle_high_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
         "high address must be contained within the region");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
  assert(low_boundary() <= lower_high() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
         lower_high() <= lower_high_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
         "high address must be contained within the region");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
  // Uncommit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
  if (upper_needs > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
    assert(middle_high_boundary() <= aligned_upper_new_high &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
           aligned_upper_new_high + upper_needs <= upper_high_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
           "must not shrink beyond region");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
    if (!os::uncommit_memory(aligned_upper_new_high, upper_needs)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
      debug_only(warning("os::uncommit_memory failed"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
      _upper_high -= upper_needs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
  if (middle_needs > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
    assert(lower_high_boundary() <= aligned_middle_new_high &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
           aligned_middle_new_high + middle_needs <= middle_high_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
           "must not shrink beyond region");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
    if (!os::uncommit_memory(aligned_middle_new_high, middle_needs)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
      debug_only(warning("os::uncommit_memory failed"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
      _middle_high -= middle_needs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
  if (lower_needs > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
    assert(low_boundary() <= aligned_lower_new_high &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
           aligned_lower_new_high + lower_needs <= lower_high_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
           "must not shrink beyond region");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
    if (!os::uncommit_memory(aligned_lower_new_high, lower_needs)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
      debug_only(warning("os::uncommit_memory failed"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
      _lower_high -= lower_needs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
  _high -= size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
void VirtualSpace::check_for_contiguity() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
  // Check contiguity.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
  assert(low_boundary() <= lower_high() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
         lower_high() <= lower_high_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
         "high address must be contained within the region");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
  assert(lower_high_boundary() <= middle_high() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
         middle_high() <= middle_high_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
         "high address must be contained within the region");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
  assert(middle_high_boundary() <= upper_high() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
         upper_high() <= upper_high_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
         "high address must be contained within the region");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
  assert(low() >= low_boundary(), "low");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
  assert(low_boundary() <= lower_high_boundary(), "lower high boundary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
  assert(upper_high_boundary() <= high_boundary(), "upper high boundary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
  assert(high() <= upper_high(), "upper high");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
19993
b1d392324718 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 19989
diff changeset
  1044
void VirtualSpace::print_on(outputStream* out) {
b1d392324718 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 19989
diff changeset
  1045
  out->print   ("Virtual space:");
b1d392324718 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 19989
diff changeset
  1046
  if (special()) out->print(" (pinned in memory)");
b1d392324718 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 19989
diff changeset
  1047
  out->cr();
b1d392324718 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 19989
diff changeset
  1048
  out->print_cr(" - committed: " SIZE_FORMAT, committed_size());
b1d392324718 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 19989
diff changeset
  1049
  out->print_cr(" - reserved:  " SIZE_FORMAT, reserved_size());
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 33105
diff changeset
  1050
  out->print_cr(" - [low, high]:     [" INTPTR_FORMAT ", " INTPTR_FORMAT "]",  p2i(low()), p2i(high()));
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 33105
diff changeset
  1051
  out->print_cr(" - [low_b, high_b]: [" INTPTR_FORMAT ", " INTPTR_FORMAT "]",  p2i(low_boundary()), p2i(high_boundary()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
19993
b1d392324718 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 19989
diff changeset
  1054
void VirtualSpace::print() {
b1d392324718 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 19989
diff changeset
  1055
  print_on(tty);
b1d392324718 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 19989
diff changeset
  1056
}
19546
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1057
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1058
/////////////// Unit tests ///////////////
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1059
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1060
#ifndef PRODUCT
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1061
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1062
#define test_log(...) \
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1063
  do {\
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1064
    if (VerboseInternalVMTests) { \
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1065
      tty->print_cr(__VA_ARGS__); \
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1066
      tty->flush(); \
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1067
    }\
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1068
  } while (false)
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1069
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1070
class TestReservedSpace : AllStatic {
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1071
 public:
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1072
  static void small_page_write(void* addr, size_t size) {
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1073
    size_t page_size = os::vm_page_size();
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1074
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1075
    char* end = (char*)addr + size;
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1076
    for (char* p = (char*)addr; p < end; p += page_size) {
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1077
      *p = 1;
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1078
    }
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1079
  }
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1080
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1081
  static void release_memory_for_test(ReservedSpace rs) {
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1082
    if (rs.special()) {
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1083
      guarantee(os::release_memory_special(rs.base(), rs.size()), "Shouldn't fail");
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1084
    } else {
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1085
      guarantee(os::release_memory(rs.base(), rs.size()), "Shouldn't fail");
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1086
    }
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1087
  }
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1088
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1089
  static void test_reserved_space1(size_t size, size_t alignment) {
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1090
    test_log("test_reserved_space1(%p)", (void*) (uintptr_t) size);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1091
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  1092
    assert(is_aligned(size, alignment), "Incorrect input parameters");
19546
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1093
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1094
    ReservedSpace rs(size,          // size
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1095
                     alignment,     // alignment
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1096
                     UseLargePages, // large
28372
ce0aad4b8c44 8064457: Introduce compressed oops mode disjoint base and improve compressed heap handling.
goetz
parents: 28208
diff changeset
  1097
                     (char *)NULL); // requested_address
19546
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1098
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1099
    test_log(" rs.special() == %d", rs.special());
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1100
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1101
    assert(rs.base() != NULL, "Must be");
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1102
    assert(rs.size() == size, "Must be");
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1103
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  1104
    assert(is_aligned(rs.base(), alignment), "aligned sizes should always give aligned addresses");
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  1105
    assert(is_aligned(rs.size(), alignment), "aligned sizes should always give aligned addresses");
19546
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1106
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1107
    if (rs.special()) {
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1108
      small_page_write(rs.base(), size);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1109
    }
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1110
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1111
    release_memory_for_test(rs);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1112
  }
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1113
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1114
  static void test_reserved_space2(size_t size) {
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1115
    test_log("test_reserved_space2(%p)", (void*)(uintptr_t)size);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1116
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  1117
    assert(is_aligned(size, os::vm_allocation_granularity()), "Must be at least AG aligned");
19546
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1118
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1119
    ReservedSpace rs(size);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1120
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1121
    test_log(" rs.special() == %d", rs.special());
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1122
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1123
    assert(rs.base() != NULL, "Must be");
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1124
    assert(rs.size() == size, "Must be");
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1125
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1126
    if (rs.special()) {
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1127
      small_page_write(rs.base(), size);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1128
    }
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1129
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1130
    release_memory_for_test(rs);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1131
  }
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1132
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1133
  static void test_reserved_space3(size_t size, size_t alignment, bool maybe_large) {
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1134
    test_log("test_reserved_space3(%p, %p, %d)",
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1135
        (void*)(uintptr_t)size, (void*)(uintptr_t)alignment, maybe_large);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1136
38009
290ae73980f7 8053885: test/runtime/memory/RunUnitTestsConcurrently.java fails on solaris with largepage options
stefank
parents: 37984
diff changeset
  1137
    if (size < alignment) {
290ae73980f7 8053885: test/runtime/memory/RunUnitTestsConcurrently.java fails on solaris with largepage options
stefank
parents: 37984
diff changeset
  1138
      // Tests might set -XX:LargePageSizeInBytes=<small pages> and cause unexpected input arguments for this test.
290ae73980f7 8053885: test/runtime/memory/RunUnitTestsConcurrently.java fails on solaris with largepage options
stefank
parents: 37984
diff changeset
  1139
      assert((size_t)os::vm_page_size() == os::large_page_size(), "Test needs further refinement");
290ae73980f7 8053885: test/runtime/memory/RunUnitTestsConcurrently.java fails on solaris with largepage options
stefank
parents: 37984
diff changeset
  1140
      return;
290ae73980f7 8053885: test/runtime/memory/RunUnitTestsConcurrently.java fails on solaris with largepage options
stefank
parents: 37984
diff changeset
  1141
    }
290ae73980f7 8053885: test/runtime/memory/RunUnitTestsConcurrently.java fails on solaris with largepage options
stefank
parents: 37984
diff changeset
  1142
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  1143
    assert(is_aligned(size, os::vm_allocation_granularity()), "Must be at least AG aligned");
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  1144
    assert(is_aligned(size, alignment), "Must be at least aligned against alignment");
19546
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1145
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1146
    bool large = maybe_large && UseLargePages && size >= os::large_page_size();
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1147
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1148
    ReservedSpace rs(size, alignment, large, false);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1149
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1150
    test_log(" rs.special() == %d", rs.special());
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1151
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1152
    assert(rs.base() != NULL, "Must be");
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1153
    assert(rs.size() == size, "Must be");
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1154
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1155
    if (rs.special()) {
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1156
      small_page_write(rs.base(), size);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1157
    }
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1158
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1159
    release_memory_for_test(rs);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1160
  }
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1161
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1162
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1163
  static void test_reserved_space1() {
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1164
    size_t size = 2 * 1024 * 1024;
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1165
    size_t ag   = os::vm_allocation_granularity();
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1166
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1167
    test_reserved_space1(size,      ag);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1168
    test_reserved_space1(size * 2,  ag);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1169
    test_reserved_space1(size * 10, ag);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1170
  }
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1171
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1172
  static void test_reserved_space2() {
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1173
    size_t size = 2 * 1024 * 1024;
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1174
    size_t ag = os::vm_allocation_granularity();
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1175
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1176
    test_reserved_space2(size * 1);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1177
    test_reserved_space2(size * 2);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1178
    test_reserved_space2(size * 10);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1179
    test_reserved_space2(ag);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1180
    test_reserved_space2(size - ag);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1181
    test_reserved_space2(size);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1182
    test_reserved_space2(size + ag);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1183
    test_reserved_space2(size * 2);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1184
    test_reserved_space2(size * 2 - ag);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1185
    test_reserved_space2(size * 2 + ag);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1186
    test_reserved_space2(size * 3);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1187
    test_reserved_space2(size * 3 - ag);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1188
    test_reserved_space2(size * 3 + ag);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1189
    test_reserved_space2(size * 10);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1190
    test_reserved_space2(size * 10 + size / 2);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1191
  }
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1192
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1193
  static void test_reserved_space3() {
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1194
    size_t ag = os::vm_allocation_granularity();
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1195
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1196
    test_reserved_space3(ag,      ag    , false);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1197
    test_reserved_space3(ag * 2,  ag    , false);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1198
    test_reserved_space3(ag * 3,  ag    , false);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1199
    test_reserved_space3(ag * 2,  ag * 2, false);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1200
    test_reserved_space3(ag * 4,  ag * 2, false);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1201
    test_reserved_space3(ag * 8,  ag * 2, false);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1202
    test_reserved_space3(ag * 4,  ag * 4, false);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1203
    test_reserved_space3(ag * 8,  ag * 4, false);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1204
    test_reserved_space3(ag * 16, ag * 4, false);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1205
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1206
    if (UseLargePages) {
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1207
      size_t lp = os::large_page_size();
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1208
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1209
      // Without large pages
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1210
      test_reserved_space3(lp,     ag * 4, false);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1211
      test_reserved_space3(lp * 2, ag * 4, false);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1212
      test_reserved_space3(lp * 4, ag * 4, false);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1213
      test_reserved_space3(lp,     lp    , false);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1214
      test_reserved_space3(lp * 2, lp    , false);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1215
      test_reserved_space3(lp * 3, lp    , false);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1216
      test_reserved_space3(lp * 2, lp * 2, false);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1217
      test_reserved_space3(lp * 4, lp * 2, false);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1218
      test_reserved_space3(lp * 8, lp * 2, false);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1219
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1220
      // With large pages
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1221
      test_reserved_space3(lp, ag * 4    , true);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1222
      test_reserved_space3(lp * 2, ag * 4, true);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1223
      test_reserved_space3(lp * 4, ag * 4, true);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1224
      test_reserved_space3(lp, lp        , true);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1225
      test_reserved_space3(lp * 2, lp    , true);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1226
      test_reserved_space3(lp * 3, lp    , true);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1227
      test_reserved_space3(lp * 2, lp * 2, true);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1228
      test_reserved_space3(lp * 4, lp * 2, true);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1229
      test_reserved_space3(lp * 8, lp * 2, true);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1230
    }
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1231
  }
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1232
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1233
  static void test_reserved_space() {
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1234
    test_reserved_space1();
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1235
    test_reserved_space2();
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1236
    test_reserved_space3();
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1237
  }
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1238
};
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1239
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1240
void TestReservedSpace_test() {
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1241
  TestReservedSpace::test_reserved_space();
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1242
}
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1243
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31620
diff changeset
  1244
#define assert_equals(actual, expected)  \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31620
diff changeset
  1245
  assert(actual == expected,             \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31620
diff changeset
  1246
         "Got " SIZE_FORMAT " expected " \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31620
diff changeset
  1247
         SIZE_FORMAT, actual, expected);
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1248
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1249
#define assert_ge(value1, value2)                  \
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1250
  assert(value1 >= value2,                         \
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31620
diff changeset
  1251
         "'" #value1 "': " SIZE_FORMAT " '"        \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31620
diff changeset
  1252
         #value2 "': " SIZE_FORMAT, value1, value2);
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1253
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1254
#define assert_lt(value1, value2)                  \
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1255
  assert(value1 < value2,                          \
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31620
diff changeset
  1256
         "'" #value1 "': " SIZE_FORMAT " '"        \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31620
diff changeset
  1257
         #value2 "': " SIZE_FORMAT, value1, value2);
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1258
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1259
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1260
class TestVirtualSpace : AllStatic {
20402
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1261
  enum TestLargePages {
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1262
    Default,
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1263
    Disable,
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1264
    Reserve,
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1265
    Commit
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1266
  };
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1267
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1268
  static ReservedSpace reserve_memory(size_t reserve_size_aligned, TestLargePages mode) {
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1269
    switch(mode) {
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1270
    default:
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1271
    case Default:
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1272
    case Reserve:
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1273
      return ReservedSpace(reserve_size_aligned);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1274
    case Disable:
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1275
    case Commit:
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1276
      return ReservedSpace(reserve_size_aligned,
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1277
                           os::vm_allocation_granularity(),
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1278
                           /* large */ false, /* exec */ false);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1279
    }
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1280
  }
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1281
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1282
  static bool initialize_virtual_space(VirtualSpace& vs, ReservedSpace rs, TestLargePages mode) {
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1283
    switch(mode) {
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1284
    default:
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1285
    case Default:
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1286
    case Reserve:
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1287
      return vs.initialize(rs, 0);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1288
    case Disable:
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1289
      return vs.initialize_with_granularity(rs, 0, os::vm_page_size());
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1290
    case Commit:
28631
a56cae1b428d 8066875: VirtualSpace does not use large pages
ehelin
parents: 28372
diff changeset
  1291
      return vs.initialize_with_granularity(rs, 0, os::page_size_for_region_unaligned(rs.size(), 1));
20402
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1292
    }
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1293
  }
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1294
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1295
 public:
20402
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1296
  static void test_virtual_space_actual_committed_space(size_t reserve_size, size_t commit_size,
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1297
                                                        TestLargePages mode = Default) {
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1298
    size_t granularity = os::vm_allocation_granularity();
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  1299
    size_t reserve_size_aligned = align_up(reserve_size, granularity);
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1300
20402
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1301
    ReservedSpace reserved = reserve_memory(reserve_size_aligned, mode);
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1302
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1303
    assert(reserved.is_reserved(), "Must be");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1304
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1305
    VirtualSpace vs;
20402
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1306
    bool initialized = initialize_virtual_space(vs, reserved, mode);
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1307
    assert(initialized, "Failed to initialize VirtualSpace");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1308
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1309
    vs.expand_by(commit_size, false);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1310
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1311
    if (vs.special()) {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1312
      assert_equals(vs.actual_committed_size(), reserve_size_aligned);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1313
    } else {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1314
      assert_ge(vs.actual_committed_size(), commit_size);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1315
      // Approximate the commit granularity.
20402
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1316
      // Make sure that we don't commit using large pages
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1317
      // if large pages has been disabled for this VirtualSpace.
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1318
      size_t commit_granularity = (mode == Disable || !UseLargePages) ?
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1319
                                   os::vm_page_size() : os::large_page_size();
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1320
      assert_lt(vs.actual_committed_size(), commit_size + commit_granularity);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1321
    }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1322
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1323
    reserved.release();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1324
  }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1325
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1326
  static void test_virtual_space_actual_committed_space_one_large_page() {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1327
    if (!UseLargePages) {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1328
      return;
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1329
    }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1330
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1331
    size_t large_page_size = os::large_page_size();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1332
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1333
    ReservedSpace reserved(large_page_size, large_page_size, true, false);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1334
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1335
    assert(reserved.is_reserved(), "Must be");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1336
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1337
    VirtualSpace vs;
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1338
    bool initialized = vs.initialize(reserved, 0);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1339
    assert(initialized, "Failed to initialize VirtualSpace");
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1340
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1341
    vs.expand_by(large_page_size, false);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1342
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1343
    assert_equals(vs.actual_committed_size(), large_page_size);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1344
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1345
    reserved.release();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1346
  }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1347
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1348
  static void test_virtual_space_actual_committed_space() {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1349
    test_virtual_space_actual_committed_space(4 * K, 0);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1350
    test_virtual_space_actual_committed_space(4 * K, 4 * K);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1351
    test_virtual_space_actual_committed_space(8 * K, 0);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1352
    test_virtual_space_actual_committed_space(8 * K, 4 * K);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1353
    test_virtual_space_actual_committed_space(8 * K, 8 * K);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1354
    test_virtual_space_actual_committed_space(12 * K, 0);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1355
    test_virtual_space_actual_committed_space(12 * K, 4 * K);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1356
    test_virtual_space_actual_committed_space(12 * K, 8 * K);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1357
    test_virtual_space_actual_committed_space(12 * K, 12 * K);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1358
    test_virtual_space_actual_committed_space(64 * K, 0);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1359
    test_virtual_space_actual_committed_space(64 * K, 32 * K);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1360
    test_virtual_space_actual_committed_space(64 * K, 64 * K);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1361
    test_virtual_space_actual_committed_space(2 * M, 0);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1362
    test_virtual_space_actual_committed_space(2 * M, 4 * K);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1363
    test_virtual_space_actual_committed_space(2 * M, 64 * K);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1364
    test_virtual_space_actual_committed_space(2 * M, 1 * M);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1365
    test_virtual_space_actual_committed_space(2 * M, 2 * M);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1366
    test_virtual_space_actual_committed_space(10 * M, 0);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1367
    test_virtual_space_actual_committed_space(10 * M, 4 * K);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1368
    test_virtual_space_actual_committed_space(10 * M, 8 * K);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1369
    test_virtual_space_actual_committed_space(10 * M, 1 * M);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1370
    test_virtual_space_actual_committed_space(10 * M, 2 * M);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1371
    test_virtual_space_actual_committed_space(10 * M, 5 * M);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1372
    test_virtual_space_actual_committed_space(10 * M, 10 * M);
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1373
  }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1374
20402
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1375
  static void test_virtual_space_disable_large_pages() {
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1376
    if (!UseLargePages) {
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1377
      return;
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1378
    }
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1379
    // These test cases verify that if we force VirtualSpace to disable large pages
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1380
    test_virtual_space_actual_committed_space(10 * M, 0, Disable);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1381
    test_virtual_space_actual_committed_space(10 * M, 4 * K, Disable);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1382
    test_virtual_space_actual_committed_space(10 * M, 8 * K, Disable);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1383
    test_virtual_space_actual_committed_space(10 * M, 1 * M, Disable);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1384
    test_virtual_space_actual_committed_space(10 * M, 2 * M, Disable);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1385
    test_virtual_space_actual_committed_space(10 * M, 5 * M, Disable);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1386
    test_virtual_space_actual_committed_space(10 * M, 10 * M, Disable);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1387
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1388
    test_virtual_space_actual_committed_space(10 * M, 0, Reserve);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1389
    test_virtual_space_actual_committed_space(10 * M, 4 * K, Reserve);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1390
    test_virtual_space_actual_committed_space(10 * M, 8 * K, Reserve);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1391
    test_virtual_space_actual_committed_space(10 * M, 1 * M, Reserve);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1392
    test_virtual_space_actual_committed_space(10 * M, 2 * M, Reserve);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1393
    test_virtual_space_actual_committed_space(10 * M, 5 * M, Reserve);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1394
    test_virtual_space_actual_committed_space(10 * M, 10 * M, Reserve);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1395
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1396
    test_virtual_space_actual_committed_space(10 * M, 0, Commit);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1397
    test_virtual_space_actual_committed_space(10 * M, 4 * K, Commit);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1398
    test_virtual_space_actual_committed_space(10 * M, 8 * K, Commit);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1399
    test_virtual_space_actual_committed_space(10 * M, 1 * M, Commit);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1400
    test_virtual_space_actual_committed_space(10 * M, 2 * M, Commit);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1401
    test_virtual_space_actual_committed_space(10 * M, 5 * M, Commit);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1402
    test_virtual_space_actual_committed_space(10 * M, 10 * M, Commit);
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1403
  }
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1404
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1405
  static void test_virtual_space() {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1406
    test_virtual_space_actual_committed_space();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1407
    test_virtual_space_actual_committed_space_one_large_page();
20402
9def9d6d969a 8025526: VirtualSpace should support per-instance disabling of large pages
mgerdin
parents: 19993
diff changeset
  1408
    test_virtual_space_disable_large_pages();
19989
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1409
  }
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1410
};
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1411
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1412
void TestVirtualSpace_test() {
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1413
  TestVirtualSpace::test_virtual_space();
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1414
}
0fc247fb59bc 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 19546
diff changeset
  1415
19546
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1416
#endif // PRODUCT
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
  1417
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
#endif