diff options
author | 2016-04-05 14:36:57 -0700 | |
---|---|---|
committer | 2016-04-05 16:10:55 -0700 | |
commit | 1609e3a42051769f4a8be3b6731e7bb2f828b3bb (patch) | |
tree | 62f33befd42f6109931e003742fe3ab03ff3c74b /runtime/class_table.h | |
parent | 657887ebcd26cf0eae7c40d8ea35bd33186903e7 (diff) |
Shard classloader classes lock
Used to guard adding and removing classes.
Previously we used the class linker classes lock, but this had
a deadlock issue since the reference processor may need to acquire
the lock to mark the classes of a class loader. Another thread could
be blocked trying to access weak globals while also holding the
class linker classes lock.
Bug: 27946564
Change-Id: If7c13e8775f0912e104d1382eacdba7e7edf6818
Diffstat (limited to 'runtime/class_table.h')
-rw-r--r-- | runtime/class_table.h | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/runtime/class_table.h b/runtime/class_table.h index 0e0e860b4f..eb784b5c71 100644 --- a/runtime/class_table.h +++ b/runtime/class_table.h @@ -71,87 +71,96 @@ class ClassTable { // Used by image writer for checking. bool Contains(mirror::Class* klass) - REQUIRES(Locks::classlinker_classes_lock_) + REQUIRES(!lock_) SHARED_REQUIRES(Locks::mutator_lock_); // Freeze the current class tables by allocating a new table and never updating or modifying the // existing table. This helps prevents dirty pages after caused by inserting after zygote fork. void FreezeSnapshot() - REQUIRES(Locks::classlinker_classes_lock_) + REQUIRES(!lock_) SHARED_REQUIRES(Locks::mutator_lock_); // Returns the number of classes in previous snapshots. - size_t NumZygoteClasses() const SHARED_REQUIRES(Locks::classlinker_classes_lock_); + size_t NumZygoteClasses() const REQUIRES(!lock_); // Returns all off the classes in the lastest snapshot. - size_t NumNonZygoteClasses() const SHARED_REQUIRES(Locks::classlinker_classes_lock_); + size_t NumNonZygoteClasses() const REQUIRES(!lock_); // Update a class in the table with the new class. Returns the existing class which was replaced. mirror::Class* UpdateClass(const char* descriptor, mirror::Class* new_klass, size_t hash) - REQUIRES(Locks::classlinker_classes_lock_) + REQUIRES(!lock_) SHARED_REQUIRES(Locks::mutator_lock_); // NO_THREAD_SAFETY_ANALYSIS for object marking requiring heap bitmap lock. template<class Visitor> void VisitRoots(Visitor& visitor) NO_THREAD_SAFETY_ANALYSIS - SHARED_REQUIRES(Locks::classlinker_classes_lock_, Locks::mutator_lock_); + REQUIRES(!lock_) + SHARED_REQUIRES(Locks::mutator_lock_); + template<class Visitor> void VisitRoots(const Visitor& visitor) NO_THREAD_SAFETY_ANALYSIS - SHARED_REQUIRES(Locks::classlinker_classes_lock_, Locks::mutator_lock_); + REQUIRES(!lock_) + SHARED_REQUIRES(Locks::mutator_lock_); // Stops visit if the visitor returns false. template <typename Visitor> bool Visit(Visitor& visitor) - SHARED_REQUIRES(Locks::classlinker_classes_lock_, Locks::mutator_lock_); + REQUIRES(!lock_) + SHARED_REQUIRES(Locks::mutator_lock_); // Return the first class that matches the descriptor. Returns null if there are none. mirror::Class* Lookup(const char* descriptor, size_t hash) - SHARED_REQUIRES(Locks::classlinker_classes_lock_, Locks::mutator_lock_); + REQUIRES(!lock_) + SHARED_REQUIRES(Locks::mutator_lock_); // Return the first class that matches the descriptor of klass. Returns null if there are none. mirror::Class* LookupByDescriptor(mirror::Class* klass) - SHARED_REQUIRES(Locks::classlinker_classes_lock_, Locks::mutator_lock_); + REQUIRES(!lock_) + SHARED_REQUIRES(Locks::mutator_lock_); void Insert(mirror::Class* klass) - REQUIRES(Locks::classlinker_classes_lock_) + REQUIRES(!lock_) SHARED_REQUIRES(Locks::mutator_lock_); + void InsertWithHash(mirror::Class* klass, size_t hash) - REQUIRES(Locks::classlinker_classes_lock_) + REQUIRES(!lock_) SHARED_REQUIRES(Locks::mutator_lock_); // Returns true if the class was found and removed, false otherwise. bool Remove(const char* descriptor) - REQUIRES(Locks::classlinker_classes_lock_) + REQUIRES(!lock_) SHARED_REQUIRES(Locks::mutator_lock_); // Return true if we inserted the dex file, false if it already exists. bool InsertDexFile(mirror::Object* dex_file) - REQUIRES(Locks::classlinker_classes_lock_) + REQUIRES(!lock_) SHARED_REQUIRES(Locks::mutator_lock_); // Combines all of the tables into one class set. size_t WriteToMemory(uint8_t* ptr) const - SHARED_REQUIRES(Locks::classlinker_classes_lock_, Locks::mutator_lock_); + REQUIRES(!lock_) + SHARED_REQUIRES(Locks::mutator_lock_); // Read a table from ptr and put it at the front of the class set. size_t ReadFromMemory(uint8_t* ptr) - REQUIRES(Locks::classlinker_classes_lock_) + REQUIRES(!lock_) SHARED_REQUIRES(Locks::mutator_lock_); // Add a class set to the front of classes. void AddClassSet(ClassSet&& set) - REQUIRES(Locks::classlinker_classes_lock_) + REQUIRES(!lock_) SHARED_REQUIRES(Locks::mutator_lock_); private: - // TODO: shard lock to have one per class loader. + // Lock to guard inserting and removing. + 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(Locks::classlinker_classes_lock_); + std::vector<ClassSet> classes_ 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(Locks::classlinker_classes_lock_); + std::vector<GcRoot<mirror::Object>> dex_files_ GUARDED_BY(lock_); }; } // namespace art |