Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | */ |
Brian Carlstrom | 7e93b50 | 2011-08-04 14:16:22 -0700 | [diff] [blame] | 16 | |
| 17 | #include "intern_table.h" |
| 18 | |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 19 | #include <memory> |
| 20 | |
David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 21 | #include "dex/utf.h" |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 22 | #include "gc/collector/garbage_collector.h" |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 23 | #include "gc/space/image_space.h" |
Mathieu Chartier | 14c3bf9 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 24 | #include "gc/weak_root_state.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 25 | #include "gc_root-inl.h" |
Andreas Gampe | e15b9b1 | 2018-10-29 12:54:27 -0700 | [diff] [blame] | 26 | #include "handle_scope-inl.h" |
Mathieu Chartier | 4a26f17 | 2016-01-26 14:26:18 -0800 | [diff] [blame] | 27 | #include "image-inl.h" |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 28 | #include "mirror/dex_cache-inl.h" |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 29 | #include "mirror/object-inl.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 30 | #include "mirror/object_array-inl.h" |
Mathieu Chartier | cdfd39f | 2014-08-29 18:16:58 -0700 | [diff] [blame] | 31 | #include "mirror/string-inl.h" |
Andreas Gampe | 5d08fcc | 2017-06-05 17:56:46 -0700 | [diff] [blame] | 32 | #include "object_callbacks.h" |
Andreas Gampe | 508fdf3 | 2017-06-05 16:42:13 -0700 | [diff] [blame] | 33 | #include "scoped_thread_state_change-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 34 | #include "thread.h" |
Brian Carlstrom | 7e93b50 | 2011-08-04 14:16:22 -0700 | [diff] [blame] | 35 | |
| 36 | namespace art { |
| 37 | |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 38 | InternTable::InternTable() |
Vladimir Marko | 1a1de67 | 2016-10-13 12:53:15 +0100 | [diff] [blame] | 39 | : log_new_roots_(false), |
Mathieu Chartier | 14c3bf9 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 40 | weak_intern_condition_("New intern condition", *Locks::intern_table_lock_), |
| 41 | weak_root_state_(gc::kWeakRootStateNormal) { |
Mathieu Chartier | c11d9b8 | 2013-09-19 10:01:59 -0700 | [diff] [blame] | 42 | } |
Elliott Hughes | de69d7f | 2011-08-18 16:49:37 -0700 | [diff] [blame] | 43 | |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 44 | size_t InternTable::Size() const { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 45 | MutexLock mu(Thread::Current(), *Locks::intern_table_lock_); |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 46 | return strong_interns_.Size() + weak_interns_.Size(); |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Hiroshi Yamauchi | a91a4bc | 2014-06-13 16:44:55 -0700 | [diff] [blame] | 49 | size_t InternTable::StrongSize() const { |
| 50 | MutexLock mu(Thread::Current(), *Locks::intern_table_lock_); |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 51 | return strong_interns_.Size(); |
Hiroshi Yamauchi | a91a4bc | 2014-06-13 16:44:55 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | size_t InternTable::WeakSize() const { |
| 55 | MutexLock mu(Thread::Current(), *Locks::intern_table_lock_); |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 56 | return weak_interns_.Size(); |
Hiroshi Yamauchi | a91a4bc | 2014-06-13 16:44:55 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Elliott Hughes | cac6cc7 | 2011-11-03 20:31:21 -0700 | [diff] [blame] | 59 | void InternTable::DumpForSigQuit(std::ostream& os) const { |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 60 | os << "Intern table: " << StrongSize() << " strong; " << WeakSize() << " weak\n"; |
Elliott Hughes | cac6cc7 | 2011-11-03 20:31:21 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 63 | void InternTable::VisitRoots(RootVisitor* visitor, VisitRootFlags flags) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 64 | MutexLock mu(Thread::Current(), *Locks::intern_table_lock_); |
Mathieu Chartier | 893263b | 2014-03-04 11:07:42 -0800 | [diff] [blame] | 65 | if ((flags & kVisitRootFlagAllRoots) != 0) { |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 66 | strong_interns_.VisitRoots(visitor); |
Mathieu Chartier | 893263b | 2014-03-04 11:07:42 -0800 | [diff] [blame] | 67 | } else if ((flags & kVisitRootFlagNewRoots) != 0) { |
Mathieu Chartier | cdfd39f | 2014-08-29 18:16:58 -0700 | [diff] [blame] | 68 | for (auto& root : new_strong_intern_roots_) { |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 69 | ObjPtr<mirror::String> old_ref = root.Read<kWithoutReadBarrier>(); |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 70 | root.VisitRoot(visitor, RootInfo(kRootInternedString)); |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 71 | ObjPtr<mirror::String> new_ref = root.Read<kWithoutReadBarrier>(); |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 72 | if (new_ref != old_ref) { |
Mathieu Chartier | cdfd39f | 2014-08-29 18:16:58 -0700 | [diff] [blame] | 73 | // The GC moved a root in the log. Need to search the strong interns and update the |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 74 | // corresponding object. This is slow, but luckily for us, this may only happen with a |
| 75 | // concurrent moving GC. |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 76 | strong_interns_.Remove(old_ref); |
| 77 | strong_interns_.Insert(new_ref); |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 78 | } |
| 79 | } |
Mathieu Chartier | 893263b | 2014-03-04 11:07:42 -0800 | [diff] [blame] | 80 | } |
Mathieu Chartier | 893263b | 2014-03-04 11:07:42 -0800 | [diff] [blame] | 81 | if ((flags & kVisitRootFlagClearRootLog) != 0) { |
| 82 | new_strong_intern_roots_.clear(); |
| 83 | } |
| 84 | if ((flags & kVisitRootFlagStartLoggingNewRoots) != 0) { |
| 85 | log_new_roots_ = true; |
| 86 | } else if ((flags & kVisitRootFlagStopLoggingNewRoots) != 0) { |
| 87 | log_new_roots_ = false; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 88 | } |
Mathieu Chartier | 423d2a3 | 2013-09-12 17:33:56 -0700 | [diff] [blame] | 89 | // Note: we deliberately don't visit the weak_interns_ table and the immutable image roots. |
Brian Carlstrom | 7e93b50 | 2011-08-04 14:16:22 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 92 | ObjPtr<mirror::String> InternTable::LookupWeak(Thread* self, ObjPtr<mirror::String> s) { |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 93 | MutexLock mu(self, *Locks::intern_table_lock_); |
| 94 | return LookupWeakLocked(s); |
Mathieu Chartier | f7fd970 | 2015-11-09 11:16:49 -0800 | [diff] [blame] | 95 | } |
| 96 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 97 | ObjPtr<mirror::String> InternTable::LookupStrong(Thread* self, ObjPtr<mirror::String> s) { |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 98 | MutexLock mu(self, *Locks::intern_table_lock_); |
| 99 | return LookupStrongLocked(s); |
| 100 | } |
| 101 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 102 | ObjPtr<mirror::String> InternTable::LookupStrong(Thread* self, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 103 | uint32_t utf16_length, |
| 104 | const char* utf8_data) { |
| 105 | DCHECK_EQ(utf16_length, CountModifiedUtf8Chars(utf8_data)); |
| 106 | Utf8String string(utf16_length, |
| 107 | utf8_data, |
| 108 | ComputeUtf16HashFromModifiedUtf8(utf8_data, utf16_length)); |
| 109 | MutexLock mu(self, *Locks::intern_table_lock_); |
| 110 | return strong_interns_.Find(string); |
| 111 | } |
| 112 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 113 | ObjPtr<mirror::String> InternTable::LookupWeakLocked(ObjPtr<mirror::String> s) { |
Nicolas Geoffray | 1bc977c | 2016-01-23 14:15:49 +0000 | [diff] [blame] | 114 | return weak_interns_.Find(s); |
| 115 | } |
| 116 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 117 | ObjPtr<mirror::String> InternTable::LookupStrongLocked(ObjPtr<mirror::String> s) { |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 118 | return strong_interns_.Find(s); |
| 119 | } |
| 120 | |
Mathieu Chartier | ea0831f | 2015-12-29 13:17:37 -0800 | [diff] [blame] | 121 | void InternTable::AddNewTable() { |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 122 | MutexLock mu(Thread::Current(), *Locks::intern_table_lock_); |
Mathieu Chartier | ea0831f | 2015-12-29 13:17:37 -0800 | [diff] [blame] | 123 | weak_interns_.AddNewTable(); |
| 124 | strong_interns_.AddNewTable(); |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 127 | ObjPtr<mirror::String> InternTable::InsertStrong(ObjPtr<mirror::String> s) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 128 | Runtime* runtime = Runtime::Current(); |
| 129 | if (runtime->IsActiveTransaction()) { |
Mathieu Chartier | cdfd39f | 2014-08-29 18:16:58 -0700 | [diff] [blame] | 130 | runtime->RecordStrongStringInsertion(s); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 131 | } |
Mathieu Chartier | 893263b | 2014-03-04 11:07:42 -0800 | [diff] [blame] | 132 | if (log_new_roots_) { |
Mathieu Chartier | cdfd39f | 2014-08-29 18:16:58 -0700 | [diff] [blame] | 133 | new_strong_intern_roots_.push_back(GcRoot<mirror::String>(s)); |
Mathieu Chartier | 893263b | 2014-03-04 11:07:42 -0800 | [diff] [blame] | 134 | } |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 135 | strong_interns_.Insert(s); |
Mathieu Chartier | 893263b | 2014-03-04 11:07:42 -0800 | [diff] [blame] | 136 | return s; |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 137 | } |
| 138 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 139 | ObjPtr<mirror::String> InternTable::InsertWeak(ObjPtr<mirror::String> s) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 140 | Runtime* runtime = Runtime::Current(); |
| 141 | if (runtime->IsActiveTransaction()) { |
Mathieu Chartier | cdfd39f | 2014-08-29 18:16:58 -0700 | [diff] [blame] | 142 | runtime->RecordWeakStringInsertion(s); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 143 | } |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 144 | weak_interns_.Insert(s); |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 145 | return s; |
| 146 | } |
| 147 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 148 | void InternTable::RemoveStrong(ObjPtr<mirror::String> s) { |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 149 | strong_interns_.Remove(s); |
Hiroshi Yamauchi | 1bd4872 | 2014-05-23 19:58:15 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 152 | void InternTable::RemoveWeak(ObjPtr<mirror::String> s) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 153 | Runtime* runtime = Runtime::Current(); |
| 154 | if (runtime->IsActiveTransaction()) { |
Mathieu Chartier | cdfd39f | 2014-08-29 18:16:58 -0700 | [diff] [blame] | 155 | runtime->RecordWeakStringRemoval(s); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 156 | } |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 157 | weak_interns_.Remove(s); |
Brian Carlstrom | 7e93b50 | 2011-08-04 14:16:22 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 160 | // Insert/remove methods used to undo changes made during an aborted transaction. |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 161 | ObjPtr<mirror::String> InternTable::InsertStrongFromTransaction(ObjPtr<mirror::String> s) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 162 | DCHECK(!Runtime::Current()->IsActiveTransaction()); |
Mathieu Chartier | cdfd39f | 2014-08-29 18:16:58 -0700 | [diff] [blame] | 163 | return InsertStrong(s); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 164 | } |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 165 | |
| 166 | ObjPtr<mirror::String> InternTable::InsertWeakFromTransaction(ObjPtr<mirror::String> s) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 167 | DCHECK(!Runtime::Current()->IsActiveTransaction()); |
Mathieu Chartier | cdfd39f | 2014-08-29 18:16:58 -0700 | [diff] [blame] | 168 | return InsertWeak(s); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 169 | } |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 170 | |
| 171 | void InternTable::RemoveStrongFromTransaction(ObjPtr<mirror::String> s) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 172 | DCHECK(!Runtime::Current()->IsActiveTransaction()); |
Mathieu Chartier | cdfd39f | 2014-08-29 18:16:58 -0700 | [diff] [blame] | 173 | RemoveStrong(s); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 174 | } |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 175 | |
| 176 | void InternTable::RemoveWeakFromTransaction(ObjPtr<mirror::String> s) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 177 | DCHECK(!Runtime::Current()->IsActiveTransaction()); |
Mathieu Chartier | cdfd39f | 2014-08-29 18:16:58 -0700 | [diff] [blame] | 178 | RemoveWeak(s); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 179 | } |
| 180 | |
Hiroshi Yamauchi | 0b71357 | 2015-06-16 18:29:23 -0700 | [diff] [blame] | 181 | void InternTable::BroadcastForNewInterns() { |
Hiroshi Yamauchi | 0b71357 | 2015-06-16 18:29:23 -0700 | [diff] [blame] | 182 | Thread* self = Thread::Current(); |
| 183 | MutexLock mu(self, *Locks::intern_table_lock_); |
Mathieu Chartier | 14c3bf9 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 184 | weak_intern_condition_.Broadcast(self); |
Hiroshi Yamauchi | 0b71357 | 2015-06-16 18:29:23 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Mathieu Chartier | 14c3bf9 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 187 | void InternTable::WaitUntilAccessible(Thread* self) { |
| 188 | Locks::intern_table_lock_->ExclusiveUnlock(self); |
Mathieu Chartier | f1d666e | 2015-09-03 16:13:34 -0700 | [diff] [blame] | 189 | { |
| 190 | ScopedThreadSuspension sts(self, kWaitingWeakGcRootRead); |
| 191 | MutexLock mu(self, *Locks::intern_table_lock_); |
Hiroshi Yamauchi | 9e6f097 | 2016-11-03 13:03:20 -0700 | [diff] [blame] | 192 | while ((!kUseReadBarrier && weak_root_state_ == gc::kWeakRootStateNoReadsOrWrites) || |
| 193 | (kUseReadBarrier && !self->GetWeakRefAccessEnabled())) { |
Mathieu Chartier | f1d666e | 2015-09-03 16:13:34 -0700 | [diff] [blame] | 194 | weak_intern_condition_.Wait(self); |
| 195 | } |
Mathieu Chartier | 14c3bf9 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 196 | } |
Mathieu Chartier | 14c3bf9 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 197 | Locks::intern_table_lock_->ExclusiveLock(self); |
| 198 | } |
| 199 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 200 | ObjPtr<mirror::String> InternTable::Insert(ObjPtr<mirror::String> s, |
| 201 | bool is_strong, |
| 202 | bool holding_locks) { |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 203 | if (s == nullptr) { |
| 204 | return nullptr; |
| 205 | } |
Mathieu Chartier | 14c3bf9 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 206 | Thread* const self = Thread::Current(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 207 | MutexLock mu(self, *Locks::intern_table_lock_); |
Mathieu Chartier | 14c3bf9 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 208 | if (kDebugLocking && !holding_locks) { |
| 209 | Locks::mutator_lock_->AssertSharedHeld(self); |
| 210 | CHECK_EQ(2u, self->NumberOfHeldMutexes()) << "may only safely hold the mutator lock"; |
Mathieu Chartier | c11d9b8 | 2013-09-19 10:01:59 -0700 | [diff] [blame] | 211 | } |
Mathieu Chartier | 14c3bf9 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 212 | while (true) { |
Mathieu Chartier | 90ef3db | 2015-08-04 15:19:41 -0700 | [diff] [blame] | 213 | if (holding_locks) { |
| 214 | if (!kUseReadBarrier) { |
| 215 | CHECK_EQ(weak_root_state_, gc::kWeakRootStateNormal); |
| 216 | } else { |
| 217 | CHECK(self->GetWeakRefAccessEnabled()); |
| 218 | } |
| 219 | } |
Mathieu Chartier | 14c3bf9 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 220 | // Check the strong table for a match. |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 221 | ObjPtr<mirror::String> strong = LookupStrongLocked(s); |
Mathieu Chartier | 14c3bf9 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 222 | if (strong != nullptr) { |
| 223 | return strong; |
| 224 | } |
Mathieu Chartier | 90ef3db | 2015-08-04 15:19:41 -0700 | [diff] [blame] | 225 | if ((!kUseReadBarrier && weak_root_state_ != gc::kWeakRootStateNoReadsOrWrites) || |
| 226 | (kUseReadBarrier && self->GetWeakRefAccessEnabled())) { |
| 227 | break; |
| 228 | } |
Mathieu Chartier | 14c3bf9 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 229 | // weak_root_state_ is set to gc::kWeakRootStateNoReadsOrWrites in the GC pause but is only |
| 230 | // cleared after SweepSystemWeaks has completed. This is why we need to wait until it is |
| 231 | // cleared. |
Mathieu Chartier | 14c3bf9 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 232 | CHECK(!holding_locks); |
| 233 | StackHandleScope<1> hs(self); |
| 234 | auto h = hs.NewHandleWrapper(&s); |
| 235 | WaitUntilAccessible(self); |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 236 | } |
Mathieu Chartier | 90ef3db | 2015-08-04 15:19:41 -0700 | [diff] [blame] | 237 | if (!kUseReadBarrier) { |
| 238 | CHECK_EQ(weak_root_state_, gc::kWeakRootStateNormal); |
| 239 | } else { |
| 240 | CHECK(self->GetWeakRefAccessEnabled()); |
| 241 | } |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 242 | // There is no match in the strong table, check the weak table. |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 243 | ObjPtr<mirror::String> weak = LookupWeakLocked(s); |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 244 | if (weak != nullptr) { |
| 245 | if (is_strong) { |
| 246 | // A match was found in the weak table. Promote to the strong table. |
| 247 | RemoveWeak(weak); |
| 248 | return InsertStrong(weak); |
| 249 | } |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 250 | return weak; |
| 251 | } |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 252 | // No match in the strong table or the weak table. Insert into the strong / weak table. |
| 253 | return is_strong ? InsertStrong(s) : InsertWeak(s); |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 256 | ObjPtr<mirror::String> InternTable::InternStrong(int32_t utf16_length, const char* utf8_data) { |
Mathieu Chartier | ed0fc1d | 2014-03-21 14:09:35 -0700 | [diff] [blame] | 257 | DCHECK(utf8_data != nullptr); |
Vladimir Marko | d2bdb9b | 2016-07-08 17:23:22 +0100 | [diff] [blame] | 258 | Thread* self = Thread::Current(); |
| 259 | // Try to avoid allocation. |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 260 | ObjPtr<mirror::String> s = LookupStrong(self, utf16_length, utf8_data); |
Vladimir Marko | d2bdb9b | 2016-07-08 17:23:22 +0100 | [diff] [blame] | 261 | if (s != nullptr) { |
| 262 | return s; |
| 263 | } |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 264 | return InternStrong(mirror::String::AllocFromModifiedUtf8( |
Vladimir Marko | d2bdb9b | 2016-07-08 17:23:22 +0100 | [diff] [blame] | 265 | self, utf16_length, utf8_data)); |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 268 | ObjPtr<mirror::String> InternTable::InternStrong(const char* utf8_data) { |
Mathieu Chartier | ed0fc1d | 2014-03-21 14:09:35 -0700 | [diff] [blame] | 269 | DCHECK(utf8_data != nullptr); |
| 270 | return InternStrong(mirror::String::AllocFromModifiedUtf8(Thread::Current(), utf8_data)); |
Brian Carlstrom | c74255f | 2011-09-11 22:47:39 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 273 | ObjPtr<mirror::String> InternTable::InternStrongImageString(ObjPtr<mirror::String> s) { |
Mathieu Chartier | 14c3bf9 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 274 | // May be holding the heap bitmap lock. |
| 275 | return Insert(s, true, true); |
| 276 | } |
| 277 | |
Vladimir Marko | 8e05f09 | 2019-06-10 11:10:38 +0100 | [diff] [blame] | 278 | void InternTable::PromoteWeakToStrong() { |
| 279 | MutexLock mu(Thread::Current(), *Locks::intern_table_lock_); |
| 280 | DCHECK_EQ(weak_interns_.tables_.size(), 1u); |
| 281 | for (GcRoot<mirror::String>& entry : weak_interns_.tables_.front().set_) { |
| 282 | DCHECK(LookupStrongLocked(entry.Read()) == nullptr); |
| 283 | InsertStrong(entry.Read()); |
| 284 | } |
| 285 | weak_interns_.tables_.front().set_.clear(); |
| 286 | } |
| 287 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 288 | ObjPtr<mirror::String> InternTable::InternStrong(ObjPtr<mirror::String> s) { |
Mathieu Chartier | 14c3bf9 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 289 | return Insert(s, true, false); |
Brian Carlstrom | c74255f | 2011-09-11 22:47:39 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Vladimir Marko | 31c3daa | 2019-06-13 12:18:37 +0100 | [diff] [blame] | 292 | ObjPtr<mirror::String> InternTable::InternWeak(const char* utf8_data) { |
| 293 | DCHECK(utf8_data != nullptr); |
| 294 | return InternWeak(mirror::String::AllocFromModifiedUtf8(Thread::Current(), utf8_data)); |
| 295 | } |
| 296 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 297 | ObjPtr<mirror::String> InternTable::InternWeak(ObjPtr<mirror::String> s) { |
Mathieu Chartier | 14c3bf9 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 298 | return Insert(s, false, false); |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 301 | bool InternTable::ContainsWeak(ObjPtr<mirror::String> s) { |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 302 | return LookupWeak(Thread::Current(), s) == s; |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 305 | void InternTable::SweepInternTableWeaks(IsMarkedVisitor* visitor) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 306 | MutexLock mu(Thread::Current(), *Locks::intern_table_lock_); |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 307 | weak_interns_.SweepWeaks(visitor); |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Mathieu Chartier | d39645e | 2015-06-09 17:50:29 -0700 | [diff] [blame] | 310 | size_t InternTable::WriteToMemory(uint8_t* ptr) { |
| 311 | MutexLock mu(Thread::Current(), *Locks::intern_table_lock_); |
Mathieu Chartier | ea0831f | 2015-12-29 13:17:37 -0800 | [diff] [blame] | 312 | return strong_interns_.WriteToMemory(ptr); |
Mathieu Chartier | d39645e | 2015-06-09 17:50:29 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 315 | std::size_t InternTable::StringHashEquals::operator()(const GcRoot<mirror::String>& root) const { |
Mathieu Chartier | cdfd39f | 2014-08-29 18:16:58 -0700 | [diff] [blame] | 316 | if (kIsDebugBuild) { |
| 317 | Locks::mutator_lock_->AssertSharedHeld(Thread::Current()); |
| 318 | } |
Alexey Grebenkin | 21f2364 | 2016-12-02 17:44:54 +0300 | [diff] [blame] | 319 | // An additional cast to prevent undesired sign extension. |
| 320 | return static_cast<size_t>( |
| 321 | static_cast<uint32_t>(root.Read<kWithoutReadBarrier>()->GetHashCode())); |
Mathieu Chartier | cdfd39f | 2014-08-29 18:16:58 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | bool InternTable::StringHashEquals::operator()(const GcRoot<mirror::String>& a, |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 325 | const GcRoot<mirror::String>& b) const { |
Mathieu Chartier | cdfd39f | 2014-08-29 18:16:58 -0700 | [diff] [blame] | 326 | if (kIsDebugBuild) { |
| 327 | Locks::mutator_lock_->AssertSharedHeld(Thread::Current()); |
| 328 | } |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 329 | return a.Read<kWithoutReadBarrier>()->Equals(b.Read<kWithoutReadBarrier>()); |
Mathieu Chartier | cdfd39f | 2014-08-29 18:16:58 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 332 | bool InternTable::StringHashEquals::operator()(const GcRoot<mirror::String>& a, |
| 333 | const Utf8String& b) const { |
| 334 | if (kIsDebugBuild) { |
| 335 | Locks::mutator_lock_->AssertSharedHeld(Thread::Current()); |
| 336 | } |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 337 | ObjPtr<mirror::String> a_string = a.Read<kWithoutReadBarrier>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 338 | uint32_t a_length = static_cast<uint32_t>(a_string->GetLength()); |
| 339 | if (a_length != b.GetUtf16Length()) { |
| 340 | return false; |
| 341 | } |
jessicahandojo | 3aaa37b | 2016-07-29 14:46:37 -0700 | [diff] [blame] | 342 | if (a_string->IsCompressed()) { |
| 343 | size_t b_byte_count = strlen(b.GetUtf8Data()); |
| 344 | size_t b_utf8_length = CountModifiedUtf8Chars(b.GetUtf8Data(), b_byte_count); |
| 345 | // Modified UTF-8 single byte character range is 0x01 .. 0x7f |
| 346 | // The string compression occurs on regular ASCII with same exact range, |
| 347 | // not on extended ASCII which up to 0xff |
| 348 | const bool is_b_regular_ascii = (b_byte_count == b_utf8_length); |
| 349 | if (is_b_regular_ascii) { |
| 350 | return memcmp(b.GetUtf8Data(), |
| 351 | a_string->GetValueCompressed(), a_length * sizeof(uint8_t)) == 0; |
| 352 | } else { |
| 353 | return false; |
| 354 | } |
| 355 | } else { |
| 356 | const uint16_t* a_value = a_string->GetValue(); |
| 357 | return CompareModifiedUtf8ToUtf16AsCodePointValues(b.GetUtf8Data(), a_value, a_length) == 0; |
| 358 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Mathieu Chartier | ea0831f | 2015-12-29 13:17:37 -0800 | [diff] [blame] | 361 | size_t InternTable::Table::WriteToMemory(uint8_t* ptr) { |
| 362 | if (tables_.empty()) { |
| 363 | return 0; |
| 364 | } |
| 365 | UnorderedSet* table_to_write; |
| 366 | UnorderedSet combined; |
| 367 | if (tables_.size() > 1) { |
| 368 | table_to_write = &combined; |
Mathieu Chartier | 8cc418e | 2018-10-31 10:54:30 -0700 | [diff] [blame] | 369 | for (InternalTable& table : tables_) { |
| 370 | for (GcRoot<mirror::String>& string : table.set_) { |
Vladimir Marko | 54159c6 | 2018-06-20 14:30:08 +0100 | [diff] [blame] | 371 | combined.insert(string); |
Mathieu Chartier | ea0831f | 2015-12-29 13:17:37 -0800 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | } else { |
Mathieu Chartier | 8cc418e | 2018-10-31 10:54:30 -0700 | [diff] [blame] | 375 | table_to_write = &tables_.back().set_; |
Mathieu Chartier | ea0831f | 2015-12-29 13:17:37 -0800 | [diff] [blame] | 376 | } |
| 377 | return table_to_write->WriteToMemory(ptr); |
Mathieu Chartier | d39645e | 2015-06-09 17:50:29 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 380 | void InternTable::Table::Remove(ObjPtr<mirror::String> s) { |
Mathieu Chartier | 8cc418e | 2018-10-31 10:54:30 -0700 | [diff] [blame] | 381 | for (InternalTable& table : tables_) { |
| 382 | auto it = table.set_.find(GcRoot<mirror::String>(s)); |
| 383 | if (it != table.set_.end()) { |
| 384 | table.set_.erase(it); |
Mathieu Chartier | ea0831f | 2015-12-29 13:17:37 -0800 | [diff] [blame] | 385 | return; |
| 386 | } |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 387 | } |
Mathieu Chartier | ea0831f | 2015-12-29 13:17:37 -0800 | [diff] [blame] | 388 | LOG(FATAL) << "Attempting to remove non-interned string " << s->ToModifiedUtf8(); |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 391 | ObjPtr<mirror::String> InternTable::Table::Find(ObjPtr<mirror::String> s) { |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 392 | Locks::intern_table_lock_->AssertHeld(Thread::Current()); |
Mathieu Chartier | 8cc418e | 2018-10-31 10:54:30 -0700 | [diff] [blame] | 393 | for (InternalTable& table : tables_) { |
| 394 | auto it = table.set_.find(GcRoot<mirror::String>(s)); |
| 395 | if (it != table.set_.end()) { |
Mathieu Chartier | ea0831f | 2015-12-29 13:17:37 -0800 | [diff] [blame] | 396 | return it->Read(); |
| 397 | } |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 398 | } |
| 399 | return nullptr; |
| 400 | } |
| 401 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 402 | ObjPtr<mirror::String> InternTable::Table::Find(const Utf8String& string) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 403 | Locks::intern_table_lock_->AssertHeld(Thread::Current()); |
Mathieu Chartier | 8cc418e | 2018-10-31 10:54:30 -0700 | [diff] [blame] | 404 | for (InternalTable& table : tables_) { |
| 405 | auto it = table.set_.find(string); |
| 406 | if (it != table.set_.end()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 407 | return it->Read(); |
| 408 | } |
| 409 | } |
| 410 | return nullptr; |
| 411 | } |
| 412 | |
Mathieu Chartier | ea0831f | 2015-12-29 13:17:37 -0800 | [diff] [blame] | 413 | void InternTable::Table::AddNewTable() { |
Mathieu Chartier | 8cc418e | 2018-10-31 10:54:30 -0700 | [diff] [blame] | 414 | tables_.push_back(InternalTable()); |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 417 | void InternTable::Table::Insert(ObjPtr<mirror::String> s) { |
Mathieu Chartier | ea0831f | 2015-12-29 13:17:37 -0800 | [diff] [blame] | 418 | // Always insert the last table, the image tables are before and we avoid inserting into these |
| 419 | // to prevent dirty pages. |
| 420 | DCHECK(!tables_.empty()); |
Mathieu Chartier | 8cc418e | 2018-10-31 10:54:30 -0700 | [diff] [blame] | 421 | tables_.back().set_.insert(GcRoot<mirror::String>(s)); |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 424 | void InternTable::Table::VisitRoots(RootVisitor* visitor) { |
Mathieu Chartier | 4809d0a | 2015-04-07 10:39:04 -0700 | [diff] [blame] | 425 | BufferedRootVisitor<kDefaultBufferedRootCount> buffered_visitor( |
| 426 | visitor, RootInfo(kRootInternedString)); |
Mathieu Chartier | 8cc418e | 2018-10-31 10:54:30 -0700 | [diff] [blame] | 427 | for (InternalTable& table : tables_) { |
| 428 | for (auto& intern : table.set_) { |
Mathieu Chartier | ea0831f | 2015-12-29 13:17:37 -0800 | [diff] [blame] | 429 | buffered_visitor.VisitRoot(intern); |
| 430 | } |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 434 | void InternTable::Table::SweepWeaks(IsMarkedVisitor* visitor) { |
Mathieu Chartier | 8cc418e | 2018-10-31 10:54:30 -0700 | [diff] [blame] | 435 | for (InternalTable& table : tables_) { |
| 436 | SweepWeaks(&table.set_, visitor); |
Mathieu Chartier | ea0831f | 2015-12-29 13:17:37 -0800 | [diff] [blame] | 437 | } |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 440 | void InternTable::Table::SweepWeaks(UnorderedSet* set, IsMarkedVisitor* visitor) { |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 441 | for (auto it = set->begin(), end = set->end(); it != end;) { |
| 442 | // This does not need a read barrier because this is called by GC. |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 443 | mirror::Object* object = it->Read<kWithoutReadBarrier>(); |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 444 | mirror::Object* new_object = visitor->IsMarked(object); |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 445 | if (new_object == nullptr) { |
Vladimir Marko | 54159c6 | 2018-06-20 14:30:08 +0100 | [diff] [blame] | 446 | it = set->erase(it); |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 447 | } else { |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 448 | *it = GcRoot<mirror::String>(new_object->AsString()); |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 449 | ++it; |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 454 | size_t InternTable::Table::Size() const { |
Mathieu Chartier | ea0831f | 2015-12-29 13:17:37 -0800 | [diff] [blame] | 455 | return std::accumulate(tables_.begin(), |
| 456 | tables_.end(), |
Mathieu Chartier | 205b762 | 2016-01-06 15:47:09 -0800 | [diff] [blame] | 457 | 0U, |
Mathieu Chartier | 8cc418e | 2018-10-31 10:54:30 -0700 | [diff] [blame] | 458 | [](size_t sum, const InternalTable& table) { |
| 459 | return sum + table.Size(); |
Mathieu Chartier | ea0831f | 2015-12-29 13:17:37 -0800 | [diff] [blame] | 460 | }); |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 461 | } |
| 462 | |
Mathieu Chartier | 14c3bf9 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 463 | void InternTable::ChangeWeakRootState(gc::WeakRootState new_state) { |
| 464 | MutexLock mu(Thread::Current(), *Locks::intern_table_lock_); |
| 465 | ChangeWeakRootStateLocked(new_state); |
| 466 | } |
| 467 | |
| 468 | void InternTable::ChangeWeakRootStateLocked(gc::WeakRootState new_state) { |
Hiroshi Yamauchi | fdbd13c | 2015-09-02 16:16:58 -0700 | [diff] [blame] | 469 | CHECK(!kUseReadBarrier); |
Mathieu Chartier | 14c3bf9 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 470 | weak_root_state_ = new_state; |
| 471 | if (new_state != gc::kWeakRootStateNoReadsOrWrites) { |
| 472 | weak_intern_condition_.Broadcast(Thread::Current()); |
| 473 | } |
| 474 | } |
| 475 | |
Mathieu Chartier | 32cc9ee | 2015-10-15 09:19:15 -0700 | [diff] [blame] | 476 | InternTable::Table::Table() { |
| 477 | Runtime* const runtime = Runtime::Current(); |
Mathieu Chartier | 8cc418e | 2018-10-31 10:54:30 -0700 | [diff] [blame] | 478 | InternalTable initial_table; |
| 479 | initial_table.set_.SetLoadFactor(runtime->GetHashTableMinLoadFactor(), |
| 480 | runtime->GetHashTableMaxLoadFactor()); |
| 481 | tables_.push_back(std::move(initial_table)); |
Mathieu Chartier | 32cc9ee | 2015-10-15 09:19:15 -0700 | [diff] [blame] | 482 | } |
| 483 | |
Brian Carlstrom | 7e93b50 | 2011-08-04 14:16:22 -0700 | [diff] [blame] | 484 | } // namespace art |