ZygoteSpace雖然間接繼承了AllocSpace,Alloc和Free都是空實現(xiàn)氮昧。所以我覺得ZygoteSpace應(yīng)該繼承MemMapSpace。
art/runtime/gc/space/zygote_space.h:30
class ZygoteSpace final : public ContinuousMemMapAllocSpace {
public:
// Returns the remaining storage in the out_map field.
static ZygoteSpace* Create(const std::string& name,
MemMap&& mem_map,
accounting::ContinuousSpaceBitmap&& live_bitmap,
accounting::ContinuousSpaceBitmap&& mark_bitmap)
REQUIRES_SHARED(Locks::mutator_lock_);
SpaceType GetType() const override {
return kSpaceTypeZygoteSpace;
}
uint64_t GetBytesAllocated() override {
return Size();
}
uint64_t GetObjectsAllocated() override {
return objects_allocated_.load();
}
bool CanMoveObjects() const override {
return false;
}
protected:
accounting::ContinuousSpaceBitmap::SweepCallback* GetSweepCallback() override {
return &SweepCallback;
}
private:
ZygoteSpace(const std::string& name, MemMap&& mem_map, size_t objects_allocated);
};
art/runtime/gc/space/zygote_space.cc:45
ZygoteSpace* ZygoteSpace::Create(const std::string& name,
MemMap&& mem_map,
accounting::ContinuousSpaceBitmap&& live_bitmap,
accounting::ContinuousSpaceBitmap&& mark_bitmap) {
DCHECK(live_bitmap.IsValid());
DCHECK(mark_bitmap.IsValid());
size_t objects_allocated = 0;
CountObjectsAllocated visitor(&objects_allocated);
ReaderMutexLock mu(Thread::Current(), *Locks::heap_bitmap_lock_);
live_bitmap.VisitMarkedRange(reinterpret_cast<uintptr_t>(mem_map.Begin()),
reinterpret_cast<uintptr_t>(mem_map.End()), visitor);
ZygoteSpace* zygote_space = new ZygoteSpace(name, std::move(mem_map), objects_allocated);
zygote_space->live_bitmap_ = std::move(live_bitmap);
zygote_space->mark_bitmap_ = std::move(mark_bitmap);
return zygote_space;
}
ZygoteSpace用于保存Zygote進程的資源昼激,不會被垃圾回收限煞。當(dāng)然子進程是fork出來的抹恳,除非重寫了該區(qū)域,不然也回收不了該區(qū)域晰骑,重新寫入數(shù)據(jù)只會導(dǎo)致copy on write适秩,反而占用內(nèi)存了。