summaryrefslogtreecommitdiffstats
path: root/src/H5Oattr.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2007-05-14 20:24:08 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2007-05-14 20:24:08 (GMT)
commit31ff357f3190a869147378a9a136510be2caafd7 (patch)
tree5220b17a8e4b6c434b799108719a1dc15d6c0326 /src/H5Oattr.c
parent1726061075e9adc99ac2286fb542438acc79c4ab (diff)
downloadhdf5-31ff357f3190a869147378a9a136510be2caafd7.zip
hdf5-31ff357f3190a869147378a9a136510be2caafd7.tar.gz
hdf5-31ff357f3190a869147378a9a136510be2caafd7.tar.bz2
[svn-r13753] Description:
Check in "unique, but sharable" optimization to ISOHM code, which allows object header messages that are only used in one object to remain in the sole user's header, but migrates messages that are used in more than one header into the ISOHM heap. Tested on: Mac OS X/32 10.4.9 (amazon) FreeBSD/32 6.2 (duty) Linux/32 2.6 (chicago) Linux/64 2.6 (chicago2)
Diffstat (limited to 'src/H5Oattr.c')
-rw-r--r--src/H5Oattr.c104
1 files changed, 37 insertions, 67 deletions
diff --git a/src/H5Oattr.c b/src/H5Oattr.c
index dbe9b0c..9c6daee 100644
--- a/src/H5Oattr.c
+++ b/src/H5Oattr.c
@@ -37,7 +37,8 @@ static herr_t H5O_attr_free(void *mesg);
static herr_t H5O_attr_pre_copy_file(H5F_t *file_src, const void *mesg_src,
hbool_t *deleted, const H5O_copy_t *cpy_info, void *udata);
static void *H5O_attr_copy_file(H5F_t *file_src, const H5O_msg_class_t *mesg_type,
- void *native_src, H5F_t *file_dst, hid_t dxpl_id, H5O_copy_t *cpy_info, void *udata);
+ void *native_src, H5F_t *file_dst, hbool_t *recompute_size,
+ H5O_copy_t *cpy_info, void *udata, hid_t dxpl_id);
static herr_t H5O_attr_post_copy_file(const H5O_loc_t *src_oloc,
const void *mesg_src, H5O_loc_t *dst_oloc, void *mesg_dst, hid_t dxpl_id,
H5O_copy_t *cpy_info);
@@ -69,7 +70,7 @@ const H5O_msg_class_t H5O_MSG_ATTR[1] = {{
H5O_ATTR_ID, /* message id number */
"attribute", /* message name for debugging */
sizeof(H5A_t), /* native message size */
- TRUE, /* messages are sharable? */
+ H5O_SHARE_IS_SHARABLE, /* messages are sharable? */
H5O_attr_shared_decode, /* decode message */
H5O_attr_shared_encode, /* encode message */
H5O_attr_copy, /* copy the native value */
@@ -78,7 +79,7 @@ const H5O_msg_class_t H5O_MSG_ATTR[1] = {{
H5O_attr_free, /* free method */
H5O_attr_shared_delete, /* file delete method */
H5O_attr_shared_link, /* link method */
- H5O_shared_copy, /* set share method */
+ NULL, /*set share method */
NULL, /*can share method */
H5O_attr_pre_copy_file, /* pre copy native value to file */
H5O_attr_shared_copy_file, /* copy native value to file */
@@ -243,7 +244,7 @@ H5O_attr_decode(H5F_t *f, hid_t dxpl_id, unsigned UNUSED mesg_flags,
ret_value = attr;
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5O_attr_decode() */
@@ -262,31 +263,15 @@ done:
DESCRIPTION
This function encodes the native memory form of the attribute
message in the "raw" disk form.
- *
- * Modifications:
- * Robb Matzke, 17 Jul 1998
- * Added padding for alignment.
- *
- * Robb Matzke, 20 Jul 1998
- * Added a version number at the beginning.
- *
- * Raymond Lu, 8 April 2004
- * For dataspace, changed the operation on H5S_simple_t to
- * H5S_extent_t
- *
- * James Laird, 15 November 2005
- * Added character encoding (version 3)
- *
--------------------------------------------------------------------------*/
static herr_t
H5O_attr_encode(H5F_t *f, uint8_t *p, const void *mesg)
{
const H5A_t *attr = (const H5A_t *) mesg;
size_t name_len; /* Attribute name length */
- htri_t is_shared_ret; /* Return value from H5O_msg_is_shared */
unsigned version; /* Attribute version */
- hbool_t type_shared; /* Flag to indicate that a shared datatype is used for this attribute */
- hbool_t space_shared; /* Flag to indicate that a shared dataspace is used for this attribute */
+ htri_t is_type_shared; /* Flag to indicate that a shared datatype is used for this attribute */
+ htri_t is_space_shared; /* Flag to indicate that a shared dataspace is used for this attribute */
hbool_t use_latest_format; /* Flag indicating the newest file format should be used */
unsigned flags = 0; /* Attribute flags */
herr_t ret_value = SUCCEED; /* Return value */
@@ -302,26 +287,18 @@ H5O_attr_encode(H5F_t *f, uint8_t *p, const void *mesg)
use_latest_format = H5F_USE_LATEST_FORMAT(f);
/* Check whether datatype and dataspace are shared */
- if((is_shared_ret = H5O_msg_is_shared(H5O_DTYPE_ID, attr->dt)) < 0)
+ if((is_type_shared = H5O_msg_is_shared(H5O_DTYPE_ID, attr->dt)) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "can't determine if datatype is shared")
- else if(is_shared_ret)
- type_shared = TRUE;
- else
- type_shared = FALSE;
- if((is_shared_ret = H5O_msg_is_shared(H5O_SDSPACE_ID, attr->ds)) < 0)
+ if((is_space_shared = H5O_msg_is_shared(H5O_SDSPACE_ID, attr->ds)) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "can't determine if dataspace is shared")
- else if(is_shared_ret)
- space_shared = TRUE;
- else
- space_shared = FALSE;
/* Check which version to write out */
if(use_latest_format)
version = H5O_ATTR_VERSION_LATEST; /* Write out latest version of format */
else if(attr->encoding != H5T_CSET_ASCII)
version = H5O_ATTR_VERSION_3; /* Write version which includes the character encoding */
- else if(type_shared || space_shared)
+ else if(is_type_shared || is_space_shared)
version = H5O_ATTR_VERSION_2; /* Write out version with flag for shared datatype & dataspaces */
else
version = H5O_ATTR_VERSION_1; /* Write out basic version */
@@ -331,8 +308,8 @@ H5O_attr_encode(H5F_t *f, uint8_t *p, const void *mesg)
/* Set attribute flags if version >1 */
if(version >= H5O_ATTR_VERSION_2) {
- flags = (type_shared ? H5O_ATTR_FLAG_TYPE_SHARED : 0 );
- flags |= (space_shared ? H5O_ATTR_FLAG_SPACE_SHARED : 0);
+ flags = (is_type_shared ? H5O_ATTR_FLAG_TYPE_SHARED : 0 );
+ flags |= (is_space_shared ? H5O_ATTR_FLAG_SPACE_SHARED : 0);
*p++ = flags; /* Set flags for attribute */
} /* end if */
else
@@ -444,10 +421,6 @@ done:
This function returns the size of the raw attribute message on
success. (Not counting the message type or size fields, only the data
portion of the message). It doesn't take into account alignment.
- *
- * Modified:
- * Robb Matzke, 17 Jul 1998
- * Added padding between message parts for alignment.
--------------------------------------------------------------------------*/
static size_t
H5O_attr_size(const H5F_t *f, const void *_mesg)
@@ -531,8 +504,6 @@ H5O_attr_size(const H5F_t *f, const void *_mesg)
* Programmer: Robb Matzke
* Tuesday, December 9, 1997
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
herr_t
@@ -559,8 +530,6 @@ H5O_attr_reset(void *_mesg)
* Programmer: Quincey Koziol
* Thursday, November 18, 2004
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static herr_t
@@ -586,14 +555,12 @@ H5O_attr_free(void *mesg)
* Programmer: Quincey Koziol
* Friday, September 26, 2003
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
herr_t
-H5O_attr_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg)
+H5O_attr_delete(H5F_t *f, hid_t dxpl_id, H5O_t *oh, void *_mesg)
{
- const H5A_t *attr = (const H5A_t *) _mesg;
+ H5A_t *attr = (H5A_t *) _mesg;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5O_attr_delete)
@@ -603,11 +570,11 @@ H5O_attr_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg)
HDassert(attr);
/* Decrement reference count on datatype in file */
- if((H5O_MSG_DTYPE->del)(f, dxpl_id, attr->dt) < 0)
+ if((H5O_MSG_DTYPE->del)(f, dxpl_id, oh, attr->dt) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_LINKCOUNT, FAIL, "unable to adjust datatype link count")
/* Decrement reference count on dataspace in file */
- if((H5O_MSG_SDSPACE->del)(f, dxpl_id, attr->ds) < 0)
+ if((H5O_MSG_SDSPACE->del)(f, dxpl_id, oh, attr->ds) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_LINKCOUNT, FAIL, "unable to adjust dataspace link count")
done:
@@ -629,9 +596,9 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5O_attr_link(H5F_t *f, hid_t dxpl_id, const void *_mesg)
+H5O_attr_link(H5F_t *f, hid_t dxpl_id, H5O_t *oh, void *_mesg)
{
- const H5A_t *attr = (const H5A_t *) _mesg;
+ H5A_t *attr = (H5A_t *) _mesg;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5O_attr_link)
@@ -646,9 +613,9 @@ H5O_attr_link(H5F_t *f, hid_t dxpl_id, const void *_mesg)
* message is deleted.
*/
/* Increment reference count on datatype & dataspace in file */
- if((H5O_MSG_DTYPE->link)(f, dxpl_id, attr->dt) < 0)
+ if((H5O_MSG_DTYPE->link)(f, dxpl_id, oh, attr->dt) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_LINKCOUNT, FAIL, "unable to adjust datatype link count")
- if((H5O_MSG_SDSPACE->link)(f, dxpl_id, attr->ds) < 0)
+ if((H5O_MSG_SDSPACE->link)(f, dxpl_id, oh, attr->ds) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_LINKCOUNT, FAIL, "unable to adjust dataspace link count")
done:
@@ -703,17 +670,12 @@ H5O_attr_pre_copy_file(H5F_t UNUSED *file_src, const void UNUSED *native_src,
* Programmer: Quincey Koziol
* November 1, 2005
*
- * Modifications: Peter Cao
- * December 17, 2005: datatype conversion for variable length datatype
- * August 1, 2006: fix reference datatype
- *
- *
*-------------------------------------------------------------------------
*/
static void *
H5O_attr_copy_file(H5F_t UNUSED *file_src, const H5O_msg_class_t UNUSED *mesg_type,
- void *native_src, H5F_t *file_dst, hid_t dxpl_id,
- H5O_copy_t *cpy_info, void UNUSED *udata)
+ void *native_src, H5F_t *file_dst, hbool_t *recompute_size,
+ H5O_copy_t *cpy_info, void UNUSED *udata, hid_t dxpl_id)
{
H5A_t *attr_src = (H5A_t *)native_src;
H5A_t *attr_dst = NULL;
@@ -779,15 +741,18 @@ H5O_attr_copy_file(H5F_t UNUSED *file_src, const H5O_msg_class_t UNUSED *mesg_ty
/* Copy the shared object from source to destination */
if(H5O_copy_header_map(src_oloc, dst_oloc, dxpl_id, cpy_info, FALSE) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, NULL, "unable to copy object")
- } else {
+
+ /* Update shared message info from named datatype info */
+ H5T_update_shared(attr_dst->dt);
+ } /* end if */
+ else {
/* If the datatype is not named, it may have been shared in the
* source file's heap. Un-share it for now. We'll try to shared
* it in the destination file below.
*/
if(H5O_msg_reset_share(H5O_DTYPE_ID, attr_dst->dt) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, "unable to reset datatype sharing")
- }
- /* end if */
+ } /* end else */
/* Copy the dataspace for the attribute */
attr_dst->ds = H5S_copy(attr_src->ds, FALSE);
@@ -803,19 +768,24 @@ H5O_attr_copy_file(H5F_t UNUSED *file_src, const H5O_msg_class_t UNUSED *mesg_ty
/* Try to share both the datatype and dataset. This does nothing if the
* datatype is committed or sharing is disabled.
*/
- if(H5SM_try_share(file_dst, dxpl_id, H5O_DTYPE_ID, attr_dst->dt) < 0)
+ if(H5SM_try_share(file_dst, dxpl_id, NULL, H5O_DTYPE_ID, attr_dst->dt, NULL) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_WRITEERROR, NULL, "can't share attribute datatype")
- if(H5SM_try_share(file_dst, dxpl_id, H5O_SDSPACE_ID, attr_dst->ds) <0)
+ if(H5SM_try_share(file_dst, dxpl_id, NULL, H5O_SDSPACE_ID, attr_dst->ds, NULL) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_WRITEERROR, NULL, "can't share attribute dataspace")
/* Compute the sizes of the datatype and dataspace. This is their raw
* size unless they're shared.
*/
- attr_dst->dt_size = H5O_msg_raw_size(file_dst, H5O_DTYPE_ID, FALSE, attr_src->dt);
+ attr_dst->dt_size = H5O_msg_raw_size(file_dst, H5O_DTYPE_ID, FALSE, attr_dst->dt);
HDassert(attr_dst->dt_size > 0);
- attr_dst->ds_size = H5O_msg_raw_size(file_dst, H5O_SDSPACE_ID, FALSE, attr_src->ds);
+ attr_dst->ds_size = H5O_msg_raw_size(file_dst, H5O_SDSPACE_ID, FALSE, attr_dst->ds);
HDassert(attr_dst->ds_size > 0);
+ /* Check whether to recompute the size of the attribute */
+ /* (happens when the datatype or dataspace changes sharing status) */
+ if(attr_dst->dt_size != attr_src->dt_size || attr_dst->ds_size != attr_src->ds_size)
+ *recompute_size = TRUE;
+
/* Compute the size of the data */
H5_ASSIGN_OVERFLOW(attr_dst->data_size, H5S_GET_EXTENT_NPOINTS(attr_dst->ds) * H5T_get_size(attr_dst->dt), hsize_t, size_t);