summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Mathieu Chartier <mathieuc@google.com> 2015-11-24 16:22:54 -0800
committer Mathieu Chartier <mathieuc@google.com> 2015-11-30 14:31:17 -0800
commit2d902b99bba7ae1ad77ebeb038a4ef63c3ed6399 (patch)
tree4f3393583e8c7da6b370aa3ba61d1d7714349e0b
parent1850cb43dbddbc655a6f990a7d475587fa9d6659 (diff)
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
-rw-r--r--runtime/java_vm_ext.cc2
-rw-r--r--test/068-classloader/expected.txt1
-rw-r--r--test/068-classloader/src/FancyLoader.java2
-rw-r--r--test/068-classloader/src/Main.java24
4 files changed, 27 insertions, 2 deletions
diff --git a/runtime/java_vm_ext.cc b/runtime/java_vm_ext.cc
index 7cc05f7cd4..58da7f285a 100644
--- a/runtime/java_vm_ext.cc
+++ b/runtime/java_vm_ext.cc
@@ -736,7 +736,7 @@ bool JavaVMExt::LoadNativeLibrary(JNIEnv* env, const std::string& path, jobject
// it's okay to decode it without worrying about unexpectedly marking it alive.
mirror::ClassLoader* loader = soa.Decode<mirror::ClassLoader*>(class_loader);
class_loader_allocator =
- Runtime::Current()->GetClassLinker()->GetAllocatorForClassLoader(loader);
+ Runtime::Current()->GetClassLinker()->GetOrCreateAllocatorForClassLoader(loader);
CHECK(class_loader_allocator != nullptr);
}
if (library != nullptr) {
diff --git a/test/068-classloader/expected.txt b/test/068-classloader/expected.txt
index 8725799fe1..36e4f4872c 100644
--- a/test/068-classloader/expected.txt
+++ b/test/068-classloader/expected.txt
@@ -13,3 +13,4 @@ Got LinkageError on DI (early)
Got LinkageError on IDI (early)
class Main
Got expected ClassNotFoundException
+JNI_OnLoad called
diff --git a/test/068-classloader/src/FancyLoader.java b/test/068-classloader/src/FancyLoader.java
index 6a153cc9e2..b8eac7b52f 100644
--- a/test/068-classloader/src/FancyLoader.java
+++ b/test/068-classloader/src/FancyLoader.java
@@ -38,7 +38,7 @@ public class FancyLoader extends ClassLoader {
static final String CLASS_PATH = "classes-ex/";
/* this is the "alternate" DEX/Jar file */
- static final String DEX_FILE = System.getenv("DEX_LOCATION") + "/068-classloader-ex.jar";
+ public static final String DEX_FILE = System.getenv("DEX_LOCATION") + "/068-classloader-ex.jar";
/* on Dalvik, this is a DexFile; otherwise, it's null */
private Class mDexClass;
diff --git a/test/068-classloader/src/Main.java b/test/068-classloader/src/Main.java
index 361e2938e3..e3bf82c8c3 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 @@ public class Main {
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() {