Merge "RegisterNativeAllocation: avoid an extraneous blocking gc."
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;
+ }
}
}