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_METABLOCK_HPP jmasa@4196: #define SHARE_VM_MEMORY_METABLOCK_HPP jmasa@4196: jmasa@4196: // Metablock are the unit of allocation from a Chunk. It is initialized jmasa@4196: // with the size of the requested allocation. That size is overwritten jmasa@4196: // once the allocation returns. jmasa@4196: // jmasa@4196: // A Metablock may be reused by its SpaceManager but are never moved between jmasa@4196: // SpaceManagers. There is no explicit link to the Metachunk jmasa@4196: // from which it was allocated. Metablock may be deallocated and jmasa@4196: // put on a freelist but the space is never freed, rather jmasa@4196: // the Metachunk it is a part of will be deallocated when it's jmasa@4196: // associated class loader is collected. jmasa@4196: jmasa@4196: class Metablock VALUE_OBJ_CLASS_SPEC { jmasa@4196: friend class VMStructs; jmasa@4196: private: jmasa@4196: // Used to align the allocation (see below). jmasa@4196: union block_t { jmasa@4196: void* _data[3]; jmasa@4196: struct header_t { jmasa@4196: size_t _word_size; jmasa@4196: Metablock* _next; jmasa@4196: Metablock* _prev; jmasa@4196: } _header; jmasa@4196: } _block; jmasa@4196: static size_t _min_block_byte_size; jmasa@4196: static size_t _overhead; jmasa@4196: jmasa@4196: typedef union block_t Block; jmasa@4196: typedef struct header_t Header; jmasa@4196: const Block* block() const { return &_block; } jmasa@4196: const Block::header_t* header() const { return &(block()->_header); } jmasa@4196: public: jmasa@4196: jmasa@4196: static Metablock* initialize(MetaWord* p, size_t word_size); jmasa@4196: jmasa@4196: // This places the body of the block at a 2 word boundary jmasa@4196: // because every block starts on a 2 word boundary. Work out jmasa@4196: // how to make the body on a 2 word boundary if the block jmasa@4196: // starts on a arbitrary boundary. JJJ jmasa@4196: jmasa@4196: size_t word_size() const { return header()->_word_size; } jmasa@4196: void set_word_size(size_t v) { _block._header._word_size = v; } jmasa@4196: size_t size() const volatile { return _block._header._word_size; } jmasa@4196: void set_size(size_t v) { _block._header._word_size = v; } jmasa@4196: Metablock* next() const { return header()->_next; } jmasa@4196: void set_next(Metablock* v) { _block._header._next = v; } jmasa@4196: Metablock* prev() const { return header()->_prev; } jmasa@4196: void set_prev(Metablock* v) { _block._header._prev = v; } jmasa@4196: jmasa@4196: static size_t min_block_byte_size() { return _min_block_byte_size; } jmasa@4196: static size_t overhead() { return _overhead; } jmasa@4196: jmasa@4196: bool is_free() { return header()->_word_size != 0; } jmasa@4196: void clear_next() { set_next(NULL); } jmasa@4196: void link_prev(Metablock* 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(Metablock* ptr) { set_next(ptr); } jmasa@4196: void link_after(Metablock* ptr){ jmasa@4196: link_next(ptr); jmasa@4196: if (ptr != NULL) ptr->link_prev(this); jmasa@4196: } jmasa@4196: jmasa@4196: // Should not be needed in a free list of Metablocks jmasa@4196: void markNotFree() { ShouldNotReachHere(); } jmasa@4196: jmasa@4196: // Debug support jmasa@4196: #ifdef ASSERT jmasa@4196: void* prev_addr() const { return (void*)&_block._header._prev; } jmasa@4196: void* next_addr() const { return (void*)&_block._header._next; } jmasa@4196: void* size_addr() const { return (void*)&_block._header._word_size; } jmasa@4196: #endif jmasa@4196: bool verify_chunk_in_free_list(Metablock* 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: }; jmasa@4196: #endif // SHARE_VM_MEMORY_METABLOCK_HPP