1*09467b48Spatrick /*===-- jitprofiling.h - JIT Profiling API-------------------------*- C -*-===* 2*09467b48Spatrick * 3*09467b48Spatrick * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*09467b48Spatrick * See https://llvm.org/LICENSE.txt for license information. 5*09467b48Spatrick * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*09467b48Spatrick * 7*09467b48Spatrick *===----------------------------------------------------------------------===* 8*09467b48Spatrick * 9*09467b48Spatrick * This file provides Intel(R) Performance Analyzer JIT (Just-In-Time) 10*09467b48Spatrick * Profiling API declaration. 11*09467b48Spatrick * 12*09467b48Spatrick * NOTE: This file comes in a style different from the rest of LLVM 13*09467b48Spatrick * source base since this is a piece of code shared from Intel(R) 14*09467b48Spatrick * products. Please do not reformat / re-style this code to make 15*09467b48Spatrick * subsequent merges and contributions from the original source base eaiser. 16*09467b48Spatrick * 17*09467b48Spatrick *===----------------------------------------------------------------------===*/ 18*09467b48Spatrick #ifndef __JITPROFILING_H__ 19*09467b48Spatrick #define __JITPROFILING_H__ 20*09467b48Spatrick 21*09467b48Spatrick /* 22*09467b48Spatrick * Various constants used by functions 23*09467b48Spatrick */ 24*09467b48Spatrick 25*09467b48Spatrick /* event notification */ 26*09467b48Spatrick typedef enum iJIT_jvm_event 27*09467b48Spatrick { 28*09467b48Spatrick 29*09467b48Spatrick /* shutdown */ 30*09467b48Spatrick 31*09467b48Spatrick /* 32*09467b48Spatrick * Program exiting EventSpecificData NA 33*09467b48Spatrick */ 34*09467b48Spatrick iJVM_EVENT_TYPE_SHUTDOWN = 2, 35*09467b48Spatrick 36*09467b48Spatrick /* JIT profiling */ 37*09467b48Spatrick 38*09467b48Spatrick /* 39*09467b48Spatrick * issued after method code jitted into memory but before code is executed 40*09467b48Spatrick * EventSpecificData is an iJIT_Method_Load 41*09467b48Spatrick */ 42*09467b48Spatrick iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED=13, 43*09467b48Spatrick 44*09467b48Spatrick /* issued before unload. Method code will no longer be executed, but code 45*09467b48Spatrick * and info are still in memory. The VTune profiler may capture method 46*09467b48Spatrick * code only at this point EventSpecificData is iJIT_Method_Id 47*09467b48Spatrick */ 48*09467b48Spatrick iJVM_EVENT_TYPE_METHOD_UNLOAD_START, 49*09467b48Spatrick 50*09467b48Spatrick /* Method Profiling */ 51*09467b48Spatrick 52*09467b48Spatrick /* method name, Id and stack is supplied 53*09467b48Spatrick * issued when a method is about to be entered EventSpecificData is 54*09467b48Spatrick * iJIT_Method_NIDS 55*09467b48Spatrick */ 56*09467b48Spatrick iJVM_EVENT_TYPE_ENTER_NIDS = 19, 57*09467b48Spatrick 58*09467b48Spatrick /* method name, Id and stack is supplied 59*09467b48Spatrick * issued when a method is about to be left EventSpecificData is 60*09467b48Spatrick * iJIT_Method_NIDS 61*09467b48Spatrick */ 62*09467b48Spatrick iJVM_EVENT_TYPE_LEAVE_NIDS 63*09467b48Spatrick } iJIT_JVM_EVENT; 64*09467b48Spatrick 65*09467b48Spatrick typedef enum _iJIT_ModeFlags 66*09467b48Spatrick { 67*09467b48Spatrick /* No need to Notify VTune, since VTune is not running */ 68*09467b48Spatrick iJIT_NO_NOTIFICATIONS = 0x0000, 69*09467b48Spatrick 70*09467b48Spatrick /* when turned on the jit must call 71*09467b48Spatrick * iJIT_NotifyEvent 72*09467b48Spatrick * ( 73*09467b48Spatrick * iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, 74*09467b48Spatrick * ) 75*09467b48Spatrick * for all the method already jitted 76*09467b48Spatrick */ 77*09467b48Spatrick iJIT_BE_NOTIFY_ON_LOAD = 0x0001, 78*09467b48Spatrick 79*09467b48Spatrick /* when turned on the jit must call 80*09467b48Spatrick * iJIT_NotifyEvent 81*09467b48Spatrick * ( 82*09467b48Spatrick * iJVM_EVENT_TYPE_METHOD_UNLOAD_FINISHED, 83*09467b48Spatrick * ) for all the method that are unloaded 84*09467b48Spatrick */ 85*09467b48Spatrick iJIT_BE_NOTIFY_ON_UNLOAD = 0x0002, 86*09467b48Spatrick 87*09467b48Spatrick /* when turned on the jit must instrument all 88*09467b48Spatrick * the currently jited code with calls on 89*09467b48Spatrick * method entries 90*09467b48Spatrick */ 91*09467b48Spatrick iJIT_BE_NOTIFY_ON_METHOD_ENTRY = 0x0004, 92*09467b48Spatrick 93*09467b48Spatrick /* when turned on the jit must instrument all 94*09467b48Spatrick * the currently jited code with calls 95*09467b48Spatrick * on method exit 96*09467b48Spatrick */ 97*09467b48Spatrick iJIT_BE_NOTIFY_ON_METHOD_EXIT = 0x0008 98*09467b48Spatrick 99*09467b48Spatrick } iJIT_ModeFlags; 100*09467b48Spatrick 101*09467b48Spatrick 102*09467b48Spatrick /* Flags used by iJIT_IsProfilingActive() */ 103*09467b48Spatrick typedef enum _iJIT_IsProfilingActiveFlags 104*09467b48Spatrick { 105*09467b48Spatrick /* No profiler is running. Currently not used */ 106*09467b48Spatrick iJIT_NOTHING_RUNNING = 0x0000, 107*09467b48Spatrick 108*09467b48Spatrick /* Sampling is running. This is the default value 109*09467b48Spatrick * returned by iJIT_IsProfilingActive() 110*09467b48Spatrick */ 111*09467b48Spatrick iJIT_SAMPLING_ON = 0x0001, 112*09467b48Spatrick 113*09467b48Spatrick /* Call Graph is running */ 114*09467b48Spatrick iJIT_CALLGRAPH_ON = 0x0002 115*09467b48Spatrick 116*09467b48Spatrick } iJIT_IsProfilingActiveFlags; 117*09467b48Spatrick 118*09467b48Spatrick /* Enumerator for the environment of methods*/ 119*09467b48Spatrick typedef enum _iJDEnvironmentType 120*09467b48Spatrick { 121*09467b48Spatrick iJDE_JittingAPI = 2 122*09467b48Spatrick } iJDEnvironmentType; 123*09467b48Spatrick 124*09467b48Spatrick /********************************** 125*09467b48Spatrick * Data structures for the events * 126*09467b48Spatrick **********************************/ 127*09467b48Spatrick 128*09467b48Spatrick /* structure for the events: 129*09467b48Spatrick * iJVM_EVENT_TYPE_METHOD_UNLOAD_START 130*09467b48Spatrick */ 131*09467b48Spatrick 132*09467b48Spatrick typedef struct _iJIT_Method_Id 133*09467b48Spatrick { 134*09467b48Spatrick /* Id of the method (same as the one passed in 135*09467b48Spatrick * the iJIT_Method_Load struct 136*09467b48Spatrick */ 137*09467b48Spatrick unsigned int method_id; 138*09467b48Spatrick 139*09467b48Spatrick } *piJIT_Method_Id, iJIT_Method_Id; 140*09467b48Spatrick 141*09467b48Spatrick 142*09467b48Spatrick /* structure for the events: 143*09467b48Spatrick * iJVM_EVENT_TYPE_ENTER_NIDS, 144*09467b48Spatrick * iJVM_EVENT_TYPE_LEAVE_NIDS, 145*09467b48Spatrick * iJVM_EVENT_TYPE_EXCEPTION_OCCURRED_NIDS 146*09467b48Spatrick */ 147*09467b48Spatrick 148*09467b48Spatrick typedef struct _iJIT_Method_NIDS 149*09467b48Spatrick { 150*09467b48Spatrick /* unique method ID */ 151*09467b48Spatrick unsigned int method_id; 152*09467b48Spatrick 153*09467b48Spatrick /* NOTE: no need to fill this field, it's filled by VTune */ 154*09467b48Spatrick unsigned int stack_id; 155*09467b48Spatrick 156*09467b48Spatrick /* method name (just the method, without the class) */ 157*09467b48Spatrick char* method_name; 158*09467b48Spatrick } *piJIT_Method_NIDS, iJIT_Method_NIDS; 159*09467b48Spatrick 160*09467b48Spatrick /* structures for the events: 161*09467b48Spatrick * iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED 162*09467b48Spatrick */ 163*09467b48Spatrick 164*09467b48Spatrick typedef struct _LineNumberInfo 165*09467b48Spatrick { 166*09467b48Spatrick /* x86 Offset from the beginning of the method*/ 167*09467b48Spatrick unsigned int Offset; 168*09467b48Spatrick 169*09467b48Spatrick /* source line number from the beginning of the source file */ 170*09467b48Spatrick unsigned int LineNumber; 171*09467b48Spatrick 172*09467b48Spatrick } *pLineNumberInfo, LineNumberInfo; 173*09467b48Spatrick 174*09467b48Spatrick typedef struct _iJIT_Method_Load 175*09467b48Spatrick { 176*09467b48Spatrick /* unique method ID - can be any unique value, (except 0 - 999) */ 177*09467b48Spatrick unsigned int method_id; 178*09467b48Spatrick 179*09467b48Spatrick /* method name (can be with or without the class and signature, in any case 180*09467b48Spatrick * the class name will be added to it) 181*09467b48Spatrick */ 182*09467b48Spatrick char* method_name; 183*09467b48Spatrick 184*09467b48Spatrick /* virtual address of that method - This determines the method range for the 185*09467b48Spatrick * iJVM_EVENT_TYPE_ENTER/LEAVE_METHOD_ADDR events 186*09467b48Spatrick */ 187*09467b48Spatrick void* method_load_address; 188*09467b48Spatrick 189*09467b48Spatrick /* Size in memory - Must be exact */ 190*09467b48Spatrick unsigned int method_size; 191*09467b48Spatrick 192*09467b48Spatrick /* Line Table size in number of entries - Zero if none */ 193*09467b48Spatrick unsigned int line_number_size; 194*09467b48Spatrick 195*09467b48Spatrick /* Pointer to the beginning of the line numbers info array */ 196*09467b48Spatrick pLineNumberInfo line_number_table; 197*09467b48Spatrick 198*09467b48Spatrick /* unique class ID */ 199*09467b48Spatrick unsigned int class_id; 200*09467b48Spatrick 201*09467b48Spatrick /* class file name */ 202*09467b48Spatrick char* class_file_name; 203*09467b48Spatrick 204*09467b48Spatrick /* source file name */ 205*09467b48Spatrick char* source_file_name; 206*09467b48Spatrick 207*09467b48Spatrick /* bits supplied by the user for saving in the JIT file */ 208*09467b48Spatrick void* user_data; 209*09467b48Spatrick 210*09467b48Spatrick /* the size of the user data buffer */ 211*09467b48Spatrick unsigned int user_data_size; 212*09467b48Spatrick 213*09467b48Spatrick /* NOTE: no need to fill this field, it's filled by VTune */ 214*09467b48Spatrick iJDEnvironmentType env; 215*09467b48Spatrick 216*09467b48Spatrick } *piJIT_Method_Load, iJIT_Method_Load; 217*09467b48Spatrick 218*09467b48Spatrick /* API Functions */ 219*09467b48Spatrick #ifdef __cplusplus 220*09467b48Spatrick extern "C" { 221*09467b48Spatrick #endif 222*09467b48Spatrick 223*09467b48Spatrick #ifndef CDECL 224*09467b48Spatrick # if defined WIN32 || defined _WIN32 225*09467b48Spatrick # define CDECL __cdecl 226*09467b48Spatrick # else /* defined WIN32 || defined _WIN32 */ 227*09467b48Spatrick # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__ 228*09467b48Spatrick # define CDECL /* not actual on x86_64 platform */ 229*09467b48Spatrick # else /* _M_X64 || _M_AMD64 || __x86_64__ */ 230*09467b48Spatrick # define CDECL __attribute__ ((cdecl)) 231*09467b48Spatrick # endif /* _M_X64 || _M_AMD64 || __x86_64__ */ 232*09467b48Spatrick # endif /* defined WIN32 || defined _WIN32 */ 233*09467b48Spatrick #endif /* CDECL */ 234*09467b48Spatrick 235*09467b48Spatrick #define JITAPI CDECL 236*09467b48Spatrick 237*09467b48Spatrick /* called when the settings are changed with new settings */ 238*09467b48Spatrick typedef void (*iJIT_ModeChangedEx)(void *UserData, iJIT_ModeFlags Flags); 239*09467b48Spatrick 240*09467b48Spatrick int JITAPI iJIT_NotifyEvent(iJIT_JVM_EVENT event_type, void *EventSpecificData); 241*09467b48Spatrick 242*09467b48Spatrick /* The new mode call back routine */ 243*09467b48Spatrick void JITAPI iJIT_RegisterCallbackEx(void *userdata, 244*09467b48Spatrick iJIT_ModeChangedEx NewModeCallBackFuncEx); 245*09467b48Spatrick 246*09467b48Spatrick iJIT_IsProfilingActiveFlags JITAPI iJIT_IsProfilingActive(void); 247*09467b48Spatrick 248*09467b48Spatrick void JITAPI FinalizeThread(void); 249*09467b48Spatrick 250*09467b48Spatrick void JITAPI FinalizeProcess(void); 251*09467b48Spatrick 252*09467b48Spatrick unsigned int JITAPI iJIT_GetNewMethodID(void); 253*09467b48Spatrick 254*09467b48Spatrick #ifdef __cplusplus 255*09467b48Spatrick } 256*09467b48Spatrick #endif 257*09467b48Spatrick 258*09467b48Spatrick #endif /* __JITPROFILING_H__ */ 259