Mon, 01 Dec 2008 23:25:24 -0800
6778647: snap(), snap_policy() should be renamed setup(), setup_policy()
Summary: Renamed Reference{Policy,Pocessor} methods from snap{,_policy}() to setup{,_policy}()
Reviewed-by: apetrusenko
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | // VirtualSpace for the parallel scavenge collector. |
duke@435 | 26 | // |
duke@435 | 27 | // VirtualSpace is data structure for committing a previously reserved address |
duke@435 | 28 | // range in smaller chunks. |
duke@435 | 29 | |
duke@435 | 30 | class PSVirtualSpace : public CHeapObj { |
duke@435 | 31 | friend class VMStructs; |
duke@435 | 32 | protected: |
duke@435 | 33 | // The space is committed/uncommited in chunks of size _alignment. The |
duke@435 | 34 | // ReservedSpace passed to initialize() must be aligned to this value. |
duke@435 | 35 | const size_t _alignment; |
duke@435 | 36 | |
duke@435 | 37 | // Reserved area |
duke@435 | 38 | char* _reserved_low_addr; |
duke@435 | 39 | char* _reserved_high_addr; |
duke@435 | 40 | |
duke@435 | 41 | // Committed area |
duke@435 | 42 | char* _committed_low_addr; |
duke@435 | 43 | char* _committed_high_addr; |
duke@435 | 44 | |
duke@435 | 45 | // The entire space has been committed and pinned in memory, no |
duke@435 | 46 | // os::commit_memory() or os::uncommit_memory(). |
duke@435 | 47 | bool _special; |
duke@435 | 48 | |
duke@435 | 49 | // Convenience wrapper. |
duke@435 | 50 | inline static size_t pointer_delta(const char* left, const char* right); |
duke@435 | 51 | |
duke@435 | 52 | public: |
duke@435 | 53 | PSVirtualSpace(ReservedSpace rs, size_t alignment); |
duke@435 | 54 | PSVirtualSpace(ReservedSpace rs); |
duke@435 | 55 | |
duke@435 | 56 | ~PSVirtualSpace(); |
duke@435 | 57 | |
duke@435 | 58 | // Eventually all instances should be created with the above 1- or 2-arg |
duke@435 | 59 | // constructors. Then the 1st constructor below should become protected and |
duke@435 | 60 | // the 2nd ctor and initialize() removed. |
duke@435 | 61 | PSVirtualSpace(size_t alignment): _alignment(alignment) { } |
duke@435 | 62 | PSVirtualSpace(); |
duke@435 | 63 | bool initialize(ReservedSpace rs, size_t commit_size); |
duke@435 | 64 | |
duke@435 | 65 | bool contains(void* p) const; |
duke@435 | 66 | |
duke@435 | 67 | // Accessors (all sizes are bytes). |
duke@435 | 68 | size_t alignment() const { return _alignment; } |
duke@435 | 69 | char* reserved_low_addr() const { return _reserved_low_addr; } |
duke@435 | 70 | char* reserved_high_addr() const { return _reserved_high_addr; } |
duke@435 | 71 | char* committed_low_addr() const { return _committed_low_addr; } |
duke@435 | 72 | char* committed_high_addr() const { return _committed_high_addr; } |
duke@435 | 73 | bool special() const { return _special; } |
duke@435 | 74 | |
duke@435 | 75 | inline size_t committed_size() const; |
duke@435 | 76 | inline size_t reserved_size() const; |
duke@435 | 77 | inline size_t uncommitted_size() const; |
duke@435 | 78 | |
duke@435 | 79 | // Operations. |
duke@435 | 80 | inline void set_reserved(char* low_addr, char* high_addr, bool special); |
duke@435 | 81 | inline void set_reserved(ReservedSpace rs); |
duke@435 | 82 | inline void set_committed(char* low_addr, char* high_addr); |
duke@435 | 83 | virtual bool expand_by(size_t bytes, bool pre_touch = false); |
duke@435 | 84 | virtual bool shrink_by(size_t bytes); |
duke@435 | 85 | virtual size_t expand_into(PSVirtualSpace* space, size_t bytes); |
duke@435 | 86 | void release(); |
duke@435 | 87 | |
duke@435 | 88 | #ifndef PRODUCT |
duke@435 | 89 | // Debugging |
duke@435 | 90 | static bool is_aligned(size_t val, size_t align); |
duke@435 | 91 | bool is_aligned(size_t val) const; |
duke@435 | 92 | bool is_aligned(char* val) const; |
duke@435 | 93 | void verify() const; |
duke@435 | 94 | void print() const; |
duke@435 | 95 | virtual bool grows_up() const { return true; } |
duke@435 | 96 | bool grows_down() const { return !grows_up(); } |
duke@435 | 97 | |
duke@435 | 98 | // Helper class to verify a space when entering/leaving a block. |
duke@435 | 99 | class PSVirtualSpaceVerifier: public StackObj { |
duke@435 | 100 | private: |
duke@435 | 101 | const PSVirtualSpace* const _space; |
duke@435 | 102 | public: |
duke@435 | 103 | PSVirtualSpaceVerifier(PSVirtualSpace* space): _space(space) { |
duke@435 | 104 | _space->verify(); |
duke@435 | 105 | } |
duke@435 | 106 | ~PSVirtualSpaceVerifier() { _space->verify(); } |
duke@435 | 107 | }; |
duke@435 | 108 | #endif |
duke@435 | 109 | |
duke@435 | 110 | virtual void print_space_boundaries_on(outputStream* st) const; |
duke@435 | 111 | |
duke@435 | 112 | // Included for compatibility with the original VirtualSpace. |
duke@435 | 113 | public: |
duke@435 | 114 | // Committed area |
duke@435 | 115 | char* low() const { return committed_low_addr(); } |
duke@435 | 116 | char* high() const { return committed_high_addr(); } |
duke@435 | 117 | |
duke@435 | 118 | // Reserved area |
duke@435 | 119 | char* low_boundary() const { return reserved_low_addr(); } |
duke@435 | 120 | char* high_boundary() const { return reserved_high_addr(); } |
duke@435 | 121 | }; |
duke@435 | 122 | |
duke@435 | 123 | // A virtual space that grows from high addresses to low addresses. |
duke@435 | 124 | class PSVirtualSpaceHighToLow : public PSVirtualSpace { |
duke@435 | 125 | friend class VMStructs; |
duke@435 | 126 | public: |
duke@435 | 127 | PSVirtualSpaceHighToLow(ReservedSpace rs, size_t alignment); |
duke@435 | 128 | PSVirtualSpaceHighToLow(ReservedSpace rs); |
duke@435 | 129 | |
duke@435 | 130 | virtual bool expand_by(size_t bytes, bool pre_touch = false); |
duke@435 | 131 | virtual bool shrink_by(size_t bytes); |
duke@435 | 132 | virtual size_t expand_into(PSVirtualSpace* space, size_t bytes); |
duke@435 | 133 | |
duke@435 | 134 | virtual void print_space_boundaries_on(outputStream* st) const; |
duke@435 | 135 | |
duke@435 | 136 | #ifndef PRODUCT |
duke@435 | 137 | // Debugging |
duke@435 | 138 | virtual bool grows_up() const { return false; } |
duke@435 | 139 | #endif |
duke@435 | 140 | }; |
duke@435 | 141 | |
duke@435 | 142 | // |
duke@435 | 143 | // PSVirtualSpace inlines. |
duke@435 | 144 | // |
duke@435 | 145 | inline size_t |
duke@435 | 146 | PSVirtualSpace::pointer_delta(const char* left, const char* right) { |
duke@435 | 147 | return ::pointer_delta((void *)left, (void*)right, sizeof(char)); |
duke@435 | 148 | } |
duke@435 | 149 | |
duke@435 | 150 | inline size_t PSVirtualSpace::committed_size() const { |
duke@435 | 151 | return pointer_delta(committed_high_addr(), committed_low_addr()); |
duke@435 | 152 | } |
duke@435 | 153 | |
duke@435 | 154 | inline size_t PSVirtualSpace::reserved_size() const { |
duke@435 | 155 | return pointer_delta(reserved_high_addr(), reserved_low_addr()); |
duke@435 | 156 | } |
duke@435 | 157 | |
duke@435 | 158 | inline size_t PSVirtualSpace::uncommitted_size() const { |
duke@435 | 159 | return reserved_size() - committed_size(); |
duke@435 | 160 | } |
duke@435 | 161 | |
duke@435 | 162 | inline void PSVirtualSpace::set_reserved(char* low_addr, char* high_addr, bool special) { |
duke@435 | 163 | _reserved_low_addr = low_addr; |
duke@435 | 164 | _reserved_high_addr = high_addr; |
duke@435 | 165 | _special = special; |
duke@435 | 166 | } |
duke@435 | 167 | |
duke@435 | 168 | inline void PSVirtualSpace::set_reserved(ReservedSpace rs) { |
duke@435 | 169 | set_reserved(rs.base(), rs.base() + rs.size(), rs.special()); |
duke@435 | 170 | } |
duke@435 | 171 | |
duke@435 | 172 | inline void PSVirtualSpace::set_committed(char* low_addr, char* high_addr) { |
duke@435 | 173 | _committed_low_addr = low_addr; |
duke@435 | 174 | _committed_high_addr = high_addr; |
duke@435 | 175 | } |