blob: 05f2794b3815834117f333cbba57d397421cb35e [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"
Mathieu Chartier14c3bf92015-07-13 14:35:43 -070026#include "gc/weak_root_state.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070027#include "gc_root.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
Vladimir Marko74527972016-11-29 15:57:32 +000041namespace linker {
42class OatWriter;
43} // namespace linker
44
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080045namespace mirror {
46class String;
47} // namespace mirror
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010048class Transaction;
Brian Carlstrom7e93b502011-08-04 14:16:22 -070049
Elliott Hughescf4c6c42011-09-01 15:16:42 -070050/**
51 * Used to intern strings.
52 *
53 * There are actually two tables: one that holds strong references to its strings, and one that
54 * holds weak references. The former is used for string literals, for which there is an effective
55 * reference from the constant pool. The latter is used for strings interned at runtime via
56 * String.intern. Some code (XML parsers being a prime example) relies on being able to intern
57 * arbitrarily many strings for the duration of a parse without permanently increasing the memory
58 * footprint.
59 */
Brian Carlstrom7e93b502011-08-04 14:16:22 -070060class InternTable {
61 public:
62 InternTable();
Brian Carlstroma663ea52011-08-19 23:33:41 -070063
Mathieu Chartier14c3bf92015-07-13 14:35:43 -070064 // Interns a potentially new string in the 'strong' table. May cause thread suspension.
Mathieu Chartier9e868092016-10-31 14:58:04 -070065 ObjPtr<mirror::String> InternStrong(int32_t utf16_length, const char* utf8_data)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070066 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Brian Carlstromc74255f2011-09-11 22:47:39 -070067
Mathieu Chartiered8990a2015-07-23 14:11:16 -070068 // Only used by image writer. Special version that may not cause thread suspension since the GC
Roland Levillain91d65e02016-01-19 15:59:16 +000069 // cannot be running while we are doing image writing. Maybe be called while while holding a
Mathieu Chartier90ef3db2015-08-04 15:19:41 -070070 // lock since there will not be thread suspension.
Mathieu Chartier9e868092016-10-31 14:58:04 -070071 ObjPtr<mirror::String> InternStrongImageString(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070072 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -070073
74 // 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(const char* utf8_data) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartiered8990a2015-07-23 14:11:16 -070076 REQUIRES(!Roles::uninterruptible_);
Brian Carlstromc74255f2011-09-11 22:47:39 -070077
Mathieu Chartier14c3bf92015-07-13 14:35:43 -070078 // Interns a potentially new string in the 'strong' table. May cause thread suspension.
Mathieu Chartier9e868092016-10-31 14:58:04 -070079 ObjPtr<mirror::String> InternStrong(ObjPtr<mirror::String> s)
80 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartiered8990a2015-07-23 14:11:16 -070081 REQUIRES(!Roles::uninterruptible_);
Brian Carlstroma663ea52011-08-19 23:33:41 -070082
Mathieu Chartier14c3bf92015-07-13 14:35:43 -070083 // Interns a potentially new string in the 'weak' table. May cause thread suspension.
Mathieu Chartier9e868092016-10-31 14:58:04 -070084 ObjPtr<mirror::String> InternWeak(ObjPtr<mirror::String> s) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartiered8990a2015-07-23 14:11:16 -070085 REQUIRES(!Roles::uninterruptible_);
Elliott Hughescf4c6c42011-09-01 15:16:42 -070086
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070087 void SweepInternTableWeaks(IsMarkedVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -070088 REQUIRES(!Locks::intern_table_lock_);
Elliott Hughescf4c6c42011-09-01 15:16:42 -070089
Mathieu Chartier9e868092016-10-31 14:58:04 -070090 bool ContainsWeak(ObjPtr<mirror::String> s) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartiered8990a2015-07-23 14:11:16 -070091 REQUIRES(!Locks::intern_table_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -070092
Mathieu Chartierfbc31082016-01-24 11:59:56 -080093 // Lookup a strong intern, returns null if not found.
Mathieu Chartier9e868092016-10-31 14:58:04 -070094 ObjPtr<mirror::String> LookupStrong(Thread* self, ObjPtr<mirror::String> s)
Mathieu Chartierfbc31082016-01-24 11:59:56 -080095 REQUIRES(!Locks::intern_table_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070096 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -070097 ObjPtr<mirror::String> LookupStrong(Thread* self, uint32_t utf16_length, const char* utf8_data)
Vladimir Markocac5a7e2016-02-22 10:39:50 +000098 REQUIRES(!Locks::intern_table_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070099 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800100
101 // Lookup a weak intern, returns null if not found.
Mathieu Chartier9e868092016-10-31 14:58:04 -0700102 ObjPtr<mirror::String> LookupWeak(Thread* self, ObjPtr<mirror::String> s)
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800103 REQUIRES(!Locks::intern_table_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700104 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800105
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700106 // Total number of interned strings.
Mathieu Chartier90443472015-07-16 20:32:27 -0700107 size_t Size() const REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800108
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700109 // Total number of weakly live interned strings.
Mathieu Chartier90443472015-07-16 20:32:27 -0700110 size_t StrongSize() const REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800111
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700112 // Total number of strongly live interned strings.
Mathieu Chartier90443472015-07-16 20:32:27 -0700113 size_t WeakSize() const REQUIRES(!Locks::intern_table_lock_);
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700114
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700115 void VisitRoots(RootVisitor* visitor, VisitRootFlags flags)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700116 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::intern_table_lock_);
Brian Carlstrom7e93b502011-08-04 14:16:22 -0700117
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700118 void DumpForSigQuit(std::ostream& os) const REQUIRES(!Locks::intern_table_lock_);
Elliott Hughescac6cc72011-11-03 20:31:21 -0700119
Hiroshi Yamauchi30493242016-11-03 13:06:52 -0700120 void BroadcastForNewInterns();
Mathieu Chartierc11d9b82013-09-19 10:01:59 -0700121
Mathieu Chartier205b7622016-01-06 15:47:09 -0800122 // Adds all of the resolved image strings from the image spaces into the intern table. The
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800123 // advantage of doing this is preventing expensive DexFile::FindStringId calls. Sets
Mathieu Chartier205b7622016-01-06 15:47:09 -0800124 // images_added_to_intern_table_ to true.
125 void AddImagesStringsToTable(const std::vector<gc::space::ImageSpace*>& image_spaces)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700126 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700127
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800128 // Add a new intern table for inserting to, previous intern tables are still there but no
129 // longer inserted into and ideally unmodified. This is done to prevent dirty pages.
130 void AddNewTable()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700131 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartierd39645e2015-06-09 17:50:29 -0700132
133 // Read the intern table from memory. The elements aren't copied, the intern hash set data will
134 // point to somewhere within ptr. Only reads the strong interns.
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800135 size_t AddTableFromMemory(const uint8_t* ptr) REQUIRES(!Locks::intern_table_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700136 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierd39645e2015-06-09 17:50:29 -0700137
138 // Write the post zygote intern table to a pointer. Only writes the strong interns since it is
139 // expected that there is no weak interns since this is called from the image writer.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700140 size_t WriteToMemory(uint8_t* ptr) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700141 REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartierd39645e2015-06-09 17:50:29 -0700142
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700143 // Change the weak root state. May broadcast to waiters.
144 void ChangeWeakRootState(gc::WeakRootState new_state)
Mathieu Chartier90443472015-07-16 20:32:27 -0700145 REQUIRES(!Locks::intern_table_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700146
Brian Carlstrom7e93b502011-08-04 14:16:22 -0700147 private:
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000148 // Modified UTF-8-encoded string treated as UTF16.
149 class Utf8String {
150 public:
151 Utf8String(uint32_t utf16_length, const char* utf8_data, int32_t hash)
152 : hash_(hash), utf16_length_(utf16_length), utf8_data_(utf8_data) { }
153
154 int32_t GetHash() const { return hash_; }
155 uint32_t GetUtf16Length() const { return utf16_length_; }
156 const char* GetUtf8Data() const { return utf8_data_; }
157
158 private:
159 int32_t hash_;
160 uint32_t utf16_length_;
161 const char* utf8_data_;
162 };
163
Mathieu Chartiercdfd39f2014-08-29 18:16:58 -0700164 class StringHashEquals {
165 public:
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800166 std::size_t operator()(const GcRoot<mirror::String>& root) const NO_THREAD_SAFETY_ANALYSIS;
167 bool operator()(const GcRoot<mirror::String>& a, const GcRoot<mirror::String>& b) const
Mathieu Chartiercdfd39f2014-08-29 18:16:58 -0700168 NO_THREAD_SAFETY_ANALYSIS;
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000169
170 // Utf8String can be used for lookup.
Alexey Grebenkin21f23642016-12-02 17:44:54 +0300171 std::size_t operator()(const Utf8String& key) const {
172 // A cast to prevent undesired sign extension.
173 return static_cast<uint32_t>(key.GetHash());
174 }
175
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000176 bool operator()(const GcRoot<mirror::String>& a, const Utf8String& b) const
177 NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartiercdfd39f2014-08-29 18:16:58 -0700178 };
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800179 class GcRootEmptyFn {
180 public:
181 void MakeEmpty(GcRoot<mirror::String>& item) const {
182 item = GcRoot<mirror::String>();
183 }
184 bool IsEmpty(const GcRoot<mirror::String>& item) const {
185 return item.IsNull();
186 }
187 };
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700188
189 // Table which holds pre zygote and post zygote interned strings. There is one instance for
190 // weak interns and strong interns.
191 class Table {
192 public:
Mathieu Chartier32cc9ee2015-10-15 09:19:15 -0700193 Table();
Mathieu Chartier9e868092016-10-31 14:58:04 -0700194 ObjPtr<mirror::String> Find(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 ObjPtr<mirror::String> Find(const Utf8String& string) REQUIRES_SHARED(Locks::mutator_lock_)
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000197 REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700198 void Insert(ObjPtr<mirror::String> s) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700199 REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700200 void Remove(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700201 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700202 void VisitRoots(RootVisitor* visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700203 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier97509952015-07-13 14:35:43 -0700204 void SweepWeaks(IsMarkedVisitor* visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700205 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800206 // Add a new intern table that will only be inserted into from now on.
207 void AddNewTable() REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier90443472015-07-16 20:32:27 -0700208 size_t Size() const REQUIRES(Locks::intern_table_lock_);
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800209 // Read and add an intern table from ptr.
210 // Tables read are inserted at the front of the table array. Only checks for conflicts in
211 // debug builds. Returns how many bytes were read.
212 size_t AddTableFromMemory(const uint8_t* ptr)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700213 REQUIRES(Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier205b7622016-01-06 15:47:09 -0800214 // Write the intern tables to ptr, if there are multiple tables they are combined into a single
215 // one. Returns how many bytes were written.
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800216 size_t WriteToMemory(uint8_t* ptr)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700217 REQUIRES(Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700218
219 private:
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800220 typedef HashSet<GcRoot<mirror::String>, GcRootEmptyFn, StringHashEquals, StringHashEquals,
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700221 TrackingAllocator<GcRoot<mirror::String>, kAllocatorTagInternTable>> UnorderedSet;
222
Mathieu Chartier97509952015-07-13 14:35:43 -0700223 void SweepWeaks(UnorderedSet* set, IsMarkedVisitor* visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700224 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700225
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800226 // We call AddNewTable when we create the zygote to reduce private dirty pages caused by
227 // modifying the zygote intern table. The back of table is modified when strings are interned.
228 std::vector<UnorderedSet> tables_;
Alexey Grebenkin21f23642016-12-02 17:44:54 +0300229
Vladimir Marko74527972016-11-29 15:57:32 +0000230 friend class linker::OatWriter; // for boot image string table slot address lookup.
Alexey Grebenkin21f23642016-12-02 17:44:54 +0300231 ART_FRIEND_TEST(InternTableTest, CrossHash);
Mathieu Chartiereb175f72014-10-31 11:49:27 -0700232 };
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700233
Mathieu Chartier90ef3db2015-08-04 15:19:41 -0700234 // Insert if non null, otherwise return null. Must be called holding the mutator lock.
235 // If holding_locks is true, then we may also hold other locks. If holding_locks is true, then we
236 // require GC is not running since it is not safe to wait while holding locks.
Mathieu Chartier9e868092016-10-31 14:58:04 -0700237 ObjPtr<mirror::String> Insert(ObjPtr<mirror::String> s, bool is_strong, bool holding_locks)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700238 REQUIRES(!Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700239
Mathieu Chartier9e868092016-10-31 14:58:04 -0700240 ObjPtr<mirror::String> LookupStrongLocked(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700241 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700242 ObjPtr<mirror::String> LookupWeakLocked(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700243 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700244 ObjPtr<mirror::String> InsertStrong(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700245 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700246 ObjPtr<mirror::String> InsertWeak(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700247 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700248 void RemoveStrong(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700249 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700250 void RemoveWeak(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700251 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700252
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100253 // Transaction rollback access.
Mathieu Chartier9e868092016-10-31 14:58:04 -0700254 ObjPtr<mirror::String> InsertStrongFromTransaction(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700255 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700256 ObjPtr<mirror::String> InsertWeakFromTransaction(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700257 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700258 void RemoveStrongFromTransaction(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700259 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier9e868092016-10-31 14:58:04 -0700260 void RemoveWeakFromTransaction(ObjPtr<mirror::String> s)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700261 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::intern_table_lock_);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100262
Mathieu Chartierea0831f2015-12-29 13:17:37 -0800263 size_t AddTableFromMemoryLocked(const uint8_t* ptr)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700264 REQUIRES(Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierd39645e2015-06-09 17:50:29 -0700265
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700266 // Change the weak root state. May broadcast to waiters.
267 void ChangeWeakRootStateLocked(gc::WeakRootState new_state)
Mathieu Chartier90443472015-07-16 20:32:27 -0700268 REQUIRES(Locks::intern_table_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700269
270 // Wait until we can read weak roots.
Mathieu Chartier90443472015-07-16 20:32:27 -0700271 void WaitUntilAccessible(Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700272 REQUIRES(Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700273
Mathieu Chartier893263b2014-03-04 11:07:42 -0800274 bool log_new_roots_ GUARDED_BY(Locks::intern_table_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700275 ConditionVariable weak_intern_condition_ GUARDED_BY(Locks::intern_table_lock_);
Hiroshi Yamauchia91a4bc2014-06-13 16:44:55 -0700276 // Since this contains (strong) roots, they need a read barrier to
277 // enable concurrent intern table (strong) root scan. Do not
278 // directly access the strings in it. Use functions that contain
279 // read barriers.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100280 Table strong_interns_ GUARDED_BY(Locks::intern_table_lock_);
Mathieu Chartiercdfd39f2014-08-29 18:16:58 -0700281 std::vector<GcRoot<mirror::String>> new_strong_intern_roots_
Mathieu Chartier893263b2014-03-04 11:07:42 -0800282 GUARDED_BY(Locks::intern_table_lock_);
Hiroshi Yamauchia91a4bc2014-06-13 16:44:55 -0700283 // Since this contains (weak) roots, they need a read barrier. Do
284 // not directly access the strings in it. Use functions that contain
285 // read barriers.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100286 Table weak_interns_ GUARDED_BY(Locks::intern_table_lock_);
Mathieu Chartier14c3bf92015-07-13 14:35:43 -0700287 // Weak root state, used for concurrent system weak processing and more.
288 gc::WeakRootState weak_root_state_ GUARDED_BY(Locks::intern_table_lock_);
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700289
Vladimir Marko74527972016-11-29 15:57:32 +0000290 friend class linker::OatWriter; // for boot image string table slot address lookup.
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700291 friend class Transaction;
Alexey Grebenkin21f23642016-12-02 17:44:54 +0300292 ART_FRIEND_TEST(InternTableTest, CrossHash);
Mathieu Chartiered8990a2015-07-23 14:11:16 -0700293 DISALLOW_COPY_AND_ASSIGN(InternTable);
Brian Carlstrom7e93b502011-08-04 14:16:22 -0700294};
295
296} // namespace art
297
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700298#endif // ART_RUNTIME_INTERN_TABLE_H_