Thu, 29 Nov 2012 10:09:04 -0800
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
Reviewed-by: coleenp
jmasa@4327 | 1 | /* |
jmasa@4327 | 2 | * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
jmasa@4327 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jmasa@4327 | 4 | * |
jmasa@4327 | 5 | * This code is free software; you can redistribute it and/or modify it |
jmasa@4327 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jmasa@4327 | 7 | * published by the Free Software Foundation. |
jmasa@4327 | 8 | * |
jmasa@4327 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jmasa@4327 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jmasa@4327 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jmasa@4327 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jmasa@4327 | 13 | * accompanied this code). |
jmasa@4327 | 14 | * |
jmasa@4327 | 15 | * You should have received a copy of the GNU General Public License version |
jmasa@4327 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jmasa@4327 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jmasa@4327 | 18 | * |
jmasa@4327 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jmasa@4327 | 20 | * or visit www.oracle.com if you need additional information or have any |
jmasa@4327 | 21 | * questions. |
jmasa@4327 | 22 | * |
jmasa@4327 | 23 | */ |
jmasa@4327 | 24 | |
jmasa@4327 | 25 | #include "precompiled.hpp" |
jmasa@4327 | 26 | #include "memory/allocation.hpp" |
jmasa@4327 | 27 | #include "memory/metablock.hpp" |
jmasa@4327 | 28 | #include "utilities/copy.hpp" |
jmasa@4327 | 29 | #include "utilities/debug.hpp" |
jmasa@4327 | 30 | |
jmasa@4327 | 31 | // Blocks of space for metadata are allocated out of Metachunks. |
jmasa@4327 | 32 | // |
jmasa@4327 | 33 | // Metachunk are allocated out of MetadataVirtualspaces and once |
jmasa@4327 | 34 | // allocated there is no explicit link between a Metachunk and |
jmasa@4327 | 35 | // the MetadataVirtualspaces from which it was allocated. |
jmasa@4327 | 36 | // |
jmasa@4327 | 37 | // Each SpaceManager maintains a |
jmasa@4327 | 38 | // list of the chunks it is using and the current chunk. The current |
jmasa@4327 | 39 | // chunk is the chunk from which allocations are done. Space freed in |
jmasa@4327 | 40 | // a chunk is placed on the free list of blocks (BlockFreelist) and |
jmasa@4327 | 41 | // reused from there. |
jmasa@4327 | 42 | // |
jmasa@4327 | 43 | // Future modification |
jmasa@4327 | 44 | // |
jmasa@4327 | 45 | // The Metachunk can conceivable be replaced by the Chunk in |
jmasa@4327 | 46 | // allocation.hpp. Note that the latter Chunk is the space for |
jmasa@4327 | 47 | // allocation (allocations from the chunk are out of the space in |
jmasa@4327 | 48 | // the Chunk after the header for the Chunk) where as Metachunks |
jmasa@4327 | 49 | // point to space in a VirtualSpace. To replace Metachunks with |
jmasa@4327 | 50 | // Chunks, change Chunks so that they can be allocated out of a VirtualSpace. |
jmasa@4327 | 51 | size_t Metablock::_min_block_byte_size = sizeof(Metablock); |
jmasa@4327 | 52 | |
jmasa@4327 | 53 | #ifdef ASSERT |
jmasa@4327 | 54 | size_t Metablock::_overhead = |
jmasa@4327 | 55 | Chunk::aligned_overhead_size(sizeof(Metablock)) / BytesPerWord; |
jmasa@4327 | 56 | #else |
jmasa@4327 | 57 | size_t Metablock::_overhead = 0; |
jmasa@4327 | 58 | #endif |
jmasa@4327 | 59 | |
jmasa@4327 | 60 | // New blocks returned by the Metaspace are zero initialized. |
jmasa@4327 | 61 | // We should fix the constructors to not assume this instead. |
jmasa@4327 | 62 | Metablock* Metablock::initialize(MetaWord* p, size_t word_size) { |
jmasa@4327 | 63 | if (p == NULL) { |
jmasa@4327 | 64 | return NULL; |
jmasa@4327 | 65 | } |
jmasa@4327 | 66 | |
jmasa@4327 | 67 | Metablock* result = (Metablock*) p; |
jmasa@4327 | 68 | |
jmasa@4327 | 69 | // Clear the memory |
jmasa@4327 | 70 | Copy::fill_to_aligned_words((HeapWord*)result, word_size); |
jmasa@4327 | 71 | #ifdef ASSERT |
jmasa@4327 | 72 | result->set_word_size(word_size); |
jmasa@4327 | 73 | #endif |
jmasa@4327 | 74 | return result; |
jmasa@4327 | 75 | } |