author | stefank |
Fri, 14 Feb 2014 09:29:56 +0100 | |
changeset 22883 | 5378704451dc |
parent 19285 | 0a3b3f115402 |
child 23452 | d7dca4e6b95d |
permissions | -rw-r--r-- |
19285
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
1 |
/* |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
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 |
|
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
25 |
#include "memory/allocation.inline.hpp" |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
26 |
#include "memory/padded.hpp" |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
27 |
#include "utilities/debug.hpp" |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
28 |
#include "utilities/globalDefinitions.hpp" |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
29 |
|
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
30 |
// Creates an aligned padded array. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
31 |
// 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
|
32 |
template <class T, MEMFLAGS flags, size_t alignment> |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
33 |
PaddedEnd<T>* PaddedArray<T, flags, alignment>::create_unfreeable(uint length) { |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
34 |
// Check that the PaddedEnd class works as intended. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
35 |
STATIC_ASSERT(is_size_aligned_(sizeof(PaddedEnd<T>), alignment)); |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
36 |
|
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
37 |
// Allocate a chunk of memory large enough to allow for some alignment. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
38 |
void* chunk = AllocateHeap(length * sizeof(PaddedEnd<T, alignment>) + alignment, flags); |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
39 |
|
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
40 |
// Make the initial alignment. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
41 |
PaddedEnd<T>* aligned_padded_array = (PaddedEnd<T>*)align_pointer_up(chunk, alignment); |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
42 |
|
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
43 |
// Call the default constructor for each element. |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
44 |
for (uint i = 0; i < length; i++) { |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
45 |
::new (&aligned_padded_array[i]) T(); |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
46 |
} |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
47 |
|
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
48 |
return aligned_padded_array; |
0a3b3f115402
8022880: False sharing between PSPromotionManager instances
stefank
parents:
diff
changeset
|
49 |
} |