diff options
author | Jan Holesovsky <kendy@suse.cz> | 2011-03-23 16:59:59 +0100 |
---|---|---|
committer | Jan Holesovsky <kendy@suse.cz> | 2011-03-23 16:59:59 +0100 |
commit | 4be7cca60bc7cc0a066b7384d56624266dc0dfcf (patch) | |
tree | 990b1fda00fca6f26ff74fd29552687b4e3c37ed /sal/rtl | |
parent | 79a6c0f8a28b43c36c3b02dc5e116f2d17e92ef0 (diff) | |
parent | a24842b43a687808376f69d4bdbb45fcddde73c4 (diff) |
Merge commit 'ooo/DEV300_m103'
Conflicts:
codemaker/source/bonobowrappermaker/corbaoptions.cxx
codemaker/source/cppumaker/cppuoptions.cxx
codemaker/source/cunomaker/cunooptions.cxx
codemaker/source/idlmaker/idloptions.cxx
codemaker/source/javamaker/javaoptions.cxx
cppu/source/typelib/typelib.cxx
idlc/source/options.cxx
offapi/com/sun/star/util/PathSubstitution.idl
offapi/drafts/com/sun/star/form/ListEntryEvent.idl
offapi/drafts/com/sun/star/form/XBindableValue.idl
offapi/drafts/com/sun/star/form/XListEntryListener.idl
offapi/drafts/com/sun/star/form/XListEntrySink.idl
offapi/drafts/com/sun/star/form/XListEntrySource.idl
offapi/drafts/com/sun/star/form/XValueBinding.idl
registry/tools/checksingleton.cxx
registry/tools/options.hxx
registry/tools/regcompare.cxx
registry/tools/regmerge.cxx
sal/cppunittester/cppunittester.cxx
sal/osl/unx/socket.c
sal/osl/w32/diagnose.c
sal/prj/d.lst
sal/rtl/source/alloc_fini.cxx
sal/rtl/source/alloc_global.c
sal/rtl/source/makefile.mk
Diffstat (limited to 'sal/rtl')
-rw-r--r-- | sal/rtl/source/alloc_arena.c | 37 | ||||
-rw-r--r-- | sal/rtl/source/alloc_cache.c | 53 | ||||
-rw-r--r-- | sal/rtl/source/alloc_fini.cxx (renamed from sal/rtl/source/memory_fini.cxx) | 23 | ||||
-rw-r--r-- | sal/rtl/source/alloc_global.c | 2 | ||||
-rw-r--r-- | sal/rtl/source/alloc_impl.h | 24 | ||||
-rw-r--r-- | sal/rtl/source/makefile.mk | 9 |
6 files changed, 122 insertions, 26 deletions
diff --git a/sal/rtl/source/alloc_arena.c b/sal/rtl/source/alloc_arena.c index 6766cf91e18d..69b4b9cf3bdb 100644 --- a/sal/rtl/source/alloc_arena.c +++ b/sal/rtl/source/alloc_arena.c @@ -29,22 +29,13 @@ #define _BSD_SOURCE /* sys/mman.h: MAP_ANON */ #include "alloc_arena.h" -#ifndef INCLUDED_RTL_ARENA_IMPL_H #include "alloc_impl.h" -#endif #include "internal/once.h" #include "sal/macros.h" #include "osl/diagnose.h" -#ifndef INCLUDED_STRING_H #include <string.h> -#endif - -#ifndef INCLUDED_STDIO_H #include <stdio.h> -#endif - -#include "sal/types.h" #ifdef OS2 #undef OSL_TRACE @@ -953,6 +944,7 @@ try_alloc: if (result != 0) { rtl_arena_type * arena = result; + VALGRIND_CREATE_MEMPOOL(arena, 0, 0); rtl_arena_constructor (arena); if (!source_arena) @@ -975,6 +967,7 @@ try_alloc: { rtl_arena_deactivate (arena); rtl_arena_destructor (arena); + VALGRIND_DESTROY_MEMPOOL(arena); rtl_arena_free (gp_arena_arena, arena, size); } } @@ -1000,6 +993,7 @@ SAL_CALL rtl_arena_destroy ( { rtl_arena_deactivate (arena); rtl_arena_destructor (arena); + VALGRIND_DESTROY_MEMPOOL(arena); rtl_arena_free (gp_arena_arena, arena, sizeof(rtl_arena_type)); } } @@ -1055,6 +1049,10 @@ SAL_CALL rtl_arena_alloc ( rtl_arena_hash_insert (arena, segment); + /* DEBUG ONLY: mark allocated, undefined */ + OSL_DEBUG_ONLY(memset((void*)(segment->m_addr), 0x77777777, segment->m_size)); + VALGRIND_MEMPOOL_ALLOC(arena, segment->m_addr, segment->m_size); + (*pSize) = segment->m_size; addr = (void*)(segment->m_addr); } @@ -1098,6 +1096,11 @@ SAL_CALL rtl_arena_free ( { rtl_arena_segment_type *next, *prev; + /* DEBUG ONLY: mark unallocated, undefined */ + VALGRIND_MEMPOOL_FREE(arena, segment->m_addr); + /* OSL_DEBUG_ONLY() */ 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); @@ -1289,6 +1292,7 @@ rtl_arena_once_init (void) static rtl_arena_type g_machdep_arena; OSL_ASSERT(gp_machdep_arena == 0); + VALGRIND_CREATE_MEMPOOL(&g_machdep_arena, 0, 0); rtl_arena_constructor (&g_machdep_arena); gp_machdep_arena = rtl_arena_activate ( @@ -1305,6 +1309,7 @@ rtl_arena_once_init (void) static rtl_arena_type g_default_arena; OSL_ASSERT(gp_default_arena == 0); + VALGRIND_CREATE_MEMPOOL(&g_default_arena, 0, 0); rtl_arena_constructor (&g_default_arena); gp_default_arena = rtl_arena_activate ( @@ -1323,6 +1328,7 @@ rtl_arena_once_init (void) static rtl_arena_type g_arena_arena; OSL_ASSERT(gp_arena_arena == 0); + VALGRIND_CREATE_MEMPOOL(&g_arena_arena, 0, 0); rtl_arena_constructor (&g_arena_arena); gp_arena_arena = rtl_arena_activate ( @@ -1348,7 +1354,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 01d4e14961f8..9da21d32a3c9 100644 --- a/sal/rtl/source/alloc_cache.c +++ b/sal/rtl/source/alloc_cache.c @@ -508,6 +508,10 @@ rtl_cache_slab_alloc ( addr = (void*)rtl_cache_hash_insert (cache, bufctl); else addr = bufctl; + + /* DEBUG ONLY: mark allocated, undefined */ + OSL_DEBUG_ONLY(memset(addr, 0x77777777, cache->m_type_size)); + VALGRIND_MEMPOOL_ALLOC(cache, addr, cache->m_type_size); } RTL_MEMORY_LOCK_RELEASE(&(cache->m_slab_lock)); @@ -530,6 +534,11 @@ rtl_cache_slab_free ( RTL_MEMORY_LOCK_ACQUIRE(&(cache->m_slab_lock)); + /* DEBUG ONLY: mark unallocated, undefined */ + VALGRIND_MEMPOOL_FREE(cache, addr); + /* OSL_DEBUG_ONLY() */ 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) { @@ -636,8 +645,13 @@ rtl_cache_magazine_clear ( void * obj = mag->m_objects[mag->m_mag_used - 1]; mag->m_objects[mag->m_mag_used - 1] = 0; + /* DEBUG ONLY: mark cached object allocated, undefined */ + VALGRIND_MEMPOOL_ALLOC(cache, obj, cache->m_type_size); if (cache->m_destructor != 0) { + /* DEBUG ONLY: keep constructed object defined */ + VALGRIND_MAKE_MEM_DEFINED(obj, cache->m_type_size); + /* destruct object */ (cache->m_destructor)(obj, cache->m_userarg); } @@ -966,11 +980,16 @@ rtl_cache_deactivate ( rtl_cache_type * cache ) { + int active = 1; + /* remove from cache list */ RTL_MEMORY_LOCK_ACQUIRE(&(g_cache_list.m_lock)); + active = QUEUE_STARTED_NAMED(cache, cache_) == 0; QUEUE_REMOVE_NAMED(cache, cache_); RTL_MEMORY_LOCK_RELEASE(&(g_cache_list.m_lock)); + OSL_PRECOND(active, "rtl_cache_deactivate(): orphaned cache."); + /* cleanup magazine layer */ if (cache->m_magazine_cache != 0) { @@ -1122,6 +1141,7 @@ try_alloc: if (result != 0) { rtl_cache_type * cache = result; + VALGRIND_CREATE_MEMPOOL(cache, 0, 0); (void) rtl_cache_constructor (cache); if (!source) @@ -1149,6 +1169,7 @@ try_alloc: /* activation failed */ rtl_cache_deactivate (cache); rtl_cache_destructor (cache); + VALGRIND_DESTROY_MEMPOOL(cache); rtl_arena_free (gp_cache_arena, cache, size); } } @@ -1173,6 +1194,7 @@ void SAL_CALL rtl_cache_destroy ( { rtl_cache_deactivate (cache); rtl_cache_destructor (cache); + VALGRIND_DESTROY_MEMPOOL(cache); rtl_arena_free (gp_cache_arena, cache, sizeof(rtl_cache_type)); } } @@ -1201,6 +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)); @@ -1243,7 +1273,6 @@ SAL_CALL rtl_cache_alloc ( rtl_cache_slab_free (cache, obj), obj = 0; } } - return (obj); } @@ -1268,6 +1297,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)); @@ -1581,6 +1613,7 @@ rtl_cache_once_init (void) static rtl_cache_type g_cache_magazine_cache; OSL_ASSERT(gp_cache_magazine_cache == 0); + VALGRIND_CREATE_MEMPOOL(&g_cache_magazine_cache, 0, 0); (void) rtl_cache_constructor (&g_cache_magazine_cache); gp_cache_magazine_cache = rtl_cache_activate ( @@ -1605,6 +1638,7 @@ rtl_cache_once_init (void) static rtl_cache_type g_cache_slab_cache; OSL_ASSERT(gp_cache_slab_cache == 0); + VALGRIND_CREATE_MEMPOOL(&g_cache_slab_cache, 0, 0); (void) rtl_cache_constructor (&g_cache_slab_cache); gp_cache_slab_cache = rtl_cache_activate ( @@ -1626,6 +1660,7 @@ rtl_cache_once_init (void) static rtl_cache_type g_cache_bufctl_cache; OSL_ASSERT(gp_cache_bufctl_cache == 0); + VALGRIND_CREATE_MEMPOOL(&g_cache_bufctl_cache, 0, 0); (void) rtl_cache_constructor (&g_cache_bufctl_cache); gp_cache_bufctl_cache = rtl_cache_activate ( @@ -1656,7 +1691,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) @@ -1677,18 +1723,21 @@ rtl_cache_fini (void) cache = gp_cache_bufctl_cache, gp_cache_bufctl_cache = 0; rtl_cache_deactivate (cache); rtl_cache_destructor (cache); + VALGRIND_DESTROY_MEMPOOL(cache); } if (gp_cache_slab_cache != 0) { cache = gp_cache_slab_cache, gp_cache_slab_cache = 0; rtl_cache_deactivate (cache); rtl_cache_destructor (cache); + VALGRIND_DESTROY_MEMPOOL(cache); } if (gp_cache_magazine_cache != 0) { cache = gp_cache_magazine_cache, gp_cache_magazine_cache = 0; rtl_cache_deactivate (cache); rtl_cache_destructor (cache); + VALGRIND_DESTROY_MEMPOOL(cache); } if (gp_cache_arena != 0) { diff --git a/sal/rtl/source/memory_fini.cxx b/sal/rtl/source/alloc_fini.cxx index a0fb012ff6a5..aba5093a362d 100644 --- a/sal/rtl/source/memory_fini.cxx +++ b/sal/rtl/source/alloc_fini.cxx @@ -26,32 +26,33 @@ * ************************************************************************/ - /* 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; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/rtl/source/alloc_global.c b/sal/rtl/source/alloc_global.c index 5930e00e57a5..ac95c8e1b188 100644 --- a/sal/rtl/source/alloc_global.c +++ b/sal/rtl/source/alloc_global.c @@ -26,6 +26,7 @@ * ************************************************************************/ +#include "alloc_impl.h" #include "rtl/alloc.h" #include <sal/macros.h> @@ -63,7 +64,6 @@ static void determine_alloc_mode(void) * * ================================================================= */ -#include "alloc_impl.h" #include "internal/once.h" #include "sal/macros.h" #include "osl/diagnose.h" diff --git a/sal/rtl/source/alloc_impl.h b/sal/rtl/source/alloc_impl.h index 4a89e62af135..18073926399f 100644 --- a/sal/rtl/source/alloc_impl.h +++ b/sal/rtl/source/alloc_impl.h @@ -241,6 +241,30 @@ typedef CRITICAL_SECTION rtl_memory_lock_type; #define RTL_CACHE_FLAG_QUANTUMCACHE (2 << 13) /* used as arena quantum cache */ +/** Valgrind support macros. + */ +#if !defined(HAVE_MEMCHECK_H) || (OSL_DEBUG_LEVEL == 0) +#if !defined(NVALGRIND) +#define NVALGRIND 1 +#endif /* ! NVALGRIND */ +#endif /* ! HAVE_MEMCHECK_H || (OSL_DEBUG_LEVEL == 0) */ + +#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) +#define VALGRIND_DESTROY_MEMPOOL(pool) +#define VALGRIND_MEMPOOL_ALLOC(pool, addr, size) +#define VALGRIND_MEMPOOL_FREE(pool, addr) +#elif defined(HAVE_MEMCHECK_H) +#include <memcheck.h> +#if !defined(FORCE_SYSALLOC) +#define FORCE_SYSALLOC 1 +#endif /* !FORCE_SYSALLOC */ +#endif /* NVALGRIND || HAVE_MEMCHECK_H */ + #ifdef __cplusplus } #endif diff --git a/sal/rtl/source/makefile.mk b/sal/rtl/source/makefile.mk index 3121f184ba8b..67ae7f8d9177 100644 --- a/sal/rtl/source/makefile.mk +++ b/sal/rtl/source/makefile.mk @@ -46,6 +46,11 @@ TARGETTYPE=CUI .INCLUDE : settings.mk +.IF "$(VALGRIND_CFLAGS)" != "" +CFLAGS += $(VALGRIND_CFLAGS) +CDEFS += -DHAVE_MEMCHECK_H=1 +.ENDIF # VALGRIND_CFLAGS + .IF "$(ALLOC)" == "SYS_ALLOC" || "$(ALLOC)" == "TCMALLOC" || "$(ALLOC)" == "JEMALLOC" CDEFS+= -DFORCE_SYSALLOC .ENDIF @@ -98,7 +103,7 @@ SLOFILES= \ $(SLO)$/alloc_arena.obj .IF "$(OS)"=="MACOSX" || "$(OS)"=="AIX" -SLOFILES+=$(SLO)$/memory_fini.obj +SLOFILES+=$(SLO)$/alloc_fini.obj .ENDIF @@ -130,7 +135,7 @@ OBJFILES= \ $(OBJ)$/alloc_arena.obj .IF "$(OS)"=="MACOSX" || "$(OS)"=="AIX" -OBJFILES+=$(OBJ)$/memory_fini.obj +OBJFILES+=$(OBJ)$/alloc_fini.obj .ENDIF |