LLVM API Documentation

jitprofiling.h
Go to the documentation of this file.
00001 /*===-- jitprofiling.h - JIT Profiling API-------------------------*- C -*-===*
00002  *
00003  *                     The LLVM Compiler Infrastructure
00004  *
00005  * This file is distributed under the University of Illinois Open Source
00006  * License. See LICENSE.TXT for details.
00007  *
00008  *===----------------------------------------------------------------------===*
00009  *
00010  * This file provides Intel(R) Performance Analyzer JIT (Just-In-Time) 
00011  * Profiling API declaration.
00012  *
00013  * NOTE: This file comes in a style different from the rest of LLVM
00014  * source base since  this is a piece of code shared from Intel(R)
00015  * products.  Please do not reformat / re-style this code to make
00016  * subsequent merges and contributions from the original source base eaiser.
00017  *
00018  *===----------------------------------------------------------------------===*/
00019 #ifndef __JITPROFILING_H__
00020 #define __JITPROFILING_H__
00021 
00022 /*
00023  * Various constants used by functions
00024  */
00025 
00026 /* event notification */
00027 typedef enum iJIT_jvm_event
00028 {
00029 
00030     /* shutdown  */
00031     
00032     /* 
00033      * Program exiting EventSpecificData NA
00034      */
00035     iJVM_EVENT_TYPE_SHUTDOWN = 2, 
00036 
00037     /* JIT profiling  */
00038     
00039     /* 
00040      * issued after method code jitted into memory but before code is executed
00041      * EventSpecificData is an iJIT_Method_Load
00042      */
00043     iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED=13,     
00044 
00045     /* issued before unload. Method code will no longer be executed, but code 
00046      * and info are still in memory. The VTune profiler may capture method 
00047      * code only at this point EventSpecificData is iJIT_Method_Id
00048      */
00049     iJVM_EVENT_TYPE_METHOD_UNLOAD_START,         
00050 
00051     /* Method Profiling */
00052 
00053     /* method name, Id and stack is supplied 
00054      * issued when a method is about to be entered EventSpecificData is 
00055      * iJIT_Method_NIDS
00056      */
00057     iJVM_EVENT_TYPE_ENTER_NIDS = 19, 
00058 
00059     /* method name, Id and stack is supplied 
00060      * issued when a method is about to be left EventSpecificData is 
00061      * iJIT_Method_NIDS
00062      */
00063     iJVM_EVENT_TYPE_LEAVE_NIDS               
00064 } iJIT_JVM_EVENT;
00065 
00066 typedef enum _iJIT_ModeFlags
00067 {
00068     /* No need to Notify VTune, since VTune is not running */
00069     iJIT_NO_NOTIFICATIONS          = 0x0000,     
00070 
00071     /* when turned on the jit must call 
00072      * iJIT_NotifyEvent
00073      * (
00074      *     iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED,
00075      * )
00076      * for all the method already jitted
00077      */
00078     iJIT_BE_NOTIFY_ON_LOAD         = 0x0001,     
00079 
00080     /* when turned on the jit must call
00081      * iJIT_NotifyEvent
00082      * (
00083      *     iJVM_EVENT_TYPE_METHOD_UNLOAD_FINISHED,
00084      *  ) for all the method that are unloaded
00085      */
00086     iJIT_BE_NOTIFY_ON_UNLOAD       = 0x0002,     
00087 
00088     /* when turned on the jit must instrument all
00089      * the currently jited code with calls on
00090      * method entries
00091      */
00092     iJIT_BE_NOTIFY_ON_METHOD_ENTRY = 0x0004,     
00093 
00094     /* when turned on the jit must instrument all
00095      * the currently jited code with calls
00096      * on method exit
00097      */
00098     iJIT_BE_NOTIFY_ON_METHOD_EXIT  = 0x0008      
00099 
00100 } iJIT_ModeFlags;
00101 
00102 
00103  /* Flags used by iJIT_IsProfilingActive() */
00104 typedef enum _iJIT_IsProfilingActiveFlags
00105 {
00106     /* No profiler is running. Currently not used */
00107     iJIT_NOTHING_RUNNING           = 0x0000,     
00108 
00109     /* Sampling is running. This is the default value
00110      * returned by iJIT_IsProfilingActive()
00111      */
00112     iJIT_SAMPLING_ON               = 0x0001,     
00113     
00114       /* Call Graph is running */
00115     iJIT_CALLGRAPH_ON              = 0x0002
00116 
00117 } iJIT_IsProfilingActiveFlags;
00118 
00119 /* Enumerator for the environment of methods*/
00120 typedef enum _iJDEnvironmentType
00121 {
00122     iJDE_JittingAPI = 2
00123 } iJDEnvironmentType;
00124 
00125 /**********************************
00126  * Data structures for the events *
00127  **********************************/
00128 
00129 /* structure for the events:
00130  * iJVM_EVENT_TYPE_METHOD_UNLOAD_START
00131  */
00132 
00133 typedef struct _iJIT_Method_Id
00134 {
00135    /* Id of the method (same as the one passed in
00136    * the iJIT_Method_Load struct
00137    */
00138     unsigned int       method_id;              
00139 
00140 } *piJIT_Method_Id, iJIT_Method_Id;
00141 
00142 
00143 /* structure for the events:
00144  * iJVM_EVENT_TYPE_ENTER_NIDS,
00145  * iJVM_EVENT_TYPE_LEAVE_NIDS,
00146  * iJVM_EVENT_TYPE_EXCEPTION_OCCURRED_NIDS
00147  */
00148 
00149 typedef struct _iJIT_Method_NIDS
00150 {
00151     /* unique method ID */
00152     unsigned int       method_id;              
00153 
00154     /* NOTE: no need to fill this field, it's filled by VTune */
00155     unsigned int       stack_id;               
00156 
00157     /* method name (just the method, without the class) */
00158     char*              method_name;            
00159 } *piJIT_Method_NIDS, iJIT_Method_NIDS;
00160 
00161 /* structures for the events:
00162  * iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED
00163  */
00164 
00165 typedef struct _LineNumberInfo
00166 {
00167   /* x86 Offset from the beginning of the method*/
00168   unsigned int Offset;
00169 
00170   /* source line number from the beginning of the source file */
00171     unsigned int        LineNumber;             
00172 
00173 } *pLineNumberInfo, LineNumberInfo;
00174 
00175 typedef struct _iJIT_Method_Load
00176 {
00177     /* unique method ID - can be any unique value, (except 0 - 999) */
00178     unsigned int        method_id;              
00179 
00180     /* method name (can be with or without the class and signature, in any case
00181      * the class name will be added to it)
00182      */
00183     char*               method_name;            
00184 
00185     /* virtual address of that method - This determines the method range for the
00186      * iJVM_EVENT_TYPE_ENTER/LEAVE_METHOD_ADDR events
00187      */
00188     void*               method_load_address;    
00189 
00190     /* Size in memory - Must be exact */
00191     unsigned int        method_size;            
00192 
00193     /* Line Table size in number of entries - Zero if none */
00194     unsigned int line_number_size;
00195 
00196     /* Pointer to the beginning of the line numbers info array */
00197     pLineNumberInfo     line_number_table;      
00198 
00199     /* unique class ID */
00200     unsigned int        class_id;               
00201     
00202     /* class file name */
00203     char*               class_file_name;        
00204 
00205     /* source file name */
00206     char*               source_file_name;       
00207 
00208     /* bits supplied by the user for saving in the JIT file */
00209     void*               user_data;              
00210 
00211     /* the size of the user data buffer */
00212     unsigned int        user_data_size;         
00213 
00214     /* NOTE: no need to fill this field, it's filled by VTune */
00215     iJDEnvironmentType  env;                    
00216 
00217 } *piJIT_Method_Load, iJIT_Method_Load;
00218 
00219 /* API Functions */
00220 #ifdef __cplusplus
00221 extern "C" {
00222 #endif
00223 
00224 #ifndef CDECL
00225 #  if defined WIN32 || defined _WIN32
00226 #    define CDECL __cdecl
00227 #  else /* defined WIN32 || defined _WIN32 */
00228 #    if defined _M_X64 || defined _M_AMD64 || defined __x86_64__
00229 #      define CDECL /* not actual on x86_64 platform */
00230 #    else  /* _M_X64 || _M_AMD64 || __x86_64__ */
00231 #      define CDECL __attribute__ ((cdecl))
00232 #    endif /* _M_X64 || _M_AMD64 || __x86_64__ */
00233 #  endif /* defined WIN32 || defined _WIN32 */
00234 #endif /* CDECL */
00235 
00236 #define JITAPI CDECL
00237 
00238 /* called when the settings are changed with new settings */
00239 typedef void (*iJIT_ModeChangedEx)(void *UserData, iJIT_ModeFlags Flags);
00240 
00241 int JITAPI iJIT_NotifyEvent(iJIT_JVM_EVENT event_type, void *EventSpecificData);
00242 
00243 /* The new mode call back routine */
00244 void JITAPI iJIT_RegisterCallbackEx(void *userdata, 
00245                                     iJIT_ModeChangedEx NewModeCallBackFuncEx);
00246 
00247 iJIT_IsProfilingActiveFlags JITAPI iJIT_IsProfilingActive(void);
00248 
00249 void JITAPI FinalizeThread(void);
00250 
00251 void JITAPI FinalizeProcess(void);
00252 
00253 unsigned int JITAPI iJIT_GetNewMethodID(void);
00254 
00255 #ifdef __cplusplus
00256 }
00257 #endif
00258 
00259 #endif /* __JITPROFILING_H__ */