author | gziemski |
Wed, 08 May 2019 11:11:50 -0500 | |
changeset 54764 | 865ec913f916 |
parent 53404 | 9ff1e6cacac3 |
permissions | -rw-r--r-- |
19285
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50281
diff
changeset
|
2 |
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. |
19285
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
4 |
* |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
8 |
* |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
13 |
* accompanied this code). |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
14 |
* |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
18 |
* |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
21 |
* questions. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
22 |
* |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
23 |
*/ |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
24 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50281
diff
changeset
|
25 |
#ifndef SHARE_MEMORY_PADDED_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50281
diff
changeset
|
26 |
#define SHARE_MEMORY_PADDED_HPP |
19285
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
27 |
|
53404 | 28 |
#include "memory/allocation.hpp" |
46625 | 29 |
#include "utilities/align.hpp" |
19285
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
30 |
#include "utilities/globalDefinitions.hpp" |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
31 |
|
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
32 |
// Bytes needed to pad type to avoid cache-line sharing; alignment should be the |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
33 |
// expected cache line size (a power of two). The first addend avoids sharing |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
34 |
// when the start address is not a multiple of alignment; the second maintains |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
35 |
// alignment of starting addresses that happen to be a multiple. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
36 |
#define PADDING_SIZE(type, alignment) \ |
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
27165
diff
changeset
|
37 |
((alignment) + align_up_(sizeof(type), (alignment))) |
19285
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
38 |
|
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
39 |
// Templates to create a subclass padded to avoid cache line sharing. These are |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
40 |
// effective only when applied to derived-most (leaf) classes. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
41 |
|
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
42 |
// When no args are passed to the base ctor. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
43 |
template <class T, size_t alignment = DEFAULT_CACHE_LINE_SIZE> |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
44 |
class Padded : public T { |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
45 |
private: |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
46 |
char _pad_buf_[PADDING_SIZE(T, alignment)]; |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
47 |
}; |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
48 |
|
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
49 |
// When either 0 or 1 args may be passed to the base ctor. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
50 |
template <class T, typename Arg1T, size_t alignment = DEFAULT_CACHE_LINE_SIZE> |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
51 |
class Padded01 : public T { |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
52 |
public: |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
53 |
Padded01(): T() { } |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
54 |
Padded01(Arg1T arg1): T(arg1) { } |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
55 |
private: |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
56 |
char _pad_buf_[PADDING_SIZE(T, alignment)]; |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
57 |
}; |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
58 |
|
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
59 |
// Super class of PaddedEnd when pad_size != 0. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
60 |
template <class T, size_t pad_size> |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
61 |
class PaddedEndImpl : public T { |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
62 |
private: |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
63 |
char _pad_buf[pad_size]; |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
64 |
}; |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
65 |
|
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
66 |
// Super class of PaddedEnd when pad_size == 0. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
67 |
template <class T> |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
68 |
class PaddedEndImpl<T, /*pad_size*/ 0> : public T { |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
69 |
// No padding. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
70 |
}; |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
71 |
|
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
27165
diff
changeset
|
72 |
#define PADDED_END_SIZE(type, alignment) (align_up_(sizeof(type), (alignment)) - sizeof(type)) |
19285
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
73 |
|
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
74 |
// More memory conservative implementation of Padded. The subclass adds the |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
75 |
// minimal amount of padding needed to make the size of the objects be aligned. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
76 |
// This will help reducing false sharing, |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
77 |
// if the start address is a multiple of alignment. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
78 |
template <class T, size_t alignment = DEFAULT_CACHE_LINE_SIZE> |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
79 |
class PaddedEnd : public PaddedEndImpl<T, PADDED_END_SIZE(T, alignment)> { |
27165
785a8d56024c
8049737: Contended Locking reorder and cache line bucket
dcubed
parents:
23458
diff
changeset
|
80 |
// C++ doesn't allow zero-length arrays. The padding is put in a |
19285
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
81 |
// super class that is specialized for the pad_size == 0 case. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
82 |
}; |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
83 |
|
27165
785a8d56024c
8049737: Contended Locking reorder and cache line bucket
dcubed
parents:
23458
diff
changeset
|
84 |
// Similar to PaddedEnd, this macro defines a _pad_buf#id field |
785a8d56024c
8049737: Contended Locking reorder and cache line bucket
dcubed
parents:
23458
diff
changeset
|
85 |
// that is (alignment - size) bytes in size. This macro is used |
785a8d56024c
8049737: Contended Locking reorder and cache line bucket
dcubed
parents:
23458
diff
changeset
|
86 |
// to add padding in between non-class fields in a class or struct. |
785a8d56024c
8049737: Contended Locking reorder and cache line bucket
dcubed
parents:
23458
diff
changeset
|
87 |
#define DEFINE_PAD_MINUS_SIZE(id, alignment, size) \ |
785a8d56024c
8049737: Contended Locking reorder and cache line bucket
dcubed
parents:
23458
diff
changeset
|
88 |
char _pad_buf##id[(alignment) - (size)] |
785a8d56024c
8049737: Contended Locking reorder and cache line bucket
dcubed
parents:
23458
diff
changeset
|
89 |
|
19285
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
90 |
// Helper class to create an array of PaddedEnd<T> objects. All elements will |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
91 |
// start at a multiple of alignment and the size will be aligned to alignment. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
92 |
template <class T, MEMFLAGS flags, size_t alignment = DEFAULT_CACHE_LINE_SIZE> |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
93 |
class PaddedArray { |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
94 |
public: |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
95 |
// Creates an aligned padded array. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
96 |
// The memory can't be deleted since the raw memory chunk is not returned. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
97 |
static PaddedEnd<T>* create_unfreeable(uint length); |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
98 |
}; |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
99 |
|
23452
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
100 |
// Helper class to create an array of references to arrays of primitive types |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
101 |
// Both the array of references and the data arrays are aligned to the given |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
102 |
// alignment. The allocated memory is zero-filled. |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
103 |
template <class T, MEMFLAGS flags, size_t alignment = DEFAULT_CACHE_LINE_SIZE> |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
104 |
class Padded2DArray { |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
105 |
public: |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
106 |
// Creates an aligned padded 2D array. |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
107 |
// The memory cannot be deleted since the raw memory chunk is not returned. |
50281 | 108 |
// Always uses mmap to reserve memory. Only the first few pages with the index to |
109 |
// the rows are touched. Allocation size should be "large" to cover page overhead. |
|
23452
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
110 |
static T** create_unfreeable(uint rows, uint columns, size_t* allocation_size = NULL); |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
111 |
}; |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
112 |
|
23458
947a3d680f3e
8036860: Pad and cache-align the BiasedMappedArray
tschatzl
parents:
23452
diff
changeset
|
113 |
// Helper class to create an array of T objects. The array as a whole will |
947a3d680f3e
8036860: Pad and cache-align the BiasedMappedArray
tschatzl
parents:
23452
diff
changeset
|
114 |
// start at a multiple of alignment and its size will be aligned to alignment. |
947a3d680f3e
8036860: Pad and cache-align the BiasedMappedArray
tschatzl
parents:
23452
diff
changeset
|
115 |
template <class T, MEMFLAGS flags, size_t alignment = DEFAULT_CACHE_LINE_SIZE> |
947a3d680f3e
8036860: Pad and cache-align the BiasedMappedArray
tschatzl
parents:
23452
diff
changeset
|
116 |
class PaddedPrimitiveArray { |
947a3d680f3e
8036860: Pad and cache-align the BiasedMappedArray
tschatzl
parents:
23452
diff
changeset
|
117 |
public: |
947a3d680f3e
8036860: Pad and cache-align the BiasedMappedArray
tschatzl
parents:
23452
diff
changeset
|
118 |
static T* create_unfreeable(size_t length); |
947a3d680f3e
8036860: Pad and cache-align the BiasedMappedArray
tschatzl
parents:
23452
diff
changeset
|
119 |
}; |
947a3d680f3e
8036860: Pad and cache-align the BiasedMappedArray
tschatzl
parents:
23452
diff
changeset
|
120 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50281
diff
changeset
|
121 |
#endif // SHARE_MEMORY_PADDED_HPP |