Change zygote_creation_lock_ to be member instead of static.
Static variables aren't thread safe and could cause the zygote to be
created twice.
Bug: 15133494
Change-Id: I65c8f089bed8de93f895b62b3dcff4c936931860
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index d37f2ad..e7f7517 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -116,6 +116,7 @@
long_pause_log_threshold_(long_pause_log_threshold),
long_gc_log_threshold_(long_gc_log_threshold),
ignore_max_footprint_(ignore_max_footprint),
+ zygote_creation_lock_("zygote creation lock", kZygoteCreationLock),
have_zygote_space_(false),
large_object_threshold_(std::numeric_limits<size_t>::max()), // Starts out disabled.
collector_type_running_(kCollectorTypeNone),
@@ -1551,7 +1552,6 @@
void Heap::PreZygoteFork() {
CollectGarbageInternal(collector::kGcTypeFull, kGcCauseBackground, false);
- static Mutex zygote_creation_lock_("zygote creation lock", kZygoteCreationLock);
Thread* self = Thread::Current();
MutexLock mu(self, zygote_creation_lock_);
// Try to see if we have any Zygote spaces.
@@ -2781,9 +2781,9 @@
CHECK(remembered_set != nullptr);
space::Space* space = remembered_set->GetSpace();
CHECK(space != nullptr);
- CHECK(remembered_sets_.find(space) == remembered_sets_.end());
+ CHECK(remembered_sets_.find(space) == remembered_sets_.end()) << space;
remembered_sets_.Put(space, remembered_set);
- CHECK(remembered_sets_.find(space) != remembered_sets_.end());
+ CHECK(remembered_sets_.find(space) != remembered_sets_.end()) << space;
}
void Heap::RemoveRememberedSet(space::Space* space) {
diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h
index 6fe0dcf..890332a 100644
--- a/runtime/gc/heap.h
+++ b/runtime/gc/heap.h
@@ -778,6 +778,9 @@
// useful for benchmarking since it reduces time spent in GC to a low %.
const bool ignore_max_footprint_;
+ // Lock which guards zygote space creation.
+ Mutex zygote_creation_lock_;
+
// If we have a zygote space.
bool have_zygote_space_;