annotate src/share/vm/memory/padded.hpp @ 5264:24e87613ee58

8009561: NPG: Metaspace fragmentation when retiring a Metachunk Summary: Use best-fit block-splitting freelist allocation from the block freelist. Reviewed-by: jmasa, stefank
author mgerdin
date Wed, 11 Sep 2013 09:37:14 +0200
parents
children
rev   line source
stefank@5080 1 /*
stefank@5080 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
stefank@5080 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
stefank@5080 4 *
stefank@5080 5 * This code is free software; you can redistribute it and/or modify it
stefank@5080 6 * under the terms of the GNU General Public License version 2 only, as
stefank@5080 7 * published by the Free Software Foundation.
stefank@5080 8 *
stefank@5080 9 * This code is distributed in the hope that it will be useful, but WITHOUT
stefank@5080 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
stefank@5080 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
stefank@5080 12 * version 2 for more details (a copy is included in the LICENSE file that
stefank@5080 13 * accompanied this code).
stefank@5080 14 *
stefank@5080 15 * You should have received a copy of the GNU General Public License version
stefank@5080 16 * 2 along with this work; if not, write to the Free Software Foundation,
stefank@5080 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
stefank@5080 18 *
stefank@5080 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
stefank@5080 20 * or visit www.oracle.com if you need additional information or have any
stefank@5080 21 * questions.
stefank@5080 22 *
stefank@5080 23 */
stefank@5080 24
stefank@5080 25 #ifndef SHARE_VM_MEMORY_PADDED_HPP
stefank@5080 26 #define SHARE_VM_MEMORY_PADDED_HPP
stefank@5080 27
stefank@5080 28 #include "memory/allocation.hpp"
stefank@5080 29 #include "utilities/globalDefinitions.hpp"
stefank@5080 30
stefank@5080 31 // Bytes needed to pad type to avoid cache-line sharing; alignment should be the
stefank@5080 32 // expected cache line size (a power of two). The first addend avoids sharing
stefank@5080 33 // when the start address is not a multiple of alignment; the second maintains
stefank@5080 34 // alignment of starting addresses that happen to be a multiple.
stefank@5080 35 #define PADDING_SIZE(type, alignment) \
stefank@5080 36 ((alignment) + align_size_up_(sizeof(type), alignment))
stefank@5080 37
stefank@5080 38 // Templates to create a subclass padded to avoid cache line sharing. These are
stefank@5080 39 // effective only when applied to derived-most (leaf) classes.
stefank@5080 40
stefank@5080 41 // When no args are passed to the base ctor.
stefank@5080 42 template <class T, size_t alignment = DEFAULT_CACHE_LINE_SIZE>
stefank@5080 43 class Padded : public T {
stefank@5080 44 private:
stefank@5080 45 char _pad_buf_[PADDING_SIZE(T, alignment)];
stefank@5080 46 };
stefank@5080 47
stefank@5080 48 // When either 0 or 1 args may be passed to the base ctor.
stefank@5080 49 template <class T, typename Arg1T, size_t alignment = DEFAULT_CACHE_LINE_SIZE>
stefank@5080 50 class Padded01 : public T {
stefank@5080 51 public:
stefank@5080 52 Padded01(): T() { }
stefank@5080 53 Padded01(Arg1T arg1): T(arg1) { }
stefank@5080 54 private:
stefank@5080 55 char _pad_buf_[PADDING_SIZE(T, alignment)];
stefank@5080 56 };
stefank@5080 57
stefank@5080 58 // Super class of PaddedEnd when pad_size != 0.
stefank@5080 59 template <class T, size_t pad_size>
stefank@5080 60 class PaddedEndImpl : public T {
stefank@5080 61 private:
stefank@5080 62 char _pad_buf[pad_size];
stefank@5080 63 };
stefank@5080 64
stefank@5080 65 // Super class of PaddedEnd when pad_size == 0.
stefank@5080 66 template <class T>
stefank@5080 67 class PaddedEndImpl<T, /*pad_size*/ 0> : public T {
stefank@5080 68 // No padding.
stefank@5080 69 };
stefank@5080 70
stefank@5080 71 #define PADDED_END_SIZE(type, alignment) (align_size_up_(sizeof(type), alignment) - sizeof(type))
stefank@5080 72
stefank@5080 73 // More memory conservative implementation of Padded. The subclass adds the
stefank@5080 74 // minimal amount of padding needed to make the size of the objects be aligned.
stefank@5080 75 // This will help reducing false sharing,
stefank@5080 76 // if the start address is a multiple of alignment.
stefank@5080 77 template <class T, size_t alignment = DEFAULT_CACHE_LINE_SIZE>
stefank@5080 78 class PaddedEnd : public PaddedEndImpl<T, PADDED_END_SIZE(T, alignment)> {
stefank@5080 79 // C++ don't allow zero-length arrays. The padding is put in a
stefank@5080 80 // super class that is specialized for the pad_size == 0 case.
stefank@5080 81 };
stefank@5080 82
stefank@5080 83 // Helper class to create an array of PaddedEnd<T> objects. All elements will
stefank@5080 84 // start at a multiple of alignment and the size will be aligned to alignment.
stefank@5080 85 template <class T, MEMFLAGS flags, size_t alignment = DEFAULT_CACHE_LINE_SIZE>
stefank@5080 86 class PaddedArray {
stefank@5080 87 public:
stefank@5080 88 // Creates an aligned padded array.
stefank@5080 89 // The memory can't be deleted since the raw memory chunk is not returned.
stefank@5080 90 static PaddedEnd<T>* create_unfreeable(uint length);
stefank@5080 91 };
stefank@5080 92
stefank@5080 93 #endif // SHARE_VM_MEMORY_PADDED_HPP