src/share/demo/jvmti/hprof/hprof_util.h

Print this page




  24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30  */
  31 
  32 /*
  33  * This source code is provided to illustrate the usage of a given feature
  34  * or technique and has been deliberately simplified. Additional steps
  35  * required for a production-quality application, such as security checks,
  36  * input validation and proper error handling, might not be present in
  37  * this sample code.
  38  */
  39 
  40 
  41 #ifndef HPROF_UTIL_H
  42 #define HPROF_UTIL_H
  43 





  44 /* Macros that protect code from accidently using a local ref improperly */
  45 #define WITH_LOCAL_REFS(env, number)            \
  46     {                                           \
  47         JNIEnv *_env = (env);                   \
  48         pushLocalFrame(_env, number);           \
  49         { /* BEGINNING OF WITH SCOPE */
  50 
  51 #define END_WITH_LOCAL_REFS                     \
  52         } /* END OF WITH SCOPE */               \
  53         popLocalFrame(_env, NULL);              \
  54     }
  55 
  56 /* Macro to check for exceptions after JNI calls. */
  57 #define CHECK_EXCEPTIONS(env)                                           \
  58     {                                                                   \
  59         JNIEnv *_env = (env);                                           \
  60         jobject _exception;                                             \
  61         _exception = exceptionOccurred(_env);                           \
  62         if ( _exception != NULL ) {                                     \
  63             exceptionDescribe(_env);                                    \


 167 jrawMonitorID createRawMonitor(const char *str);
 168 void          rawMonitorEnter(jrawMonitorID m);
 169 void          rawMonitorWait(jrawMonitorID m, jlong pause_time);
 170 void          rawMonitorNotifyAll(jrawMonitorID m);
 171 void          rawMonitorExit(jrawMonitorID m);
 172 void          destroyRawMonitor(jrawMonitorID m);
 173 
 174 /* JVMTI alloc/dealloc */
 175 void *        jvmtiAllocate(int size);
 176 void          jvmtiDeallocate(void *ptr);
 177 
 178 /* System malloc/free */
 179 void *        hprof_malloc(int size);
 180 void          hprof_free(void *ptr);
 181 
 182 #include "debug_malloc.h"
 183 
 184 #ifdef DEBUG
 185     void *        hprof_debug_malloc(int size, char *file, int line);
 186     void          hprof_debug_free(void *ptr, char *file, int line);
 187     #define HPROF_MALLOC(size)  hprof_debug_malloc(size, __FILE__, __LINE__)
 188     #define HPROF_FREE(ptr)     hprof_debug_free(ptr, __FILE__, __LINE__)
 189 #else
 190     #define HPROF_MALLOC(size)  hprof_malloc(size)
 191     #define HPROF_FREE(ptr)     hprof_free(ptr)
 192 #endif
 193 
 194 #endif


  24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30  */
  31 
  32 /*
  33  * This source code is provided to illustrate the usage of a given feature
  34  * or technique and has been deliberately simplified. Additional steps
  35  * required for a production-quality application, such as security checks,
  36  * input validation and proper error handling, might not be present in
  37  * this sample code.
  38  */
  39 
  40 
  41 #ifndef HPROF_UTIL_H
  42 #define HPROF_UTIL_H
  43 
  44 /* Use THIS_FILE when it is available. */
  45 #ifndef THIS_FILE
  46     #define THIS_FILE __FILE__
  47 #endif
  48 
  49 /* Macros that protect code from accidently using a local ref improperly */
  50 #define WITH_LOCAL_REFS(env, number)            \
  51     {                                           \
  52         JNIEnv *_env = (env);                   \
  53         pushLocalFrame(_env, number);           \
  54         { /* BEGINNING OF WITH SCOPE */
  55 
  56 #define END_WITH_LOCAL_REFS                     \
  57         } /* END OF WITH SCOPE */               \
  58         popLocalFrame(_env, NULL);              \
  59     }
  60 
  61 /* Macro to check for exceptions after JNI calls. */
  62 #define CHECK_EXCEPTIONS(env)                                           \
  63     {                                                                   \
  64         JNIEnv *_env = (env);                                           \
  65         jobject _exception;                                             \
  66         _exception = exceptionOccurred(_env);                           \
  67         if ( _exception != NULL ) {                                     \
  68             exceptionDescribe(_env);                                    \


 172 jrawMonitorID createRawMonitor(const char *str);
 173 void          rawMonitorEnter(jrawMonitorID m);
 174 void          rawMonitorWait(jrawMonitorID m, jlong pause_time);
 175 void          rawMonitorNotifyAll(jrawMonitorID m);
 176 void          rawMonitorExit(jrawMonitorID m);
 177 void          destroyRawMonitor(jrawMonitorID m);
 178 
 179 /* JVMTI alloc/dealloc */
 180 void *        jvmtiAllocate(int size);
 181 void          jvmtiDeallocate(void *ptr);
 182 
 183 /* System malloc/free */
 184 void *        hprof_malloc(int size);
 185 void          hprof_free(void *ptr);
 186 
 187 #include "debug_malloc.h"
 188 
 189 #ifdef DEBUG
 190     void *        hprof_debug_malloc(int size, char *file, int line);
 191     void          hprof_debug_free(void *ptr, char *file, int line);
 192     #define HPROF_MALLOC(size)  hprof_debug_malloc(size, THIS_FILE, __LINE__)
 193     #define HPROF_FREE(ptr)     hprof_debug_free(ptr, THIS_FILE, __LINE__)
 194 #else
 195     #define HPROF_MALLOC(size)  hprof_malloc(size)
 196     #define HPROF_FREE(ptr)     hprof_free(ptr)
 197 #endif
 198 
 199 #endif