GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — async-profiler/src/lookup.cpp at jonoffcpu-dev · jonoffcpu/async-profiler Expand file tree/ Copy pathlookup.cppMore file actions 187 lines (162 loc) · 5.7 KB / Copy pathlookup.cppFile metadata and controls187 lines (162 loc) · 5.7 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 /* * Copyright The async-profiler authors * SPDX-License-Identifier: Apache-2.0 */ #include <string.h> #include "demangle.h" #include "dictionary.h" #include "index.h" #include "lookup.h" #include "profiler.h" #include "vmStructs.h" jint MethodInfo::getLineNumber(jint bci) { if (_line_number_table_size == 0) { return 0; } int i = 1; while (i < _line_number_table_size && bci >= _line_number_table[i].start_location) { i++; } return _line_number_table[i - 1].line_number; } MethodMap::~MethodMap() { jvmtiEnv* jvmti = VM::jvmti(); for (const_iterator it = begin(); it != end(); ++it) { jvmtiLineNumberEntry* line_number_table = it->second._line_number_table; if (line_number_table != NULL) { jvmti->Deallocate((unsigned char*)line_number_table); } } } size_t MethodMap::usedMemory() { size_t bytes = 0; for (const_iterator it = begin(); it != end(); ++it) { bytes += sizeof(jmethodID) + sizeof(MethodInfo); bytes += it->second._line_number_table_size * sizeof(jvmtiLineNumberEntry); } return bytes; } MethodInfo* Lookup::resolveMethod(ASGCT_CallFrame& frame) { jmethodID method = frame.method_id; MethodInfo* mi = &(*_method_map)[method]; bool first_time = mi->_key == 0; if (first_time) { mi->_key = _method_map->size(); } if (!mi->_mark) { mi->_mark = true; if (method == NULL) { fillNativeMethodInfo(mi, "unknown", NULL); } else if (frame.bci > BCI_NATIVE_FRAME) { if (!fillJavaMethodInfo(mi, method, first_time)) { fillNativeMethodInfo(mi, "stale_jmethodID", NULL); } } else if (frame.bci == BCI_NATIVE_FRAME) { const char* name = (const char*)method; fillNativeMethodInfo(mi, name, Profiler::instance()->getLibraryName(name)); } else if (frame.bci == BCI_ADDRESS) { char buf[32]; snprintf(buf, sizeof(buf), "%p", method); fillNativeMethodInfo(mi, buf, NULL); } else if (frame.bci == BCI_ERROR) { fillNativeMethodInfo(mi, (const char*)method, NULL); } else if (frame.bci == BCI_CPU) { char buf[32]; snprintf(buf, sizeof(buf), "CPU-%d", ((int)(uintptr_t)method) & 0x7fff); fillNativeMethodInfo(mi, buf, NULL); } else { fillJavaClassInfo(mi, (uintptr_t)method); } } return mi; } u32 Lookup::getPackage(const char* class_name) { assert(_packages != nullptr); const char* package = strrchr(class_name, '/'); if (package == NULL) { return 0; } if (package[1] >= '0' && package[1] <= '9') { // Seems like a hidden or anonymous class, e.g. com/example/Foo/0x012345 do { if (package == class_name) return 0; } while (*--package != '/'); } if (class_name[0] == '[') { class_name = strchr(class_name, 'L') + 1; } return _packages->indexOf(class_name, package - class_name); } void Lookup::fillNativeMethodInfo(MethodInfo* mi, const char* name, const char* lib_name) { if (lib_name == NULL) { mi->_class = _classes->lookup(""); } else if (lib_name[0] == '[' && lib_name[1] != 0) { mi->_class = _classes->lookup(lib_name + 1, strlen(lib_name) - 2); } else { mi->_class = _classes->lookup(lib_name); } mi->_modifiers = 0x100; if (Demangle::needsDemangling(name)) { char* demangled = Demangle::demangle(name, false); if (demangled != NULL) { mi->_name = _symbols->indexOf(demangled); mi->_sig = _symbols->indexOf("()L;"); mi->_type = FRAME_CPP; free(demangled); return; } } size_t len = strlen(name); if (len >= 4 && strcmp(name + len - 4, "_[k]") == 0) { mi->_name = _symbols->indexOf(name, len - 4); mi->_sig = _symbols->indexOf("(Lk;)L;"); mi->_type = FRAME_KERNEL; } else { mi->_name = _symbols->indexOf(name); mi->_sig = _symbols->indexOf("()L;"); mi->_type = FRAME_NATIVE; } } bool Lookup::fillJavaMethodInfo(MethodInfo* mi, jmethodID method, bool first_time) { if (VMMethod::isStaleMethodId(method)) { return false; } jclass method_class = NULL; char* class_name = NULL; char* method_name = NULL; char* method_sig = NULL; jvmtiEnv* jvmti = VM::jvmti(); jvmtiError err; if ((err = jvmti->GetMethodName(method, &method_name, &method_sig, NULL)) == 0 && (err = jvmti->GetMethodDeclaringClass(method, &method_class)) == 0) { mi->_sig = _symbols->indexOf(method_sig); mi->_name = _symbols->indexOf(method_name); if ((err = jvmti->GetClassSignature(method_class, &class_name, NULL)) == 0) { mi->_class = _classes->lookup(class_name + 1, strlen(class_name) - 2); } } if (method_class) { _jni->DeleteLocalRef(method_class); } jvmti->Deallocate((unsigned char*)method_sig); jvmti->Deallocate((unsigned char*)method_name); jvmti->Deallocate((unsigned char*)class_name); if (err != 0) { return false; } if (first_time && jvmti->GetMethodModifiers(method, &mi->_modifiers) != 0) { mi->_modifiers = 0; } if (first_time && jvmti->GetLineNumberTable(method, &mi->_line_number_table_size, &mi->_line_number_table) != 0) { mi->_line_number_table_size = 0; mi->_line_number_table = NULL; } mi->_type = FRAME_INTERPRETED; return true; } void Lookup::fillJavaClassInfo(MethodInfo* mi, u32 class_id) { mi->_class = class_id; mi->_name = _symbols->indexOf(""); mi->_sig = _symbols->indexOf("()L;"); mi->_type = FRAME_INLINED; } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |