Do superclass validation at compile time and log with new class status.

Tries to perform superclass validation for classes that are resolved,
but not initialized at runtime. If successful, saves the result in the
oat file with a new class status. At runtime, the superclass validation
can be skipped during class initialization, saving some time and
reducing string accesses.

Results show savings of 50kB PSS in maps on startup, with slight
decrease in startup time.

Maps (average of 100 runs)
Before: dex 9941.3 odex 15159.8 total 25101.1 launch 908
After: dex 9897.4 odex 15155.7 total 25053.1 launch 906.6

Bug: 63456114
Test: mm test-art-host
Change-Id: If67a4a49d61781b6d561c26118d7e0c6b9cc0d6f
diff --git a/test/138-duplicate-classes-check2/src/Main.java b/test/138-duplicate-classes-check2/src/Main.java
index faf8b5d..588e5eb 100644
--- a/test/138-duplicate-classes-check2/src/Main.java
+++ b/test/138-duplicate-classes-check2/src/Main.java
@@ -15,12 +15,30 @@
  */
 
 import java.io.File;
+import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 
 /**
  * Structural hazard test.
  */
 public class Main {
+    public static String TEST_NAME = "138-duplicate-classes-check2";
+
+    public static ClassLoader getClassLoaderFor(String location) throws Exception {
+        try {
+            Class<?> class_loader_class = Class.forName("dalvik.system.PathClassLoader");
+            Constructor<?> ctor =
+                    class_loader_class.getConstructor(String.class, ClassLoader.class);
+            /* on Dalvik, this is a DexFile; otherwise, it's null */
+            return (ClassLoader) ctor.newInstance(location + "/" + TEST_NAME + "-ex.jar",
+                                                  Main.class.getClassLoader());
+        } catch (ClassNotFoundException e) {
+            // Running on RI. Use URLClassLoader.
+            return new java.net.URLClassLoader(
+                    new java.net.URL[] { new java.net.URL("file://" + location + "/classes-ex/") });
+        }
+    }
+
     public static void main(String[] args) {
         new Main().run();
     }
@@ -29,15 +47,18 @@
         System.out.println(new A().i);
 
         // Now run the class from the -ex file.
-
-        FancyLoader loader = new FancyLoader(getClass().getClassLoader());
-
         try {
-            Class<?> testEx = loader.loadClass("TestEx");
-            Method test = testEx.getDeclaredMethod("test");
-            test.invoke(null);
-        } catch (Exception exc) {
-            exc.printStackTrace(System.out);
+            /* this is the "alternate" DEX/Jar file */
+            ClassLoader new_loader = getClassLoaderFor(System.getenv("DEX_LOCATION"));
+            Class<?> klass = (Class<?>) new_loader.loadClass("TestEx");
+            if (klass == null) {
+                throw new AssertionError("loadClass failed");
+            }
+            Method run_test = klass.getMethod("test");
+            run_test.invoke(null);
+        } catch (Exception e) {
+            System.out.println(e.toString());
+            e.printStackTrace(System.out);
         }
     }
 }