blob: 2ec03be6709b3a2502e4bbbcde375e464dd4ffb3 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 Carlstrom7e93b502011-08-04 14:16:22 -070016
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_INTERN_TABLE_H_
18#define ART_RUNTIME_INTERN_TABLE_H_
Brian Carlstrom7e93b502011-08-04 14:16:22 -070019
Mathieu Chartiercdfd39f2014-08-29 18:16:58 -070020#include <unordered_set>
Brian Carlstrom7e93b502011-08-04 14:16:22 -070021
Mathieu Chartier14c3bf92015-07-13 14:35:43 -070022#include "atomic.h"
Mathieu Chartierbad02672014-08-25 13:08:22 -070023#include "base/allocator.h"
Mathieu Chartierc2e20622014-11-03 11:41:47 -080024#include "base/hash_set.h"
Ian Rogers719d1a32014-03-06 12:13:39 -080025#include "base/mutex.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070026#include "gc_root.h"
Mathieu Chartier14c3bf92015-07-13 14:35:43 -070027#include "gc/weak_root_state.h"
Ian Rogers719d1a32014-03-06 12:13:39 -080028
Brian Carlstrom7e93b502011-08-04 14:16:22 -070029namespace art {
Mathieu Chartier893263b2014-03-04 11:07:42 -080030
Andreas Gampe5d08fcc2017-06-05 17:56:46 -070031class IsMarkedVisitor;
32
Mathieu Chartiereb175f72014-10-31 11:49:27 -070033namespace gc {
34namespace space {
35class ImageSpace;
36} // namespace space
37} // namespace gc
38
Mathieu Chartier893263b2014-03-04 11:07:42 -080039enum VisitRootFlags : uint8_t;
40
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080041namespace mirror {
42class String;
43} // namespace mirror
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010044class Transaction;
Brian Carlstrom7e93b502011-08-04 14:16:22 -070045
Elliott Hughescf4c6c42011-09-01 15:16:42 -070046/**
47 * Used to intern strings.
48 *
49 * There are actually two tables: one that holds strong references to its strings, and one that
50 * holds weak references. The former is used for string literals, for which there is an effective
51 * reference from the constant pool. The latter is used for strings interned at runtime via
52 * String.intern. Some code (XML parsers being a prime example) relies on being able to intern
53 * arbitrarily many strings for the duration of a parse without permanently increasing the memory
54 * footprint.
55 */
Brian Carlstrom7e93b502011-08-04 14:16:22 -070056class InternTable {
57 public:
58 InternTable();
Brian Carlstroma663ea52011-08-19 23:33:41 -070059
Mathieu Chartier14c3bf92015-07-13 14:35:43 -070060 // Interns a potentially new string in the 'strong' table. May cause thread suspension.
Mathieu Chartier9e868092016-10-31 14:58:04 -070061 ObjPtr<mirror::String> InternStrong(int32_t utf16_length, const char* utf8_data)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070062 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Brian Carlstromc74255f2011-09-11 22:47:39 -070063
Mathieu Chartiered8990a2015-07-23 14:11:16 -070064 // Only used by image writer. Special version that may not cause thread suspension since the GC
Roland Levillain91d65e02016-01-19 15:59:16 +000065 // cannot be running while we are doing image writing. Maybe be called while while holding a
Mathieu Chartier90ef3db2015-08-04 15:19:41 -070066 // lock since there will not be thread suspension.
Mathieu Chartier9e868092016-10-31 14:58:04 -070067 ObjPtr<mirror::String> InternStrongImageString(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070068 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -070069
70 // Interns a potentially new string in the 'strong' table. May cause thread suspension.
Mathieu Chartier9e868092016-10-31 14:58:04 -070071 ObjPtr<mirror::String> InternStrong(const char* utf8_data) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartiered8990a2015-07-23 14:11:16 -070072 REQUIRES(!Roles::uninterruptible_);
Brian Carlstromc74255f2011-09-11 22:47:39 -070073
Mathieu Chartier14c3bf92015-07-13 14:35:43 -070074 // Interns a potentially new string in the 'strong' table. May cause thread suspension.
Mathieu Chartier9e868092016-10-31 14:58:04 -070075 ObjPtr<mirror::String> InternStrong(ObjPtr<mirror::String> s)
76 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartiered8990a2015-07-23 14:11:16 -070077 REQUIRES(!Roles::uninterruptible_);
Brian Carlstroma663ea52011-08-19 23:33:41 -070078
Mathieu Chartier14c3bf92015-07-13 14:35:43 -070079 // Interns a potentially new string in the 'weak' table. May cause thread suspension.
Mathieu Chartier9e868092016-10-31 14:58:04 -070080 ObjPtr<mirror::String> InternWeak(ObjPtr<mirror::String> s) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartiered8990a2015-07-23 14:11:16 -070081 REQUIRES(!Roles::uninterruptible_);
Elliott Hughescf4c6c42011-09-01 15:16:42 -070082
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070083 void SweepInternTableWeaks(IsMarkedVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -070084 REQUIRES(!Locks::intern_table_lock_);
Elliott Hughescf4c6c42011-09-01 15:16:42 -070085
Mathieu Chartier9e868092016-10-31 14:58:04 -070086 bool ContainsWeak(ObjPtr<mirror::String> s) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartiered8990a2015-07-23 14:11:16 -070087 REQUIRES(!Locks::intern_table_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -070088
Mathieu Chartierfbc31082016-01-24 11:59:56 -080089 // Lookup a strong intern, returns null if not found.
Mathieu Chartier9e868092016-10-31 14:58:04 -070090 ObjPtr<mirror::String> LookupStrong(Thread* self, ObjPtr<mirror::String> s)
Mathieu Chartierfbc31082016-01-24 11:59:56 -080091 REQUIRES(!Locks::intern_table_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070092 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -070093 ObjPtr<mirror::String> LookupStrong(Thread* self, uint32_t utf16_length, const char* utf8_data)
Vladimir Markocac5a7e2016-02-22 10:39:50 +000094 REQUIRES(!Locks::intern_table_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070095 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -080096
97 // Lookup a weak intern, returns null if not found.
Mathieu Chartier9e868092016-10-31 14:58:04 -070098 ObjPtr<mirror::String> LookupWeak(Thread* self, ObjPtr<mirror::String> s)
Mathieu Chartierfbc31082016-01-24 11:59:56 -080099 REQUIRES(!Locks::intern_table_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700100 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800101
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700102 // Total number of interned strings.
Mathieu Chartier90443472015-07-16 20:32:27 -0700103 size_t Size() const REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800104
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700105 // Total number of weakly live interned strings.
Mathieu Chartier90443472015-07-16 20:32:27 -0700106 size_t StrongSize() const REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800107
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700108 // Total number of strongly live interned strings.
Mathieu Chartier90443472015-07-16 20:32:27 -0700109 size_t WeakSize() const REQUIRES(!Locks::intern_table_lock_);
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700110
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700111 void VisitRoots(RootVisitor* visitor, VisitRootFlags flags)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700112 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::intern_table_lock_);
Brian Carlstrom7e93b502011-08-04 14:16:22 -0700113
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700114 void DumpForSigQuit(std::ostream& os) const REQUIRES(!Locks::intern_table_lock_);
Elliott Hughescac6cc72011-11-03 20:31:21 -0700115
Hiroshi Yamauchi30493242016-11-03 13:06:52 -0700116 void BroadcastForNewInterns();
Mathieu Chartierc11d9b82013-09-19 10:01:59 -0700117
Mathieu Chartier205b7622016-01-06 15:47:09 -0800118 // Adds all of the resolved image strings from the image spaces into the intern table. The
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800119 // advantage of doing this is preventing expensive DexFile::FindStringId calls. Sets
Mathieu Chartier205b7622016-01-06 15:47:09 -0800120 // images_added_to_intern_table_ to true.
121 void AddImagesStringsToTable(const std::vector<gc::space::ImageSpace*>& image_spaces)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700122 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700123
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800124 // Add a new intern table for inserting to, previous intern tables are still there but no
125 // longer inserted into and ideally unmodified. This is done to prevent dirty pages.
126 void AddNewTable()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700127 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartierd39645e2015-06-09 17:50:29 -0700128
129 // Read the intern table from memory. The elements aren't copied, the intern hash set data will
130 // point to somewhere within ptr. Only reads the strong interns.
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800131 size_t AddTableFromMemory(const uint8_t* ptr) REQUIRES(!Locks::intern_table_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700132 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierd39645e2015-06-09 17:50:29 -0700133
134 // Write the post zygote intern table to a pointer. Only writes the strong interns since it is
135 // expected that there is no weak interns since this is called from the image writer.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700136 size_t WriteToMemory(uint8_t* ptr) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700137 REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartierd39645e2015-06-09 17:50:29 -0700138
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700139 // Change the weak root state. May broadcast to waiters.
140 void ChangeWeakRootState(gc::WeakRootState new_state)
Mathieu Chartier90443472015-07-16 20:32:27 -0700141 REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700142
Brian Carlstrom7e93b502011-08-04 14:16:22 -0700143 private:
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000144 // Modified UTF-8-encoded string treated as UTF16.
145 class Utf8String {
146 public:
147 Utf8String(uint32_t utf16_length, const char* utf8_data, int32_t hash)
148 : hash_(hash), utf16_length_(utf16_length), utf8_data_(utf8_data) { }
149
150 int32_t GetHash() const { return hash_; }
151 uint32_t GetUtf16Length() const { return utf16_length_; }
152 const char* GetUtf8Data() const { return utf8_data_; }
153
154 private:
155 int32_t hash_;
156 uint32_t utf16_length_;
157 const char* utf8_data_;
158 };
159
Mathieu Chartiercdfd39f2014-08-29 18:16:58 -0700160 class StringHashEquals {
161 public:
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800162 std::size_t operator()(const GcRoot<mirror::String>& root) const NO_THREAD_SAFETY_ANALYSIS;
163 bool operator()(const GcRoot<mirror::String>& a, const GcRoot<mirror::String>& b) const
Mathieu Chartiercdfd39f2014-08-29 18:16:58 -0700164 NO_THREAD_SAFETY_ANALYSIS;
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000165
166 // Utf8String can be used for lookup.
Alexey Grebenkin21f23642016-12-02 17:44:54 +0300167 std::size_t operator()(const Utf8String& key) const {
168 // A cast to prevent undesired sign extension.
169 return static_cast<uint32_t>(key.GetHash());
170 }
171
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000172 bool operator()(const GcRoot<mirror::String>& a, const Utf8String& b) const
173 NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartiercdfd39f2014-08-29 18:16:58 -0700174 };
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800175 class GcRootEmptyFn {
176 public:
177 void MakeEmpty(GcRoot<mirror::String>& item) const {
178 item = GcRoot<mirror::String>();
179 }
180 bool IsEmpty(const GcRoot<mirror::String>& item) const {
181 return item.IsNull();
182 }
183 };
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700184
185 // Table which holds pre zygote and post zygote interned strings. There is one instance for
186 // weak interns and strong interns.
187 class Table {
188 public:
Mathieu Chartier32cc9ee2015-10-15 09:19:15 -0700189 Table();
Mathieu Chartier9e868092016-10-31 14:58:04 -0700190 ObjPtr<mirror::String> Find(ObjPtr<mirror::String> s) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700191 REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700192 ObjPtr<mirror::String> Find(const Utf8String& string) REQUIRES_SHARED(Locks::mutator_lock_)
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000193 REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700194 void Insert(ObjPtr<mirror::String> s) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700195 REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700196 void Remove(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700197 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700198 void VisitRoots(RootVisitor* visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700199 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier97509952015-07-13 14:35:43 -0700200 void SweepWeaks(IsMarkedVisitor* visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700201 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800202 // Add a new intern table that will only be inserted into from now on.
203 void AddNewTable() REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier90443472015-07-16 20:32:27 -0700204 size_t Size() const REQUIRES(Locks::intern_table_lock_);
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800205 // Read and add an intern table from ptr.
206 // Tables read are inserted at the front of the table array. Only checks for conflicts in
207 // debug builds. Returns how many bytes were read.
208 size_t AddTableFromMemory(const uint8_t* ptr)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700209 REQUIRES(Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier205b7622016-01-06 15:47:09 -0800210 // Write the intern tables to ptr, if there are multiple tables they are combined into a single
211 // one. Returns how many bytes were written.
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800212 size_t WriteToMemory(uint8_t* ptr)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700213 REQUIRES(Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700214
215 private:
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800216 typedef HashSet<GcRoot<mirror::String>, GcRootEmptyFn, StringHashEquals, StringHashEquals,
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700217 TrackingAllocator<GcRoot<mirror::String>, kAllocatorTagInternTable>> UnorderedSet;
218
Mathieu Chartier97509952015-07-13 14:35:43 -0700219 void SweepWeaks(UnorderedSet* set, IsMarkedVisitor* visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700220 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700221
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800222 // We call AddNewTable when we create the zygote to reduce private dirty pages caused by
223 // modifying the zygote intern table. The back of table is modified when strings are interned.
224 std::vector<UnorderedSet> tables_;
Alexey Grebenkin21f23642016-12-02 17:44:54 +0300225
226 ART_FRIEND_TEST(InternTableTest, CrossHash);
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700227 };
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700228
Mathieu Chartier90ef3db2015-08-04 15:19:41 -0700229 // Insert if non null, otherwise return null. Must be called holding the mutator lock.
230 // If holding_locks is true, then we may also hold other locks. If holding_locks is true, then we
231 // require GC is not running since it is not safe to wait while holding locks.
Mathieu Chartier9e868092016-10-31 14:58:04 -0700232 ObjPtr<mirror::String> Insert(ObjPtr<mirror::String> s, bool is_strong, bool holding_locks)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700233 REQUIRES(!Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700234
Mathieu Chartier9e868092016-10-31 14:58:04 -0700235 ObjPtr<mirror::String> LookupStrongLocked(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700236 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700237 ObjPtr<mirror::String> LookupWeakLocked(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700238 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700239 ObjPtr<mirror::String> InsertStrong(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700240 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700241 ObjPtr<mirror::String> InsertWeak(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700242 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700243 void RemoveStrong(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700244 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700245 void RemoveWeak(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700246 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700247
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100248 // Transaction rollback access.
Mathieu Chartier9e868092016-10-31 14:58:04 -0700249 ObjPtr<mirror::String> InsertStrongFromTransaction(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700250 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700251 ObjPtr<mirror::String> InsertWeakFromTransaction(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700252 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700253 void RemoveStrongFromTransaction(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700254 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700255 void RemoveWeakFromTransaction(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700256 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100257
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800258 size_t AddTableFromMemoryLocked(const uint8_t* ptr)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700259 REQUIRES(Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierd39645e2015-06-09 17:50:29 -0700260
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700261 // Change the weak root state. May broadcast to waiters.
262 void ChangeWeakRootStateLocked(gc::WeakRootState new_state)
Mathieu Chartier90443472015-07-16 20:32:27 -0700263 REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700264
265 // Wait until we can read weak roots.
Mathieu Chartier90443472015-07-16 20:32:27 -0700266 void WaitUntilAccessible(Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700267 REQUIRES(Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700268
Mathieu Chartier893263b2014-03-04 11:07:42 -0800269 bool log_new_roots_ GUARDED_BY(Locks::intern_table_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700270 ConditionVariable weak_intern_condition_ GUARDED_BY(Locks::intern_table_lock_);
Hiroshi Yamauchia91a4bc2014-06-13 16:44:55 -0700271 // Since this contains (strong) roots, they need a read barrier to
272 // enable concurrent intern table (strong) root scan. Do not
273 // directly access the strings in it. Use functions that contain
274 // read barriers.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100275 Table strong_interns_ GUARDED_BY(Locks::intern_table_lock_);
Mathieu Chartiercdfd39f2014-08-29 18:16:58 -0700276 std::vector<GcRoot<mirror::String>> new_strong_intern_roots_
Mathieu Chartier893263b2014-03-04 11:07:42 -0800277 GUARDED_BY(Locks::intern_table_lock_);
Hiroshi Yamauchia91a4bc2014-06-13 16:44:55 -0700278 // Since this contains (weak) roots, they need a read barrier. Do
279 // not directly access the strings in it. Use functions that contain
280 // read barriers.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100281 Table weak_interns_ GUARDED_BY(Locks::intern_table_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700282 // Weak root state, used for concurrent system weak processing and more.
283 gc::WeakRootState weak_root_state_ GUARDED_BY(Locks::intern_table_lock_);
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700284
285 friend class Transaction;
Alexey Grebenkin21f23642016-12-02 17:44:54 +0300286 ART_FRIEND_TEST(InternTableTest, CrossHash);
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700287 DISALLOW_COPY_AND_ASSIGN(InternTable);
Brian Carlstrom7e93b502011-08-04 14:16:22 -0700288};
289
290} // namespace art
291
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700292#endif // ART_RUNTIME_INTERN_TABLE_H_