void JNICALL OnVMDeath(jvmtiEnv *jvmti_env, JNIEnv *jni_env) { IMPLICITLY_USE(jvmti_env); IMPLICITLY_USE(jni_env); if (prof->isRunning()) prof->stop(); }
// This has to be here, or the VM turns off class loading events. // And AsyncGetCallTrace needs class loading events to be turned on! void JNICALL OnClassLoad(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thread, jclass klass) { IMPLICITLY_USE(jvmti_env); IMPLICITLY_USE(jni_env); IMPLICITLY_USE(thread); IMPLICITLY_USE(klass); }
void JNICALL OnClassPrepare(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thread, jclass klass) { IMPLICITLY_USE(jni_env); IMPLICITLY_USE(thread); // We need to do this to "prime the pump", as it were -- make sure // that all of the methodIDs have been initialized internally, for // AsyncGetCallTrace. I imagine it slows down class loading a mite, // but honestly, how fast does class loading have to be? CreateJMethodIDsForClass(jvmti_env, klass); }
void Processor::start(JNIEnv *jniEnv) { std::cout << "Start\n"; jthread thread = newThread(jniEnv); jvmtiStartFunction callback = [](jvmtiEnv *jvmti_env, JNIEnv *jni_env, void *arg) { IMPLICITLY_USE(jvmti_env); IMPLICITLY_USE(jni_env); Processor *processor = (Processor *) arg; processor->run(); }; jvmti_->RunAgentThread(thread, callback, this, JVMTI_THREAD_NORM_PRIORITY); }
void Profiler::handle(int signum, siginfo_t *info, void *context) { IMPLICITLY_USE(signum); IMPLICITLY_USE(info); // sample data structure JVMPI_CallFrame frames[kMaxFramesToCapture]; JVMPI_CallTrace trace; trace.frames = frames; JNIEnv *jniEnv = getJNIEnv(jvm_); if (jniEnv == NULL) { trace.num_frames = -3; // ticks_unknown_not_Java } else { trace.env_id = jniEnv; ASGCTType asgct = Asgct::GetAsgct(); (*asgct)(&trace, kMaxFramesToCapture, context); } // log all samples, failures included, let the post processing sift through the data buffer->push(trace); }
void JNICALL OnVMInit(jvmtiEnv *jvmti, JNIEnv *jniEnv, jthread thread) { IMPLICITLY_USE(thread); TimeUtils::init(); // required to init OS X's clock service // Forces the creation of jmethodIDs of the classes that had already // been loaded (eg java.lang.Object, java.lang.ClassLoader) and // OnClassPrepare() misses. jint class_count; JvmtiScopedPtr<jclass> classes(jvmti); JVMTI_ERROR((jvmti->GetLoadedClasses(&class_count, classes.GetRef()))); jclass *classList = classes.Get(); for (int i = 0; i < class_count; ++i) { jclass klass = classList[i]; CreateJMethodIDsForClass(jvmti, klass); } if (!configuration.host.empty() && !configuration.port.empty()) { controller->start(); } }
void JNICALL OnVMInit(jvmtiEnv *jvmti, JNIEnv *jniEnv, jthread thread) { IMPLICITLY_USE(thread); TimeUtils::init(); // required to init OS X's clock service // Forces the creation of jmethodIDs of the classes that had already // been loaded (eg java.lang.Object, java.lang.ClassLoader) and // OnClassPrepare() misses. jint class_count; JvmtiScopedPtr<jclass> classes(jvmti); JVMTI_ERROR((jvmti->GetLoadedClasses(&class_count, classes.GetRef()))); jclass *classList = classes.Get(); for (int i = 0; i < class_count; ++i) { jclass klass = classList[i]; CreateJMethodIDsForClass(jvmti, klass); } #ifndef GETENV_NEW_THREAD_ASYNC_UNSAFE if (CONFIGURATION->host != NULL && CONFIGURATION->port != NULL) { controller->start(); } #endif }