summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/openjdkjvmti/ti_class.cc8
-rw-r--r--test/ti-stress/stress.cc23
2 files changed, 29 insertions, 2 deletions
diff --git a/runtime/openjdkjvmti/ti_class.cc b/runtime/openjdkjvmti/ti_class.cc
index cd078b6c5a..332181497c 100644
--- a/runtime/openjdkjvmti/ti_class.cc
+++ b/runtime/openjdkjvmti/ti_class.cc
@@ -313,8 +313,10 @@ struct ClassCallback : public art::ClassLoadCallback {
art::Thread* thread = art::Thread::Current();
ScopedLocalRef<jclass> jklass(thread->GetJniEnv(),
thread->GetJniEnv()->AddLocalReference<jclass>(klass.Get()));
+ art::ObjPtr<art::mirror::Object> peer(thread->GetPeer());
ScopedLocalRef<jthread> thread_jni(
- thread->GetJniEnv(), thread->GetJniEnv()->AddLocalReference<jthread>(thread->GetPeer()));
+ thread->GetJniEnv(),
+ peer.IsNull() ? nullptr : thread->GetJniEnv()->AddLocalReference<jthread>(peer));
{
art::ScopedThreadSuspension sts(thread, art::ThreadState::kNative);
event_handler->DispatchEvent<ArtJvmtiEvent::kClassLoad>(
@@ -341,8 +343,10 @@ struct ClassCallback : public art::ClassLoadCallback {
}
ScopedLocalRef<jclass> jklass(thread->GetJniEnv(),
thread->GetJniEnv()->AddLocalReference<jclass>(klass.Get()));
+ art::ObjPtr<art::mirror::Object> peer(thread->GetPeer());
ScopedLocalRef<jthread> thread_jni(
- thread->GetJniEnv(), thread->GetJniEnv()->AddLocalReference<jthread>(thread->GetPeer()));
+ thread->GetJniEnv(),
+ peer.IsNull() ? nullptr : thread->GetJniEnv()->AddLocalReference<jthread>(peer));
art::ScopedThreadSuspension sts(thread, art::ThreadState::kNative);
event_handler->DispatchEvent<ArtJvmtiEvent::kClassPrepare>(
thread,
diff --git a/test/ti-stress/stress.cc b/test/ti-stress/stress.cc
index 515a39126d..76f894325b 100644
--- a/test/ti-stress/stress.cc
+++ b/test/ti-stress/stress.cc
@@ -338,6 +338,20 @@ void JNICALL MethodEntryHook(jvmtiEnv* jvmtienv,
LOG(INFO) << "Entering method \"" << method_info << "\". Thread is \"" << info.GetName() << "\"";
}
+void JNICALL ClassPrepareHook(jvmtiEnv* jvmtienv,
+ JNIEnv* env,
+ jthread thread,
+ jclass klass) {
+ ScopedThreadInfo info(jvmtienv, env, thread);
+ ScopedClassInfo class_info(jvmtienv, klass);
+ if (!class_info.Init()) {
+ LOG(ERROR) << "Unable to get class info!";
+ return;
+ }
+ LOG(INFO) << "Prepared class \"" << class_info.GetName() << "\". Thread is \""
+ << info.GetName() << "\"";
+}
+
// The hook we are using.
void JNICALL ClassFileLoadHookSecretNoOp(jvmtiEnv* jvmti,
JNIEnv* jni_env ATTRIBUTE_UNUSED,
@@ -487,6 +501,7 @@ extern "C" JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM* vm,
cb.VMInit = PerformFinalSetupVMInit;
cb.MethodEntry = MethodEntryHook;
cb.MethodExit = MethodExitHook;
+ cb.ClassPrepare = ClassPrepareHook;
if (jvmti->SetEventCallbacks(&cb, sizeof(cb)) != JVMTI_ERROR_NONE) {
LOG(ERROR) << "Unable to set class file load hook cb!";
return 1;
@@ -503,6 +518,14 @@ extern "C" JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM* vm,
LOG(ERROR) << "Unable to enable JVMTI_EVENT_VM_INIT event!";
return 1;
}
+ if (data->trace_stress) {
+ if (jvmti->SetEventNotificationMode(JVMTI_ENABLE,
+ JVMTI_EVENT_CLASS_PREPARE,
+ nullptr) != JVMTI_ERROR_NONE) {
+ LOG(ERROR) << "Unable to enable CLASS_PREPARE event!";
+ return 1;
+ }
+ }
if (data->redefine_stress) {
if (jvmti->SetEventNotificationMode(JVMTI_ENABLE,
JVMTI_EVENT_CLASS_FILE_LOAD_HOOK,