Thu, 26 Jun 2014 11:36:58 +0200
8047818: G1 HeapRegions can no longer be ContiguousSpaces
Summary: Change parent of G1OffsetTableContigSpace to CompactibleSpace, reimplement missing functionality
Reviewed-by: stefank, jmasa, tschatzl
jmasa@4196 | 1 | /* |
stefank@5941 | 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
jmasa@4196 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jmasa@4196 | 4 | * |
jmasa@4196 | 5 | * This code is free software; you can redistribute it and/or modify it |
jmasa@4196 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jmasa@4196 | 7 | * published by the Free Software Foundation. |
jmasa@4196 | 8 | * |
jmasa@4196 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jmasa@4196 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jmasa@4196 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jmasa@4196 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jmasa@4196 | 13 | * accompanied this code). |
jmasa@4196 | 14 | * |
jmasa@4196 | 15 | * You should have received a copy of the GNU General Public License version |
jmasa@4196 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jmasa@4196 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jmasa@4196 | 18 | * |
jmasa@4196 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jmasa@4196 | 20 | * or visit www.oracle.com if you need additional information or have any |
jmasa@4196 | 21 | * questions. |
jmasa@4196 | 22 | * |
jmasa@4196 | 23 | */ |
jmasa@4196 | 24 | #ifndef SHARE_VM_MEMORY_METACHUNK_HPP |
jmasa@4196 | 25 | #define SHARE_VM_MEMORY_METACHUNK_HPP |
jmasa@4196 | 26 | |
stefank@5941 | 27 | #include "memory/allocation.hpp" |
stefank@5941 | 28 | #include "utilities/debug.hpp" |
stefank@5941 | 29 | #include "utilities/globalDefinitions.hpp" |
jmasa@4196 | 30 | |
jmasa@5007 | 31 | class VirtualSpaceNode; |
jmasa@5007 | 32 | |
stefank@5941 | 33 | // Super class of Metablock and Metachunk to allow them to |
stefank@5941 | 34 | // be put on the FreeList and in the BinaryTreeDictionary. |
stefank@5941 | 35 | template <class T> |
stefank@5941 | 36 | class Metabase VALUE_OBJ_CLASS_SPEC { |
stefank@5941 | 37 | size_t _word_size; |
stefank@5941 | 38 | T* _next; |
stefank@5941 | 39 | T* _prev; |
jmasa@4196 | 40 | |
stefank@5941 | 41 | protected: |
stefank@5941 | 42 | Metabase(size_t word_size) : _word_size(word_size), _next(NULL), _prev(NULL) {} |
jmasa@4196 | 43 | |
jmasa@4196 | 44 | public: |
stefank@5941 | 45 | T* next() const { return _next; } |
stefank@5941 | 46 | T* prev() const { return _prev; } |
stefank@5941 | 47 | void set_next(T* v) { _next = v; assert(v != this, "Boom");} |
stefank@5941 | 48 | void set_prev(T* v) { _prev = v; assert(v != this, "Boom");} |
stefank@5941 | 49 | void clear_next() { set_next(NULL); } |
stefank@5941 | 50 | void clear_prev() { set_prev(NULL); } |
jmasa@4196 | 51 | |
jmasa@4196 | 52 | size_t size() const volatile { return _word_size; } |
jmasa@4196 | 53 | void set_size(size_t v) { _word_size = v; } |
stefank@5941 | 54 | |
stefank@5941 | 55 | void link_next(T* ptr) { set_next(ptr); } |
stefank@5941 | 56 | void link_prev(T* ptr) { set_prev(ptr); } |
stefank@5941 | 57 | void link_after(T* ptr) { |
jmasa@4196 | 58 | link_next(ptr); |
stefank@5941 | 59 | if (ptr != NULL) ptr->link_prev((T*)this); |
jmasa@4196 | 60 | } |
jmasa@4196 | 61 | |
stefank@5941 | 62 | uintptr_t* end() const { return ((uintptr_t*) this) + size(); } |
jmasa@4196 | 63 | |
stefank@5941 | 64 | bool cantCoalesce() const { return false; } |
jmasa@4196 | 65 | |
jmasa@4196 | 66 | // Debug support |
jmasa@4196 | 67 | #ifdef ASSERT |
jmasa@4196 | 68 | void* prev_addr() const { return (void*)&_prev; } |
jmasa@4196 | 69 | void* next_addr() const { return (void*)&_next; } |
jmasa@4196 | 70 | void* size_addr() const { return (void*)&_word_size; } |
jmasa@4196 | 71 | #endif |
stefank@5941 | 72 | bool verify_chunk_in_free_list(T* tc) const { return true; } |
jmasa@4196 | 73 | bool verify_par_locked() { return true; } |
jmasa@4196 | 74 | |
jmasa@4196 | 75 | void assert_is_mangled() const {/* Don't check "\*/} |
jmasa@4196 | 76 | |
stefank@5941 | 77 | bool is_free() { return true; } |
stefank@5941 | 78 | }; |
stefank@5941 | 79 | |
stefank@5941 | 80 | // Metachunk - Quantum of allocation from a Virtualspace |
stefank@5941 | 81 | // Metachunks are reused (when freed are put on a global freelist) and |
stefank@5941 | 82 | // have no permanent association to a SpaceManager. |
stefank@5941 | 83 | |
stefank@5941 | 84 | // +--------------+ <- end --+ --+ |
stefank@5941 | 85 | // | | | | |
stefank@5941 | 86 | // | | | free | |
stefank@5941 | 87 | // | | | | |
stefank@5941 | 88 | // | | | | size | capacity |
stefank@5941 | 89 | // | | | | |
stefank@5941 | 90 | // | | <- top -- + | |
stefank@5941 | 91 | // | | | | |
stefank@5941 | 92 | // | | | used | |
stefank@5941 | 93 | // | | | | |
stefank@5941 | 94 | // | | | | |
stefank@5941 | 95 | // +--------------+ <- bottom --+ --+ |
stefank@5941 | 96 | |
stefank@5941 | 97 | class Metachunk : public Metabase<Metachunk> { |
stefank@5941 | 98 | friend class TestMetachunk; |
stefank@5941 | 99 | // The VirtualSpaceNode containing this chunk. |
stefank@5941 | 100 | VirtualSpaceNode* _container; |
stefank@5941 | 101 | |
stefank@5941 | 102 | // Current allocation top. |
stefank@5941 | 103 | MetaWord* _top; |
stefank@5941 | 104 | |
stefank@5941 | 105 | DEBUG_ONLY(bool _is_tagged_free;) |
stefank@5941 | 106 | |
stefank@5941 | 107 | MetaWord* initial_top() const { return (MetaWord*)this + overhead(); } |
stefank@5941 | 108 | MetaWord* top() const { return _top; } |
stefank@5941 | 109 | |
stefank@5941 | 110 | public: |
stefank@5941 | 111 | // Metachunks are allocated out of a MetadataVirtualSpace and |
stefank@5941 | 112 | // and use some of its space to describe itself (plus alignment |
stefank@5941 | 113 | // considerations). Metadata is allocated in the rest of the chunk. |
stefank@5941 | 114 | // This size is the overhead of maintaining the Metachunk within |
stefank@5941 | 115 | // the space. |
stefank@5941 | 116 | |
stefank@5941 | 117 | // Alignment of each allocation in the chunks. |
stefank@5941 | 118 | static size_t object_alignment(); |
stefank@5941 | 119 | |
stefank@5941 | 120 | // Size of the Metachunk header, including alignment. |
stefank@5941 | 121 | static size_t overhead(); |
stefank@5941 | 122 | |
stefank@5941 | 123 | Metachunk(size_t word_size , VirtualSpaceNode* container); |
stefank@5941 | 124 | |
stefank@5941 | 125 | MetaWord* allocate(size_t word_size); |
stefank@5941 | 126 | |
stefank@5941 | 127 | VirtualSpaceNode* container() const { return _container; } |
stefank@5941 | 128 | |
stefank@5941 | 129 | MetaWord* bottom() const { return (MetaWord*) this; } |
stefank@5941 | 130 | |
stefank@5941 | 131 | // Reset top to bottom so chunk can be reused. |
stefank@5941 | 132 | void reset_empty() { _top = initial_top(); clear_next(); clear_prev(); } |
stefank@5941 | 133 | bool is_empty() { return _top == initial_top(); } |
stefank@5941 | 134 | |
stefank@5941 | 135 | // used (has been allocated) |
stefank@5941 | 136 | // free (available for future allocations) |
stefank@5941 | 137 | size_t word_size() const { return size(); } |
stefank@5941 | 138 | size_t used_word_size() const; |
stefank@5941 | 139 | size_t free_word_size() const; |
stefank@5941 | 140 | |
stefank@5941 | 141 | #ifdef ASSERT |
stefank@5941 | 142 | bool is_tagged_free() { return _is_tagged_free; } |
stefank@5941 | 143 | void set_is_tagged_free(bool v) { _is_tagged_free = v; } |
stefank@5941 | 144 | #endif |
jmasa@4196 | 145 | |
coleenp@6305 | 146 | bool contains(const void* ptr) { return bottom() <= ptr && ptr < _top; } |
coleenp@6305 | 147 | |
stefank@5944 | 148 | NOT_PRODUCT(void mangle();) |
stefank@5944 | 149 | |
jmasa@4196 | 150 | void print_on(outputStream* st) const; |
jmasa@4196 | 151 | void verify(); |
jmasa@4196 | 152 | }; |
stefank@5941 | 153 | |
stefank@5941 | 154 | // Metablock is the unit of allocation from a Chunk. |
stefank@5941 | 155 | // |
stefank@5941 | 156 | // A Metablock may be reused by its SpaceManager but are never moved between |
stefank@5941 | 157 | // SpaceManagers. There is no explicit link to the Metachunk |
stefank@5941 | 158 | // from which it was allocated. Metablock may be deallocated and |
stefank@5941 | 159 | // put on a freelist but the space is never freed, rather |
stefank@5941 | 160 | // the Metachunk it is a part of will be deallocated when it's |
stefank@5941 | 161 | // associated class loader is collected. |
stefank@5941 | 162 | |
stefank@5941 | 163 | class Metablock : public Metabase<Metablock> { |
stefank@5941 | 164 | friend class VMStructs; |
stefank@5941 | 165 | public: |
stefank@5941 | 166 | Metablock(size_t word_size) : Metabase<Metablock>(word_size) {} |
stefank@5941 | 167 | }; |
stefank@5941 | 168 | |
jmasa@4196 | 169 | #endif // SHARE_VM_MEMORY_METACHUNK_HPP |