dex2oat: Test whether the passed vdex has no dex file.

In such a case, use the passed APK instead.

bug: 63920015
Test: 674-vdex-uncompressed
Change-Id: Icec87e6a6b65091a800ebec28b47d35daa6711c9
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index a836d75..8555abf 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -2404,7 +2404,7 @@
 
   bool AddDexFileSources() {
     TimingLogger::ScopedTiming t2("AddDexFileSources", timings_);
-    if (input_vdex_file_ != nullptr) {
+    if (input_vdex_file_ != nullptr && input_vdex_file_->HasDexSection()) {
       DCHECK_EQ(oat_writers_.size(), 1u);
       const std::string& name = zip_location_.empty() ? dex_locations_[0] : zip_location_;
       DCHECK(!name.empty());
diff --git a/runtime/vdex_file.h b/runtime/vdex_file.h
index 4e45128..202380d 100644
--- a/runtime/vdex_file.h
+++ b/runtime/vdex_file.h
@@ -218,6 +218,10 @@
   ArrayRef<const uint8_t> GetQuickenedInfoOf(const DexFile& dex_file,
                                              uint32_t dex_method_idx) const;
 
+  bool HasDexSection() const {
+    return GetHeader().GetDexSize() != 0;
+  }
+
  private:
   uint32_t GetQuickeningInfoTableOffset(const uint8_t* source_dex_begin) const;
 
@@ -235,10 +239,6 @@
       uint32_t num_method_ids,
       const ArrayRef<const uint8_t>& quickening_info) const;
 
-  bool HasDexSection() const {
-    return GetHeader().GetDexSize() != 0;
-  }
-
   bool ContainsDexFile(const DexFile& dex_file) const;
 
   const uint8_t* DexBegin() const {
diff --git a/test/674-vdex-uncompress/build b/test/674-vdex-uncompress/build
new file mode 100755
index 0000000..7b1804d
--- /dev/null
+++ b/test/674-vdex-uncompress/build
@@ -0,0 +1,19 @@
+#!/bin/bash
+#
+# Copyright 2018 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.
+
+# Uncompress and align the dex files so that dex2oat will not copy the dex
+# code to the .vdex file.
+./default-build "$@" --zip-compression-method store --zip-align 4
diff --git a/test/674-vdex-uncompress/expected.txt b/test/674-vdex-uncompress/expected.txt
new file mode 100644
index 0000000..d0f61f6
--- /dev/null
+++ b/test/674-vdex-uncompress/expected.txt
@@ -0,0 +1,2 @@
+In foo
+In foo
diff --git a/test/674-vdex-uncompress/info.txt b/test/674-vdex-uncompress/info.txt
new file mode 100644
index 0000000..6aa6f7b
--- /dev/null
+++ b/test/674-vdex-uncompress/info.txt
@@ -0,0 +1,2 @@
+Test that dex2oat can compile an APK that has uncompressed dex files,
+and where --input-vdex is passed.
diff --git a/test/674-vdex-uncompress/run b/test/674-vdex-uncompress/run
new file mode 100644
index 0000000..edf699f
--- /dev/null
+++ b/test/674-vdex-uncompress/run
@@ -0,0 +1,17 @@
+#!/bin/bash
+#
+# Copyright (C) 2018 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.
+
+exec ${RUN} -Xcompiler-option --compiler-filter=verify --vdex "${@}"
diff --git a/test/674-vdex-uncompress/src/Main.java b/test/674-vdex-uncompress/src/Main.java
new file mode 100644
index 0000000..0a25b56
--- /dev/null
+++ b/test/674-vdex-uncompress/src/Main.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+public class Main {
+  Main() {
+    // Will be quickened with RETURN_VOID_NO_BARRIER.
+  }
+
+  public static void main(String[] args) {
+    Main m = new Main();
+    Object o = m;
+    // The call and field accesses will be quickened.
+    m.foo(m.a);
+
+    // The checkcast will be quickened.
+    m.foo(((Main)o).a);
+  }
+
+  int a;
+  void foo(int a) {
+    System.out.println("In foo");
+  }
+}
+