Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ddprof-lib/src/main/cpp/javaApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ Java_com_datadoghq_profiler_JVMAccess_findStringJVMFlag0(JNIEnv *env,
jobject unused,
jstring flagName) {
JniString flag_str(env, flagName);
JVMFlag *f = JVMFlag::find(flag_str.c_str(), {JVMFlag::Type::String, JVMFlag::Type::Stringlist});
VMFlag *f = VMFlag::find(flag_str.c_str(), {VMFlag::Type::String, VMFlag::Type::Stringlist});
if (f) {
char** value = static_cast<char**>(f->addr());
if (value != NULL && *value != NULL) {
Expand All @@ -365,7 +365,7 @@ Java_com_datadoghq_profiler_JVMAccess_setStringJVMFlag0(JNIEnv *env,
jstring flagValue) {
JniString flag_str(env, flagName);
JniString value_str(env, flagValue);
JVMFlag *f = JVMFlag::find(flag_str.c_str(), {JVMFlag::Type::String, JVMFlag::Type::Stringlist});
VMFlag *f = VMFlag::find(flag_str.c_str(), {VMFlag::Type::String, VMFlag::Type::Stringlist});
if (f) {
char** value = static_cast<char**>(f->addr());
if (value != NULL) {
Expand All @@ -379,7 +379,7 @@ Java_com_datadoghq_profiler_JVMAccess_findBooleanJVMFlag0(JNIEnv *env,
jobject unused,
jstring flagName) {
JniString flag_str(env, flagName);
JVMFlag *f = JVMFlag::find(flag_str.c_str(), {JVMFlag::Type::Bool});
VMFlag *f = VMFlag::find(flag_str.c_str(), {VMFlag::Type::Bool});
if (f) {
char* value = static_cast<char*>(f->addr());
if (value != NULL) {
Expand All @@ -395,7 +395,7 @@ Java_com_datadoghq_profiler_JVMAccess_setBooleanJVMFlag0(JNIEnv *env,
jstring flagName,
jboolean flagValue) {
JniString flag_str(env, flagName);
JVMFlag *f = JVMFlag::find(flag_str.c_str(), {JVMFlag::Type::Bool});
VMFlag *f = VMFlag::find(flag_str.c_str(), {VMFlag::Type::Bool});
if (f) {
char* value = static_cast<char*>(f->addr());
if (value != NULL) {
Expand All @@ -409,7 +409,7 @@ Java_com_datadoghq_profiler_JVMAccess_findIntJVMFlag0(JNIEnv *env,
jobject unused,
jstring flagName) {
JniString flag_str(env, flagName);
JVMFlag *f = JVMFlag::find(flag_str.c_str(), {JVMFlag::Type::Int, JVMFlag::Type::Uint, JVMFlag::Type::Intx, JVMFlag::Type::Uintx, JVMFlag::Type::Uint64_t, JVMFlag::Type::Size_t});
VMFlag *f = VMFlag::find(flag_str.c_str(), {VMFlag::Type::Int, VMFlag::Type::Uint, VMFlag::Type::Intx, VMFlag::Type::Uintx, VMFlag::Type::Uint64_t, VMFlag::Type::Size_t});
if (f) {
long* value = static_cast<long*>(f->addr());
if (value != NULL) {
Expand All @@ -424,7 +424,7 @@ Java_com_datadoghq_profiler_JVMAccess_findFloatJVMFlag0(JNIEnv *env,
jobject unused,
jstring flagName) {
JniString flag_str(env, flagName);
JVMFlag *f = JVMFlag::find(flag_str.c_str(),{ JVMFlag::Type::Double});
VMFlag *f = VMFlag::find(flag_str.c_str(),{ VMFlag::Type::Double});
if (f) {
double* value = static_cast<double*>(f->addr());
if (value != NULL) {
Expand Down
14 changes: 7 additions & 7 deletions ddprof-lib/src/main/cpp/profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ int Profiler::getJavaTraceAsync(void *ucontext, ASGCT_CallFrame *frames,
VM::_asyncGetCallTrace(&trace, max_depth, ucontext);
}
} else if (VMStructs::hasMethodStructs()) {
NMethod *nmethod = CodeHeap::findNMethod((const void *)frame.pc());
VMNMethod *nmethod = CodeHeap::findNMethod((const void *)frame.pc());
if (nmethod != NULL && nmethod->isNMethod() && nmethod->isAlive()) {
VMMethod *method = nmethod->method();
if (method != NULL) {
Expand Down Expand Up @@ -623,7 +623,7 @@ int Profiler::getJavaTraceAsync(void *ucontext, ASGCT_CallFrame *frames,
}
} else if (trace.num_frames == ticks_unknown_not_Java &&
!(_safe_mode & LAST_JAVA_PC)) {
JavaFrameAnchor* anchor = vm_thread->anchor();
VMJavaFrameAnchor* anchor = vm_thread->anchor();
uintptr_t sp = anchor->lastJavaSP();
const void* pc = anchor->lastJavaPC();
if (sp != 0 && pc == NULL) {
Expand All @@ -632,7 +632,7 @@ int Profiler::getJavaTraceAsync(void *ucontext, ASGCT_CallFrame *frames,
pc = ((const void**)sp)[-1];
anchor->setLastJavaPC(pc);

NMethod *m = CodeHeap::findNMethod(pc);
VMNMethod *m = CodeHeap::findNMethod(pc);
if (m != NULL) {
// AGCT fails if the last Java frame is a Runtime Stub with an invalid
// _frame_complete_offset. In this case we patch _frame_complete_offset
Expand All @@ -650,13 +650,13 @@ int Profiler::getJavaTraceAsync(void *ucontext, ASGCT_CallFrame *frames,
}
} else if (trace.num_frames == ticks_not_walkable_not_Java &&
!(_safe_mode & LAST_JAVA_PC)) {
JavaFrameAnchor* anchor = vm_thread->anchor();
VMJavaFrameAnchor* anchor = vm_thread->anchor();
uintptr_t sp = anchor->lastJavaSP();
const void* pc = anchor->lastJavaPC();
if (sp != 0 && pc != NULL) {
// Similar to the above: last Java frame is set,
// but points to a Runtime Stub with an invalid _frame_complete_offset
NMethod *m = CodeHeap::findNMethod(pc);
VMNMethod *m = CodeHeap::findNMethod(pc);
if (m != NULL && !m->isNMethod() && m->frameSize() > 0 &&
m->frameCompleteOffset() == -1) {
m->setFrameCompleteOffset(0);
Expand Down Expand Up @@ -691,7 +691,7 @@ int Profiler::getJavaTraceAsync(void *ucontext, ASGCT_CallFrame *frames,
}

void Profiler::fillFrameTypes(ASGCT_CallFrame *frames, int num_frames,
NMethod *nmethod) {
VMNMethod *nmethod) {
if (nmethod->isNMethod() && nmethod->isAlive()) {
VMMethod *method = nmethod->method();
if (method == NULL) {
Expand Down Expand Up @@ -850,7 +850,7 @@ void Profiler::recordSample(void *ucontext, u64 counter, int tid,
if (mutex.acquired()) {
java_frames = getJavaTraceAsync(ucontext, frames + num_frames, max_remaining, &java_ctx, &truncated);
if (java_frames > 0 && java_ctx.pc != NULL && VMStructs::hasMethodStructs()) {
NMethod* nmethod = CodeHeap::findNMethod(java_ctx.pc);
VMNMethod* nmethod = CodeHeap::findNMethod(java_ctx.pc);
if (nmethod != NULL) {
fillFrameTypes(frames + num_frames, java_frames, nmethod);
}
Expand Down
4 changes: 2 additions & 2 deletions ddprof-lib/src/main/cpp/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ union CallTraceBuffer {
};

class FrameName;
class NMethod;
class VMNMethod;
class StackContext;
class VM;

Expand Down Expand Up @@ -178,7 +178,7 @@ class alignas(alignof(SpinLock)) Profiler {
int getJavaTraceAsync(void *ucontext, ASGCT_CallFrame *frames, int max_depth,
StackContext *java_ctx, bool *truncated);
void fillFrameTypes(ASGCT_CallFrame *frames, int num_frames,
NMethod *nmethod);
VMNMethod *nmethod);
void updateThreadName(jvmtiEnv *jvmti, JNIEnv *jni, jthread thread,
bool self = false);
void updateJavaThreadNames();
Expand Down
17 changes: 16 additions & 1 deletion ddprof-lib/src/main/cpp/safeAccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "arch.h"
#include "codeCache.h"
#include "os.h"
#include <cassert>
#include <stdint.h>

Expand Down Expand Up @@ -74,10 +75,24 @@ class SafeAccess {
NOINLINE __attribute__((aligned(16)))
static void *loadPtr(void** ptr, void* default_value);

static inline bool isReadable(void* ptr) {
static inline bool isReadable(const void* ptr) {
return load32((int32_t*)ptr, 1) != 1 ||
load32((int32_t*)ptr, -1) != -1;
}

static inline bool isReadableRange(const void* start, size_t size) {
assert(size > 0);
void* start_page = (void*)align_down((uintptr_t)start, OS::page_size);
void* end_page = (void*)align_down((uintptr_t)start + size - 1, OS::page_size);
// Memory readability is determined at the page level, so we check each page in the range for readability.
// This is more efficient than checking each byte.
for (void* page = start_page; page <= end_page; page = (void*)((uintptr_t)page + OS::page_size)) {
if (!isReadable(page)) {
return false;
}
}
return true;
}
};

#endif // _SAFEACCESS_H
12 changes: 6 additions & 6 deletions ddprof-lib/src/main/cpp/stackFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "arch.h"


class NMethod;
class VMNMethod;

class StackFrame {
private:
Expand Down Expand Up @@ -61,23 +61,23 @@ class StackFrame {
return unwindStub(entry, name, pc(), sp(), fp());
}

bool unwindCompiled(NMethod* nm) {
bool unwindCompiled(VMNMethod* nm) {
return unwindCompiled(nm, pc(), sp(), fp());
}

bool unwindStub(instruction_t* entry, const char* name, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp);
bool unwindAtomicStub(const void*& pc);

// TODO: this function will be removed once `vm` becomes the default stack walking mode
bool unwindCompiled(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp);
bool unwindCompiled(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp);

bool unwindPrologue(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp);
bool unwindEpilogue(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp);
bool unwindPrologue(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp);
bool unwindEpilogue(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp);

void adjustSP(const void* entry, const void* pc, uintptr_t& sp);

// SP baseline helpers for compiled frame unwinding
uintptr_t sender_sp_baseline(const NMethod* nm, uintptr_t sp, uintptr_t fp, const void* pc);
uintptr_t sender_sp_baseline(const VMNMethod* nm, uintptr_t sp, uintptr_t fp, const void* pc);
const void* read_caller_pc_from_sp(uintptr_t sp_base);
uintptr_t read_saved_fp_from_sp(uintptr_t sp_base);

Expand Down
8 changes: 4 additions & 4 deletions ddprof-lib/src/main/cpp/stackFrame_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ static inline bool isEntryBarrier(instruction_t* ip) {
return ip[0] == 0xb9402389 && ip[1] == 0xeb09011f;
}

bool StackFrame::unwindCompiled(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
bool StackFrame::unwindCompiled(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
instruction_t* ip = (instruction_t*)pc;
instruction_t* entry = (instruction_t*)nm->entry();
if ((*ip & 0xffe07fff) == 0xa9007bfd) {
Expand Down Expand Up @@ -236,7 +236,7 @@ static inline bool isFrameComplete(instruction_t* entry, instruction_t* ip) {
return false;
}

bool StackFrame::unwindPrologue(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
bool StackFrame::unwindPrologue(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
// C1/C2 methods:
// {stack_bang}
// sub sp, sp, #0x40
Expand Down Expand Up @@ -312,7 +312,7 @@ static inline bool isPollReturn(instruction_t* ip) {
return false;
}

bool StackFrame::unwindEpilogue(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
bool StackFrame::unwindEpilogue(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
// ldp x29, x30, [sp, #32]
// add sp, sp, #0x30
// {poll_return}
Expand All @@ -329,7 +329,7 @@ bool StackFrame::unwindAtomicStub(const void*& pc) {
// VM threads may call generated atomic stubs, which are not normally walkable
const void* lr = (const void*)link();
if (VMStructs::libjvm()->contains(lr)) {
NMethod* nm = CodeHeap::findNMethod(pc);
VMNMethod* nm = CodeHeap::findNMethod(pc);
if (nm != NULL && strncmp(nm->name(), "Stub", 4) == 0) {
pc = lr;
return true;
Expand Down
6 changes: 3 additions & 3 deletions ddprof-lib/src/main/cpp/stackFrame_arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool StackFrame::unwindStub(instruction_t* entry, const char* name, uintptr_t& p
return false;
}

bool StackFrame::unwindCompiled(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
bool StackFrame::unwindCompiled(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
instruction_t* ip = (instruction_t*)pc;
instruction_t* entry = (instruction_t*)nm->entry();
if (ip > entry && ip <= entry + 4 && (*ip & 0xffffff00) == 0xe24dd000) {
Expand All @@ -101,7 +101,7 @@ bool StackFrame::unwindCompiled(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintp
return true;
}

bool StackFrame::unwindPrologue(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
bool StackFrame::unwindPrologue(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
instruction_t* ip = (instruction_t*)pc;
instruction_t* entry = (instruction_t*)nm->entry();
if (ip <= entry) {
Expand All @@ -111,7 +111,7 @@ bool StackFrame::unwindPrologue(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintp
return false;
}

bool StackFrame::unwindEpilogue(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
bool StackFrame::unwindEpilogue(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
// Not yet implemented
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions ddprof-lib/src/main/cpp/stackFrame_i386.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ bool StackFrame::unwindStub(instruction_t* entry, const char* name, uintptr_t& p
return false;
}

bool StackFrame::unwindCompiled(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
bool StackFrame::unwindCompiled(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
instruction_t* ip = (instruction_t*)pc;
instruction_t* entry = (instruction_t*)nm->entry();
if (ip <= entry
Expand All @@ -116,7 +116,7 @@ bool StackFrame::unwindCompiled(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintp
return false;
}

bool StackFrame::unwindPrologue(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
bool StackFrame::unwindPrologue(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
instruction_t* ip = (instruction_t*)pc;
instruction_t* entry = (instruction_t*)nm->entry();
if (ip <= entry || *ip == 0x55) { // push ebp
Expand All @@ -127,7 +127,7 @@ bool StackFrame::unwindPrologue(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintp
return false;
}

bool StackFrame::unwindEpilogue(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
bool StackFrame::unwindEpilogue(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
instruction_t* ip = (instruction_t*)pc;
if (*ip == 0xc3) { // ret
pc = *(uintptr_t*)sp;
Expand Down
6 changes: 3 additions & 3 deletions ddprof-lib/src/main/cpp/stackFrame_loongarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ bool StackFrame::unwindStub(instruction_t* entry, const char* name, uintptr_t& p
return false;
}

bool StackFrame::unwindCompiled(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
bool StackFrame::unwindCompiled(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
// Not yet implemented
return false;
}

bool StackFrame::unwindPrologue(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
bool StackFrame::unwindPrologue(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
// Not yet implemented
return false;
}

bool StackFrame::unwindEpilogue(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
bool StackFrame::unwindEpilogue(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
// Not yet implemented
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions ddprof-lib/src/main/cpp/stackFrame_ppc64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ bool StackFrame::unwindStub(instruction_t* entry, const char* name, uintptr_t& p
return true;
}

bool StackFrame::unwindCompiled(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
bool StackFrame::unwindCompiled(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
// On PPC there is a valid back link to the previous frame at all times. The callee stores
// the return address in the caller's frame before it constructs its own frame. After it
// has destroyed its frame it restores the link register and returns. A problematic sequence
Expand All @@ -127,12 +127,12 @@ bool StackFrame::unwindCompiled(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintp
return true;
}

bool StackFrame::unwindPrologue(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
bool StackFrame::unwindPrologue(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
// Not yet implemented
return false;
}

bool StackFrame::unwindEpilogue(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
bool StackFrame::unwindEpilogue(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
// Not yet implemented
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions ddprof-lib/src/main/cpp/stackFrame_riscv64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ bool StackFrame::unwindStub(instruction_t* entry, const char* name, uintptr_t& p
return false;
}

bool StackFrame::unwindCompiled(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
bool StackFrame::unwindCompiled(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
// Not yet implemented
return false;
}

bool StackFrame::unwindPrologue(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
bool StackFrame::unwindPrologue(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
// Not yet implemented
return false;
}

bool StackFrame::unwindEpilogue(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
bool StackFrame::unwindEpilogue(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
// Not yet implemented
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions ddprof-lib/src/main/cpp/stackFrame_x64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ __attribute__((no_sanitize("address"))) bool StackFrame::unwindStub(instruction_
return false;
}

bool StackFrame::unwindCompiled(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
bool StackFrame::unwindCompiled(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
instruction_t* ip = (instruction_t*)pc;
instruction_t* entry = (instruction_t*)nm->entry();
if (ip <= entry
Expand Down Expand Up @@ -156,7 +156,7 @@ static inline bool isFrameComplete(instruction_t* entry, instruction_t* ip) {
return false;
}

bool StackFrame::unwindPrologue(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
bool StackFrame::unwindPrologue(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
// 0: mov %eax,-0x14000(%rsp)
// 7: push %rbp
// 8: mov %rsp,%rbp ; for native methods only
Expand Down Expand Up @@ -219,7 +219,7 @@ static inline bool isPollReturn(instruction_t* ip) {
return false;
}

bool StackFrame::unwindEpilogue(NMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
bool StackFrame::unwindEpilogue(VMNMethod* nm, uintptr_t& pc, uintptr_t& sp, uintptr_t& fp) {
// add $0x40,%rsp
// pop %rbp
// {poll_return}
Expand Down
Loading
Loading