jvm-profiling-tools / honest-profiler

A sampling JVM profiler without the safepoint sample bias
https://github.com/RichardWarburton/honest-profiler/wiki
MIT License
1.25k stars 146 forks source link

What are restrictions in async callback? #277

Closed BigBabolBee closed 2 years ago

BigBabolBee commented 2 years ago

Hi,

As you mentioned in wiki - The Profiling Approach, there are restrictions in async callback.

What are they exactly?

Actually, I've met some trouble while implementing the signal handler with JVMTI which I think they come frome the restriction. Below is my code:

void signalHandler(...){
     ...
     vm->GetEnv(*jni, JNI_VERSION_1_6);

     pAGCT(&trace, MAXFRAMES, ucontext);      //invoke asyncGetCallTrace funciton
     if (trace.num_frames > ){
         jni->FindClass(...);
         jni->GetStaticMethodID(...);
         jni->CallStaticObjectMethod(...);
         ...
     }
}

void setSignalHandler(...){
    ...
    sa.sa_sigaction = &signalHandler;
    ...
}

JNIEXPORT jint JNICALL
Agent_OnAttach(...){
    ...
    enable_capabilities();
    set_callbacks();
    set_notif();
    setSignalHandler();
    setitimer(...);
}

The VM crashed when I was trying to attach this agent on a running program and I got SIGFPE or SIGSEGV signal in core dump. What i found in hs_err_pid.log is that the problematic frame is always in [libjvm.so]. This almost drives me mad.

Would you kindly explain why these crashes happened?

Thank you

RichardWarburton commented 2 years ago

This isn't an issue about Honest Profiler - it's a question about how to write your own profiler.