Merge "ART: Move openjdkjvm to art/"
diff --git a/Android.bp b/Android.bp
index dff6efa..cb72082 100644
--- a/Android.bp
+++ b/Android.bp
@@ -36,6 +36,7 @@
     "profman",
     "runtime",
     "sigchainlib",
+    "simulator",
     "test",
     "tools/cpp-define-generator",
     "tools/dmtracedump",
diff --git a/compiler/Android.bp b/compiler/Android.bp
index b721d21..f11d256 100644
--- a/compiler/Android.bp
+++ b/compiler/Android.bp
@@ -423,8 +423,11 @@
         },
     },
 
+    header_libs: ["libart_simulator_headers"],
+
     shared_libs: [
         "libartd-compiler",
+        "libartd-simulator-container",
         "libvixld-arm",
         "libvixld-arm64",
 
diff --git a/compiler/dex/verification_results.cc b/compiler/dex/verification_results.cc
index e657e3b..cfb56e3 100644
--- a/compiler/dex/verification_results.cc
+++ b/compiler/dex/verification_results.cc
@@ -46,10 +46,6 @@
 
 void VerificationResults::ProcessVerifiedMethod(verifier::MethodVerifier* method_verifier) {
   DCHECK(method_verifier != nullptr);
-  if (!compiler_options_->IsAnyCompilationEnabled()) {
-    // Verified methods are only required for quickening and compilation.
-    return;
-  }
   MethodReference ref = method_verifier->GetMethodReference();
   std::unique_ptr<const VerifiedMethod> verified_method(VerifiedMethod::Create(method_verifier));
   if (verified_method == nullptr) {
@@ -104,7 +100,6 @@
 
 const VerifiedMethod* VerificationResults::GetVerifiedMethod(MethodReference ref) {
   const VerifiedMethod* ret = nullptr;
-  DCHECK(compiler_options_->IsAnyCompilationEnabled());
   if (atomic_verified_methods_.Get(DexFileReference(ref.dex_file, ref.dex_method_index), &ret)) {
     return ret;
   }
diff --git a/compiler/optimizing/codegen_test_utils.h b/compiler/optimizing/codegen_test_utils.h
index 1b38acd..cada2e6 100644
--- a/compiler/optimizing/codegen_test_utils.h
+++ b/compiler/optimizing/codegen_test_utils.h
@@ -28,6 +28,7 @@
 #include "arch/x86/instruction_set_features_x86.h"
 #include "arch/x86/registers_x86.h"
 #include "arch/x86_64/instruction_set_features_x86_64.h"
+#include "code_simulator.h"
 #include "code_simulator_container.h"
 #include "common_compiler_test.h"
 #include "graph_checker.h"
diff --git a/runtime/Android.bp b/runtime/Android.bp
index 1df647d..ff803eb 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -50,7 +50,6 @@
         "class_linker.cc",
         "class_loader_context.cc",
         "class_table.cc",
-        "code_simulator_container.cc",
         "common_throws.cc",
         "compiler_filter.cc",
         "debugger.cc",
@@ -628,5 +627,4 @@
 
 subdirs = [
     "openjdkjvmti",
-    "simulator",
 ]
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index e5ed8ae..25000e5 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -8587,7 +8587,7 @@
   if (!method->IsNative()) {
     method->SetEntryPointFromQuickCompiledCode(GetQuickToInterpreterBridge());
   } else {
-    SetEntryPointsToCompiledCode(method, GetQuickGenericJniStub());
+    method->SetEntryPointFromQuickCompiledCode(GetQuickGenericJniStub());
   }
 }
 
diff --git a/runtime/class_loader_context.cc b/runtime/class_loader_context.cc
index ff440d7..92d0f8d 100644
--- a/runtime/class_loader_context.cc
+++ b/runtime/class_loader_context.cc
@@ -607,7 +607,8 @@
   if (expected_context.class_loader_chain_.size() != class_loader_chain_.size()) {
     LOG(WARNING) << "ClassLoaderContext size mismatch. expected="
         << expected_context.class_loader_chain_.size()
-        << ", actual=" << class_loader_chain_.size();
+        << ", actual=" << class_loader_chain_.size()
+        << " (" << context_spec << " | " << EncodeContextForOatFile("") << ")";
     return false;
   }
 
@@ -617,13 +618,15 @@
     if (info.type != expected_info.type) {
       LOG(WARNING) << "ClassLoaderContext type mismatch for position " << i
           << ". expected=" << GetClassLoaderTypeName(expected_info.type)
-          << ", found=" << GetClassLoaderTypeName(info.type);
+          << ", found=" << GetClassLoaderTypeName(info.type)
+          << " (" << context_spec << " | " << EncodeContextForOatFile("") << ")";
       return false;
     }
     if (info.classpath.size() != expected_info.classpath.size()) {
       LOG(WARNING) << "ClassLoaderContext classpath size mismatch for position " << i
             << ". expected=" << expected_info.classpath.size()
-            << ", found=" << info.classpath.size();
+            << ", found=" << info.classpath.size()
+            << " (" << context_spec << " | " << EncodeContextForOatFile("") << ")";
       return false;
     }
 
@@ -634,13 +637,15 @@
       if (info.classpath[k] != expected_info.classpath[k]) {
         LOG(WARNING) << "ClassLoaderContext classpath element mismatch for position " << i
             << ". expected=" << expected_info.classpath[k]
-            << ", found=" << info.classpath[k];
+            << ", found=" << info.classpath[k]
+            << " (" << context_spec << " | " << EncodeContextForOatFile("") << ")";
         return false;
       }
       if (info.checksums[k] != expected_info.checksums[k]) {
         LOG(WARNING) << "ClassLoaderContext classpath element checksum mismatch for position " << i
             << ". expected=" << expected_info.checksums[k]
-            << ", found=" << info.checksums[k];
+            << ", found=" << info.checksums[k]
+            << " (" << context_spec << " | " << EncodeContextForOatFile("") << ")";
         return false;
       }
     }
diff --git a/runtime/simulator/Android.bp b/simulator/Android.bp
similarity index 60%
rename from runtime/simulator/Android.bp
rename to simulator/Android.bp
index 03e3f15..a399289 100644
--- a/runtime/simulator/Android.bp
+++ b/simulator/Android.bp
@@ -14,6 +14,12 @@
 // limitations under the License.
 //
 
+cc_library_headers {
+    name: "libart_simulator_headers",
+    host_supported: true,
+    export_include_dirs: ["include"],
+}
+
 cc_defaults {
     name: "libart_simulator_defaults",
     host_supported: true,
@@ -29,8 +35,8 @@
         "liblog",
     ],
     cflags: ["-DVIXL_INCLUDE_SIMULATOR_AARCH64"],
-    export_include_dirs: ["."],
-    include_dirs: ["art/runtime"],
+
+    header_libs: ["libart_simulator_headers"],
 }
 
 art_cc_library {
@@ -53,3 +59,38 @@
         "libvixld-arm64",
     ],
 }
+
+cc_defaults {
+    name: "libart_simulator_container_defaults",
+    host_supported: true,
+
+    defaults: ["art_defaults"],
+    srcs: [
+        "code_simulator_container.cc",
+    ],
+    shared_libs: [
+        "libbase",
+    ],
+
+    header_libs: ["libart_simulator_headers"],
+    export_include_dirs: ["."],  // TODO: Consider a proper separation.
+}
+
+art_cc_library {
+    name: "libart-simulator-container",
+    defaults: ["libart_simulator_container_defaults"],
+    shared_libs: [
+        "libart",
+    ],
+}
+
+art_cc_library {
+    name: "libartd-simulator-container",
+    defaults: [
+        "art_debug_defaults",
+        "libart_simulator_container_defaults",
+    ],
+    shared_libs: [
+        "libartd",
+    ],
+}
diff --git a/runtime/simulator/code_simulator.cc b/simulator/code_simulator.cc
similarity index 92%
rename from runtime/simulator/code_simulator.cc
rename to simulator/code_simulator.cc
index 1a11160..e653dfc 100644
--- a/runtime/simulator/code_simulator.cc
+++ b/simulator/code_simulator.cc
@@ -14,8 +14,9 @@
  * limitations under the License.
  */
 
-#include "simulator/code_simulator.h"
-#include "simulator/code_simulator_arm64.h"
+#include "code_simulator.h"
+
+#include "code_simulator_arm64.h"
 
 namespace art {
 
diff --git a/runtime/simulator/code_simulator_arm64.cc b/simulator/code_simulator_arm64.cc
similarity index 97%
rename from runtime/simulator/code_simulator_arm64.cc
rename to simulator/code_simulator_arm64.cc
index c7ad1fd..939d2e2 100644
--- a/runtime/simulator/code_simulator_arm64.cc
+++ b/simulator/code_simulator_arm64.cc
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "simulator/code_simulator_arm64.h"
+#include "code_simulator_arm64.h"
 
 #include "base/logging.h"
 
diff --git a/runtime/simulator/code_simulator_arm64.h b/simulator/code_simulator_arm64.h
similarity index 88%
rename from runtime/simulator/code_simulator_arm64.h
rename to simulator/code_simulator_arm64.h
index 59ea34f..0542593 100644
--- a/runtime/simulator/code_simulator_arm64.h
+++ b/simulator/code_simulator_arm64.h
@@ -14,11 +14,10 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_SIMULATOR_CODE_SIMULATOR_ARM64_H_
-#define ART_RUNTIME_SIMULATOR_CODE_SIMULATOR_ARM64_H_
+#ifndef ART_SIMULATOR_CODE_SIMULATOR_ARM64_H_
+#define ART_SIMULATOR_CODE_SIMULATOR_ARM64_H_
 
 #include "memory"
-#include "simulator/code_simulator.h"
 
 // TODO(VIXL): Make VIXL compile with -Wshadow.
 #pragma GCC diagnostic push
@@ -26,6 +25,8 @@
 #include "aarch64/simulator-aarch64.h"
 #pragma GCC diagnostic pop
 
+#include "code_simulator.h"
+
 namespace art {
 namespace arm64 {
 
@@ -55,4 +56,4 @@
 }  // namespace arm64
 }  // namespace art
 
-#endif  // ART_RUNTIME_SIMULATOR_CODE_SIMULATOR_ARM64_H_
+#endif  // ART_SIMULATOR_CODE_SIMULATOR_ARM64_H_
diff --git a/runtime/code_simulator_container.cc b/simulator/code_simulator_container.cc
similarity index 98%
rename from runtime/code_simulator_container.cc
rename to simulator/code_simulator_container.cc
index d884c58..a5f05dc 100644
--- a/runtime/code_simulator_container.cc
+++ b/simulator/code_simulator_container.cc
@@ -17,6 +17,8 @@
 #include <dlfcn.h>
 
 #include "code_simulator_container.h"
+
+#include "code_simulator.h"
 #include "globals.h"
 
 namespace art {
diff --git a/runtime/code_simulator_container.h b/simulator/code_simulator_container.h
similarity index 87%
rename from runtime/code_simulator_container.h
rename to simulator/code_simulator_container.h
index 10178ba..31a915e 100644
--- a/runtime/code_simulator_container.h
+++ b/simulator/code_simulator_container.h
@@ -14,15 +14,16 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_CODE_SIMULATOR_CONTAINER_H_
-#define ART_RUNTIME_CODE_SIMULATOR_CONTAINER_H_
+#ifndef ART_SIMULATOR_CODE_SIMULATOR_CONTAINER_H_
+#define ART_SIMULATOR_CODE_SIMULATOR_CONTAINER_H_
 
 #include "arch/instruction_set.h"
 #include "base/logging.h"
-#include "simulator/code_simulator.h"
 
 namespace art {
 
+class CodeSimulator;
+
 // This container dynamically opens and closes libart-simulator.
 class CodeSimulatorContainer {
  public:
@@ -52,4 +53,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_CODE_SIMULATOR_CONTAINER_H_
+#endif  // ART_SIMULATOR_CODE_SIMULATOR_CONTAINER_H_
diff --git a/runtime/simulator/code_simulator.h b/simulator/include/code_simulator.h
similarity index 89%
rename from runtime/simulator/code_simulator.h
rename to simulator/include/code_simulator.h
index bd48909..256ab23 100644
--- a/runtime/simulator/code_simulator.h
+++ b/simulator/include/code_simulator.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_SIMULATOR_CODE_SIMULATOR_H_
-#define ART_RUNTIME_SIMULATOR_CODE_SIMULATOR_H_
+#ifndef ART_SIMULATOR_INCLUDE_CODE_SIMULATOR_H_
+#define ART_SIMULATOR_INCLUDE_CODE_SIMULATOR_H_
 
 #include "arch/instruction_set.h"
 
@@ -43,4 +43,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_SIMULATOR_CODE_SIMULATOR_H_
+#endif  // ART_SIMULATOR_INCLUDE_CODE_SIMULATOR_H_
diff --git a/tools/dexfuzz/README b/tools/dexfuzz/README
index a635fe9..1f74262 100644
--- a/tools/dexfuzz/README
+++ b/tools/dexfuzz/README
@@ -145,7 +145,7 @@
 PoolIndexChanger 30
 RandomBranchChanger 30
 RandomInstructionGenerator 30
-RegisterClobber 40
+RegisterClobber 10
 SwitchBranchShifter 30
 TryBlockShifter 40
 ValuePrinter 40
diff --git a/tools/dexfuzz/src/dexfuzz/DexFuzz.java b/tools/dexfuzz/src/dexfuzz/DexFuzz.java
index b0ce5a8..2b3b8e7 100644
--- a/tools/dexfuzz/src/dexfuzz/DexFuzz.java
+++ b/tools/dexfuzz/src/dexfuzz/DexFuzz.java
@@ -33,9 +33,9 @@
  * Entrypoint class for dexfuzz.
  */
 public class DexFuzz {
-  // Last version update 1.6: added temporary register to ArrayLengthChanger.
+  // Last version update 1.7: changed the likelihood of RegisterClobber.
   private static int majorVersion = 1;
-  private static int minorVersion = 6;
+  private static int minorVersion = 7;
   private static int seedChangeVersion = 0;
 
   /**
diff --git a/tools/dexfuzz/src/dexfuzz/program/mutators/RegisterClobber.java b/tools/dexfuzz/src/dexfuzz/program/mutators/RegisterClobber.java
index 11da1d4..90f4f0f 100644
--- a/tools/dexfuzz/src/dexfuzz/program/mutators/RegisterClobber.java
+++ b/tools/dexfuzz/src/dexfuzz/program/mutators/RegisterClobber.java
@@ -61,7 +61,7 @@
 
   public RegisterClobber(Random rng, MutationStats stats, List<Mutation> mutations) {
     super(rng, stats, mutations);
-    likelihood = 40;
+    likelihood = 10;
   }
 
   @Override
@@ -90,6 +90,7 @@
       newInsn.insn = new Instruction();
       newInsn.insn.info = Instruction.getOpcodeInfo(Opcode.CONST_16);
       newInsn.insn.vregA = i;
+      // Used zero because it may also apply to objects, resulting in fewer verification failures.
       newInsn.insn.vregB = 0;
       mutatableCode.insertInstructionAt(newInsn, mutation.regClobberIdx + i);
     }
diff --git a/tools/generate_cmake_lists.py b/tools/generate_cmake_lists.py
new file mode 100755
index 0000000..6c3ce08
--- /dev/null
+++ b/tools/generate_cmake_lists.py
@@ -0,0 +1,98 @@
+#!/usr/bin/env python
+#
+# Copyright 2017, 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.
+
+
+"""
+./generate_cmake_lists.py --project-name <project-name> --arch <arch>
+
+- project-name - name of the new project
+- arch - arch type. make generates seperate CMakeLists files for
+         each architecture. To avoid collision in targets, only one of
+         them can be included in the super project.
+
+The primary objective of this file is to generate CMakeLists files
+for CLion setup.
+
+Steps to setup CLion.
+1) Open the generated CMakeList file in CLion as a project.
+2) Change the project root ANDROID_BUILD_TOP.
+(Also, exclude projects that you don't bother about. This will make
+the indexing faster).
+"""
+
+import sys
+import os
+import subprocess
+import argparse
+
+def get_android_build_top():
+  path_to_top = os.environ.get('ANDROID_BUILD_TOP')
+  if not path_to_top:
+    # nothing set. try to guess it based on the relative path of this env.py file.
+    this_file_path = os.path.realpath(__file__)
+    path_to_top = os.path.join(os.path.dirname(this_file_path), '../..')
+    path_to_top = os.path.realpath(path_to_top)
+
+  if not os.path.exists(os.path.join(path_to_top, 'build/envsetup.sh')):
+    print path_to_top
+    raise AssertionError("geneate_cmake_lists.py must be located inside an android source tree")
+
+  return path_to_top
+
+def main():
+  # Parse arguments
+  parser = argparse.ArgumentParser(description="Generate CMakeLists files for ART")
+  parser.add_argument('--project-name', dest="project_name", required=True,
+                      help='name of the project')
+  parser.add_argument('--arch', dest="arch", required=True, help='arch')
+  args = parser.parse_args()
+  project_name = args.project_name
+  arch = args.arch
+
+  # Invoke make to generate CMakeFiles
+  os.environ['SOONG_GEN_CMAKEFILES']='1'
+  os.environ['SOONG_GEN_CMAKEFILES_DEBUG']='1'
+
+  ANDROID_BUILD_TOP = get_android_build_top()
+
+  subprocess.check_output(('make -j64 -C %s') % (ANDROID_BUILD_TOP), shell=True)
+
+  out_art_cmakelists_dir = os.path.join(ANDROID_BUILD_TOP,
+                                        'out/development/ide/clion/art')
+
+  # Prepare a list of directories containing generated CMakeLists files for sub projects.
+  cmake_sub_dirs = set()
+  for root, dirs, files in os.walk(out_art_cmakelists_dir):
+    for name in files:
+      if name == 'CMakeLists.txt':
+        if (os.path.samefile(root, out_art_cmakelists_dir)):
+          continue
+        if arch not in root:
+          continue
+        cmake_sub_dir = cmake_sub_dirs.add(root.replace(out_art_cmakelists_dir,
+                                                        '.'))
+
+  # Generate CMakeLists file.
+  f = open(os.path.join(out_art_cmakelists_dir, 'CMakeLists.txt'), 'w')
+  f.write('cmake_minimum_required(VERSION 3.6)\n')
+  f.write('project(%s)\n' % (project_name))
+
+  for dr in cmake_sub_dirs:
+    f.write('add_subdirectory(%s)\n' % (dr))
+
+
+if __name__ == '__main__':
+  main()