Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
Andreas Gampe | ba8df69 | 2016-11-01 10:30:44 -0700 | [diff] [blame] | 17 | #include "ti_heap.h" |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 18 | |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 19 | #include "art_field-inl.h" |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 20 | #include "art_jvmti.h" |
| 21 | #include "base/macros.h" |
| 22 | #include "base/mutex.h" |
Andreas Gampe | aa8b60c | 2016-10-12 12:51:25 -0700 | [diff] [blame] | 23 | #include "class_linker.h" |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 24 | #include "gc/heap.h" |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 25 | #include "gc_root-inl.h" |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame^] | 26 | #include "java_frame_root_info.h" |
Andreas Gampe | aa8b60c | 2016-10-12 12:51:25 -0700 | [diff] [blame] | 27 | #include "jni_env_ext.h" |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 28 | #include "jni_internal.h" |
Andreas Gampe | 9e38a50 | 2017-03-06 08:19:26 -0800 | [diff] [blame] | 29 | #include "jvmti_weak_table-inl.h" |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 30 | #include "mirror/class.h" |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 31 | #include "mirror/object-inl.h" |
| 32 | #include "mirror/object_array-inl.h" |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 33 | #include "object_callbacks.h" |
| 34 | #include "object_tagging.h" |
| 35 | #include "obj_ptr-inl.h" |
Andreas Gampe | becd6ad | 2017-02-22 19:20:37 -0800 | [diff] [blame] | 36 | #include "primitive.h" |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 37 | #include "runtime.h" |
| 38 | #include "scoped_thread_state_change-inl.h" |
Andreas Gampe | 513061a | 2017-06-01 09:17:34 -0700 | [diff] [blame] | 39 | #include "stack.h" |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 40 | #include "thread-inl.h" |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 41 | #include "thread_list.h" |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 42 | |
| 43 | namespace openjdkjvmti { |
| 44 | |
Andreas Gampe | 3ec8e40 | 2017-02-21 15:49:53 -0800 | [diff] [blame] | 45 | namespace { |
| 46 | |
Andreas Gampe | 9e38a50 | 2017-03-06 08:19:26 -0800 | [diff] [blame] | 47 | struct IndexCache { |
| 48 | // The number of interface fields implemented by the class. This is a prefix to all assigned |
| 49 | // field indices. |
| 50 | size_t interface_fields; |
| 51 | |
| 52 | // It would be nice to also cache the following, but it is complicated to wire up into the |
| 53 | // generic visit: |
| 54 | // The number of fields in interfaces and superclasses. This is the first index assigned to |
| 55 | // fields of the class. |
| 56 | // size_t superclass_fields; |
| 57 | }; |
| 58 | using IndexCachingTable = JvmtiWeakTable<IndexCache>; |
| 59 | |
| 60 | static IndexCachingTable gIndexCachingTable; |
| 61 | |
Andreas Gampe | 3ec8e40 | 2017-02-21 15:49:53 -0800 | [diff] [blame] | 62 | // Report the contents of a string, if a callback is set. |
| 63 | jint ReportString(art::ObjPtr<art::mirror::Object> obj, |
| 64 | jvmtiEnv* env, |
| 65 | ObjectTagTable* tag_table, |
| 66 | const jvmtiHeapCallbacks* cb, |
| 67 | const void* user_data) REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 68 | if (UNLIKELY(cb->string_primitive_value_callback != nullptr) && obj->IsString()) { |
| 69 | art::ObjPtr<art::mirror::String> str = obj->AsString(); |
| 70 | int32_t string_length = str->GetLength(); |
Andreas Gampe | 5f94203 | 2017-02-27 19:59:40 -0800 | [diff] [blame] | 71 | JvmtiUniquePtr<uint16_t[]> data; |
Andreas Gampe | 3ec8e40 | 2017-02-21 15:49:53 -0800 | [diff] [blame] | 72 | |
Andreas Gampe | 5f94203 | 2017-02-27 19:59:40 -0800 | [diff] [blame] | 73 | if (string_length > 0) { |
| 74 | jvmtiError alloc_error; |
| 75 | data = AllocJvmtiUniquePtr<uint16_t[]>(env, string_length, &alloc_error); |
| 76 | if (data == nullptr) { |
| 77 | // TODO: Not really sure what to do here. Should we abort the iteration and go all the way |
| 78 | // back? For now just warn. |
| 79 | LOG(WARNING) << "Unable to allocate buffer for string reporting! Silently dropping value." |
| 80 | << " >" << str->ToModifiedUtf8() << "<"; |
| 81 | return 0; |
Andreas Gampe | 3ec8e40 | 2017-02-21 15:49:53 -0800 | [diff] [blame] | 82 | } |
Andreas Gampe | 5f94203 | 2017-02-27 19:59:40 -0800 | [diff] [blame] | 83 | |
| 84 | if (str->IsCompressed()) { |
| 85 | uint8_t* compressed_data = str->GetValueCompressed(); |
| 86 | for (int32_t i = 0; i != string_length; ++i) { |
| 87 | data[i] = compressed_data[i]; |
| 88 | } |
| 89 | } else { |
| 90 | // Can copy directly. |
| 91 | memcpy(data.get(), str->GetValue(), string_length * sizeof(uint16_t)); |
| 92 | } |
Andreas Gampe | 3ec8e40 | 2017-02-21 15:49:53 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | const jlong class_tag = tag_table->GetTagOrZero(obj->GetClass()); |
| 96 | jlong string_tag = tag_table->GetTagOrZero(obj.Ptr()); |
| 97 | const jlong saved_string_tag = string_tag; |
| 98 | |
| 99 | jint result = cb->string_primitive_value_callback(class_tag, |
| 100 | obj->SizeOf(), |
| 101 | &string_tag, |
| 102 | data.get(), |
| 103 | string_length, |
| 104 | const_cast<void*>(user_data)); |
| 105 | if (string_tag != saved_string_tag) { |
| 106 | tag_table->Set(obj.Ptr(), string_tag); |
| 107 | } |
| 108 | |
| 109 | return result; |
| 110 | } |
| 111 | return 0; |
| 112 | } |
| 113 | |
Andreas Gampe | becd6ad | 2017-02-22 19:20:37 -0800 | [diff] [blame] | 114 | // Report the contents of a primitive array, if a callback is set. |
| 115 | jint ReportPrimitiveArray(art::ObjPtr<art::mirror::Object> obj, |
| 116 | jvmtiEnv* env, |
| 117 | ObjectTagTable* tag_table, |
| 118 | const jvmtiHeapCallbacks* cb, |
| 119 | const void* user_data) REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 120 | if (UNLIKELY(cb->array_primitive_value_callback != nullptr) && |
| 121 | obj->IsArrayInstance() && |
| 122 | !obj->IsObjectArray()) { |
| 123 | art::ObjPtr<art::mirror::Array> array = obj->AsArray(); |
| 124 | int32_t array_length = array->GetLength(); |
| 125 | size_t component_size = array->GetClass()->GetComponentSize(); |
| 126 | art::Primitive::Type art_prim_type = array->GetClass()->GetComponentType()->GetPrimitiveType(); |
| 127 | jvmtiPrimitiveType prim_type = |
| 128 | static_cast<jvmtiPrimitiveType>(art::Primitive::Descriptor(art_prim_type)[0]); |
| 129 | DCHECK(prim_type == JVMTI_PRIMITIVE_TYPE_BOOLEAN || |
| 130 | prim_type == JVMTI_PRIMITIVE_TYPE_BYTE || |
| 131 | prim_type == JVMTI_PRIMITIVE_TYPE_CHAR || |
| 132 | prim_type == JVMTI_PRIMITIVE_TYPE_SHORT || |
| 133 | prim_type == JVMTI_PRIMITIVE_TYPE_INT || |
| 134 | prim_type == JVMTI_PRIMITIVE_TYPE_LONG || |
| 135 | prim_type == JVMTI_PRIMITIVE_TYPE_FLOAT || |
| 136 | prim_type == JVMTI_PRIMITIVE_TYPE_DOUBLE); |
| 137 | |
| 138 | const jlong class_tag = tag_table->GetTagOrZero(obj->GetClass()); |
| 139 | jlong array_tag = tag_table->GetTagOrZero(obj.Ptr()); |
| 140 | const jlong saved_array_tag = array_tag; |
| 141 | |
| 142 | jint result; |
| 143 | if (array_length == 0) { |
| 144 | result = cb->array_primitive_value_callback(class_tag, |
| 145 | obj->SizeOf(), |
| 146 | &array_tag, |
| 147 | 0, |
| 148 | prim_type, |
| 149 | nullptr, |
| 150 | const_cast<void*>(user_data)); |
| 151 | } else { |
| 152 | jvmtiError alloc_error; |
| 153 | JvmtiUniquePtr<char[]> data = AllocJvmtiUniquePtr<char[]>(env, |
| 154 | array_length * component_size, |
| 155 | &alloc_error); |
| 156 | if (data == nullptr) { |
| 157 | // TODO: Not really sure what to do here. Should we abort the iteration and go all the way |
| 158 | // back? For now just warn. |
| 159 | LOG(WARNING) << "Unable to allocate buffer for array reporting! Silently dropping value."; |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | memcpy(data.get(), array->GetRawData(component_size, 0), array_length * component_size); |
| 164 | |
| 165 | result = cb->array_primitive_value_callback(class_tag, |
| 166 | obj->SizeOf(), |
| 167 | &array_tag, |
| 168 | array_length, |
| 169 | prim_type, |
| 170 | data.get(), |
| 171 | const_cast<void*>(user_data)); |
| 172 | } |
| 173 | |
| 174 | if (array_tag != saved_array_tag) { |
| 175 | tag_table->Set(obj.Ptr(), array_tag); |
| 176 | } |
| 177 | |
| 178 | return result; |
| 179 | } |
| 180 | return 0; |
| 181 | } |
| 182 | |
Andreas Gampe | e731693 | 2017-02-25 09:15:05 -0800 | [diff] [blame] | 183 | template <typename UserData> |
| 184 | bool VisitorFalse(art::ObjPtr<art::mirror::Object> obj ATTRIBUTE_UNUSED, |
| 185 | art::ObjPtr<art::mirror::Class> klass ATTRIBUTE_UNUSED, |
| 186 | art::ArtField& field ATTRIBUTE_UNUSED, |
| 187 | size_t field_index ATTRIBUTE_UNUSED, |
| 188 | UserData* user_data ATTRIBUTE_UNUSED) { |
| 189 | return false; |
| 190 | } |
| 191 | |
Andreas Gampe | 9511460 | 2017-02-28 15:47:44 -0800 | [diff] [blame] | 192 | template <typename UserData, bool kCallVisitorOnRecursion> |
Andreas Gampe | e731693 | 2017-02-25 09:15:05 -0800 | [diff] [blame] | 193 | class FieldVisitor { |
| 194 | public: |
| 195 | // Report the contents of a primitive fields of the given object, if a callback is set. |
Andreas Gampe | 9511460 | 2017-02-28 15:47:44 -0800 | [diff] [blame] | 196 | template <typename StaticPrimitiveVisitor, |
| 197 | typename StaticReferenceVisitor, |
| 198 | typename InstancePrimitiveVisitor, |
| 199 | typename InstanceReferenceVisitor> |
Andreas Gampe | e731693 | 2017-02-25 09:15:05 -0800 | [diff] [blame] | 200 | static bool ReportFields(art::ObjPtr<art::mirror::Object> obj, |
| 201 | UserData* user_data, |
| 202 | StaticPrimitiveVisitor& static_prim_visitor, |
| 203 | StaticReferenceVisitor& static_ref_visitor, |
| 204 | InstancePrimitiveVisitor& instance_prim_visitor, |
| 205 | InstanceReferenceVisitor& instance_ref_visitor) |
| 206 | REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 207 | FieldVisitor fv(user_data); |
| 208 | |
| 209 | if (obj->IsClass()) { |
| 210 | // When visiting a class, we only visit the static fields of the given class. No field of |
| 211 | // superclasses is visited. |
| 212 | art::ObjPtr<art::mirror::Class> klass = obj->AsClass(); |
| 213 | // Only report fields on resolved classes. We need valid field data. |
| 214 | if (!klass->IsResolved()) { |
| 215 | return false; |
| 216 | } |
| 217 | return fv.ReportFieldsImpl(nullptr, |
| 218 | obj->AsClass(), |
| 219 | obj->AsClass()->IsInterface(), |
| 220 | static_prim_visitor, |
| 221 | static_ref_visitor, |
| 222 | instance_prim_visitor, |
| 223 | instance_ref_visitor); |
| 224 | } else { |
| 225 | // See comment above. Just double-checking here, but an instance *should* mean the class was |
| 226 | // resolved. |
| 227 | DCHECK(obj->GetClass()->IsResolved() || obj->GetClass()->IsErroneousResolved()); |
| 228 | return fv.ReportFieldsImpl(obj, |
| 229 | obj->GetClass(), |
| 230 | false, |
| 231 | static_prim_visitor, |
| 232 | static_ref_visitor, |
| 233 | instance_prim_visitor, |
| 234 | instance_ref_visitor); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | private: |
| 239 | explicit FieldVisitor(UserData* user_data) : user_data_(user_data) {} |
| 240 | |
| 241 | // Report the contents of fields of the given object. If obj is null, report the static fields, |
| 242 | // otherwise the instance fields. |
Andreas Gampe | 9511460 | 2017-02-28 15:47:44 -0800 | [diff] [blame] | 243 | template <typename StaticPrimitiveVisitor, |
| 244 | typename StaticReferenceVisitor, |
| 245 | typename InstancePrimitiveVisitor, |
| 246 | typename InstanceReferenceVisitor> |
Andreas Gampe | e731693 | 2017-02-25 09:15:05 -0800 | [diff] [blame] | 247 | bool ReportFieldsImpl(art::ObjPtr<art::mirror::Object> obj, |
| 248 | art::ObjPtr<art::mirror::Class> klass, |
| 249 | bool skip_java_lang_object, |
| 250 | StaticPrimitiveVisitor& static_prim_visitor, |
| 251 | StaticReferenceVisitor& static_ref_visitor, |
| 252 | InstancePrimitiveVisitor& instance_prim_visitor, |
| 253 | InstanceReferenceVisitor& instance_ref_visitor) |
| 254 | REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 255 | // Compute the offset of field indices. |
| 256 | size_t interface_field_count = CountInterfaceFields(klass); |
| 257 | |
| 258 | size_t tmp; |
| 259 | bool aborted = ReportFieldsRecursive(obj, |
| 260 | klass, |
| 261 | interface_field_count, |
| 262 | skip_java_lang_object, |
| 263 | static_prim_visitor, |
| 264 | static_ref_visitor, |
| 265 | instance_prim_visitor, |
| 266 | instance_ref_visitor, |
| 267 | &tmp); |
| 268 | return aborted; |
| 269 | } |
| 270 | |
| 271 | // Visit primitive fields in an object (instance). Return true if the visit was aborted. |
Andreas Gampe | 9511460 | 2017-02-28 15:47:44 -0800 | [diff] [blame] | 272 | template <typename StaticPrimitiveVisitor, |
| 273 | typename StaticReferenceVisitor, |
| 274 | typename InstancePrimitiveVisitor, |
| 275 | typename InstanceReferenceVisitor> |
Andreas Gampe | e731693 | 2017-02-25 09:15:05 -0800 | [diff] [blame] | 276 | bool ReportFieldsRecursive(art::ObjPtr<art::mirror::Object> obj, |
| 277 | art::ObjPtr<art::mirror::Class> klass, |
| 278 | size_t interface_fields, |
| 279 | bool skip_java_lang_object, |
| 280 | StaticPrimitiveVisitor& static_prim_visitor, |
| 281 | StaticReferenceVisitor& static_ref_visitor, |
| 282 | InstancePrimitiveVisitor& instance_prim_visitor, |
| 283 | InstanceReferenceVisitor& instance_ref_visitor, |
| 284 | size_t* field_index_out) |
| 285 | REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 286 | DCHECK(klass != nullptr); |
| 287 | size_t field_index; |
| 288 | if (klass->GetSuperClass() == nullptr) { |
| 289 | // j.l.Object. Start with the fields from interfaces. |
| 290 | field_index = interface_fields; |
| 291 | if (skip_java_lang_object) { |
| 292 | *field_index_out = field_index; |
| 293 | return false; |
| 294 | } |
| 295 | } else { |
| 296 | // Report superclass fields. |
| 297 | if (kCallVisitorOnRecursion) { |
| 298 | if (ReportFieldsRecursive(obj, |
| 299 | klass->GetSuperClass(), |
| 300 | interface_fields, |
| 301 | skip_java_lang_object, |
| 302 | static_prim_visitor, |
| 303 | static_ref_visitor, |
| 304 | instance_prim_visitor, |
| 305 | instance_ref_visitor, |
| 306 | &field_index)) { |
| 307 | return true; |
| 308 | } |
| 309 | } else { |
| 310 | // Still call, but with empty visitor. This is required for correct counting. |
| 311 | ReportFieldsRecursive(obj, |
| 312 | klass->GetSuperClass(), |
| 313 | interface_fields, |
| 314 | skip_java_lang_object, |
| 315 | VisitorFalse<UserData>, |
| 316 | VisitorFalse<UserData>, |
| 317 | VisitorFalse<UserData>, |
| 318 | VisitorFalse<UserData>, |
| 319 | &field_index); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | // Now visit fields for the current klass. |
| 324 | |
| 325 | for (auto& static_field : klass->GetSFields()) { |
| 326 | if (static_field.IsPrimitiveType()) { |
| 327 | if (static_prim_visitor(obj, |
| 328 | klass, |
| 329 | static_field, |
| 330 | field_index, |
| 331 | user_data_)) { |
| 332 | return true; |
| 333 | } |
| 334 | } else { |
| 335 | if (static_ref_visitor(obj, |
| 336 | klass, |
| 337 | static_field, |
| 338 | field_index, |
| 339 | user_data_)) { |
| 340 | return true; |
| 341 | } |
| 342 | } |
| 343 | field_index++; |
| 344 | } |
| 345 | |
| 346 | for (auto& instance_field : klass->GetIFields()) { |
| 347 | if (instance_field.IsPrimitiveType()) { |
| 348 | if (instance_prim_visitor(obj, |
| 349 | klass, |
| 350 | instance_field, |
| 351 | field_index, |
| 352 | user_data_)) { |
| 353 | return true; |
| 354 | } |
| 355 | } else { |
| 356 | if (instance_ref_visitor(obj, |
| 357 | klass, |
| 358 | instance_field, |
| 359 | field_index, |
| 360 | user_data_)) { |
| 361 | return true; |
| 362 | } |
| 363 | } |
| 364 | field_index++; |
| 365 | } |
| 366 | |
| 367 | *field_index_out = field_index; |
| 368 | return false; |
| 369 | } |
| 370 | |
| 371 | // Implements a visit of the implemented interfaces of a given class. |
| 372 | template <typename T> |
| 373 | struct RecursiveInterfaceVisit { |
| 374 | static void VisitStatic(art::Thread* self, art::ObjPtr<art::mirror::Class> klass, T& visitor) |
| 375 | REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 376 | RecursiveInterfaceVisit rv; |
| 377 | rv.Visit(self, klass, visitor); |
| 378 | } |
| 379 | |
| 380 | void Visit(art::Thread* self, art::ObjPtr<art::mirror::Class> klass, T& visitor) |
| 381 | REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 382 | // First visit the parent, to get the order right. |
| 383 | // (We do this in preparation for actual visiting of interface fields.) |
| 384 | if (klass->GetSuperClass() != nullptr) { |
| 385 | Visit(self, klass->GetSuperClass(), visitor); |
| 386 | } |
| 387 | for (uint32_t i = 0; i != klass->NumDirectInterfaces(); ++i) { |
| 388 | art::ObjPtr<art::mirror::Class> inf_klass = |
| 389 | art::mirror::Class::GetDirectInterface(self, klass, i); |
| 390 | DCHECK(inf_klass != nullptr); |
| 391 | VisitInterface(self, inf_klass, visitor); |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | void VisitInterface(art::Thread* self, art::ObjPtr<art::mirror::Class> inf_klass, T& visitor) |
| 396 | REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 397 | auto it = visited_interfaces.find(inf_klass.Ptr()); |
| 398 | if (it != visited_interfaces.end()) { |
| 399 | return; |
| 400 | } |
| 401 | visited_interfaces.insert(inf_klass.Ptr()); |
| 402 | |
| 403 | // Let the visitor know about this one. Note that this order is acceptable, as the ordering |
| 404 | // of these fields never matters for known visitors. |
| 405 | visitor(inf_klass); |
| 406 | |
| 407 | // Now visit the superinterfaces. |
| 408 | for (uint32_t i = 0; i != inf_klass->NumDirectInterfaces(); ++i) { |
| 409 | art::ObjPtr<art::mirror::Class> super_inf_klass = |
| 410 | art::mirror::Class::GetDirectInterface(self, inf_klass, i); |
| 411 | DCHECK(super_inf_klass != nullptr); |
| 412 | VisitInterface(self, super_inf_klass, visitor); |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | std::unordered_set<art::mirror::Class*> visited_interfaces; |
| 417 | }; |
| 418 | |
| 419 | // Counting interface fields. Note that we cannot use the interface table, as that only contains |
| 420 | // "non-marker" interfaces (= interfaces with methods). |
| 421 | static size_t CountInterfaceFields(art::ObjPtr<art::mirror::Class> klass) |
| 422 | REQUIRES_SHARED(art::Locks::mutator_lock_) { |
Andreas Gampe | 9e38a50 | 2017-03-06 08:19:26 -0800 | [diff] [blame] | 423 | // Do we have a cached value? |
| 424 | IndexCache tmp; |
| 425 | if (gIndexCachingTable.GetTag(klass.Ptr(), &tmp)) { |
| 426 | return tmp.interface_fields; |
| 427 | } |
| 428 | |
Andreas Gampe | e731693 | 2017-02-25 09:15:05 -0800 | [diff] [blame] | 429 | size_t count = 0; |
| 430 | auto visitor = [&count](art::ObjPtr<art::mirror::Class> inf_klass) |
| 431 | REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 432 | DCHECK(inf_klass->IsInterface()); |
| 433 | DCHECK_EQ(0u, inf_klass->NumInstanceFields()); |
| 434 | count += inf_klass->NumStaticFields(); |
| 435 | }; |
| 436 | RecursiveInterfaceVisit<decltype(visitor)>::VisitStatic(art::Thread::Current(), klass, visitor); |
Andreas Gampe | e731693 | 2017-02-25 09:15:05 -0800 | [diff] [blame] | 437 | |
Andreas Gampe | 9e38a50 | 2017-03-06 08:19:26 -0800 | [diff] [blame] | 438 | // Store this into the cache. |
| 439 | tmp.interface_fields = count; |
| 440 | gIndexCachingTable.Set(klass.Ptr(), tmp); |
| 441 | |
| 442 | return count; |
Andreas Gampe | e731693 | 2017-02-25 09:15:05 -0800 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | UserData* user_data_; |
| 446 | }; |
| 447 | |
| 448 | // Debug helper. Prints the structure of an object. |
| 449 | template <bool kStatic, bool kRef> |
| 450 | struct DumpVisitor { |
| 451 | static bool Callback(art::ObjPtr<art::mirror::Object> obj ATTRIBUTE_UNUSED, |
| 452 | art::ObjPtr<art::mirror::Class> klass ATTRIBUTE_UNUSED, |
| 453 | art::ArtField& field, |
| 454 | size_t field_index, |
| 455 | void* user_data ATTRIBUTE_UNUSED) |
| 456 | REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 457 | LOG(ERROR) << (kStatic ? "static " : "instance ") |
| 458 | << (kRef ? "ref " : "primitive ") |
| 459 | << field.PrettyField() |
| 460 | << " @ " |
| 461 | << field_index; |
| 462 | return false; |
| 463 | } |
| 464 | }; |
| 465 | ATTRIBUTE_UNUSED |
| 466 | void DumpObjectFields(art::ObjPtr<art::mirror::Object> obj) |
| 467 | REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 468 | if (obj->IsClass()) { |
Andreas Gampe | 9511460 | 2017-02-28 15:47:44 -0800 | [diff] [blame] | 469 | FieldVisitor<void, false>:: ReportFields(obj, |
| 470 | nullptr, |
| 471 | DumpVisitor<true, false>::Callback, |
| 472 | DumpVisitor<true, true>::Callback, |
| 473 | DumpVisitor<false, false>::Callback, |
| 474 | DumpVisitor<false, true>::Callback); |
Andreas Gampe | e731693 | 2017-02-25 09:15:05 -0800 | [diff] [blame] | 475 | } else { |
Andreas Gampe | 9511460 | 2017-02-28 15:47:44 -0800 | [diff] [blame] | 476 | FieldVisitor<void, true>::ReportFields(obj, |
| 477 | nullptr, |
| 478 | DumpVisitor<true, false>::Callback, |
| 479 | DumpVisitor<true, true>::Callback, |
| 480 | DumpVisitor<false, false>::Callback, |
| 481 | DumpVisitor<false, true>::Callback); |
Andreas Gampe | e731693 | 2017-02-25 09:15:05 -0800 | [diff] [blame] | 482 | } |
| 483 | } |
| 484 | |
| 485 | class ReportPrimitiveField { |
| 486 | public: |
| 487 | static bool Report(art::ObjPtr<art::mirror::Object> obj, |
| 488 | ObjectTagTable* tag_table, |
| 489 | const jvmtiHeapCallbacks* cb, |
| 490 | const void* user_data) |
| 491 | REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 492 | if (UNLIKELY(cb->primitive_field_callback != nullptr)) { |
| 493 | jlong class_tag = tag_table->GetTagOrZero(obj->GetClass()); |
| 494 | ReportPrimitiveField rpf(tag_table, class_tag, cb, user_data); |
| 495 | if (obj->IsClass()) { |
Andreas Gampe | 9511460 | 2017-02-28 15:47:44 -0800 | [diff] [blame] | 496 | return FieldVisitor<ReportPrimitiveField, false>::ReportFields( |
| 497 | obj, |
| 498 | &rpf, |
| 499 | ReportPrimitiveFieldCallback<true>, |
| 500 | VisitorFalse<ReportPrimitiveField>, |
| 501 | VisitorFalse<ReportPrimitiveField>, |
| 502 | VisitorFalse<ReportPrimitiveField>); |
Andreas Gampe | e731693 | 2017-02-25 09:15:05 -0800 | [diff] [blame] | 503 | } else { |
Andreas Gampe | 9511460 | 2017-02-28 15:47:44 -0800 | [diff] [blame] | 504 | return FieldVisitor<ReportPrimitiveField, true>::ReportFields( |
| 505 | obj, |
| 506 | &rpf, |
| 507 | VisitorFalse<ReportPrimitiveField>, |
| 508 | VisitorFalse<ReportPrimitiveField>, |
| 509 | ReportPrimitiveFieldCallback<false>, |
| 510 | VisitorFalse<ReportPrimitiveField>); |
Andreas Gampe | e731693 | 2017-02-25 09:15:05 -0800 | [diff] [blame] | 511 | } |
| 512 | } |
| 513 | return false; |
| 514 | } |
| 515 | |
| 516 | |
| 517 | private: |
| 518 | ReportPrimitiveField(ObjectTagTable* tag_table, |
| 519 | jlong class_tag, |
| 520 | const jvmtiHeapCallbacks* cb, |
| 521 | const void* user_data) |
| 522 | : tag_table_(tag_table), class_tag_(class_tag), cb_(cb), user_data_(user_data) {} |
| 523 | |
| 524 | template <bool kReportStatic> |
| 525 | static bool ReportPrimitiveFieldCallback(art::ObjPtr<art::mirror::Object> obj, |
| 526 | art::ObjPtr<art::mirror::Class> klass, |
| 527 | art::ArtField& field, |
| 528 | size_t field_index, |
| 529 | ReportPrimitiveField* user_data) |
| 530 | REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 531 | art::Primitive::Type art_prim_type = field.GetTypeAsPrimitiveType(); |
| 532 | jvmtiPrimitiveType prim_type = |
| 533 | static_cast<jvmtiPrimitiveType>(art::Primitive::Descriptor(art_prim_type)[0]); |
| 534 | DCHECK(prim_type == JVMTI_PRIMITIVE_TYPE_BOOLEAN || |
| 535 | prim_type == JVMTI_PRIMITIVE_TYPE_BYTE || |
| 536 | prim_type == JVMTI_PRIMITIVE_TYPE_CHAR || |
| 537 | prim_type == JVMTI_PRIMITIVE_TYPE_SHORT || |
| 538 | prim_type == JVMTI_PRIMITIVE_TYPE_INT || |
| 539 | prim_type == JVMTI_PRIMITIVE_TYPE_LONG || |
| 540 | prim_type == JVMTI_PRIMITIVE_TYPE_FLOAT || |
| 541 | prim_type == JVMTI_PRIMITIVE_TYPE_DOUBLE); |
| 542 | jvmtiHeapReferenceInfo info; |
| 543 | info.field.index = field_index; |
| 544 | |
| 545 | jvalue value; |
| 546 | memset(&value, 0, sizeof(jvalue)); |
| 547 | art::ObjPtr<art::mirror::Object> src = kReportStatic ? klass : obj; |
| 548 | switch (art_prim_type) { |
| 549 | case art::Primitive::Type::kPrimBoolean: |
| 550 | value.z = field.GetBoolean(src) == 0 ? JNI_FALSE : JNI_TRUE; |
| 551 | break; |
| 552 | case art::Primitive::Type::kPrimByte: |
| 553 | value.b = field.GetByte(src); |
| 554 | break; |
| 555 | case art::Primitive::Type::kPrimChar: |
| 556 | value.c = field.GetChar(src); |
| 557 | break; |
| 558 | case art::Primitive::Type::kPrimShort: |
| 559 | value.s = field.GetShort(src); |
| 560 | break; |
| 561 | case art::Primitive::Type::kPrimInt: |
| 562 | value.i = field.GetInt(src); |
| 563 | break; |
| 564 | case art::Primitive::Type::kPrimLong: |
| 565 | value.j = field.GetLong(src); |
| 566 | break; |
| 567 | case art::Primitive::Type::kPrimFloat: |
| 568 | value.f = field.GetFloat(src); |
| 569 | break; |
| 570 | case art::Primitive::Type::kPrimDouble: |
| 571 | value.d = field.GetDouble(src); |
| 572 | break; |
| 573 | case art::Primitive::Type::kPrimVoid: |
| 574 | case art::Primitive::Type::kPrimNot: { |
| 575 | LOG(FATAL) << "Should not reach here"; |
| 576 | UNREACHABLE(); |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | jlong obj_tag = user_data->tag_table_->GetTagOrZero(src.Ptr()); |
| 581 | const jlong saved_obj_tag = obj_tag; |
| 582 | |
| 583 | jint ret = user_data->cb_->primitive_field_callback(kReportStatic |
| 584 | ? JVMTI_HEAP_REFERENCE_STATIC_FIELD |
| 585 | : JVMTI_HEAP_REFERENCE_FIELD, |
| 586 | &info, |
| 587 | user_data->class_tag_, |
| 588 | &obj_tag, |
| 589 | value, |
| 590 | prim_type, |
| 591 | const_cast<void*>(user_data->user_data_)); |
| 592 | |
| 593 | if (saved_obj_tag != obj_tag) { |
| 594 | user_data->tag_table_->Set(src.Ptr(), obj_tag); |
| 595 | } |
| 596 | |
| 597 | if ((ret & JVMTI_VISIT_ABORT) != 0) { |
| 598 | return true; |
| 599 | } |
| 600 | |
| 601 | return false; |
| 602 | } |
| 603 | |
| 604 | ObjectTagTable* tag_table_; |
| 605 | jlong class_tag_; |
| 606 | const jvmtiHeapCallbacks* cb_; |
| 607 | const void* user_data_; |
| 608 | }; |
| 609 | |
Andreas Gampe | 6ea0607 | 2017-02-24 18:01:19 +0000 | [diff] [blame] | 610 | struct HeapFilter { |
| 611 | explicit HeapFilter(jint heap_filter) |
| 612 | : filter_out_tagged((heap_filter & JVMTI_HEAP_FILTER_TAGGED) != 0), |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 613 | filter_out_untagged((heap_filter & JVMTI_HEAP_FILTER_UNTAGGED) != 0), |
| 614 | filter_out_class_tagged((heap_filter & JVMTI_HEAP_FILTER_CLASS_TAGGED) != 0), |
| 615 | filter_out_class_untagged((heap_filter & JVMTI_HEAP_FILTER_CLASS_UNTAGGED) != 0), |
| 616 | any_filter(filter_out_tagged || |
| 617 | filter_out_untagged || |
| 618 | filter_out_class_tagged || |
Andreas Gampe | 6ea0607 | 2017-02-24 18:01:19 +0000 | [diff] [blame] | 619 | filter_out_class_untagged) { |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 620 | } |
| 621 | |
Andreas Gampe | 6ea0607 | 2017-02-24 18:01:19 +0000 | [diff] [blame] | 622 | bool ShouldReportByHeapFilter(jlong tag, jlong class_tag) const { |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 623 | if (!any_filter) { |
| 624 | return true; |
| 625 | } |
| 626 | |
| 627 | if ((tag == 0 && filter_out_untagged) || (tag != 0 && filter_out_tagged)) { |
| 628 | return false; |
| 629 | } |
| 630 | |
| 631 | if ((class_tag == 0 && filter_out_class_untagged) || |
| 632 | (class_tag != 0 && filter_out_class_tagged)) { |
| 633 | return false; |
| 634 | } |
| 635 | |
| 636 | return true; |
| 637 | } |
| 638 | |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 639 | const bool filter_out_tagged; |
| 640 | const bool filter_out_untagged; |
| 641 | const bool filter_out_class_tagged; |
| 642 | const bool filter_out_class_untagged; |
| 643 | const bool any_filter; |
Andreas Gampe | 6ea0607 | 2017-02-24 18:01:19 +0000 | [diff] [blame] | 644 | }; |
| 645 | |
| 646 | } // namespace |
| 647 | |
Andreas Gampe | 9e38a50 | 2017-03-06 08:19:26 -0800 | [diff] [blame] | 648 | void HeapUtil::Register() { |
| 649 | art::Runtime::Current()->AddSystemWeakHolder(&gIndexCachingTable); |
| 650 | } |
| 651 | |
| 652 | void HeapUtil::Unregister() { |
| 653 | art::Runtime::Current()->RemoveSystemWeakHolder(&gIndexCachingTable); |
| 654 | } |
| 655 | |
Andreas Gampe | f787fd3 | 2017-05-09 16:04:20 -0700 | [diff] [blame] | 656 | template <typename Callback> |
Andreas Gampe | 6ea0607 | 2017-02-24 18:01:19 +0000 | [diff] [blame] | 657 | struct IterateThroughHeapData { |
Andreas Gampe | f787fd3 | 2017-05-09 16:04:20 -0700 | [diff] [blame] | 658 | IterateThroughHeapData(Callback _cb, |
| 659 | ObjectTagTable* _tag_table, |
Andreas Gampe | 6ea0607 | 2017-02-24 18:01:19 +0000 | [diff] [blame] | 660 | jvmtiEnv* _env, |
| 661 | art::ObjPtr<art::mirror::Class> klass, |
| 662 | jint _heap_filter, |
| 663 | const jvmtiHeapCallbacks* _callbacks, |
| 664 | const void* _user_data) |
Andreas Gampe | f787fd3 | 2017-05-09 16:04:20 -0700 | [diff] [blame] | 665 | : cb(_cb), |
| 666 | tag_table(_tag_table), |
Andreas Gampe | 6ea0607 | 2017-02-24 18:01:19 +0000 | [diff] [blame] | 667 | heap_filter(_heap_filter), |
| 668 | filter_klass(klass), |
| 669 | env(_env), |
| 670 | callbacks(_callbacks), |
| 671 | user_data(_user_data), |
| 672 | stop_reports(false) { |
| 673 | } |
| 674 | |
Andreas Gampe | f787fd3 | 2017-05-09 16:04:20 -0700 | [diff] [blame] | 675 | static void ObjectCallback(art::mirror::Object* obj, void* arg) |
| 676 | REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 677 | IterateThroughHeapData* ithd = reinterpret_cast<IterateThroughHeapData*>(arg); |
| 678 | ithd->ObjectCallback(obj); |
| 679 | } |
| 680 | |
| 681 | void ObjectCallback(art::mirror::Object* obj) |
| 682 | REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 683 | // Early return, as we can't really stop visiting. |
| 684 | if (stop_reports) { |
| 685 | return; |
| 686 | } |
| 687 | |
| 688 | art::ScopedAssertNoThreadSuspension no_suspension("IterateThroughHeapCallback"); |
| 689 | |
| 690 | jlong tag = 0; |
| 691 | tag_table->GetTag(obj, &tag); |
| 692 | |
| 693 | jlong class_tag = 0; |
| 694 | art::ObjPtr<art::mirror::Class> klass = obj->GetClass(); |
| 695 | tag_table->GetTag(klass.Ptr(), &class_tag); |
| 696 | // For simplicity, even if we find a tag = 0, assume 0 = not tagged. |
| 697 | |
| 698 | if (!heap_filter.ShouldReportByHeapFilter(tag, class_tag)) { |
| 699 | return; |
| 700 | } |
| 701 | |
| 702 | if (filter_klass != nullptr) { |
| 703 | if (filter_klass != klass) { |
| 704 | return; |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | jlong size = obj->SizeOf(); |
| 709 | |
| 710 | jint length = -1; |
| 711 | if (obj->IsArrayInstance()) { |
| 712 | length = obj->AsArray()->GetLength(); |
| 713 | } |
| 714 | |
| 715 | jlong saved_tag = tag; |
| 716 | jint ret = cb(obj, callbacks, class_tag, size, &tag, length, const_cast<void*>(user_data)); |
| 717 | |
| 718 | if (tag != saved_tag) { |
| 719 | tag_table->Set(obj, tag); |
| 720 | } |
| 721 | |
| 722 | stop_reports = (ret & JVMTI_VISIT_ABORT) != 0; |
| 723 | |
| 724 | if (!stop_reports) { |
| 725 | jint string_ret = ReportString(obj, env, tag_table, callbacks, user_data); |
| 726 | stop_reports = (string_ret & JVMTI_VISIT_ABORT) != 0; |
| 727 | } |
| 728 | |
| 729 | if (!stop_reports) { |
| 730 | jint array_ret = ReportPrimitiveArray(obj, env, tag_table, callbacks, user_data); |
| 731 | stop_reports = (array_ret & JVMTI_VISIT_ABORT) != 0; |
| 732 | } |
| 733 | |
| 734 | if (!stop_reports) { |
| 735 | stop_reports = ReportPrimitiveField::Report(obj, tag_table, callbacks, user_data); |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | Callback cb; |
| 740 | ObjectTagTable* tag_table; |
Andreas Gampe | 6ea0607 | 2017-02-24 18:01:19 +0000 | [diff] [blame] | 741 | const HeapFilter heap_filter; |
| 742 | art::ObjPtr<art::mirror::Class> filter_klass; |
| 743 | jvmtiEnv* env; |
| 744 | const jvmtiHeapCallbacks* callbacks; |
| 745 | const void* user_data; |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 746 | |
| 747 | bool stop_reports; |
| 748 | }; |
| 749 | |
Andreas Gampe | f787fd3 | 2017-05-09 16:04:20 -0700 | [diff] [blame] | 750 | template <typename T> |
| 751 | static jvmtiError DoIterateThroughHeap(T fn, |
| 752 | jvmtiEnv* env, |
| 753 | ObjectTagTable* tag_table, |
| 754 | jint heap_filter, |
| 755 | jclass klass, |
| 756 | const jvmtiHeapCallbacks* callbacks, |
| 757 | const void* user_data) { |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 758 | if (callbacks == nullptr) { |
| 759 | return ERR(NULL_POINTER); |
| 760 | } |
| 761 | |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 762 | art::Thread* self = art::Thread::Current(); |
| 763 | art::ScopedObjectAccess soa(self); // Now we know we have the shared lock. |
| 764 | |
Andreas Gampe | f787fd3 | 2017-05-09 16:04:20 -0700 | [diff] [blame] | 765 | using Iterator = IterateThroughHeapData<T>; |
| 766 | Iterator ithd(fn, |
| 767 | tag_table, |
| 768 | env, |
| 769 | soa.Decode<art::mirror::Class>(klass), |
| 770 | heap_filter, |
| 771 | callbacks, |
| 772 | user_data); |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 773 | |
Andreas Gampe | f787fd3 | 2017-05-09 16:04:20 -0700 | [diff] [blame] | 774 | art::Runtime::Current()->GetHeap()->VisitObjects(Iterator::ObjectCallback, &ithd); |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 775 | |
| 776 | return ERR(NONE); |
| 777 | } |
| 778 | |
Andreas Gampe | f787fd3 | 2017-05-09 16:04:20 -0700 | [diff] [blame] | 779 | jvmtiError HeapUtil::IterateThroughHeap(jvmtiEnv* env, |
| 780 | jint heap_filter, |
| 781 | jclass klass, |
| 782 | const jvmtiHeapCallbacks* callbacks, |
| 783 | const void* user_data) { |
| 784 | auto JvmtiIterateHeap = [](art::mirror::Object* obj ATTRIBUTE_UNUSED, |
| 785 | const jvmtiHeapCallbacks* cb_callbacks, |
| 786 | jlong class_tag, |
| 787 | jlong size, |
| 788 | jlong* tag, |
| 789 | jint length, |
| 790 | void* cb_user_data) |
| 791 | REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 792 | return cb_callbacks->heap_iteration_callback(class_tag, |
| 793 | size, |
| 794 | tag, |
| 795 | length, |
| 796 | cb_user_data); |
| 797 | }; |
| 798 | return DoIterateThroughHeap(JvmtiIterateHeap, |
| 799 | env, |
| 800 | ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get(), |
| 801 | heap_filter, |
| 802 | klass, |
| 803 | callbacks, |
| 804 | user_data); |
| 805 | } |
| 806 | |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 807 | class FollowReferencesHelper FINAL { |
| 808 | public: |
| 809 | FollowReferencesHelper(HeapUtil* h, |
Andreas Gampe | 3ec8e40 | 2017-02-21 15:49:53 -0800 | [diff] [blame] | 810 | jvmtiEnv* jvmti_env, |
Andreas Gampe | 638a693 | 2016-12-02 19:11:17 -0800 | [diff] [blame] | 811 | art::ObjPtr<art::mirror::Object> initial_object, |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 812 | const jvmtiHeapCallbacks* callbacks, |
Andreas Gampe | 38da9f2 | 2017-02-20 13:35:36 -0800 | [diff] [blame] | 813 | art::ObjPtr<art::mirror::Class> class_filter, |
Andreas Gampe | 6ea0607 | 2017-02-24 18:01:19 +0000 | [diff] [blame] | 814 | jint heap_filter, |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 815 | const void* user_data) |
Andreas Gampe | 3ec8e40 | 2017-02-21 15:49:53 -0800 | [diff] [blame] | 816 | : env(jvmti_env), |
| 817 | tag_table_(h->GetTags()), |
Andreas Gampe | 638a693 | 2016-12-02 19:11:17 -0800 | [diff] [blame] | 818 | initial_object_(initial_object), |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 819 | callbacks_(callbacks), |
Andreas Gampe | 38da9f2 | 2017-02-20 13:35:36 -0800 | [diff] [blame] | 820 | class_filter_(class_filter), |
Andreas Gampe | 6ea0607 | 2017-02-24 18:01:19 +0000 | [diff] [blame] | 821 | heap_filter_(heap_filter), |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 822 | user_data_(user_data), |
| 823 | start_(0), |
| 824 | stop_reports_(false) { |
| 825 | } |
| 826 | |
| 827 | void Init() |
| 828 | REQUIRES_SHARED(art::Locks::mutator_lock_) |
| 829 | REQUIRES(!*tag_table_->GetAllowDisallowLock()) { |
Andreas Gampe | 638a693 | 2016-12-02 19:11:17 -0800 | [diff] [blame] | 830 | if (initial_object_.IsNull()) { |
| 831 | CollectAndReportRootsVisitor carrv(this, tag_table_, &worklist_, &visited_); |
Andreas Gampe | f10dfcd | 2016-12-02 14:42:33 -0800 | [diff] [blame] | 832 | |
| 833 | // We need precise info (e.g., vregs). |
| 834 | constexpr art::VisitRootFlags kRootFlags = static_cast<art::VisitRootFlags>( |
| 835 | art::VisitRootFlags::kVisitRootFlagAllRoots | art::VisitRootFlags::kVisitRootFlagPrecise); |
| 836 | art::Runtime::Current()->VisitRoots(&carrv, kRootFlags); |
| 837 | |
Andreas Gampe | 638a693 | 2016-12-02 19:11:17 -0800 | [diff] [blame] | 838 | art::Runtime::Current()->VisitImageRoots(&carrv); |
| 839 | stop_reports_ = carrv.IsStopReports(); |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 840 | |
Andreas Gampe | 638a693 | 2016-12-02 19:11:17 -0800 | [diff] [blame] | 841 | if (stop_reports_) { |
| 842 | worklist_.clear(); |
| 843 | } |
| 844 | } else { |
| 845 | visited_.insert(initial_object_.Ptr()); |
| 846 | worklist_.push_back(initial_object_.Ptr()); |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 847 | } |
| 848 | } |
| 849 | |
| 850 | void Work() |
| 851 | REQUIRES_SHARED(art::Locks::mutator_lock_) |
| 852 | REQUIRES(!*tag_table_->GetAllowDisallowLock()) { |
| 853 | // Currently implemented as a BFS. To lower overhead, we don't erase elements immediately |
| 854 | // from the head of the work list, instead postponing until there's a gap that's "large." |
| 855 | // |
| 856 | // Alternatively, we can implement a DFS and use the work list as a stack. |
| 857 | while (start_ < worklist_.size()) { |
| 858 | art::mirror::Object* cur_obj = worklist_[start_]; |
| 859 | start_++; |
| 860 | |
| 861 | if (start_ >= kMaxStart) { |
| 862 | worklist_.erase(worklist_.begin(), worklist_.begin() + start_); |
| 863 | start_ = 0; |
| 864 | } |
| 865 | |
| 866 | VisitObject(cur_obj); |
| 867 | |
| 868 | if (stop_reports_) { |
| 869 | break; |
| 870 | } |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | private: |
| 875 | class CollectAndReportRootsVisitor FINAL : public art::RootVisitor { |
| 876 | public: |
| 877 | CollectAndReportRootsVisitor(FollowReferencesHelper* helper, |
| 878 | ObjectTagTable* tag_table, |
| 879 | std::vector<art::mirror::Object*>* worklist, |
| 880 | std::unordered_set<art::mirror::Object*>* visited) |
| 881 | : helper_(helper), |
| 882 | tag_table_(tag_table), |
| 883 | worklist_(worklist), |
| 884 | visited_(visited), |
| 885 | stop_reports_(false) {} |
| 886 | |
| 887 | void VisitRoots(art::mirror::Object*** roots, size_t count, const art::RootInfo& info) |
| 888 | OVERRIDE |
| 889 | REQUIRES_SHARED(art::Locks::mutator_lock_) |
| 890 | REQUIRES(!*helper_->tag_table_->GetAllowDisallowLock()) { |
| 891 | for (size_t i = 0; i != count; ++i) { |
| 892 | AddRoot(*roots[i], info); |
| 893 | } |
| 894 | } |
| 895 | |
| 896 | void VisitRoots(art::mirror::CompressedReference<art::mirror::Object>** roots, |
| 897 | size_t count, |
| 898 | const art::RootInfo& info) |
| 899 | OVERRIDE REQUIRES_SHARED(art::Locks::mutator_lock_) |
| 900 | REQUIRES(!*helper_->tag_table_->GetAllowDisallowLock()) { |
| 901 | for (size_t i = 0; i != count; ++i) { |
| 902 | AddRoot(roots[i]->AsMirrorPtr(), info); |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | bool IsStopReports() { |
| 907 | return stop_reports_; |
| 908 | } |
| 909 | |
| 910 | private: |
| 911 | void AddRoot(art::mirror::Object* root_obj, const art::RootInfo& info) |
| 912 | REQUIRES_SHARED(art::Locks::mutator_lock_) |
| 913 | REQUIRES(!*tag_table_->GetAllowDisallowLock()) { |
Andreas Gampe | c756f08 | 2017-03-29 17:58:28 -0700 | [diff] [blame] | 914 | if (stop_reports_) { |
| 915 | return; |
| 916 | } |
| 917 | bool add_to_worklist = ReportRoot(root_obj, info); |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 918 | // We use visited_ to mark roots already so we do not need another set. |
| 919 | if (visited_->find(root_obj) == visited_->end()) { |
Andreas Gampe | c756f08 | 2017-03-29 17:58:28 -0700 | [diff] [blame] | 920 | if (add_to_worklist) { |
Andreas Gampe | e0f8ed9 | 2017-04-13 16:52:23 -0700 | [diff] [blame] | 921 | visited_->insert(root_obj); |
Andreas Gampe | c756f08 | 2017-03-29 17:58:28 -0700 | [diff] [blame] | 922 | worklist_->push_back(root_obj); |
| 923 | } |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 924 | } |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 925 | } |
| 926 | |
Andreas Gampe | 93c3090 | 2016-11-18 13:30:30 -0800 | [diff] [blame] | 927 | // Remove NO_THREAD_SAFETY_ANALYSIS once ASSERT_CAPABILITY works correctly. |
| 928 | art::Thread* FindThread(const art::RootInfo& info) NO_THREAD_SAFETY_ANALYSIS { |
| 929 | art::Locks::thread_list_lock_->AssertExclusiveHeld(art::Thread::Current()); |
| 930 | return art::Runtime::Current()->GetThreadList()->FindThreadByThreadId(info.GetThreadId()); |
| 931 | } |
| 932 | |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 933 | jvmtiHeapReferenceKind GetReferenceKind(const art::RootInfo& info, |
| 934 | jvmtiHeapReferenceInfo* ref_info) |
| 935 | REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 936 | // TODO: Fill in ref_info. |
| 937 | memset(ref_info, 0, sizeof(jvmtiHeapReferenceInfo)); |
| 938 | |
| 939 | switch (info.GetType()) { |
| 940 | case art::RootType::kRootJNIGlobal: |
| 941 | return JVMTI_HEAP_REFERENCE_JNI_GLOBAL; |
| 942 | |
| 943 | case art::RootType::kRootJNILocal: |
Andreas Gampe | 93c3090 | 2016-11-18 13:30:30 -0800 | [diff] [blame] | 944 | { |
| 945 | uint32_t thread_id = info.GetThreadId(); |
| 946 | ref_info->jni_local.thread_id = thread_id; |
| 947 | |
| 948 | art::Thread* thread = FindThread(info); |
| 949 | if (thread != nullptr) { |
Andreas Gampe | 202f85a | 2017-02-06 10:23:26 -0800 | [diff] [blame] | 950 | art::mirror::Object* thread_obj; |
Andreas Gampe | 93c3090 | 2016-11-18 13:30:30 -0800 | [diff] [blame] | 951 | if (thread->IsStillStarting()) { |
| 952 | thread_obj = nullptr; |
| 953 | } else { |
Andreas Gampe | 202f85a | 2017-02-06 10:23:26 -0800 | [diff] [blame] | 954 | thread_obj = thread->GetPeerFromOtherThread(); |
Andreas Gampe | 93c3090 | 2016-11-18 13:30:30 -0800 | [diff] [blame] | 955 | } |
| 956 | if (thread_obj != nullptr) { |
| 957 | ref_info->jni_local.thread_tag = tag_table_->GetTagOrZero(thread_obj); |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | // TODO: We don't have this info. |
| 962 | if (thread != nullptr) { |
| 963 | ref_info->jni_local.depth = 0; |
| 964 | art::ArtMethod* method = thread->GetCurrentMethod(nullptr, false /* abort_on_error */); |
| 965 | if (method != nullptr) { |
| 966 | ref_info->jni_local.method = art::jni::EncodeArtMethod(method); |
| 967 | } |
| 968 | } |
| 969 | |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 970 | return JVMTI_HEAP_REFERENCE_JNI_LOCAL; |
Andreas Gampe | 93c3090 | 2016-11-18 13:30:30 -0800 | [diff] [blame] | 971 | } |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 972 | |
| 973 | case art::RootType::kRootJavaFrame: |
Andreas Gampe | f10dfcd | 2016-12-02 14:42:33 -0800 | [diff] [blame] | 974 | { |
| 975 | uint32_t thread_id = info.GetThreadId(); |
| 976 | ref_info->stack_local.thread_id = thread_id; |
| 977 | |
| 978 | art::Thread* thread = FindThread(info); |
| 979 | if (thread != nullptr) { |
Andreas Gampe | 202f85a | 2017-02-06 10:23:26 -0800 | [diff] [blame] | 980 | art::mirror::Object* thread_obj; |
Andreas Gampe | f10dfcd | 2016-12-02 14:42:33 -0800 | [diff] [blame] | 981 | if (thread->IsStillStarting()) { |
| 982 | thread_obj = nullptr; |
| 983 | } else { |
Andreas Gampe | 202f85a | 2017-02-06 10:23:26 -0800 | [diff] [blame] | 984 | thread_obj = thread->GetPeerFromOtherThread(); |
Andreas Gampe | f10dfcd | 2016-12-02 14:42:33 -0800 | [diff] [blame] | 985 | } |
| 986 | if (thread_obj != nullptr) { |
| 987 | ref_info->stack_local.thread_tag = tag_table_->GetTagOrZero(thread_obj); |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | auto& java_info = static_cast<const art::JavaFrameRootInfo&>(info); |
| 992 | ref_info->stack_local.slot = static_cast<jint>(java_info.GetVReg()); |
| 993 | const art::StackVisitor* visitor = java_info.GetVisitor(); |
| 994 | ref_info->stack_local.location = |
| 995 | static_cast<jlocation>(visitor->GetDexPc(false /* abort_on_failure */)); |
| 996 | ref_info->stack_local.depth = static_cast<jint>(visitor->GetFrameDepth()); |
| 997 | art::ArtMethod* method = visitor->GetMethod(); |
| 998 | if (method != nullptr) { |
| 999 | ref_info->stack_local.method = art::jni::EncodeArtMethod(method); |
| 1000 | } |
| 1001 | |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1002 | return JVMTI_HEAP_REFERENCE_STACK_LOCAL; |
Andreas Gampe | f10dfcd | 2016-12-02 14:42:33 -0800 | [diff] [blame] | 1003 | } |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1004 | |
| 1005 | case art::RootType::kRootNativeStack: |
| 1006 | case art::RootType::kRootThreadBlock: |
| 1007 | case art::RootType::kRootThreadObject: |
| 1008 | return JVMTI_HEAP_REFERENCE_THREAD; |
| 1009 | |
| 1010 | case art::RootType::kRootStickyClass: |
| 1011 | case art::RootType::kRootInternedString: |
| 1012 | // Note: this isn't a root in the RI. |
| 1013 | return JVMTI_HEAP_REFERENCE_SYSTEM_CLASS; |
| 1014 | |
| 1015 | case art::RootType::kRootMonitorUsed: |
| 1016 | case art::RootType::kRootJNIMonitor: |
| 1017 | return JVMTI_HEAP_REFERENCE_MONITOR; |
| 1018 | |
| 1019 | case art::RootType::kRootFinalizing: |
| 1020 | case art::RootType::kRootDebugger: |
| 1021 | case art::RootType::kRootReferenceCleanup: |
| 1022 | case art::RootType::kRootVMInternal: |
| 1023 | case art::RootType::kRootUnknown: |
| 1024 | return JVMTI_HEAP_REFERENCE_OTHER; |
| 1025 | } |
| 1026 | LOG(FATAL) << "Unreachable"; |
| 1027 | UNREACHABLE(); |
| 1028 | } |
| 1029 | |
Andreas Gampe | c756f08 | 2017-03-29 17:58:28 -0700 | [diff] [blame] | 1030 | bool ReportRoot(art::mirror::Object* root_obj, const art::RootInfo& info) |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1031 | REQUIRES_SHARED(art::Locks::mutator_lock_) |
| 1032 | REQUIRES(!*tag_table_->GetAllowDisallowLock()) { |
| 1033 | jvmtiHeapReferenceInfo ref_info; |
| 1034 | jvmtiHeapReferenceKind kind = GetReferenceKind(info, &ref_info); |
| 1035 | jint result = helper_->ReportReference(kind, &ref_info, nullptr, root_obj); |
| 1036 | if ((result & JVMTI_VISIT_ABORT) != 0) { |
| 1037 | stop_reports_ = true; |
| 1038 | } |
Andreas Gampe | c756f08 | 2017-03-29 17:58:28 -0700 | [diff] [blame] | 1039 | return (result & JVMTI_VISIT_OBJECTS) != 0; |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | private: |
| 1043 | FollowReferencesHelper* helper_; |
| 1044 | ObjectTagTable* tag_table_; |
| 1045 | std::vector<art::mirror::Object*>* worklist_; |
| 1046 | std::unordered_set<art::mirror::Object*>* visited_; |
| 1047 | bool stop_reports_; |
| 1048 | }; |
| 1049 | |
| 1050 | void VisitObject(art::mirror::Object* obj) |
| 1051 | REQUIRES_SHARED(art::Locks::mutator_lock_) |
| 1052 | REQUIRES(!*tag_table_->GetAllowDisallowLock()) { |
| 1053 | if (obj->IsClass()) { |
| 1054 | VisitClass(obj->AsClass()); |
| 1055 | return; |
| 1056 | } |
| 1057 | if (obj->IsArrayInstance()) { |
| 1058 | VisitArray(obj); |
| 1059 | return; |
| 1060 | } |
| 1061 | |
Andreas Gampe | 9511460 | 2017-02-28 15:47:44 -0800 | [diff] [blame] | 1062 | // All instance fields. |
| 1063 | auto report_instance_field = [&](art::ObjPtr<art::mirror::Object> src, |
| 1064 | art::ObjPtr<art::mirror::Class> obj_klass ATTRIBUTE_UNUSED, |
| 1065 | art::ArtField& field, |
| 1066 | size_t field_index, |
| 1067 | void* user_data ATTRIBUTE_UNUSED) |
| 1068 | REQUIRES_SHARED(art::Locks::mutator_lock_) |
| 1069 | REQUIRES(!*tag_table_->GetAllowDisallowLock()) { |
| 1070 | art::ObjPtr<art::mirror::Object> field_value = field.GetObject(src); |
| 1071 | if (field_value != nullptr) { |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1072 | jvmtiHeapReferenceInfo reference_info; |
| 1073 | memset(&reference_info, 0, sizeof(reference_info)); |
| 1074 | |
Andreas Gampe | 9511460 | 2017-02-28 15:47:44 -0800 | [diff] [blame] | 1075 | reference_info.field.index = field_index; |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1076 | |
| 1077 | jvmtiHeapReferenceKind kind = |
Andreas Gampe | 9511460 | 2017-02-28 15:47:44 -0800 | [diff] [blame] | 1078 | field.GetOffset().Int32Value() == art::mirror::Object::ClassOffset().Int32Value() |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1079 | ? JVMTI_HEAP_REFERENCE_CLASS |
| 1080 | : JVMTI_HEAP_REFERENCE_FIELD; |
| 1081 | const jvmtiHeapReferenceInfo* reference_info_ptr = |
| 1082 | kind == JVMTI_HEAP_REFERENCE_CLASS ? nullptr : &reference_info; |
| 1083 | |
Andreas Gampe | 9511460 | 2017-02-28 15:47:44 -0800 | [diff] [blame] | 1084 | return !ReportReferenceMaybeEnqueue(kind, reference_info_ptr, src.Ptr(), field_value.Ptr()); |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1085 | } |
Andreas Gampe | 9511460 | 2017-02-28 15:47:44 -0800 | [diff] [blame] | 1086 | return false; |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1087 | }; |
Andreas Gampe | 9511460 | 2017-02-28 15:47:44 -0800 | [diff] [blame] | 1088 | stop_reports_ = FieldVisitor<void, true>::ReportFields(obj, |
| 1089 | nullptr, |
| 1090 | VisitorFalse<void>, |
| 1091 | VisitorFalse<void>, |
| 1092 | VisitorFalse<void>, |
| 1093 | report_instance_field); |
| 1094 | if (stop_reports_) { |
| 1095 | return; |
Andreas Gampe | 3ec8e40 | 2017-02-21 15:49:53 -0800 | [diff] [blame] | 1096 | } |
Andreas Gampe | e731693 | 2017-02-25 09:15:05 -0800 | [diff] [blame] | 1097 | |
Andreas Gampe | 9511460 | 2017-02-28 15:47:44 -0800 | [diff] [blame] | 1098 | jint string_ret = ReportString(obj, env, tag_table_, callbacks_, user_data_); |
| 1099 | stop_reports_ = (string_ret & JVMTI_VISIT_ABORT) != 0; |
| 1100 | if (stop_reports_) { |
| 1101 | return; |
Andreas Gampe | e731693 | 2017-02-25 09:15:05 -0800 | [diff] [blame] | 1102 | } |
Andreas Gampe | 9511460 | 2017-02-28 15:47:44 -0800 | [diff] [blame] | 1103 | |
| 1104 | stop_reports_ = ReportPrimitiveField::Report(obj, tag_table_, callbacks_, user_data_); |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | void VisitArray(art::mirror::Object* array) |
| 1108 | REQUIRES_SHARED(art::Locks::mutator_lock_) |
| 1109 | REQUIRES(!*tag_table_->GetAllowDisallowLock()) { |
| 1110 | stop_reports_ = !ReportReferenceMaybeEnqueue(JVMTI_HEAP_REFERENCE_CLASS, |
| 1111 | nullptr, |
| 1112 | array, |
| 1113 | array->GetClass()); |
| 1114 | if (stop_reports_) { |
| 1115 | return; |
| 1116 | } |
| 1117 | |
| 1118 | if (array->IsObjectArray()) { |
| 1119 | art::mirror::ObjectArray<art::mirror::Object>* obj_array = |
| 1120 | array->AsObjectArray<art::mirror::Object>(); |
| 1121 | int32_t length = obj_array->GetLength(); |
| 1122 | for (int32_t i = 0; i != length; ++i) { |
| 1123 | art::mirror::Object* elem = obj_array->GetWithoutChecks(i); |
| 1124 | if (elem != nullptr) { |
| 1125 | jvmtiHeapReferenceInfo reference_info; |
| 1126 | reference_info.array.index = i; |
| 1127 | stop_reports_ = !ReportReferenceMaybeEnqueue(JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT, |
| 1128 | &reference_info, |
| 1129 | array, |
| 1130 | elem); |
| 1131 | if (stop_reports_) { |
| 1132 | break; |
| 1133 | } |
| 1134 | } |
| 1135 | } |
Andreas Gampe | becd6ad | 2017-02-22 19:20:37 -0800 | [diff] [blame] | 1136 | } else { |
| 1137 | if (!stop_reports_) { |
| 1138 | jint array_ret = ReportPrimitiveArray(array, env, tag_table_, callbacks_, user_data_); |
| 1139 | stop_reports_ = (array_ret & JVMTI_VISIT_ABORT) != 0; |
| 1140 | } |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1141 | } |
| 1142 | } |
| 1143 | |
| 1144 | void VisitClass(art::mirror::Class* klass) |
| 1145 | REQUIRES_SHARED(art::Locks::mutator_lock_) |
| 1146 | REQUIRES(!*tag_table_->GetAllowDisallowLock()) { |
| 1147 | // TODO: Are erroneous classes reported? Are non-prepared ones? For now, just use resolved ones. |
| 1148 | if (!klass->IsResolved()) { |
| 1149 | return; |
| 1150 | } |
| 1151 | |
| 1152 | // Superclass. |
| 1153 | stop_reports_ = !ReportReferenceMaybeEnqueue(JVMTI_HEAP_REFERENCE_SUPERCLASS, |
| 1154 | nullptr, |
| 1155 | klass, |
| 1156 | klass->GetSuperClass()); |
| 1157 | if (stop_reports_) { |
| 1158 | return; |
| 1159 | } |
| 1160 | |
| 1161 | // Directly implemented or extended interfaces. |
| 1162 | art::Thread* self = art::Thread::Current(); |
| 1163 | art::StackHandleScope<1> hs(self); |
| 1164 | art::Handle<art::mirror::Class> h_klass(hs.NewHandle<art::mirror::Class>(klass)); |
| 1165 | for (size_t i = 0; i < h_klass->NumDirectInterfaces(); ++i) { |
| 1166 | art::ObjPtr<art::mirror::Class> inf_klass = |
Vladimir Marko | 19a4d37 | 2016-12-08 14:41:46 +0000 | [diff] [blame] | 1167 | art::mirror::Class::ResolveDirectInterface(self, h_klass, i); |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1168 | if (inf_klass == nullptr) { |
| 1169 | // TODO: With a resolved class this should not happen... |
| 1170 | self->ClearException(); |
| 1171 | break; |
| 1172 | } |
| 1173 | |
| 1174 | stop_reports_ = !ReportReferenceMaybeEnqueue(JVMTI_HEAP_REFERENCE_INTERFACE, |
| 1175 | nullptr, |
| 1176 | klass, |
| 1177 | inf_klass.Ptr()); |
| 1178 | if (stop_reports_) { |
| 1179 | return; |
| 1180 | } |
| 1181 | } |
| 1182 | |
| 1183 | // Classloader. |
| 1184 | // TODO: What about the boot classpath loader? We'll skip for now, but do we have to find the |
| 1185 | // fake BootClassLoader? |
| 1186 | if (klass->GetClassLoader() != nullptr) { |
| 1187 | stop_reports_ = !ReportReferenceMaybeEnqueue(JVMTI_HEAP_REFERENCE_CLASS_LOADER, |
| 1188 | nullptr, |
| 1189 | klass, |
| 1190 | klass->GetClassLoader()); |
| 1191 | if (stop_reports_) { |
| 1192 | return; |
| 1193 | } |
| 1194 | } |
| 1195 | DCHECK_EQ(h_klass.Get(), klass); |
| 1196 | |
| 1197 | // Declared static fields. |
Andreas Gampe | 9511460 | 2017-02-28 15:47:44 -0800 | [diff] [blame] | 1198 | auto report_static_field = [&](art::ObjPtr<art::mirror::Object> obj ATTRIBUTE_UNUSED, |
| 1199 | art::ObjPtr<art::mirror::Class> obj_klass, |
| 1200 | art::ArtField& field, |
| 1201 | size_t field_index, |
| 1202 | void* user_data ATTRIBUTE_UNUSED) |
| 1203 | REQUIRES_SHARED(art::Locks::mutator_lock_) |
| 1204 | REQUIRES(!*tag_table_->GetAllowDisallowLock()) { |
| 1205 | art::ObjPtr<art::mirror::Object> field_value = field.GetObject(obj_klass); |
| 1206 | if (field_value != nullptr) { |
| 1207 | jvmtiHeapReferenceInfo reference_info; |
| 1208 | memset(&reference_info, 0, sizeof(reference_info)); |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1209 | |
Andreas Gampe | 9511460 | 2017-02-28 15:47:44 -0800 | [diff] [blame] | 1210 | reference_info.field.index = static_cast<jint>(field_index); |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1211 | |
Andreas Gampe | 9511460 | 2017-02-28 15:47:44 -0800 | [diff] [blame] | 1212 | return !ReportReferenceMaybeEnqueue(JVMTI_HEAP_REFERENCE_STATIC_FIELD, |
| 1213 | &reference_info, |
| 1214 | obj_klass.Ptr(), |
| 1215 | field_value.Ptr()); |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1216 | } |
Andreas Gampe | 9511460 | 2017-02-28 15:47:44 -0800 | [diff] [blame] | 1217 | return false; |
| 1218 | }; |
| 1219 | stop_reports_ = FieldVisitor<void, false>::ReportFields(klass, |
| 1220 | nullptr, |
| 1221 | VisitorFalse<void>, |
| 1222 | report_static_field, |
| 1223 | VisitorFalse<void>, |
| 1224 | VisitorFalse<void>); |
| 1225 | if (stop_reports_) { |
| 1226 | return; |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1227 | } |
Andreas Gampe | e731693 | 2017-02-25 09:15:05 -0800 | [diff] [blame] | 1228 | |
Andreas Gampe | 9511460 | 2017-02-28 15:47:44 -0800 | [diff] [blame] | 1229 | stop_reports_ = ReportPrimitiveField::Report(klass, tag_table_, callbacks_, user_data_); |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | void MaybeEnqueue(art::mirror::Object* obj) REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 1233 | if (visited_.find(obj) == visited_.end()) { |
| 1234 | worklist_.push_back(obj); |
| 1235 | visited_.insert(obj); |
| 1236 | } |
| 1237 | } |
| 1238 | |
| 1239 | bool ReportReferenceMaybeEnqueue(jvmtiHeapReferenceKind kind, |
| 1240 | const jvmtiHeapReferenceInfo* reference_info, |
| 1241 | art::mirror::Object* referree, |
| 1242 | art::mirror::Object* referrer) |
| 1243 | REQUIRES_SHARED(art::Locks::mutator_lock_) |
| 1244 | REQUIRES(!*tag_table_->GetAllowDisallowLock()) { |
| 1245 | jint result = ReportReference(kind, reference_info, referree, referrer); |
| 1246 | if ((result & JVMTI_VISIT_ABORT) == 0) { |
| 1247 | if ((result & JVMTI_VISIT_OBJECTS) != 0) { |
| 1248 | MaybeEnqueue(referrer); |
| 1249 | } |
| 1250 | return true; |
| 1251 | } else { |
| 1252 | return false; |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | jint ReportReference(jvmtiHeapReferenceKind kind, |
| 1257 | const jvmtiHeapReferenceInfo* reference_info, |
| 1258 | art::mirror::Object* referrer, |
| 1259 | art::mirror::Object* referree) |
| 1260 | REQUIRES_SHARED(art::Locks::mutator_lock_) |
| 1261 | REQUIRES(!*tag_table_->GetAllowDisallowLock()) { |
| 1262 | if (referree == nullptr || stop_reports_) { |
| 1263 | return 0; |
| 1264 | } |
| 1265 | |
Andreas Gampe | 38da9f2 | 2017-02-20 13:35:36 -0800 | [diff] [blame] | 1266 | if (UNLIKELY(class_filter_ != nullptr) && class_filter_ != referree->GetClass()) { |
| 1267 | return JVMTI_VISIT_OBJECTS; |
| 1268 | } |
| 1269 | |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1270 | const jlong class_tag = tag_table_->GetTagOrZero(referree->GetClass()); |
Andreas Gampe | 6ea0607 | 2017-02-24 18:01:19 +0000 | [diff] [blame] | 1271 | jlong tag = tag_table_->GetTagOrZero(referree); |
| 1272 | |
| 1273 | if (!heap_filter_.ShouldReportByHeapFilter(tag, class_tag)) { |
| 1274 | return JVMTI_VISIT_OBJECTS; |
| 1275 | } |
| 1276 | |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1277 | const jlong referrer_class_tag = |
| 1278 | referrer == nullptr ? 0 : tag_table_->GetTagOrZero(referrer->GetClass()); |
| 1279 | const jlong size = static_cast<jlong>(referree->SizeOf()); |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1280 | jlong saved_tag = tag; |
| 1281 | jlong referrer_tag = 0; |
| 1282 | jlong saved_referrer_tag = 0; |
| 1283 | jlong* referrer_tag_ptr; |
| 1284 | if (referrer == nullptr) { |
| 1285 | referrer_tag_ptr = nullptr; |
| 1286 | } else { |
| 1287 | if (referrer == referree) { |
| 1288 | referrer_tag_ptr = &tag; |
| 1289 | } else { |
| 1290 | referrer_tag = saved_referrer_tag = tag_table_->GetTagOrZero(referrer); |
| 1291 | referrer_tag_ptr = &referrer_tag; |
| 1292 | } |
| 1293 | } |
Andreas Gampe | 38da9f2 | 2017-02-20 13:35:36 -0800 | [diff] [blame] | 1294 | |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1295 | jint length = -1; |
| 1296 | if (referree->IsArrayInstance()) { |
| 1297 | length = referree->AsArray()->GetLength(); |
| 1298 | } |
| 1299 | |
| 1300 | jint result = callbacks_->heap_reference_callback(kind, |
| 1301 | reference_info, |
| 1302 | class_tag, |
| 1303 | referrer_class_tag, |
| 1304 | size, |
| 1305 | &tag, |
| 1306 | referrer_tag_ptr, |
| 1307 | length, |
| 1308 | const_cast<void*>(user_data_)); |
| 1309 | |
| 1310 | if (tag != saved_tag) { |
| 1311 | tag_table_->Set(referree, tag); |
| 1312 | } |
| 1313 | if (referrer_tag != saved_referrer_tag) { |
| 1314 | tag_table_->Set(referrer, referrer_tag); |
| 1315 | } |
| 1316 | |
| 1317 | return result; |
| 1318 | } |
| 1319 | |
Andreas Gampe | 3ec8e40 | 2017-02-21 15:49:53 -0800 | [diff] [blame] | 1320 | jvmtiEnv* env; |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1321 | ObjectTagTable* tag_table_; |
Andreas Gampe | 638a693 | 2016-12-02 19:11:17 -0800 | [diff] [blame] | 1322 | art::ObjPtr<art::mirror::Object> initial_object_; |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1323 | const jvmtiHeapCallbacks* callbacks_; |
Andreas Gampe | 38da9f2 | 2017-02-20 13:35:36 -0800 | [diff] [blame] | 1324 | art::ObjPtr<art::mirror::Class> class_filter_; |
Andreas Gampe | 6ea0607 | 2017-02-24 18:01:19 +0000 | [diff] [blame] | 1325 | const HeapFilter heap_filter_; |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1326 | const void* user_data_; |
| 1327 | |
| 1328 | std::vector<art::mirror::Object*> worklist_; |
| 1329 | size_t start_; |
| 1330 | static constexpr size_t kMaxStart = 1000000U; |
| 1331 | |
| 1332 | std::unordered_set<art::mirror::Object*> visited_; |
| 1333 | |
| 1334 | bool stop_reports_; |
| 1335 | |
| 1336 | friend class CollectAndReportRootsVisitor; |
| 1337 | }; |
| 1338 | |
Andreas Gampe | 3ec8e40 | 2017-02-21 15:49:53 -0800 | [diff] [blame] | 1339 | jvmtiError HeapUtil::FollowReferences(jvmtiEnv* env, |
Andreas Gampe | 6ea0607 | 2017-02-24 18:01:19 +0000 | [diff] [blame] | 1340 | jint heap_filter, |
Andreas Gampe | 38da9f2 | 2017-02-20 13:35:36 -0800 | [diff] [blame] | 1341 | jclass klass, |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1342 | jobject initial_object, |
| 1343 | const jvmtiHeapCallbacks* callbacks, |
| 1344 | const void* user_data) { |
| 1345 | if (callbacks == nullptr) { |
| 1346 | return ERR(NULL_POINTER); |
| 1347 | } |
| 1348 | |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1349 | art::Thread* self = art::Thread::Current(); |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1350 | |
Andreas Gampe | 638a693 | 2016-12-02 19:11:17 -0800 | [diff] [blame] | 1351 | art::gc::Heap* heap = art::Runtime::Current()->GetHeap(); |
| 1352 | if (heap->IsGcConcurrentAndMoving()) { |
| 1353 | // Need to take a heap dump while GC isn't running. See the |
| 1354 | // comment in Heap::VisitObjects(). |
| 1355 | heap->IncrementDisableMovingGC(self); |
| 1356 | } |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1357 | { |
Andreas Gampe | 638a693 | 2016-12-02 19:11:17 -0800 | [diff] [blame] | 1358 | art::ScopedObjectAccess soa(self); // Now we know we have the shared lock. |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1359 | art::ScopedThreadSuspension sts(self, art::kWaitingForVisitObjects); |
| 1360 | art::ScopedSuspendAll ssa("FollowReferences"); |
| 1361 | |
Andreas Gampe | 38da9f2 | 2017-02-20 13:35:36 -0800 | [diff] [blame] | 1362 | art::ObjPtr<art::mirror::Class> class_filter = klass == nullptr |
| 1363 | ? nullptr |
| 1364 | : art::ObjPtr<art::mirror::Class>::DownCast(self->DecodeJObject(klass)); |
Andreas Gampe | 638a693 | 2016-12-02 19:11:17 -0800 | [diff] [blame] | 1365 | FollowReferencesHelper frh(this, |
Andreas Gampe | 3ec8e40 | 2017-02-21 15:49:53 -0800 | [diff] [blame] | 1366 | env, |
Andreas Gampe | 638a693 | 2016-12-02 19:11:17 -0800 | [diff] [blame] | 1367 | self->DecodeJObject(initial_object), |
| 1368 | callbacks, |
Andreas Gampe | 38da9f2 | 2017-02-20 13:35:36 -0800 | [diff] [blame] | 1369 | class_filter, |
Andreas Gampe | 6ea0607 | 2017-02-24 18:01:19 +0000 | [diff] [blame] | 1370 | heap_filter, |
Andreas Gampe | 638a693 | 2016-12-02 19:11:17 -0800 | [diff] [blame] | 1371 | user_data); |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1372 | frh.Init(); |
| 1373 | frh.Work(); |
| 1374 | } |
Andreas Gampe | 638a693 | 2016-12-02 19:11:17 -0800 | [diff] [blame] | 1375 | if (heap->IsGcConcurrentAndMoving()) { |
| 1376 | heap->DecrementDisableMovingGC(self); |
| 1377 | } |
Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 1378 | |
| 1379 | return ERR(NONE); |
| 1380 | } |
| 1381 | |
Andreas Gampe | aa8b60c | 2016-10-12 12:51:25 -0700 | [diff] [blame] | 1382 | jvmtiError HeapUtil::GetLoadedClasses(jvmtiEnv* env, |
| 1383 | jint* class_count_ptr, |
| 1384 | jclass** classes_ptr) { |
| 1385 | if (class_count_ptr == nullptr || classes_ptr == nullptr) { |
| 1386 | return ERR(NULL_POINTER); |
| 1387 | } |
| 1388 | |
| 1389 | class ReportClassVisitor : public art::ClassVisitor { |
| 1390 | public: |
| 1391 | explicit ReportClassVisitor(art::Thread* self) : self_(self) {} |
| 1392 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 1393 | bool operator()(art::ObjPtr<art::mirror::Class> klass) |
| 1394 | OVERRIDE REQUIRES_SHARED(art::Locks::mutator_lock_) { |
Andreas Gampe | ef54d8d | 2016-10-25 09:55:53 -0700 | [diff] [blame] | 1395 | classes_.push_back(self_->GetJniEnv()->AddLocalReference<jclass>(klass)); |
Andreas Gampe | aa8b60c | 2016-10-12 12:51:25 -0700 | [diff] [blame] | 1396 | return true; |
| 1397 | } |
| 1398 | |
| 1399 | art::Thread* self_; |
| 1400 | std::vector<jclass> classes_; |
| 1401 | }; |
| 1402 | |
| 1403 | art::Thread* self = art::Thread::Current(); |
| 1404 | ReportClassVisitor rcv(self); |
| 1405 | { |
| 1406 | art::ScopedObjectAccess soa(self); |
| 1407 | art::Runtime::Current()->GetClassLinker()->VisitClasses(&rcv); |
| 1408 | } |
| 1409 | |
| 1410 | size_t size = rcv.classes_.size(); |
| 1411 | jclass* classes = nullptr; |
| 1412 | jvmtiError alloc_ret = env->Allocate(static_cast<jlong>(size * sizeof(jclass)), |
| 1413 | reinterpret_cast<unsigned char**>(&classes)); |
| 1414 | if (alloc_ret != ERR(NONE)) { |
| 1415 | return alloc_ret; |
| 1416 | } |
| 1417 | |
| 1418 | for (size_t i = 0; i < size; ++i) { |
| 1419 | classes[i] = rcv.classes_[i]; |
| 1420 | } |
| 1421 | *classes_ptr = classes; |
| 1422 | *class_count_ptr = static_cast<jint>(size); |
| 1423 | |
| 1424 | return ERR(NONE); |
| 1425 | } |
| 1426 | |
Andreas Gampe | 8da6d03 | 2016-10-31 19:31:03 -0700 | [diff] [blame] | 1427 | jvmtiError HeapUtil::ForceGarbageCollection(jvmtiEnv* env ATTRIBUTE_UNUSED) { |
| 1428 | art::Runtime::Current()->GetHeap()->CollectGarbage(false); |
| 1429 | |
| 1430 | return ERR(NONE); |
| 1431 | } |
Andreas Gampe | d73aba4 | 2017-05-03 21:40:26 -0700 | [diff] [blame] | 1432 | |
| 1433 | static constexpr jint kHeapIdDefault = 0; |
| 1434 | static constexpr jint kHeapIdImage = 1; |
| 1435 | static constexpr jint kHeapIdZygote = 2; |
| 1436 | static constexpr jint kHeapIdApp = 3; |
| 1437 | |
Andreas Gampe | 2eb25e4 | 2017-05-09 17:14:58 -0700 | [diff] [blame] | 1438 | static jint GetHeapId(art::ObjPtr<art::mirror::Object> obj) |
| 1439 | REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 1440 | if (obj == nullptr) { |
| 1441 | return -1; |
| 1442 | } |
| 1443 | |
| 1444 | art::gc::Heap* const heap = art::Runtime::Current()->GetHeap(); |
| 1445 | const art::gc::space::ContinuousSpace* const space = |
| 1446 | heap->FindContinuousSpaceFromObject(obj, true); |
| 1447 | jint heap_type = kHeapIdApp; |
| 1448 | if (space != nullptr) { |
| 1449 | if (space->IsZygoteSpace()) { |
| 1450 | heap_type = kHeapIdZygote; |
| 1451 | } else if (space->IsImageSpace() && heap->ObjectIsInBootImageSpace(obj)) { |
| 1452 | // Only count objects in the boot image as HPROF_HEAP_IMAGE, this leaves app image objects |
| 1453 | // as HPROF_HEAP_APP. b/35762934 |
| 1454 | heap_type = kHeapIdImage; |
| 1455 | } |
| 1456 | } else { |
| 1457 | const auto* los = heap->GetLargeObjectsSpace(); |
| 1458 | if (los->Contains(obj.Ptr()) && los->IsZygoteLargeObject(art::Thread::Current(), obj.Ptr())) { |
| 1459 | heap_type = kHeapIdZygote; |
| 1460 | } |
| 1461 | } |
| 1462 | return heap_type; |
| 1463 | }; |
| 1464 | |
Andreas Gampe | d73aba4 | 2017-05-03 21:40:26 -0700 | [diff] [blame] | 1465 | jvmtiError HeapExtensions::GetObjectHeapId(jvmtiEnv* env, jlong tag, jint* heap_id, ...) { |
| 1466 | if (heap_id == nullptr) { |
| 1467 | return ERR(NULL_POINTER); |
| 1468 | } |
| 1469 | |
| 1470 | art::Thread* self = art::Thread::Current(); |
| 1471 | |
| 1472 | auto work = [&]() REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 1473 | ObjectTagTable* tag_table = ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get(); |
| 1474 | art::ObjPtr<art::mirror::Object> obj = tag_table->Find(tag); |
Andreas Gampe | 2eb25e4 | 2017-05-09 17:14:58 -0700 | [diff] [blame] | 1475 | jint heap_type = GetHeapId(obj); |
| 1476 | if (heap_type == -1) { |
Andreas Gampe | d73aba4 | 2017-05-03 21:40:26 -0700 | [diff] [blame] | 1477 | return ERR(NOT_FOUND); |
| 1478 | } |
Andreas Gampe | d73aba4 | 2017-05-03 21:40:26 -0700 | [diff] [blame] | 1479 | *heap_id = heap_type; |
| 1480 | return ERR(NONE); |
| 1481 | }; |
| 1482 | |
| 1483 | if (!art::Locks::mutator_lock_->IsSharedHeld(self)) { |
| 1484 | if (!self->IsThreadSuspensionAllowable()) { |
| 1485 | return ERR(INTERNAL); |
| 1486 | } |
| 1487 | art::ScopedObjectAccess soa(self); |
| 1488 | return work(); |
| 1489 | } else { |
| 1490 | // We cannot use SOA in this case. We might be holding the lock, but may not be in the |
| 1491 | // runnable state (e.g., during GC). |
| 1492 | art::Locks::mutator_lock_->AssertSharedHeld(self); |
| 1493 | // TODO: Investigate why ASSERT_SHARED_CAPABILITY doesn't work. |
| 1494 | auto annotalysis_workaround = [&]() NO_THREAD_SAFETY_ANALYSIS { |
| 1495 | return work(); |
| 1496 | }; |
| 1497 | return annotalysis_workaround(); |
| 1498 | } |
| 1499 | } |
| 1500 | |
| 1501 | static jvmtiError CopyStringAndReturn(jvmtiEnv* env, const char* in, char** out) { |
| 1502 | jvmtiError error; |
| 1503 | JvmtiUniquePtr<char[]> param_name = CopyString(env, in, &error); |
| 1504 | if (param_name == nullptr) { |
| 1505 | return error; |
| 1506 | } |
| 1507 | *out = param_name.release(); |
| 1508 | return ERR(NONE); |
| 1509 | } |
| 1510 | |
| 1511 | static constexpr const char* kHeapIdDefaultName = "default"; |
| 1512 | static constexpr const char* kHeapIdImageName = "image"; |
| 1513 | static constexpr const char* kHeapIdZygoteName = "zygote"; |
| 1514 | static constexpr const char* kHeapIdAppName = "app"; |
| 1515 | |
| 1516 | jvmtiError HeapExtensions::GetHeapName(jvmtiEnv* env, jint heap_id, char** heap_name, ...) { |
| 1517 | switch (heap_id) { |
| 1518 | case kHeapIdDefault: |
| 1519 | return CopyStringAndReturn(env, kHeapIdDefaultName, heap_name); |
| 1520 | case kHeapIdImage: |
| 1521 | return CopyStringAndReturn(env, kHeapIdImageName, heap_name); |
| 1522 | case kHeapIdZygote: |
| 1523 | return CopyStringAndReturn(env, kHeapIdZygoteName, heap_name); |
| 1524 | case kHeapIdApp: |
| 1525 | return CopyStringAndReturn(env, kHeapIdAppName, heap_name); |
| 1526 | |
| 1527 | default: |
| 1528 | return ERR(ILLEGAL_ARGUMENT); |
| 1529 | } |
| 1530 | } |
| 1531 | |
Andreas Gampe | 2eb25e4 | 2017-05-09 17:14:58 -0700 | [diff] [blame] | 1532 | jvmtiError HeapExtensions::IterateThroughHeapExt(jvmtiEnv* env, |
| 1533 | jint heap_filter, |
| 1534 | jclass klass, |
| 1535 | const jvmtiHeapCallbacks* callbacks, |
| 1536 | const void* user_data) { |
| 1537 | if (ArtJvmTiEnv::AsArtJvmTiEnv(env)->capabilities.can_tag_objects != 1) { \ |
| 1538 | return ERR(MUST_POSSESS_CAPABILITY); \ |
| 1539 | } |
| 1540 | |
| 1541 | // ART extension API: Also pass the heap id. |
| 1542 | auto ArtIterateHeap = [](art::mirror::Object* obj, |
| 1543 | const jvmtiHeapCallbacks* cb_callbacks, |
| 1544 | jlong class_tag, |
| 1545 | jlong size, |
| 1546 | jlong* tag, |
| 1547 | jint length, |
| 1548 | void* cb_user_data) |
| 1549 | REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 1550 | jint heap_id = GetHeapId(obj); |
| 1551 | using ArtExtensionAPI = jint (*)(jlong, jlong, jlong*, jint length, void*, jint); |
| 1552 | return reinterpret_cast<ArtExtensionAPI>(cb_callbacks->heap_iteration_callback)( |
| 1553 | class_tag, size, tag, length, cb_user_data, heap_id); |
| 1554 | }; |
| 1555 | return DoIterateThroughHeap(ArtIterateHeap, |
| 1556 | env, |
| 1557 | ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get(), |
| 1558 | heap_filter, |
| 1559 | klass, |
| 1560 | callbacks, |
| 1561 | user_data); |
| 1562 | } |
| 1563 | |
Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 1564 | } // namespace openjdkjvmti |