comparison src/share/vm/memory/padded.inline.hpp @ 17754:d7070f371770

8035815: Cache-align and pad the from card cache Summary: The from card cache is a very frequently accessed data structure. It is essentially a 2d array of per-region values, one row of values for every GC thread. Pad and align the data structure to avoid false sharing. Reviewed-by: stefank
author tschatzl
date Mon, 24 Mar 2014 15:30:30 +0100
parents 9766f73e770d
children 5479cb006184
comparison
equal deleted inserted replaced
17753:191174b49bec 17754:d7070f371770
1 /* 1 /*
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 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. 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.
45 ::new (&aligned_padded_array[i]) T(); 45 ::new (&aligned_padded_array[i]) T();
46 } 46 }
47 47
48 return aligned_padded_array; 48 return aligned_padded_array;
49 } 49 }
50
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;
59
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);
67
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 }
72
73 if (allocation_size != NULL) {
74 *allocation_size = total_size;
75 }
76
77 return result;
78 }