Ensure GetPhase returns correct values.
We were incorrectly waiting until after the kInit and kStart runtime
phase callbacks to change the current runtime phase. The phase should
have already changed by the time the VMInit and VMStart are
dispatched.
Test: ./test.py --host -j50
Change-Id: I959221025a6692f2244048aa852170bb70dc2b7a
diff --git a/openjdkjvmti/ti_phase.cc b/openjdkjvmti/ti_phase.cc
index 8893c9b..e8c1ca7 100644
--- a/openjdkjvmti/ti_phase.cc
+++ b/openjdkjvmti/ti_phase.cc
@@ -63,18 +63,18 @@
break;
case RuntimePhase::kStart:
{
+ PhaseUtil::current_phase_ = JVMTI_PHASE_START;
art::ScopedThreadSuspension sts(art::Thread::Current(), art::ThreadState::kNative);
event_handler->DispatchEvent<ArtJvmtiEvent::kVmStart>(nullptr, GetJniEnv());
- PhaseUtil::current_phase_ = JVMTI_PHASE_START;
}
break;
case RuntimePhase::kInit:
{
ThreadUtil::CacheData();
+ PhaseUtil::current_phase_ = JVMTI_PHASE_LIVE;
ScopedLocalRef<jthread> thread(GetJniEnv(), GetCurrentJThread());
art::ScopedThreadSuspension sts(art::Thread::Current(), art::ThreadState::kNative);
event_handler->DispatchEvent<ArtJvmtiEvent::kVmInit>(nullptr, GetJniEnv(), thread.get());
- PhaseUtil::current_phase_ = JVMTI_PHASE_LIVE;
}
break;
case RuntimePhase::kDeath:
diff --git a/test/901-hello-ti-agent/basics.cc b/test/901-hello-ti-agent/basics.cc
index 2edd91e..472f2b7 100644
--- a/test/901-hello-ti-agent/basics.cc
+++ b/test/901-hello-ti-agent/basics.cc
@@ -38,20 +38,27 @@
}
}
-static void JNICALL VMStartCallback(jvmtiEnv *jenv ATTRIBUTE_UNUSED,
- JNIEnv* jni_env ATTRIBUTE_UNUSED) {
- printf("VMStart\n");
+static jvmtiPhase getPhase(jvmtiEnv* jenv) {
+ jvmtiPhase out = static_cast<jvmtiPhase>(-1);
+ jenv->GetPhase(&out);
+ return out;
}
-static void JNICALL VMInitCallback(jvmtiEnv *jvmti_env ATTRIBUTE_UNUSED,
+static void JNICALL VMStartCallback(jvmtiEnv *jenv, JNIEnv* jni_env ATTRIBUTE_UNUSED) {
+ printf("VMStart (phase %d)\n", getPhase(jenv));
+ fsync(1);
+}
+
+static void JNICALL VMInitCallback(jvmtiEnv *jvmti_env,
JNIEnv* jni_env ATTRIBUTE_UNUSED,
jthread thread ATTRIBUTE_UNUSED) {
- printf("VMInit\n");
+ printf("VMInit (phase %d)\n", getPhase(jvmti_env));
+ fsync(1);
}
-static void JNICALL VMDeatchCallback(jvmtiEnv *jenv ATTRIBUTE_UNUSED,
- JNIEnv* jni_env ATTRIBUTE_UNUSED) {
- printf("VMDeath\n");
+static void JNICALL VMDeatchCallback(jvmtiEnv *jenv, JNIEnv* jni_env ATTRIBUTE_UNUSED) {
+ printf("VMDeath (phase %d)\n", getPhase(jenv));
+ fsync(1);
}
diff --git a/test/901-hello-ti-agent/expected.txt b/test/901-hello-ti-agent/expected.txt
index 4177ffc..73e389c 100644
--- a/test/901-hello-ti-agent/expected.txt
+++ b/test/901-hello-ti-agent/expected.txt
@@ -1,6 +1,6 @@
Loaded Agent for test 901-hello-ti-agent
-VMStart
-VMInit
+VMStart (phase 6)
+VMInit (phase 4)
Hello, world!
Agent in live phase.
Received expected error for unattached JVMTI calls
@@ -73,4 +73,4 @@
115 = JVMTI_ERROR_UNATTACHED_THREAD
116 = JVMTI_ERROR_INVALID_ENVIRONMENT
1 times JVMTI_ERROR_ILLEGAL_ARGUMENT
-VMDeath
+VMDeath (phase 4)