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
2 files changed
tree: a2f3f7f2081bbcde289208c26d0c3234cb7887ed
  1. .github/
  2. bazel/
  3. build_overrides/
  4. buildtools/
  5. debian/
  6. docs/
  7. examples/
  8. gn/
  9. include/
  10. infra/
  11. protos/
  12. python/
  13. src/
  14. test/
  15. third_party/
  16. tools/
  17. ui/
  18. .clang-format
  19. .clang-tidy
  20. .git-blame-ignore-revs
  21. .gitattributes
  22. .gitignore
  23. .gn
  24. .style.yapf
  25. Android.bp
  26. Android.bp.extras
  27. BUILD
  28. BUILD.extras
  29. BUILD.gn
  30. CHANGELOG
  31. codereview.settings
  32. DIR_METADATA
  33. heapprofd.rc
  34. LICENSE
  35. meson.build
  36. METADATA
  37. MODULE_LICENSE_APACHE2
  38. OWNERS
  39. perfetto.rc
  40. PerfettoIntegrationTests.xml
  41. PRESUBMIT.py
  42. README.chromium
  43. README.md
  44. TEST_MAPPING
  45. traced_perf.rc
  46. WORKSPACE
README.md

Perfetto - System profiling, app tracing and trace analysis

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.