src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.hpp

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

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 4153
b9a9ed0f8eeb
parent 0
f90c822e73f8
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2003, 2012, 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_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSVIRTUALSPACE_HPP
aoqi@0 26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSVIRTUALSPACE_HPP
aoqi@0 27
aoqi@0 28 #include "runtime/virtualspace.hpp"
aoqi@0 29
aoqi@0 30 // VirtualSpace for the parallel scavenge collector.
aoqi@0 31 //
aoqi@0 32 // VirtualSpace is data structure for committing a previously reserved address
aoqi@0 33 // range in smaller chunks.
aoqi@0 34
aoqi@0 35 class PSVirtualSpace : public CHeapObj<mtGC> {
aoqi@0 36 friend class VMStructs;
aoqi@0 37 protected:
aoqi@0 38 // The space is committed/uncommited in chunks of size _alignment. The
aoqi@0 39 // ReservedSpace passed to initialize() must be aligned to this value.
aoqi@0 40 const size_t _alignment;
aoqi@0 41
aoqi@0 42 // Reserved area
aoqi@0 43 char* _reserved_low_addr;
aoqi@0 44 char* _reserved_high_addr;
aoqi@0 45
aoqi@0 46 // Committed area
aoqi@0 47 char* _committed_low_addr;
aoqi@0 48 char* _committed_high_addr;
aoqi@0 49
aoqi@0 50 // The entire space has been committed and pinned in memory, no
aoqi@0 51 // os::commit_memory() or os::uncommit_memory().
aoqi@0 52 bool _special;
aoqi@0 53
aoqi@0 54 // Convenience wrapper.
aoqi@0 55 inline static size_t pointer_delta(const char* left, const char* right);
aoqi@0 56
aoqi@0 57 public:
aoqi@0 58 PSVirtualSpace(ReservedSpace rs, size_t alignment);
aoqi@0 59 PSVirtualSpace(ReservedSpace rs);
aoqi@0 60
aoqi@0 61 ~PSVirtualSpace();
aoqi@0 62
aoqi@0 63 // Eventually all instances should be created with the above 1- or 2-arg
aoqi@0 64 // constructors. Then the 1st constructor below should become protected and
aoqi@0 65 // the 2nd ctor and initialize() removed.
aoqi@0 66 PSVirtualSpace(size_t alignment): _alignment(alignment) { }
aoqi@0 67 PSVirtualSpace();
aoqi@0 68 bool initialize(ReservedSpace rs, size_t commit_size);
aoqi@0 69
aoqi@0 70 bool contains(void* p) const;
aoqi@0 71
aoqi@0 72 // Accessors (all sizes are bytes).
aoqi@0 73 size_t alignment() const { return _alignment; }
aoqi@0 74 char* reserved_low_addr() const { return _reserved_low_addr; }
aoqi@0 75 char* reserved_high_addr() const { return _reserved_high_addr; }
aoqi@0 76 char* committed_low_addr() const { return _committed_low_addr; }
aoqi@0 77 char* committed_high_addr() const { return _committed_high_addr; }
aoqi@0 78 bool special() const { return _special; }
aoqi@0 79
aoqi@0 80 inline size_t committed_size() const;
aoqi@0 81 inline size_t reserved_size() const;
aoqi@0 82 inline size_t uncommitted_size() const;
aoqi@0 83
aoqi@0 84 // Operations.
aoqi@0 85 inline void set_reserved(char* low_addr, char* high_addr, bool special);
aoqi@0 86 inline void set_reserved(ReservedSpace rs);
aoqi@0 87 inline void set_committed(char* low_addr, char* high_addr);
aoqi@0 88 virtual bool expand_by(size_t bytes);
aoqi@0 89 virtual bool shrink_by(size_t bytes);
aoqi@0 90 virtual size_t expand_into(PSVirtualSpace* space, size_t bytes);
aoqi@0 91 void release();
aoqi@0 92
aoqi@0 93 #ifndef PRODUCT
aoqi@0 94 // Debugging
aoqi@0 95 static bool is_aligned(size_t val, size_t align);
aoqi@0 96 bool is_aligned(size_t val) const;
aoqi@0 97 bool is_aligned(char* val) const;
aoqi@0 98 void verify() const;
aoqi@0 99 void print() const;
aoqi@0 100 virtual bool grows_up() const { return true; }
aoqi@0 101 bool grows_down() const { return !grows_up(); }
aoqi@0 102
aoqi@0 103 // Helper class to verify a space when entering/leaving a block.
aoqi@0 104 class PSVirtualSpaceVerifier: public StackObj {
aoqi@0 105 private:
aoqi@0 106 const PSVirtualSpace* const _space;
aoqi@0 107 public:
aoqi@0 108 PSVirtualSpaceVerifier(PSVirtualSpace* space): _space(space) {
aoqi@0 109 _space->verify();
aoqi@0 110 }
aoqi@0 111 ~PSVirtualSpaceVerifier() { _space->verify(); }
aoqi@0 112 };
aoqi@0 113 #endif
aoqi@0 114
aoqi@0 115 virtual void print_space_boundaries_on(outputStream* st) const;
aoqi@0 116
aoqi@0 117 // Included for compatibility with the original VirtualSpace.
aoqi@0 118 public:
aoqi@0 119 // Committed area
aoqi@0 120 char* low() const { return committed_low_addr(); }
aoqi@0 121 char* high() const { return committed_high_addr(); }
aoqi@0 122
aoqi@0 123 // Reserved area
aoqi@0 124 char* low_boundary() const { return reserved_low_addr(); }
aoqi@0 125 char* high_boundary() const { return reserved_high_addr(); }
aoqi@0 126 };
aoqi@0 127
aoqi@0 128 // A virtual space that grows from high addresses to low addresses.
aoqi@0 129 class PSVirtualSpaceHighToLow : public PSVirtualSpace {
aoqi@0 130 friend class VMStructs;
aoqi@0 131 public:
aoqi@0 132 PSVirtualSpaceHighToLow(ReservedSpace rs, size_t alignment);
aoqi@0 133 PSVirtualSpaceHighToLow(ReservedSpace rs);
aoqi@0 134
aoqi@0 135 virtual bool expand_by(size_t bytes);
aoqi@0 136 virtual bool shrink_by(size_t bytes);
aoqi@0 137 virtual size_t expand_into(PSVirtualSpace* space, size_t bytes);
aoqi@0 138
aoqi@0 139 virtual void print_space_boundaries_on(outputStream* st) const;
aoqi@0 140
aoqi@0 141 #ifndef PRODUCT
aoqi@0 142 // Debugging
aoqi@0 143 virtual bool grows_up() const { return false; }
aoqi@0 144 #endif
aoqi@0 145 };
aoqi@0 146
aoqi@0 147 //
aoqi@0 148 // PSVirtualSpace inlines.
aoqi@0 149 //
aoqi@0 150 inline size_t
aoqi@0 151 PSVirtualSpace::pointer_delta(const char* left, const char* right) {
aoqi@0 152 return ::pointer_delta((void *)left, (void*)right, sizeof(char));
aoqi@0 153 }
aoqi@0 154
aoqi@0 155 inline size_t PSVirtualSpace::committed_size() const {
aoqi@0 156 return pointer_delta(committed_high_addr(), committed_low_addr());
aoqi@0 157 }
aoqi@0 158
aoqi@0 159 inline size_t PSVirtualSpace::reserved_size() const {
aoqi@0 160 return pointer_delta(reserved_high_addr(), reserved_low_addr());
aoqi@0 161 }
aoqi@0 162
aoqi@0 163 inline size_t PSVirtualSpace::uncommitted_size() const {
aoqi@0 164 return reserved_size() - committed_size();
aoqi@0 165 }
aoqi@0 166
aoqi@0 167 inline void PSVirtualSpace::set_reserved(char* low_addr, char* high_addr, bool special) {
aoqi@0 168 _reserved_low_addr = low_addr;
aoqi@0 169 _reserved_high_addr = high_addr;
aoqi@0 170 _special = special;
aoqi@0 171 }
aoqi@0 172
aoqi@0 173 inline void PSVirtualSpace::set_reserved(ReservedSpace rs) {
aoqi@0 174 set_reserved(rs.base(), rs.base() + rs.size(), rs.special());
aoqi@0 175 }
aoqi@0 176
aoqi@0 177 inline void PSVirtualSpace::set_committed(char* low_addr, char* high_addr) {
aoqi@0 178 _committed_low_addr = low_addr;
aoqi@0 179 _committed_high_addr = high_addr;
aoqi@0 180 }
aoqi@0 181
aoqi@0 182 #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSVIRTUALSPACE_HPP

mercurial