1 /* 2 This file is provided under a dual BSD/GPLv2 license. When using or 3 redistributing this file, you may do so under either license. 4 5 GPL LICENSE SUMMARY 6 7 Copyright (c) 2005-2012 Intel Corporation. All rights reserved. 8 9 This program is free software; you can redistribute it and/or modify 10 it under the terms of version 2 of the GNU General Public License as 11 published by the Free Software Foundation. 12 13 This program is distributed in the hope that it will be useful, but 14 WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 21 The full GNU General Public License is included in this distribution 22 in the file called LICENSE.GPL. 23 24 Contact Information: 25 http://software.intel.com/en-us/articles/intel-vtune-amplifier-xe/ 26 27 BSD LICENSE 28 29 Copyright (c) 2005-2012 Intel Corporation. All rights reserved. 30 All rights reserved. 31 32 Redistribution and use in source and binary forms, with or without 33 modification, are permitted provided that the following conditions 34 are met: 35 36 * Redistributions of source code must retain the above copyright 37 notice, this list of conditions and the following disclaimer. 38 * Redistributions in binary form must reproduce the above copyright 39 notice, this list of conditions and the following disclaimer in 40 the documentation and/or other materials provided with the 41 distribution. 42 * Neither the name of Intel Corporation nor the names of its 43 contributors may be used to endorse or promote products derived 44 from this software without specific prior written permission. 45 46 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 47 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 48 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 49 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 50 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 51 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 52 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 53 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 54 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 55 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 56 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 */ 58 #ifndef __JITPROFILING_H__ 59 #define __JITPROFILING_H__ 60 61 /* 62 * Various constants used by functions 63 */ 64 65 /* event notification */ 66 typedef enum iJIT_jvm_event 67 { 68 69 /* shutdown */ 70 71 /* 72 * Program exiting EventSpecificData NA 73 */ 74 iJVM_EVENT_TYPE_SHUTDOWN = 2, 75 76 /* JIT profiling */ 77 78 /* 79 * issued after method code jitted into memory but before code is executed 80 * EventSpecificData is an iJIT_Method_Load 81 */ 82 iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED=13, 83 84 /* issued before unload. Method code will no longer be executed, but code 85 * and info are still in memory. The VTune profiler may capture method 86 * code only at this point EventSpecificData is iJIT_Method_Id 87 */ 88 iJVM_EVENT_TYPE_METHOD_UNLOAD_START, 89 90 /* Method Profiling */ 91 92 /* method name, Id and stack is supplied 93 * issued when a method is about to be entered EventSpecificData is 94 * iJIT_Method_NIDS 95 */ 96 iJVM_EVENT_TYPE_ENTER_NIDS = 19, 97 98 /* method name, Id and stack is supplied 99 * issued when a method is about to be left EventSpecificData is 100 * iJIT_Method_NIDS 101 */ 102 iJVM_EVENT_TYPE_LEAVE_NIDS 103 } iJIT_JVM_EVENT; 104 105 typedef enum _iJIT_ModeFlags 106 { 107 /* No need to Notify VTune, since VTune is not running */ 108 iJIT_NO_NOTIFICATIONS = 0x0000, 109 110 /* when turned on the jit must call 111 * iJIT_NotifyEvent 112 * ( 113 * iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, 114 * ) 115 * for all the method already jitted 116 */ 117 iJIT_BE_NOTIFY_ON_LOAD = 0x0001, 118 119 /* when turned on the jit must call 120 * iJIT_NotifyEvent 121 * ( 122 * iJVM_EVENT_TYPE_METHOD_UNLOAD_FINISHED, 123 * ) for all the method that are unloaded 124 */ 125 iJIT_BE_NOTIFY_ON_UNLOAD = 0x0002, 126 127 /* when turned on the jit must instrument all 128 * the currently jited code with calls on 129 * method entries 130 */ 131 iJIT_BE_NOTIFY_ON_METHOD_ENTRY = 0x0004, 132 133 /* when turned on the jit must instrument all 134 * the currently jited code with calls 135 * on method exit 136 */ 137 iJIT_BE_NOTIFY_ON_METHOD_EXIT = 0x0008 138 139 } iJIT_ModeFlags; 140 141 142 /* Flags used by iJIT_IsProfilingActive() */ 143 typedef enum _iJIT_IsProfilingActiveFlags 144 { 145 /* No profiler is running. Currently not used */ 146 iJIT_NOTHING_RUNNING = 0x0000, 147 148 /* Sampling is running. This is the default value 149 * returned by iJIT_IsProfilingActive() 150 */ 151 iJIT_SAMPLING_ON = 0x0001, 152 153 /* Call Graph is running */ 154 iJIT_CALLGRAPH_ON = 0x0002 155 156 } iJIT_IsProfilingActiveFlags; 157 158 /* Enumerator for the environment of methods*/ 159 typedef enum _iJDEnvironmentType 160 { 161 iJDE_JittingAPI = 2 162 } iJDEnvironmentType; 163 164 /********************************** 165 * Data structures for the events * 166 **********************************/ 167 168 /* structure for the events: 169 * iJVM_EVENT_TYPE_METHOD_UNLOAD_START 170 */ 171 172 typedef struct _iJIT_Method_Id 173 { 174 /* Id of the method (same as the one passed in 175 * the iJIT_Method_Load struct 176 */ 177 unsigned int method_id; 178 179 } *piJIT_Method_Id, iJIT_Method_Id; 180 181 182 /* structure for the events: 183 * iJVM_EVENT_TYPE_ENTER_NIDS, 184 * iJVM_EVENT_TYPE_LEAVE_NIDS, 185 * iJVM_EVENT_TYPE_EXCEPTION_OCCURRED_NIDS 186 */ 187 188 typedef struct _iJIT_Method_NIDS 189 { 190 /* unique method ID */ 191 unsigned int method_id; 192 193 /* NOTE: no need to fill this field, it's filled by VTune */ 194 unsigned int stack_id; 195 196 /* method name (just the method, without the class) */ 197 char* method_name; 198 } *piJIT_Method_NIDS, iJIT_Method_NIDS; 199 200 /* structures for the events: 201 * iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED 202 */ 203 204 typedef struct _LineNumberInfo 205 { 206 /* x86 Offset from the beginning of the method*/ 207 unsigned int Offset; 208 209 /* source line number from the beginning of the source file */ 210 unsigned int LineNumber; 211 212 } *pLineNumberInfo, LineNumberInfo; 213 214 typedef struct _iJIT_Method_Load 215 { 216 /* unique method ID - can be any unique value, (except 0 - 999) */ 217 unsigned int method_id; 218 219 /* method name (can be with or without the class and signature, in any case 220 * the class name will be added to it) 221 */ 222 char* method_name; 223 224 /* virtual address of that method - This determines the method range for the 225 * iJVM_EVENT_TYPE_ENTER/LEAVE_METHOD_ADDR events 226 */ 227 void* method_load_address; 228 229 /* Size in memory - Must be exact */ 230 unsigned int method_size; 231 232 /* Line Table size in number of entries - Zero if none */ 233 unsigned int line_number_size; 234 235 /* Pointer to the beginning of the line numbers info array */ 236 pLineNumberInfo line_number_table; 237 238 /* unique class ID */ 239 unsigned int class_id; 240 241 /* class file name */ 242 char* class_file_name; 243 244 /* source file name */ 245 char* source_file_name; 246 247 /* bits supplied by the user for saving in the JIT file */ 248 void* user_data; 249 250 /* the size of the user data buffer */ 251 unsigned int user_data_size; 252 253 /* NOTE: no need to fill this field, it's filled by VTune */ 254 iJDEnvironmentType env; 255 256 } *piJIT_Method_Load, iJIT_Method_Load; 257 258 /* API Functions */ 259 #ifdef __cplusplus 260 extern "C" { 261 #endif 262 263 #ifndef CDECL 264 # if defined WIN32 || defined _WIN32 265 # define CDECL __cdecl 266 # else /* defined WIN32 || defined _WIN32 */ 267 # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__ 268 # define CDECL /* not actual on x86_64 platform */ 269 # else /* _M_X64 || _M_AMD64 || __x86_64__ */ 270 # define CDECL __attribute__ ((cdecl)) 271 # endif /* _M_X64 || _M_AMD64 || __x86_64__ */ 272 # endif /* defined WIN32 || defined _WIN32 */ 273 #endif /* CDECL */ 274 275 #define JITAPI CDECL 276 277 /* called when the settings are changed with new settings */ 278 typedef void (*iJIT_ModeChangedEx)(void *UserData, iJIT_ModeFlags Flags); 279 280 int JITAPI iJIT_NotifyEvent(iJIT_JVM_EVENT event_type, void *EventSpecificData); 281 282 /* The new mode call back routine */ 283 void JITAPI iJIT_RegisterCallbackEx(void *userdata, 284 iJIT_ModeChangedEx NewModeCallBackFuncEx); 285 286 iJIT_IsProfilingActiveFlags JITAPI iJIT_IsProfilingActive(void); 287 288 void JITAPI FinalizeThread(void); 289 290 void JITAPI FinalizeProcess(void); 291 292 unsigned int JITAPI iJIT_GetNewMethodID(void); 293 294 #ifdef __cplusplus 295 } 296 #endif 297 298 #endif /* __JITPROFILING_H__ */ 299