diff options
author | kitty <kitty@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-02-26 04:58:19 +0000 |
---|---|---|
committer | kitty <kitty@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-02-26 04:58:19 +0000 |
commit | 74cb1db6ba6a9979c94cb3738eb406ef11fc51ff (patch) | |
tree | 5d05b985705b56e747ec99e85fe3f0613be38127 | |
parent | a8b5acade6aff4c9a7c6f4d82e57c6d11ba61f22 (diff) | |
download | ATCD-74cb1db6ba6a9979c94cb3738eb406ef11fc51ff.tar.gz |
Tue Feb 25 22:26:30 2003 Krishnakumar B <kitty@cs.wustl.edu>
-rw-r--r-- | ChangeLog | 44 | ||||
-rw-r--r-- | ace/Malloc.cpp | 4 | ||||
-rw-r--r-- | ace/Malloc.h | 74 | ||||
-rw-r--r-- | ace/Malloc_T.cpp | 4 | ||||
-rw-r--r-- | ace/OS_Memory.h | 4 | ||||
-rw-r--r-- | ace/PI_Malloc.cpp | 4 | ||||
-rw-r--r-- | ace/PI_Malloc.h | 26 | ||||
-rw-r--r-- | include/makeinclude/rules.lib.GNU | 2 |
8 files changed, 82 insertions, 80 deletions
diff --git a/ChangeLog b/ChangeLog index 179af2d3cc0..03cf49d22c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,47 @@ +Tue Feb 25 22:26:30 2003 Krishnakumar B <kitty@cs.wustl.edu> + + * ace/Malloc.h: + * ace/Malloc.cpp: + * ace/Malloc.h: + * ace/Malloc_T.cpp: + * ace/PI_Malloc.cpp: + * ace/PI_Malloc.h: + + Teach ACE_Control_Block and friends to do alignment on 64-bit + platforms. The previous code was buggy and caused a lot of bus + errors on platforms with greater than 4-byte alignment. We no + longer multiply and divide by sizeof (long) and do the alignment + based on sizeof (union ACE_max_align_info). This change also + makes the default alignment to be at 8-byte boundary (which is + ofcourse overridable) and errs in favour of safe code by default + vs optimization for code size. This should get rid of bug + reports on SGI IRIX, Solaris 64-bit etc related to + ACE_*_Allocator and friends. + + Also fixed a couple of rounding errors which result in core + dumps, in ACE_Cached_Allocator and ACE_Dynamic_Cached_Allocator + where we happily traverse memory irrespective of alignment of + the chunk_size. + + Thanks to Dave Mercer <mercer@itgssi.com> for reporting the + problem. + + One of the items from the long list of pending items post-5.3.1. + + * ace/OS_Memory.h: + + Removed the definition of ACE_MALLOC_ALIGN from this file. + ACE_MALLOC_ALIGN is an internal definition of Malloc.h and + should have no business in OS_Memory.h. + + * include/makeinclude/rules.lib.GNU: + + Use echo on VLOBJS instead of find with *.o. This fixes build + problems on lame platforms like MacOS X where ar doesn't + generate an index and need to use ranlib. Probably the right + thing to do even otherwise since there might be more objects in + .{sh,}obj than needed for a library. + Tue Feb 25 10:00:54 2003 Ossama Othman <ossama@uci.edu> * ace/CDR_Base.h (LongLong): diff --git a/ace/Malloc.cpp b/ace/Malloc.cpp index ea23fb7f871..a96c21c8e6e 100644 --- a/ace/Malloc.cpp +++ b/ace/Malloc.cpp @@ -48,7 +48,7 @@ ACE_Control_Block::print_alignment_info (void) ACE_LIB_TEXT ("Sizeof ACE_MALLOC_HEADER_SIZE: %d\n") ACE_LIB_TEXT ("Sizeof ACE_MALLOC_PADDING_SIZE: %d\n") ACE_LIB_TEXT ("Sizeof ACE_CONTROL_BLOCK_SIZE: %d\n") - ACE_LIB_TEXT ("Sizeof ACE_CONTROL_BLOCK_ALIGN_LONGS: %d\n") + ACE_LIB_TEXT ("Sizeof ACE_CONTROL_BLOCK_ALIGN_BYTES: %d\n") ACE_LIB_TEXT ("Sizeof (MALLOC_HEADER): %d\n") ACE_LIB_TEXT ("Sizeof (CONTROL_BLOCK): %d\n"), sizeof (char *), @@ -60,7 +60,7 @@ ACE_Control_Block::print_alignment_info (void) ACE_MALLOC_HEADER_SIZE, ACE_MALLOC_PADDING_SIZE, ACE_CONTROL_BLOCK_SIZE, - ACE_CONTROL_BLOCK_ALIGN_LONGS, + ACE_CONTROL_BLOCK_ALIGN_BYTES, sizeof (ACE_Malloc_Header), sizeof (ACE_Control_Block) )); diff --git a/ace/Malloc.h b/ace/Malloc.h index f682a20f0c1..eb2c65fa31b 100644 --- a/ace/Malloc.h +++ b/ace/Malloc.h @@ -59,26 +59,11 @@ typedef ACE_Atomic_Op<ACE_PROCESS_MUTEX, int> ACE_INT; } // The size is in number of | | // Malloc_Header (including this one.)| +-----------------------------------------+ - |long paddings_[ACE_MALLOC_PADDING_SIZE]; | - | // Padding long array. This purpose | + |char paddings_[ACE_MALLOC_PADDING_SIZE]; | + | // Padding array. This purpose | | // of this padding array is to adjust | | // the sizeof (Malloc_Header) to be | | // multiple of ACE_MALLOC_ALIGN. | - | // If you are sure that | - | // sizeof (MALLOC_HEADER_PTR) | - | // + sizeof (size_t) is a multiple | - | // of ACE_MALLOC_ALIGN, then you can | - | // #define ACE_MALLOC_PADDING_SIZE 0 | - | // to complete remove this data member| - | // from Malloc_Header. Otherwise, | - | // ACE will try to figure out the | - | // correct value of this macro. | - | // However, the calculation does not | - | // always do the right thing and in | - | // some rare cases, you'll need to | - | // tweak this value by defining the | - | // macro (ACE_MALLOC_PADDING_SIZE) | - | // explicitly. | +-----------------------------------------+ * Name_Node @@ -137,7 +122,7 @@ typedef ACE_Atomic_Op<ACE_PROCESS_MUTEX, int> ACE_INT; | // ACE_HAS_MALLOC_STATS is not | | | // defined. | | +-----------------------------------------+ | - |long align_[CONTROL_BLOCK_ALIGN_LONGS]; | | + |char align_[CONTROL_BLOCK_ALIGN_BYTES]; | | | // | | +-----------------------------------------+ | |Malloc_Header base_; |<--+ @@ -223,24 +208,30 @@ struct ACE_Export ACE_Malloc_Stats // ACE_MALLOC_PADDING allows you to insure that allocated regions are // at least <ACE_MALLOC_PADDING> bytes long. It is especially useful // when you want areas to be at least a page long, or 32K long, or -// something like that. It doesn't guarantee alignment to an address -// multiple, like 8-byte data alignment, etc. The allocated area's -// padding to your selected size is done with an added array of long[] -// and your compiler will decide how to align things in memory. +// something like that. #define ACE_MALLOC_PADDING 1 #endif /* ACE_MALLOC_PADDING */ +union ACE_max_align_info +{ + int (*i)(); + void* p; + long l; + double d; +}; + #if !defined (ACE_MALLOC_ALIGN) // Align the malloc header size to a multiple of a double. -#define ACE_MALLOC_ALIGN (sizeof (double)) +#define ACE_MALLOC_ALIGN (sizeof (ACE_max_align_info)) #endif /* ACE_MALLOC_ALIGN */ +#if !defined ACE_MALLOC_ROUNDUP +#define ACE_MALLOC_ROUNDUP(X, Y) ((X) + ((Y) - 1) & ~((Y) - 1)) +#endif + // ACE_MALLOC_HEADER_SIZE is the normalized malloc header size. -#define ACE_MALLOC_HEADER_SIZE (ACE_MALLOC_PADDING % ACE_MALLOC_ALIGN == 0 \ - ? ACE_MALLOC_PADDING \ - : (((ACE_MALLOC_PADDING / ACE_MALLOC_ALIGN) + 1) \ - * ACE_MALLOC_ALIGN)) +#define ACE_MALLOC_HEADER_SIZE ACE_MALLOC_ROUNDUP(ACE_MALLOC_PADDING, ACE_MALLOC_ALIGN) /** * @class ACE_Control_Block @@ -282,16 +273,10 @@ public: /// Size of this header control block. size_t size_; -#if defined (ACE_MALLOC_PADDING_SIZE) && (ACE_MALLOC_PADDING_SIZE == 0) - // No padding required. -#else # if !defined (ACE_MALLOC_PADDING_SIZE) -# define ACE_MALLOC_PADDING_SIZE ((int) (ACE_MALLOC_HEADER_SIZE - \ - (sizeof (ACE_Malloc_Header*) + sizeof (size_t)))\ - / (int) sizeof (long)) +# define ACE_MALLOC_PADDING_SIZE ACE_MALLOC_ROUNDUP (ACE_MALLOC_HEADER_SIZE + sizeof (ACE_Malloc_Header*) + sizeof (size_t), ACE_MALLOC_ALIGN) - (sizeof (ACE_Malloc_Header*) + sizeof (size_t)) # endif /* !ACE_MALLOC_PADDING_SIZE */ - long padding_[ACE_MALLOC_PADDING_SIZE < 1 ? 1 : ACE_MALLOC_PADDING_SIZE]; -#endif /* ACE_MALLOC_PADDING_SIZE && ACE_MALLOC_PADDING_SIZE == 0 */ + char padding_[(ACE_MALLOC_PADDING_SIZE) ? ACE_MALLOC_PADDING_SIZE : ACE_MALLOC_ALIGN]; /// Dump the state of the object. void dump (void) const; @@ -383,20 +368,11 @@ public: + MAXNAMELEN)) #endif /* ACE_HAS_MALLOC_STATS */ -// Notice the casting to int for <sizeof> otherwise unsigned int -// arithmetic is used and some awful things may happen. -#if defined (ACE_CONTROL_BLOCK_ALIGN_LONGS) && (ACE_CONTROL_BLOCK_ALIGN_LONGS == 0) - // No padding required in control block. -#else -# if !defined (ACE_CONTROL_BLOCK_ALIGN_LONGS) -# define ACE_CONTROL_BLOCK_ALIGN_LONGS \ - ((ACE_CONTROL_BLOCK_SIZE % ACE_MALLOC_ALIGN != 0 \ - ? ACE_MALLOC_ALIGN - (ACE_CONTROL_BLOCK_SIZE % ACE_MALLOC_ALIGN) \ - : ACE_MALLOC_ALIGN) / int (sizeof (long))) -# endif /* !ACE_CONTROL_BLOCK_ALIGN_LONGS */ - /// Force alignment. - long align_[ACE_CONTROL_BLOCK_ALIGN_LONGS < 1 ? 1 : ACE_CONTROL_BLOCK_ALIGN_LONGS]; -#endif /* ACE_CONTROL_BLOCK_ALIGN_LONGS && ACE_CONTROL_BLOCK_ALIGN_LONGS == 0 */ +# if !defined (ACE_CONTROL_BLOCK_ALIGN_BYTES) +# define ACE_CONTROL_BLOCK_ALIGN_BYTES \ + ACE_MALLOC_ROUNDUP (ACE_CONTROL_BLOCK_SIZE, ACE_MALLOC_ALIGN) - ACE_CONTROL_BLOCK_SIZE +# endif /* !ACE_CONTROL_BLOCK_ALIGN_BYTES */ + char align_[(ACE_CONTROL_BLOCK_ALIGN_BYTES) ? ACE_CONTROL_BLOCK_ALIGN_BYTES : ACE_MALLOC_ALIGN]; /// Dummy node used to anchor the freelist. This needs to come last... ACE_Malloc_Header base_; diff --git a/ace/Malloc_T.cpp b/ace/Malloc_T.cpp index faf7b0f942a..997af40ab62 100644 --- a/ace/Malloc_T.cpp +++ b/ace/Malloc_T.cpp @@ -35,8 +35,7 @@ ACE_Cached_Allocator<T, ACE_LOCK>::ACE_Cached_Allocator (size_t n_chunks) // require a default constructor on T - a requirement that is not in // previous versions of ACE size_t chunk_size = sizeof (T); - if (chunk_size % ACE_MALLOC_ALIGN != 0) - chunk_size += (ACE_MALLOC_ALIGN - (chunk_size % ACE_MALLOC_ALIGN)); + chunk_size = ACE_MALLOC_ROUNDUP (chunk_size, ACE_MALLOC_ALIGN); ACE_NEW (this->pool_, char[n_chunks * chunk_size]); @@ -64,6 +63,7 @@ ACE_Dynamic_Cached_Allocator<ACE_LOCK>::ACE_Dynamic_Cached_Allocator free_list_ (ACE_PURE_FREE_LIST), chunk_size_(chunk_size) { + chunk_size = ACE_MALLOC_ROUNDUP (chunk_size, ACE_MALLOC_ALIGN); ACE_NEW (this->pool_, char[n_chunks * chunk_size_]); for (size_t c = 0; diff --git a/ace/OS_Memory.h b/ace/OS_Memory.h index 77b735f2390..4fda98c1867 100644 --- a/ace/OS_Memory.h +++ b/ace/OS_Memory.h @@ -28,10 +28,6 @@ #include <stddef.h> #endif // ACE_HAS_WINCE -# if !defined (ACE_MALLOC_ALIGN) -# define ACE_MALLOC_ALIGN ((int) sizeof (long)) -# endif /* ACE_MALLOC_ALIGN */ - // Allow an installation to replace the lowest-level allocation // functions without changing the source of ACE. // diff --git a/ace/PI_Malloc.cpp b/ace/PI_Malloc.cpp index 0901fec9642..031d8b53d7e 100644 --- a/ace/PI_Malloc.cpp +++ b/ace/PI_Malloc.cpp @@ -44,7 +44,7 @@ ACE_PI_Control_Block::print_alignment_info (void) ACE_LIB_TEXT ("Sizeof ACE_MALLOC_HEADER_SIZE: %d\n") ACE_LIB_TEXT ("Sizeof ACE_PI_MALLOC_PADDING_SIZE: %d\n") ACE_LIB_TEXT ("Sizeof ACE_PI_CONTROL_BLOCK_SIZE: %d\n") - ACE_LIB_TEXT ("Sizeof ACE_PI_CONTROL_BLOCK_ALIGN_LONGS: %d\n") + ACE_LIB_TEXT ("Sizeof ACE_PI_CONTROL_BLOCK_ALIGN_BYTES: %d\n") ACE_LIB_TEXT ("Sizeof (MALLOC_HEADER): %d\n") ACE_LIB_TEXT ("Sizeof (CONTROL_BLOCK): %d\n"), sizeof (char *), @@ -56,7 +56,7 @@ ACE_PI_Control_Block::print_alignment_info (void) ACE_MALLOC_HEADER_SIZE, ACE_PI_MALLOC_PADDING_SIZE, ACE_PI_CONTROL_BLOCK_SIZE, - ACE_PI_CONTROL_BLOCK_ALIGN_LONGS, + ACE_PI_CONTROL_BLOCK_ALIGN_BYTES, sizeof (ACE_Malloc_Header), sizeof (ACE_PI_Control_Block) )); diff --git a/ace/PI_Malloc.h b/ace/PI_Malloc.h index bd65dc05e1d..f6d13443337 100644 --- a/ace/PI_Malloc.h +++ b/ace/PI_Malloc.h @@ -72,16 +72,10 @@ public: /// Size of this header control block. size_t size_; -#if defined (ACE_PI_MALLOC_PADDING_SIZE) && (ACE_PI_MALLOC_PADDING_SIZE == 0) - // No padding required for PI_Malloc_Header. -#else # if !defined (ACE_PI_MALLOC_PADDING_SIZE) -# define ACE_PI_MALLOC_PADDING_SIZE ((int) (ACE_MALLOC_HEADER_SIZE - \ - (sizeof (MALLOC_HEADER_PTR) + sizeof (size_t)))\ - / (int) sizeof (long)) +# define ACE_PI_MALLOC_PADDING_SIZE ACE_MALLOC_ROUNDUP (ACE_MALLOC_HEADER_SIZE + sizeof (MALLOC_HEADER_PTR) + sizeof (size_t), ACE_MALLOC_ALIGN) - (sizeof (MALLOC_HEADER_PTR) + sizeof (size_t)) # endif /* !ACE_PI_MALLOC_PADDING_SIZE */ - long padding_[ACE_PI_MALLOC_PADDING_SIZE < 1 ? 1 : ACE_PI_MALLOC_PADDING_SIZE]; -#endif /* ACE_PI_MALLOC_PADDING_SIZE && ACE_PI_MALLOC_PADDING_SIZE == 0 */ + char padding_[(ACE_PI_MALLOC_PADDING_SIZE) ? ACE_PI_MALLOC_PADDING_SIZE : ACE_MALLOC_ALIGN]; /// Dump the state of the object. void dump (void) const; @@ -179,20 +173,12 @@ public: + MAXNAMELEN)) #endif /* ACE_HAS_MALLOC_STATS */ -#if defined (ACE_PI_CONTROL_BLOCK_ALIGN_LONGS) && (ACE_PI_CONTROL_BLOCK_ALIGN_LONGS == 0) - // No padding required for PI_Control_Block. -#else -# if !defined (ACE_PI_CONTROL_BLOCK_ALIGN_LONGS) -// Notice the casting to int for <sizeof> otherwise unsigned int -// arithmetic is used and some awful things may happen. -# define ACE_PI_CONTROL_BLOCK_ALIGN_LONGS \ - ((ACE_PI_CONTROL_BLOCK_SIZE % ACE_MALLOC_ALIGN != 0 \ - ? ACE_MALLOC_ALIGN - (ACE_PI_CONTROL_BLOCK_SIZE % ACE_MALLOC_ALIGN) \ - : ACE_MALLOC_ALIGN) / int (sizeof (long))) +# if !defined (ACE_PI_CONTROL_BLOCK_ALIGN_BYTES) +# define ACE_PI_CONTROL_BLOCK_ALIGN_BYTES \ + ACE_MALLOC_ROUNDUP (ACE_PI_CONTROL_BLOCK_SIZE, ACE_MALLOC_ALIGN) - ACE_PI_CONTROL_BLOCK_SIZE # endif /* !ACE_PI_CONTROL_BLOCK_ALIGN_LONGS */ /// Force alignment. - long align_[ACE_PI_CONTROL_BLOCK_ALIGN_LONGS < 1 ? 1 : ACE_PI_CONTROL_BLOCK_ALIGN_LONGS]; -#endif /* ACE_PI_CONTROL_BLOCK_ALIGN_LONGS && ACE_PI_CONTROL_BLOCK_ALIGN_LONGS == 0 */ + char align_[(ACE_PI_CONTROL_BLOCK_ALIGN_BYTES) ? ACE_PI_CONTROL_BLOCK_ALIGN_BYTES : ACE_MALLOC_ALIGN]; /// Dummy node used to anchor the freelist. This needs to come last... ACE_Malloc_Header base_; diff --git a/include/makeinclude/rules.lib.GNU b/include/makeinclude/rules.lib.GNU index ba86550aa3d..3cdfee3518e 100644 --- a/include/makeinclude/rules.lib.GNU +++ b/include/makeinclude/rules.lib.GNU @@ -59,7 +59,7 @@ ifeq (1,$(ace_lib_prelink)) #### to lib files, for example. -$(LINK.cc) $(LINK_OUTPUT_FLAG) ace-templ_inst $? $(LDFLAGS) $(ACE_NUL_STDERR) endif # ace_lib_prelink - find $(VDIR) $(TMPINCDIR:%=%) -name "*.o" | xargs $(AR) $(ARFLAGS) $@; + echo $(TMPINCDIR:%=%/*.o) $? | xargs $(AR) $(ARFLAGS) $@; ifdef ibmcxx_build # This is required to get AIX IBM C/C++ to instantiate and compile the needed # templates. |