From 356412e2b7ba3fde164bc08a44fee0ddc19c54e1 Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Mon, 21 Sep 2015 09:07:37 -0700 Subject: Add one LinearAlloc per ClassLoader Also added freeing linear alloc and class table when the corresponding class loader is no longer reachable. Bug: 22720414 Change-Id: Icb32c3a4c865f240e147bc87ed080a6b1d8a5795 --- runtime/class_linker.h | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'runtime/class_linker.h') diff --git a/runtime/class_linker.h b/runtime/class_linker.h index fee706625b..f705330b14 100644 --- a/runtime/class_linker.h +++ b/runtime/class_linker.h @@ -403,9 +403,13 @@ class ClassLinker { SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_); - LengthPrefixedArray* AllocArtFieldArray(Thread* self, size_t length); + LengthPrefixedArray* AllocArtFieldArray(Thread* self, + LinearAlloc* allocator, + size_t length); - LengthPrefixedArray* AllocArtMethodArray(Thread* self, size_t length); + LengthPrefixedArray* AllocArtMethodArray(Thread* self, + LinearAlloc* allocator, + size_t length); mirror::PointerArray* AllocPointerArray(Thread* self, size_t length) SHARED_REQUIRES(Locks::mutator_lock_) @@ -546,17 +550,24 @@ class ClassLinker { // entries are roots, but potentially not image classes. void DropFindArrayClassCache() SHARED_REQUIRES(Locks::mutator_lock_); - private: - // The RemoveClearedLoaders version removes cleared weak global class loaders and frees their - // class tables. This version can only be called with reader access to the - // classlinker_classes_lock_ since it modifies the class_loaders_ list. - void VisitClassLoadersAndRemoveClearedLoaders(ClassLoaderVisitor* visitor) - REQUIRES(Locks::classlinker_classes_lock_) + // Clean up class loaders, this needs to happen after JNI weak globals are cleared. + void CleanupClassLoaders() + SHARED_REQUIRES(Locks::mutator_lock_) + REQUIRES(!Locks::classlinker_classes_lock_); + + static LinearAlloc* GetAllocatorForClassLoader(mirror::ClassLoader* class_loader) SHARED_REQUIRES(Locks::mutator_lock_); + + private: + struct ClassLoaderData { + jobject weak_root; // Weak root to enable class unloading. + ClassTable* class_table; + LinearAlloc* allocator; + }; + void VisitClassLoaders(ClassLoaderVisitor* visitor) const SHARED_REQUIRES(Locks::classlinker_classes_lock_, Locks::mutator_lock_); - void VisitClassesInternal(ClassVisitor* visitor) SHARED_REQUIRES(Locks::classlinker_classes_lock_, Locks::mutator_lock_); @@ -826,8 +837,8 @@ class ClassLinker { std::vector oat_files_ GUARDED_BY(dex_lock_); // This contains the class loaders which have class tables. It is populated by - // InsertClassTableForClassLoader. Weak roots to enable class unloading. - std::list class_loaders_ + // InsertClassTableForClassLoader. + std::list class_loaders_ GUARDED_BY(Locks::classlinker_classes_lock_); // Boot class path table. Since the class loader for this is null. -- cgit v1.2.3-59-g8ed1b