Thu, 12 Oct 2017 21:27:07 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2012, 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 | #ifndef SHARE_VM_MEMORY_METACHUNK_HPP |
aoqi@0 | 25 | #define SHARE_VM_MEMORY_METACHUNK_HPP |
aoqi@0 | 26 | |
aoqi@0 | 27 | #include "memory/allocation.hpp" |
aoqi@0 | 28 | #include "utilities/debug.hpp" |
aoqi@0 | 29 | #include "utilities/globalDefinitions.hpp" |
aoqi@0 | 30 | |
aoqi@0 | 31 | class VirtualSpaceNode; |
aoqi@0 | 32 | |
aoqi@0 | 33 | // Super class of Metablock and Metachunk to allow them to |
aoqi@0 | 34 | // be put on the FreeList and in the BinaryTreeDictionary. |
aoqi@0 | 35 | template <class T> |
aoqi@0 | 36 | class Metabase VALUE_OBJ_CLASS_SPEC { |
aoqi@0 | 37 | size_t _word_size; |
aoqi@0 | 38 | T* _next; |
aoqi@0 | 39 | T* _prev; |
aoqi@0 | 40 | |
aoqi@0 | 41 | protected: |
aoqi@0 | 42 | Metabase(size_t word_size) : _word_size(word_size), _next(NULL), _prev(NULL) {} |
aoqi@0 | 43 | |
aoqi@0 | 44 | public: |
aoqi@0 | 45 | T* next() const { return _next; } |
aoqi@0 | 46 | T* prev() const { return _prev; } |
aoqi@0 | 47 | void set_next(T* v) { _next = v; assert(v != this, "Boom");} |
aoqi@0 | 48 | void set_prev(T* v) { _prev = v; assert(v != this, "Boom");} |
aoqi@0 | 49 | void clear_next() { set_next(NULL); } |
aoqi@0 | 50 | void clear_prev() { set_prev(NULL); } |
aoqi@0 | 51 | |
aoqi@0 | 52 | size_t size() const volatile { return _word_size; } |
aoqi@0 | 53 | void set_size(size_t v) { _word_size = v; } |
aoqi@0 | 54 | |
aoqi@0 | 55 | void link_next(T* ptr) { set_next(ptr); } |
aoqi@0 | 56 | void link_prev(T* ptr) { set_prev(ptr); } |
aoqi@0 | 57 | void link_after(T* ptr) { |
aoqi@0 | 58 | link_next(ptr); |
aoqi@0 | 59 | if (ptr != NULL) ptr->link_prev((T*)this); |
aoqi@0 | 60 | } |
aoqi@0 | 61 | |
aoqi@0 | 62 | uintptr_t* end() const { return ((uintptr_t*) this) + size(); } |
aoqi@0 | 63 | |
aoqi@0 | 64 | bool cantCoalesce() const { return false; } |
aoqi@0 | 65 | |
aoqi@0 | 66 | // Debug support |
aoqi@0 | 67 | #ifdef ASSERT |
aoqi@0 | 68 | void* prev_addr() const { return (void*)&_prev; } |
aoqi@0 | 69 | void* next_addr() const { return (void*)&_next; } |
aoqi@0 | 70 | void* size_addr() const { return (void*)&_word_size; } |
aoqi@0 | 71 | #endif |
aoqi@0 | 72 | bool verify_chunk_in_free_list(T* tc) const { return true; } |
aoqi@0 | 73 | bool verify_par_locked() { return true; } |
aoqi@0 | 74 | |
aoqi@0 | 75 | void assert_is_mangled() const {/* Don't check "\*/} |
aoqi@0 | 76 | |
aoqi@0 | 77 | bool is_free() { return true; } |
aoqi@0 | 78 | }; |
aoqi@0 | 79 | |
aoqi@0 | 80 | // Metachunk - Quantum of allocation from a Virtualspace |
aoqi@0 | 81 | // Metachunks are reused (when freed are put on a global freelist) and |
aoqi@0 | 82 | // have no permanent association to a SpaceManager. |
aoqi@0 | 83 | |
aoqi@0 | 84 | // +--------------+ <- end --+ --+ |
aoqi@0 | 85 | // | | | | |
aoqi@0 | 86 | // | | | free | |
aoqi@0 | 87 | // | | | | |
aoqi@0 | 88 | // | | | | size | capacity |
aoqi@0 | 89 | // | | | | |
aoqi@0 | 90 | // | | <- top -- + | |
aoqi@0 | 91 | // | | | | |
aoqi@0 | 92 | // | | | used | |
aoqi@0 | 93 | // | | | | |
aoqi@0 | 94 | // | | | | |
aoqi@0 | 95 | // +--------------+ <- bottom --+ --+ |
aoqi@0 | 96 | |
aoqi@0 | 97 | class Metachunk : public Metabase<Metachunk> { |
aoqi@0 | 98 | friend class TestMetachunk; |
aoqi@0 | 99 | // The VirtualSpaceNode containing this chunk. |
aoqi@0 | 100 | VirtualSpaceNode* _container; |
aoqi@0 | 101 | |
aoqi@0 | 102 | // Current allocation top. |
aoqi@0 | 103 | MetaWord* _top; |
aoqi@0 | 104 | |
aoqi@0 | 105 | DEBUG_ONLY(bool _is_tagged_free;) |
aoqi@0 | 106 | |
aoqi@0 | 107 | MetaWord* initial_top() const { return (MetaWord*)this + overhead(); } |
aoqi@0 | 108 | MetaWord* top() const { return _top; } |
aoqi@0 | 109 | |
aoqi@0 | 110 | public: |
aoqi@0 | 111 | // Metachunks are allocated out of a MetadataVirtualSpace and |
aoqi@0 | 112 | // and use some of its space to describe itself (plus alignment |
aoqi@0 | 113 | // considerations). Metadata is allocated in the rest of the chunk. |
aoqi@0 | 114 | // This size is the overhead of maintaining the Metachunk within |
aoqi@0 | 115 | // the space. |
aoqi@0 | 116 | |
aoqi@0 | 117 | // Alignment of each allocation in the chunks. |
aoqi@0 | 118 | static size_t object_alignment(); |
aoqi@0 | 119 | |
aoqi@0 | 120 | // Size of the Metachunk header, including alignment. |
aoqi@0 | 121 | static size_t overhead(); |
aoqi@0 | 122 | |
aoqi@0 | 123 | Metachunk(size_t word_size , VirtualSpaceNode* container); |
aoqi@0 | 124 | |
aoqi@0 | 125 | MetaWord* allocate(size_t word_size); |
aoqi@0 | 126 | |
aoqi@0 | 127 | VirtualSpaceNode* container() const { return _container; } |
aoqi@0 | 128 | |
aoqi@0 | 129 | MetaWord* bottom() const { return (MetaWord*) this; } |
aoqi@0 | 130 | |
aoqi@0 | 131 | // Reset top to bottom so chunk can be reused. |
aoqi@0 | 132 | void reset_empty() { _top = initial_top(); clear_next(); clear_prev(); } |
aoqi@0 | 133 | bool is_empty() { return _top == initial_top(); } |
aoqi@0 | 134 | |
aoqi@0 | 135 | // used (has been allocated) |
aoqi@0 | 136 | // free (available for future allocations) |
aoqi@0 | 137 | size_t word_size() const { return size(); } |
aoqi@0 | 138 | size_t used_word_size() const; |
aoqi@0 | 139 | size_t free_word_size() const; |
aoqi@0 | 140 | |
aoqi@0 | 141 | #ifdef ASSERT |
aoqi@0 | 142 | bool is_tagged_free() { return _is_tagged_free; } |
aoqi@0 | 143 | void set_is_tagged_free(bool v) { _is_tagged_free = v; } |
aoqi@0 | 144 | #endif |
aoqi@0 | 145 | |
aoqi@0 | 146 | bool contains(const void* ptr) { return bottom() <= ptr && ptr < _top; } |
aoqi@0 | 147 | |
aoqi@0 | 148 | NOT_PRODUCT(void mangle();) |
aoqi@0 | 149 | |
aoqi@0 | 150 | void print_on(outputStream* st) const; |
aoqi@0 | 151 | void verify(); |
aoqi@0 | 152 | }; |
aoqi@0 | 153 | |
aoqi@0 | 154 | // Metablock is the unit of allocation from a Chunk. |
aoqi@0 | 155 | // |
aoqi@0 | 156 | // A Metablock may be reused by its SpaceManager but are never moved between |
aoqi@0 | 157 | // SpaceManagers. There is no explicit link to the Metachunk |
aoqi@0 | 158 | // from which it was allocated. Metablock may be deallocated and |
aoqi@0 | 159 | // put on a freelist but the space is never freed, rather |
aoqi@0 | 160 | // the Metachunk it is a part of will be deallocated when it's |
aoqi@0 | 161 | // associated class loader is collected. |
aoqi@0 | 162 | |
aoqi@0 | 163 | class Metablock : public Metabase<Metablock> { |
aoqi@0 | 164 | friend class VMStructs; |
aoqi@0 | 165 | public: |
aoqi@0 | 166 | Metablock(size_t word_size) : Metabase<Metablock>(word_size) {} |
aoqi@0 | 167 | }; |
aoqi@0 | 168 | |
aoqi@0 | 169 | #endif // SHARE_VM_MEMORY_METACHUNK_HPP |