0N/A/*
2362N/A * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A *
0N/A * Redistribution and use in source and binary forms, with or without
0N/A * modification, are permitted provided that the following conditions
0N/A * are met:
0N/A *
0N/A * - Redistributions of source code must retain the above copyright
0N/A * notice, this list of conditions and the following disclaimer.
0N/A *
0N/A * - Redistributions in binary form must reproduce the above copyright
0N/A * notice, this list of conditions and the following disclaimer in the
0N/A * documentation and/or other materials provided with the distribution.
0N/A *
2362N/A * - Neither the name of Oracle nor the names of its
0N/A * contributors may be used to endorse or promote products derived
0N/A * from this software without specific prior written permission.
0N/A *
0N/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
0N/A * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
0N/A * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
0N/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
0N/A * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0N/A * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0N/A * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
0N/A * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0N/A * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0N/A * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
0N/A * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0N/A */
0N/A
4378N/A/*
4378N/A * This source code is provided to illustrate the usage of a given feature
4378N/A * or technique and has been deliberately simplified. Additional steps
4378N/A * required for a production-quality application, such as security checks,
4378N/A * input validation and proper error handling, might not be present in
4378N/A * this sample code.
4378N/A */
4378N/A
4378N/A
0N/A#ifndef HPROF_UTIL_H
0N/A#define HPROF_UTIL_H
0N/A
0N/A/* Macros that protect code from accidently using a local ref improperly */
0N/A#define WITH_LOCAL_REFS(env, number) \
0N/A { \
0N/A JNIEnv *_env = (env); \
0N/A pushLocalFrame(_env, number); \
0N/A { /* BEGINNING OF WITH SCOPE */
0N/A
0N/A#define END_WITH_LOCAL_REFS \
0N/A } /* END OF WITH SCOPE */ \
0N/A popLocalFrame(_env, NULL); \
0N/A }
0N/A
0N/A/* Macro to check for exceptions after JNI calls. */
0N/A#define CHECK_EXCEPTIONS(env) \
0N/A { \
0N/A JNIEnv *_env = (env); \
0N/A jobject _exception; \
0N/A _exception = exceptionOccurred(_env); \
0N/A if ( _exception != NULL ) { \
0N/A exceptionDescribe(_env); \
0N/A HPROF_ERROR(JNI_TRUE, "Unexpected Exception found beforehand");\
0N/A } \
0N/A {
0N/A
0N/A#define END_CHECK_EXCEPTIONS \
0N/A } \
0N/A _exception = exceptionOccurred(_env); \
0N/A if ( _exception != NULL ) { \
0N/A exceptionDescribe(_env); \
0N/A HPROF_ERROR(JNI_TRUE, "Unexpected Exception found afterward");\
0N/A } \
0N/A }
0N/A
0N/AJNIEnv * getEnv(void);
0N/A
0N/A/* JNI support functions */
0N/Ajobject newGlobalReference(JNIEnv *env, jobject object);
0N/Ajobject newWeakGlobalReference(JNIEnv *env, jobject object);
0N/Avoid deleteGlobalReference(JNIEnv *env, jobject object);
0N/Ajobject newLocalReference(JNIEnv *env, jobject object);
0N/Avoid deleteLocalReference(JNIEnv *env, jobject object);
0N/Avoid deleteWeakGlobalReference(JNIEnv *env, jobject object);
0N/Ajclass getObjectClass(JNIEnv *env, jobject object);
0N/AjmethodID getMethodID(JNIEnv *env, jclass clazz, const char* name,
0N/A const char *sig);
0N/Ajclass getSuperclass(JNIEnv *env, jclass klass);
0N/AjmethodID getStaticMethodID(JNIEnv *env, jclass clazz, const char* name,
0N/A const char *sig);
0N/AjfieldID getStaticFieldID(JNIEnv *env, jclass clazz, const char* name,
0N/A const char *sig);
0N/Ajclass findClass(JNIEnv *env, const char *name);
0N/Avoid setStaticIntField(JNIEnv *env, jclass clazz, jfieldID field,
0N/A jint value);
0N/Ajboolean isSameObject(JNIEnv *env, jobject o1, jobject o2);
0N/Avoid pushLocalFrame(JNIEnv *env, jint capacity);
0N/Avoid popLocalFrame(JNIEnv *env, jobject ret);
0N/Ajobject exceptionOccurred(JNIEnv *env);
0N/Avoid exceptionDescribe(JNIEnv *env);
0N/Avoid exceptionClear(JNIEnv *env);
0N/Avoid registerNatives(JNIEnv *env, jclass clazz,
0N/A JNINativeMethod *methods, jint count);
0N/A
0N/A/* More JVMTI support functions */
0N/Achar * getErrorName(jvmtiError error_number);
0N/AjvmtiPhase getPhase(void);
0N/Achar * phaseString(jvmtiPhase phase);
0N/Avoid disposeEnvironment(void);
0N/Ajlong getObjectSize(jobject object);
0N/Ajobject getClassLoader(jclass klass);
0N/Ajint getClassStatus(jclass klass);
0N/Ajlong getTag(jobject object);
0N/Avoid setTag(jobject object, jlong tag);
0N/Avoid getObjectMonitorUsage(jobject object, jvmtiMonitorUsage *uinfo);
0N/Avoid getOwnedMonitorInfo(jthread thread, jobject **ppobjects,
0N/A jint *pcount);
0N/Avoid getSystemProperty(const char *name, char **value);
0N/Avoid getClassSignature(jclass klass, char**psignature,
0N/A char **pgeneric_signature);
0N/Avoid getSourceFileName(jclass klass, char** src_name_ptr);
0N/A
0N/AjvmtiPrimitiveType sigToPrimType(char *sig);
0N/Aint sigToPrimSize(char *sig);
0N/Achar primTypeToSigChar(jvmtiPrimitiveType primType);
0N/A
0N/Avoid getAllClassFieldInfo(JNIEnv *env, jclass klass,
0N/A jint* field_count_ptr, FieldInfo** fields_ptr);
0N/Avoid getMethodName(jmethodID method, char** name_ptr,
0N/A char** signature_ptr);
0N/Avoid getMethodClass(jmethodID method, jclass *pclazz);
0N/Ajboolean isMethodNative(jmethodID method);
0N/Avoid getPotentialCapabilities(jvmtiCapabilities *capabilities);
0N/Avoid addCapabilities(jvmtiCapabilities *capabilities);
0N/Avoid setEventCallbacks(jvmtiEventCallbacks *pcallbacks);
0N/Avoid setEventNotificationMode(jvmtiEventMode mode, jvmtiEvent event,
0N/A jthread thread);
0N/Avoid * getThreadLocalStorage(jthread thread);
0N/Avoid setThreadLocalStorage(jthread thread, void *ptr);
0N/Avoid getThreadState(jthread thread, jint *threadState);
0N/Avoid getThreadInfo(jthread thread, jvmtiThreadInfo *info);
0N/Avoid getThreadGroupInfo(jthreadGroup thread_group, jvmtiThreadGroupInfo *info);
0N/Avoid getLoadedClasses(jclass **ppclasses, jint *pcount);
0N/Ajint getLineNumber(jmethodID method, jlocation location);
0N/Ajlong getMaxMemory(JNIEnv *env);
0N/Avoid createAgentThread(JNIEnv *env, const char *name,
0N/A jvmtiStartFunction func);
0N/Ajlong getThreadCpuTime(jthread thread);
0N/Avoid getStackTrace(jthread thread, jvmtiFrameInfo *pframes, jint depth,
0N/A jint *pcount);
0N/Avoid getThreadListStackTraces(jint count, jthread *threads,
0N/A jint depth, jvmtiStackInfo **stack_info);
0N/Avoid getFrameCount(jthread thread, jint *pcount);
0N/Avoid followReferences(jvmtiHeapCallbacks *pHeapCallbacks, void *user_data);
0N/A
0N/A/* GC control */
0N/Avoid runGC(void);
0N/A
0N/A/* Get initial JVMTI environment */
0N/Avoid getJvmti(void);
0N/A
0N/A/* Get current runtime JVMTI version */
0N/Ajint jvmtiVersion(void);
0N/A
0N/A/* Raw monitor functions */
0N/AjrawMonitorID createRawMonitor(const char *str);
0N/Avoid rawMonitorEnter(jrawMonitorID m);
0N/Avoid rawMonitorWait(jrawMonitorID m, jlong pause_time);
0N/Avoid rawMonitorNotifyAll(jrawMonitorID m);
0N/Avoid rawMonitorExit(jrawMonitorID m);
0N/Avoid destroyRawMonitor(jrawMonitorID m);
0N/A
0N/A/* JVMTI alloc/dealloc */
0N/Avoid * jvmtiAllocate(int size);
0N/Avoid jvmtiDeallocate(void *ptr);
0N/A
0N/A/* System malloc/free */
0N/Avoid * hprof_malloc(int size);
0N/Avoid hprof_free(void *ptr);
0N/A
0N/A#include "debug_malloc.h"
0N/A
0N/A#ifdef DEBUG
0N/A void * hprof_debug_malloc(int size, char *file, int line);
0N/A void hprof_debug_free(void *ptr, char *file, int line);
0N/A #define HPROF_MALLOC(size) hprof_debug_malloc(size, __FILE__, __LINE__)
0N/A #define HPROF_FREE(ptr) hprof_debug_free(ptr, __FILE__, __LINE__)
0N/A#else
0N/A #define HPROF_MALLOC(size) hprof_malloc(size)
0N/A #define HPROF_FREE(ptr) hprof_free(ptr)
0N/A#endif
0N/A
0N/A#endif