author | tschatzl |
Mon, 28 May 2018 11:13:21 +0200 | |
changeset 50281 | bc1336220671 |
parent 47216 | 71c04702a3d5 |
child 53244 | 9807daeb47c4 |
permissions | -rw-r--r-- |
19285
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
1 |
/* |
50281 | 2 |
* Copyright (c) 2013, 2018, 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 |
|
30578 | 25 |
#ifndef SHARE_VM_MEMORY_PADDED_INLINE_HPP |
26 |
#define SHARE_VM_MEMORY_PADDED_INLINE_HPP |
|
27 |
||
19285
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
28 |
#include "memory/allocation.inline.hpp" |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
29 |
#include "memory/padded.hpp" |
46625 | 30 |
#include "utilities/align.hpp" |
19285
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
31 |
#include "utilities/debug.hpp" |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
32 |
#include "utilities/globalDefinitions.hpp" |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
33 |
|
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
34 |
// Creates an aligned padded array. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
35 |
// 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
|
36 |
template <class T, MEMFLAGS flags, size_t alignment> |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
37 |
PaddedEnd<T>* PaddedArray<T, flags, alignment>::create_unfreeable(uint length) { |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
38 |
// Check that the PaddedEnd class works as intended. |
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
35898
diff
changeset
|
39 |
STATIC_ASSERT(is_aligned_(sizeof(PaddedEnd<T>), alignment)); |
19285
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
40 |
|
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
41 |
// Allocate a chunk of memory large enough to allow for some alignment. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
42 |
void* chunk = AllocateHeap(length * sizeof(PaddedEnd<T, alignment>) + alignment, flags); |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
43 |
|
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
44 |
// Make the initial alignment. |
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
35898
diff
changeset
|
45 |
PaddedEnd<T>* aligned_padded_array = (PaddedEnd<T>*)align_up(chunk, alignment); |
19285
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
46 |
|
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
47 |
// Call the default constructor for each element. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
48 |
for (uint i = 0; i < length; i++) { |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
49 |
::new (&aligned_padded_array[i]) T(); |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
50 |
} |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
51 |
|
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
52 |
return aligned_padded_array; |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
53 |
} |
23452
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
54 |
|
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
55 |
template <class T, MEMFLAGS flags, size_t alignment> |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
56 |
T** Padded2DArray<T, flags, alignment>::create_unfreeable(uint rows, uint columns, size_t* allocation_size) { |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
57 |
// Calculate and align the size of the first dimension's table. |
46622
910fc72c03e8
8178501: Replace usages of align macros with calls to the align inline functions
stefank
parents:
46619
diff
changeset
|
58 |
size_t table_size = align_up(rows * sizeof(T*), alignment); |
23452
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
59 |
// The size of the separate rows. |
46622
910fc72c03e8
8178501: Replace usages of align macros with calls to the align inline functions
stefank
parents:
46619
diff
changeset
|
60 |
size_t row_size = align_up(columns * sizeof(T), alignment); |
23452
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
61 |
// Total size consists of the indirection table plus the rows. |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
62 |
size_t total_size = table_size + rows * row_size + alignment; |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
63 |
|
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
64 |
// Allocate a chunk of memory large enough to allow alignment of the chunk. |
50281 | 65 |
void* chunk = MmapArrayAllocator<uint8_t>::allocate(total_size, flags); |
23452
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
66 |
// Clear the allocated memory. |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
67 |
// Align the chunk of memory. |
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
35898
diff
changeset
|
68 |
T** result = (T**)align_up(chunk, alignment); |
23452
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
69 |
void* data_start = (void*)((uintptr_t)result + table_size); |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
70 |
|
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
71 |
// Fill in the row table. |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
72 |
for (size_t i = 0; i < rows; i++) { |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
73 |
result[i] = (T*)((uintptr_t)data_start + i * row_size); |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
74 |
} |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
75 |
|
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
76 |
if (allocation_size != NULL) { |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
77 |
*allocation_size = total_size; |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
78 |
} |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
79 |
|
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
80 |
return result; |
d7dca4e6b95d
8035815: Cache-align and pad the from card cache
tschatzl
parents:
19285
diff
changeset
|
81 |
} |
23458
947a3d680f3e
8036860: Pad and cache-align the BiasedMappedArray
tschatzl
parents:
23452
diff
changeset
|
82 |
|
947a3d680f3e
8036860: Pad and cache-align the BiasedMappedArray
tschatzl
parents:
23452
diff
changeset
|
83 |
template <class T, MEMFLAGS flags, size_t alignment> |
947a3d680f3e
8036860: Pad and cache-align the BiasedMappedArray
tschatzl
parents:
23452
diff
changeset
|
84 |
T* PaddedPrimitiveArray<T, flags, alignment>::create_unfreeable(size_t length) { |
947a3d680f3e
8036860: Pad and cache-align the BiasedMappedArray
tschatzl
parents:
23452
diff
changeset
|
85 |
// Allocate a chunk of memory large enough to allow for some alignment. |
947a3d680f3e
8036860: Pad and cache-align the BiasedMappedArray
tschatzl
parents:
23452
diff
changeset
|
86 |
void* chunk = AllocateHeap(length * sizeof(T) + alignment, flags); |
947a3d680f3e
8036860: Pad and cache-align the BiasedMappedArray
tschatzl
parents:
23452
diff
changeset
|
87 |
|
947a3d680f3e
8036860: Pad and cache-align the BiasedMappedArray
tschatzl
parents:
23452
diff
changeset
|
88 |
memset(chunk, 0, length * sizeof(T) + alignment); |
947a3d680f3e
8036860: Pad and cache-align the BiasedMappedArray
tschatzl
parents:
23452
diff
changeset
|
89 |
|
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
35898
diff
changeset
|
90 |
return (T*)align_up(chunk, alignment); |
23458
947a3d680f3e
8036860: Pad and cache-align the BiasedMappedArray
tschatzl
parents:
23452
diff
changeset
|
91 |
} |
30578 | 92 |
|
93 |
#endif // SHARE_VM_MEMORY_PADDED_INLINE_HPP |