hotspot/src/share/vm/memory/padded.inline.hpp
changeset 35898 ddc274f0052f
parent 30578 8b6c44532ca2
child 46619 a3919f5e8d2b
equal deleted inserted replaced
35897:beba2418d973 35898:ddc274f0052f
     1 /*
     1 /*
     2  * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    39 
    39 
    40   // Allocate a chunk of memory large enough to allow for some alignment.
    40   // Allocate a chunk of memory large enough to allow for some alignment.
    41   void* chunk = AllocateHeap(length * sizeof(PaddedEnd<T, alignment>) + alignment, flags);
    41   void* chunk = AllocateHeap(length * sizeof(PaddedEnd<T, alignment>) + alignment, flags);
    42 
    42 
    43   // Make the initial alignment.
    43   // Make the initial alignment.
    44   PaddedEnd<T>* aligned_padded_array = (PaddedEnd<T>*)align_pointer_up(chunk, alignment);
    44   PaddedEnd<T>* aligned_padded_array = (PaddedEnd<T>*)align_ptr_up(chunk, alignment);
    45 
    45 
    46   // Call the default constructor for each element.
    46   // Call the default constructor for each element.
    47   for (uint i = 0; i < length; i++) {
    47   for (uint i = 0; i < length; i++) {
    48     ::new (&aligned_padded_array[i]) T();
    48     ::new (&aligned_padded_array[i]) T();
    49   }
    49   }
    63   // Allocate a chunk of memory large enough to allow alignment of the chunk.
    63   // Allocate a chunk of memory large enough to allow alignment of the chunk.
    64   void* chunk = AllocateHeap(total_size, flags);
    64   void* chunk = AllocateHeap(total_size, flags);
    65   // Clear the allocated memory.
    65   // Clear the allocated memory.
    66   memset(chunk, 0, total_size);
    66   memset(chunk, 0, total_size);
    67   // Align the chunk of memory.
    67   // Align the chunk of memory.
    68   T** result = (T**)align_pointer_up(chunk, alignment);
    68   T** result = (T**)align_ptr_up(chunk, alignment);
    69   void* data_start = (void*)((uintptr_t)result + table_size);
    69   void* data_start = (void*)((uintptr_t)result + table_size);
    70 
    70 
    71   // Fill in the row table.
    71   // Fill in the row table.
    72   for (size_t i = 0; i < rows; i++) {
    72   for (size_t i = 0; i < rows; i++) {
    73     result[i] = (T*)((uintptr_t)data_start + i * row_size);
    73     result[i] = (T*)((uintptr_t)data_start + i * row_size);
    85   // Allocate a chunk of memory large enough to allow for some alignment.
    85   // Allocate a chunk of memory large enough to allow for some alignment.
    86   void* chunk = AllocateHeap(length * sizeof(T) + alignment, flags);
    86   void* chunk = AllocateHeap(length * sizeof(T) + alignment, flags);
    87 
    87 
    88   memset(chunk, 0, length * sizeof(T) + alignment);
    88   memset(chunk, 0, length * sizeof(T) + alignment);
    89 
    89 
    90   return (T*)align_pointer_up(chunk, alignment);
    90   return (T*)align_ptr_up(chunk, alignment);
    91 }
    91 }
    92 
    92 
    93 #endif // SHARE_VM_MEMORY_PADDED_INLINE_HPP
    93 #endif // SHARE_VM_MEMORY_PADDED_INLINE_HPP