Support using adbconnection and openjdkjvmti without JAVA_DEBUGGABLE

We need to support using a best-effort JDWP when we have the
ENABLE_JDWP attribute without the JAVA_DEBUGGABLE attribute. This is
used on eng and userdebug builds. We do this by making the plugin try
to change the runtime to debuggable if possible and to allow getting
an ArtTiEnv which is a best-effort version of JVMTI by calling GetEnv
with (JVMTI_VERSION_1_2 | 0x4000000). This is needed since if the
runtime isn't debuggable we cannot guarantee compatibility with the
JVMTI specification in all cases due to compiler optimizations such as
inlining. By creating this special version agents are able to
positively signal that they are able to deal with this uncertainty.

We also support using openjdkjvmti without being JAVA_DEBUGGABLE. This
is done by either only allowing the best effort ArtTiEnvs or by
changing the environment to be debuggable if we are loaded early
enough.

Moving the runtime to debuggable state involves deoptimizing the boot
image and throwing out any image files associated with non-debuggable
oat-files.

Bug: 62821960
Test: ./test.py --host -j50
Test: Manual
Test: Build, Test debugging system_server and other processes.
Change-Id: I2233299fceb83c76785e5de09e51eaf18b7922e8
diff --git a/adbconnection/adbconnection.cc b/adbconnection/adbconnection.cc
index a5c885a..80cfc83 100644
--- a/adbconnection/adbconnection.cc
+++ b/adbconnection/adbconnection.cc
@@ -63,9 +63,7 @@
 static AdbConnectionState* gState;
 
 static bool IsDebuggingPossible() {
-  // TODO We need to do this on IsJdwpAllowed not IsDebuggable in order to support userdebug
-  // workloads. For now we will only allow it when we are debuggable so that testing is easier.
-  return art::Runtime::Current()->IsJavaDebuggable() && art::Dbg::IsJdwpAllowed();
+  return art::Dbg::IsJdwpAllowed();
 }
 
 // Begin running the debugger.
@@ -581,11 +579,14 @@
         DCHECK(!agent_has_socket_);
         if (!agent_loaded_) {
           DCHECK(!agent_listening_);
+          // TODO Should we check in some other way if we are userdebug/eng?
+          CHECK(art::Dbg::IsJdwpAllowed());
           // Load the agent now!
           self->AssertNoPendingException();
           art::Runtime::Current()->AttachAgent(/* JNIEnv* */ nullptr,
                                                MakeAgentArg(),
-                                               /* classloader */ nullptr);
+                                               /* classloader */ nullptr,
+                                               /*allow_non_debuggable_tooling*/ true);
           if (self->IsExceptionPending()) {
             LOG(ERROR) << "Failed to load agent " << agent_name_;
             art::ScopedObjectAccess soa(self);