stefank@5515: /* stefank@5515: * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. stefank@5515: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. stefank@5515: * stefank@5515: * This code is free software; you can redistribute it and/or modify it stefank@5515: * under the terms of the GNU General Public License version 2 only, as stefank@5515: * published by the Free Software Foundation. stefank@5515: * stefank@5515: * This code is distributed in the hope that it will be useful, but WITHOUT stefank@5515: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or stefank@5515: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License stefank@5515: * version 2 for more details (a copy is included in the LICENSE file that stefank@5515: * accompanied this code). stefank@5515: * stefank@5515: * You should have received a copy of the GNU General Public License version stefank@5515: * 2 along with this work; if not, write to the Free Software Foundation, stefank@5515: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. stefank@5515: * stefank@5515: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA stefank@5515: * or visit www.oracle.com if you need additional information or have any stefank@5515: * questions. stefank@5515: * stefank@5515: */ stefank@5515: stefank@5515: #include "memory/allocation.inline.hpp" stefank@5515: #include "memory/padded.hpp" stefank@5515: #include "utilities/debug.hpp" stefank@5515: #include "utilities/globalDefinitions.hpp" stefank@5515: stefank@5515: // Creates an aligned padded array. stefank@5515: // The memory can't be deleted since the raw memory chunk is not returned. stefank@5515: template stefank@5515: PaddedEnd* PaddedArray::create_unfreeable(uint length) { stefank@5515: // Check that the PaddedEnd class works as intended. stefank@5515: STATIC_ASSERT(is_size_aligned_(sizeof(PaddedEnd), alignment)); stefank@5515: stefank@5515: // Allocate a chunk of memory large enough to allow for some alignment. stefank@5515: void* chunk = AllocateHeap(length * sizeof(PaddedEnd) + alignment, flags); stefank@5515: stefank@5515: // Make the initial alignment. stefank@5515: PaddedEnd* aligned_padded_array = (PaddedEnd*)align_pointer_up(chunk, alignment); stefank@5515: stefank@5515: // Call the default constructor for each element. stefank@5515: for (uint i = 0; i < length; i++) { stefank@5515: ::new (&aligned_padded_array[i]) T(); stefank@5515: } stefank@5515: stefank@5515: return aligned_padded_array; stefank@5515: }