OSDN Git Service

Remove some more read barriers in image relocation
authorMathieu Chartier <mathieuc@google.com>
Thu, 28 Jan 2016 02:37:48 +0000 (18:37 -0800)
committerMathieu Chartier <mathieuc@google.com>
Thu, 28 Jan 2016 19:01:18 +0000 (11:01 -0800)
Bug: 26786304
Bug: 22858531
Change-Id: I70dacae7657ebf6dac2b3dad7726eebe5a2b2649

runtime/gc/space/image_space.cc
runtime/mirror/dex_cache-inl.h
runtime/mirror/dex_cache.h

index 891e280..f607923 100644 (file)
@@ -1041,7 +1041,7 @@ static bool RelocateInPlace(ImageHeader& image_header,
     auto* dex_caches = image_header.GetImageRoot<kWithoutReadBarrier>(ImageHeader::kDexCaches)->
         AsObjectArray<mirror::DexCache>();
     for (int32_t i = 0, count = dex_caches->GetLength(); i < count; ++i) {
-      mirror::DexCache* dex_cache = dex_caches->Get(i);
+      mirror::DexCache* dex_cache = dex_caches->Get<kVerifyNone, kWithoutReadBarrier>(i);
       // Fix up dex cache pointers.
       GcRoot<mirror::String>* strings = dex_cache->GetStrings();
       if (strings != nullptr) {
@@ -1049,7 +1049,7 @@ static bool RelocateInPlace(ImageHeader& image_header,
         if (strings != new_strings) {
           dex_cache->SetFieldPtr64<false>(mirror::DexCache::StringsOffset(), new_strings);
         }
-        dex_cache->FixupStrings(new_strings, fixup_adapter);
+        dex_cache->FixupStrings<kWithoutReadBarrier>(new_strings, fixup_adapter);
       }
       GcRoot<mirror::Class>* types = dex_cache->GetResolvedTypes();
       if (types != nullptr) {
@@ -1057,7 +1057,7 @@ static bool RelocateInPlace(ImageHeader& image_header,
         if (types != new_types) {
           dex_cache->SetFieldPtr64<false>(mirror::DexCache::ResolvedTypesOffset(), new_types);
         }
-        dex_cache->FixupResolvedTypes(new_types, fixup_adapter);
+        dex_cache->FixupResolvedTypes<kWithoutReadBarrier>(new_types, fixup_adapter);
       }
       ArtMethod** methods = dex_cache->GetResolvedMethods();
       if (methods != nullptr) {
index 2ecc9fb..2da3d84 100644 (file)
@@ -142,12 +142,11 @@ inline void DexCache::VisitReferences(mirror::Class* klass, const Visitor& visit
   }
 }
 
-template <typename Visitor>
+template <ReadBarrierOption kReadBarrierOption, typename Visitor>
 inline void DexCache::FixupStrings(GcRoot<mirror::String>* dest, const Visitor& visitor) {
   GcRoot<mirror::String>* src = GetStrings();
   for (size_t i = 0, count = NumStrings(); i < count; ++i) {
-    // TODO: Probably don't need read barrier for most callers.
-    mirror::String* source = src[i].Read();
+    mirror::String* source = src[i].Read<kReadBarrierOption>();
     mirror::String* new_source = visitor(source);
     if (source != new_source) {
       dest[i] = GcRoot<mirror::String>(new_source);
@@ -155,12 +154,11 @@ inline void DexCache::FixupStrings(GcRoot<mirror::String>* dest, const Visitor&
   }
 }
 
-template <typename Visitor>
+template <ReadBarrierOption kReadBarrierOption, typename Visitor>
 inline void DexCache::FixupResolvedTypes(GcRoot<mirror::Class>* dest, const Visitor& visitor) {
   GcRoot<mirror::Class>* src = GetResolvedTypes();
   for (size_t i = 0, count = NumResolvedTypes(); i < count; ++i) {
-    // TODO: Probably don't need read barrier for most callers.
-    mirror::Class* source = src[i].Read();
+    mirror::Class* source = src[i].Read<kReadBarrierOption>();
     mirror::Class* new_source = visitor(source);
     if (source != new_source) {
       dest[i] = GcRoot<mirror::Class>(new_source);
index 0002076..7912510 100644 (file)
@@ -61,11 +61,11 @@ class MANAGED DexCache FINAL : public Object {
   void Fixup(ArtMethod* trampoline, size_t pointer_size)
       SHARED_REQUIRES(Locks::mutator_lock_);
 
-  template <typename Visitor>
+  template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier, typename Visitor>
   void FixupStrings(GcRoot<mirror::String>* dest, const Visitor& visitor)
       SHARED_REQUIRES(Locks::mutator_lock_);
 
-  template <typename Visitor>
+  template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier, typename Visitor>
   void FixupResolvedTypes(GcRoot<mirror::Class>* dest, const Visitor& visitor)
       SHARED_REQUIRES(Locks::mutator_lock_);