diff options
author | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-01-08 01:38:53 +0000 |
---|---|---|
committer | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-01-08 01:38:53 +0000 |
commit | 918edee0cc707ee298d2bd321bc9520255d6e556 (patch) | |
tree | 99d520d9bf01e3e224cd7368050fd3f15ae9b119 /gcc/ggc-page.c | |
parent | e07cc1193abbf50775e7de2230bd054f3d7b339c (diff) | |
download | gcc-918edee0cc707ee298d2bd321bc9520255d6e556.tar.gz |
* ggc-page.c (max_alignment): New structure.
(MAX_ALIGNMENT): New macro.
(init_ggc): Use it to round up the sizes in the
extra_order_size_table.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@38791 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ggc-page.c')
-rw-r--r-- | gcc/ggc-page.c | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/gcc/ggc-page.c b/gcc/ggc-page.c index abe88d7d57d..73dc4d1b4c1 100644 --- a/gcc/ggc-page.c +++ b/gcc/ggc-page.c @@ -140,23 +140,12 @@ Boston, MA 02111-1307, USA. */ /* The size of an object on a page of the indicated ORDER. */ #define OBJECT_SIZE(ORDER) object_size_table[ORDER] -#ifdef NO_ALIGNMENT_PROBLEM - /* The number of extra orders, not corresponding to power-of-two sized objects. */ #define NUM_EXTRA_ORDERS \ (sizeof (extra_order_size_table) / sizeof (extra_order_size_table[0])) -#else /* !defined(NO_ALIGNMENT_PROBLEM) */ - -/* For now, we can't use this code because we don't ensure that the - objects returned are appropriately aligned. The problem is that - some tree_list sized things, for example, use */ -#define NUM_EXTRA_ORDERS 0 - -#endif /* !defined(NO_ALIGNMENT_PROBLEM) */ - /* The Ith entry is the maximum size of an object to be stored in the Ith extra order. Adding a new entry to this array is the *only* thing you need to do to add a new special allocation size. */ @@ -170,6 +159,26 @@ static const size_t extra_order_size_table[] = { #define NUM_ORDERS (HOST_BITS_PER_PTR + NUM_EXTRA_ORDERS) +/* We use this structure to determine the alignment required for + allocations. For power-of-two sized allocations, that's not a + problem, but it does matter for odd-sized allocations. */ + +struct max_alignment { + char c; + union { + HOST_WIDEST_INT i; +#ifdef HAVE_LONG_DOUBLE + long double d; +#else + double d; +#endif + } u; +}; + +/* The biggest alignment required. */ + +#define MAX_ALIGNMENT (offsetof (struct max_alignment, u)) + /* The Ith entry is the number of objects on a page or order I. */ static unsigned objects_per_page_table[NUM_ORDERS]; @@ -878,8 +887,14 @@ init_ggc () for (order = 0; order < HOST_BITS_PER_PTR; ++order) object_size_table[order] = (size_t) 1 << order; for (order = HOST_BITS_PER_PTR; order < NUM_ORDERS; ++order) - object_size_table[order] = - extra_order_size_table[order - HOST_BITS_PER_PTR]; + { + size_t s = extra_order_size_table[order - HOST_BITS_PER_PTR]; + + /* If S is not a multiple of the MAX_ALIGNMENT, then round it up + so that we're sure of getting aligned memory. */ + s = CEIL (s, MAX_ALIGNMENT) * MAX_ALIGNMENT; + object_size_table[order] = s; + } /* Initialize the objects-per-page table. */ for (order = 0; order < NUM_ORDERS; ++order) |