Snap for 8748207 from e9a851ffb63d0fc082940db0f23390c8a1d48ce5 to mainline-uwb-release

Change-Id: I2ccaa7c40009c80f6908bc8b64e004a5800edc0c
diff --git a/openjdkjvmti/deopt_manager.cc b/openjdkjvmti/deopt_manager.cc
index a15e667..312a797 100644
--- a/openjdkjvmti/deopt_manager.cc
+++ b/openjdkjvmti/deopt_manager.cc
@@ -460,15 +460,7 @@
   art::ScopedThreadStateChange stsc(self, art::ThreadState::kSuspended);
   deoptimization_status_lock_.ExclusiveLock(self);
   deopter_count_++;
-  if (deopter_count_ == 1) {
-    ScopedDeoptimizationContext sdc(self, this);
-    art::instrumentation::Instrumentation* instrumentation =
-        art::Runtime::Current()->GetInstrumentation();
-    // Tell instrumentation we will be deopting single threads.
-    instrumentation->EnableSingleThreadDeopt(kInstrumentationKey);
-  } else {
-    deoptimization_status_lock_.ExclusiveUnlock(self);
-  }
+  deoptimization_status_lock_.ExclusiveUnlock(self);
 }
 
 void DeoptManager::DeoptimizeThread(art::Thread* target) {
diff --git a/runtime/instrumentation.cc b/runtime/instrumentation.cc
index 1e328a3..6ec98ff 100644
--- a/runtime/instrumentation.cc
+++ b/runtime/instrumentation.cc
@@ -372,7 +372,7 @@
     REQUIRES_SHARED(Locks::mutator_lock_) {
   // Use instrumentation entrypoints if instrumentation is installed.
   if (UNLIKELY(EntryExitStubsInstalled()) && !IsProxyInit(method)) {
-    if (!method->IsNative() && InterpretOnly()) {
+    if (!method->IsNative() && InterpretOnly(method)) {
       UpdateEntryPoints(method, GetQuickToInterpreterBridge());
     } else {
       UpdateEntryPoints(method, GetQuickInstrumentationEntryPoint());
@@ -380,7 +380,7 @@
     return;
   }
 
-  if (UNLIKELY(IsForcedInterpretOnly())) {
+  if (UNLIKELY(IsForcedInterpretOnly() || IsDeoptimized(method))) {
     UpdateEntryPoints(
         method, method->IsNative() ? GetQuickGenericJniStub() : GetQuickToInterpreterBridge());
     return;
@@ -896,11 +896,6 @@
   UpdateStubs();
 }
 
-void Instrumentation::EnableSingleThreadDeopt(const char* key) {
-  // Prepare for single thread deopt by installing instrumentation stubs.
-  ConfigureStubs(key, InstrumentationLevel::kInstrumentWithInstrumentationStubs);
-}
-
 void Instrumentation::UpdateInstrumentationLevel(InstrumentationLevel requested_level) {
   instrumentation_level_ = requested_level;
 }
@@ -922,7 +917,9 @@
   Locks::mutator_lock_->AssertExclusiveHeld(self);
   Runtime::Current()->GetThreadList()->ForEach([&](Thread* t) NO_THREAD_SAFETY_ANALYSIS {
     no_remaining_deopts =
-        no_remaining_deopts && !t->IsForceInterpreter() &&
+        no_remaining_deopts &&
+        !t->IsForceInterpreter() &&
+        !t->HasDebuggerShadowFrames() &&
         std::all_of(t->GetInstrumentationStack()->cbegin(),
                     t->GetInstrumentationStack()->cend(),
                     [&](const auto& frame) REQUIRES_SHARED(Locks::mutator_lock_) {
@@ -1058,7 +1055,7 @@
 }
 
 void Instrumentation::UpdateMethodsCodeImpl(ArtMethod* method, const void* new_code) {
-  if (!EntryExitStubsInstalled()) {
+  if (!AreExitStubsInstalled()) {
     // Fast path: no instrumentation.
     DCHECK(!IsDeoptimized(method));
     UpdateEntryPoints(method, new_code);
@@ -1079,7 +1076,7 @@
     return;
   }
 
-  if (CodeNeedsEntryExitStub(new_code, method)) {
+  if (EntryExitStubsInstalled() && CodeNeedsEntryExitStub(new_code, method)) {
     DCHECK(method->GetEntryPointFromQuickCompiledCode() == GetQuickInstrumentationEntryPoint() ||
         class_linker->IsQuickToInterpreterBridge(method->GetEntryPointFromQuickCompiledCode()))
               << EntryPointString(method->GetEntryPointFromQuickCompiledCode())
diff --git a/runtime/instrumentation.h b/runtime/instrumentation.h
index b163109..c811935 100644
--- a/runtime/instrumentation.h
+++ b/runtime/instrumentation.h
@@ -524,13 +524,6 @@
   void InstallStubsForMethod(ArtMethod* method)
       REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!GetDeoptimizedMethodsLock());
 
-  // Sets up instrumentation to allow single thread deoptimization using ForceInterpreterCount.
-  void EnableSingleThreadDeopt(const char* key)
-      REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_)
-      REQUIRES(!Locks::thread_list_lock_,
-               !Locks::classlinker_classes_lock_,
-               !GetDeoptimizedMethodsLock());
-
   // Install instrumentation exit stub on every method of the stack of the given thread.
   // This is used by:
   //  - the debugger to cause a deoptimization of the all frames in thread's stack (for
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc
index 5e01aaa..6d634ae 100644
--- a/runtime/jit/jit.cc
+++ b/runtime/jit/jit.cc
@@ -568,7 +568,12 @@
   // Before allowing the jump, make sure no code is actively inspecting the method to avoid
   // jumping from interpreter to OSR while e.g. single stepping. Note that we could selectively
   // disable OSR when single stepping, but that's currently hard to know at this point.
-  if (Runtime::Current()->GetRuntimeCallbacks()->IsMethodBeingInspected(method)) {
+  if (Runtime::Current()->GetInstrumentation()->InterpreterStubsInstalled() ||
+      Runtime::Current()->GetInstrumentation()->IsDeoptimized(method) ||
+      thread->IsForceInterpreter() ||
+      method->GetDeclaringClass()->IsObsoleteObject() ||
+      Dbg::IsForcedInterpreterNeededForUpcall(thread, method) ||
+      Runtime::Current()->GetRuntimeCallbacks()->IsMethodBeingInspected(method)) {
     return false;
   }
 
diff --git a/test/etc/run-test-jar b/test/etc/run-test-jar
index 75dc8fe..ef168ca 100755
--- a/test/etc/run-test-jar
+++ b/test/etc/run-test-jar
@@ -650,11 +650,11 @@
     # needed anymore since the plugin can do it for us now.
     FLAGS="${FLAGS} -Xplugin:${plugin}"
 
-    # For jvmti tests, set the threshold of compilation to 0, so we jit on the first
-    # use to provide better test coverage for jvmti + jit. This means we won't run
+    # For jvmti tests, set the threshold of compilation to 1, so we jit early to
+    # provide better test coverage for jvmti + jit. This means we won't run
     # the default --jit configuration but it is not too important test scenario for
     # jvmti tests. This is art specific flag, so don't use it with jvm.
-    FLAGS="${FLAGS} -Xjitthreshold:0"
+    FLAGS="${FLAGS} -Xjitthreshold:1"
   fi
 fi