diff options
-rw-r--r-- | runtime/Android.mk | 1 | ||||
-rw-r--r-- | runtime/gc/collector/concurrent_copying.cc | 25 | ||||
-rw-r--r-- | runtime/gc/collector/concurrent_copying.h | 56 | ||||
-rw-r--r-- | runtime/gc/collector/garbage_collector.cc | 4 | ||||
-rw-r--r-- | runtime/gc/collector_type.h | 2 | ||||
-rw-r--r-- | runtime/gc/heap.cc | 25 | ||||
-rw-r--r-- | runtime/gc/heap.h | 7 | ||||
-rw-r--r-- | runtime/parsed_options.cc | 2 |
8 files changed, 114 insertions, 8 deletions
diff --git a/runtime/Android.mk b/runtime/Android.mk index 1ca8e07..1576905 100644 --- a/runtime/Android.mk +++ b/runtime/Android.mk @@ -52,6 +52,7 @@ LIBART_COMMON_SRC_FILES := \ gc/accounting/mod_union_table.cc \ gc/accounting/remembered_set.cc \ gc/accounting/space_bitmap.cc \ + gc/collector/concurrent_copying.cc \ gc/collector/garbage_collector.cc \ gc/collector/immune_region.cc \ gc/collector/mark_sweep.cc \ diff --git a/runtime/gc/collector/concurrent_copying.cc b/runtime/gc/collector/concurrent_copying.cc new file mode 100644 index 0000000..079eeba --- /dev/null +++ b/runtime/gc/collector/concurrent_copying.cc @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "concurrent_copying.h" + +namespace art { +namespace gc { +namespace collector { + +} // namespace collector +} // namespace gc +} // namespace art diff --git a/runtime/gc/collector/concurrent_copying.h b/runtime/gc/collector/concurrent_copying.h new file mode 100644 index 0000000..ab26a9c --- /dev/null +++ b/runtime/gc/collector/concurrent_copying.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ART_RUNTIME_GC_COLLECTOR_CONCURRENT_COPYING_H_ +#define ART_RUNTIME_GC_COLLECTOR_CONCURRENT_COPYING_H_ + +#include "garbage_collector.h" + +namespace art { +namespace gc { +namespace collector { + +class ConcurrentCopying : public GarbageCollector { + public: + explicit ConcurrentCopying(Heap* heap, bool generational = false, + const std::string& name_prefix = "") + : GarbageCollector(heap, + name_prefix + (name_prefix.empty() ? "" : " ") + + "concurrent copying + mark sweep") {} + + ~ConcurrentCopying() {} + + virtual void InitializePhase() OVERRIDE {} + virtual void MarkingPhase() OVERRIDE {} + virtual void ReclaimPhase() OVERRIDE {} + virtual void FinishPhase() OVERRIDE {} + virtual GcType GetGcType() const OVERRIDE { + return kGcTypePartial; + } + virtual CollectorType GetCollectorType() const OVERRIDE { + return kCollectorTypeCC; + } + virtual void RevokeAllThreadLocalBuffers() OVERRIDE {} + + private: + DISALLOW_COPY_AND_ASSIGN(ConcurrentCopying); +}; + +} // namespace collector +} // namespace gc +} // namespace art + +#endif // ART_RUNTIME_GC_COLLECTOR_CONCURRENT_COPYING_H_ diff --git a/runtime/gc/collector/garbage_collector.cc b/runtime/gc/collector/garbage_collector.cc index 65b5471..4a2541f 100644 --- a/runtime/gc/collector/garbage_collector.cc +++ b/runtime/gc/collector/garbage_collector.cc @@ -142,6 +142,10 @@ void GarbageCollector::Run(GcCause gc_cause, bool clear_soft_references) { FinishPhase(); break; } + case kCollectorTypeCC: { + // To be implemented. + break; + } default: { LOG(FATAL) << "Unreachable collector type=" << static_cast<size_t>(collector_type); break; diff --git a/runtime/gc/collector_type.h b/runtime/gc/collector_type.h index 98c27fb..c0a6b6a 100644 --- a/runtime/gc/collector_type.h +++ b/runtime/gc/collector_type.h @@ -36,6 +36,8 @@ enum CollectorType { kCollectorTypeGSS, // Heap trimming collector, doesn't do any actual collecting. kCollectorTypeHeapTrim, + // A (mostly) concurrent copying collector. + kCollectorTypeCC, }; std::ostream& operator<<(std::ostream& os, const CollectorType& collector_type); diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc index 02e7e3f..26bc76d 100644 --- a/runtime/gc/heap.cc +++ b/runtime/gc/heap.cc @@ -35,6 +35,7 @@ #include "gc/accounting/mod_union_table-inl.h" #include "gc/accounting/remembered_set.h" #include "gc/accounting/space_bitmap-inl.h" +#include "gc/collector/concurrent_copying.h" #include "gc/collector/mark_sweep-inl.h" #include "gc/collector/partial_mark_sweep.h" #include "gc/collector/semi_space.h" @@ -328,6 +329,9 @@ Heap::Heap(size_t initial_size, size_t growth_limit, size_t min_free, size_t max bool generational = post_zygote_collector_type_ == kCollectorTypeGSS; semi_space_collector_ = new collector::SemiSpace(this, generational); garbage_collectors_.push_back(semi_space_collector_); + + concurrent_copying_collector_ = new collector::ConcurrentCopying(this); + garbage_collectors_.push_back(concurrent_copying_collector_); } if (running_on_valgrind_) { @@ -1430,7 +1434,8 @@ void Heap::TransitionCollector(CollectorType collector_type) { break; } default: { - LOG(FATAL) << "Attempted to transition to invalid collector type"; + LOG(FATAL) << "Attempted to transition to invalid collector type " + << static_cast<size_t>(collector_type); break; } } @@ -1460,6 +1465,7 @@ void Heap::ChangeCollector(CollectorType collector_type) { collector_type_ = collector_type; gc_plan_.clear(); switch (collector_type_) { + case kCollectorTypeCC: // Fall-through. case kCollectorTypeSS: // Fall-through. case kCollectorTypeGSS: { gc_plan_.push_back(collector::kGcTypeFull); @@ -1812,12 +1818,19 @@ collector::GcType Heap::CollectGarbageInternal(collector::GcType gc_type, GcCaus if (compacting_gc) { DCHECK(current_allocator_ == kAllocatorTypeBumpPointer || current_allocator_ == kAllocatorTypeTLAB); - gc_type = semi_space_collector_->GetGcType(); - CHECK(temp_space_->IsEmpty()); - semi_space_collector_->SetFromSpace(bump_pointer_space_); - semi_space_collector_->SetToSpace(temp_space_); + if (collector_type_ == kCollectorTypeSS || collector_type_ == kCollectorTypeGSS) { + gc_type = semi_space_collector_->GetGcType(); + semi_space_collector_->SetFromSpace(bump_pointer_space_); + semi_space_collector_->SetToSpace(temp_space_); + collector = semi_space_collector_; + } else if (collector_type_ == kCollectorTypeCC) { + gc_type = concurrent_copying_collector_->GetGcType(); + collector = concurrent_copying_collector_; + } else { + LOG(FATAL) << "Unreachable - invalid collector type " << static_cast<size_t>(collector_type_); + } temp_space_->GetMemMap()->Protect(PROT_READ | PROT_WRITE); - collector = semi_space_collector_; + CHECK(temp_space_->IsEmpty()); gc_type = collector::kGcTypeFull; } else if (current_allocator_ == kAllocatorTypeRosAlloc || current_allocator_ == kAllocatorTypeDlMalloc) { diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h index 60b8450..7afb930 100644 --- a/runtime/gc/heap.h +++ b/runtime/gc/heap.h @@ -60,6 +60,7 @@ namespace accounting { } // namespace accounting namespace collector { + class ConcurrentCopying; class GarbageCollector; class MarkSweep; class SemiSpace; @@ -575,7 +576,8 @@ class Heap { return AllocatorHasAllocationStack(allocator_type); } static bool IsCompactingGC(CollectorType collector_type) { - return collector_type == kCollectorTypeSS || collector_type == kCollectorTypeGSS; + return collector_type == kCollectorTypeSS || collector_type == kCollectorTypeGSS || + collector_type == kCollectorTypeCC; } bool ShouldAllocLargeObject(mirror::Class* c, size_t byte_count) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); @@ -688,7 +690,7 @@ class Heap { // What kind of concurrency behavior is the runtime after? Currently true for concurrent mark // sweep GC, false for other GC types. bool IsGcConcurrent() const ALWAYS_INLINE { - return collector_type_ == kCollectorTypeCMS; + return collector_type_ == kCollectorTypeCMS || collector_type_ == kCollectorTypeCC; } // All-known continuous spaces, where objects lie within fixed bounds. @@ -932,6 +934,7 @@ class Heap { std::vector<collector::GarbageCollector*> garbage_collectors_; collector::SemiSpace* semi_space_collector_; + collector::ConcurrentCopying* concurrent_copying_collector_; const bool running_on_valgrind_; const bool use_tlab_; diff --git a/runtime/parsed_options.cc b/runtime/parsed_options.cc index 9b1c013..e2086f1 100644 --- a/runtime/parsed_options.cc +++ b/runtime/parsed_options.cc @@ -107,6 +107,8 @@ static gc::CollectorType ParseCollectorType(const std::string& option) { return gc::kCollectorTypeSS; } else if (option == "GSS") { return gc::kCollectorTypeGSS; + } else if (option == "CC") { + return gc::kCollectorTypeCC; } else { return gc::kCollectorTypeNone; } |