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