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 | |
| 17 | #include "indirect_reference_table.h" |
Elliott Hughes | a250199 | 2011-08-26 19:39:54 -0700 | [diff] [blame] | 18 | #include "jni_internal.h" |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 19 | #include "reference_table.h" |
Elliott Hughes | a250199 | 2011-08-26 19:39:54 -0700 | [diff] [blame] | 20 | #include "runtime.h" |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 21 | #include "thread.h" |
Ian Rogers | cdd1d2d | 2011-08-18 09:58:17 -0700 | [diff] [blame] | 22 | #include "utils.h" |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 23 | |
| 24 | #include <cstdlib> |
| 25 | |
| 26 | namespace art { |
| 27 | |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 28 | static void AbortMaybe() { |
Elliott Hughes | a250199 | 2011-08-26 19:39:54 -0700 | [diff] [blame] | 29 | // If -Xcheck:jni is on, it'll give a more detailed error before aborting. |
| 30 | if (!Runtime::Current()->GetJavaVM()->check_jni) { |
| 31 | // Otherwise, we want to abort rather than hand back a bad reference. |
| 32 | LOG(FATAL) << "JNI ERROR (app bug): see above."; |
| 33 | } |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | IndirectReferenceTable::IndirectReferenceTable(size_t initialCount, |
| 37 | size_t maxCount, IndirectRefKind desiredKind) |
| 38 | { |
| 39 | CHECK_GT(initialCount, 0U); |
| 40 | CHECK_LE(initialCount, maxCount); |
Ian Rogers | 408f79a | 2011-08-23 18:22:33 -0700 | [diff] [blame] | 41 | CHECK_NE(desiredKind, kSirtOrInvalid); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 42 | |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 43 | table_ = reinterpret_cast<const Object**>(malloc(initialCount * sizeof(const Object*))); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 44 | CHECK(table_ != NULL); |
| 45 | #ifndef NDEBUG |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 46 | memset(table_, 0xd1, initialCount * sizeof(const Object*)); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 47 | #endif |
| 48 | |
| 49 | slot_data_ = reinterpret_cast<IndirectRefSlot*>(calloc(initialCount, sizeof(IndirectRefSlot))); |
| 50 | CHECK(slot_data_ != NULL); |
| 51 | |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 52 | segment_state_.all = IRT_FIRST_SEGMENT; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 53 | alloc_entries_ = initialCount; |
| 54 | max_entries_ = maxCount; |
| 55 | kind_ = desiredKind; |
| 56 | } |
| 57 | |
| 58 | IndirectReferenceTable::~IndirectReferenceTable() { |
| 59 | free(table_); |
| 60 | free(slot_data_); |
| 61 | table_ = NULL; |
| 62 | slot_data_ = NULL; |
| 63 | alloc_entries_ = max_entries_ = -1; |
| 64 | } |
| 65 | |
| 66 | /* |
| 67 | * Make sure that the entry at "idx" is correctly paired with "iref". |
| 68 | */ |
| 69 | bool IndirectReferenceTable::CheckEntry(const char* what, IndirectRef iref, int idx) const { |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 70 | const Object* obj = table_[idx]; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 71 | IndirectRef checkRef = ToIndirectRef(obj, idx); |
| 72 | if (checkRef != iref) { |
| 73 | LOG(ERROR) << "JNI ERROR (app bug): attempt to " << what |
| 74 | << " stale " << kind_ << " " << iref |
| 75 | << " (should be " << checkRef << ")"; |
| 76 | AbortMaybe(); |
| 77 | return false; |
| 78 | } |
| 79 | return true; |
| 80 | } |
| 81 | |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 82 | IndirectRef IndirectReferenceTable::Add(uint32_t cookie, const Object* obj) { |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 83 | IRTSegmentState prevState; |
| 84 | prevState.all = cookie; |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 85 | size_t topIndex = segment_state_.parts.topIndex; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 86 | |
| 87 | DCHECK(obj != NULL); |
Ian Rogers | cdd1d2d | 2011-08-18 09:58:17 -0700 | [diff] [blame] | 88 | // TODO: stronger sanity check on the object (such as in heap) |
Elliott Hughes | 06b37d9 | 2011-10-16 11:51:29 -0700 | [diff] [blame] | 89 | DCHECK_ALIGNED(reinterpret_cast<intptr_t>(obj), 8); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 90 | DCHECK(table_ != NULL); |
| 91 | DCHECK_LE(alloc_entries_, max_entries_); |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 92 | DCHECK_GE(segment_state_.parts.numHoles, prevState.parts.numHoles); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 93 | |
| 94 | if (topIndex == alloc_entries_) { |
| 95 | /* reached end of allocated space; did we hit buffer max? */ |
| 96 | if (topIndex == max_entries_) { |
| 97 | LOG(ERROR) << "JNI ERROR (app bug): " << kind_ << " table overflow " |
| 98 | << "(max=" << max_entries_ << ")"; |
| 99 | Dump(); |
| 100 | LOG(FATAL); // TODO: operator<< for IndirectReferenceTable |
| 101 | } |
| 102 | |
| 103 | size_t newSize = alloc_entries_ * 2; |
| 104 | if (newSize > max_entries_) { |
| 105 | newSize = max_entries_; |
| 106 | } |
| 107 | DCHECK_GT(newSize, alloc_entries_); |
| 108 | |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 109 | table_ = (const Object**) realloc(table_, newSize * sizeof(const Object*)); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 110 | slot_data_ = (IndirectRefSlot*) realloc(slot_data_, newSize * sizeof(IndirectRefSlot)); |
| 111 | if (table_ == NULL || slot_data_ == NULL) { |
| 112 | LOG(ERROR) << "JNI ERROR (app bug): unable to expand " |
| 113 | << kind_ << " table (from " |
| 114 | << alloc_entries_ << " to " << newSize |
| 115 | << ", max=" << max_entries_ << ")"; |
| 116 | Dump(); |
| 117 | LOG(FATAL); // TODO: operator<< for IndirectReferenceTable |
| 118 | } |
| 119 | |
| 120 | // Clear the newly-allocated slot_data_ elements. |
| 121 | memset(slot_data_ + alloc_entries_, 0, (newSize - alloc_entries_) * sizeof(IndirectRefSlot)); |
| 122 | |
| 123 | alloc_entries_ = newSize; |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * We know there's enough room in the table. Now we just need to find |
| 128 | * the right spot. If there's a hole, find it and fill it; otherwise, |
| 129 | * add to the end of the list. |
| 130 | */ |
| 131 | IndirectRef result; |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 132 | int numHoles = segment_state_.parts.numHoles - prevState.parts.numHoles; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 133 | if (numHoles > 0) { |
| 134 | DCHECK_GT(topIndex, 1U); |
| 135 | /* find the first hole; likely to be near the end of the list */ |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 136 | const Object** pScan = &table_[topIndex - 1]; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 137 | DCHECK(*pScan != NULL); |
| 138 | while (*--pScan != NULL) { |
| 139 | DCHECK_GE(pScan, table_ + prevState.parts.topIndex); |
| 140 | } |
| 141 | UpdateSlotAdd(obj, pScan - table_); |
| 142 | result = ToIndirectRef(obj, pScan - table_); |
| 143 | *pScan = obj; |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 144 | segment_state_.parts.numHoles--; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 145 | } else { |
| 146 | /* add to the end */ |
| 147 | UpdateSlotAdd(obj, topIndex); |
| 148 | result = ToIndirectRef(obj, topIndex); |
| 149 | table_[topIndex++] = obj; |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 150 | segment_state_.parts.topIndex = topIndex; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 151 | } |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 152 | if (false) { |
| 153 | LOG(INFO) << "+++ added at " << ExtractIndex(result) << " top=" << segment_state_.parts.topIndex |
| 154 | << " holes=" << segment_state_.parts.numHoles; |
| 155 | } |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 156 | |
| 157 | DCHECK(result != NULL); |
| 158 | return result; |
| 159 | } |
| 160 | |
Elliott Hughes | 726079d | 2011-10-07 18:43:44 -0700 | [diff] [blame] | 161 | void IndirectReferenceTable::AssertEmpty() { |
| 162 | if (begin() != end()) { |
| 163 | Dump(); |
| 164 | LOG(FATAL) << "Internal Error: non-empty local reference table"; |
| 165 | } |
| 166 | } |
| 167 | |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 168 | /* |
| 169 | * Verify that the indirect table lookup is valid. |
| 170 | * |
| 171 | * Returns "false" if something looks bad. |
| 172 | */ |
| 173 | bool IndirectReferenceTable::GetChecked(IndirectRef iref) const { |
| 174 | if (iref == NULL) { |
| 175 | LOG(WARNING) << "Attempt to look up NULL " << kind_; |
| 176 | return false; |
| 177 | } |
Ian Rogers | 408f79a | 2011-08-23 18:22:33 -0700 | [diff] [blame] | 178 | if (GetIndirectRefKind(iref) == kSirtOrInvalid) { |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 179 | LOG(ERROR) << "JNI ERROR (app bug): invalid " << kind_ << " " << iref; |
| 180 | AbortMaybe(); |
| 181 | return false; |
| 182 | } |
| 183 | |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 184 | int topIndex = segment_state_.parts.topIndex; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 185 | int idx = ExtractIndex(iref); |
| 186 | if (idx >= topIndex) { |
| 187 | /* bad -- stale reference? */ |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 188 | LOG(ERROR) << "JNI ERROR (app bug): accessed stale " << kind_ << " " |
| 189 | << iref << " (index " << idx << " in a table of size " << topIndex << ")"; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 190 | AbortMaybe(); |
| 191 | return false; |
| 192 | } |
| 193 | |
| 194 | if (table_[idx] == NULL) { |
| 195 | LOG(ERROR) << "JNI ERROR (app bug): accessed deleted " << kind_ << " " << iref; |
| 196 | AbortMaybe(); |
| 197 | return false; |
| 198 | } |
| 199 | |
| 200 | if (!CheckEntry("use", iref, idx)) { |
| 201 | return false; |
| 202 | } |
| 203 | |
| 204 | return true; |
| 205 | } |
| 206 | |
Elliott Hughes | 2ced6a5 | 2011-10-16 18:44:48 -0700 | [diff] [blame] | 207 | static int Find(Object* direct_pointer, int bottomIndex, int topIndex, const Object** table) { |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 208 | for (int i = bottomIndex; i < topIndex; ++i) { |
Elliott Hughes | 2ced6a5 | 2011-10-16 18:44:48 -0700 | [diff] [blame] | 209 | if (table[i] == direct_pointer) { |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 210 | return i; |
| 211 | } |
| 212 | } |
| 213 | return -1; |
| 214 | } |
| 215 | |
Elliott Hughes | 2ced6a5 | 2011-10-16 18:44:48 -0700 | [diff] [blame] | 216 | bool IndirectReferenceTable::ContainsDirectPointer(Object* direct_pointer) const { |
| 217 | return Find(direct_pointer, 0, segment_state_.parts.topIndex, table_) != -1; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /* |
| 221 | * Remove "obj" from "pRef". We extract the table offset bits from "iref" |
| 222 | * and zap the corresponding entry, leaving a hole if it's not at the top. |
| 223 | * |
| 224 | * If the entry is not between the current top index and the bottom index |
| 225 | * specified by the cookie, we don't remove anything. This is the behavior |
| 226 | * required by JNI's DeleteLocalRef function. |
| 227 | * |
| 228 | * Note this is NOT called when a local frame is popped. This is only used |
| 229 | * for explicit single removals. |
| 230 | * |
| 231 | * Returns "false" if nothing was removed. |
| 232 | */ |
| 233 | bool IndirectReferenceTable::Remove(uint32_t cookie, IndirectRef iref) { |
| 234 | IRTSegmentState prevState; |
| 235 | prevState.all = cookie; |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 236 | int topIndex = segment_state_.parts.topIndex; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 237 | int bottomIndex = prevState.parts.topIndex; |
| 238 | |
| 239 | DCHECK(table_ != NULL); |
| 240 | DCHECK_LE(alloc_entries_, max_entries_); |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 241 | DCHECK_GE(segment_state_.parts.numHoles, prevState.parts.numHoles); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 242 | |
| 243 | int idx = ExtractIndex(iref); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 244 | |
Elliott Hughes | c5bfa8f | 2011-08-30 14:32:49 -0700 | [diff] [blame] | 245 | JavaVMExt* vm = Runtime::Current()->GetJavaVM(); |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 246 | if (GetIndirectRefKind(iref) == kSirtOrInvalid && |
| 247 | Thread::Current()->SirtContains(reinterpret_cast<jobject>(iref))) { |
| 248 | LOG(WARNING) << "Attempt to remove local SIRT entry from IRT, ignoring"; |
| 249 | return true; |
| 250 | } |
Elliott Hughes | c5bfa8f | 2011-08-30 14:32:49 -0700 | [diff] [blame] | 251 | if (GetIndirectRefKind(iref) == kSirtOrInvalid || vm->work_around_app_jni_bugs) { |
Elliott Hughes | 2ced6a5 | 2011-10-16 18:44:48 -0700 | [diff] [blame] | 252 | Object* direct_pointer = reinterpret_cast<Object*>(iref); |
| 253 | idx = Find(direct_pointer, bottomIndex, topIndex, table_); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 254 | if (idx == -1) { |
| 255 | LOG(WARNING) << "trying to work around app JNI bugs, but didn't find " << iref << " in table!"; |
| 256 | return false; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | if (idx < bottomIndex) { |
Elliott Hughes | 726079d | 2011-10-07 18:43:44 -0700 | [diff] [blame] | 261 | // Wrong segment. |
| 262 | LOG(WARNING) << "Attempt to remove index outside index area (" << idx |
| 263 | << " vs " << bottomIndex << "-" << topIndex << ")"; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 264 | return false; |
| 265 | } |
| 266 | if (idx >= topIndex) { |
Elliott Hughes | 726079d | 2011-10-07 18:43:44 -0700 | [diff] [blame] | 267 | // Bad --- stale reference? |
| 268 | LOG(WARNING) << "Attempt to remove invalid index " << idx |
| 269 | << " (bottom=" << bottomIndex << " top=" << topIndex << ")"; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 270 | return false; |
| 271 | } |
| 272 | |
| 273 | if (idx == topIndex-1) { |
| 274 | // Top-most entry. Scan up and consume holes. |
| 275 | |
Elliott Hughes | c5bfa8f | 2011-08-30 14:32:49 -0700 | [diff] [blame] | 276 | if (!vm->work_around_app_jni_bugs && !CheckEntry("remove", iref, idx)) { |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 277 | return false; |
| 278 | } |
| 279 | |
| 280 | table_[idx] = NULL; |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 281 | int numHoles = segment_state_.parts.numHoles - prevState.parts.numHoles; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 282 | if (numHoles != 0) { |
| 283 | while (--topIndex > bottomIndex && numHoles != 0) { |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 284 | if (false) { |
| 285 | LOG(INFO) << "+++ checking for hole at " << topIndex-1 |
| 286 | << " (cookie=" << cookie << ") val=" << table_[topIndex - 1]; |
| 287 | } |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 288 | if (table_[topIndex-1] != NULL) { |
| 289 | break; |
| 290 | } |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 291 | if (false) { |
| 292 | LOG(INFO) << "+++ ate hole at " << (topIndex - 1); |
| 293 | } |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 294 | numHoles--; |
| 295 | } |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 296 | segment_state_.parts.numHoles = numHoles + prevState.parts.numHoles; |
| 297 | segment_state_.parts.topIndex = topIndex; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 298 | } else { |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 299 | segment_state_.parts.topIndex = topIndex-1; |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 300 | if (false) { |
| 301 | LOG(INFO) << "+++ ate last entry " << topIndex - 1; |
| 302 | } |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 303 | } |
| 304 | } else { |
| 305 | /* |
| 306 | * Not the top-most entry. This creates a hole. We NULL out the |
| 307 | * entry to prevent somebody from deleting it twice and screwing up |
| 308 | * the hole count. |
| 309 | */ |
| 310 | if (table_[idx] == NULL) { |
| 311 | LOG(INFO) << "--- WEIRD: removing null entry " << idx; |
| 312 | return false; |
| 313 | } |
Elliott Hughes | c5bfa8f | 2011-08-30 14:32:49 -0700 | [diff] [blame] | 314 | if (!vm->work_around_app_jni_bugs && !CheckEntry("remove", iref, idx)) { |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 315 | return false; |
| 316 | } |
| 317 | |
| 318 | table_[idx] = NULL; |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 319 | segment_state_.parts.numHoles++; |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 320 | if (false) { |
| 321 | LOG(INFO) << "+++ left hole at " << idx << ", holes=" << segment_state_.parts.numHoles; |
| 322 | } |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | return true; |
| 326 | } |
| 327 | |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 328 | void IndirectReferenceTable::VisitRoots(Heap::RootVisitor* visitor, void* arg) { |
| 329 | typedef IndirectReferenceTable::iterator It; // TODO: C++0x auto |
| 330 | for (It it = begin(), end = this->end(); it != end; ++it) { |
| 331 | visitor(**it, arg); |
| 332 | } |
| 333 | } |
| 334 | |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 335 | std::ostream& operator<<(std::ostream& os, IndirectRefKind rhs) { |
| 336 | switch (rhs) { |
Ian Rogers | 408f79a | 2011-08-23 18:22:33 -0700 | [diff] [blame] | 337 | case kSirtOrInvalid: |
| 338 | os << "stack indirect reference table or invalid reference"; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 339 | break; |
| 340 | case kLocal: |
| 341 | os << "local reference"; |
| 342 | break; |
| 343 | case kGlobal: |
| 344 | os << "global reference"; |
| 345 | break; |
| 346 | case kWeakGlobal: |
| 347 | os << "weak global reference"; |
| 348 | break; |
| 349 | default: |
| 350 | os << "IndirectRefKind[" << static_cast<int>(rhs) << "]"; |
| 351 | break; |
| 352 | } |
| 353 | return os; |
| 354 | } |
| 355 | |
| 356 | void IndirectReferenceTable::Dump() const { |
| 357 | LOG(WARNING) << kind_ << " table dump:"; |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 358 | std::vector<const Object*> entries(table_, table_ + Capacity()); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 359 | ReferenceTable::Dump(entries); |
| 360 | } |
| 361 | |
| 362 | } // namespace art |