9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_MEMORY_PADDED_HPP
26 #define SHARE_VM_MEMORY_PADDED_HPP
27
28 #include "memory/allocation.hpp"
29 #include "utilities/globalDefinitions.hpp"
30
31 // Bytes needed to pad type to avoid cache-line sharing; alignment should be the
32 // expected cache line size (a power of two). The first addend avoids sharing
33 // when the start address is not a multiple of alignment; the second maintains
34 // alignment of starting addresses that happen to be a multiple.
35 #define PADDING_SIZE(type, alignment) \
36 ((alignment) + align_up_(sizeof(type), (alignment)))
37
38 // Templates to create a subclass padded to avoid cache line sharing. These are
39 // effective only when applied to derived-most (leaf) classes.
40
41 // When no args are passed to the base ctor.
42 template <class T, size_t alignment = DEFAULT_CACHE_LINE_SIZE>
43 class Padded : public T {
44 private:
45 char _pad_buf_[PADDING_SIZE(T, alignment)];
46 };
47
48 // When either 0 or 1 args may be passed to the base ctor.
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_MEMORY_PADDED_HPP
26 #define SHARE_VM_MEMORY_PADDED_HPP
27
28 #include "memory/allocation.hpp"
29 #include "utilities/align.hpp"
30 #include "utilities/globalDefinitions.hpp"
31
32 // Bytes needed to pad type to avoid cache-line sharing; alignment should be the
33 // expected cache line size (a power of two). The first addend avoids sharing
34 // when the start address is not a multiple of alignment; the second maintains
35 // alignment of starting addresses that happen to be a multiple.
36 #define PADDING_SIZE(type, alignment) \
37 ((alignment) + align_up_(sizeof(type), (alignment)))
38
39 // Templates to create a subclass padded to avoid cache line sharing. These are
40 // effective only when applied to derived-most (leaf) classes.
41
42 // When no args are passed to the base ctor.
43 template <class T, size_t alignment = DEFAULT_CACHE_LINE_SIZE>
44 class Padded : public T {
45 private:
46 char _pad_buf_[PADDING_SIZE(T, alignment)];
47 };
48
49 // When either 0 or 1 args may be passed to the base ctor.
|