diff options
| -rw-r--r-- | runtime/gc/collector_type.h | 2 | ||||
| -rw-r--r-- | runtime/gc/gc_cause.cc | 1 | ||||
| -rw-r--r-- | runtime/gc/gc_cause.h | 2 | ||||
| -rw-r--r-- | runtime/jit/profile_saver.cc | 33 |
4 files changed, 26 insertions, 12 deletions
diff --git a/runtime/gc/collector_type.h b/runtime/gc/collector_type.h index f0e1029f85..8979e742c8 100644 --- a/runtime/gc/collector_type.h +++ b/runtime/gc/collector_type.h @@ -61,6 +61,8 @@ enum CollectorType { kCollectorTypeAddRemoveSystemWeakHolder, // Fake collector type for GetObjectsAllocated kCollectorTypeGetObjectsAllocated, + // Fake collector type for ScopedGCCriticalSection + kCollectorTypeCriticalSection, }; std::ostream& operator<<(std::ostream& os, const CollectorType& collector_type); diff --git a/runtime/gc/gc_cause.cc b/runtime/gc/gc_cause.cc index 2bbc86e3e9..39b5e3952d 100644 --- a/runtime/gc/gc_cause.cc +++ b/runtime/gc/gc_cause.cc @@ -42,6 +42,7 @@ const char* PrettyCause(GcCause cause) { case kGcCauseAddRemoveSystemWeakHolder: return "SystemWeakHolder"; case kGcCauseHprof: return "Hprof"; case kGcCauseGetObjectsAllocated: return "ObjectsAllocated"; + case kGcCauseProfileSaver: return "ProfileSaver"; } LOG(FATAL) << "Unreachable"; UNREACHABLE(); diff --git a/runtime/gc/gc_cause.h b/runtime/gc/gc_cause.h index b8cf3c4295..b2b3a91645 100644 --- a/runtime/gc/gc_cause.h +++ b/runtime/gc/gc_cause.h @@ -61,6 +61,8 @@ enum GcCause { kGcCauseHprof, // Not a real GC cause, used to prevent GetObjectsAllocated running in the middle of GC. kGcCauseGetObjectsAllocated, + // GC cause for the profile saver. + kGcCauseProfileSaver, }; const char* PrettyCause(GcCause cause); diff --git a/runtime/jit/profile_saver.cc b/runtime/jit/profile_saver.cc index 1e6f7a846d..2dba9b76a2 100644 --- a/runtime/jit/profile_saver.cc +++ b/runtime/jit/profile_saver.cc @@ -28,10 +28,12 @@ #include "base/systrace.h" #include "base/time_utils.h" #include "compiler_filter.h" +#include "gc/collector_type.h" +#include "gc/gc_cause.h" +#include "gc/scoped_gc_critical_section.h" #include "oat_file_manager.h" #include "scoped_thread_state_change-inl.h" - namespace art { ProfileSaver* ProfileSaver::instance_ = nullptr; @@ -208,20 +210,27 @@ void ProfileSaver::FetchAndCacheResolvedClassesAndMethods() { // Resolve any new registered locations. ResolveTrackedLocations(); - ClassLinker* const class_linker = Runtime::Current()->GetClassLinker(); - std::set<DexCacheResolvedClasses> resolved_classes = - class_linker->GetResolvedClasses(/*ignore boot classes*/ true); - + Thread* const self = Thread::Current(); std::vector<MethodReference> methods; + std::set<DexCacheResolvedClasses> resolved_classes; { - ScopedTrace trace2("Get hot methods"); - GetMethodsVisitor visitor(&methods, options_.GetStartupMethodSamples()); - ScopedObjectAccess soa(Thread::Current()); - class_linker->VisitClasses(&visitor); - VLOG(profiler) << "Methods with samples greater than " - << options_.GetStartupMethodSamples() << " = " << methods.size(); + ScopedObjectAccess soa(self); + gc::ScopedGCCriticalSection sgcs(self, + gc::kGcCauseProfileSaver, + gc::kCollectorTypeCriticalSection); + + ClassLinker* const class_linker = Runtime::Current()->GetClassLinker(); + resolved_classes = class_linker->GetResolvedClasses(/*ignore boot classes*/ true); + + { + ScopedTrace trace2("Get hot methods"); + GetMethodsVisitor visitor(&methods, options_.GetStartupMethodSamples()); + class_linker->VisitClasses(&visitor); + VLOG(profiler) << "Methods with samples greater than " + << options_.GetStartupMethodSamples() << " = " << methods.size(); + } } - MutexLock mu(Thread::Current(), *Locks::profiler_lock_); + MutexLock mu(self, *Locks::profiler_lock_); uint64_t total_number_of_profile_entries_cached = 0; for (const auto& it : tracked_dex_base_locations_) { |