blob: 652fcdfa05fbc026a7093d6c242983da91d723ab [file] [log] [blame]
Elliott Hughes6c1a3942011-08-17 15:00:06 -07001/*
2 * Copyright (C) 2009 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 */
16
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_INDIRECT_REFERENCE_TABLE_H_
18#define ART_RUNTIME_INDIRECT_REFERENCE_TABLE_H_
Elliott Hughes6c1a3942011-08-17 15:00:06 -070019
Elliott Hughes07ed66b2012-12-12 18:34:25 -080020#include <stdint.h>
Elliott Hughes6c1a3942011-08-17 15:00:06 -070021
22#include <iosfwd>
Andreas Gampee03662b2016-10-13 17:12:56 -070023#include <limits>
Elliott Hughes6c1a3942011-08-17 15:00:06 -070024#include <string>
25
Andreas Gampedc061d02016-10-24 13:19:37 -070026#include "base/bit_utils.h"
Elliott Hughes07ed66b2012-12-12 18:34:25 -080027#include "base/logging.h"
Ian Rogers719d1a32014-03-06 12:13:39 -080028#include "base/mutex.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070029#include "gc_root.h"
Mathieu Chartier8778c522016-10-04 19:06:30 -070030#include "obj_ptr.h"
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080031#include "object_callbacks.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032#include "offsets.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070033#include "read_barrier_option.h"
Elliott Hughes07ed66b2012-12-12 18:34:25 -080034
Elliott Hughes6c1a3942011-08-17 15:00:06 -070035namespace art {
Ian Rogers68d8b422014-07-17 11:09:10 -070036
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -080037class RootInfo;
38
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080039namespace mirror {
Elliott Hughes6c1a3942011-08-17 15:00:06 -070040class Object;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080041} // namespace mirror
Elliott Hughes6c1a3942011-08-17 15:00:06 -070042
Ian Rogers68d8b422014-07-17 11:09:10 -070043class MemMap;
44
Andreas Gampee03662b2016-10-13 17:12:56 -070045// Maintain a table of indirect references. Used for local/global JNI references.
46//
47// The table contains object references, where the strong (local/global) references are part of the
48// GC root set (but not the weak global references). When an object is added we return an
49// IndirectRef that is not a valid pointer but can be used to find the original value in O(1) time.
50// Conversions to and from indirect references are performed on upcalls and downcalls, so they need
51// to be very fast.
52//
53// To be efficient for JNI local variable storage, we need to provide operations that allow us to
54// operate on segments of the table, where segments are pushed and popped as if on a stack. For
55// example, deletion of an entry should only succeed if it appears in the current segment, and we
56// want to be able to strip off the current segment quickly when a method returns. Additions to the
57// table must be made in the current segment even if space is available in an earlier area.
58//
59// A new segment is created when we call into native code from interpreted code, or when we handle
60// the JNI PushLocalFrame function.
61//
62// The GC must be able to scan the entire table quickly.
63//
64// In summary, these must be very fast:
65// - adding or removing a segment
66// - adding references to a new segment
67// - converting an indirect reference back to an Object
68// These can be a little slower, but must still be pretty quick:
69// - adding references to a "mature" segment
70// - removing individual references
71// - scanning the entire table straight through
72//
73// If there's more than one segment, we don't guarantee that the table will fill completely before
74// we fail due to lack of space. We do ensure that the current segment will pack tightly, which
75// should satisfy JNI requirements (e.g. EnsureLocalCapacity).
76//
77// Only SynchronizedGet is synchronized.
Elliott Hughes6c1a3942011-08-17 15:00:06 -070078
Andreas Gampee03662b2016-10-13 17:12:56 -070079// Indirect reference definition. This must be interchangeable with JNI's jobject, and it's
80// convenient to let null be null, so we use void*.
81//
82// We need a (potentially) large table index and a 2-bit reference type (global, local, weak
83// global). We also reserve some bits to be used to detect stale indirect references: we put a
84// serial number in the extra bits, and keep a copy of the serial number in the table. This requires
85// more memory and additional memory accesses on add/get, but is moving-GC safe. It will catch
86// additional problems, e.g.: create iref1 for obj, delete iref1, create iref2 for same obj,
87// lookup iref1. A pattern based on object bits will miss this.
Elliott Hughes6c1a3942011-08-17 15:00:06 -070088typedef void* IndirectRef;
89
Andreas Gampee03662b2016-10-13 17:12:56 -070090// Indirect reference kind, used as the two low bits of IndirectRef.
91//
92// For convenience these match up with enum jobjectRefType from jni.h.
Elliott Hughes6c1a3942011-08-17 15:00:06 -070093enum IndirectRefKind {
Andreas Gampedc061d02016-10-24 13:19:37 -070094 kHandleScopeOrInvalid = 0, // <<stack indirect reference table or invalid reference>>
95 kLocal = 1, // <<local reference>>
96 kGlobal = 2, // <<global reference>>
97 kWeakGlobal = 3, // <<weak global reference>>
98 kLastKind = kWeakGlobal
Elliott Hughes6c1a3942011-08-17 15:00:06 -070099};
Elliott Hughes0e57ccb2012-04-03 16:04:52 -0700100std::ostream& operator<<(std::ostream& os, const IndirectRefKind& rhs);
Andreas Gampef1e86302016-10-03 11:42:31 -0700101const char* GetIndirectRefKindString(const IndirectRefKind& kind);
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700102
Andreas Gampee03662b2016-10-13 17:12:56 -0700103// Table definition.
104//
105// For the global reference table, the expected common operations are adding a new entry and
106// removing a recently-added entry (usually the most-recently-added entry). For JNI local
107// references, the common operations are adding a new entry and removing an entire table segment.
108//
109// If we delete entries from the middle of the list, we will be left with "holes". We track the
110// number of holes so that, when adding new elements, we can quickly decide to do a trivial append
111// or go slot-hunting.
112//
113// When the top-most entry is removed, any holes immediately below it are also removed. Thus,
114// deletion of an entry may reduce "top_index" by more than one.
115//
116// To get the desired behavior for JNI locals, we need to know the bottom and top of the current
117// "segment". The top is managed internally, and the bottom is passed in as a function argument.
118// When we call a native method or push a local frame, the current top index gets pushed on, and
119// serves as the new bottom. When we pop a frame off, the value from the stack becomes the new top
120// index, and the value stored in the previous frame becomes the new bottom.
121//
122// Holes are being locally cached for the segment. Otherwise we'd have to pass bottom index and
123// number of holes, which restricts us to 16 bits for the top index. The value is cached within the
124// table. To avoid code in generated JNI transitions, which implicitly form segments, the code for
125// adding and removing references needs to detect the change of a segment. Helper fields are used
126// for this detection.
127//
128// Common alternative implementation: make IndirectRef a pointer to the actual reference slot.
129// Instead of getting a table and doing a lookup, the lookup can be done instantly. Operations like
130// determining the type and deleting the reference are more expensive because the table must be
131// hunted for (i.e. you have to do a pointer comparison to see which table it's in), you can't move
132// the table when expanding it (so realloc() is out), and tricks like serial number checking to
133// detect stale references aren't possible (though we may be able to get similar benefits with other
134// approaches).
135//
136// TODO: consider a "lastDeleteIndex" for quick hole-filling when an add immediately follows a
137// delete; must invalidate after segment pop might be worth only using it for JNI globals.
138//
139// TODO: may want completely different add/remove algorithms for global and local refs to improve
140// performance. A large circular buffer might reduce the amortized cost of adding global
141// references.
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700142
Andreas Gampee03662b2016-10-13 17:12:56 -0700143// The state of the current segment. We only store the index. Splitting it for index and hole
144// count restricts the range too much.
145struct IRTSegmentState {
146 uint32_t top_index;
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700147};
148
Andreas Gampee03662b2016-10-13 17:12:56 -0700149// Use as initial value for "cookie", and when table has only one segment.
150static constexpr IRTSegmentState kIRTFirstSegment = { 0 };
151
Mathieu Chartier4838d662014-09-25 15:27:43 -0700152// Try to choose kIRTPrevCount so that sizeof(IrtEntry) is a power of 2.
153// Contains multiple entries but only one active one, this helps us detect use after free errors
154// since the serial stored in the indirect ref wont match.
Andreas Gampedc061d02016-10-24 13:19:37 -0700155static constexpr size_t kIRTPrevCount = kIsDebugBuild ? 7 : 3;
156
Hiroshi Yamauchi9e47bfa2015-02-23 11:14:40 -0800157class IrtEntry {
Mathieu Chartier4838d662014-09-25 15:27:43 -0700158 public:
Mathieu Chartier8778c522016-10-04 19:06:30 -0700159 void Add(ObjPtr<mirror::Object> obj) REQUIRES_SHARED(Locks::mutator_lock_);
160
Mathieu Chartier4838d662014-09-25 15:27:43 -0700161 GcRoot<mirror::Object>* GetReference() {
162 DCHECK_LT(serial_, kIRTPrevCount);
163 return &references_[serial_];
164 }
Mathieu Chartier8778c522016-10-04 19:06:30 -0700165
Andreas Gampee03662b2016-10-13 17:12:56 -0700166 const GcRoot<mirror::Object>* GetReference() const {
167 DCHECK_LT(serial_, kIRTPrevCount);
168 return &references_[serial_];
169 }
170
Mathieu Chartier4838d662014-09-25 15:27:43 -0700171 uint32_t GetSerial() const {
172 return serial_;
173 }
Mathieu Chartier8778c522016-10-04 19:06:30 -0700174
175 void SetReference(ObjPtr<mirror::Object> obj) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier4838d662014-09-25 15:27:43 -0700176
177 private:
178 uint32_t serial_;
179 GcRoot<mirror::Object> references_[kIRTPrevCount];
180};
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700181static_assert(sizeof(IrtEntry) == (1 + kIRTPrevCount) * sizeof(uint32_t),
Hiroshi Yamauchi9e47bfa2015-02-23 11:14:40 -0800182 "Unexpected sizeof(IrtEntry)");
Andreas Gampedc061d02016-10-24 13:19:37 -0700183static_assert(IsPowerOfTwo(sizeof(IrtEntry)), "Unexpected sizeof(IrtEntry)");
Mathieu Chartier4838d662014-09-25 15:27:43 -0700184
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700185class IrtIterator {
186 public:
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700187 IrtIterator(IrtEntry* table, size_t i, size_t capacity) REQUIRES_SHARED(Locks::mutator_lock_)
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700188 : table_(table), i_(i), capacity_(capacity) {
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700189 }
190
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700191 IrtIterator& operator++() REQUIRES_SHARED(Locks::mutator_lock_) {
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700192 ++i_;
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700193 return *this;
194 }
195
Mathieu Chartier8778c522016-10-04 19:06:30 -0700196 GcRoot<mirror::Object>* operator*() REQUIRES_SHARED(Locks::mutator_lock_) {
Hiroshi Yamauchiea2e1bd2014-06-18 13:47:35 -0700197 // This does not have a read barrier as this is used to visit roots.
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700198 return table_[i_].GetReference();
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700199 }
200
201 bool equals(const IrtIterator& rhs) const {
202 return (i_ == rhs.i_ && table_ == rhs.table_);
203 }
204
205 private:
Mathieu Chartier4838d662014-09-25 15:27:43 -0700206 IrtEntry* const table_;
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700207 size_t i_;
Ian Rogersc0542af2014-09-03 16:16:56 -0700208 const size_t capacity_;
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700209};
210
Elliott Hughes726079d2011-10-07 18:43:44 -0700211bool inline operator==(const IrtIterator& lhs, const IrtIterator& rhs) {
212 return lhs.equals(rhs);
213}
214
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700215bool inline operator!=(const IrtIterator& lhs, const IrtIterator& rhs) {
216 return !lhs.equals(rhs);
217}
218
219class IndirectReferenceTable {
220 public:
Andreas Gampee03662b2016-10-13 17:12:56 -0700221 // WARNING: Construction of the IndirectReferenceTable may fail.
222 // error_msg must not be null. If error_msg is set by the constructor, then
223 // construction has failed and the IndirectReferenceTable will be in an
224 // invalid state. Use IsValid to check whether the object is in an invalid
225 // state.
Richard Uhlerda0a69e2016-10-11 15:06:38 +0100226 IndirectReferenceTable(size_t max_count, IndirectRefKind kind, std::string* error_msg);
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700227
228 ~IndirectReferenceTable();
229
Richard Uhlerda0a69e2016-10-11 15:06:38 +0100230 /*
231 * Checks whether construction of the IndirectReferenceTable succeeded.
232 *
233 * This object must only be used if IsValid() returns true. It is safe to
234 * call IsValid from multiple threads without locking or other explicit
235 * synchronization.
236 */
Andreas Gampe3f5881f2015-04-08 10:26:16 -0700237 bool IsValid() const;
238
Andreas Gampee03662b2016-10-13 17:12:56 -0700239 // Add a new entry. "obj" must be a valid non-null object reference. This function will
240 // abort if the table is full (max entries reached, or expansion failed).
241 IndirectRef Add(IRTSegmentState previous_state, ObjPtr<mirror::Object> obj)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700242 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700243
Andreas Gampee03662b2016-10-13 17:12:56 -0700244 // Given an IndirectRef in the table, return the Object it refers to.
245 //
246 // This function may abort under error conditions.
Hiroshi Yamauchi196851b2014-05-29 12:16:04 -0700247 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier8778c522016-10-04 19:06:30 -0700248 ObjPtr<mirror::Object> Get(IndirectRef iref) const REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartierc56057e2014-05-04 13:18:58 -0700249 ALWAYS_INLINE;
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700250
Mathieu Chartierc56057e2014-05-04 13:18:58 -0700251 // Synchronized get which reads a reference, acquiring a lock if necessary.
Hiroshi Yamauchi196851b2014-05-29 12:16:04 -0700252 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier8778c522016-10-04 19:06:30 -0700253 ObjPtr<mirror::Object> SynchronizedGet(IndirectRef iref) const
254 REQUIRES_SHARED(Locks::mutator_lock_) {
Hiroshi Yamauchi196851b2014-05-29 12:16:04 -0700255 return Get<kReadBarrierOption>(iref);
Mathieu Chartierc56057e2014-05-04 13:18:58 -0700256 }
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700257
Andreas Gampee03662b2016-10-13 17:12:56 -0700258 // Updates an existing indirect reference to point to a new object.
Mathieu Chartier8778c522016-10-04 19:06:30 -0700259 void Update(IndirectRef iref, ObjPtr<mirror::Object> obj) REQUIRES_SHARED(Locks::mutator_lock_);
Jeff Hao39b6c242015-05-19 20:30:23 -0700260
Andreas Gampee03662b2016-10-13 17:12:56 -0700261 // Remove an existing entry.
262 //
263 // If the entry is not between the current top index and the bottom index
264 // specified by the cookie, we don't remove anything. This is the behavior
265 // required by JNI's DeleteLocalRef function.
266 //
267 // Returns "false" if nothing was removed.
268 bool Remove(IRTSegmentState previous_state, IndirectRef iref);
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700269
Mathieu Chartier8778c522016-10-04 19:06:30 -0700270 void AssertEmpty() REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes726079d2011-10-07 18:43:44 -0700271
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700272 void Dump(std::ostream& os) const REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700273
Andreas Gampee03662b2016-10-13 17:12:56 -0700274 // Return the #of entries in the entire table. This includes holes, and
275 // so may be larger than the actual number of "live" entries.
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700276 size_t Capacity() const {
Andreas Gampee03662b2016-10-13 17:12:56 -0700277 return segment_state_.top_index;
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700278 }
279
Hiroshi Yamauchiea2e1bd2014-06-18 13:47:35 -0700280 // Note IrtIterator does not have a read barrier as it's used to visit roots.
Mathieu Chartier02e25112013-08-14 16:14:24 -0700281 IrtIterator begin() {
282 return IrtIterator(table_, 0, Capacity());
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700283 }
284
Mathieu Chartier02e25112013-08-14 16:14:24 -0700285 IrtIterator end() {
286 return IrtIterator(table_, Capacity(), Capacity());
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700287 }
288
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700289 void VisitRoots(RootVisitor* visitor, const RootInfo& root_info)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700290 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes410c0c82011-09-01 17:58:25 -0700291
Andreas Gampee03662b2016-10-13 17:12:56 -0700292 IRTSegmentState GetSegmentState() const {
293 return segment_state_;
Ian Rogersad25ac52011-10-04 19:13:33 -0700294 }
295
Andreas Gampee03662b2016-10-13 17:12:56 -0700296 void SetSegmentState(IRTSegmentState new_state);
Ian Rogersad25ac52011-10-04 19:13:33 -0700297
Andreas Gampe4d98c842015-12-09 15:14:04 -0800298 static Offset SegmentStateOffset(size_t pointer_size ATTRIBUTE_UNUSED) {
299 // Note: Currently segment_state_ is at offset 0. We're testing the expected value in
300 // jni_internal_test to make sure it stays correct. It is not OFFSETOF_MEMBER, as that
301 // is not pointer-size-safe.
302 return Offset(0);
Ian Rogersdc51b792011-09-22 20:41:37 -0700303 }
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800304
Mathieu Chartier91c2f0c2014-11-26 11:21:15 -0800305 // Release pages past the end of the table that may have previously held references.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700306 void Trim() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier91c2f0c2014-11-26 11:21:15 -0800307
Andreas Gampedc061d02016-10-24 13:19:37 -0700308 // Determine what kind of indirect reference this is. Opposite of EncodeIndirectRefKind.
309 ALWAYS_INLINE static inline IndirectRefKind GetIndirectRefKind(IndirectRef iref) {
310 return DecodeIndirectRefKind(reinterpret_cast<uintptr_t>(iref));
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700311 }
312
Andreas Gampedc061d02016-10-24 13:19:37 -0700313 private:
314 static constexpr size_t kSerialBits = MinimumBitsToStore(kIRTPrevCount);
315 static constexpr uint32_t kShiftedSerialMask = (1u << kSerialBits) - 1;
316
317 static constexpr size_t kKindBits = MinimumBitsToStore(
318 static_cast<uint32_t>(IndirectRefKind::kLastKind));
319 static constexpr uint32_t kKindMask = (1u << kKindBits) - 1;
320
321 static constexpr uintptr_t EncodeIndex(uint32_t table_index) {
322 static_assert(sizeof(IndirectRef) == sizeof(uintptr_t), "Unexpected IndirectRef size");
323 DCHECK_LE(MinimumBitsToStore(table_index), BitSizeOf<uintptr_t>() - kSerialBits - kKindBits);
324 return (static_cast<uintptr_t>(table_index) << kKindBits << kSerialBits);
325 }
326 static constexpr uint32_t DecodeIndex(uintptr_t uref) {
327 return static_cast<uint32_t>((uref >> kKindBits) >> kSerialBits);
328 }
329
330 static constexpr uintptr_t EncodeIndirectRefKind(IndirectRefKind kind) {
331 return static_cast<uintptr_t>(kind);
332 }
333 static constexpr IndirectRefKind DecodeIndirectRefKind(uintptr_t uref) {
334 return static_cast<IndirectRefKind>(uref & kKindMask);
335 }
336
337 static constexpr uintptr_t EncodeSerial(uint32_t serial) {
338 DCHECK_LE(MinimumBitsToStore(serial), kSerialBits);
339 return serial << kKindBits;
340 }
341 static constexpr uint32_t DecodeSerial(uintptr_t uref) {
342 return static_cast<uint32_t>(uref >> kKindBits) & kShiftedSerialMask;
343 }
344
345 constexpr uintptr_t EncodeIndirectRef(uint32_t table_index, uint32_t serial) const {
346 DCHECK_LT(table_index, max_entries_);
347 return EncodeIndex(table_index) | EncodeSerial(serial) | EncodeIndirectRefKind(kind_);
348 }
349
350 static void ConstexprChecks();
351
352 // Extract the table index from an indirect reference.
353 ALWAYS_INLINE static uint32_t ExtractIndex(IndirectRef iref) {
354 return DecodeIndex(reinterpret_cast<uintptr_t>(iref));
355 }
356
357 IndirectRef ToIndirectRef(uint32_t table_index) const {
358 DCHECK_LT(table_index, max_entries_);
359 uint32_t serial = table_[table_index].GetSerial();
360 return reinterpret_cast<IndirectRef>(EncodeIndirectRef(table_index, serial));
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700361 }
362
Andreas Gampee03662b2016-10-13 17:12:56 -0700363 // Resize the backing table. Currently must be larger than the current size.
364 bool Resize(size_t new_size, std::string* error_msg);
365
366 void RecoverHoles(IRTSegmentState from);
367
Andreas Gampef1e86302016-10-03 11:42:31 -0700368 // Abort if check_jni is not enabled. Otherwise, just log as an error.
369 static void AbortIfNoCheckJNI(const std::string& msg);
Mathieu Chartierc56057e2014-05-04 13:18:58 -0700370
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700371 /* extra debugging checks */
Mathieu Chartier8778c522016-10-04 19:06:30 -0700372 bool GetChecked(IndirectRef) const REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampee03662b2016-10-13 17:12:56 -0700373 bool CheckEntry(const char*, IndirectRef, uint32_t) const;
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700374
Andreas Gampee03662b2016-10-13 17:12:56 -0700375 /// semi-public - read/write by jni down calls.
Ian Rogersdc51b792011-09-22 20:41:37 -0700376 IRTSegmentState segment_state_;
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700377
Mathieu Chartierc56057e2014-05-04 13:18:58 -0700378 // Mem map where we store the indirect refs.
Ian Rogers700a4022014-05-19 16:49:03 -0700379 std::unique_ptr<MemMap> table_mem_map_;
Hiroshi Yamauchiea2e1bd2014-06-18 13:47:35 -0700380 // bottom of the stack. Do not directly access the object references
381 // in this as they are roots. Use Get() that has a read barrier.
Mathieu Chartier4838d662014-09-25 15:27:43 -0700382 IrtEntry* table_;
Andreas Gampee03662b2016-10-13 17:12:56 -0700383 // bit mask, ORed into all irefs.
Mathieu Chartier4838d662014-09-25 15:27:43 -0700384 const IndirectRefKind kind_;
Andreas Gampee03662b2016-10-13 17:12:56 -0700385
386 // max #of entries allowed.
387 size_t max_entries_;
388
389 // Some values to retain old behavior with holes. Description of the algorithm is in the .cc
390 // file.
391 // TODO: Consider other data structures for compact tables, e.g., free lists.
392 size_t current_num_holes_;
393 IRTSegmentState last_known_previous_state_;
Elliott Hughes6c1a3942011-08-17 15:00:06 -0700394};
395
396} // namespace art
397
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700398#endif // ART_RUNTIME_INDIRECT_REFERENCE_TABLE_H_