OSDN Git Service

Put the deletion of profiling info under a GC critical section.
authorNicolas Geoffray <ngeoffray@google.com>
Sat, 30 Jul 2016 21:49:11 +0000 (22:49 +0100)
committerNarayan Kamath <narayan@google.com>
Wed, 10 Aug 2016 08:50:32 +0000 (08:50 +0000)
Otherwise the GC could see dangling pointers.

bug:30033802

(cherry picked from commit cf48fa030780c3185f225d558b704c396f7713cc)

Change-Id: I2c43e973878f50dc147aa0af81551ecc942a790d

runtime/gc/collector_type.h
runtime/gc/gc_cause.cc
runtime/gc/gc_cause.h
runtime/gc/heap.cc
runtime/jit/jit_code_cache.cc
runtime/jit/jit_code_cache.h

index a06ccbe..f14d086 100644 (file)
@@ -49,6 +49,8 @@ enum CollectorType {
   kCollectorTypeHomogeneousSpaceCompact,
   // Class linker fake collector.
   kCollectorTypeClassLinker,
+  // JIT Code cache fake collector.
+  kCollectorTypeJitCodeCache,
 };
 std::ostream& operator<<(std::ostream& os, const CollectorType& collector_type);
 
index 1b03460..cf765f5 100644 (file)
@@ -36,6 +36,7 @@ const char* PrettyCause(GcCause cause) {
     case kGcCauseInstrumentation: return "Instrumentation";
     case kGcCauseAddRemoveAppImageSpace: return "AddRemoveAppImageSpace";
     case kGcCauseClassLinker: return "ClassLinker";
+    case kGcCauseJitCodeCache: return "JitCodeCache";
     default:
       LOG(FATAL) << "Unreachable";
       UNREACHABLE();
index df3aba9..7d2cc4f 100644 (file)
@@ -47,6 +47,8 @@ enum GcCause {
   kGcCauseHomogeneousSpaceCompact,
   // Class linker cause, used to guard filling art methods with special values.
   kGcCauseClassLinker,
+  // Not a real GC cause, used to implement exclusion between code cache metadata and GC.
+  kGcCauseJitCodeCache,
 };
 
 const char* PrettyCause(GcCause cause);
index cdd5f2e..03b7713 100644 (file)
@@ -2709,7 +2709,8 @@ collector::GcType Heap::CollectGarbageInternal(collector::GcType gc_type,
   }
 
   // It's time to clear all inline caches, in case some classes can be unloaded.
-  if ((gc_type == collector::kGcTypeFull) && (runtime->GetJit() != nullptr)) {
+  if (((gc_type == collector::kGcTypeFull) || (gc_type == collector::kGcTypePartial)) &&
+      (runtime->GetJit() != nullptr)) {
     runtime->GetJit()->GetCodeCache()->ClearGcRootsInInlineCaches(self);
   }
 
index 6b6f5a5..8c1d776 100644 (file)
@@ -25,6 +25,7 @@
 #include "debugger_interface.h"
 #include "entrypoints/runtime_asm_entrypoints.h"
 #include "gc/accounting/bitmap-inl.h"
+#include "gc/scoped_gc_critical_section.h"
 #include "jit/jit.h"
 #include "jit/profiling_info.h"
 #include "linear_alloc.h"
@@ -727,6 +728,9 @@ void JitCodeCache::DoCollection(Thread* self, bool collect_profiling_info) {
   RemoveUnmarkedCode(self);
 
   if (collect_profiling_info) {
+    ScopedThreadSuspension sts(self, kSuspended);
+    gc::ScopedGCCriticalSection gcs(
+        self, gc::kGcCauseJitCodeCache, gc::kCollectorTypeJitCodeCache);
     MutexLock mu(self, lock_);
     // Free all profiling infos of methods not compiled nor being compiled.
     auto profiling_kept_end = std::remove_if(profiling_infos_.begin(), profiling_infos_.end(),
index 4df6762..6dc1578 100644 (file)
@@ -255,8 +255,7 @@ class JitCodeCache {
       SHARED_REQUIRES(Locks::mutator_lock_);
 
   bool CheckLiveCompiledCodeHasProfilingInfo()
-      REQUIRES(lock_)
-      SHARED_REQUIRES(Locks::mutator_lock_);
+      REQUIRES(lock_);
 
   void FreeCode(uint8_t* code) REQUIRES(lock_);
   uint8_t* AllocateCode(size_t code_size) REQUIRES(lock_);