V8 Project
jitprofiling.cc File Reference
#include "ittnotify_config.h"
#include <windows.h>
#include <malloc.h>
#include <stdlib.h>
#include "jitprofiling.h"
#include <stdio.h>
+ Include dependency graph for jitprofiling.cc:

Go to the source code of this file.

Classes

struct  ThreadStack
 

Macros

#define DLL_ENVIRONMENT_VAR   "VS_PROFILER"
 
#define NEW_DLL_ENVIRONMENT_VAR   "INTEL_JIT_PROFILER32"
 
#define DEFAULT_DLLNAME   "JitPI.dll"
 
#define ANDROID_JIT_AGENT_PATH   "/data/intel/libittnotify.so"
 
#define INIT_TOP_Stack   10000
 

Typedefs

typedef unsigned int(* TPInitialize) (void)
 
typedef unsigned int(* TPNotify) (unsigned int, void *)
 
typedef struct ThreadStackpThreadStack
 

Functions

static int loadiJIT_Funcs (void)
 
ITT_EXTERN_C int JITAPI iJIT_NotifyEvent (iJIT_JVM_EVENT event_type, void *EventSpecificData)
 
ITT_EXTERN_C void JITAPI iJIT_RegisterCallbackEx (void *userdata, iJIT_ModeChangedEx NewModeCallBackFuncEx)
 
ITT_EXTERN_C iJIT_IsProfilingActiveFlags JITAPI iJIT_IsProfilingActive ()
 
ITT_EXTERN_C void JITAPI FinalizeThread ()
 
ITT_EXTERN_C void JITAPI FinalizeProcess ()
 
ITT_EXTERN_C unsigned int JITAPI iJIT_GetNewMethodID ()
 

Variables

static const char rcsid [] = "\n@(#) $Revision: 234474 $\n"
 
HINSTANCE m_libHandle = NULL
 
static TPInitialize FUNC_Initialize =NULL
 
static TPNotify FUNC_NotifyEvent =NULL
 
static iJIT_IsProfilingActiveFlags executionMode = iJIT_NOTHING_RUNNING
 
static int iJIT_DLL_is_missing = 0
 
static DWORD threadLocalStorageHandle = 0
 

Macro Definition Documentation

◆ ANDROID_JIT_AGENT_PATH

#define ANDROID_JIT_AGENT_PATH   "/data/intel/libittnotify.so"

Definition at line 93 of file jitprofiling.cc.

◆ DEFAULT_DLLNAME

#define DEFAULT_DLLNAME   "JitPI.dll"

Definition at line 85 of file jitprofiling.cc.

◆ DLL_ENVIRONMENT_VAR

#define DLL_ENVIRONMENT_VAR   "VS_PROFILER"

Definition at line 74 of file jitprofiling.cc.

◆ INIT_TOP_Stack

#define INIT_TOP_Stack   10000

Definition at line 130 of file jitprofiling.cc.

◆ NEW_DLL_ENVIRONMENT_VAR

#define NEW_DLL_ENVIRONMENT_VAR   "INTEL_JIT_PROFILER32"

Definition at line 78 of file jitprofiling.cc.

Typedef Documentation

◆ pThreadStack

typedef struct ThreadStack * pThreadStack

◆ TPInitialize

typedef unsigned int(* TPInitialize) (void)

Definition at line 96 of file jitprofiling.cc.

◆ TPNotify

typedef unsigned int(* TPNotify) (unsigned int, void *)

Definition at line 99 of file jitprofiling.cc.

Function Documentation

◆ FinalizeProcess()

ITT_EXTERN_C void JITAPI FinalizeProcess ( void  )

Definition at line 465 of file jitprofiling.cc.

466 {
467  if (m_libHandle)
468  {
469 #if ITT_PLATFORM==ITT_PLATFORM_WIN
470  FreeLibrary(m_libHandle);
471 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
472  dlclose(m_libHandle);
473 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
474  m_libHandle = NULL;
475  }
476 
478 #if ITT_PLATFORM==ITT_PLATFORM_WIN
479  TlsFree (threadLocalStorageHandle);
480 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
481  pthread_key_delete(threadLocalStorageHandle);
482 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
483 }
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
static DWORD threadLocalStorageHandle
HINSTANCE m_libHandle
Definition: jitprofiling.cc:86

References m_libHandle, NULL, and threadLocalStorageHandle.

◆ FinalizeThread()

ITT_EXTERN_C void JITAPI FinalizeThread ( void  )

Definition at line 439 of file jitprofiling.cc.

440 {
442  {
443 #if ITT_PLATFORM==ITT_PLATFORM_WIN
444  pThreadStack threadStack = (pThreadStack)TlsGetValue (threadLocalStorageHandle);
445 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
446  pThreadStack threadStack = (pThreadStack)pthread_getspecific(threadLocalStorageHandle);
447 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
448  if (threadStack)
449  {
450  free (threadStack);
451  threadStack = NULL;
452 #if ITT_PLATFORM==ITT_PLATFORM_WIN
453  TlsSetValue (threadLocalStorageHandle, threadStack);
454 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
455  pthread_setspecific(threadLocalStorageHandle, threadStack);
456 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
457  }
458  }
459 }
struct ThreadStack * pThreadStack

References NULL, and threadLocalStorageHandle.

◆ iJIT_GetNewMethodID()

ITT_EXTERN_C unsigned int JITAPI iJIT_GetNewMethodID ( void  )

Definition at line 490 of file jitprofiling.cc.

491 {
492  static unsigned int methodID = 0x100000;
493 
494  if (methodID == 0)
495  return 0; // ERROR : this is not a valid value
496 
497  return methodID++;
498 }

Referenced by vTune::internal::VTUNEJITInterface::event_handler().

+ Here is the caller graph for this function:

◆ iJIT_IsProfilingActive()

ITT_EXTERN_C iJIT_IsProfilingActiveFlags JITAPI iJIT_IsProfilingActive ( void  )

Definition at line 286 of file jitprofiling.cc.

287 {
288  if (!iJIT_DLL_is_missing)
289  {
290  loadiJIT_Funcs();
291  }
292 
293  return executionMode;
294 }
static int iJIT_DLL_is_missing
static int loadiJIT_Funcs(void)
static iJIT_IsProfilingActiveFlags executionMode

References executionMode, iJIT_DLL_is_missing, and loadiJIT_Funcs().

+ Here is the call graph for this function:

◆ iJIT_NotifyEvent()

ITT_EXTERN_C int JITAPI iJIT_NotifyEvent ( iJIT_JVM_EVENT  event_type,
void *  EventSpecificData 
)

Definition at line 151 of file jitprofiling.cc.

152 {
153  int ReturnValue;
154 
155  /*******************************************************************************
156  ** This section is for debugging outside of VTune.
157  ** It creates the environment variables that indicates call graph mode.
158  ** If running outside of VTune remove the remark.
159  **
160 
161  static int firstTime = 1;
162  char DoCallGraph[12] = "DoCallGraph";
163  if (firstTime)
164  {
165  firstTime = 0;
166  SetEnvironmentVariable( "BISTRO_COLLECTORS_DO_CALLGRAPH", DoCallGraph);
167  }
168 
169  ** end of section.
170  *******************************************************************************/
171 
172  /* initialization part - the functions have not been loaded yet. This part
173  ** will load the functions, and check if we are in Call Graph mode.
174  ** (for special treatment).
175  */
176  if (!FUNC_NotifyEvent)
177  {
179  return 0;
180 
181  // load the Function from the DLL
182  if (!loadiJIT_Funcs())
183  return 0;
184 
185  /* Call Graph initialization. */
186  }
187 
188  /* If the event is method entry/exit, check that in the current mode
189  ** VTune is allowed to receive it
190  */
191  if ((event_type == iJVM_EVENT_TYPE_ENTER_NIDS || event_type == iJVM_EVENT_TYPE_LEAVE_NIDS) &&
193  {
194  return 0;
195  }
196  /* This section is performed when method enter event occurs.
197  ** It updates the virtual stack, or creates it if this is the first
198  ** method entry in the thread. The stack pointer is decreased.
199  */
200  if (event_type == iJVM_EVENT_TYPE_ENTER_NIDS)
201  {
202 #if ITT_PLATFORM==ITT_PLATFORM_WIN
203  pThreadStack threadStack = (pThreadStack)TlsGetValue (threadLocalStorageHandle);
204 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
205  pThreadStack threadStack = (pThreadStack)pthread_getspecific(threadLocalStorageHandle);
206 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
207 
208  // check for use of reserved method IDs
209  if ( ((piJIT_Method_NIDS) EventSpecificData)->method_id <= 999 )
210  return 0;
211 
212  if (!threadStack)
213  {
214  // initialize the stack.
215  threadStack = (pThreadStack) calloc (sizeof(ThreadStack), 1);
216  threadStack->TopStack = INIT_TOP_Stack;
217  threadStack->CurrentStack = INIT_TOP_Stack;
218 #if ITT_PLATFORM==ITT_PLATFORM_WIN
219  TlsSetValue(threadLocalStorageHandle,(void*)threadStack);
220 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
221  pthread_setspecific(threadLocalStorageHandle,(void*)threadStack);
222 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
223  }
224 
225  // decrease the stack.
226  ((piJIT_Method_NIDS) EventSpecificData)->stack_id = (threadStack->CurrentStack)--;
227  }
228 
229  /* This section is performed when method leave event occurs
230  ** It updates the virtual stack.
231  ** Increases the stack pointer.
232  ** If the stack pointer reached the top (left the global function)
233  ** increase the pointer and the top pointer.
234  */
235  if (event_type == iJVM_EVENT_TYPE_LEAVE_NIDS)
236  {
237 #if ITT_PLATFORM==ITT_PLATFORM_WIN
238  pThreadStack threadStack = (pThreadStack)TlsGetValue (threadLocalStorageHandle);
239 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
240  pThreadStack threadStack = (pThreadStack)pthread_getspecific(threadLocalStorageHandle);
241 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
242 
243  // check for use of reserved method IDs
244  if ( ((piJIT_Method_NIDS) EventSpecificData)->method_id <= 999 )
245  return 0;
246 
247  if (!threadStack)
248  {
249  /* Error: first report in this thread is method exit */
250  exit (1);
251  }
252 
253  ((piJIT_Method_NIDS) EventSpecificData)->stack_id = ++(threadStack->CurrentStack) + 1;
254 
255  if (((piJIT_Method_NIDS) EventSpecificData)->stack_id > threadStack->TopStack)
256  ((piJIT_Method_NIDS) EventSpecificData)->stack_id = (unsigned int)-1;
257  }
258 
259  if (event_type == iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED)
260  {
261  // check for use of reserved method IDs
262  if ( ((piJIT_Method_Load) EventSpecificData)->method_id <= 999 )
263  return 0;
264  }
265 
266  ReturnValue = (int)FUNC_NotifyEvent(event_type, EventSpecificData);
267 
268  return ReturnValue;
269 }
#define INIT_TOP_Stack
static TPNotify FUNC_NotifyEvent
@ iJVM_EVENT_TYPE_ENTER_NIDS
Definition: jitprofiling.h:96
@ iJVM_EVENT_TYPE_LEAVE_NIDS
Definition: jitprofiling.h:102
@ iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED
Definition: jitprofiling.h:82
@ iJIT_CALLGRAPH_ON
Definition: jitprofiling.h:154
struct _iJIT_Method_NIDS * piJIT_Method_NIDS
unsigned int TopStack
unsigned int CurrentStack

References ThreadStack::CurrentStack, executionMode, FUNC_NotifyEvent, iJIT_CALLGRAPH_ON, iJIT_DLL_is_missing, iJVM_EVENT_TYPE_ENTER_NIDS, iJVM_EVENT_TYPE_LEAVE_NIDS, iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, INIT_TOP_Stack, loadiJIT_Funcs(), threadLocalStorageHandle, and ThreadStack::TopStack.

Referenced by vTune::internal::VTUNEJITInterface::event_handler().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ iJIT_RegisterCallbackEx()

ITT_EXTERN_C void JITAPI iJIT_RegisterCallbackEx ( void *  userdata,
iJIT_ModeChangedEx  NewModeCallBackFuncEx 
)

Definition at line 271 of file jitprofiling.cc.

272 {
273  // is it already missing... or the load of functions from the DLL failed
275  {
276  NewModeCallBackFuncEx(userdata, iJIT_NO_NOTIFICATIONS); // then do not bother with notifications
277  /* Error: could not load JIT functions. */
278  return;
279  }
280  // nothing to do with the callback
281 }
@ iJIT_NO_NOTIFICATIONS
Definition: jitprofiling.h:108

References iJIT_DLL_is_missing, iJIT_NO_NOTIFICATIONS, and loadiJIT_Funcs().

+ Here is the call graph for this function:

◆ loadiJIT_Funcs()

static int loadiJIT_Funcs ( void  )
static

Definition at line 300 of file jitprofiling.cc.

301 {
302  static int bDllWasLoaded = 0;
303  char *dllName = (char*)rcsid; // !!! Just to avoid unused code elimination !!!
304 #if ITT_PLATFORM==ITT_PLATFORM_WIN
305  DWORD dNameLength = 0;
306 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
307 
308  if(bDllWasLoaded)
309  {// dll was already loaded, no need to do it for the second time
310  return 1;
311  }
312 
313  // Assumes that the DLL will not be found
316 
317  if (m_libHandle)
318  {
319 #if ITT_PLATFORM==ITT_PLATFORM_WIN
320  FreeLibrary(m_libHandle);
321 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
322  dlclose(m_libHandle);
323 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
324  m_libHandle = NULL;
325  }
326 
327  // try to get the dll name from the environment
328 #if ITT_PLATFORM==ITT_PLATFORM_WIN
329  dNameLength = GetEnvironmentVariableA(NEW_DLL_ENVIRONMENT_VAR, NULL, 0);
330  if (dNameLength)
331  {
332  DWORD envret = 0;
333  dllName = (char*)malloc(sizeof(char) * (dNameLength + 1));
334  envret = GetEnvironmentVariableA(NEW_DLL_ENVIRONMENT_VAR, dllName, dNameLength);
335  if (envret)
336  {
337  // Try to load the dll from the PATH...
338  m_libHandle = LoadLibraryExA(dllName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
339  }
340  free(dllName);
341  } else {
342  // Try to use old VS_PROFILER variable
343  dNameLength = GetEnvironmentVariableA(DLL_ENVIRONMENT_VAR, NULL, 0);
344  if (dNameLength)
345  {
346  DWORD envret = 0;
347  dllName = (char*)malloc(sizeof(char) * (dNameLength + 1));
348  envret = GetEnvironmentVariableA(DLL_ENVIRONMENT_VAR, dllName, dNameLength);
349  if (envret)
350  {
351  // Try to load the dll from the PATH...
352  m_libHandle = LoadLibraryA(dllName);
353  }
354  free(dllName);
355  }
356  }
357 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
358  dllName = getenv(NEW_DLL_ENVIRONMENT_VAR);
359  if (!dllName) {
360  dllName = getenv(DLL_ENVIRONMENT_VAR);
361  }
362 #ifdef ANDROID
363  if (!dllName)
364  dllName = ANDROID_JIT_AGENT_PATH;
365 #endif
366  if (dllName)
367  {
368  // Try to load the dll from the PATH...
369  m_libHandle = dlopen(dllName, RTLD_LAZY);
370  }
371 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
372 
373  if (!m_libHandle)
374  {
375 #if ITT_PLATFORM==ITT_PLATFORM_WIN
376  m_libHandle = LoadLibraryA(DEFAULT_DLLNAME);
377 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
378  m_libHandle = dlopen(DEFAULT_DLLNAME, RTLD_LAZY);
379 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
380  }
381 
382  // if the dll wasn't loaded - exit.
383  if (!m_libHandle)
384  {
385  iJIT_DLL_is_missing = 1; // don't try to initialize JIT agent the second time
386  return 0;
387  }
388 #if ITT_PLATFORM==ITT_PLATFORM_WIN
389  FUNC_NotifyEvent = (TPNotify)GetProcAddress(m_libHandle, "NotifyEvent");
390 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
391  FUNC_NotifyEvent = reinterpret_cast<TPNotify>(reinterpret_cast<intptr_t>(dlsym(m_libHandle, "NotifyEvent")));
392 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
393  if (!FUNC_NotifyEvent)
394  {
396  return 0;
397  }
398 
399 #if ITT_PLATFORM==ITT_PLATFORM_WIN
400  FUNC_Initialize = (TPInitialize)GetProcAddress(m_libHandle, "Initialize");
401 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
402  FUNC_Initialize = reinterpret_cast<TPInitialize>(reinterpret_cast<intptr_t>(dlsym(m_libHandle, "Initialize")));
403 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
404  if (!FUNC_Initialize)
405  {
407  return 0;
408  }
409 
413 
414  bDllWasLoaded = 1;
415  iJIT_DLL_is_missing = 0; // DLL is ok.
416 
417  /*
418  ** Call Graph mode: init the thread local storage
419  ** (need to store the virtual stack there).
420  */
422  {
423  // Allocate a thread local storage slot for the thread "stack"
425 #if ITT_PLATFORM==ITT_PLATFORM_WIN
426  threadLocalStorageHandle = TlsAlloc();
427 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
428  pthread_key_create(&threadLocalStorageHandle, NULL);
429 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
430  }
431 
432  return 1;
433 }
#define ANDROID_JIT_AGENT_PATH
Definition: jitprofiling.cc:93
unsigned int(* TPNotify)(unsigned int, void *)
Definition: jitprofiling.cc:99
#define DEFAULT_DLLNAME
Definition: jitprofiling.cc:85
static TPInitialize FUNC_Initialize
Definition: jitprofiling.cc:97
static const char rcsid[]
Definition: jitprofiling.cc:72
unsigned int(* TPInitialize)(void)
Definition: jitprofiling.cc:96
#define NEW_DLL_ENVIRONMENT_VAR
Definition: jitprofiling.cc:78
#define DLL_ENVIRONMENT_VAR
Definition: jitprofiling.cc:74
@ iJIT_SAMPLING_ON
Definition: jitprofiling.h:151
enum _iJIT_IsProfilingActiveFlags iJIT_IsProfilingActiveFlags
typedef DWORD(__stdcall *DLL_FUNC_TYPE(SymGetOptions))(VOID)

References ANDROID_JIT_AGENT_PATH, DEFAULT_DLLNAME, DLL_ENVIRONMENT_VAR, v8::base::DWORD(), executionMode, FUNC_Initialize, FUNC_NotifyEvent, iJIT_CALLGRAPH_ON, iJIT_DLL_is_missing, iJIT_SAMPLING_ON, m_libHandle, NEW_DLL_ENVIRONMENT_VAR, NULL, rcsid, and threadLocalStorageHandle.

Referenced by iJIT_IsProfilingActive(), iJIT_NotifyEvent(), and iJIT_RegisterCallbackEx().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ executionMode

◆ FUNC_Initialize

TPInitialize FUNC_Initialize =NULL
static

Definition at line 97 of file jitprofiling.cc.

Referenced by loadiJIT_Funcs().

◆ FUNC_NotifyEvent

TPNotify FUNC_NotifyEvent =NULL
static

Definition at line 100 of file jitprofiling.cc.

Referenced by iJIT_NotifyEvent(), and loadiJIT_Funcs().

◆ iJIT_DLL_is_missing

int iJIT_DLL_is_missing = 0
static

◆ m_libHandle

HINSTANCE m_libHandle = NULL

Definition at line 86 of file jitprofiling.cc.

Referenced by FinalizeProcess(), and loadiJIT_Funcs().

◆ rcsid

const char rcsid[] = "\n@(#) $Revision: 234474 $\n"
static

Definition at line 72 of file jitprofiling.cc.

Referenced by loadiJIT_Funcs().

◆ threadLocalStorageHandle

DWORD threadLocalStorageHandle = 0
static

Definition at line 125 of file jitprofiling.cc.

Referenced by FinalizeProcess(), FinalizeThread(), iJIT_NotifyEvent(), and loadiJIT_Funcs().