Don't use oat / runtime app images in debuggable runtimes

Oat code even when compiled in debuggable mode lacks method entry / exit
hooks. While runtime app images could be potentially used in debuggable
runtimes, they don't impact the performance much. So to keep things
simple, just don't load images in debuggable runtimes.

Also, fix the entrypoints when initializing the classes. This is
strictly not necessary but a safe thing to do.

Test: art/testrunner.py --speed --debuggable

Change-Id: I1c2b5c54a634ff3cde7f46f1077b5e16db2ecb0e
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 19f7948..fca86a5 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -2190,7 +2190,9 @@
   }
 
   // Set entry point to interpreter if in InterpretOnly mode.
-  if (!runtime->IsAotCompiler() && runtime->GetInstrumentation()->InterpretOnly()) {
+  if (!runtime->IsAotCompiler() &&
+      (runtime->GetInstrumentation()->InterpretOnly() ||
+       runtime->IsJavaDebuggable())) {
     // Set image methods' entry point to interpreter.
     header.VisitPackedArtMethods([&](ArtMethod& method) REQUIRES_SHARED(Locks::mutator_lock_) {
       if (!method.IsRuntimeMethod()) {
diff --git a/runtime/oat_file_manager.cc b/runtime/oat_file_manager.cc
index 63e005d..1413896 100644
--- a/runtime/oat_file_manager.cc
+++ b/runtime/oat_file_manager.cc
@@ -169,9 +169,9 @@
   return oat_files;
 }
 
-bool OatFileManager::ShouldLoadAppImage(const OatFile* source_oat_file) const {
+bool OatFileManager::ShouldLoadAppImage() const {
   Runtime* const runtime = Runtime::Current();
-  return kEnableAppImage && (!runtime->IsJavaDebuggableAtInit() || source_oat_file->IsDebuggable());
+  return kEnableAppImage && !runtime->IsJavaDebuggableAtInit();
 }
 
 std::vector<std::unique_ptr<const DexFile>> OatFileManager::OpenDexFilesFromOat(
@@ -265,7 +265,7 @@
       // We need to throw away the image space if we are debuggable but the oat-file source of the
       // image is not otherwise we might get classes with inlined methods or other such things.
       std::unique_ptr<gc::space::ImageSpace> image_space;
-      if (ShouldLoadAppImage(oat_file.get())) {
+      if (ShouldLoadAppImage()) {
         if (oat_file->IsExecutable()) {
           // App images generated by the compiler can only be used if the oat file
           // is executable.
diff --git a/runtime/oat_file_manager.h b/runtime/oat_file_manager.h
index e09390b..d812829 100644
--- a/runtime/oat_file_manager.h
+++ b/runtime/oat_file_manager.h
@@ -158,7 +158,7 @@
       REQUIRES(Locks::oat_file_manager_lock_);
 
   // Return true if we should attempt to load the app image.
-  bool ShouldLoadAppImage(const OatFile* source_oat_file) const;
+  bool ShouldLoadAppImage() const;
 
   std::set<std::unique_ptr<const OatFile>> oat_files_ GUARDED_BY(Locks::oat_file_manager_lock_);
 
diff --git a/test/685-deoptimizeable/src/Main.java b/test/685-deoptimizeable/src/Main.java
index 41dcfd1..674b2fc 100644
--- a/test/685-deoptimizeable/src/Main.java
+++ b/test/685-deoptimizeable/src/Main.java
@@ -74,6 +74,8 @@
           disableStackFrameAsserts();
         }
 
+        // Just declare a new int array so that the int arrays are resolved properly when JITing.
+        int[] tmp = new int[3];
         ensureAllJitCompiled();
 
         final HashMap<SampleObject, Long> map = new HashMap<SampleObject, Long>();
diff --git a/test/knownfailures.json b/test/knownfailures.json
index 0455db4..f5b695d 100644
--- a/test/knownfailures.json
+++ b/test/knownfailures.json
@@ -311,8 +311,8 @@
         "variant": "field-stress | jvmti-stress | redefine-stress | step-stress | trace-stress"
     },
     {
-        "tests": "596-app-images",
-        "description": "app images do not initialize classes when debuggable",
+        "tests": ["596-app-images", "597-app-images-same-classloader", "661-oat-writer-layout"],
+        "description": "app images are not loaded when debuggable",
         "variant": "debuggable"
     },
     {
@@ -1167,6 +1167,7 @@
                   "844-exception2",
                   "845-fast-verify",
                   "845-data-image",
+		  "2264-debuggable-data-image",
                   "846-multidex-data-image",
                   "847-filled-new-aray",
                   "999-redefine-hiddenapi",
@@ -1564,7 +1565,7 @@
         "description": ["Test timing out on debug gc."]
     },
     {
-        "tests": ["845-data-image", "846-multidex-data-image"],
+        "tests": ["845-data-image", "846-multidex-data-image", "2264-debuggable-data-image"],
         "variant": "debuggable | trace | stream",
         "description": ["Runtime app images are not supported with debuggable."]
     },