From 631e94869b7c0c4e7f053f06769b7b4550216a63 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Sun, 25 Jul 2004 23:41:52 -0500 Subject: [svn-r8947] Purpose: Code cleanup, sorta Description: Added ifdef sections for "H5_USING_PURIFY" in various places in the code, which are designed to reduce the spurious "uninitialized memory read" warnings from purify which are actually OK. Note that this macro will have to be turned on by adding it to the CFLAGS for the build - I didn't think it was important enough to add a configure flag for. Also, the changes in H5HG.c optimize the walks through the objects in a heap to only look at the 'used' entries instead of all the 'allocated' entries. Platforms tested: Solaris 2.7 (arabica) w/purify Not tested by h5committest --- release_docs/RELEASE.txt | 5 +++++ src/H5Distore.c | 10 ++++++++++ src/H5FD.c | 15 +++++++++++++++ src/H5FLprivate.h | 2 +- src/H5Gnode.c | 3 +++ src/H5HG.c | 35 ++++++++++++++++++++--------------- 6 files changed, 54 insertions(+), 16 deletions(-) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index e0c28a5..65ce589 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -38,6 +38,11 @@ New Features Configuration: -------------- + - Added some initial support for making purify (or similar memory + checking products) happier by initializing buffers to zero and + disabling the internal free list code. To take advantage of this, + define 'H5_USING_PURIFY' in your CFLAGS when building the library. + QAK - 2004/07/23 Library: -------- diff --git a/src/H5Distore.c b/src/H5Distore.c index 209dd46..7e3c73a 100644 --- a/src/H5Distore.c +++ b/src/H5Distore.c @@ -970,6 +970,9 @@ H5D_istore_init (H5F_t *f, H5D_t *dset) assert(shared->sizeof_rnode); if(NULL==(shared->page=H5FL_BLK_MALLOC(chunk_page,shared->sizeof_rnode))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for B-tree page") +#ifdef H5_USING_PURIFY +HDmemset(shared->page,0,shared->sizeof_rnode); +#endif /* H5_USING_PURIFY */ if(NULL==(shared->nkey=H5FL_SEQ_MALLOC(size_t,(size_t)(2*H5F_KVALUE(f,H5B_ISTORE)+1)))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for B-tree page") @@ -1607,6 +1610,10 @@ H5D_istore_lock(H5F_t *f, const H5D_dxpl_cache_t *dxpl_cache, hid_t dxpl_id, HDmemset (chunk, 0, chunk_size); } /* end else */ } /* end if */ +#ifdef H5_USING_PURIFY +else + HDmemset(ret_value,0,size); +#endif /* H5_USING_PURIFY */ rdcc->ninits++; } /* end else */ } @@ -2238,6 +2245,9 @@ H5D_istore_chunk_alloc(size_t size, const H5O_pline_t *pline) ret_value=H5MM_malloc(size); else ret_value=H5FL_BLK_MALLOC(chunk,size); +#ifdef H5_USING_PURIFY +HDmemset(ret_value,0,size); +#endif /* H5_USING_PURIFY */ FUNC_LEAVE_NOAPI(ret_value); } /* H5D_istore_chunk_alloc() */ diff --git a/src/H5FD.c b/src/H5FD.c index d8f7e93..fe7350a 100644 --- a/src/H5FD.c +++ b/src/H5FD.c @@ -3210,6 +3210,9 @@ H5FD_write(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t si /* Reallocate the metadata accumulator buffer */ if ((file->meta_accum=H5FL_BLK_REALLOC(meta_accum,file->meta_accum,file->accum_buf_size))==NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate metadata accumulator buffer") +#ifdef H5_USING_PURIFY +HDmemset(file->meta_accum+file->accum_size,0,(file->accum_buf_size-file->accum_size)); +#endif /* H5_USING_PURIFY */ } /* end if */ /* Move the existing metadata to the proper location */ @@ -3235,6 +3238,9 @@ H5FD_write(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t si /* Reallocate the metadata accumulator buffer */ if ((file->meta_accum=H5FL_BLK_REALLOC(meta_accum,file->meta_accum,file->accum_buf_size))==NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate metadata accumulator buffer") +#ifdef H5_USING_PURIFY +HDmemset(file->meta_accum+file->accum_size,0,(file->accum_buf_size-file->accum_size)); +#endif /* H5_USING_PURIFY */ } /* end if */ /* Copy the new metadata to the end */ @@ -3267,6 +3273,9 @@ H5FD_write(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t si /* Reallocate the metadata accumulator buffer */ if ((file->meta_accum=H5FL_BLK_REALLOC(meta_accum,file->meta_accum,file->accum_buf_size))==NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate metadata accumulator buffer") +#ifdef H5_USING_PURIFY +HDmemset(file->meta_accum+file->accum_size,0,(file->accum_buf_size-file->accum_size)); +#endif /* H5_USING_PURIFY */ } /* end if */ /* Calculate the proper offset of the existing metadata */ @@ -3298,6 +3307,9 @@ H5FD_write(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t si /* Reallocate the metadata accumulator buffer */ if ((file->meta_accum=H5FL_BLK_REALLOC(meta_accum,file->meta_accum,file->accum_buf_size))==NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate metadata accumulator buffer") +#ifdef H5_USING_PURIFY +HDmemset(file->meta_accum+file->accum_size,0,(file->accum_buf_size-file->accum_size)); +#endif /* H5_USING_PURIFY */ } /* end if */ /* Copy the new metadata to the end */ @@ -3345,6 +3357,9 @@ H5FD_write(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t si /* Note the new buffer size */ file->accum_buf_size=tmp_size; +#ifdef H5_USING_PURIFY +HDmemset(file->meta_accum+file->accum_size,0,(file->accum_buf_size-file->accum_size)); +#endif /* H5_USING_PURIFY */ } /* end if */ } /* end else */ diff --git a/src/H5FLprivate.h b/src/H5FLprivate.h index c1fbfae..641a630 100644 --- a/src/H5FLprivate.h +++ b/src/H5FLprivate.h @@ -36,7 +36,7 @@ /* Macros for turning off free lists in the library */ /* #define H5_NO_FREE_LISTS */ -#ifdef H5_NO_FREE_LISTS +#if defined H5_NO_FREE_LISTS || defined H5_USING_PURIFY #define H5_NO_REG_FREE_LISTS #define H5_NO_ARR_FREE_LISTS #define H5_NO_SEQ_FREE_LISTS diff --git a/src/H5Gnode.c b/src/H5Gnode.c index eaa0089..6ee15d9 100644 --- a/src/H5Gnode.c +++ b/src/H5Gnode.c @@ -1711,6 +1711,9 @@ H5G_node_init(H5F_t *f) assert(shared->sizeof_rnode); if(NULL==(shared->page=H5FL_BLK_MALLOC(grp_page,shared->sizeof_rnode))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for B-tree page") +#ifdef H5_USING_PURIFY +HDmemset(shared->page,0,shared->sizeof_rnode); +#endif /* H5_USING_PURIFY */ if(NULL==(shared->nkey=H5FL_SEQ_MALLOC(size_t,(size_t)(2*H5F_KVALUE(f,H5B_SNODE)+1)))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for B-tree page") diff --git a/src/H5HG.c b/src/H5HG.c index e76ab1a..d79bb35 100644 --- a/src/H5HG.c +++ b/src/H5HG.c @@ -152,7 +152,7 @@ struct H5HG_heap_t { size_t size; /*total size of collection */ uint8_t *chunk; /*the collection, incl. header */ size_t nalloc; /*numb object slots allocated */ - size_t next_idx; /* Object index to use next */ + size_t nused; /*number of slots used */ /* If this value is >65535 then all indices */ /* have been used at some time and the */ /* correct new index should be searched for */ @@ -247,8 +247,11 @@ H5HG_create (H5F_t *f, hid_t dxpl_id, size_t size) heap->cache_info.dirty = TRUE; if (NULL==(heap->chunk = H5FL_BLK_MALLOC (heap_chunk,size))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); +#ifdef H5_USING_PURIFY +HDmemset(heap->chunk,0,size); +#endif /* H5_USING_PURIFY */ heap->nalloc = H5HG_NOBJS (f, size); - heap->next_idx = 1; /* skip index 0, which is used for the free object */ + heap->nused = 1; /* account for index 0, which is used for the free object */ if (NULL==(heap->obj = H5FL_SEQ_MALLOC (H5HG_obj_t,heap->nalloc))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); @@ -462,9 +465,9 @@ H5HG_load (H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * udata1, /* Set the next index value to use */ if(max_idx>0) - heap->next_idx=max_idx+1; + heap->nused=max_idx+1; else - heap->next_idx=1; + heap->nused=1; /* * Add the new heap to the CWFS list, removing some other entry if @@ -662,11 +665,10 @@ H5HG_alloc (H5F_t *f, H5HG_heap_t *heap, size_t size) * Find an ID for the new object. ID zero is reserved for the free space * object. */ - if(heap->next_idxnext_idx++; - } /* end if */ + if(heap->nusednused++; else { - for (idx=1; idxnalloc; idx++) + for (idx=1; idxnused; idx++) if (NULL==heap->obj[idx].begin) break; } /* end else */ @@ -687,7 +689,7 @@ H5HG_alloc (H5F_t *f, H5HG_heap_t *heap, size_t size) /* Update heap information */ heap->nalloc=new_alloc; heap->obj=new_obj; - assert(heap->nalloc>heap->next_idx); + assert(heap->nalloc>heap->nused); } /* end if */ /* Initialize the new object */ @@ -795,6 +797,9 @@ H5HG_extend (H5F_t *f, H5HG_heap_t *heap, size_t size) /* Re-allocate the heap information in memory */ if (NULL==(new_chunk = H5FL_BLK_REALLOC (heap_chunk, heap->chunk, heap->size+need))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "new heap allocation failed"); +#ifdef H5_USING_PURIFY +HDmemset(new_chunk+heap->size,0,need); +#endif /* H5_USING_PURIFY */ /* Adjust the size of the heap */ old_size=heap->size; @@ -805,7 +810,7 @@ H5HG_extend (H5F_t *f, H5HG_heap_t *heap, size_t size) H5F_ENCODE_LENGTH (f, p, heap->size); /* Move the pointers to the existing objects to their new locations */ - for (u=0; unalloc; u++) + for (u=0; unused; u++) if(heap->obj[u].begin) heap->obj[u].begin = new_chunk + (heap->obj[u].begin - heap->chunk); @@ -993,7 +998,7 @@ H5HG_peek (H5F_t *f, hid_t dxpl_id, H5HG_t *hobj) if (NULL==(heap=H5AC_find(f, dxpl_id, H5AC_GHEAP, hobj->addr, NULL, NULL))) HGOTO_ERROR (H5E_HEAP, H5E_CANTLOAD, NULL, "unable to load heap"); - assert (hobj->idx>0 && hobj->idxnalloc); + assert (hobj->idx>0 && hobj->idxnused); ret_value = heap->obj[hobj->idx].begin + H5HG_SIZEOF_OBJHDR (f); assert (ret_value); @@ -1057,7 +1062,7 @@ H5HG_read (H5F_t *f, hid_t dxpl_id, H5HG_t *hobj, void *object/*out*/) if (NULL==(heap=H5AC_find(f, dxpl_id, H5AC_GHEAP, hobj->addr, NULL, NULL))) HGOTO_ERROR (H5E_HEAP, H5E_CANTLOAD, NULL, "unable to load heap"); - assert (hobj->idx>0 && hobj->idxnalloc); + assert (hobj->idx>0 && hobj->idxnused); assert (heap->obj[hobj->idx].begin); size = heap->obj[hobj->idx].size; p = heap->obj[hobj->idx].begin + H5HG_SIZEOF_OBJHDR (f); @@ -1126,7 +1131,7 @@ H5HG_link (H5F_t *f, hid_t dxpl_id, const H5HG_t *hobj, int adjust) /* Load the heap */ if (NULL==(heap=H5AC_find(f, dxpl_id, H5AC_GHEAP, hobj->addr, NULL, NULL))) HGOTO_ERROR (H5E_HEAP, H5E_CANTLOAD, FAIL, "unable to load heap"); - assert (hobj->idx>0 && hobj->idxnalloc); + assert (hobj->idx>0 && hobj->idxnused); assert (heap->obj[hobj->idx].begin); if (heap->obj[hobj->idx].nrefs+adjust<0) HGOTO_ERROR (H5E_HEAP, H5E_BADRANGE, FAIL, "new link count would be out of range"); @@ -1179,14 +1184,14 @@ H5HG_remove (H5F_t *f, hid_t dxpl_id, H5HG_t *hobj) /* Load the heap */ if (NULL==(heap=H5AC_find(f, dxpl_id, H5AC_GHEAP, hobj->addr, NULL, NULL))) HGOTO_ERROR (H5E_HEAP, H5E_CANTLOAD, FAIL, "unable to load heap"); - assert (hobj->idx>0 && hobj->idxnalloc); + assert (hobj->idx>0 && hobj->idxnused); assert (heap->obj[hobj->idx].begin); obj_start = heap->obj[hobj->idx].begin; /* Include object header size */ need = H5HG_ALIGN(heap->obj[hobj->idx].size)+H5HG_SIZEOF_OBJHDR(f); /* Move the new free space to the end of the heap */ - for (u=0; unalloc; u++) { + for (u=0; unused; u++) { if (heap->obj[u].begin > heap->obj[hobj->idx].begin) heap->obj[u].begin -= need; } -- cgit v0.12