24 25 #ifndef SHARE_VM_MEMORY_PADDED_INLINE_HPP 26 #define SHARE_VM_MEMORY_PADDED_INLINE_HPP 27 28 #include "memory/allocation.inline.hpp" 29 #include "memory/padded.hpp" 30 #include "utilities/debug.hpp" 31 #include "utilities/globalDefinitions.hpp" 32 33 // Creates an aligned padded array. 34 // The memory can't be deleted since the raw memory chunk is not returned. 35 template <class T, MEMFLAGS flags, size_t alignment> 36 PaddedEnd<T>* PaddedArray<T, flags, alignment>::create_unfreeable(uint length) { 37 // Check that the PaddedEnd class works as intended. 38 STATIC_ASSERT(is_size_aligned_(sizeof(PaddedEnd<T>), alignment)); 39 40 // Allocate a chunk of memory large enough to allow for some alignment. 41 void* chunk = AllocateHeap(length * sizeof(PaddedEnd<T, alignment>) + alignment, flags); 42 43 // Make the initial alignment. 44 PaddedEnd<T>* aligned_padded_array = (PaddedEnd<T>*)align_pointer_up(chunk, alignment); 45 46 // Call the default constructor for each element. 47 for (uint i = 0; i < length; i++) { 48 ::new (&aligned_padded_array[i]) T(); 49 } 50 51 return aligned_padded_array; 52 } 53 54 template <class T, MEMFLAGS flags, size_t alignment> 55 T** Padded2DArray<T, flags, alignment>::create_unfreeable(uint rows, uint columns, size_t* allocation_size) { 56 // Calculate and align the size of the first dimension's table. 57 size_t table_size = align_size_up_(rows * sizeof(T*), alignment); 58 // The size of the separate rows. 59 size_t row_size = align_size_up_(columns * sizeof(T), alignment); 60 // Total size consists of the indirection table plus the rows. 61 size_t total_size = table_size + rows * row_size + alignment; 62 63 // Allocate a chunk of memory large enough to allow alignment of the chunk. 64 void* chunk = AllocateHeap(total_size, flags); 65 // Clear the allocated memory. 66 memset(chunk, 0, total_size); 67 // Align the chunk of memory. 68 T** result = (T**)align_pointer_up(chunk, alignment); 69 void* data_start = (void*)((uintptr_t)result + table_size); 70 71 // Fill in the row table. 72 for (size_t i = 0; i < rows; i++) { 73 result[i] = (T*)((uintptr_t)data_start + i * row_size); 74 } 75 76 if (allocation_size != NULL) { 77 *allocation_size = total_size; 78 } 79 80 return result; 81 } 82 83 template <class T, MEMFLAGS flags, size_t alignment> 84 T* PaddedPrimitiveArray<T, flags, alignment>::create_unfreeable(size_t length) { 85 // Allocate a chunk of memory large enough to allow for some alignment. 86 void* chunk = AllocateHeap(length * sizeof(T) + alignment, flags); 87 88 memset(chunk, 0, length * sizeof(T) + alignment); 89 90 return (T*)align_pointer_up(chunk, alignment); 91 } 92 93 #endif // SHARE_VM_MEMORY_PADDED_INLINE_HPP | 24 25 #ifndef SHARE_VM_MEMORY_PADDED_INLINE_HPP 26 #define SHARE_VM_MEMORY_PADDED_INLINE_HPP 27 28 #include "memory/allocation.inline.hpp" 29 #include "memory/padded.hpp" 30 #include "utilities/debug.hpp" 31 #include "utilities/globalDefinitions.hpp" 32 33 // Creates an aligned padded array. 34 // The memory can't be deleted since the raw memory chunk is not returned. 35 template <class T, MEMFLAGS flags, size_t alignment> 36 PaddedEnd<T>* PaddedArray<T, flags, alignment>::create_unfreeable(uint length) { 37 // Check that the PaddedEnd class works as intended. 38 STATIC_ASSERT(is_size_aligned_(sizeof(PaddedEnd<T>), alignment)); 39 40 // Allocate a chunk of memory large enough to allow for some alignment. 41 void* chunk = AllocateHeap(length * sizeof(PaddedEnd<T, alignment>) + alignment, flags); 42 43 // Make the initial alignment. 44 PaddedEnd<T>* aligned_padded_array = (PaddedEnd<T>*)align_ptr_up(chunk, alignment); 45 46 // Call the default constructor for each element. 47 for (uint i = 0; i < length; i++) { 48 ::new (&aligned_padded_array[i]) T(); 49 } 50 51 return aligned_padded_array; 52 } 53 54 template <class T, MEMFLAGS flags, size_t alignment> 55 T** Padded2DArray<T, flags, alignment>::create_unfreeable(uint rows, uint columns, size_t* allocation_size) { 56 // Calculate and align the size of the first dimension's table. 57 size_t table_size = align_size_up_(rows * sizeof(T*), alignment); 58 // The size of the separate rows. 59 size_t row_size = align_size_up_(columns * sizeof(T), alignment); 60 // Total size consists of the indirection table plus the rows. 61 size_t total_size = table_size + rows * row_size + alignment; 62 63 // Allocate a chunk of memory large enough to allow alignment of the chunk. 64 void* chunk = AllocateHeap(total_size, flags); 65 // Clear the allocated memory. 66 memset(chunk, 0, total_size); 67 // Align the chunk of memory. 68 T** result = (T**)align_ptr_up(chunk, alignment); 69 void* data_start = (void*)((uintptr_t)result + table_size); 70 71 // Fill in the row table. 72 for (size_t i = 0; i < rows; i++) { 73 result[i] = (T*)((uintptr_t)data_start + i * row_size); 74 } 75 76 if (allocation_size != NULL) { 77 *allocation_size = total_size; 78 } 79 80 return result; 81 } 82 83 template <class T, MEMFLAGS flags, size_t alignment> 84 T* PaddedPrimitiveArray<T, flags, alignment>::create_unfreeable(size_t length) { 85 // Allocate a chunk of memory large enough to allow for some alignment. 86 void* chunk = AllocateHeap(length * sizeof(T) + alignment, flags); 87 88 memset(chunk, 0, length * sizeof(T) + alignment); 89 90 return (T*)align_ptr_up(chunk, alignment); 91 } 92 93 #endif // SHARE_VM_MEMORY_PADDED_INLINE_HPP |