summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alex Light <allight@google.com> 2017-08-16 16:07:37 -0700
committer Alex Light <allight@google.com> 2017-08-16 16:18:12 -0700
commitbf9e516f4964ee900d2996abaf60977c1c643aa3 (patch)
tree0656e7a0c692ca4539c67ea1684dfbe7a6f95048
parent675c779cb046bca49229e1e5268d0eb622159214 (diff)
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
-rw-r--r--openjdkjvmti/ti_phase.cc4
-rw-r--r--test/901-hello-ti-agent/basics.cc23
-rw-r--r--test/901-hello-ti-agent/expected.txt6
3 files changed, 20 insertions, 13 deletions
diff --git a/openjdkjvmti/ti_phase.cc b/openjdkjvmti/ti_phase.cc
index 8893c9b4aa..e8c1ca7335 100644
--- a/openjdkjvmti/ti_phase.cc
+++ b/openjdkjvmti/ti_phase.cc
@@ -63,18 +63,18 @@ struct PhaseUtil::PhaseCallback : public art::RuntimePhaseCallback {
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 2edd91eb66..472f2b768e 100644
--- a/test/901-hello-ti-agent/basics.cc
+++ b/test/901-hello-ti-agent/basics.cc
@@ -38,20 +38,27 @@ static void EnableEvent(jvmtiEnv* env, jvmtiEvent evt) {
}
}
-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 4177ffc4dc..73e389c8a1 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 @@ JVMTI_ERROR_ILLEGAL_ARGUMENT
115 = JVMTI_ERROR_UNATTACHED_THREAD
116 = JVMTI_ERROR_INVALID_ENVIRONMENT
1 times JVMTI_ERROR_ILLEGAL_ARGUMENT
-VMDeath
+VMDeath (phase 4)