src/share/vm/runtime/virtualspace.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6198
55fb97c4c58d
parent 0
f90c822e73f8
child 7994
04ff2f6cd0eb
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_RUNTIME_VIRTUALSPACE_HPP
aoqi@0 26 #define SHARE_VM_RUNTIME_VIRTUALSPACE_HPP
aoqi@0 27
aoqi@0 28 #include "memory/allocation.hpp"
aoqi@0 29
aoqi@0 30 // ReservedSpace is a data structure for reserving a contiguous address range.
aoqi@0 31
aoqi@0 32 class ReservedSpace VALUE_OBJ_CLASS_SPEC {
aoqi@0 33 friend class VMStructs;
aoqi@0 34 private:
aoqi@0 35 char* _base;
aoqi@0 36 size_t _size;
aoqi@0 37 size_t _noaccess_prefix;
aoqi@0 38 size_t _alignment;
aoqi@0 39 bool _special;
aoqi@0 40 bool _executable;
aoqi@0 41
aoqi@0 42 // ReservedSpace
aoqi@0 43 ReservedSpace(char* base, size_t size, size_t alignment, bool special,
aoqi@0 44 bool executable);
aoqi@0 45 void initialize(size_t size, size_t alignment, bool large,
aoqi@0 46 char* requested_address,
aoqi@0 47 const size_t noaccess_prefix,
aoqi@0 48 bool executable);
aoqi@0 49
aoqi@0 50 protected:
aoqi@0 51 // Create protection page at the beginning of the space.
aoqi@0 52 void protect_noaccess_prefix(const size_t size);
aoqi@0 53
aoqi@0 54 public:
aoqi@0 55 // Constructor
aoqi@0 56 ReservedSpace();
aoqi@0 57 ReservedSpace(size_t size);
aoqi@0 58 ReservedSpace(size_t size, size_t alignment, bool large,
aoqi@0 59 char* requested_address = NULL,
aoqi@0 60 const size_t noaccess_prefix = 0);
aoqi@0 61 ReservedSpace(size_t size, size_t alignment, bool large, bool executable);
aoqi@0 62
aoqi@0 63 // Accessors
aoqi@0 64 char* base() const { return _base; }
aoqi@0 65 size_t size() const { return _size; }
aoqi@0 66 size_t alignment() const { return _alignment; }
aoqi@0 67 bool special() const { return _special; }
aoqi@0 68 bool executable() const { return _executable; }
aoqi@0 69 size_t noaccess_prefix() const { return _noaccess_prefix; }
aoqi@0 70 bool is_reserved() const { return _base != NULL; }
aoqi@0 71 void release();
aoqi@0 72
aoqi@0 73 // Splitting
aoqi@0 74 ReservedSpace first_part(size_t partition_size, size_t alignment,
aoqi@0 75 bool split = false, bool realloc = true);
aoqi@0 76 ReservedSpace last_part (size_t partition_size, size_t alignment);
aoqi@0 77
aoqi@0 78 // These simply call the above using the default alignment.
aoqi@0 79 inline ReservedSpace first_part(size_t partition_size,
aoqi@0 80 bool split = false, bool realloc = true);
aoqi@0 81 inline ReservedSpace last_part (size_t partition_size);
aoqi@0 82
aoqi@0 83 // Alignment
aoqi@0 84 static size_t page_align_size_up(size_t size);
aoqi@0 85 static size_t page_align_size_down(size_t size);
aoqi@0 86 static size_t allocation_align_size_up(size_t size);
aoqi@0 87 static size_t allocation_align_size_down(size_t size);
aoqi@0 88 };
aoqi@0 89
aoqi@0 90 ReservedSpace
aoqi@0 91 ReservedSpace::first_part(size_t partition_size, bool split, bool realloc)
aoqi@0 92 {
aoqi@0 93 return first_part(partition_size, alignment(), split, realloc);
aoqi@0 94 }
aoqi@0 95
aoqi@0 96 ReservedSpace ReservedSpace::last_part(size_t partition_size)
aoqi@0 97 {
aoqi@0 98 return last_part(partition_size, alignment());
aoqi@0 99 }
aoqi@0 100
aoqi@0 101 // Class encapsulating behavior specific of memory space reserved for Java heap
aoqi@0 102 class ReservedHeapSpace : public ReservedSpace {
aoqi@0 103 public:
aoqi@0 104 // Constructor
aoqi@0 105 ReservedHeapSpace(size_t size, size_t forced_base_alignment,
aoqi@0 106 bool large, char* requested_address);
aoqi@0 107 };
aoqi@0 108
aoqi@0 109 // Class encapsulating behavior specific memory space for Code
aoqi@0 110 class ReservedCodeSpace : public ReservedSpace {
aoqi@0 111 public:
aoqi@0 112 // Constructor
aoqi@0 113 ReservedCodeSpace(size_t r_size, size_t rs_align, bool large);
aoqi@0 114 };
aoqi@0 115
aoqi@0 116 // VirtualSpace is data structure for committing a previously reserved address range in smaller chunks.
aoqi@0 117
aoqi@0 118 class VirtualSpace VALUE_OBJ_CLASS_SPEC {
aoqi@0 119 friend class VMStructs;
aoqi@0 120 private:
aoqi@0 121 // Reserved area
aoqi@0 122 char* _low_boundary;
aoqi@0 123 char* _high_boundary;
aoqi@0 124
aoqi@0 125 // Committed area
aoqi@0 126 char* _low;
aoqi@0 127 char* _high;
aoqi@0 128
aoqi@0 129 // The entire space has been committed and pinned in memory, no
aoqi@0 130 // os::commit_memory() or os::uncommit_memory().
aoqi@0 131 bool _special;
aoqi@0 132
aoqi@0 133 // Need to know if commit should be executable.
aoqi@0 134 bool _executable;
aoqi@0 135
aoqi@0 136 // MPSS Support
aoqi@0 137 // Each virtualspace region has a lower, middle, and upper region.
aoqi@0 138 // Each region has an end boundary and a high pointer which is the
aoqi@0 139 // high water mark for the last allocated byte.
aoqi@0 140 // The lower and upper unaligned to LargePageSizeInBytes uses default page.
aoqi@0 141 // size. The middle region uses large page size.
aoqi@0 142 char* _lower_high;
aoqi@0 143 char* _middle_high;
aoqi@0 144 char* _upper_high;
aoqi@0 145
aoqi@0 146 char* _lower_high_boundary;
aoqi@0 147 char* _middle_high_boundary;
aoqi@0 148 char* _upper_high_boundary;
aoqi@0 149
aoqi@0 150 size_t _lower_alignment;
aoqi@0 151 size_t _middle_alignment;
aoqi@0 152 size_t _upper_alignment;
aoqi@0 153
aoqi@0 154 // MPSS Accessors
aoqi@0 155 char* lower_high() const { return _lower_high; }
aoqi@0 156 char* middle_high() const { return _middle_high; }
aoqi@0 157 char* upper_high() const { return _upper_high; }
aoqi@0 158
aoqi@0 159 char* lower_high_boundary() const { return _lower_high_boundary; }
aoqi@0 160 char* middle_high_boundary() const { return _middle_high_boundary; }
aoqi@0 161 char* upper_high_boundary() const { return _upper_high_boundary; }
aoqi@0 162
aoqi@0 163 size_t lower_alignment() const { return _lower_alignment; }
aoqi@0 164 size_t middle_alignment() const { return _middle_alignment; }
aoqi@0 165 size_t upper_alignment() const { return _upper_alignment; }
aoqi@0 166
aoqi@0 167 public:
aoqi@0 168 // Committed area
aoqi@0 169 char* low() const { return _low; }
aoqi@0 170 char* high() const { return _high; }
aoqi@0 171
aoqi@0 172 // Reserved area
aoqi@0 173 char* low_boundary() const { return _low_boundary; }
aoqi@0 174 char* high_boundary() const { return _high_boundary; }
aoqi@0 175
aoqi@0 176 bool special() const { return _special; }
aoqi@0 177
aoqi@0 178 public:
aoqi@0 179 // Initialization
aoqi@0 180 VirtualSpace();
aoqi@0 181 bool initialize_with_granularity(ReservedSpace rs, size_t committed_byte_size, size_t max_commit_ganularity);
aoqi@0 182 bool initialize(ReservedSpace rs, size_t committed_byte_size);
aoqi@0 183
aoqi@0 184 // Destruction
aoqi@0 185 ~VirtualSpace();
aoqi@0 186
aoqi@0 187 // Reserved memory
aoqi@0 188 size_t reserved_size() const;
aoqi@0 189 // Actually committed OS memory
aoqi@0 190 size_t actual_committed_size() const;
aoqi@0 191 // Memory used/expanded in this virtual space
aoqi@0 192 size_t committed_size() const;
aoqi@0 193 // Memory left to use/expand in this virtual space
aoqi@0 194 size_t uncommitted_size() const;
aoqi@0 195
aoqi@0 196 bool contains(const void* p) const;
aoqi@0 197
aoqi@0 198 // Operations
aoqi@0 199 // returns true on success, false otherwise
aoqi@0 200 bool expand_by(size_t bytes, bool pre_touch = false);
aoqi@0 201 void shrink_by(size_t bytes);
aoqi@0 202 void release();
aoqi@0 203
aoqi@0 204 void check_for_contiguity() PRODUCT_RETURN;
aoqi@0 205
aoqi@0 206 // Debugging
aoqi@0 207 void print_on(outputStream* out) PRODUCT_RETURN;
aoqi@0 208 void print();
aoqi@0 209 };
aoqi@0 210
aoqi@0 211 #endif // SHARE_VM_RUNTIME_VIRTUALSPACE_HPP

mercurial