From d57d454a11ac6f49eaa397ec14d6231e3a2727b7 Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Wed, 14 Oct 2015 10:55:30 -0700 Subject: Allocate dex cache arrays in their class loader's linear alloc Fixes memory leak for class unloading where the dex cache arrays used to be in the runtime linear alloc which never got freed. TODO: Some of the callers like the compiler just use the runtime linear alloc. We could clean this up if we want to have class unloading during compilation for some reason. Added regression test. Bug: 22720414 Change-Id: Ia50333a06a339efbdaedb5ad94b7a1ae841124ec --- compiler/driver/compiler_driver.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'compiler/driver/compiler_driver.cc') diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc index 74f19a1029..8324bf30d6 100644 --- a/compiler/driver/compiler_driver.cc +++ b/compiler/driver/compiler_driver.cc @@ -953,7 +953,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 dex_cache(hs2.NewHandle(class_linker->RegisterDexFile(*dex_file))); + Handle dex_cache(hs2.NewHandle(class_linker->RegisterDexFile( + *dex_file, + Runtime::Current()->GetLinearAlloc()))); Handle klass(hs2.NewHandle( class_linker->ResolveType(*dex_file, exception_type_idx, dex_cache, NullHandle()))); @@ -2010,9 +2012,11 @@ class ResolveTypeVisitor : public CompilationVisitor { ClassLinker* class_linker = manager_->GetClassLinker(); const DexFile& dex_file = *manager_->GetDexFile(); StackHandleScope<2> hs(soa.Self()); - Handle dex_cache(hs.NewHandle(class_linker->RegisterDexFile(dex_file))); Handle class_loader( hs.NewHandle(soa.Decode(manager_->GetClassLoader()))); + Handle dex_cache(hs.NewHandle(class_linker->RegisterDexFile( + dex_file, + class_linker->GetOrCreateAllocatorForClassLoader(class_loader.Get())))); mirror::Class* klass = class_linker->ResolveType(dex_file, type_idx, dex_cache, class_loader); if (klass == nullptr) { -- cgit v1.2.3-59-g8ed1b