Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
Mathieu Chartier | c56057e | 2014-05-04 13:18:58 -0700 | [diff] [blame] | 17 | #include "indirect_reference_table-inl.h" |
| 18 | |
Elliott Hughes | a250199 | 2011-08-26 19:39:54 -0700 | [diff] [blame] | 19 | #include "jni_internal.h" |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 20 | #include "reference_table.h" |
Elliott Hughes | a250199 | 2011-08-26 19:39:54 -0700 | [diff] [blame] | 21 | #include "runtime.h" |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 22 | #include "scoped_thread_state_change.h" |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 23 | #include "thread.h" |
Ian Rogers | cdd1d2d | 2011-08-18 09:58:17 -0700 | [diff] [blame] | 24 | #include "utils.h" |
Mathieu Chartier | 6dda898 | 2014-03-06 11:11:48 -0800 | [diff] [blame] | 25 | #include "verify_object-inl.h" |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 26 | |
| 27 | #include <cstdlib> |
| 28 | |
| 29 | namespace art { |
| 30 | |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 31 | template<typename T> |
| 32 | class MutatorLockedDumpable { |
| 33 | public: |
| 34 | explicit MutatorLockedDumpable(T& value) |
| 35 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) : value_(value) { |
| 36 | } |
| 37 | |
| 38 | void Dump(std::ostream& os) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 39 | value_.Dump(os); |
| 40 | } |
| 41 | |
| 42 | private: |
| 43 | T& value_; |
| 44 | |
| 45 | DISALLOW_COPY_AND_ASSIGN(MutatorLockedDumpable); |
| 46 | }; |
| 47 | |
| 48 | template<typename T> |
| 49 | std::ostream& operator<<(std::ostream& os, const MutatorLockedDumpable<T>& rhs) |
| 50 | // TODO: should be SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) however annotalysis |
| 51 | // currently fails for this. |
| 52 | NO_THREAD_SAFETY_ANALYSIS { |
| 53 | rhs.Dump(os); |
| 54 | return os; |
| 55 | } |
| 56 | |
Mathieu Chartier | c56057e | 2014-05-04 13:18:58 -0700 | [diff] [blame] | 57 | void IndirectReferenceTable::AbortIfNoCheckJNI() { |
Elliott Hughes | a250199 | 2011-08-26 19:39:54 -0700 | [diff] [blame] | 58 | // If -Xcheck:jni is on, it'll give a more detailed error before aborting. |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 59 | JavaVMExt* vm = Runtime::Current()->GetJavaVM(); |
| 60 | if (!vm->IsCheckJniEnabled()) { |
Elliott Hughes | a250199 | 2011-08-26 19:39:54 -0700 | [diff] [blame] | 61 | // Otherwise, we want to abort rather than hand back a bad reference. |
| 62 | LOG(FATAL) << "JNI ERROR (app bug): see above."; |
| 63 | } |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | IndirectReferenceTable::IndirectReferenceTable(size_t initialCount, |
Mathieu Chartier | 4838d66 | 2014-09-25 15:27:43 -0700 | [diff] [blame] | 67 | size_t maxCount, IndirectRefKind desiredKind) |
| 68 | : kind_(desiredKind), |
| 69 | max_entries_(maxCount) { |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 70 | CHECK_GT(initialCount, 0U); |
| 71 | CHECK_LE(initialCount, maxCount); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 72 | CHECK_NE(desiredKind, kHandleScopeOrInvalid); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 73 | |
Mathieu Chartier | c56057e | 2014-05-04 13:18:58 -0700 | [diff] [blame] | 74 | std::string error_str; |
Mathieu Chartier | 4838d66 | 2014-09-25 15:27:43 -0700 | [diff] [blame] | 75 | const size_t table_bytes = maxCount * sizeof(IrtEntry); |
Mathieu Chartier | c56057e | 2014-05-04 13:18:58 -0700 | [diff] [blame] | 76 | table_mem_map_.reset(MemMap::MapAnonymous("indirect ref table", nullptr, table_bytes, |
| 77 | PROT_READ | PROT_WRITE, false, &error_str)); |
| 78 | CHECK(table_mem_map_.get() != nullptr) << error_str; |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 79 | CHECK_EQ(table_mem_map_->Size(), table_bytes); |
Mathieu Chartier | 4838d66 | 2014-09-25 15:27:43 -0700 | [diff] [blame] | 80 | table_ = reinterpret_cast<IrtEntry*>(table_mem_map_->Begin()); |
Mathieu Chartier | c56057e | 2014-05-04 13:18:58 -0700 | [diff] [blame] | 81 | CHECK(table_ != nullptr); |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 82 | segment_state_.all = IRT_FIRST_SEGMENT; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | IndirectReferenceTable::~IndirectReferenceTable() { |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Mathieu Chartier | 423d2a3 | 2013-09-12 17:33:56 -0700 | [diff] [blame] | 88 | IndirectRef IndirectReferenceTable::Add(uint32_t cookie, mirror::Object* obj) { |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 89 | IRTSegmentState prevState; |
| 90 | prevState.all = cookie; |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 91 | size_t topIndex = segment_state_.parts.topIndex; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 92 | |
Mathieu Chartier | cd2cfff | 2013-12-19 15:46:55 -0800 | [diff] [blame] | 93 | CHECK(obj != NULL); |
Mathieu Chartier | 6dda898 | 2014-03-06 11:11:48 -0800 | [diff] [blame] | 94 | VerifyObject(obj); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 95 | DCHECK(table_ != NULL); |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 96 | DCHECK_GE(segment_state_.parts.numHoles, prevState.parts.numHoles); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 97 | |
Mathieu Chartier | 4838d66 | 2014-09-25 15:27:43 -0700 | [diff] [blame] | 98 | if (topIndex == max_entries_) { |
| 99 | LOG(FATAL) << "JNI ERROR (app bug): " << kind_ << " table overflow " |
| 100 | << "(max=" << max_entries_ << ")\n" |
| 101 | << MutatorLockedDumpable<IndirectReferenceTable>(*this); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Elliott Hughes | 73e66f7 | 2012-05-09 09:34:45 -0700 | [diff] [blame] | 104 | // We know there's enough room in the table. Now we just need to find |
| 105 | // the right spot. If there's a hole, find it and fill it; otherwise, |
| 106 | // add to the end of the list. |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 107 | IndirectRef result; |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 108 | int numHoles = segment_state_.parts.numHoles - prevState.parts.numHoles; |
Mathieu Chartier | 4838d66 | 2014-09-25 15:27:43 -0700 | [diff] [blame] | 109 | size_t index; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 110 | if (numHoles > 0) { |
| 111 | DCHECK_GT(topIndex, 1U); |
Elliott Hughes | 73e66f7 | 2012-05-09 09:34:45 -0700 | [diff] [blame] | 112 | // Find the first hole; likely to be near the end of the list. |
Mathieu Chartier | 4838d66 | 2014-09-25 15:27:43 -0700 | [diff] [blame] | 113 | IrtEntry* pScan = &table_[topIndex - 1]; |
| 114 | DCHECK(!pScan->GetReference()->IsNull()); |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 115 | --pScan; |
Mathieu Chartier | 4838d66 | 2014-09-25 15:27:43 -0700 | [diff] [blame] | 116 | while (!pScan->GetReference()->IsNull()) { |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 117 | DCHECK_GE(pScan, table_ + prevState.parts.topIndex); |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 118 | --pScan; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 119 | } |
Mathieu Chartier | 4838d66 | 2014-09-25 15:27:43 -0700 | [diff] [blame] | 120 | index = pScan - table_; |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 121 | segment_state_.parts.numHoles--; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 122 | } else { |
Elliott Hughes | 73e66f7 | 2012-05-09 09:34:45 -0700 | [diff] [blame] | 123 | // Add to the end. |
Mathieu Chartier | 4838d66 | 2014-09-25 15:27:43 -0700 | [diff] [blame] | 124 | index = topIndex++; |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 125 | segment_state_.parts.topIndex = topIndex; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 126 | } |
Mathieu Chartier | 4838d66 | 2014-09-25 15:27:43 -0700 | [diff] [blame] | 127 | table_[index].Add(obj); |
| 128 | result = ToIndirectRef(index); |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 129 | if (false) { |
| 130 | LOG(INFO) << "+++ added at " << ExtractIndex(result) << " top=" << segment_state_.parts.topIndex |
| 131 | << " holes=" << segment_state_.parts.numHoles; |
| 132 | } |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 133 | |
| 134 | DCHECK(result != NULL); |
| 135 | return result; |
| 136 | } |
| 137 | |
Elliott Hughes | 726079d | 2011-10-07 18:43:44 -0700 | [diff] [blame] | 138 | void IndirectReferenceTable::AssertEmpty() { |
Hiroshi Yamauchi | 8a74117 | 2014-09-08 13:22:56 -0700 | [diff] [blame] | 139 | for (size_t i = 0; i < Capacity(); ++i) { |
Mathieu Chartier | 4838d66 | 2014-09-25 15:27:43 -0700 | [diff] [blame] | 140 | if (!table_[i].GetReference()->IsNull()) { |
Hiroshi Yamauchi | 8a74117 | 2014-09-08 13:22:56 -0700 | [diff] [blame] | 141 | ScopedObjectAccess soa(Thread::Current()); |
| 142 | LOG(FATAL) << "Internal Error: non-empty local reference table\n" |
| 143 | << MutatorLockedDumpable<IndirectReferenceTable>(*this); |
| 144 | } |
Elliott Hughes | 726079d | 2011-10-07 18:43:44 -0700 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
Elliott Hughes | 73e66f7 | 2012-05-09 09:34:45 -0700 | [diff] [blame] | 148 | // Removes an object. We extract the table offset bits from "iref" |
| 149 | // and zap the corresponding entry, leaving a hole if it's not at the top. |
| 150 | // If the entry is not between the current top index and the bottom index |
| 151 | // specified by the cookie, we don't remove anything. This is the behavior |
| 152 | // required by JNI's DeleteLocalRef function. |
| 153 | // This method is not called when a local frame is popped; this is only used |
| 154 | // for explicit single removals. |
| 155 | // Returns "false" if nothing was removed. |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 156 | bool IndirectReferenceTable::Remove(uint32_t cookie, IndirectRef iref) { |
| 157 | IRTSegmentState prevState; |
| 158 | prevState.all = cookie; |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 159 | int topIndex = segment_state_.parts.topIndex; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 160 | int bottomIndex = prevState.parts.topIndex; |
| 161 | |
| 162 | DCHECK(table_ != NULL); |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 163 | DCHECK_GE(segment_state_.parts.numHoles, prevState.parts.numHoles); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 164 | |
| 165 | int idx = ExtractIndex(iref); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 166 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 167 | if (GetIndirectRefKind(iref) == kHandleScopeOrInvalid && |
| 168 | Thread::Current()->HandleScopeContains(reinterpret_cast<jobject>(iref))) { |
| 169 | LOG(WARNING) << "Attempt to remove local handle scope entry from IRT, ignoring"; |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 170 | return true; |
| 171 | } |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 172 | if (idx < bottomIndex) { |
Elliott Hughes | 726079d | 2011-10-07 18:43:44 -0700 | [diff] [blame] | 173 | // Wrong segment. |
| 174 | LOG(WARNING) << "Attempt to remove index outside index area (" << idx |
| 175 | << " vs " << bottomIndex << "-" << topIndex << ")"; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 176 | return false; |
| 177 | } |
| 178 | if (idx >= topIndex) { |
Elliott Hughes | 726079d | 2011-10-07 18:43:44 -0700 | [diff] [blame] | 179 | // Bad --- stale reference? |
| 180 | LOG(WARNING) << "Attempt to remove invalid index " << idx |
| 181 | << " (bottom=" << bottomIndex << " top=" << topIndex << ")"; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 182 | return false; |
| 183 | } |
| 184 | |
Mathieu Chartier | 4838d66 | 2014-09-25 15:27:43 -0700 | [diff] [blame] | 185 | if (idx == topIndex - 1) { |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 186 | // Top-most entry. Scan up and consume holes. |
| 187 | |
Ian Rogers | 987560f | 2014-04-22 11:42:59 -0700 | [diff] [blame] | 188 | if (!CheckEntry("remove", iref, idx)) { |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 189 | return false; |
| 190 | } |
| 191 | |
Mathieu Chartier | 4838d66 | 2014-09-25 15:27:43 -0700 | [diff] [blame] | 192 | *table_[idx].GetReference() = GcRoot<mirror::Object>(nullptr); |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 193 | int numHoles = segment_state_.parts.numHoles - prevState.parts.numHoles; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 194 | if (numHoles != 0) { |
| 195 | while (--topIndex > bottomIndex && numHoles != 0) { |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 196 | if (false) { |
Mathieu Chartier | 4838d66 | 2014-09-25 15:27:43 -0700 | [diff] [blame] | 197 | LOG(INFO) << "+++ checking for hole at " << topIndex - 1 |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 198 | << " (cookie=" << cookie << ") val=" |
Mathieu Chartier | 4838d66 | 2014-09-25 15:27:43 -0700 | [diff] [blame] | 199 | << table_[topIndex - 1].GetReference()->Read<kWithoutReadBarrier>(); |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 200 | } |
Mathieu Chartier | 4838d66 | 2014-09-25 15:27:43 -0700 | [diff] [blame] | 201 | if (!table_[topIndex - 1].GetReference()->IsNull()) { |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 202 | break; |
| 203 | } |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 204 | if (false) { |
| 205 | LOG(INFO) << "+++ ate hole at " << (topIndex - 1); |
| 206 | } |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 207 | numHoles--; |
| 208 | } |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 209 | segment_state_.parts.numHoles = numHoles + prevState.parts.numHoles; |
| 210 | segment_state_.parts.topIndex = topIndex; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 211 | } else { |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 212 | segment_state_.parts.topIndex = topIndex-1; |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 213 | if (false) { |
| 214 | LOG(INFO) << "+++ ate last entry " << topIndex - 1; |
| 215 | } |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 216 | } |
| 217 | } else { |
Elliott Hughes | 73e66f7 | 2012-05-09 09:34:45 -0700 | [diff] [blame] | 218 | // Not the top-most entry. This creates a hole. We NULL out the |
| 219 | // entry to prevent somebody from deleting it twice and screwing up |
| 220 | // the hole count. |
Mathieu Chartier | 4838d66 | 2014-09-25 15:27:43 -0700 | [diff] [blame] | 221 | if (table_[idx].GetReference()->IsNull()) { |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 222 | LOG(INFO) << "--- WEIRD: removing null entry " << idx; |
| 223 | return false; |
| 224 | } |
Ian Rogers | 987560f | 2014-04-22 11:42:59 -0700 | [diff] [blame] | 225 | if (!CheckEntry("remove", iref, idx)) { |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 226 | return false; |
| 227 | } |
| 228 | |
Mathieu Chartier | 4838d66 | 2014-09-25 15:27:43 -0700 | [diff] [blame] | 229 | *table_[idx].GetReference() = GcRoot<mirror::Object>(nullptr); |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 230 | segment_state_.parts.numHoles++; |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 231 | if (false) { |
| 232 | LOG(INFO) << "+++ left hole at " << idx << ", holes=" << segment_state_.parts.numHoles; |
| 233 | } |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | return true; |
| 237 | } |
| 238 | |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 239 | void IndirectReferenceTable::VisitRoots(RootCallback* callback, void* arg, uint32_t tid, |
| 240 | RootType root_type) { |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 241 | for (auto ref : *this) { |
Hiroshi Yamauchi | 8a74117 | 2014-09-08 13:22:56 -0700 | [diff] [blame] | 242 | if (*ref == nullptr) { |
| 243 | // Need to skip null entries to make it possible to do the |
| 244 | // non-null check after the call back. |
| 245 | continue; |
| 246 | } |
Mathieu Chartier | 815873e | 2014-02-13 18:02:13 -0800 | [diff] [blame] | 247 | callback(ref, arg, tid, root_type); |
Mathieu Chartier | 423d2a3 | 2013-09-12 17:33:56 -0700 | [diff] [blame] | 248 | DCHECK(*ref != nullptr); |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | |
Elliott Hughes | 73e66f7 | 2012-05-09 09:34:45 -0700 | [diff] [blame] | 252 | void IndirectReferenceTable::Dump(std::ostream& os) const { |
| 253 | os << kind_ << " table dump:\n"; |
Hiroshi Yamauchi | 196851b | 2014-05-29 12:16:04 -0700 | [diff] [blame] | 254 | ReferenceTable::Table entries; |
| 255 | for (size_t i = 0; i < Capacity(); ++i) { |
Mathieu Chartier | 4838d66 | 2014-09-25 15:27:43 -0700 | [diff] [blame] | 256 | mirror::Object* obj = table_[i].GetReference()->Read<kWithoutReadBarrier>(); |
Hiroshi Yamauchi | 196851b | 2014-05-29 12:16:04 -0700 | [diff] [blame] | 257 | if (UNLIKELY(obj == nullptr)) { |
| 258 | // Remove NULLs. |
Hiroshi Yamauchi | 196851b | 2014-05-29 12:16:04 -0700 | [diff] [blame] | 259 | } else { |
Mathieu Chartier | 4838d66 | 2014-09-25 15:27:43 -0700 | [diff] [blame] | 260 | obj = table_[i].GetReference()->Read(); |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 261 | entries.push_back(GcRoot<mirror::Object>(obj)); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 262 | } |
| 263 | } |
Elliott Hughes | 73e66f7 | 2012-05-09 09:34:45 -0700 | [diff] [blame] | 264 | ReferenceTable::Dump(os, entries); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 267 | } // namespace art |