Change LoadNativeLibrary to use GetOrCreateAllocator

Previously we used GetAllocatorForClassLoader. This did not
handle the case where someone called LoadLibrary without having
already loaded a class.

Added regression test.

Bug: 25866849

Change-Id: Id720505eaded3b0f9c2eab59a40611b328837c4a
diff --git a/test/068-classloader/src/Main.java b/test/068-classloader/src/Main.java
index 361e293..e3bf82c 100644
--- a/test/068-classloader/src/Main.java
+++ b/test/068-classloader/src/Main.java
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 /**
  * Class loader test.
  */
@@ -62,6 +64,28 @@
         testSeparation();
 
         testClassForName();
+
+        // Attempt to load without a class table, regression test for b/25866849.
+        testLoadNativeLibrary(args[0]);
+    }
+
+    static void testLoadNativeLibrary(String libName) throws Exception {
+        Class pathClassLoader = Class.forName("dalvik.system.PathClassLoader");
+        if (pathClassLoader == null) {
+            throw new AssertionError("Couldn't find path class loader class");
+        }
+        Constructor constructor =
+            pathClassLoader.getDeclaredConstructor(String.class, ClassLoader.class);
+        ClassLoader loader = (ClassLoader) constructor.newInstance(
+            FancyLoader.DEX_FILE, ClassLoader.getSystemClassLoader());
+        Runtime runtime = Runtime.getRuntime();
+        Method method = runtime.getClass().getDeclaredMethod("loadLibrary", String.class,
+            ClassLoader.class);
+        if (method == null) {
+            throw new RuntimeException("loadLibrary not found");
+        }
+        method.setAccessible(true);
+        method.invoke(runtime, libName, loader);
     }
 
     static void testSeparation() {