OSDN Git Service

Fix JIT for vmdebug test 99
authorMathieu Chartier <mathieuc@google.com>
Wed, 25 Feb 2015 21:22:57 +0000 (13:22 -0800)
committerMathieu Chartier <mathieuc@google.com>
Wed, 25 Feb 2015 23:03:03 +0000 (15:03 -0800)
Test was flaky due to JIT re-compiliation after deoptimization
resulting in some invalid PC offsets.

Bug: 17950037
Change-Id: I276c84c918579259ce47ef873892c3c5dcf0c977

compiler/dex/verification_results.cc
compiler/jit/jit_compiler.cc
runtime/class_linker.cc

index 51a3d84..150bdac 100644 (file)
@@ -71,8 +71,11 @@ bool VerificationResults::ProcessVerifiedMethod(verifier::MethodVerifier* method
       DCHECK_EQ(it->second->GetSafeCastSet().size(), verified_method->GetSafeCastSet().size());
     }
     DCHECK_EQ(it->second->GetDexGcMap().size(), verified_method->GetDexGcMap().size());
-    delete it->second;
-    verified_methods_.erase(it);
+    // Delete the new verified method since there was already an existing one registered. It
+    // is unsafe to replace the existing one since the JIT may be using it to generate a
+    // native GC map.
+    delete verified_method;
+    return true;
   }
   verified_methods_.Put(ref, verified_method);
   DCHECK(verified_methods_.find(ref) != verified_methods_.end());
index b1d972e..2577391 100644 (file)
@@ -132,7 +132,20 @@ bool JitCompiler::CompileMethod(Thread* self, mirror::ArtMethod* method) {
     return false;
   }
   total_time_ += NanoTime() - start_time;
-  const bool result = MakeExecutable(compiled_method, h_method.Get());
+  // Don't add the method if we are supposed to be deoptimized.
+  bool result = false;
+  if (!runtime->GetInstrumentation()->AreAllMethodsDeoptimized()) {
+    const void* code = Runtime::Current()->GetClassLinker()->GetOatMethodQuickCodeFor(
+        h_method.Get());
+    if (code != nullptr) {
+      // Already have some compiled code, just use this instead of linking.
+      // TODO: Fix recompilation.
+      h_method->SetEntryPointFromQuickCompiledCode(code);
+      result = true;
+    } else {
+      result = MakeExecutable(compiled_method, h_method.Get());
+    }
+  }
   // Remove the compiled method to save memory.
   compiler_driver_->RemoveCompiledMethod(method_ref);
   return result;
index f28253a..ee5eefb 100644 (file)
@@ -2520,16 +2520,16 @@ const void* ClassLinker::GetQuickOatCodeFor(mirror::ArtMethod* method) {
     return GetQuickProxyInvokeHandler();
   }
   bool found;
-  jit::Jit* const jit = Runtime::Current()->GetJit();
-  if (jit != nullptr) {
-    auto* code = jit->GetCodeCache()->GetCodeFor(method);
+  OatFile::OatMethod oat_method = FindOatMethodFor(method, &found);
+  if (found) {
+    auto* code = oat_method.GetQuickCode();
     if (code != nullptr) {
       return code;
     }
   }
-  OatFile::OatMethod oat_method = FindOatMethodFor(method, &found);
-  if (found) {
-    auto* code = oat_method.GetQuickCode();
+  jit::Jit* const jit = Runtime::Current()->GetJit();
+  if (jit != nullptr) {
+    auto* code = jit->GetCodeCache()->GetCodeFor(method);
     if (code != nullptr) {
       return code;
     }
@@ -2545,6 +2545,11 @@ const void* ClassLinker::GetOatMethodQuickCodeFor(mirror::ArtMethod* method) {
   if (method->IsNative() || method->IsAbstract() || method->IsProxyMethod()) {
     return nullptr;
   }
+  bool found;
+  OatFile::OatMethod oat_method = FindOatMethodFor(method, &found);
+  if (found) {
+    return oat_method.GetQuickCode();
+  }
   jit::Jit* jit = Runtime::Current()->GetJit();
   if (jit != nullptr) {
     auto* code = jit->GetCodeCache()->GetCodeFor(method);
@@ -2552,11 +2557,6 @@ const void* ClassLinker::GetOatMethodQuickCodeFor(mirror::ArtMethod* method) {
       return code;
     }
   }
-  bool found;
-  OatFile::OatMethod oat_method = FindOatMethodFor(method, &found);
-  if (found) {
-    return oat_method.GetQuickCode();
-  }
   return nullptr;
 }