summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorMatthias Huetsch [mhu] <matthias.huetsch@oracle.com>2011-01-27 14:36:05 +0100
committerMatthias Huetsch [mhu] <matthias.huetsch@oracle.com>2011-01-27 14:36:05 +0100
commit3859e8f28b464409015d8a2a3c6facb1d56b7632 (patch)
treed6144497b82a2ae2e4f1c5a9ada508089e2cae6a /sal
parent45afa697bd2f8a7a698a44328fc39a806393653e (diff)
#i115784# sal/rtl/alloc: improved support for valgrind(memcheck).
Diffstat (limited to 'sal')
-rw-r--r--sal/rtl/source/alloc_arena.c18
-rw-r--r--sal/rtl/source/alloc_cache.c29
-rwxr-xr-xsal/rtl/source/alloc_fini.cxx (renamed from sal/rtl/source/memory_fini.cxx)23
-rw-r--r--sal/rtl/source/alloc_global.c8
-rw-r--r--sal/rtl/source/alloc_impl.h1
-rw-r--r--sal/rtl/source/makefile.mk4
6 files changed, 61 insertions, 22 deletions
diff --git a/sal/rtl/source/alloc_arena.c b/sal/rtl/source/alloc_arena.c
index e2735cc014e4..ec516f3573ac 100644
--- a/sal/rtl/source/alloc_arena.c
+++ b/sal/rtl/source/alloc_arena.c
@@ -1109,9 +1109,10 @@ SAL_CALL rtl_arena_free (
{
rtl_arena_segment_type *next, *prev;
- /* DEBUG ONLY: mark undefined, unallocated */
- OSL_DEBUG_ONLY(memset((void*)(segment->m_addr), 0x33333333, segment->m_size));
+ /* DEBUG ONLY: mark unallocated, undefined */
VALGRIND_MEMPOOL_FREE(arena, segment->m_addr);
+ VALGRIND_MAKE_MEM_UNDEFINED(segment->m_addr, segment->m_size);
+ OSL_DEBUG_ONLY(memset((void*)(segment->m_addr), 0x33333333, segment->m_size));
/* coalesce w/ adjacent free segment(s) */
rtl_arena_segment_coalesce (arena, segment);
@@ -1366,7 +1367,18 @@ rtl_arena_init (void)
/* ================================================================= */
-#if defined(__GNUC__)
+/*
+ Issue http://udk.openoffice.org/issues/show_bug.cgi?id=92388
+
+ Mac OS X does not seem to support "__cxa__atexit", thus leading
+ to the situation that "__attribute__((destructor))__" functions
+ (in particular "rtl_{memory|cache|arena}_fini") become called
+ _before_ global C++ object d'tors.
+
+ Delegated the call to "rtl_arena_fini()" into a dummy C++ object,
+ see alloc_fini.cxx .
+*/
+#if defined(__GNUC__) && !defined(MACOSX)
static void rtl_arena_fini (void) __attribute__((destructor));
#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
#pragma fini(rtl_arena_fini)
diff --git a/sal/rtl/source/alloc_cache.c b/sal/rtl/source/alloc_cache.c
index db02c79d5ba7..563e777873d6 100644
--- a/sal/rtl/source/alloc_cache.c
+++ b/sal/rtl/source/alloc_cache.c
@@ -534,9 +534,9 @@ rtl_cache_slab_free (
RTL_MEMORY_LOCK_ACQUIRE(&(cache->m_slab_lock));
/* DEBUG ONLY: mark unallocated, undefined */
- OSL_DEBUG_ONLY(memset(addr, 0x33333333, cache->m_type_size));
VALGRIND_MEMPOOL_FREE(cache, addr);
VALGRIND_MAKE_MEM_UNDEFINED(addr, cache->m_type_size);
+ OSL_DEBUG_ONLY(memset(addr, 0x33333333, cache->m_type_size));
/* determine slab from addr */
if (cache->m_features & RTL_CACHE_FEATURE_HASH)
@@ -644,8 +644,13 @@ rtl_cache_magazine_clear (
void * obj = mag->m_objects[mag->m_mag_used - 1];
mag->m_objects[mag->m_mag_used - 1] = 0;
+ /* mark cached object allocated, undefined */
+ VALGRIND_MEMPOOL_ALLOC(cache, obj, cache->m_type_size);
if (cache->m_destructor != 0)
{
+ /* keep constructed object defined */
+ VALGRIND_MAKE_MEM_DEFINED(obj, cache->m_type_size);
+
/* destruct object */
(cache->m_destructor)(obj, cache->m_userarg);
}
@@ -1218,7 +1223,14 @@ SAL_CALL rtl_cache_alloc (
if ((curr != 0) && (curr->m_mag_used > 0))
{
obj = curr->m_objects[--curr->m_mag_used];
+#if defined(HAVE_VALGRIND_MEMCHECK_H)
VALGRIND_MEMPOOL_ALLOC(cache, obj, cache->m_type_size);
+ if (cache->m_constructor != 0)
+ {
+ /* keep constructed object defined */
+ VALGRIND_MAKE_MEM_DEFINED(obj, cache->m_type_size);
+ }
+#endif /* HAVE_VALGRIND_MEMCHECK_H */
cache->m_cpu_stats.m_alloc += 1;
RTL_MEMORY_LOCK_RELEASE(&(cache->m_depot_lock));
@@ -1286,7 +1298,9 @@ SAL_CALL rtl_cache_free (
if ((curr != 0) && (curr->m_mag_used < curr->m_mag_size))
{
curr->m_objects[curr->m_mag_used++] = obj;
+#if defined(HAVE_VALGRIND_MEMCHECK_H)
VALGRIND_MEMPOOL_FREE(cache, obj);
+#endif /* HAVE_VALGRIND_MEMCHECK_H */
cache->m_cpu_stats.m_free += 1;
RTL_MEMORY_LOCK_RELEASE(&(cache->m_depot_lock));
@@ -1678,7 +1692,18 @@ rtl_cache_init (void)
/* ================================================================= */
-#if defined(__GNUC__)
+/*
+ Issue http://udk.openoffice.org/issues/show_bug.cgi?id=92388
+
+ Mac OS X does not seem to support "__cxa__atexit", thus leading
+ to the situation that "__attribute__((destructor))__" functions
+ (in particular "rtl_{memory|cache|arena}_fini") become called
+ _before_ global C++ object d'tors.
+
+ Delegated the call to "rtl_cache_fini()" into a dummy C++ object,
+ see alloc_fini.cxx .
+*/
+#if defined(__GNUC__) && !defined(MACOSX)
static void rtl_cache_fini (void) __attribute__((destructor));
#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
#pragma fini(rtl_cache_fini)
diff --git a/sal/rtl/source/memory_fini.cxx b/sal/rtl/source/alloc_fini.cxx
index f88f09887595..cb04a525e75e 100755
--- a/sal/rtl/source/memory_fini.cxx
+++ b/sal/rtl/source/alloc_fini.cxx
@@ -25,30 +25,31 @@
*
************************************************************************/
-
/*
Issue http://udk.openoffice.org/issues/show_bug.cgi?id=92388
Mac OS X does not seem to support "__cxa__atexit", thus leading
to the situation that "__attribute__((destructor))__" functions
- (in particular "rtl_memory_fini") become called _before_ global
- C++ object d'tors.
+ (in particular "rtl_{memory|cache|arena}_fini") become called
+ _before_ global C++ object d'tors.
Using a C++ dummy object instead.
*/
-#include <stdio.h>
-
extern "C" void rtl_memory_fini (void);
+extern "C" void rtl_cache_fini (void);
+extern "C" void rtl_arena_fini (void);
-
-struct RTL_Memory_Fini {
- ~RTL_Memory_Fini() ;
+struct RTL_Alloc_Fini
+{
+ ~RTL_Alloc_Fini() ;
};
-RTL_Memory_Fini::~RTL_Memory_Fini() {
+RTL_Alloc_Fini::~RTL_Alloc_Fini()
+{
rtl_memory_fini();
+ rtl_cache_fini();
+ rtl_arena_fini();
}
-
-static RTL_Memory_Fini rtl_Memory_Fini;
+static RTL_Alloc_Fini g_RTL_Alloc_Fini;
diff --git a/sal/rtl/source/alloc_global.c b/sal/rtl/source/alloc_global.c
index 5137f868127d..57f3ec52dbd7 100644
--- a/sal/rtl/source/alloc_global.c
+++ b/sal/rtl/source/alloc_global.c
@@ -151,11 +151,11 @@ rtl_memory_init (void)
Mac OS X does not seem to support "__cxa__atexit", thus leading
to the situation that "__attribute__((destructor))__" functions
- (in particular "rtl_memory_fini") become called _before_ global
- C++ object d'tors.
+ (in particular "rtl_{memory|cache|arena}_fini") become called
+ _before_ global C++ object d'tors.
- Delegated the call to "rtl_memory_fini" into a dummy C++ object,
- see memory_fini.cxx .
+ Delegated the call to "rtl_memory_fini()" into a dummy C++ object,
+ see alloc_fini.cxx .
*/
#if defined(__GNUC__) && !defined(MACOSX)
static void rtl_memory_fini (void) __attribute__((destructor));
diff --git a/sal/rtl/source/alloc_impl.h b/sal/rtl/source/alloc_impl.h
index fcebdf4369cc..93f8330451d6 100644
--- a/sal/rtl/source/alloc_impl.h
+++ b/sal/rtl/source/alloc_impl.h
@@ -250,6 +250,7 @@ typedef CRITICAL_SECTION rtl_memory_lock_type;
#if defined(NVALGRIND)
#define VALGRIND_MAKE_MEM_UNDEFINED(addr, size)
+#define VALGRIND_MAKE_MEM_DEFINED(addr, size)
#define VALGRIND_MALLOCLIKE_BLOCK(addr, sizeB, rzB, is_zeroed)
#define VALGRIND_FREELIKE_BLOCK(addr, rzB)
#define VALGRIND_CREATE_MEMPOOL(pool, rzB, is_zeroed)
diff --git a/sal/rtl/source/makefile.mk b/sal/rtl/source/makefile.mk
index 9968d8992be4..5aaf29ae7d50 100644
--- a/sal/rtl/source/makefile.mk
+++ b/sal/rtl/source/makefile.mk
@@ -96,7 +96,7 @@ SLOFILES= \
$(SLO)$/alloc_arena.obj
.IF "$(OS)"=="MACOSX"
-SLOFILES+=$(SLO)$/memory_fini.obj
+SLOFILES+=$(SLO)$/alloc_fini.obj
.ENDIF
@@ -129,7 +129,7 @@ OBJFILES= \
$(OBJ)$/alloc_arena.obj
.IF "$(OS)"=="MACOSX"
-OBJFILES+=$(OBJ)$/memory_fini.obj
+OBJFILES+=$(OBJ)$/alloc_fini.obj
.ENDIF