commit | 2fde7e3de639ad40fa6a46a3839495b68d702443 | [log] [tgz] |
---|---|---|
author | Daniele Di Proietto <ddiproietto@google.com> | Wed Oct 04 07:35:02 2023 +0000 |
committer | Daniele Di Proietto <ddiproietto@google.com> | Thu Oct 05 13:25:04 2023 +0000 |
tree | a2f3f7f2081bbcde289208c26d0c3234cb7887ed | |
parent | 588afc706ccc44c15d33fcb4e644652a2fbbf782 [diff] |
heap_graph_tracker: Fix strong fields for non strong references When building a flamegraph, once we find an object whose type has a reference kind (WEAK, SOFT, FINALIZER or PHANTOM), we ignore all its children. It turns out that this is not accurate, only the reference through the `java.lang.ref.Reference.referent` field should be ignored. This prevents correct accounting for types that extend Reference, such as `java.util.WeakHashMap$Entry<K,V>`. Here's the code for that: ``` class java.lang.ref.Reference<T> { volatile T referent; } class java.lang.ref.WeakReference<T> extends Reference<T> { //... } class java.util.WeakHashMap$Entry<K,V> extends WeakReference<K> { //... V value; } ``` The type `java.util.WeakHashMap$Entry<K,V>` is marked as KIND_WEAK_REFERENCE by the runtime. When getting children of an object of type `java.util.WeakHashMap$Entry<K,V>`, we should ignore its `java.lang.ref.Reference.referent` field, but we should consider its `java.util.WeakHashMap$Entry<K,V>.value` field. ahat has [similar logic](https://cs.android.com/android/platform/superproject/main/+/main:art/tools/ahat/src/main/com/android/ahat/heapdump/AhatClassInstance.java;drc=3bc7238ded3e123ff7f7211d92c88b2731fec3d7;l=440) where the "referent" field is treated specially. This commit adds a new test that correctly checks the new behavior for weak references and removes weak reference from another test (it was checking the wrong behavior, added in 4771c5d("Ignore weak references for flamegraph.")) Bug: 302662734 Change-Id: I820df2c824217cca8a81f1eaffd4f63be87ee606
Perfetto is a production-grade open-source stack for performance instrumentation and trace analysis. It offers services and libraries and for recording system-level and app-level traces, native + java heap profiling, a library for analyzing traces using SQL and a web-based UI to visualize and explore multi-GB traces.
See https://perfetto.dev/docs or the /docs/ directory for documentation.