jmasa@4196: /* jmasa@4196: * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. jmasa@4196: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jmasa@4196: * jmasa@4196: * This code is free software; you can redistribute it and/or modify it jmasa@4196: * under the terms of the GNU General Public License version 2 only, as jmasa@4196: * published by the Free Software Foundation. jmasa@4196: * jmasa@4196: * This code is distributed in the hope that it will be useful, but WITHOUT jmasa@4196: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jmasa@4196: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jmasa@4196: * version 2 for more details (a copy is included in the LICENSE file that jmasa@4196: * accompanied this code). jmasa@4196: * jmasa@4196: * You should have received a copy of the GNU General Public License version jmasa@4196: * 2 along with this work; if not, write to the Free Software Foundation, jmasa@4196: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jmasa@4196: * jmasa@4196: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jmasa@4196: * or visit www.oracle.com if you need additional information or have any jmasa@4196: * questions. jmasa@4196: * jmasa@4196: */ jmasa@4196: #ifndef SHARE_VM_MEMORY_METACHUNK_HPP jmasa@4196: #define SHARE_VM_MEMORY_METACHUNK_HPP jmasa@4196: jmasa@4196: // Metachunk - Quantum of allocation from a Virtualspace jmasa@4196: // Metachunks are reused (when freed are put on a global freelist) and jmasa@4196: // have no permanent association to a SpaceManager. jmasa@4196: jmasa@4196: // +--------------+ <- end jmasa@4196: // | | --+ ---+ jmasa@4196: // | | | free | jmasa@4196: // | | | | jmasa@4196: // | | | | capacity jmasa@4196: // | | | | jmasa@4196: // | | <- top --+ | jmasa@4196: // | | ---+ | jmasa@4196: // | | | used | jmasa@4196: // | | | | jmasa@4196: // | | | | jmasa@4196: // +--------------+ <- bottom ---+ ---+ jmasa@4196: jmasa@5007: class VirtualSpaceNode; jmasa@5007: jmasa@4196: class Metachunk VALUE_OBJ_CLASS_SPEC { jmasa@4196: // link to support lists of chunks jmasa@4196: Metachunk* _next; jmasa@4196: Metachunk* _prev; jmasa@5007: VirtualSpaceNode* _container; jmasa@4196: jmasa@4196: MetaWord* _bottom; jmasa@4196: MetaWord* _end; jmasa@4196: MetaWord* _top; jmasa@4196: size_t _word_size; jmasa@4196: // Used in a guarantee() so included in the Product builds jmasa@4196: // even through it is only for debugging. jmasa@4196: bool _is_free; jmasa@4196: jmasa@4196: // Metachunks are allocated out of a MetadataVirtualSpace and jmasa@4196: // and use some of its space to describe itself (plus alignment jmasa@4196: // considerations). Metadata is allocated in the rest of the chunk. jmasa@4196: // This size is the overhead of maintaining the Metachunk within jmasa@4196: // the space. jmasa@4196: static size_t _overhead; jmasa@4196: jmasa@4196: public: jmasa@5007: Metachunk(size_t word_size , VirtualSpaceNode* container); jmasa@4196: jmasa@4196: // Used to add a Metachunk to a list of Metachunks jmasa@4196: void set_next(Metachunk* v) { _next = v; assert(v != this, "Boom");} jmasa@4196: void set_prev(Metachunk* v) { _prev = v; assert(v != this, "Boom");} jmasa@5007: void set_container(VirtualSpaceNode* v) { _container = v; } jmasa@4196: jmasa@4196: MetaWord* allocate(size_t word_size); jmasa@4196: jmasa@4196: // Accessors jmasa@4196: Metachunk* next() const { return _next; } jmasa@4196: Metachunk* prev() const { return _prev; } jmasa@5007: VirtualSpaceNode* container() const { return _container; } jmasa@4196: MetaWord* bottom() const { return _bottom; } jmasa@4196: MetaWord* end() const { return _end; } jmasa@4196: MetaWord* top() const { return _top; } jmasa@4196: size_t word_size() const { return _word_size; } jmasa@4196: size_t size() const volatile { return _word_size; } jmasa@4196: void set_size(size_t v) { _word_size = v; } jmasa@4196: bool is_free() { return _is_free; } jmasa@4196: void set_is_free(bool v) { _is_free = v; } jmasa@4196: static size_t overhead() { return _overhead; } jmasa@4196: void clear_next() { set_next(NULL); } jmasa@4196: void link_prev(Metachunk* ptr) { set_prev(ptr); } jmasa@4196: uintptr_t* end() { return ((uintptr_t*) this) + size(); } jmasa@4196: bool cantCoalesce() const { return false; } jmasa@4196: void link_next(Metachunk* ptr) { set_next(ptr); } jmasa@4196: void link_after(Metachunk* ptr){ jmasa@4196: link_next(ptr); jmasa@4196: if (ptr != NULL) ptr->link_prev(this); jmasa@4196: } jmasa@4196: jmasa@4196: // Reset top to bottom so chunk can be reused. jmasa@4382: void reset_empty() { _top = (_bottom + _overhead); _next = NULL; _prev = NULL; } jmasa@4196: bool is_empty() { return _top == (_bottom + _overhead); } jmasa@4196: jmasa@4196: // used (has been allocated) jmasa@4196: // free (available for future allocations) jmasa@4196: // capacity (total size of chunk) jmasa@4382: size_t used_word_size() const; jmasa@4382: size_t free_word_size() const; jmasa@4382: size_t capacity_word_size()const; jmasa@4196: jmasa@4196: // Debug support jmasa@4196: #ifdef ASSERT jmasa@4196: void* prev_addr() const { return (void*)&_prev; } jmasa@4196: void* next_addr() const { return (void*)&_next; } jmasa@4196: void* size_addr() const { return (void*)&_word_size; } jmasa@4196: #endif jmasa@4196: bool verify_chunk_in_free_list(Metachunk* tc) const { return true; } jmasa@4196: bool verify_par_locked() { return true; } jmasa@4196: jmasa@4196: void assert_is_mangled() const {/* Don't check "\*/} jmasa@4196: coleenp@4304: NOT_PRODUCT(void mangle();) jmasa@4196: jmasa@4196: void print_on(outputStream* st) const; jmasa@4196: void verify(); jmasa@4196: }; jmasa@4196: #endif // SHARE_VM_MEMORY_METACHUNK_HPP