Do native method bind in jvmti-stress
Extend the jvmti-stress test suite to intercept the NativeMethodBind
event for every method.
Also fix small issue where we tried to add a local reference to a null
thread in ti_method.cc if we had an event trigger before VMInit.
Test: ./test/testrunner/testrunner.py --host --jvmti-stress -j40
Bug: 37432636
Change-Id: I2d83fc460b18edf035ed7296b8e2b06cff3671e5
diff --git a/runtime/openjdkjvmti/ti_method.cc b/runtime/openjdkjvmti/ti_method.cc
index 2adabba..f7e5347 100644
--- a/runtime/openjdkjvmti/ti_method.cc
+++ b/runtime/openjdkjvmti/ti_method.cc
@@ -44,6 +44,7 @@
#include "ScopedLocalRef.h"
#include "thread-inl.h"
#include "thread_list.h"
+#include "ti_phase.h"
namespace openjdkjvmti {
@@ -54,12 +55,14 @@
OVERRIDE REQUIRES_SHARED(art::Locks::mutator_lock_) {
if (event_handler->IsEventEnabledAnywhere(ArtJvmtiEvent::kNativeMethodBind)) {
art::Thread* thread = art::Thread::Current();
+ art::JNIEnvExt* jnienv = thread->GetJniEnv();
ScopedLocalRef<jthread> thread_jni(
- thread->GetJniEnv(), thread->GetJniEnv()->AddLocalReference<jthread>(thread->GetPeer()));
+ jnienv, PhaseUtil::IsLivePhase() ? jnienv->AddLocalReference<jthread>(thread->GetPeer())
+ : nullptr);
art::ScopedThreadSuspension sts(thread, art::ThreadState::kNative);
event_handler->DispatchEvent<ArtJvmtiEvent::kNativeMethodBind>(
thread,
- static_cast<JNIEnv*>(thread->GetJniEnv()),
+ static_cast<JNIEnv*>(jnienv),
thread_jni.get(),
art::jni::EncodeArtMethod(method),
const_cast<void*>(cur_method),