summaryrefslogtreecommitdiff
path: root/runtime/native/dalvik_system_DexFile.cc
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2017-02-03 11:47:34 +0000
committer Vladimir Marko <vmarko@google.com> 2017-02-09 10:10:29 +0000
commitcd556b003adbb53739d4b3f43135e6a0ae69509a (patch)
treea30c9f03071d87e1f75a0d0b8c2961d113ea767d /runtime/native/dalvik_system_DexFile.cc
parent357dcb73934356239292c46d6fbedba734da5e00 (diff)
Fix dex cache resolved types and class table mismatch.
Record class table in ClassLinker::DexCacheData and use it in DexCache.setResolvedType() to store the type also in the initiating loader's class table if the dex file has been registered. Also throw InternalError when trying to register the same DexFile with multiple class loaders. (Different DexFile instances referencing the same file are OK.) Test: 155-java-set-resolved-type Test: m test-art-host Bug: 30627598 Bug: 34193123 Bug: 34839984 Change-Id: Ia48acb300337c45880ea1459d2d32789546d67f4
Diffstat (limited to 'runtime/native/dalvik_system_DexFile.cc')
-rw-r--r--runtime/native/dalvik_system_DexFile.cc12
1 files changed, 9 insertions, 3 deletions
diff --git a/runtime/native/dalvik_system_DexFile.cc b/runtime/native/dalvik_system_DexFile.cc
index cd0e55f261..1234933db9 100644
--- a/runtime/native/dalvik_system_DexFile.cc
+++ b/runtime/native/dalvik_system_DexFile.cc
@@ -188,7 +188,7 @@ static jobject DexFile_openDexFileNative(JNIEnv* env,
if (array == nullptr) {
ScopedObjectAccess soa(env);
for (auto& dex_file : dex_files) {
- if (linker->FindDexCache(soa.Self(), *dex_file, true) != nullptr) {
+ if (linker->IsDexFileRegistered(soa.Self(), *dex_file)) {
dex_file.release();
}
}
@@ -230,7 +230,7 @@ static jboolean DexFile_closeDexFile(JNIEnv* env, jclass, jobject cookie) {
if (dex_file != nullptr) {
// Only delete the dex file if the dex cache is not found to prevent runtime crashes if there
// are calls to DexFile.close while the ART DexFile is still in use.
- if (class_linker->FindDexCache(soa.Self(), *dex_file, true) == nullptr) {
+ if (!class_linker->IsDexFileRegistered(soa.Self(), *dex_file)) {
// Clear the element in the array so that we can call close again.
long_dex_files->Set(i, 0);
delete dex_file;
@@ -281,7 +281,13 @@ static jclass DexFile_defineClassNative(JNIEnv* env,
StackHandleScope<1> hs(soa.Self());
Handle<mirror::ClassLoader> class_loader(
hs.NewHandle(soa.Decode<mirror::ClassLoader>(javaLoader)));
- class_linker->RegisterDexFile(*dex_file, class_loader.Get());
+ ObjPtr<mirror::DexCache> dex_cache =
+ class_linker->RegisterDexFile(*dex_file, class_loader.Get());
+ if (dex_cache == nullptr) {
+ // OOME or InternalError (dexFile already registered with a different class loader).
+ soa.Self()->AssertPendingException();
+ return nullptr;
+ }
ObjPtr<mirror::Class> result = class_linker->DefineClass(soa.Self(),
descriptor.c_str(),
hash,