src/share/vm/memory/padded.inline.hpp

changeset 6403
d7070f371770
parent 5515
9766f73e770d
child 6409
5479cb006184
     1.1 --- a/src/share/vm/memory/padded.inline.hpp	Mon Mar 24 15:30:14 2014 +0100
     1.2 +++ b/src/share/vm/memory/padded.inline.hpp	Mon Mar 24 15:30:30 2014 +0100
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -47,3 +47,32 @@
    1.11  
    1.12    return aligned_padded_array;
    1.13  }
    1.14 +
    1.15 +template <class T, MEMFLAGS flags, size_t alignment>
    1.16 +T** Padded2DArray<T, flags, alignment>::create_unfreeable(uint rows, uint columns, size_t* allocation_size) {
    1.17 +  // Calculate and align the size of the first dimension's table.
    1.18 +  size_t table_size = align_size_up_(rows * sizeof(T*), alignment);
    1.19 +  // The size of the separate rows.
    1.20 +  size_t row_size = align_size_up_(columns * sizeof(T), alignment);
    1.21 +  // Total size consists of the indirection table plus the rows.
    1.22 +  size_t total_size = table_size + rows * row_size + alignment;
    1.23 +
    1.24 +  // Allocate a chunk of memory large enough to allow alignment of the chunk.
    1.25 +  void* chunk = AllocateHeap(total_size, flags);
    1.26 +  // Clear the allocated memory.
    1.27 +  memset(chunk, 0, total_size);
    1.28 +  // Align the chunk of memory.
    1.29 +  T** result = (T**)align_pointer_up(chunk, alignment);
    1.30 +  void* data_start = (void*)((uintptr_t)result + table_size);
    1.31 +
    1.32 +  // Fill in the row table.
    1.33 +  for (size_t i = 0; i < rows; i++) {
    1.34 +    result[i] = (T*)((uintptr_t)data_start + i * row_size);
    1.35 +  }
    1.36 +
    1.37 +  if (allocation_size != NULL) {
    1.38 +    *allocation_size = total_size;
    1.39 +  }
    1.40 +
    1.41 +  return result;
    1.42 +}

mercurial