summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Carlstrom <bdc@google.com>2016-06-04 00:46:17 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-06-04 00:46:17 +0000
commitd0b7ea3a8b4ce2fc03931dbc43a3c197dd20a279 (patch)
treed3e9d667bc7d746a0800e95d4ce78918718a9636
parent2659f2da1f40b761c690b6a25c5b4414d9999fb6 (diff)
parentf102faf1bcbdb2149e3e7bf27b1819f621b7894b (diff)
downloadandroid_art-d0b7ea3a8b4ce2fc03931dbc43a3c197dd20a279.tar.gz
android_art-d0b7ea3a8b4ce2fc03931dbc43a3c197dd20a279.tar.bz2
android_art-d0b7ea3a8b4ce2fc03931dbc43a3c197dd20a279.zip
Revert "Hold dex caches live in class table"
am: f102faf1bc * commit 'f102faf1bcbdb2149e3e7bf27b1819f621b7894b': Revert "Hold dex caches live in class table" Change-Id: I048421781af100212e6e8826c5dbbc5d8ca2877c
-rw-r--r--compiler/driver/compiler_driver-inl.h5
-rw-r--r--compiler/driver/compiler_driver.cc7
-rw-r--r--compiler/oat_test.cc7
-rw-r--r--dex2oat/dex2oat.cc3
-rw-r--r--oatdump/oatdump.cc5
-rw-r--r--runtime/class_linker.cc37
-rw-r--r--runtime/class_linker.h3
-rw-r--r--runtime/class_table-inl.h4
-rw-r--r--runtime/class_table.cc10
-rw-r--r--runtime/class_table.h11
-rw-r--r--runtime/native/dalvik_system_DexFile.cc4
-rw-r--r--runtime/native/dalvik_system_VMRuntime.cc3
12 files changed, 48 insertions, 51 deletions
diff --git a/compiler/driver/compiler_driver-inl.h b/compiler/driver/compiler_driver-inl.h
index 94f5acc2b6..3cb63e7082 100644
--- a/compiler/driver/compiler_driver-inl.h
+++ b/compiler/driver/compiler_driver-inl.h
@@ -390,8 +390,9 @@ inline int CompilerDriver::IsFastInvoke(
*devirt_target->dex_file, devirt_target->dex_method_index, dex_cache, class_loader,
nullptr, kVirtual);
} else {
- auto target_dex_cache(hs.NewHandle(class_linker->RegisterDexFile(*devirt_target->dex_file,
- class_loader.Get())));
+ auto target_dex_cache(hs.NewHandle(class_linker->RegisterDexFile(
+ *devirt_target->dex_file,
+ class_linker->GetOrCreateAllocatorForClassLoader(class_loader.Get()))));
called_method = class_linker->ResolveMethod<ClassLinker::kNoICCECheckForCache>(
*devirt_target->dex_file, devirt_target->dex_method_index, target_dex_cache,
class_loader, nullptr, kVirtual);
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index f88337ee6e..e366e071f5 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -1113,8 +1113,9 @@ void CompilerDriver::LoadImageClasses(TimingLogger* timings) {
uint16_t exception_type_idx = exception_type.first;
const DexFile* dex_file = exception_type.second;
StackHandleScope<2> hs2(self);
- Handle<mirror::DexCache> dex_cache(hs2.NewHandle(class_linker->RegisterDexFile(*dex_file,
- nullptr)));
+ Handle<mirror::DexCache> dex_cache(hs2.NewHandle(class_linker->RegisterDexFile(
+ *dex_file,
+ Runtime::Current()->GetLinearAlloc())));
Handle<mirror::Class> klass(hs2.NewHandle(
class_linker->ResolveType(*dex_file,
exception_type_idx,
@@ -2155,7 +2156,7 @@ class ResolveTypeVisitor : public CompilationVisitor {
hs.NewHandle(soa.Decode<mirror::ClassLoader*>(manager_->GetClassLoader())));
Handle<mirror::DexCache> dex_cache(hs.NewHandle(class_linker->RegisterDexFile(
dex_file,
- class_loader.Get())));
+ class_linker->GetOrCreateAllocatorForClassLoader(class_loader.Get()))));
mirror::Class* klass = class_linker->ResolveType(dex_file, type_idx, dex_cache, class_loader);
if (klass == nullptr) {
diff --git a/compiler/oat_test.cc b/compiler/oat_test.cc
index 6d1f94491e..21e198c12f 100644
--- a/compiler/oat_test.cc
+++ b/compiler/oat_test.cc
@@ -199,7 +199,7 @@ class OatTest : public CommonCompilerTest {
for (const std::unique_ptr<const DexFile>& dex_file : opened_dex_files) {
dex_files.push_back(dex_file.get());
ScopedObjectAccess soa(Thread::Current());
- class_linker->RegisterDexFile(*dex_file, nullptr);
+ class_linker->RegisterDexFile(*dex_file, runtime->GetLinearAlloc());
}
linker::MultiOatRelativePatcher patcher(compiler_driver_->GetInstructionSet(),
instruction_set_features_.get());
@@ -491,7 +491,10 @@ TEST_F(OatTest, EmptyTextSection) {
ClassLinker* const class_linker = Runtime::Current()->GetClassLinker();
for (const DexFile* dex_file : dex_files) {
ScopedObjectAccess soa(Thread::Current());
- class_linker->RegisterDexFile(*dex_file, soa.Decode<mirror::ClassLoader*>(class_loader));
+ class_linker->RegisterDexFile(
+ *dex_file,
+ class_linker->GetOrCreateAllocatorForClassLoader(
+ soa.Decode<mirror::ClassLoader*>(class_loader)));
}
compiler_driver_->SetDexFilesForOatFile(dex_files);
compiler_driver_->CompileAll(class_loader, dex_files, &timings);
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index c4754ce420..cce83f32b5 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -1462,8 +1462,7 @@ class Dex2Oat FINAL {
for (const auto& dex_file : dex_files_) {
ScopedObjectAccess soa(self);
dex_caches_.push_back(soa.AddLocalReference<jobject>(
- class_linker->RegisterDexFile(*dex_file,
- soa.Decode<mirror::ClassLoader*>(class_loader_))));
+ class_linker->RegisterDexFile(*dex_file, Runtime::Current()->GetLinearAlloc())));
}
return true;
diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc
index aa4635d6a4..f5458c067d 100644
--- a/oatdump/oatdump.cc
+++ b/oatdump/oatdump.cc
@@ -1118,7 +1118,8 @@ class OatDumper {
ScopedObjectAccess soa(Thread::Current());
Runtime* const runtime = Runtime::Current();
Handle<mirror::DexCache> dex_cache(
- hs->NewHandle(runtime->GetClassLinker()->RegisterDexFile(*dex_file, nullptr)));
+ hs->NewHandle(runtime->GetClassLinker()->RegisterDexFile(*dex_file,
+ runtime->GetLinearAlloc())));
DCHECK(options_.class_loader_ != nullptr);
return verifier::MethodVerifier::VerifyMethodAndDump(
soa.Self(), vios, dex_method_idx, dex_file, dex_cache, *options_.class_loader_,
@@ -2282,7 +2283,7 @@ static int DumpOatWithRuntime(Runtime* runtime, OatFile* oat_file, OatDumperOpti
std::string error_msg;
const DexFile* const dex_file = OpenDexFile(odf, &error_msg);
CHECK(dex_file != nullptr) << error_msg;
- class_linker->RegisterDexFile(*dex_file, nullptr);
+ class_linker->RegisterDexFile(*dex_file, runtime->GetLinearAlloc());
class_path.push_back(dex_file);
}
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index abc51ca175..b369e10b41 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -2468,7 +2468,9 @@ mirror::Class* ClassLinker::DefineClass(Thread* self,
self->AssertPendingOOMException();
return nullptr;
}
- mirror::DexCache* dex_cache = RegisterDexFile(dex_file, class_loader.Get());
+ mirror::DexCache* dex_cache = RegisterDexFile(
+ dex_file,
+ GetOrCreateAllocatorForClassLoader(class_loader.Get()));
if (dex_cache == nullptr) {
self->AssertPendingOOMException();
return nullptr;
@@ -3227,8 +3229,7 @@ void ClassLinker::RegisterDexFileLocked(const DexFile& dex_file,
dex_caches_.push_back(data);
}
-mirror::DexCache* ClassLinker::RegisterDexFile(const DexFile& dex_file,
- mirror::ClassLoader* class_loader) {
+mirror::DexCache* ClassLinker::RegisterDexFile(const DexFile& dex_file, LinearAlloc* linear_alloc) {
Thread* self = Thread::Current();
{
ReaderMutexLock mu(self, dex_lock_);
@@ -3237,31 +3238,21 @@ mirror::DexCache* ClassLinker::RegisterDexFile(const DexFile& dex_file,
return dex_cache;
}
}
- LinearAlloc* const linear_alloc = GetOrCreateAllocatorForClassLoader(class_loader);
- DCHECK(linear_alloc != nullptr);
- ClassTable* table;
- {
- WriterMutexLock mu(self, *Locks::classlinker_classes_lock_);
- table = InsertClassTableForClassLoader(class_loader);
- }
// Don't alloc while holding the lock, since allocation may need to
// suspend all threads and another thread may need the dex_lock_ to
// get to a suspend point.
StackHandleScope<1> hs(self);
Handle<mirror::DexCache> h_dex_cache(hs.NewHandle(AllocDexCache(self, dex_file, linear_alloc)));
- {
- WriterMutexLock mu(self, dex_lock_);
- mirror::DexCache* dex_cache = FindDexCacheLocked(self, dex_file, true);
- if (dex_cache != nullptr) {
- return dex_cache;
- }
- if (h_dex_cache.Get() == nullptr) {
- self->AssertPendingOOMException();
- return nullptr;
- }
- RegisterDexFileLocked(dex_file, h_dex_cache);
+ WriterMutexLock mu(self, dex_lock_);
+ mirror::DexCache* dex_cache = FindDexCacheLocked(self, dex_file, true);
+ if (dex_cache != nullptr) {
+ return dex_cache;
+ }
+ if (h_dex_cache.Get() == nullptr) {
+ self->AssertPendingOOMException();
+ return nullptr;
}
- table->InsertStrongRoot(h_dex_cache.Get());
+ RegisterDexFileLocked(dex_file, h_dex_cache);
return h_dex_cache.Get();
}
@@ -7998,7 +7989,7 @@ void ClassLinker::InsertDexFileInToClassLoader(mirror::Object* dex_file,
WriterMutexLock mu(self, *Locks::classlinker_classes_lock_);
ClassTable* const table = ClassTableForClassLoader(class_loader);
DCHECK(table != nullptr);
- if (table->InsertStrongRoot(dex_file) && class_loader != nullptr) {
+ if (table->InsertDexFile(dex_file) && class_loader != nullptr) {
// It was not already inserted, perform the write barrier to let the GC know the class loader's
// class table was modified.
Runtime::Current()->GetHeap()->WriteBarrierEveryFieldOf(class_loader);
diff --git a/runtime/class_linker.h b/runtime/class_linker.h
index ec98649ac4..9b5ca0eeab 100644
--- a/runtime/class_linker.h
+++ b/runtime/class_linker.h
@@ -377,8 +377,7 @@ class ClassLinker {
SHARED_REQUIRES(Locks::mutator_lock_)
REQUIRES(!dex_lock_, !Roles::uninterruptible_);
- mirror::DexCache* RegisterDexFile(const DexFile& dex_file,
- mirror::ClassLoader* class_loader)
+ mirror::DexCache* RegisterDexFile(const DexFile& dex_file, LinearAlloc* linear_alloc)
REQUIRES(!dex_lock_)
SHARED_REQUIRES(Locks::mutator_lock_);
void RegisterDexFile(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache)
diff --git a/runtime/class_table-inl.h b/runtime/class_table-inl.h
index d52365df6d..42e320ae71 100644
--- a/runtime/class_table-inl.h
+++ b/runtime/class_table-inl.h
@@ -29,7 +29,7 @@ void ClassTable::VisitRoots(Visitor& visitor) {
visitor.VisitRoot(root.AddressWithoutBarrier());
}
}
- for (GcRoot<mirror::Object>& root : strong_roots_) {
+ for (GcRoot<mirror::Object>& root : dex_files_) {
visitor.VisitRoot(root.AddressWithoutBarrier());
}
}
@@ -42,7 +42,7 @@ void ClassTable::VisitRoots(const Visitor& visitor) {
visitor.VisitRoot(root.AddressWithoutBarrier());
}
}
- for (GcRoot<mirror::Object>& root : strong_roots_) {
+ for (GcRoot<mirror::Object>& root : dex_files_) {
visitor.VisitRoot(root.AddressWithoutBarrier());
}
}
diff --git a/runtime/class_table.cc b/runtime/class_table.cc
index f5ebcc5191..8267c68b29 100644
--- a/runtime/class_table.cc
+++ b/runtime/class_table.cc
@@ -146,15 +146,15 @@ uint32_t ClassTable::ClassDescriptorHashEquals::operator()(const char* descripto
return ComputeModifiedUtf8Hash(descriptor);
}
-bool ClassTable::InsertStrongRoot(mirror::Object* obj) {
+bool ClassTable::InsertDexFile(mirror::Object* dex_file) {
WriterMutexLock mu(Thread::Current(), lock_);
- DCHECK(obj != nullptr);
- for (GcRoot<mirror::Object>& root : strong_roots_) {
- if (root.Read() == obj) {
+ DCHECK(dex_file != nullptr);
+ for (GcRoot<mirror::Object>& root : dex_files_) {
+ if (root.Read() == dex_file) {
return false;
}
}
- strong_roots_.push_back(GcRoot<mirror::Object>(obj));
+ dex_files_.push_back(GcRoot<mirror::Object>(dex_file));
return true;
}
diff --git a/runtime/class_table.h b/runtime/class_table.h
index 854a85e816..686381d35c 100644
--- a/runtime/class_table.h
+++ b/runtime/class_table.h
@@ -133,8 +133,8 @@ class ClassTable {
REQUIRES(!lock_)
SHARED_REQUIRES(Locks::mutator_lock_);
- // Return true if we inserted the strong root, false if it already exists.
- bool InsertStrongRoot(mirror::Object* obj)
+ // Return true if we inserted the dex file, false if it already exists.
+ bool InsertDexFile(mirror::Object* dex_file)
REQUIRES(!lock_)
SHARED_REQUIRES(Locks::mutator_lock_);
@@ -162,10 +162,9 @@ class ClassTable {
mutable ReaderWriterMutex lock_;
// We have a vector to help prevent dirty pages after the zygote forks by calling FreezeSnapshot.
std::vector<ClassSet> classes_ GUARDED_BY(lock_);
- // Extra strong roots that can be either dex files or dex caches. Dex files used by the class
- // loader which may not be owned by the class loader must be held strongly live. Also dex caches
- // are held live to prevent them being unloading once they have classes in them.
- std::vector<GcRoot<mirror::Object>> strong_roots_ GUARDED_BY(lock_);
+ // Dex files used by the class loader which may not be owned by the class loader. We keep these
+ // live so that we do not have issues closing any of the dex files.
+ std::vector<GcRoot<mirror::Object>> dex_files_ GUARDED_BY(lock_);
};
} // namespace art
diff --git a/runtime/native/dalvik_system_DexFile.cc b/runtime/native/dalvik_system_DexFile.cc
index 8c7c966102..f30f7a641e 100644
--- a/runtime/native/dalvik_system_DexFile.cc
+++ b/runtime/native/dalvik_system_DexFile.cc
@@ -278,7 +278,9 @@ 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());
+ class_linker->RegisterDexFile(
+ *dex_file,
+ class_linker->GetOrCreateAllocatorForClassLoader(class_loader.Get()));
mirror::Class* result = class_linker->DefineClass(soa.Self(),
descriptor.c_str(),
hash,
diff --git a/runtime/native/dalvik_system_VMRuntime.cc b/runtime/native/dalvik_system_VMRuntime.cc
index 759d6fa333..56c0d58e69 100644
--- a/runtime/native/dalvik_system_VMRuntime.cc
+++ b/runtime/native/dalvik_system_VMRuntime.cc
@@ -504,7 +504,8 @@ static void VMRuntime_preloadDexCaches(JNIEnv* env, jobject) {
const DexFile* dex_file = boot_class_path[i];
CHECK(dex_file != nullptr);
StackHandleScope<1> hs(soa.Self());
- Handle<mirror::DexCache> dex_cache(hs.NewHandle(linker->RegisterDexFile(*dex_file, nullptr)));
+ Handle<mirror::DexCache> dex_cache(
+ hs.NewHandle(linker->RegisterDexFile(*dex_file, runtime->GetLinearAlloc())));
if (kPreloadDexCachesStrings) {
for (size_t j = 0; j < dex_cache->NumStrings(); j++) {