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