00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef HPROF_UTIL_H
00038 #define HPROF_UTIL_H
00039
00040
00041 #define WITH_LOCAL_REFS(env, number) \
00042 { \
00043 JNIEnv *_env = (env); \
00044 pushLocalFrame(_env, number); \
00045 {
00046
00047 #define END_WITH_LOCAL_REFS \
00048 } \
00049 popLocalFrame(_env, NULL); \
00050 }
00051
00052
00053 #define CHECK_EXCEPTIONS(env) \
00054 { \
00055 JNIEnv *_env = (env); \
00056 jobject _exception; \
00057 _exception = exceptionOccurred(_env); \
00058 if ( _exception != NULL ) { \
00059 exceptionDescribe(_env); \
00060 HPROF_ERROR(JNI_TRUE, "Unexpected Exception found beforehand");\
00061 } \
00062 {
00063
00064 #define END_CHECK_EXCEPTIONS \
00065 } \
00066 _exception = exceptionOccurred(_env); \
00067 if ( _exception != NULL ) { \
00068 exceptionDescribe(_env); \
00069 HPROF_ERROR(JNI_TRUE, "Unexpected Exception found afterward");\
00070 } \
00071 }
00072
00073 JNIEnv * getEnv(void);
00074
00075
00076 jobject newGlobalReference(JNIEnv *env, jobject object);
00077 jobject newWeakGlobalReference(JNIEnv *env, jobject object);
00078 void deleteGlobalReference(JNIEnv *env, jobject object);
00079 jobject newLocalReference(JNIEnv *env, jobject object);
00080 void deleteLocalReference(JNIEnv *env, jobject object);
00081 void deleteWeakGlobalReference(JNIEnv *env, jobject object);
00082 jclass getObjectClass(JNIEnv *env, jobject object);
00083 jmethodID getMethodID(JNIEnv *env, jclass clazz, const char* name,
00084 const char *sig);
00085 jclass getSuperclass(JNIEnv *env, jclass klass);
00086 jmethodID getStaticMethodID(JNIEnv *env, jclass clazz, const char* name,
00087 const char *sig);
00088 jfieldID getStaticFieldID(JNIEnv *env, jclass clazz, const char* name,
00089 const char *sig);
00090 jclass findClass(JNIEnv *env, const char *name);
00091 void setStaticIntField(JNIEnv *env, jclass clazz, jfieldID field,
00092 jint value);
00093 jboolean isSameObject(JNIEnv *env, jobject o1, jobject o2);
00094 void pushLocalFrame(JNIEnv *env, jint capacity);
00095 void popLocalFrame(JNIEnv *env, jobject ret);
00096 jobject exceptionOccurred(JNIEnv *env);
00097 void exceptionDescribe(JNIEnv *env);
00098 void exceptionClear(JNIEnv *env);
00099 void registerNatives(JNIEnv *env, jclass clazz,
00100 JNINativeMethod *methods, jint count);
00101
00102
00103 char * getErrorName(jvmtiError error_number);
00104 jvmtiPhase getPhase(void);
00105 char * phaseString(jvmtiPhase phase);
00106 void disposeEnvironment(void);
00107 jlong getObjectSize(jobject object);
00108 jobject getClassLoader(jclass klass);
00109 jint getClassStatus(jclass klass);
00110 jlong getTag(jobject object);
00111 void setTag(jobject object, jlong tag);
00112 void getObjectMonitorUsage(jobject object, jvmtiMonitorUsage *uinfo);
00113 void getOwnedMonitorInfo(jthread thread, jobject **ppobjects,
00114 jint *pcount);
00115 void getSystemProperty(const char *name, char **value);
00116 void getClassSignature(jclass klass, char**psignature,
00117 char **pgeneric_signature);
00118 void getSourceFileName(jclass klass, char** src_name_ptr);
00119
00120 jvmtiPrimitiveType sigToPrimType(char *sig);
00121 int sigToPrimSize(char *sig);
00122 char primTypeToSigChar(jvmtiPrimitiveType primType);
00123
00124 void getAllClassFieldInfo(JNIEnv *env, jclass klass,
00125 jint* field_count_ptr, FieldInfo** fields_ptr);
00126 void getMethodName(jmethodID method, char** name_ptr,
00127 char** signature_ptr);
00128 void getMethodClass(jmethodID method, jclass *pclazz);
00129 jboolean isMethodNative(jmethodID method);
00130 void getPotentialCapabilities(jvmtiCapabilities *capabilities);
00131 void addCapabilities(jvmtiCapabilities *capabilities);
00132 void setEventCallbacks(jvmtiEventCallbacks *pcallbacks);
00133 void setEventNotificationMode(jvmtiEventMode mode, jvmtiEvent event,
00134 jthread thread);
00135 void * getThreadLocalStorage(jthread thread);
00136 void setThreadLocalStorage(jthread thread, void *ptr);
00137 void getThreadState(jthread thread, jint *threadState);
00138 void getThreadInfo(jthread thread, jvmtiThreadInfo *info);
00139 void getThreadGroupInfo(jthreadGroup thread_group, jvmtiThreadGroupInfo *info);
00140 void getLoadedClasses(jclass **ppclasses, jint *pcount);
00141 jint getLineNumber(jmethodID method, jlocation location);
00142 jlong getMaxMemory(JNIEnv *env);
00143 void createAgentThread(JNIEnv *env, const char *name,
00144 jvmtiStartFunction func);
00145 jlong getThreadCpuTime(jthread thread);
00146 void getStackTrace(jthread thread, jvmtiFrameInfo *pframes, jint depth,
00147 jint *pcount);
00148 void getThreadListStackTraces(jint count, jthread *threads,
00149 jint depth, jvmtiStackInfo **stack_info);
00150 void getFrameCount(jthread thread, jint *pcount);
00151 void followReferences(jvmtiHeapCallbacks *pHeapCallbacks, void *user_data);
00152
00153
00154 void runGC(void);
00155
00156
00157 void getJvmti(void);
00158
00159
00160 jint jvmtiVersion(void);
00161
00162
00163 jrawMonitorID createRawMonitor(const char *str);
00164 void rawMonitorEnter(jrawMonitorID m);
00165 void rawMonitorWait(jrawMonitorID m, jlong pause_time);
00166 void rawMonitorNotifyAll(jrawMonitorID m);
00167 void rawMonitorExit(jrawMonitorID m);
00168 void destroyRawMonitor(jrawMonitorID m);
00169
00170
00171 void * jvmtiAllocate(int size);
00172 void jvmtiDeallocate(void *ptr);
00173
00174
00175 void * hprof_malloc(int size);
00176 void hprof_free(void *ptr);
00177
00178 #include "debug_malloc.h"
00179
00180 #ifdef DEBUG
00181 void * hprof_debug_malloc(int size, char *file, int line);
00182 void hprof_debug_free(void *ptr, char *file, int line);
00183 #define HPROF_MALLOC(size) hprof_debug_malloc(size, __FILE__, __LINE__)
00184 #define HPROF_FREE(ptr) hprof_debug_free(ptr, __FILE__, __LINE__)
00185 #else
00186 #define HPROF_MALLOC(size) hprof_malloc(size)
00187 #define HPROF_FREE(ptr) hprof_free(ptr)
00188 #endif
00189
00190 #endif