Thu, 26 Jun 2014 11:36:58 +0200
8047818: G1 HeapRegions can no longer be ContiguousSpaces
Summary: Change parent of G1OffsetTableContigSpace to CompactibleSpace, reimplement missing functionality
Reviewed-by: stefank, jmasa, tschatzl
1 /*
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
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 */
25 #include "memory/allocation.inline.hpp"
26 #include "memory/padded.hpp"
27 #include "utilities/debug.hpp"
28 #include "utilities/globalDefinitions.hpp"
30 // Creates an aligned padded array.
31 // The memory can't be deleted since the raw memory chunk is not returned.
32 template <class T, MEMFLAGS flags, size_t alignment>
33 PaddedEnd<T>* PaddedArray<T, flags, alignment>::create_unfreeable(uint length) {
34 // Check that the PaddedEnd class works as intended.
35 STATIC_ASSERT(is_size_aligned_(sizeof(PaddedEnd<T>), alignment));
37 // Allocate a chunk of memory large enough to allow for some alignment.
38 void* chunk = AllocateHeap(length * sizeof(PaddedEnd<T, alignment>) + alignment, flags);
40 // Make the initial alignment.
41 PaddedEnd<T>* aligned_padded_array = (PaddedEnd<T>*)align_pointer_up(chunk, alignment);
43 // Call the default constructor for each element.
44 for (uint i = 0; i < length; i++) {
45 ::new (&aligned_padded_array[i]) T();
46 }
48 return aligned_padded_array;
49 }
51 template <class T, MEMFLAGS flags, size_t alignment>
52 T** Padded2DArray<T, flags, alignment>::create_unfreeable(uint rows, uint columns, size_t* allocation_size) {
53 // Calculate and align the size of the first dimension's table.
54 size_t table_size = align_size_up_(rows * sizeof(T*), alignment);
55 // The size of the separate rows.
56 size_t row_size = align_size_up_(columns * sizeof(T), alignment);
57 // Total size consists of the indirection table plus the rows.
58 size_t total_size = table_size + rows * row_size + alignment;
60 // Allocate a chunk of memory large enough to allow alignment of the chunk.
61 void* chunk = AllocateHeap(total_size, flags);
62 // Clear the allocated memory.
63 memset(chunk, 0, total_size);
64 // Align the chunk of memory.
65 T** result = (T**)align_pointer_up(chunk, alignment);
66 void* data_start = (void*)((uintptr_t)result + table_size);
68 // Fill in the row table.
69 for (size_t i = 0; i < rows; i++) {
70 result[i] = (T*)((uintptr_t)data_start + i * row_size);
71 }
73 if (allocation_size != NULL) {
74 *allocation_size = total_size;
75 }
77 return result;
78 }
80 template <class T, MEMFLAGS flags, size_t alignment>
81 T* PaddedPrimitiveArray<T, flags, alignment>::create_unfreeable(size_t length) {
82 // Allocate a chunk of memory large enough to allow for some alignment.
83 void* chunk = AllocateHeap(length * sizeof(T) + alignment, flags);
85 memset(chunk, 0, length * sizeof(T) + alignment);
87 return (T*)align_pointer_up(chunk, alignment);
88 }