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