Skip to content

Commit 87c5436

Browse files
committed
Better allocation stack traces on non-HotSpot JVMs
1 parent 9afed85 commit 87c5436

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

src/flightRecorder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ class Lookup {
187187
char* method_name = NULL;
188188
char* method_sig = NULL;
189189

190-
if (jvmti->GetMethodDeclaringClass(method, &method_class) == 0 &&
191-
jvmti->GetClassSignature(method_class, &class_name, NULL) == 0 &&
192-
jvmti->GetMethodName(method, &method_name, &method_sig, NULL) == 0) {
190+
if (jvmti->GetMethodName(method, &method_name, &method_sig, NULL) == 0 &&
191+
jvmti->GetMethodDeclaringClass(method, &method_class) == 0 &&
192+
jvmti->GetClassSignature(method_class, &class_name, NULL) == 0) {
193193
mi->_class = _classes->lookup(class_name + 1, strlen(class_name) - 2);
194194
mi->_name = _symbols.lookup(method_name);
195195
mi->_sig = _symbols.lookup(method_sig);

src/vmEntry.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,15 @@ static bool isVmRuntimeEntry(const char* blob_name) {
4545
|| strncmp(blob_name, "_Z22post_allocation_notify", 26) == 0
4646
|| strncmp(blob_name, "_ZN11OptoRuntime", 16) == 0
4747
|| strncmp(blob_name, "_ZN8Runtime1", 12) == 0
48+
|| strncmp(blob_name, "_ZN13SharedRuntime", 18) == 0
4849
|| strncmp(blob_name, "_ZN18InterpreterRuntime", 23) == 0;
4950
}
5051

52+
static bool isZingRuntimeEntry(const char* blob_name) {
53+
return strncmp(blob_name, "_ZN14DolphinRuntime", 19) == 0
54+
|| strncmp(blob_name, "_ZN37JvmtiSampledObjectAllocEventCollector", 42) == 0;
55+
}
56+
5157
static bool isZeroInterpreterMethod(const char* blob_name) {
5258
return strncmp(blob_name, "_ZN15ZeroInterpreter", 20) == 0
5359
|| strncmp(blob_name, "_ZN19BytecodeInterpreter3run", 28) == 0;
@@ -83,6 +89,10 @@ static bool isOpenJ9GcAlloc(const char* blob_name) {
8389
return strncmp(blob_name, "J9Allocate", 10) == 0;
8490
}
8591

92+
static bool isOpenJ9JvmtiAlloc(const char* blob_name) {
93+
return strcmp(blob_name, "jvmtiHookSampledObjectAlloc") == 0;
94+
}
95+
8696
static bool isCompilerEntry(const char* blob_name) {
8797
return strncmp(blob_name, "_ZN13CompileBroker25invoke_compiler_on_method", 45) == 0;
8898
}
@@ -104,13 +114,6 @@ bool VM::init(JavaVM* vm, bool attach) {
104114
return false;
105115
}
106116

107-
Dl_info dl_info;
108-
if (dladdr((const void*)resolveMethodId, &dl_info) && dl_info.dli_fname != NULL) {
109-
// Make sure async-profiler DSO cannot be unloaded, since it contains JVM callbacks.
110-
// Don't use ELF NODELETE flag because of https://sourceware.org/bugzilla/show_bug.cgi?id=20839
111-
dlopen(dl_info.dli_fname, RTLD_LAZY | RTLD_NODELETE);
112-
}
113-
114117
bool is_hotspot = false;
115118
bool is_zero_vm = false;
116119
char* prop;
@@ -148,18 +151,18 @@ bool VM::init(JavaVM* vm, bool attach) {
148151
_freeMemory = (JVM_MemoryFunc)dlsym(libjvm, "JVM_FreeMemory");
149152

150153
Profiler* profiler = Profiler::instance();
151-
profiler->updateSymbols(false);
154+
if (VMStructs::libjvm() == NULL) {
155+
profiler->updateSymbols(false);
156+
VMStructs::init(profiler->findLibraryByAddress((const void*)_asyncGetCallTrace));
157+
}
152158

153159
_openj9 = !is_hotspot && J9Ext::initialize(_jvmti, profiler->resolveSymbol("j9thread_self"));
154160

155-
CodeCache* lib = isOpenJ9()
156-
? profiler->findJvmLibrary("libj9vm")
157-
: profiler->findLibraryByAddress((const void*)_asyncGetCallTrace);
161+
CodeCache* lib = profiler->findJvmLibrary("libj9vm");
158162
if (lib == NULL) {
159163
return false;
160164
}
161165

162-
VMStructs::init(lib);
163166
if (isOpenJ9()) {
164167
lib->mark(isOpenJ9InterpreterMethod, MARK_INTERPRETER);
165168
lib->mark(isOpenJ9Resolve, MARK_VM_RUNTIME);
@@ -172,9 +175,15 @@ bool VM::init(JavaVM* vm, bool attach) {
172175
if (libgc != NULL) {
173176
libgc->mark(isOpenJ9GcAlloc, MARK_VM_RUNTIME);
174177
}
178+
CodeCache* libjvmti = profiler->findJvmLibrary("libj9jvmti");
179+
if (libjvmti != NULL) {
180+
libjvmti->mark(isOpenJ9JvmtiAlloc, MARK_VM_RUNTIME);
181+
}
175182
} else {
176183
lib->mark(isVmRuntimeEntry, MARK_VM_RUNTIME);
177-
if (is_zero_vm) {
184+
if (isZing()) {
185+
lib->mark(isZingRuntimeEntry, MARK_VM_RUNTIME);
186+
} else if (is_zero_vm) {
178187
lib->mark(isZeroInterpreterMethod, MARK_INTERPRETER);
179188
} else {
180189
lib->mark(isCompilerEntry, MARK_COMPILER_ENTRY);
@@ -239,7 +248,7 @@ bool VM::init(JavaVM* vm, bool attach) {
239248
// DebugNonSafepoints is automatically enabled with CompiledMethodLoad,
240249
// otherwise we set the flag manually
241250
JVMFlag* f = JVMFlag::find("DebugNonSafepoints");
242-
if (f != NULL && f->origin() == 0) {
251+
if (f != NULL && f->isDefault()) {
243252
f->set(1);
244253
}
245254
}

0 commit comments

Comments
 (0)