heap: Optimize PreFinalizer traversal

This CL optimizes pre-finalizer invocation.

Previously, we would maintain pre-finalizers in a LinkedHashSet and invoke as follows:
1. Create a reversed copy of pre-finalizers in a Vector
2. Iterate the vector
2.a Invoke pre-finalizers on dead objects
2.b Remove dead objects from HashSet

Instead, we now maintain pre-finalizers in a Deque and invoke as follows:
1. Iterate the deque backwards
2. Store non-pre-finalized (live) objects in a new Deque
3. Move the new Deque over.

This improves performance on selected microbenchmarks by at least 25% (and up to 65%).

Bug: 981043
Change-Id: I0f3e3bbbc9c75ca017b11c6d60f991b1a68b44be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1698465
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676801}
2 files changed