blob: 7065015a13c4234effe9c8b2aa519e00edb2425d [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 Chartierbad02672014-08-25 13:08:22 -070020#include "base/allocator.h"
Mathieu Chartierc2e20622014-11-03 11:41:47 -080021#include "base/hash_set.h"
Ian Rogers719d1a32014-03-06 12:13:39 -080022#include "base/mutex.h"
Mathieu Chartier14c3bf92015-07-13 14:35:43 -070023#include "gc/weak_root_state.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070024#include "gc_root.h"
Ian Rogers719d1a32014-03-06 12:13:39 -080025
Brian Carlstrom7e93b502011-08-04 14:16:22 -070026namespace art {
Mathieu Chartier893263b2014-03-04 11:07:42 -080027
Andreas Gampe5d08fcc2017-06-05 17:56:46 -070028class IsMarkedVisitor;
29
Mathieu Chartiereb175f72014-10-31 11:49:27 -070030namespace gc {
31namespace space {
32class ImageSpace;
33} // namespace space
34} // namespace gc
35
Mathieu Chartier893263b2014-03-04 11:07:42 -080036enum VisitRootFlags : uint8_t;
37
Vladimir Marko74527972016-11-29 15:57:32 +000038namespace linker {
Vladimir Markoca8de0a2018-07-04 11:56:08 +010039class ImageWriter;
Vladimir Marko74527972016-11-29 15:57:32 +000040} // namespace linker
41
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080042namespace mirror {
43class String;
44} // namespace mirror
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010045class Transaction;
Brian Carlstrom7e93b502011-08-04 14:16:22 -070046
Elliott Hughescf4c6c42011-09-01 15:16:42 -070047/**
48 * Used to intern strings.
49 *
50 * There are actually two tables: one that holds strong references to its strings, and one that
51 * holds weak references. The former is used for string literals, for which there is an effective
52 * reference from the constant pool. The latter is used for strings interned at runtime via
53 * String.intern. Some code (XML parsers being a prime example) relies on being able to intern
54 * arbitrarily many strings for the duration of a parse without permanently increasing the memory
55 * footprint.
56 */
Brian Carlstrom7e93b502011-08-04 14:16:22 -070057class InternTable {
58 public:
Mathieu Chartier74ccee62018-10-10 10:30:29 -070059 // Modified UTF-8-encoded string treated as UTF16.
60 class Utf8String {
61 public:
62 Utf8String(uint32_t utf16_length, const char* utf8_data, int32_t hash)
63 : hash_(hash), utf16_length_(utf16_length), utf8_data_(utf8_data) { }
64
65 int32_t GetHash() const { return hash_; }
66 uint32_t GetUtf16Length() const { return utf16_length_; }
67 const char* GetUtf8Data() const { return utf8_data_; }
68
69 private:
70 int32_t hash_;
71 uint32_t utf16_length_;
72 const char* utf8_data_;
73 };
74
75 class StringHashEquals {
76 public:
77 std::size_t operator()(const GcRoot<mirror::String>& root) const NO_THREAD_SAFETY_ANALYSIS;
78 bool operator()(const GcRoot<mirror::String>& a, const GcRoot<mirror::String>& b) const
79 NO_THREAD_SAFETY_ANALYSIS;
80
81 // Utf8String can be used for lookup.
82 std::size_t operator()(const Utf8String& key) const {
83 // A cast to prevent undesired sign extension.
84 return static_cast<uint32_t>(key.GetHash());
85 }
86
87 bool operator()(const GcRoot<mirror::String>& a, const Utf8String& b) const
88 NO_THREAD_SAFETY_ANALYSIS;
89 };
90
91 class GcRootEmptyFn {
92 public:
93 void MakeEmpty(GcRoot<mirror::String>& item) const {
94 item = GcRoot<mirror::String>();
95 }
96 bool IsEmpty(const GcRoot<mirror::String>& item) const {
97 return item.IsNull();
98 }
99 };
100
101 using UnorderedSet = HashSet<GcRoot<mirror::String>,
102 GcRootEmptyFn,
103 StringHashEquals,
104 StringHashEquals,
105 TrackingAllocator<GcRoot<mirror::String>, kAllocatorTagInternTable>>;
106
Brian Carlstrom7e93b502011-08-04 14:16:22 -0700107 InternTable();
Brian Carlstroma663ea52011-08-19 23:33:41 -0700108
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700109 // Interns a potentially new string in the 'strong' table. May cause thread suspension.
Mathieu Chartier9e868092016-10-31 14:58:04 -0700110 ObjPtr<mirror::String> InternStrong(int32_t utf16_length, const char* utf8_data)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700111 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Brian Carlstromc74255f2011-09-11 22:47:39 -0700112
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700113 // Only used by image writer. Special version that may not cause thread suspension since the GC
Roland Levillain91d65e02016-01-19 15:59:16 +0000114 // cannot be running while we are doing image writing. Maybe be called while while holding a
Mathieu Chartier90ef3db2015-08-04 15:19:41 -0700115 // lock since there will not be thread suspension.
Mathieu Chartier9e868092016-10-31 14:58:04 -0700116 ObjPtr<mirror::String> InternStrongImageString(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700117 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700118
Vladimir Marko8e05f092019-06-10 11:10:38 +0100119 // Only used by image writer. Promote all weak interns to strong interns.
120 void PromoteWeakToStrong() REQUIRES_SHARED(Locks::mutator_lock_);
121
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700122 // Interns a potentially new string in the 'strong' table. May cause thread suspension.
Mathieu Chartier9e868092016-10-31 14:58:04 -0700123 ObjPtr<mirror::String> InternStrong(const char* utf8_data) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700124 REQUIRES(!Roles::uninterruptible_);
Brian Carlstromc74255f2011-09-11 22:47:39 -0700125
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700126 // Interns a potentially new string in the 'strong' table. May cause thread suspension.
Mathieu Chartier9e868092016-10-31 14:58:04 -0700127 ObjPtr<mirror::String> InternStrong(ObjPtr<mirror::String> s)
128 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700129 REQUIRES(!Roles::uninterruptible_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700130
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700131 // Interns a potentially new string in the 'weak' table. May cause thread suspension.
Vladimir Marko31c3daa2019-06-13 12:18:37 +0100132 ObjPtr<mirror::String> InternWeak(const char* utf8_data) REQUIRES_SHARED(Locks::mutator_lock_)
133 REQUIRES(!Roles::uninterruptible_);
134
135 // Interns a potentially new string in the 'weak' table. May cause thread suspension.
Mathieu Chartier9e868092016-10-31 14:58:04 -0700136 ObjPtr<mirror::String> InternWeak(ObjPtr<mirror::String> s) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700137 REQUIRES(!Roles::uninterruptible_);
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700138
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700139 void SweepInternTableWeaks(IsMarkedVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700140 REQUIRES(!Locks::intern_table_lock_);
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700141
Mathieu Chartier9e868092016-10-31 14:58:04 -0700142 bool ContainsWeak(ObjPtr<mirror::String> s) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700143 REQUIRES(!Locks::intern_table_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700144
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800145 // Lookup a strong intern, returns null if not found.
Mathieu Chartier9e868092016-10-31 14:58:04 -0700146 ObjPtr<mirror::String> LookupStrong(Thread* self, ObjPtr<mirror::String> s)
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800147 REQUIRES(!Locks::intern_table_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700148 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700149 ObjPtr<mirror::String> LookupStrong(Thread* self, uint32_t utf16_length, const char* utf8_data)
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000150 REQUIRES(!Locks::intern_table_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700151 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier41c08082018-10-31 11:50:26 -0700152 ObjPtr<mirror::String> LookupStrongLocked(ObjPtr<mirror::String> s)
153 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800154
155 // Lookup a weak intern, returns null if not found.
Mathieu Chartier9e868092016-10-31 14:58:04 -0700156 ObjPtr<mirror::String> LookupWeak(Thread* self, ObjPtr<mirror::String> s)
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800157 REQUIRES(!Locks::intern_table_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700158 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier41c08082018-10-31 11:50:26 -0700159 ObjPtr<mirror::String> LookupWeakLocked(ObjPtr<mirror::String> s)
160 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800161
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700162 // Total number of interned strings.
Mathieu Chartier90443472015-07-16 20:32:27 -0700163 size_t Size() const REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800164
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700165 // Total number of weakly live interned strings.
Mathieu Chartier90443472015-07-16 20:32:27 -0700166 size_t StrongSize() const REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800167
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700168 // Total number of strongly live interned strings.
Mathieu Chartier90443472015-07-16 20:32:27 -0700169 size_t WeakSize() const REQUIRES(!Locks::intern_table_lock_);
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700170
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700171 void VisitRoots(RootVisitor* visitor, VisitRootFlags flags)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700172 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::intern_table_lock_);
Brian Carlstrom7e93b502011-08-04 14:16:22 -0700173
Mathieu Chartier8cc418e2018-10-31 10:54:30 -0700174 // Visit all of the interns in the table.
175 template <typename Visitor>
176 void VisitInterns(const Visitor& visitor,
177 bool visit_boot_images,
178 bool visit_non_boot_images)
179 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
180
Mathieu Chartier8fc75582018-11-01 14:21:33 -0700181 // Count the number of intern strings in the table.
182 size_t CountInterns(bool visit_boot_images, bool visit_non_boot_images) const
183 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
184
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700185 void DumpForSigQuit(std::ostream& os) const REQUIRES(!Locks::intern_table_lock_);
Elliott Hughescac6cc72011-11-03 20:31:21 -0700186
Hiroshi Yamauchi30493242016-11-03 13:06:52 -0700187 void BroadcastForNewInterns();
Mathieu Chartierc11d9b82013-09-19 10:01:59 -0700188
Mathieu Chartier74ccee62018-10-10 10:30:29 -0700189 // Add all of the strings in the image's intern table into this intern table. This is required so
190 // the intern table is correct.
191 // The visitor arg type is UnorderedSet
192 template <typename Visitor>
193 void AddImageStringsToTable(gc::space::ImageSpace* image_space,
194 const Visitor& visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700195 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700196
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800197 // Add a new intern table for inserting to, previous intern tables are still there but no
198 // longer inserted into and ideally unmodified. This is done to prevent dirty pages.
199 void AddNewTable()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700200 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartierd39645e2015-06-09 17:50:29 -0700201
Mathieu Chartierd39645e2015-06-09 17:50:29 -0700202 // Write the post zygote intern table to a pointer. Only writes the strong interns since it is
203 // expected that there is no weak interns since this is called from the image writer.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700204 size_t WriteToMemory(uint8_t* ptr) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700205 REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartierd39645e2015-06-09 17:50:29 -0700206
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700207 // Change the weak root state. May broadcast to waiters.
208 void ChangeWeakRootState(gc::WeakRootState new_state)
Mathieu Chartier90443472015-07-16 20:32:27 -0700209 REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700210
Brian Carlstrom7e93b502011-08-04 14:16:22 -0700211 private:
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700212 // Table which holds pre zygote and post zygote interned strings. There is one instance for
213 // weak interns and strong interns.
214 class Table {
215 public:
Mathieu Chartier8cc418e2018-10-31 10:54:30 -0700216 class InternalTable {
217 public:
218 InternalTable() = default;
219 InternalTable(UnorderedSet&& set, bool is_boot_image)
220 : set_(std::move(set)), is_boot_image_(is_boot_image) {}
221
222 bool Empty() const {
223 return set_.empty();
224 }
225
226 size_t Size() const {
227 return set_.size();
228 }
229
230 bool IsBootImage() const {
231 return is_boot_image_;
232 }
233
234 private:
235 UnorderedSet set_;
236 bool is_boot_image_ = false;
237
238 friend class InternTable;
239 friend class Table;
240 ART_FRIEND_TEST(InternTableTest, CrossHash);
241 };
242
Mathieu Chartier32cc9ee2015-10-15 09:19:15 -0700243 Table();
Mathieu Chartier9e868092016-10-31 14:58:04 -0700244 ObjPtr<mirror::String> Find(ObjPtr<mirror::String> s) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700245 REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700246 ObjPtr<mirror::String> Find(const Utf8String& string) REQUIRES_SHARED(Locks::mutator_lock_)
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000247 REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700248 void Insert(ObjPtr<mirror::String> s) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700249 REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700250 void Remove(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700251 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700252 void VisitRoots(RootVisitor* visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700253 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier97509952015-07-13 14:35:43 -0700254 void SweepWeaks(IsMarkedVisitor* visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700255 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800256 // Add a new intern table that will only be inserted into from now on.
257 void AddNewTable() REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier90443472015-07-16 20:32:27 -0700258 size_t Size() const REQUIRES(Locks::intern_table_lock_);
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800259 // Read and add an intern table from ptr.
260 // Tables read are inserted at the front of the table array. Only checks for conflicts in
261 // debug builds. Returns how many bytes were read.
Mathieu Chartier74ccee62018-10-10 10:30:29 -0700262 // NO_THREAD_SAFETY_ANALYSIS for the visitor that may require locks.
263 template <typename Visitor>
Mathieu Chartier8cc418e2018-10-31 10:54:30 -0700264 size_t AddTableFromMemory(const uint8_t* ptr, const Visitor& visitor, bool is_boot_image)
Mathieu Chartier74ccee62018-10-10 10:30:29 -0700265 REQUIRES(!Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier205b7622016-01-06 15:47:09 -0800266 // Write the intern tables to ptr, if there are multiple tables they are combined into a single
267 // one. Returns how many bytes were written.
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800268 size_t WriteToMemory(uint8_t* ptr)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700269 REQUIRES(Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700270
271 private:
Mathieu Chartier97509952015-07-13 14:35:43 -0700272 void SweepWeaks(UnorderedSet* set, IsMarkedVisitor* visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700273 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700274
Mathieu Chartier74ccee62018-10-10 10:30:29 -0700275 // Add a table to the front of the tables vector.
Mathieu Chartier8cc418e2018-10-31 10:54:30 -0700276 void AddInternStrings(UnorderedSet&& intern_strings, bool is_boot_image)
Mathieu Chartier74ccee62018-10-10 10:30:29 -0700277 REQUIRES(Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
278
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800279 // We call AddNewTable when we create the zygote to reduce private dirty pages caused by
280 // modifying the zygote intern table. The back of table is modified when strings are interned.
Mathieu Chartier8cc418e2018-10-31 10:54:30 -0700281 std::vector<InternalTable> tables_;
Alexey Grebenkin21f23642016-12-02 17:44:54 +0300282
Mathieu Chartier74ccee62018-10-10 10:30:29 -0700283 friend class InternTable;
Vladimir Markoca8de0a2018-07-04 11:56:08 +0100284 friend class linker::ImageWriter;
Alexey Grebenkin21f23642016-12-02 17:44:54 +0300285 ART_FRIEND_TEST(InternTableTest, CrossHash);
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700286 };
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700287
Mathieu Chartier90ef3db2015-08-04 15:19:41 -0700288 // Insert if non null, otherwise return null. Must be called holding the mutator lock.
289 // If holding_locks is true, then we may also hold other locks. If holding_locks is true, then we
290 // require GC is not running since it is not safe to wait while holding locks.
Mathieu Chartier9e868092016-10-31 14:58:04 -0700291 ObjPtr<mirror::String> Insert(ObjPtr<mirror::String> s, bool is_strong, bool holding_locks)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700292 REQUIRES(!Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700293
Mathieu Chartier74ccee62018-10-10 10:30:29 -0700294 // Add a table from memory to the strong interns.
295 template <typename Visitor>
Mathieu Chartier8cc418e2018-10-31 10:54:30 -0700296 size_t AddTableFromMemory(const uint8_t* ptr, const Visitor& visitor, bool is_boot_image)
Mathieu Chartier74ccee62018-10-10 10:30:29 -0700297 REQUIRES(!Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
298
Mathieu Chartier9e868092016-10-31 14:58:04 -0700299 ObjPtr<mirror::String> InsertStrong(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700300 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700301 ObjPtr<mirror::String> InsertWeak(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700302 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700303 void RemoveStrong(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700304 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700305 void RemoveWeak(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700306 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700307
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100308 // Transaction rollback access.
Mathieu Chartier9e868092016-10-31 14:58:04 -0700309 ObjPtr<mirror::String> InsertStrongFromTransaction(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700310 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700311 ObjPtr<mirror::String> InsertWeakFromTransaction(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700312 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700313 void RemoveStrongFromTransaction(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700314 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700315 void RemoveWeakFromTransaction(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700316 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100317
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700318 // Change the weak root state. May broadcast to waiters.
319 void ChangeWeakRootStateLocked(gc::WeakRootState new_state)
Mathieu Chartier90443472015-07-16 20:32:27 -0700320 REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700321
322 // Wait until we can read weak roots.
Mathieu Chartier90443472015-07-16 20:32:27 -0700323 void WaitUntilAccessible(Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700324 REQUIRES(Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700325
Mathieu Chartier893263b2014-03-04 11:07:42 -0800326 bool log_new_roots_ GUARDED_BY(Locks::intern_table_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700327 ConditionVariable weak_intern_condition_ GUARDED_BY(Locks::intern_table_lock_);
Hiroshi Yamauchia91a4bc2014-06-13 16:44:55 -0700328 // Since this contains (strong) roots, they need a read barrier to
329 // enable concurrent intern table (strong) root scan. Do not
330 // directly access the strings in it. Use functions that contain
331 // read barriers.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100332 Table strong_interns_ GUARDED_BY(Locks::intern_table_lock_);
Mathieu Chartiercdfd39f2014-08-29 18:16:58 -0700333 std::vector<GcRoot<mirror::String>> new_strong_intern_roots_
Mathieu Chartier893263b2014-03-04 11:07:42 -0800334 GUARDED_BY(Locks::intern_table_lock_);
Hiroshi Yamauchia91a4bc2014-06-13 16:44:55 -0700335 // Since this contains (weak) roots, they need a read barrier. Do
336 // not directly access the strings in it. Use functions that contain
337 // read barriers.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100338 Table weak_interns_ GUARDED_BY(Locks::intern_table_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700339 // Weak root state, used for concurrent system weak processing and more.
340 gc::WeakRootState weak_root_state_ GUARDED_BY(Locks::intern_table_lock_);
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700341
Vladimir Marko4df2d802018-09-27 16:42:44 +0000342 friend class gc::space::ImageSpace;
Vladimir Markoca8de0a2018-07-04 11:56:08 +0100343 friend class linker::ImageWriter;
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700344 friend class Transaction;
Alexey Grebenkin21f23642016-12-02 17:44:54 +0300345 ART_FRIEND_TEST(InternTableTest, CrossHash);
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700346 DISALLOW_COPY_AND_ASSIGN(InternTable);
Brian Carlstrom7e93b502011-08-04 14:16:22 -0700347};
348
349} // namespace art
350
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700351#endif // ART_RUNTIME_INTERN_TABLE_H_