blob: d115f51f7e2ada9e395e79b07e117da8e8a6905c [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"
Vladimir Marko365c0202022-03-22 09:53:31 +000021#include "base/dchecked_vector.h"
Mathieu Chartierc2e20622014-11-03 11:41:47 -080022#include "base/hash_set.h"
Ian Rogers719d1a32014-03-06 12:13:39 -080023#include "base/mutex.h"
Mathieu Chartier14c3bf92015-07-13 14:35:43 -070024#include "gc/weak_root_state.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070025#include "gc_root.h"
Ian Rogers719d1a32014-03-06 12:13:39 -080026
Brian Carlstrom7e93b502011-08-04 14:16:22 -070027namespace art {
Mathieu Chartier893263b2014-03-04 11:07:42 -080028
Andreas Gampe5d08fcc2017-06-05 17:56:46 -070029class IsMarkedVisitor;
30
Mathieu Chartiereb175f72014-10-31 11:49:27 -070031namespace gc {
32namespace space {
33class ImageSpace;
34} // namespace space
35} // namespace gc
36
Mathieu Chartier893263b2014-03-04 11:07:42 -080037enum VisitRootFlags : uint8_t;
38
Vladimir Marko74527972016-11-29 15:57:32 +000039namespace linker {
Vladimir Markoca8de0a2018-07-04 11:56:08 +010040class ImageWriter;
Vladimir Marko74527972016-11-29 15:57:32 +000041} // namespace linker
42
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080043namespace mirror {
44class String;
45} // namespace mirror
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010046class Transaction;
Brian Carlstrom7e93b502011-08-04 14:16:22 -070047
Elliott Hughescf4c6c42011-09-01 15:16:42 -070048/**
49 * Used to intern strings.
50 *
51 * There are actually two tables: one that holds strong references to its strings, and one that
52 * holds weak references. The former is used for string literals, for which there is an effective
53 * reference from the constant pool. The latter is used for strings interned at runtime via
54 * String.intern. Some code (XML parsers being a prime example) relies on being able to intern
55 * arbitrarily many strings for the duration of a parse without permanently increasing the memory
56 * footprint.
57 */
Brian Carlstrom7e93b502011-08-04 14:16:22 -070058class InternTable {
59 public:
Mathieu Chartier74ccee62018-10-10 10:30:29 -070060 // Modified UTF-8-encoded string treated as UTF16.
61 class Utf8String {
62 public:
Vladimir Marko365c0202022-03-22 09:53:31 +000063 Utf8String(uint32_t utf16_length, const char* utf8_data)
64 : utf16_length_(utf16_length), utf8_data_(utf8_data) { }
Mathieu Chartier74ccee62018-10-10 10:30:29 -070065
Vladimir Marko365c0202022-03-22 09:53:31 +000066 uint32_t GetHash() const { return Hash(utf16_length_, utf8_data_); }
Mathieu Chartier74ccee62018-10-10 10:30:29 -070067 uint32_t GetUtf16Length() const { return utf16_length_; }
68 const char* GetUtf8Data() const { return utf8_data_; }
69
Vladimir Marko365c0202022-03-22 09:53:31 +000070 static uint32_t Hash(uint32_t utf16_length, const char* utf8_data);
Vladimir Marko4625f252022-02-23 11:20:26 +000071
Mathieu Chartier74ccee62018-10-10 10:30:29 -070072 private:
Mathieu Chartier74ccee62018-10-10 10:30:29 -070073 uint32_t utf16_length_;
74 const char* utf8_data_;
75 };
76
Vladimir Markoeae6a712021-02-05 13:33:28 +000077 class StringHash {
Mathieu Chartier74ccee62018-10-10 10:30:29 -070078 public:
Vladimir Marko365c0202022-03-22 09:53:31 +000079 // NO_THREAD_SAFETY_ANALYSIS: Used from unannotated `HashSet<>` functions.
80 size_t operator()(const GcRoot<mirror::String>& root) const NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartier74ccee62018-10-10 10:30:29 -070081
Vladimir Marko365c0202022-03-22 09:53:31 +000082 // Utf8String can be used for lookup. While we're passing the hash explicitly to all
83 // `HashSet<>` functions, they `DCHECK()` the supplied hash against the hash we provide here.
84 size_t operator()(const Utf8String& key) const {
85 static_assert(std::is_same_v<uint32_t, decltype(key.GetHash())>);
86 return key.GetHash();
Mathieu Chartier74ccee62018-10-10 10:30:29 -070087 }
Vladimir Markoeae6a712021-02-05 13:33:28 +000088 };
Mathieu Chartier74ccee62018-10-10 10:30:29 -070089
Vladimir Markoeae6a712021-02-05 13:33:28 +000090 class StringEquals {
91 public:
Vladimir Marko365c0202022-03-22 09:53:31 +000092 // NO_THREAD_SAFETY_ANALYSIS: Used from unannotated `HashSet<>` functions.
Vladimir Markoeae6a712021-02-05 13:33:28 +000093 bool operator()(const GcRoot<mirror::String>& a, const GcRoot<mirror::String>& b) const
94 NO_THREAD_SAFETY_ANALYSIS;
95
96 // Utf8String can be used for lookup.
Vladimir Marko365c0202022-03-22 09:53:31 +000097 // NO_THREAD_SAFETY_ANALYSIS: Used from unannotated `HashSet<>` functions.
Mathieu Chartier74ccee62018-10-10 10:30:29 -070098 bool operator()(const GcRoot<mirror::String>& a, const Utf8String& b) const
99 NO_THREAD_SAFETY_ANALYSIS;
100 };
101
102 class GcRootEmptyFn {
103 public:
104 void MakeEmpty(GcRoot<mirror::String>& item) const {
105 item = GcRoot<mirror::String>();
106 }
107 bool IsEmpty(const GcRoot<mirror::String>& item) const {
108 return item.IsNull();
109 }
110 };
111
112 using UnorderedSet = HashSet<GcRoot<mirror::String>,
113 GcRootEmptyFn,
Vladimir Markoeae6a712021-02-05 13:33:28 +0000114 StringHash,
115 StringEquals,
Mathieu Chartier74ccee62018-10-10 10:30:29 -0700116 TrackingAllocator<GcRoot<mirror::String>, kAllocatorTagInternTable>>;
117
Brian Carlstrom7e93b502011-08-04 14:16:22 -0700118 InternTable();
Brian Carlstroma663ea52011-08-19 23:33:41 -0700119
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700120 // Interns a potentially new string in the 'strong' table. May cause thread suspension.
Vladimir Marko4625f252022-02-23 11:20:26 +0000121 ObjPtr<mirror::String> InternStrong(uint32_t utf16_length, const char* utf8_data)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700122 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Brian Carlstromc74255f2011-09-11 22:47:39 -0700123
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700124 // Interns a potentially new string in the 'strong' table. May cause thread suspension.
Mathieu Chartier9e868092016-10-31 14:58:04 -0700125 ObjPtr<mirror::String> InternStrong(const char* utf8_data) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700126 REQUIRES(!Roles::uninterruptible_);
Brian Carlstromc74255f2011-09-11 22:47:39 -0700127
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700128 // Interns a potentially new string in the 'strong' table. May cause thread suspension.
Mathieu Chartier9e868092016-10-31 14:58:04 -0700129 ObjPtr<mirror::String> InternStrong(ObjPtr<mirror::String> s)
130 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700131 REQUIRES(!Roles::uninterruptible_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700132
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700133 // Interns a potentially new string in the 'weak' table. May cause thread suspension.
Vladimir Marko31c3daa2019-06-13 12:18:37 +0100134 ObjPtr<mirror::String> InternWeak(const char* utf8_data) REQUIRES_SHARED(Locks::mutator_lock_)
135 REQUIRES(!Roles::uninterruptible_);
136
137 // Interns a potentially new string in the 'weak' table. May cause thread suspension.
Mathieu Chartier9e868092016-10-31 14:58:04 -0700138 ObjPtr<mirror::String> InternWeak(ObjPtr<mirror::String> s) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700139 REQUIRES(!Roles::uninterruptible_);
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700140
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700141 void SweepInternTableWeaks(IsMarkedVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700142 REQUIRES(!Locks::intern_table_lock_);
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700143
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800144 // Lookup a strong intern, returns null if not found.
Mathieu Chartier9e868092016-10-31 14:58:04 -0700145 ObjPtr<mirror::String> LookupStrong(Thread* self, ObjPtr<mirror::String> s)
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800146 REQUIRES(!Locks::intern_table_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700147 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700148 ObjPtr<mirror::String> LookupStrong(Thread* self, uint32_t utf16_length, const char* utf8_data)
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000149 REQUIRES(!Locks::intern_table_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700150 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier41c08082018-10-31 11:50:26 -0700151 ObjPtr<mirror::String> LookupStrongLocked(ObjPtr<mirror::String> s)
152 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800153
154 // Lookup a weak intern, returns null if not found.
Mathieu Chartier9e868092016-10-31 14:58:04 -0700155 ObjPtr<mirror::String> LookupWeak(Thread* self, ObjPtr<mirror::String> s)
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800156 REQUIRES(!Locks::intern_table_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700157 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier41c08082018-10-31 11:50:26 -0700158 ObjPtr<mirror::String> LookupWeakLocked(ObjPtr<mirror::String> s)
159 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800160
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700161 // Total number of interned strings.
Mathieu Chartier90443472015-07-16 20:32:27 -0700162 size_t Size() const REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800163
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700164 // Total number of weakly live interned strings.
Mathieu Chartier90443472015-07-16 20:32:27 -0700165 size_t StrongSize() const REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800166
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700167 // Total number of strongly live interned strings.
Mathieu Chartier90443472015-07-16 20:32:27 -0700168 size_t WeakSize() const REQUIRES(!Locks::intern_table_lock_);
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700169
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700170 void VisitRoots(RootVisitor* visitor, VisitRootFlags flags)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700171 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::intern_table_lock_);
Brian Carlstrom7e93b502011-08-04 14:16:22 -0700172
Mathieu Chartier8cc418e2018-10-31 10:54:30 -0700173 // Visit all of the interns in the table.
174 template <typename Visitor>
175 void VisitInterns(const Visitor& visitor,
176 bool visit_boot_images,
177 bool visit_non_boot_images)
178 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
179
Mathieu Chartier8fc75582018-11-01 14:21:33 -0700180 // Count the number of intern strings in the table.
181 size_t CountInterns(bool visit_boot_images, bool visit_non_boot_images) const
182 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
183
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700184 void DumpForSigQuit(std::ostream& os) const REQUIRES(!Locks::intern_table_lock_);
Elliott Hughescac6cc72011-11-03 20:31:21 -0700185
Hiroshi Yamauchi30493242016-11-03 13:06:52 -0700186 void BroadcastForNewInterns();
Mathieu Chartierc11d9b82013-09-19 10:01:59 -0700187
Mathieu Chartier74ccee62018-10-10 10:30:29 -0700188 // Add all of the strings in the image's intern table into this intern table. This is required so
189 // the intern table is correct.
190 // The visitor arg type is UnorderedSet
191 template <typename Visitor>
192 void AddImageStringsToTable(gc::space::ImageSpace* image_space,
193 const Visitor& visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700194 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700195
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800196 // Add a new intern table for inserting to, previous intern tables are still there but no
197 // longer inserted into and ideally unmodified. This is done to prevent dirty pages.
198 void AddNewTable()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700199 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartierd39645e2015-06-09 17:50:29 -0700200
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700201 // Change the weak root state. May broadcast to waiters.
202 void ChangeWeakRootState(gc::WeakRootState new_state)
Mathieu Chartier90443472015-07-16 20:32:27 -0700203 REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700204
Brian Carlstrom7e93b502011-08-04 14:16:22 -0700205 private:
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700206 // Table which holds pre zygote and post zygote interned strings. There is one instance for
207 // weak interns and strong interns.
208 class Table {
209 public:
Mathieu Chartier8cc418e2018-10-31 10:54:30 -0700210 class InternalTable {
211 public:
212 InternalTable() = default;
213 InternalTable(UnorderedSet&& set, bool is_boot_image)
214 : set_(std::move(set)), is_boot_image_(is_boot_image) {}
215
216 bool Empty() const {
217 return set_.empty();
218 }
219
220 size_t Size() const {
221 return set_.size();
222 }
223
224 bool IsBootImage() const {
225 return is_boot_image_;
226 }
227
228 private:
229 UnorderedSet set_;
230 bool is_boot_image_ = false;
231
232 friend class InternTable;
Vladimir Marko151e23a2021-01-22 10:11:13 +0000233 friend class linker::ImageWriter;
Mathieu Chartier8cc418e2018-10-31 10:54:30 -0700234 friend class Table;
235 ART_FRIEND_TEST(InternTableTest, CrossHash);
236 };
237
Mathieu Chartier32cc9ee2015-10-15 09:19:15 -0700238 Table();
Vladimir Marko47eea602022-04-04 10:27:25 +0000239 ObjPtr<mirror::String> Find(ObjPtr<mirror::String> s,
240 uint32_t hash,
241 size_t num_searched_frozen_tables = 0u)
Vladimir Marko365c0202022-03-22 09:53:31 +0000242 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
243 ObjPtr<mirror::String> Find(const Utf8String& string, uint32_t hash)
244 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
245 void Insert(ObjPtr<mirror::String> s, uint32_t hash)
246 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
247 void Remove(ObjPtr<mirror::String> s, uint32_t hash)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700248 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700249 void VisitRoots(RootVisitor* visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700250 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier97509952015-07-13 14:35:43 -0700251 void SweepWeaks(IsMarkedVisitor* visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700252 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800253 // Add a new intern table that will only be inserted into from now on.
254 void AddNewTable() REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier90443472015-07-16 20:32:27 -0700255 size_t Size() const REQUIRES(Locks::intern_table_lock_);
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800256 // Read and add an intern table from ptr.
257 // Tables read are inserted at the front of the table array. Only checks for conflicts in
258 // debug builds. Returns how many bytes were read.
Mathieu Chartier74ccee62018-10-10 10:30:29 -0700259 // NO_THREAD_SAFETY_ANALYSIS for the visitor that may require locks.
260 template <typename Visitor>
Mathieu Chartier8cc418e2018-10-31 10:54:30 -0700261 size_t AddTableFromMemory(const uint8_t* ptr, const Visitor& visitor, bool is_boot_image)
Mathieu Chartier74ccee62018-10-10 10:30:29 -0700262 REQUIRES(!Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700263
264 private:
Mathieu Chartier97509952015-07-13 14:35:43 -0700265 void SweepWeaks(UnorderedSet* set, IsMarkedVisitor* visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700266 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700267
Mathieu Chartier74ccee62018-10-10 10:30:29 -0700268 // Add a table to the front of the tables vector.
Mathieu Chartier8cc418e2018-10-31 10:54:30 -0700269 void AddInternStrings(UnorderedSet&& intern_strings, bool is_boot_image)
Mathieu Chartier74ccee62018-10-10 10:30:29 -0700270 REQUIRES(Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
271
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800272 // We call AddNewTable when we create the zygote to reduce private dirty pages caused by
273 // modifying the zygote intern table. The back of table is modified when strings are interned.
Vladimir Marko365c0202022-03-22 09:53:31 +0000274 dchecked_vector<InternalTable> tables_;
Alexey Grebenkin21f23642016-12-02 17:44:54 +0300275
Mathieu Chartier74ccee62018-10-10 10:30:29 -0700276 friend class InternTable;
Vladimir Markoca8de0a2018-07-04 11:56:08 +0100277 friend class linker::ImageWriter;
Alexey Grebenkin21f23642016-12-02 17:44:54 +0300278 ART_FRIEND_TEST(InternTableTest, CrossHash);
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700279 };
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700280
Mathieu Chartier90ef3db2015-08-04 15:19:41 -0700281 // Insert if non null, otherwise return null. Must be called holding the mutator lock.
Vladimir Marko47eea602022-04-04 10:27:25 +0000282 ObjPtr<mirror::String> Insert(ObjPtr<mirror::String> s,
283 uint32_t hash,
284 bool is_strong,
285 size_t num_searched_strong_frozen_tables = 0u)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700286 REQUIRES(!Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700287
Mathieu Chartier74ccee62018-10-10 10:30:29 -0700288 // Add a table from memory to the strong interns.
289 template <typename Visitor>
Mathieu Chartier8cc418e2018-10-31 10:54:30 -0700290 size_t AddTableFromMemory(const uint8_t* ptr, const Visitor& visitor, bool is_boot_image)
Mathieu Chartier74ccee62018-10-10 10:30:29 -0700291 REQUIRES(!Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
292
Vladimir Marko365c0202022-03-22 09:53:31 +0000293 // Note: Transaction rollback calls these helper functions directly.
294 ObjPtr<mirror::String> InsertStrong(ObjPtr<mirror::String> s, uint32_t hash)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700295 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Vladimir Marko365c0202022-03-22 09:53:31 +0000296 ObjPtr<mirror::String> InsertWeak(ObjPtr<mirror::String> s, uint32_t hash)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700297 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Vladimir Marko365c0202022-03-22 09:53:31 +0000298 void RemoveStrong(ObjPtr<mirror::String> s, uint32_t hash)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700299 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Vladimir Marko365c0202022-03-22 09:53:31 +0000300 void RemoveWeak(ObjPtr<mirror::String> s, uint32_t hash)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700301 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100302
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700303 // Change the weak root state. May broadcast to waiters.
304 void ChangeWeakRootStateLocked(gc::WeakRootState new_state)
Mathieu Chartier90443472015-07-16 20:32:27 -0700305 REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700306
307 // Wait until we can read weak roots.
Mathieu Chartier90443472015-07-16 20:32:27 -0700308 void WaitUntilAccessible(Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700309 REQUIRES(Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700310
Mathieu Chartier893263b2014-03-04 11:07:42 -0800311 bool log_new_roots_ GUARDED_BY(Locks::intern_table_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700312 ConditionVariable weak_intern_condition_ GUARDED_BY(Locks::intern_table_lock_);
Hiroshi Yamauchia91a4bc2014-06-13 16:44:55 -0700313 // Since this contains (strong) roots, they need a read barrier to
314 // enable concurrent intern table (strong) root scan. Do not
315 // directly access the strings in it. Use functions that contain
316 // read barriers.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100317 Table strong_interns_ GUARDED_BY(Locks::intern_table_lock_);
Vladimir Marko365c0202022-03-22 09:53:31 +0000318 dchecked_vector<GcRoot<mirror::String>> new_strong_intern_roots_
Mathieu Chartier893263b2014-03-04 11:07:42 -0800319 GUARDED_BY(Locks::intern_table_lock_);
Hiroshi Yamauchia91a4bc2014-06-13 16:44:55 -0700320 // Since this contains (weak) roots, they need a read barrier. Do
321 // not directly access the strings in it. Use functions that contain
322 // read barriers.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100323 Table weak_interns_ GUARDED_BY(Locks::intern_table_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700324 // Weak root state, used for concurrent system weak processing and more.
325 gc::WeakRootState weak_root_state_ GUARDED_BY(Locks::intern_table_lock_);
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700326
Vladimir Marko4df2d802018-09-27 16:42:44 +0000327 friend class gc::space::ImageSpace;
Vladimir Markoca8de0a2018-07-04 11:56:08 +0100328 friend class linker::ImageWriter;
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700329 friend class Transaction;
Alexey Grebenkin21f23642016-12-02 17:44:54 +0300330 ART_FRIEND_TEST(InternTableTest, CrossHash);
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700331 DISALLOW_COPY_AND_ASSIGN(InternTable);
Brian Carlstrom7e93b502011-08-04 14:16:22 -0700332};
333
334} // namespace art
335
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700336#endif // ART_RUNTIME_INTERN_TABLE_H_