Refactor large object sweeping.
Moved basic sweeping logic into large_object_space.cc.
Renamed SpaceSetMap -> ObjectSet.
Change-Id: I938c1f29f69b0682350347da2bd5de021c0e0224
diff --git a/runtime/gc/space/large_object_space.cc b/runtime/gc/space/large_object_space.cc
index ab6e42b..7fcfed4 100644
--- a/runtime/gc/space/large_object_space.cc
+++ b/runtime/gc/space/large_object_space.cc
@@ -331,6 +331,29 @@
}
}
+void LargeObjectSpace::Sweep(bool swap_bitmaps, size_t* freed_objects, size_t* freed_bytes) {
+ // Sweep large objects
+ accounting::ObjectSet* large_live_objects = GetLiveObjects();
+ accounting::ObjectSet* large_mark_objects = GetMarkObjects();
+ if (swap_bitmaps) {
+ std::swap(large_live_objects, large_mark_objects);
+ }
+ DCHECK(freed_objects != nullptr);
+ DCHECK(freed_bytes != nullptr);
+ // O(n*log(n)) but hopefully there are not too many large objects.
+ size_t objects = 0;
+ size_t bytes = 0;
+ Thread* self = Thread::Current();
+ for (const mirror::Object* obj : large_live_objects->GetObjects()) {
+ if (!large_mark_objects->Test(obj)) {
+ bytes += Free(self, const_cast<mirror::Object*>(obj));
+ ++objects;
+ }
+ }
+ *freed_objects += objects;
+ *freed_bytes += bytes;
+}
+
} // namespace space
} // namespace gc
} // namespace art
diff --git a/runtime/gc/space/large_object_space.h b/runtime/gc/space/large_object_space.h
index d374ad3..cd7c383 100644
--- a/runtime/gc/space/large_object_space.h
+++ b/runtime/gc/space/large_object_space.h
@@ -67,6 +67,8 @@
return this;
}
+ virtual void Sweep(bool swap_bitmaps, size_t* freed_objects, size_t* freed_bytes);
+
protected:
explicit LargeObjectSpace(const std::string& name);
diff --git a/runtime/gc/space/space.cc b/runtime/gc/space/space.cc
index 8eb17e0..f8ba6b3 100644
--- a/runtime/gc/space/space.cc
+++ b/runtime/gc/space/space.cc
@@ -37,8 +37,8 @@
DiscontinuousSpace::DiscontinuousSpace(const std::string& name,
GcRetentionPolicy gc_retention_policy) :
Space(name, gc_retention_policy),
- live_objects_(new accounting::SpaceSetMap("large live objects")),
- mark_objects_(new accounting::SpaceSetMap("large marked objects")) {
+ live_objects_(new accounting::ObjectSet("large live objects")),
+ mark_objects_(new accounting::ObjectSet("large marked objects")) {
}
} // namespace space
diff --git a/runtime/gc/space/space.h b/runtime/gc/space/space.h
index 31bbb7b..5292344 100644
--- a/runtime/gc/space/space.h
+++ b/runtime/gc/space/space.h
@@ -314,11 +314,11 @@
// is suitable for use for large primitive arrays.
class DiscontinuousSpace : public Space {
public:
- accounting::SpaceSetMap* GetLiveObjects() const {
+ accounting::ObjectSet* GetLiveObjects() const {
return live_objects_.get();
}
- accounting::SpaceSetMap* GetMarkObjects() const {
+ accounting::ObjectSet* GetMarkObjects() const {
return mark_objects_.get();
}
@@ -331,8 +331,8 @@
protected:
DiscontinuousSpace(const std::string& name, GcRetentionPolicy gc_retention_policy);
- UniquePtr<accounting::SpaceSetMap> live_objects_;
- UniquePtr<accounting::SpaceSetMap> mark_objects_;
+ UniquePtr<accounting::ObjectSet> live_objects_;
+ UniquePtr<accounting::ObjectSet> mark_objects_;
private:
DISALLOW_COPY_AND_ASSIGN(DiscontinuousSpace);