hotspot/src/os/windows/vm/vtune_windows.cpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2007 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_vtune_windows.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
static int current_method_ID = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// ------------- iJITProf.h -------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// defined by Intel -- do not change
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
#include "windows.h"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
extern "C" {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  enum iJITP_Event {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
    ExceptionOccurred_S,                  // Java exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    ExceptionOccurred_IDS,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    Shutdown,                             // VM exit
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    ThreadCreate,                         // threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    ThreadDestroy,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    ThreadSwitch,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    ClassLoadStart,                       // class loading
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    ClassLoadEnd,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    GCStart,                              // GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    GCEnd,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    NMethodCreate = 13,                   // nmethod creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    NMethodDelete
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    // rest of event types omitted (call profiling not supported yet)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  // version number -- 0 if VTune not installed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  int WINAPI iJitP_VersionNumber();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  enum iJITP_ModeFlags {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    NoNotification = 0x0,                // don't call vtune
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    NotifyNMethodCreate   = 0x1,         // notify NMethod_Create
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    NotifyNMethodDelete   = 0x2,         // notify NMethod_Create
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    NotifyMethodEnter     = 0x4,         // method entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    NotifyMethodExit      = 0x8,         // method exit
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    NotifyShutdown        = 0x10,        // VM exit
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    NotifyGC              = 0x20,        // GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // call back function type
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  typedef void (WINAPI *ModeChangedFn)(iJITP_ModeFlags flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  // -------------  VTune method interfaces ----------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  typedef void  (WINAPI *RegisterCallbackFn)(ModeChangedFn fn);   // register callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  typedef int   (WINAPI *NotifyEventFn)(iJITP_Event, void* event_data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // specific event data structures
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // data for NMethodCreate
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  struct VTuneObj {                       // base class for allocation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
                                          // (can't use CHeapObj -- has vtable ptr)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    void* operator new(size_t size) { return os::malloc(size); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    void  operator delete(void* p)  { fatal("never delete VTune data"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  struct LineNumberInfo : VTuneObj {      // PC-to-line number mapping
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    unsigned long offset;                 // byte offset from start of method
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    unsigned long line_num;               // corresponding line number
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  struct MethodLoadInfo : VTuneObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    unsigned long methodID;               // unique method ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    const char* name;                     // method name
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    unsigned long instr_start;            // start address
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    unsigned long instr_size;             // length in bytes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    unsigned long line_number_size;       // size of line number table
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    LineNumberInfo* line_number_table;    // line number mapping
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    unsigned long classID;                // unique class ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    char* class_file_name;                // fully qualified class file name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    char* source_file_name;               // fully qualified source file name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    MethodLoadInfo(nmethod* nm);          // for real nmethods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    MethodLoadInfo(const char* vm_name, address start, address end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
                                          // for "nmethods" like stubs, interpreter, etc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  // data for NMethodDelete
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  struct MethodInfo : VTuneObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    unsigned long methodID;               // unique method ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    unsigned long classID;                // (added for convenience -- not part of Intel interface)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    MethodInfo(methodOop m);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
MethodInfo::MethodInfo(methodOop m) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  // just give it a new ID -- we're not compiling methods twice (usually)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  // (and even if we did, one might want to see the two versions separately)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  methodID = ++current_method_ID;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
MethodLoadInfo::MethodLoadInfo(const char* vm_name, address start, address end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  classID  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  methodID = ++current_method_ID;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  name = vm_name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  instr_start = (unsigned long)start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  instr_size = end - start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  line_number_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  line_number_table = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  class_file_name = source_file_name = "HotSpot JVM";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
MethodLoadInfo::MethodLoadInfo(nmethod* nm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  methodOop m = nm->method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  MethodInfo info(m);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  classID  = info.classID;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  methodID = info.methodID;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  name = strdup(m->name()->as_C_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  instr_start = (unsigned long)nm->instructions_begin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  instr_size = nm->code_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  line_number_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  line_number_table = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  klassOop kl = m->method_holder();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  char* class_name = Klass::cast(kl)->name()->as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  char* file_name = NEW_C_HEAP_ARRAY(char, strlen(class_name) + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  strcpy(file_name, class_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  class_file_name = file_name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  char* src_name = NEW_C_HEAP_ARRAY(char, strlen(class_name) + strlen(".java") + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  strcpy(src_name, class_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  strcat(src_name, ".java");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  source_file_name = src_name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
// --------------------- DLL loading functions ------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
#define DLLNAME "iJitProf.dll"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
static HINSTANCE load_lib(char* name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  HINSTANCE lib = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  HKEY hk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  // try to get VTune directory from the registry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  if (RegOpenKey(HKEY_CURRENT_USER, "Software\\VB and VBA Program Settings\\VTune\\StartUp", &hk) == ERROR_SUCCESS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    for (int i = 0; true; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
      char szName[MAX_PATH + 1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
      char szVal [MAX_PATH + 1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      DWORD cbName, cbVal;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      cbName = cbVal = MAX_PATH + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      if (RegEnumValue(hk, i, szName, &cbName, NULL, NULL, (LPBYTE)szVal, &cbVal) == ERROR_SUCCESS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
        // get VTune directory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
        if (!strcmp(szName, name)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
          char*p = szVal;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
          while (*p == ' ') p++;    // trim
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
          char* q = p + strlen(p) - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
          while (*q == ' ') *(q--) = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
          // chdir to the VTune dir
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
          GetCurrentDirectory(MAX_PATH + 1, szName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
          SetCurrentDirectory(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
          // load lib
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
          lib = LoadLibrary(strcat(strcat(p, "\\"), DLLNAME));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
          if (lib != NULL && WizardMode) tty->print_cr("*loaded VTune DLL %s", p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
          // restore current dir
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
          SetCurrentDirectory(szName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  return lib;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
static RegisterCallbackFn iJIT_RegisterCallback = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
static NotifyEventFn      iJIT_NotifyEvent      = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
static bool load_iJIT_funcs() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  // first try to load from PATH
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  HINSTANCE lib = LoadLibrary(DLLNAME);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  if (lib != NULL && WizardMode) tty->print_cr("*loaded VTune DLL %s via PATH", DLLNAME);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  // if not successful, try to look in the VTUNE directory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  if (lib == NULL) lib = load_lib("VTUNEDIR30");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  if (lib == NULL) lib = load_lib("VTUNEDIR25");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  if (lib == NULL) lib = load_lib("VTUNEDIR");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  if (lib == NULL) return false;    // unsuccessful
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  // try to load the functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  iJIT_RegisterCallback = (RegisterCallbackFn)GetProcAddress(lib, "iJIT_RegisterCallback");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  iJIT_NotifyEvent      = (NotifyEventFn)     GetProcAddress(lib, "iJIT_NotifyEvent");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  if (!iJIT_RegisterCallback) tty->print_cr("*couldn't find VTune entry point iJIT_RegisterCallback");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  if (!iJIT_NotifyEvent)      tty->print_cr("*couldn't find VTune entry point iJIT_NotifyEvent");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  return iJIT_RegisterCallback != NULL && iJIT_NotifyEvent != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
// --------------------- VTune class ------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
static bool active = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
static int  flags  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
void VTune::start_GC() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  if (active && (flags & NotifyGC)) iJIT_NotifyEvent(GCStart, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
void VTune::end_GC() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  if (active && (flags & NotifyGC)) iJIT_NotifyEvent(GCEnd, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
void VTune::start_class_load() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  // not yet implemented in VTune
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
void VTune::end_class_load() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  // not yet implemented in VTune
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
void VTune::exit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  if (active && (flags & NotifyShutdown)) iJIT_NotifyEvent(Shutdown, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
void VTune::register_stub(const char* name, address start, address end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  if (flags & NotifyNMethodCreate) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    MethodLoadInfo* info = new MethodLoadInfo(name, start, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    if (PrintMiscellaneous && WizardMode && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
      tty->print_cr("NMethodCreate %s (%d): %#x..%#x", info->name, info->methodID,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
                    info->instr_start, info->instr_start + info->instr_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    iJIT_NotifyEvent(NMethodCreate, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
void VTune::create_nmethod(nmethod* nm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  if (flags & NotifyNMethodCreate) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    MethodLoadInfo* info = new MethodLoadInfo(nm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    if (PrintMiscellaneous && WizardMode && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
      tty->print_cr("NMethodCreate %s (%d): %#x..%#x", info->name, info->methodID,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
                    info->instr_start, info->instr_start + info->instr_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    iJIT_NotifyEvent(NMethodCreate, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
void VTune::delete_nmethod(nmethod* nm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  if (flags & NotifyNMethodDelete) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    MethodInfo* info = new MethodInfo(nm->method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    iJIT_NotifyEvent(NMethodDelete, info);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
static void set_flags(int new_flags) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  flags = new_flags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  // if (WizardMode) tty->print_cr("*new VTune flags: %#x", flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
void vtune_init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  if (!UseVTune) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  active = load_iJIT_funcs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  if (active) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    iJIT_RegisterCallback((ModeChangedFn)set_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    assert(flags == 0, "flags shouldn't be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
}