RegisterNativeAllocation: avoid an extraneous blocking gc.
If another thread already ran a blocking gc since
RegisterNativeAllocation was entered, there's no need to run another
blocking gc before exiting RegisterNativeAllocation.
Bug: 29156652
Bug: 32576211
Test: 004-NativeAllocations run test.
Change-Id: Ie89652760deaa24b70adb07227a9918059da46c7
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index 051f3f7..0a45fce 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -3887,13 +3887,15 @@
// blocking watermark. Ensure that only one of those threads runs the
// blocking GC. The rest of the threads should instead wait for the
// blocking GC to complete.
- if (native_blocking_gc_in_progress_) {
- do {
- native_blocking_gc_cond_->Wait(self);
- } while (native_blocking_gcs_finished_ == initial_gcs_finished);
- } else {
- native_blocking_gc_in_progress_ = true;
- run_gc = true;
+ if (native_blocking_gcs_finished_ == initial_gcs_finished) {
+ if (native_blocking_gc_in_progress_) {
+ do {
+ native_blocking_gc_cond_->Wait(self);
+ } while (native_blocking_gcs_finished_ == initial_gcs_finished);
+ } else {
+ native_blocking_gc_in_progress_ = true;
+ run_gc = true;
+ }
}
}