Tue, 16 Sep 2014 14:27:40 +0200
8057768: Make heap region region type in G1 HeapRegion explicit
Reviewed-by: brutisso, tschatzl
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2014, 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_G1_G1CODECACHEREMSET_HPP |
aoqi@0 | 26 | #define SHARE_VM_GC_IMPLEMENTATION_G1_G1CODECACHEREMSET_HPP |
aoqi@0 | 27 | |
aoqi@0 | 28 | #include "memory/allocation.hpp" |
aoqi@0 | 29 | #include "memory/freeList.hpp" |
aoqi@0 | 30 | #include "runtime/globals.hpp" |
aoqi@0 | 31 | |
aoqi@0 | 32 | class CodeBlobClosure; |
aoqi@0 | 33 | |
stefank@6992 | 34 | // The elements of the G1CodeRootChunk is either: |
stefank@6992 | 35 | // 1) nmethod pointers |
stefank@6992 | 36 | // 2) nodes in an internally chained free list |
stefank@6992 | 37 | typedef union { |
stefank@6992 | 38 | nmethod* _nmethod; |
stefank@6992 | 39 | void* _link; |
stefank@6992 | 40 | } NmethodOrLink; |
stefank@6992 | 41 | |
aoqi@0 | 42 | class G1CodeRootChunk : public CHeapObj<mtGC> { |
aoqi@0 | 43 | private: |
aoqi@0 | 44 | static const int NUM_ENTRIES = 32; |
aoqi@0 | 45 | public: |
aoqi@0 | 46 | G1CodeRootChunk* _next; |
aoqi@0 | 47 | G1CodeRootChunk* _prev; |
aoqi@0 | 48 | |
stefank@6992 | 49 | NmethodOrLink* _top; |
stefank@6992 | 50 | // First free position within the chunk. |
stefank@6992 | 51 | volatile NmethodOrLink* _free; |
aoqi@0 | 52 | |
stefank@6992 | 53 | NmethodOrLink _data[NUM_ENTRIES]; |
aoqi@0 | 54 | |
stefank@6992 | 55 | NmethodOrLink* bottom() const { |
stefank@6992 | 56 | return (NmethodOrLink*) &(_data[0]); |
aoqi@0 | 57 | } |
aoqi@0 | 58 | |
stefank@6992 | 59 | NmethodOrLink* end() const { |
stefank@6992 | 60 | return (NmethodOrLink*) &(_data[NUM_ENTRIES]); |
stefank@6992 | 61 | } |
stefank@6992 | 62 | |
stefank@6992 | 63 | bool is_link(NmethodOrLink* nmethod_or_link) { |
stefank@6992 | 64 | return nmethod_or_link->_link == NULL || |
stefank@6992 | 65 | (bottom() <= nmethod_or_link->_link |
stefank@6992 | 66 | && nmethod_or_link->_link < end()); |
stefank@6992 | 67 | } |
stefank@6992 | 68 | |
stefank@6992 | 69 | bool is_nmethod(NmethodOrLink* nmethod_or_link) { |
stefank@6992 | 70 | return !is_link(nmethod_or_link); |
aoqi@0 | 71 | } |
aoqi@0 | 72 | |
aoqi@0 | 73 | public: |
aoqi@0 | 74 | G1CodeRootChunk(); |
aoqi@0 | 75 | ~G1CodeRootChunk() {} |
aoqi@0 | 76 | |
aoqi@0 | 77 | static size_t word_size() { return (size_t)(align_size_up_(sizeof(G1CodeRootChunk), HeapWordSize) / HeapWordSize); } |
aoqi@0 | 78 | |
aoqi@0 | 79 | // FreeList "interface" methods |
aoqi@0 | 80 | |
aoqi@0 | 81 | G1CodeRootChunk* next() const { return _next; } |
aoqi@0 | 82 | G1CodeRootChunk* prev() const { return _prev; } |
aoqi@0 | 83 | void set_next(G1CodeRootChunk* v) { _next = v; assert(v != this, "Boom");} |
aoqi@0 | 84 | void set_prev(G1CodeRootChunk* v) { _prev = v; assert(v != this, "Boom");} |
aoqi@0 | 85 | void clear_next() { set_next(NULL); } |
aoqi@0 | 86 | void clear_prev() { set_prev(NULL); } |
aoqi@0 | 87 | |
aoqi@0 | 88 | size_t size() const { return word_size(); } |
aoqi@0 | 89 | |
aoqi@0 | 90 | void link_next(G1CodeRootChunk* ptr) { set_next(ptr); } |
aoqi@0 | 91 | void link_prev(G1CodeRootChunk* ptr) { set_prev(ptr); } |
aoqi@0 | 92 | void link_after(G1CodeRootChunk* ptr) { |
aoqi@0 | 93 | link_next(ptr); |
aoqi@0 | 94 | if (ptr != NULL) ptr->link_prev((G1CodeRootChunk*)this); |
aoqi@0 | 95 | } |
aoqi@0 | 96 | |
aoqi@0 | 97 | bool is_free() { return true; } |
aoqi@0 | 98 | |
aoqi@0 | 99 | // New G1CodeRootChunk routines |
aoqi@0 | 100 | |
aoqi@0 | 101 | void reset(); |
aoqi@0 | 102 | |
aoqi@0 | 103 | bool is_empty() const { |
aoqi@0 | 104 | return _top == bottom(); |
aoqi@0 | 105 | } |
aoqi@0 | 106 | |
aoqi@0 | 107 | bool is_full() const { |
stefank@6992 | 108 | return _top == end() && _free == NULL; |
aoqi@0 | 109 | } |
aoqi@0 | 110 | |
aoqi@0 | 111 | bool contains(nmethod* method) { |
stefank@6992 | 112 | NmethodOrLink* cur = bottom(); |
aoqi@0 | 113 | while (cur != _top) { |
stefank@6992 | 114 | if (cur->_nmethod == method) return true; |
aoqi@0 | 115 | cur++; |
aoqi@0 | 116 | } |
aoqi@0 | 117 | return false; |
aoqi@0 | 118 | } |
aoqi@0 | 119 | |
aoqi@0 | 120 | bool add(nmethod* method) { |
stefank@6992 | 121 | if (is_full()) { |
stefank@6992 | 122 | return false; |
stefank@6992 | 123 | } |
stefank@6992 | 124 | |
stefank@6992 | 125 | if (_free != NULL) { |
stefank@6992 | 126 | // Take from internally chained free list |
stefank@6992 | 127 | NmethodOrLink* first_free = (NmethodOrLink*)_free; |
stefank@6992 | 128 | _free = (NmethodOrLink*)_free->_link; |
stefank@6992 | 129 | first_free->_nmethod = method; |
stefank@6992 | 130 | } else { |
stefank@6992 | 131 | // Take from top. |
stefank@6992 | 132 | _top->_nmethod = method; |
stefank@6992 | 133 | _top++; |
stefank@6992 | 134 | } |
stefank@6992 | 135 | |
aoqi@0 | 136 | return true; |
aoqi@0 | 137 | } |
aoqi@0 | 138 | |
stefank@6992 | 139 | bool remove_lock_free(nmethod* method); |
aoqi@0 | 140 | |
aoqi@0 | 141 | void nmethods_do(CodeBlobClosure* blk); |
aoqi@0 | 142 | |
aoqi@0 | 143 | nmethod* pop() { |
stefank@6992 | 144 | if (_free != NULL) { |
stefank@6992 | 145 | // Kill the free list. |
stefank@6992 | 146 | _free = NULL; |
aoqi@0 | 147 | } |
stefank@6992 | 148 | |
stefank@6992 | 149 | while (!is_empty()) { |
stefank@6992 | 150 | _top--; |
stefank@6992 | 151 | if (is_nmethod(_top)) { |
stefank@6992 | 152 | return _top->_nmethod; |
stefank@6992 | 153 | } |
stefank@6992 | 154 | } |
stefank@6992 | 155 | |
stefank@6992 | 156 | return NULL; |
aoqi@0 | 157 | } |
aoqi@0 | 158 | }; |
aoqi@0 | 159 | |
tschatzl@6925 | 160 | // Manages free chunks. |
tschatzl@6925 | 161 | class G1CodeRootChunkManager VALUE_OBJ_CLASS_SPEC { |
tschatzl@6925 | 162 | private: |
tschatzl@6925 | 163 | // Global free chunk list management |
tschatzl@6925 | 164 | FreeList<G1CodeRootChunk> _free_list; |
tschatzl@6925 | 165 | // Total number of chunks handed out |
tschatzl@6925 | 166 | size_t _num_chunks_handed_out; |
tschatzl@6925 | 167 | |
tschatzl@6925 | 168 | public: |
tschatzl@6925 | 169 | G1CodeRootChunkManager(); |
tschatzl@6925 | 170 | |
tschatzl@6925 | 171 | G1CodeRootChunk* new_chunk(); |
tschatzl@6925 | 172 | void free_chunk(G1CodeRootChunk* chunk); |
tschatzl@6925 | 173 | // Free all elements of the given list. |
tschatzl@6925 | 174 | void free_all_chunks(FreeList<G1CodeRootChunk>* list); |
tschatzl@6925 | 175 | |
tschatzl@6925 | 176 | void initialize(); |
tschatzl@6925 | 177 | void purge_chunks(size_t keep_ratio); |
tschatzl@6925 | 178 | |
tschatzl@6932 | 179 | static size_t static_mem_size(); |
tschatzl@6925 | 180 | size_t fl_mem_size(); |
tschatzl@6925 | 181 | |
tschatzl@6925 | 182 | #ifndef PRODUCT |
tschatzl@6925 | 183 | size_t num_chunks_handed_out() const; |
tschatzl@6925 | 184 | size_t num_free_chunks() const; |
tschatzl@6925 | 185 | #endif |
tschatzl@6925 | 186 | }; |
tschatzl@6925 | 187 | |
aoqi@0 | 188 | // Implements storage for a set of code roots. |
aoqi@0 | 189 | // All methods that modify the set are not thread-safe except if otherwise noted. |
aoqi@0 | 190 | class G1CodeRootSet VALUE_OBJ_CLASS_SPEC { |
aoqi@0 | 191 | private: |
tschatzl@6925 | 192 | // Global default free chunk manager instance. |
tschatzl@6925 | 193 | static G1CodeRootChunkManager _default_chunk_manager; |
aoqi@0 | 194 | |
tschatzl@6925 | 195 | G1CodeRootChunk* new_chunk() { return _manager->new_chunk(); } |
tschatzl@6925 | 196 | void free_chunk(G1CodeRootChunk* chunk) { _manager->free_chunk(chunk); } |
aoqi@0 | 197 | // Free all elements of the given list. |
tschatzl@6925 | 198 | void free_all_chunks(FreeList<G1CodeRootChunk>* list) { _manager->free_all_chunks(list); } |
aoqi@0 | 199 | |
aoqi@0 | 200 | // Return the chunk that contains the given nmethod, NULL otherwise. |
aoqi@0 | 201 | // Scans the list of chunks backwards, as this method is used to add new |
aoqi@0 | 202 | // entries, which are typically added in bulk for a single nmethod. |
aoqi@0 | 203 | G1CodeRootChunk* find(nmethod* method); |
aoqi@0 | 204 | void free(G1CodeRootChunk* chunk); |
aoqi@0 | 205 | |
aoqi@0 | 206 | size_t _length; |
aoqi@0 | 207 | FreeList<G1CodeRootChunk> _list; |
tschatzl@6925 | 208 | G1CodeRootChunkManager* _manager; |
aoqi@0 | 209 | |
aoqi@0 | 210 | public: |
tschatzl@6925 | 211 | // If an instance is initialized with a chunk manager of NULL, use the global |
tschatzl@6925 | 212 | // default one. |
tschatzl@6925 | 213 | G1CodeRootSet(G1CodeRootChunkManager* manager = NULL); |
aoqi@0 | 214 | ~G1CodeRootSet(); |
aoqi@0 | 215 | |
aoqi@0 | 216 | static void purge_chunks(size_t keep_ratio); |
aoqi@0 | 217 | |
tschatzl@6932 | 218 | static size_t free_chunks_static_mem_size(); |
tschatzl@6925 | 219 | static size_t free_chunks_mem_size(); |
aoqi@0 | 220 | |
aoqi@0 | 221 | // Search for the code blob from the recently allocated ones to find duplicates more quickly, as this |
aoqi@0 | 222 | // method is likely to be repeatedly called with the same nmethod. |
aoqi@0 | 223 | void add(nmethod* method); |
aoqi@0 | 224 | |
stefank@6992 | 225 | void remove_lock_free(nmethod* method); |
aoqi@0 | 226 | nmethod* pop(); |
aoqi@0 | 227 | |
aoqi@0 | 228 | bool contains(nmethod* method); |
aoqi@0 | 229 | |
aoqi@0 | 230 | void clear(); |
aoqi@0 | 231 | |
aoqi@0 | 232 | void nmethods_do(CodeBlobClosure* blk) const; |
aoqi@0 | 233 | |
aoqi@0 | 234 | bool is_empty() { return length() == 0; } |
aoqi@0 | 235 | |
aoqi@0 | 236 | // Length in elements |
aoqi@0 | 237 | size_t length() const { return _length; } |
aoqi@0 | 238 | |
tschatzl@6932 | 239 | // Static data memory size in bytes of this set. |
tschatzl@6932 | 240 | static size_t static_mem_size(); |
aoqi@0 | 241 | // Memory size in bytes taken by this set. |
aoqi@0 | 242 | size_t mem_size(); |
aoqi@0 | 243 | |
aoqi@0 | 244 | static void test() PRODUCT_RETURN; |
aoqi@0 | 245 | }; |
aoqi@0 | 246 | |
aoqi@0 | 247 | #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1CODECACHEREMSET_HPP |