Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "class_table.h" |
| 18 | |
| 19 | #include "mirror/class-inl.h" |
Andreas Gampe | c15a2f4 | 2017-04-21 12:09:39 -0700 | [diff] [blame^] | 20 | #include "oat_file.h" |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 21 | |
| 22 | namespace art { |
| 23 | |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 24 | ClassTable::ClassTable() : lock_("Class loader classes", kClassLoaderClassesLock) { |
Mathieu Chartier | 32cc9ee | 2015-10-15 09:19:15 -0700 | [diff] [blame] | 25 | Runtime* const runtime = Runtime::Current(); |
| 26 | classes_.push_back(ClassSet(runtime->GetHashTableMinLoadFactor(), |
| 27 | runtime->GetHashTableMaxLoadFactor())); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | void ClassTable::FreezeSnapshot() { |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 31 | WriterMutexLock mu(Thread::Current(), lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 32 | classes_.push_back(ClassSet()); |
| 33 | } |
| 34 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 35 | bool ClassTable::Contains(ObjPtr<mirror::Class> klass) { |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 36 | ReaderMutexLock mu(Thread::Current(), lock_); |
Mathieu Chartier | db70ce5 | 2016-12-12 11:06:59 -0800 | [diff] [blame] | 37 | TableSlot slot(klass); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 38 | for (ClassSet& class_set : classes_) { |
Mathieu Chartier | db70ce5 | 2016-12-12 11:06:59 -0800 | [diff] [blame] | 39 | auto it = class_set.Find(slot); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 40 | if (it != class_set.end()) { |
| 41 | return it->Read() == klass; |
| 42 | } |
| 43 | } |
| 44 | return false; |
| 45 | } |
| 46 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 47 | mirror::Class* ClassTable::LookupByDescriptor(ObjPtr<mirror::Class> klass) { |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 48 | ReaderMutexLock mu(Thread::Current(), lock_); |
Mathieu Chartier | db70ce5 | 2016-12-12 11:06:59 -0800 | [diff] [blame] | 49 | TableSlot slot(klass); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 50 | for (ClassSet& class_set : classes_) { |
Mathieu Chartier | db70ce5 | 2016-12-12 11:06:59 -0800 | [diff] [blame] | 51 | auto it = class_set.Find(slot); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 52 | if (it != class_set.end()) { |
| 53 | return it->Read(); |
| 54 | } |
| 55 | } |
| 56 | return nullptr; |
| 57 | } |
| 58 | |
Jayant Chowdhary | 8de1297 | 2017-02-28 10:54:20 -0800 | [diff] [blame] | 59 | // To take into account http://b/35845221 |
| 60 | #pragma clang diagnostic push |
| 61 | #if __clang_major__ < 4 |
| 62 | #pragma clang diagnostic ignored "-Wunreachable-code" |
| 63 | #endif |
| 64 | |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 65 | mirror::Class* ClassTable::UpdateClass(const char* descriptor, mirror::Class* klass, size_t hash) { |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 66 | WriterMutexLock mu(Thread::Current(), lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 67 | // Should only be updating latest table. |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 68 | DescriptorHashPair pair(descriptor, hash); |
| 69 | auto existing_it = classes_.back().FindWithHash(pair, hash); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 70 | if (kIsDebugBuild && existing_it == classes_.back().end()) { |
| 71 | for (const ClassSet& class_set : classes_) { |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 72 | if (class_set.FindWithHash(pair, hash) != class_set.end()) { |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 73 | LOG(FATAL) << "Updating class found in frozen table " << descriptor; |
| 74 | } |
| 75 | } |
| 76 | LOG(FATAL) << "Updating class not found " << descriptor; |
| 77 | } |
| 78 | mirror::Class* const existing = existing_it->Read(); |
| 79 | CHECK_NE(existing, klass) << descriptor; |
| 80 | CHECK(!existing->IsResolved()) << descriptor; |
| 81 | CHECK_EQ(klass->GetStatus(), mirror::Class::kStatusResolving) << descriptor; |
| 82 | CHECK(!klass->IsTemp()) << descriptor; |
| 83 | VerifyObject(klass); |
| 84 | // Update the element in the hash set with the new class. This is safe to do since the descriptor |
| 85 | // doesn't change. |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 86 | *existing_it = TableSlot(klass, hash); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 87 | return existing; |
| 88 | } |
| 89 | |
Jayant Chowdhary | 8de1297 | 2017-02-28 10:54:20 -0800 | [diff] [blame] | 90 | #pragma clang diagnostic pop |
| 91 | |
Vladimir Marko | c5798bf | 2016-12-09 10:20:54 +0000 | [diff] [blame] | 92 | size_t ClassTable::CountDefiningLoaderClasses(ObjPtr<mirror::ClassLoader> defining_loader, |
| 93 | const ClassSet& set) const { |
| 94 | size_t count = 0; |
| 95 | for (const TableSlot& root : set) { |
| 96 | if (root.Read()->GetClassLoader() == defining_loader) { |
| 97 | ++count; |
| 98 | } |
| 99 | } |
| 100 | return count; |
| 101 | } |
| 102 | |
| 103 | size_t ClassTable::NumZygoteClasses(ObjPtr<mirror::ClassLoader> defining_loader) const { |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 104 | ReaderMutexLock mu(Thread::Current(), lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 105 | size_t sum = 0; |
| 106 | for (size_t i = 0; i < classes_.size() - 1; ++i) { |
Vladimir Marko | c5798bf | 2016-12-09 10:20:54 +0000 | [diff] [blame] | 107 | sum += CountDefiningLoaderClasses(defining_loader, classes_[i]); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 108 | } |
| 109 | return sum; |
| 110 | } |
| 111 | |
Vladimir Marko | c5798bf | 2016-12-09 10:20:54 +0000 | [diff] [blame] | 112 | size_t ClassTable::NumNonZygoteClasses(ObjPtr<mirror::ClassLoader> defining_loader) const { |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 113 | ReaderMutexLock mu(Thread::Current(), lock_); |
Vladimir Marko | c5798bf | 2016-12-09 10:20:54 +0000 | [diff] [blame] | 114 | return CountDefiningLoaderClasses(defining_loader, classes_.back()); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 117 | size_t ClassTable::NumReferencedZygoteClasses() const { |
| 118 | ReaderMutexLock mu(Thread::Current(), lock_); |
| 119 | size_t sum = 0; |
| 120 | for (size_t i = 0; i < classes_.size() - 1; ++i) { |
| 121 | sum += classes_[i].Size(); |
| 122 | } |
| 123 | return sum; |
| 124 | } |
| 125 | |
| 126 | size_t ClassTable::NumReferencedNonZygoteClasses() const { |
| 127 | ReaderMutexLock mu(Thread::Current(), lock_); |
| 128 | return classes_.back().Size(); |
| 129 | } |
| 130 | |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 131 | mirror::Class* ClassTable::Lookup(const char* descriptor, size_t hash) { |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 132 | DescriptorHashPair pair(descriptor, hash); |
Mathieu Chartier | db70ce5 | 2016-12-12 11:06:59 -0800 | [diff] [blame] | 133 | ReaderMutexLock mu(Thread::Current(), lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 134 | for (ClassSet& class_set : classes_) { |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 135 | auto it = class_set.FindWithHash(pair, hash); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 136 | if (it != class_set.end()) { |
Vladimir Marko | c5798bf | 2016-12-09 10:20:54 +0000 | [diff] [blame] | 137 | return it->Read(); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | return nullptr; |
| 141 | } |
| 142 | |
Vladimir Marko | cd556b0 | 2017-02-03 11:47:34 +0000 | [diff] [blame] | 143 | ObjPtr<mirror::Class> ClassTable::TryInsert(ObjPtr<mirror::Class> klass) { |
| 144 | TableSlot slot(klass); |
| 145 | WriterMutexLock mu(Thread::Current(), lock_); |
| 146 | for (ClassSet& class_set : classes_) { |
| 147 | auto it = class_set.Find(slot); |
| 148 | if (it != class_set.end()) { |
| 149 | return it->Read(); |
| 150 | } |
| 151 | } |
| 152 | classes_.back().Insert(slot); |
| 153 | return klass; |
| 154 | } |
| 155 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 156 | void ClassTable::Insert(ObjPtr<mirror::Class> klass) { |
Mathieu Chartier | db70ce5 | 2016-12-12 11:06:59 -0800 | [diff] [blame] | 157 | const uint32_t hash = TableSlot::HashDescriptor(klass); |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 158 | WriterMutexLock mu(Thread::Current(), lock_); |
Mathieu Chartier | db70ce5 | 2016-12-12 11:06:59 -0800 | [diff] [blame] | 159 | classes_.back().InsertWithHash(TableSlot(klass, hash), hash); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Vladimir Marko | 6ad2f6d | 2017-01-18 15:22:59 +0000 | [diff] [blame] | 162 | void ClassTable::CopyWithoutLocks(const ClassTable& source_table) { |
| 163 | if (kIsDebugBuild) { |
| 164 | for (ClassSet& class_set : classes_) { |
| 165 | CHECK(class_set.Empty()); |
| 166 | } |
| 167 | } |
| 168 | for (const ClassSet& class_set : source_table.classes_) { |
| 169 | for (const TableSlot& slot : class_set) { |
| 170 | classes_.back().Insert(slot); |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 175 | void ClassTable::InsertWithoutLocks(ObjPtr<mirror::Class> klass) { |
Mathieu Chartier | db70ce5 | 2016-12-12 11:06:59 -0800 | [diff] [blame] | 176 | const uint32_t hash = TableSlot::HashDescriptor(klass); |
| 177 | classes_.back().InsertWithHash(TableSlot(klass, hash), hash); |
Mathieu Chartier | 496577f | 2016-09-20 15:33:31 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 180 | void ClassTable::InsertWithHash(ObjPtr<mirror::Class> klass, size_t hash) { |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 181 | WriterMutexLock mu(Thread::Current(), lock_); |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 182 | classes_.back().InsertWithHash(TableSlot(klass, hash), hash); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | bool ClassTable::Remove(const char* descriptor) { |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 186 | DescriptorHashPair pair(descriptor, ComputeModifiedUtf8Hash(descriptor)); |
Mathieu Chartier | db70ce5 | 2016-12-12 11:06:59 -0800 | [diff] [blame] | 187 | WriterMutexLock mu(Thread::Current(), lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 188 | for (ClassSet& class_set : classes_) { |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 189 | auto it = class_set.Find(pair); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 190 | if (it != class_set.end()) { |
| 191 | class_set.Erase(it); |
| 192 | return true; |
| 193 | } |
| 194 | } |
| 195 | return false; |
| 196 | } |
| 197 | |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 198 | uint32_t ClassTable::ClassDescriptorHashEquals::operator()(const TableSlot& slot) |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 199 | const { |
| 200 | std::string temp; |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 201 | return ComputeModifiedUtf8Hash(slot.Read()->GetDescriptor(&temp)); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 204 | bool ClassTable::ClassDescriptorHashEquals::operator()(const TableSlot& a, |
| 205 | const TableSlot& b) const { |
| 206 | if (a.Hash() != b.Hash()) { |
| 207 | std::string temp; |
| 208 | DCHECK(!a.Read()->DescriptorEquals(b.Read()->GetDescriptor(&temp))); |
| 209 | return false; |
| 210 | } |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 211 | std::string temp; |
| 212 | return a.Read()->DescriptorEquals(b.Read()->GetDescriptor(&temp)); |
| 213 | } |
| 214 | |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 215 | bool ClassTable::ClassDescriptorHashEquals::operator()(const TableSlot& a, |
| 216 | const DescriptorHashPair& b) const { |
| 217 | if (!a.MaskedHashEquals(b.second)) { |
| 218 | DCHECK(!a.Read()->DescriptorEquals(b.first)); |
| 219 | return false; |
| 220 | } |
| 221 | return a.Read()->DescriptorEquals(b.first); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 224 | uint32_t ClassTable::ClassDescriptorHashEquals::operator()(const DescriptorHashPair& pair) const { |
| 225 | return ComputeModifiedUtf8Hash(pair.first); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Mathieu Chartier | bc5a795 | 2016-10-17 15:46:31 -0700 | [diff] [blame] | 228 | bool ClassTable::InsertStrongRoot(ObjPtr<mirror::Object> obj) { |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 229 | WriterMutexLock mu(Thread::Current(), lock_); |
Mathieu Chartier | c9dbb1d | 2016-06-03 17:47:32 -0700 | [diff] [blame] | 230 | DCHECK(obj != nullptr); |
| 231 | for (GcRoot<mirror::Object>& root : strong_roots_) { |
| 232 | if (root.Read() == obj) { |
Mathieu Chartier | 00310e0 | 2015-10-17 12:46:42 -0700 | [diff] [blame] | 233 | return false; |
| 234 | } |
| 235 | } |
Mathieu Chartier | c9dbb1d | 2016-06-03 17:47:32 -0700 | [diff] [blame] | 236 | strong_roots_.push_back(GcRoot<mirror::Object>(obj)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 237 | // If `obj` is a dex cache associated with a new oat file with GC roots, add it to oat_files_. |
| 238 | if (obj->IsDexCache()) { |
Mathieu Chartier | bc5a795 | 2016-10-17 15:46:31 -0700 | [diff] [blame] | 239 | const DexFile* dex_file = ObjPtr<mirror::DexCache>::DownCast(obj)->GetDexFile(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 240 | if (dex_file != nullptr && dex_file->GetOatDexFile() != nullptr) { |
| 241 | const OatFile* oat_file = dex_file->GetOatDexFile()->GetOatFile(); |
Mathieu Chartier | 1b86849 | 2016-11-16 16:22:37 -0800 | [diff] [blame] | 242 | if (oat_file != nullptr && !oat_file->GetBssGcRoots().empty()) { |
Vladimir Marko | 1bc4b17 | 2016-10-24 16:53:39 +0000 | [diff] [blame] | 243 | InsertOatFileLocked(oat_file); // Ignore return value. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | } |
Mathieu Chartier | 00310e0 | 2015-10-17 12:46:42 -0700 | [diff] [blame] | 247 | return true; |
| 248 | } |
| 249 | |
Vladimir Marko | 1bc4b17 | 2016-10-24 16:53:39 +0000 | [diff] [blame] | 250 | bool ClassTable::InsertOatFile(const OatFile* oat_file) { |
| 251 | WriterMutexLock mu(Thread::Current(), lock_); |
| 252 | return InsertOatFileLocked(oat_file); |
| 253 | } |
| 254 | |
| 255 | bool ClassTable::InsertOatFileLocked(const OatFile* oat_file) { |
| 256 | if (ContainsElement(oat_files_, oat_file)) { |
| 257 | return false; |
| 258 | } |
| 259 | oat_files_.push_back(oat_file); |
| 260 | return true; |
| 261 | } |
| 262 | |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 263 | size_t ClassTable::WriteToMemory(uint8_t* ptr) const { |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 264 | ReaderMutexLock mu(Thread::Current(), lock_); |
Mathieu Chartier | 41dc8ce | 2015-12-04 15:07:48 -0800 | [diff] [blame] | 265 | ClassSet combined; |
| 266 | // Combine all the class sets in case there are multiple, also adjusts load factor back to |
| 267 | // default in case classes were pruned. |
| 268 | for (const ClassSet& class_set : classes_) { |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 269 | for (const TableSlot& root : class_set) { |
Mathieu Chartier | 41dc8ce | 2015-12-04 15:07:48 -0800 | [diff] [blame] | 270 | combined.Insert(root); |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 271 | } |
| 272 | } |
Mathieu Chartier | 41dc8ce | 2015-12-04 15:07:48 -0800 | [diff] [blame] | 273 | const size_t ret = combined.WriteToMemory(ptr); |
| 274 | // Sanity check. |
| 275 | if (kIsDebugBuild && ptr != nullptr) { |
| 276 | size_t read_count; |
| 277 | ClassSet class_set(ptr, /*make copy*/false, &read_count); |
| 278 | class_set.Verify(); |
| 279 | } |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 280 | return ret; |
| 281 | } |
| 282 | |
| 283 | size_t ClassTable::ReadFromMemory(uint8_t* ptr) { |
| 284 | size_t read_count = 0; |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 285 | AddClassSet(ClassSet(ptr, /*make copy*/false, &read_count)); |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 286 | return read_count; |
| 287 | } |
| 288 | |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 289 | void ClassTable::AddClassSet(ClassSet&& set) { |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 290 | WriterMutexLock mu(Thread::Current(), lock_); |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 291 | classes_.insert(classes_.begin(), std::move(set)); |
| 292 | } |
| 293 | |
Mathieu Chartier | c9dbb1d | 2016-06-03 17:47:32 -0700 | [diff] [blame] | 294 | void ClassTable::ClearStrongRoots() { |
| 295 | WriterMutexLock mu(Thread::Current(), lock_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 296 | oat_files_.clear(); |
Mathieu Chartier | c9dbb1d | 2016-06-03 17:47:32 -0700 | [diff] [blame] | 297 | strong_roots_.clear(); |
| 298 | } |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 299 | |
Mathieu Chartier | db70ce5 | 2016-12-12 11:06:59 -0800 | [diff] [blame] | 300 | ClassTable::TableSlot::TableSlot(ObjPtr<mirror::Class> klass) |
| 301 | : TableSlot(klass, HashDescriptor(klass)) {} |
| 302 | |
| 303 | uint32_t ClassTable::TableSlot::HashDescriptor(ObjPtr<mirror::Class> klass) { |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 304 | std::string temp; |
Mathieu Chartier | db70ce5 | 2016-12-12 11:06:59 -0800 | [diff] [blame] | 305 | return ComputeModifiedUtf8Hash(klass->GetDescriptor(&temp)); |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 306 | } |
| 307 | |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 308 | } // namespace art |