ART: Add compiler option for code deduplication

Add --deduplicate-code and --no-deduplicate-code to ease in
experiments with deduplication, e.g., profiling.

Add dex2oat test.

Test: m test-art-host
Change-Id: Ib6c7fe082f43c5f76c8463cc563e2503c9a50480
diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc
index cb91978..99be111 100644
--- a/dex2oat/dex2oat_test.cc
+++ b/dex2oat/dex2oat_test.cc
@@ -1481,4 +1481,36 @@
   EXPECT_EQ(0, res_no_fail);
 }
 
+class Dex2oatDedupeCode : public Dex2oatTest {};
+
+TEST_F(Dex2oatDedupeCode, DedupeTest) {
+  // Use MyClassNatives. It has lots of native methods that will produce deduplicate-able code.
+  std::unique_ptr<const DexFile> dex(OpenTestDexFile("MyClassNatives"));
+  std::string out_dir = GetScratchDir();
+  const std::string base_oat_name = out_dir + "/base.oat";
+  size_t no_dedupe_size = 0;
+  GenerateOdexForTest(dex->GetLocation(),
+                      base_oat_name,
+                      CompilerFilter::Filter::kSpeed,
+                      { "--deduplicate-code=false" },
+                      true,  // expect_success
+                      false,  // use_fd
+                      [&no_dedupe_size](const OatFile& o) {
+                        no_dedupe_size = o.Size();
+                      });
+
+  size_t dedupe_size = 0;
+  GenerateOdexForTest(dex->GetLocation(),
+                      base_oat_name,
+                      CompilerFilter::Filter::kSpeed,
+                      { "--deduplicate-code=true" },
+                      true,  // expect_success
+                      false,  // use_fd
+                      [&dedupe_size](const OatFile& o) {
+                        dedupe_size = o.Size();
+                      });
+
+  EXPECT_LT(dedupe_size, no_dedupe_size);
+}
+
 }  // namespace art