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