Commit 1b518303 authored by brinn's avatar brinn
Browse files

change: improve performance on type conversions (especially reading compound data will profit)

SVN: 9628
parent 8871aae2
Copyright Notice and Statement for NCSA Hierarchical Data Format (HDF)
Java Software Library and Utilities
NCSA Hierarchical Data Format (HDF) Software Library and Utilities
Copyright 1988-2004, the Board of Trustees of the University of Illinois.
Copyright 2007-2009, Center for Information Sciences and Databases, ETH Zurich, Switzerland.
All rights reserved.
Contributors to the library: National Center for Supercomputing
Applications (NCSA) at the University of Illinois, Lawrence
Livermore Nationall Laboratory (LLNL), Sandia National Laboratories (SNL),
Los Alamos National Laboratory (LANL). Fortner Software, Unidata
Program Center (netCDF), The Independent JPEG Group (JPEG),
Jean-loup Gailly and Mark Adler (gzip), and Digital Equipment
Corporation (DEC). Macintosh support contributed by Gregory L. Guerin.
The package 'glguerin':
Copyright 1998, 1999 by Gregory L. Guerin.
Redistribute or reuse only as described below.
These files are from the MacBinary Toolkit for Java:
<http://www.amug.org/~glguerin/sw/#macbinary>
and are redistributed by NCSA with permission of the author.
This work was supported in part by a Cooperative Agreement with
NASA under NASA grant NAG 5-2040 and NAG NCC5-599.
Redistribution and use in source and binary forms, with or without
modification, are permitted for any purpose (including commercial purposes)
provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or materials provided with the distribution.
3. In addition, redistributions of modified forms of the source or binary
code must carry prominent notices stating that the original code was
changed and the date of the change.
4. All publications or advertising materials mentioning features or use of
this software must acknowledge that it was developed by the National
Center for Supercomputing Applications at the University of Illinois, and
credit the Contributors.
5. Neither the name of the University nor the names of the Contributors may
be used to endorse or promote products derived from this software without
specific prior written permission from the University or the Contributors.
6. THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND THE CONTRIBUTORS "AS IS"
WITH NO WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED. In no event
shall the University or the Contributors be liable for any damages
suffered by the users arising out of the use of this software, even if
advised of the possibility of such damage.
--------------------------------------------------------------------------
Portions of HDF5 were developed with support from the University of
California, Lawrence Livermore National Laboratory (UC LLNL).
The following statement applies to those portions of the product
and must be retained in any redistribution of source code, binaries,
documentation, and/or accompanying materials:
This work was partially produced at the University of California,
Lawrence Livermore National Laboratory (UC LLNL) under contract no.
W-7405-ENG-48 (Contract 48) between the U.S. Department of Energy
(DOE) and The Regents of the University of California (University)
for the operation of UC LLNL.
DISCLAIMER:
This work was prepared as an account of work sponsored by an agency
of the United States Government. Neither the United States
Government nor the University of California nor any of their
employees, makes any warranty, express or implied, or assumes any
liability or responsibility for the accuracy, completeness, or
usefulness of any information, apparatus, product, or process
disclosed, or represents that its use would not infringe privately-
owned rights. Reference herein to any specific commercial products,
process, or service by trade name, trademark, manufacturer, or
otherwise, does not necessarily constitute or imply its endorsement,
recommendation, or favoring by the United States Government or the
University of California. The views and opinions of authors
expressed herein do not necessarily state or reflect those of the
United States Government or the University of California, and shall
not be used for advertising or product endorsement purposes.
--------------------------------------------------------------------------
......@@ -231,7 +231,11 @@ LINK32_OBJS= \
"$(INTDIR)\h5tImp.obj" \
"$(INTDIR)\h5util.obj" \
"$(INTDIR)\h5zImp.obj" \
"$(INTDIR)\nativeData.obj"
"$(INTDIR)\copyByteDouble.obj" \
"$(INTDIR)\copyByteFloat.obj" \
"$(INTDIR)\copyByteInt.obj" \
"$(INTDIR)\copyByteLong.obj" \
"$(INTDIR)\copyByteShort.obj"
"$(OUTDIR)\jhdf5.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
......@@ -335,11 +339,32 @@ SOURCE=$(SRCDIR)\h5zImp.c
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=$(SRCDIR)\nativeData.c
SOURCE=$(SRCDIR)\copyByteDouble.c
"$(INTDIR)\nativeData.obj" : $(SOURCE) $(INCLUDES) "$(INTDIR)"
"$(INTDIR)\copyByteDouble.obj" : $(SOURCE) $(INCLUDES) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=$(SRCDIR)\copyByteFloat.c
"$(INTDIR)\copyByteFloat.obj" : $(SOURCE) $(INCLUDES) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=$(SRCDIR)\copyByteInt.c
"$(INTDIR)\copyByteInt.obj" : $(SOURCE) $(INCLUDES) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=$(SRCDIR)\copyByteLong.c
"$(INTDIR)\copyByteLong.obj" : $(SOURCE) $(INCLUDES) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=$(SRCDIR)\copyByteShort.c
"$(INTDIR)\copyByteShort.obj" : $(SOURCE) $(INCLUDES) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
CLEAN :
-@erase "$(INTDIR)\exceptionImp.obj"
......@@ -357,7 +382,11 @@ CLEAN :
-@erase "$(INTDIR)\h5tImp.obj"
-@erase "$(INTDIR)\h5zImp.obj"
-@erase "$(INTDIR)\h5util.obj"
-@erase "$(INTDIR)\nativeData.obj"
-@erase "$(INTDIR)\copyByteDouble.obj"
-@erase "$(INTDIR)\copyByteFloat.obj"
-@erase "$(INTDIR)\copyByteInt.obj"
-@erase "$(INTDIR)\copyByteLong.obj"
-@erase "$(INTDIR)\copyByteShort.obj"
-@erase "$(INTDIR)\vc80.idb"
-@erase "$(INTDIR)\jhdf5.exp"
-@erase "$(INTDIR)\jhdf5.lib"
......
......@@ -231,7 +231,12 @@ LINK64_OBJS= \
"$(INTDIR)\h5tImp.obj" \
"$(INTDIR)\h5util.obj" \
"$(INTDIR)\h5zImp.obj" \
"$(INTDIR)\nativeData.obj"
"$(INTDIR)\copyByteDouble.obj" \
"$(INTDIR)\copyByteFloat.obj" \
"$(INTDIR)\copyByteInt.obj" \
"$(INTDIR)\copyByteLong.obj" \
"$(INTDIR)\copyByteShort.obj"
"$(OUTDIR)\jhdf5.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK64_OBJS)
$(LINK64) @<<
......@@ -335,11 +340,32 @@ SOURCE=$(SRCDIR)\h5zImp.c
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=$(SRCDIR)\nativeData.c
SOURCE=$(SRCDIR)\copyByteDouble.c
"$(INTDIR)\copyByteDouble.obj" : $(SOURCE) $(INCLUDES) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=$(SRCDIR)\copyByteFloat.c
"$(INTDIR)\copyByteFloat.obj" : $(SOURCE) $(INCLUDES) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=$(SRCDIR)\copyByteInt.c
"$(INTDIR)\copyByteInt.obj" : $(SOURCE) $(INCLUDES) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=$(SRCDIR)\copyByteLong.c
"$(INTDIR)\nativeData.obj" : $(SOURCE) $(INCLUDES) "$(INTDIR)"
"$(INTDIR)\copyByteLong.obj" : $(SOURCE) $(INCLUDES) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=$(SRCDIR)\copyByteShort.c
"$(INTDIR)\copyByteShort.obj" : $(SOURCE) $(INCLUDES) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
CLEAN :
-@erase "$(INTDIR)\exceptionImp.obj"
......@@ -357,7 +383,11 @@ CLEAN :
-@erase "$(INTDIR)\h5tImp.obj"
-@erase "$(INTDIR)\h5zImp.obj"
-@erase "$(INTDIR)\h5util.obj"
-@erase "$(INTDIR)\nativeData.obj"
-@erase "$(INTDIR)\copyByteDouble.obj"
-@erase "$(INTDIR)\copyByteFloat.obj"
-@erase "$(INTDIR)\copyByteInt.obj"
-@erase "$(INTDIR)\copyByteLong.obj"
-@erase "$(INTDIR)\copyByteShort.obj"
-@erase "$(INTDIR)\vc80.idb"
-@erase "$(INTDIR)\jhdf5.exp"
-@erase "$(INTDIR)\jhdf5.lib"
......
/****************************************************************************
* NCSA HDF *
* National Computational Science Alliance *
* University of Illinois at Urbana-Champaign *
* 605 E. Springfield, Champaign IL 61820 *
* *
* Center for Information Sciences and Databases, ETH Zurich, Switzerland *
* *
* For conditions of distribution and use, see the accompanying *
* COPYING file. *
* *
****************************************************************************/
/*
* This module contains the implementation of all the native methods
* used for number conversion. This is represented by the Java
* class HDFNativeData.
*
* These routines convert one dimensional arrays of bytes into
* one-D arrays of other types (int, double, etc) and vice versa.
*
* These routines are called from the Java parts of the Java-C
* interface.
*
* ***Important notes:
*
* 1. These routines are designed to be portable--they use the
* C compiler to do the required native data manipulation.
* 2. These routines copy the data at least once -- a serious
* but unavoidable performance hit.
*/
#define TARGET jdouble
#define TARGET_ARRAY jdoubleArray
#define METHODNAMETB "copyDoubleToByte"
#define FUNCTIONNAMETB Java_ncsa_hdf_hdf5lib_HDFNativeData_copyDoubleToByte___3DI_3BII
#define METHODNAMEBT "copyByteToDouble"
#define FUNCTIONNAMEBT Java_ncsa_hdf_hdf5lib_HDFNativeData_copyByteToDouble___3BI_3DII
#define COPY_FUNC GetDoubleArrayRegion
#include "copyByteTarget.ctempl"
/****************************************************************************
* NCSA HDF *
* National Computational Science Alliance *
* University of Illinois at Urbana-Champaign *
* 605 E. Springfield, Champaign IL 61820 *
* *
* Center for Information Sciences and Databases, ETH Zurich, Switzerland *
* *
* For conditions of distribution and use, see the accompanying *
* COPYING file. *
* *
****************************************************************************/
/*
* This module contains the implementation of all the native methods
* used for number conversion. This is represented by the Java
* class HDFNativeData.
*
* These routines convert one dimensional arrays of bytes into
* one-D arrays of other types (int, float, etc) and vice versa.
*
* These routines are called from the Java parts of the Java-C
* interface.
*
* ***Important notes:
*
* 1. These routines are designed to be portable--they use the
* C compiler to do the required native data manipulation.
* 2. These routines copy the data at least once -- a serious
* but unavoidable performance hit.
*/
#define TARGET jfloat
#define TARGET_ARRAY jfloatArray
#define METHODNAMETB "copyFloatToByte"
#define FUNCTIONNAMETB Java_ncsa_hdf_hdf5lib_HDFNativeData_copyFloatToByte___3FI_3BII
#define METHODNAMEBT "copyByteToFloat"
#define FUNCTIONNAMEBT Java_ncsa_hdf_hdf5lib_HDFNativeData_copyByteToFloat___3BI_3FII
#define COPY_FUNC GetFloatArrayRegion
#include "copyByteTarget.ctempl"
/****************************************************************************
* NCSA HDF *
* National Computational Science Alliance *
* University of Illinois at Urbana-Champaign *
* 605 E. Springfield, Champaign IL 61820 *
* *
* Center for Information Sciences and Databases, ETH Zurich, Switzerland *
* *
* For conditions of distribution and use, see the accompanying *
* COPYING file. *
* *
****************************************************************************/
/*
* This module contains the implementation of all the native methods
* used for number conversion. This is represented by the Java
* class HDFNativeData.
*
* These routines convert one dimensional arrays of bytes into
* one-D arrays of other types (int, float, etc) and vice versa.
*
* These routines are called from the Java parts of the Java-C
* interface.
*
* ***Important notes:
*
* 1. These routines are designed to be portable--they use the
* C compiler to do the required native data manipulation.
* 2. These routines copy the data at least once -- a serious
* but unavoidable performance hit.
*/
#define TARGET jint
#define TARGET_ARRAY jintArray
#define METHODNAMETB "copyIntToByte"
#define FUNCTIONNAMETB Java_ncsa_hdf_hdf5lib_HDFNativeData_copyIntToByte___3II_3BII
#define METHODNAMEBT "copyByteToInt"
#define FUNCTIONNAMEBT Java_ncsa_hdf_hdf5lib_HDFNativeData_copyByteToInt___3BI_3III
#define COPY_FUNC GetIntArrayRegion
#include "copyByteTarget.ctempl"
/****************************************************************************
* NCSA HDF *
* National Computational Science Alliance *
* University of Illinois at Urbana-Champaign *
* 605 E. Springfield, Champaign IL 61820 *
* *
* Center for Information Sciences and Databases, ETH Zurich, Switzerland *
* *
* For conditions of distribution and use, see the accompanying *
* COPYING file. *
* *
****************************************************************************/
/*
* This module contains the implementation of all the native methods
* used for number conversion. This is represented by the Java
* class HDFNativeData.
*
* These routines convert one dimensional arrays of bytes into
* one-D arrays of other types (int, float, etc) and vice versa.
*
* These routines are called from the Java parts of the Java-C
* interface.
*
* ***Important notes:
*
* 1. These routines are designed to be portable--they use the
* C compiler to do the required native data manipulation.
* 2. These routines copy the data at least once -- a serious
* but unavoidable performance hit.
*/
#define TARGET jlong
#define TARGET_ARRAY jlongArray
#define METHODNAMETB "copyLongToByte"
#define FUNCTIONNAMETB Java_ncsa_hdf_hdf5lib_HDFNativeData_copyLongToByte___3JI_3BII
#define METHODNAMEBT "copyByteToLong"
#define FUNCTIONNAMEBT Java_ncsa_hdf_hdf5lib_HDFNativeData_copyByteToLong___3BI_3JII
#define COPY_FUNC GetLongArrayRegion
#include "copyByteTarget.ctempl"
/****************************************************************************
* NCSA HDF *
* National Computational Science Alliance *
* University of Illinois at Urbana-Champaign *
* 605 E. Springfield, Champaign IL 61820 *
* *
* Center for Information Sciences and Databases, ETH Zurich, Switzerland *
* *
* For conditions of distribution and use, see the accompanying *
* COPYING file. *
* *
****************************************************************************/
/*
* This module contains the implementation of all the native methods
* used for number conversion. This is represented by the Java
* class HDFNativeData.
*
* These routines convert one dimensional arrays of bytes into
* one-D arrays of other types (int, float, etc) and vice versa.
*
* These routines are called from the Java parts of the Java-C
* interface.
*
* ***Important notes:
*
* 1. These routines are designed to be portable--they use the
* C compiler to do the required native data manipulation.
* 2. These routines copy the data at least once -- a serious
* but unavoidable performance hit.
*/
#define TARGET jshort
#define TARGET_ARRAY jshortArray
#define METHODNAMETB "copyShortToByte"
#define FUNCTIONNAMETB Java_ncsa_hdf_hdf5lib_HDFNativeData_copyShortToByte___3SI_3BII
#define METHODNAMEBT "copyByteToShort"
#define FUNCTIONNAMEBT Java_ncsa_hdf_hdf5lib_HDFNativeData_copyByteToShort___3BI_3SII
#define COPY_FUNC GetShortArrayRegion
#include "copyByteTarget.ctempl"
/****************************************************************************
* NCSA HDF *
* National Computational Science Alliance *
* University of Illinois at Urbana-Champaign *
* 605 E. Springfield, Champaign IL 61820 *
* *
* Center for Information Sciences and Databases, ETH Zurich, Switzerland *
* *
* For conditions of distribution and use, see the accompanying *
* COPYING file. *
* *
****************************************************************************/
/*
* This module contains the implementation of all the native methods
* used for number conversion. This is represented by the Java
* class HDFNativeData.
*
* These routines convert one dimensional arrays of bytes into
* one-D arrays of other types (int, float, etc) and vice versa.
*
* These routines are called from the Java parts of the Java-C
* interface.
*
* ***Important notes:
*
* 1. These routines are designed to be portable--they use the
* C compiler to do the required native data manipulation.
* 2. These routines copy the data at least once -- a serious
* but unavoidable performance hit.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include "hdf5.h"
#include <jni.h>
extern jboolean h5JNIFatalError( JNIEnv *env, char *functName);
extern jboolean h5nullArgument( JNIEnv *env, char *functName);
extern jboolean h5badArgument( JNIEnv *env, char *functName);
#define INDATA_IS_NULL_ERR_TB METHODNAMETB ": inData is NULL"
#define OUTDATA_IS_NULL_ERR_TB METHODNAMETB ": outData is NULL"
#define OOB_IN_ERR_TB METHODNAMETB ": inStart or len is out of bounds"
#define OOB_OUT_ERR_TB METHODNAMETB ": outStart or len is out of bounds"
#define PINNING_OUT_ERR_TB METHODNAMETB ": pinning outArray failed"
#define INDATA_IS_NULL_ERR_BT METHODNAMEBT ": inData is NULL"
#define OUTDATA_IS_NULL_ERR_BT METHODNAMEBT ": outData is NULL"
#define OOB_IN_ERR_BT METHODNAMEBT ": inStart or len is out of bounds"
#define OOB_OUT_ERR_BT METHODNAMEBT ": outStart or len is out of bounds"
#define PINNING_OUT_ERR_BT METHODNAMEBT ": pinning outArray failed"
/*
* public static native void copy<TARGET_CAPT>oByte(<TARGET>[] inData, int inStart,
* byte[] outData, int outStart, int len);
*/
JNIEXPORT void JNICALL FUNCTIONNAMETB
(JNIEnv *env,
jclass clss,
TARGET_ARRAY inData, /* IN: array of TARGET */
jint inStart,
jbyteArray outData, /* OUT: array of byte */
jint outStart,
jint len
)
{
jsize inSize, outSize;
jint lenInBytes;
jbyte *outArray;
jboolean isCopy;
if (inData == NULL) {
h5nullArgument(env, INDATA_IS_NULL_ERR_BT);
return;
}
if (outData == NULL) {
h5nullArgument(env, OUTDATA_IS_NULL_ERR_TB);
return;
}
lenInBytes = len * sizeof(TARGET);
#ifdef __cplusplus
inSize = env->GetArrayLength(inData);
#else
inSize = (*env)->GetArrayLength(env, inData);
#endif
if ((inStart < 0) || (inStart + len > inSize)) {
h5badArgument(env, OOB_IN_ERR_TB);
return;
}
#ifdef __cplusplus
outSize = env->GetArrayLength(outData);
#else
outSize = (*env)->GetArrayLength(env, outData);
#endif
if ((outStart < 0) || (outStart + lenInBytes > outSize)) {
h5badArgument(env, OOB_OUT_ERR_TB);
return;
}
#ifdef __cplusplus
outArray = env->GetPrimitiveArrayCritical(outData, &isCopy);
#else
outArray = (*env)->GetPrimitiveArrayCritical(env, outData, &isCopy);
#endif
if (outArray == NULL) {
h5JNIFatalError(env, PINNING_OUT_ERR_TB);
return;
}
#ifdef __cplusplus
env->COPY_FUNC(inData, inStart, len, (TARGET*) (outArray + outStart));
#else
(*env)->COPY_FUNC(env, inData, inStart, len, (TARGET*) (outArray + outStart));
#endif
#ifdef __cplusplus
env->ReleasePrimitiveArrayCritical(outData, outArray, 0);
#else
(*env)->ReleasePrimitiveArrayCritical(env, outData,outArray, 0);
#endif
return;
}
/*
* public static native void copyByteTo<TARGET_CAP>(byte[] inData, int inStart,
* TARGET[] outData, int outStart, int len);
*/
JNIEXPORT void JNICALL FUNCTIONNAMEBT
(JNIEnv *env,
jclass clss,
jbyteArray inData, /* IN: array of byte */
jint inStart,
TARGET_ARRAY outData, /* OUT: array of TAGET */
jint outStart,
jint len
)
{
jsize inSize, outSize;
jint lenInBytes;
TARGET *outArray;
jboolean isCopy;
if (inData == NULL) {
h5nullArgument(env, INDATA_IS_NULL_ERR_BT);
return;
}
if (outData == NULL) {
h5nullArgument(env, OUTDATA_IS_NULL_ERR_BT);
return;
}
lenInBytes = len * sizeof(TARGET);
#ifdef __cplusplus
inSize = env->GetArrayLength(inData);
#else
inSize = (*env)->GetArrayLength(env, inData);
#endif
if ((inStart < 0) || (inStart + lenInBytes > inSize)) {
h5badArgument(env, OOB_IN_ERR_BT);
return;
}
#ifdef __cplusplus
outSize = env->GetArrayLength(outData);
#else
outSize = (*env)->GetArrayLength(env, outData);
#endif
if ((outStart < 0) || (outStart + len > outSize)) {
h5badArgument(env, OOB_OUT_ERR_BT);
return;
}
#ifdef __cplusplus
outArray = env->GetPrimitiveArrayCritical(outData, &isCopy);
#else
outArray = (*env)->GetPrimitiveArrayCritical(env, outData, &isCopy);
#endif
if (outArray == NULL) {
h5JNIFatalError(env, PINNING_OUT_ERR_BT);
return;
}
#ifdef __cplusplus
env->GetByteArrayRegion(inData, inStart, lenInBytes, outArray + outStart);
#else
(*env)->GetByteArrayRegion(env, inData, inStart, lenInBytes, (jbyte*) (outArray + outStart));
#endif
#ifdef __cplusplus
env->ReleasePrimitiveArrayCritical(outData, outArray, 0);
#else
(*env)->ReleasePrimitiveArrayCritical(env, outData, outArray, 0);
#endif
return;
}
#ifdef __cplusplus
}
#endif
......@@ -262,9 +262,9 @@ JNIEXPORT jint JNICALL Java_ncsa_hdf_hdf5lib_H5_H5Dread
return -1;
}
#ifdef __cplusplus
byteP = env->GetByteArrayElements(buf,&isCopy);
byteP = env->GetPrimitiveArrayCritical(buf,&isCopy);