jmasa@4327: /* jmasa@4327: * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. jmasa@4327: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jmasa@4327: * jmasa@4327: * This code is free software; you can redistribute it and/or modify it jmasa@4327: * under the terms of the GNU General Public License version 2 only, as jmasa@4327: * published by the Free Software Foundation. jmasa@4327: * jmasa@4327: * This code is distributed in the hope that it will be useful, but WITHOUT jmasa@4327: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jmasa@4327: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jmasa@4327: * version 2 for more details (a copy is included in the LICENSE file that jmasa@4327: * accompanied this code). jmasa@4327: * jmasa@4327: * You should have received a copy of the GNU General Public License version jmasa@4327: * 2 along with this work; if not, write to the Free Software Foundation, jmasa@4327: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jmasa@4327: * jmasa@4327: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jmasa@4327: * or visit www.oracle.com if you need additional information or have any jmasa@4327: * questions. jmasa@4327: * jmasa@4327: */ jmasa@4327: jmasa@4327: #include "precompiled.hpp" jmasa@4327: #include "memory/allocation.hpp" jmasa@4327: #include "memory/metablock.hpp" jmasa@4327: #include "utilities/copy.hpp" jmasa@4327: #include "utilities/debug.hpp" jmasa@4327: jmasa@4327: // Blocks of space for metadata are allocated out of Metachunks. jmasa@4327: // jmasa@4327: // Metachunk are allocated out of MetadataVirtualspaces and once jmasa@4327: // allocated there is no explicit link between a Metachunk and jmasa@4327: // the MetadataVirtualspaces from which it was allocated. jmasa@4327: // jmasa@4327: // Each SpaceManager maintains a jmasa@4327: // list of the chunks it is using and the current chunk. The current jmasa@4327: // chunk is the chunk from which allocations are done. Space freed in jmasa@4327: // a chunk is placed on the free list of blocks (BlockFreelist) and jmasa@4327: // reused from there. jmasa@4327: // jmasa@4327: // Future modification jmasa@4327: // jmasa@4327: // The Metachunk can conceivable be replaced by the Chunk in jmasa@4327: // allocation.hpp. Note that the latter Chunk is the space for jmasa@4327: // allocation (allocations from the chunk are out of the space in jmasa@4327: // the Chunk after the header for the Chunk) where as Metachunks jmasa@4327: // point to space in a VirtualSpace. To replace Metachunks with jmasa@4327: // Chunks, change Chunks so that they can be allocated out of a VirtualSpace. jmasa@4327: size_t Metablock::_min_block_byte_size = sizeof(Metablock); jmasa@4327: jmasa@4327: #ifdef ASSERT jmasa@4327: size_t Metablock::_overhead = jmasa@4327: Chunk::aligned_overhead_size(sizeof(Metablock)) / BytesPerWord; jmasa@4327: #else jmasa@4327: size_t Metablock::_overhead = 0; jmasa@4327: #endif jmasa@4327: jmasa@4327: // New blocks returned by the Metaspace are zero initialized. jmasa@4327: // We should fix the constructors to not assume this instead. jmasa@4327: Metablock* Metablock::initialize(MetaWord* p, size_t word_size) { jmasa@4327: if (p == NULL) { jmasa@4327: return NULL; jmasa@4327: } jmasa@4327: jmasa@4327: Metablock* result = (Metablock*) p; jmasa@4327: jmasa@4327: // Clear the memory jmasa@4327: Copy::fill_to_aligned_words((HeapWord*)result, word_size); jmasa@4327: #ifdef ASSERT jmasa@4327: result->set_word_size(word_size); jmasa@4327: #endif jmasa@4327: return result; jmasa@4327: }