Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 16 | |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 17 | #include "arch/instruction_set_features.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 18 | #include "art_method-inl.h" |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 19 | #include "base/enums.h" |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 20 | #include "base/unix_file/fd_file.h" |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 21 | #include "class_linker.h" |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 22 | #include "common_compiler_test.h" |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 23 | #include "compiled_method.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 24 | #include "compiler.h" |
David Srbecky | 4fda4eb | 2016-02-05 13:34:46 +0000 | [diff] [blame] | 25 | #include "debug/method_debug_info.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 26 | #include "dex/quick_compiler_callbacks.h" |
Mathieu Chartier | 5bdab12 | 2015-01-26 18:30:19 -0800 | [diff] [blame] | 27 | #include "dex/verification_results.h" |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 28 | #include "driver/compiler_driver.h" |
| 29 | #include "driver/compiler_options.h" |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 30 | #include "elf_writer.h" |
| 31 | #include "elf_writer_quick.h" |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 32 | #include "entrypoints/quick/quick_entrypoints.h" |
Vladimir Marko | 944da60 | 2016-02-19 12:27:55 +0000 | [diff] [blame] | 33 | #include "linker/multi_oat_relative_patcher.h" |
Vladimir Marko | 131980f | 2015-12-03 18:29:23 +0000 | [diff] [blame] | 34 | #include "linker/vector_output_stream.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 35 | #include "mirror/class-inl.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 36 | #include "mirror/object-inl.h" |
David Srbecky | 4fda4eb | 2016-02-05 13:34:46 +0000 | [diff] [blame] | 37 | #include "mirror/object_array-inl.h" |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 38 | #include "oat_file-inl.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 39 | #include "oat_writer.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 40 | #include "scoped_thread_state_change-inl.h" |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 41 | #include "utils/test_dex_file_builder.h" |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 42 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 43 | namespace art { |
| 44 | |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 45 | NO_RETURN static void Usage(const char* fmt, ...) { |
| 46 | va_list ap; |
| 47 | va_start(ap, fmt); |
| 48 | std::string error; |
| 49 | StringAppendV(&error, fmt, ap); |
| 50 | LOG(FATAL) << error; |
| 51 | va_end(ap); |
| 52 | UNREACHABLE(); |
| 53 | } |
| 54 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 55 | class OatTest : public CommonCompilerTest { |
Logan Chien | eeb7edf | 2012-03-09 20:38:39 +0800 | [diff] [blame] | 56 | protected: |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 57 | static const bool kCompile = false; // DISABLED_ due to the time to compile libcore |
| 58 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 59 | void CheckMethod(ArtMethod* method, |
Logan Chien | eeb7edf | 2012-03-09 20:38:39 +0800 | [diff] [blame] | 60 | const OatFile::OatMethod& oat_method, |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 61 | const DexFile& dex_file) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 62 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Logan Chien | eeb7edf | 2012-03-09 20:38:39 +0800 | [diff] [blame] | 63 | const CompiledMethod* compiled_method = |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 64 | compiler_driver_->GetCompiledMethod(MethodReference(&dex_file, |
Brian Carlstrom | 51c2467 | 2013-07-11 16:00:56 -0700 | [diff] [blame] | 65 | method->GetDexMethodIndex())); |
Logan Chien | eeb7edf | 2012-03-09 20:38:39 +0800 | [diff] [blame] | 66 | |
Ian Rogers | d4c4d95 | 2014-10-16 20:31:53 -0700 | [diff] [blame] | 67 | if (compiled_method == nullptr) { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 68 | EXPECT_TRUE(oat_method.GetQuickCode() == nullptr) << method->PrettyMethod() << " " |
Ian Rogers | d4c4d95 | 2014-10-16 20:31:53 -0700 | [diff] [blame] | 69 | << oat_method.GetQuickCode(); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 70 | EXPECT_EQ(oat_method.GetFrameSizeInBytes(), 0U); |
Logan Chien | eeb7edf | 2012-03-09 20:38:39 +0800 | [diff] [blame] | 71 | EXPECT_EQ(oat_method.GetCoreSpillMask(), 0U); |
| 72 | EXPECT_EQ(oat_method.GetFpSpillMask(), 0U); |
| 73 | } else { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 74 | const void* quick_oat_code = oat_method.GetQuickCode(); |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 75 | EXPECT_TRUE(quick_oat_code != nullptr) << method->PrettyMethod(); |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 76 | EXPECT_EQ(oat_method.GetFrameSizeInBytes(), compiled_method->GetFrameSizeInBytes()); |
| 77 | EXPECT_EQ(oat_method.GetCoreSpillMask(), compiled_method->GetCoreSpillMask()); |
| 78 | EXPECT_EQ(oat_method.GetFpSpillMask(), compiled_method->GetFpSpillMask()); |
| 79 | uintptr_t oat_code_aligned = RoundDown(reinterpret_cast<uintptr_t>(quick_oat_code), 2); |
| 80 | quick_oat_code = reinterpret_cast<const void*>(oat_code_aligned); |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 81 | ArrayRef<const uint8_t> quick_code = compiled_method->GetQuickCode(); |
| 82 | EXPECT_FALSE(quick_code.empty()); |
| 83 | size_t code_size = quick_code.size() * sizeof(quick_code[0]); |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 84 | EXPECT_EQ(0, memcmp(quick_oat_code, &quick_code[0], code_size)) |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 85 | << method->PrettyMethod() << " " << code_size; |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 86 | CHECK_EQ(0, memcmp(quick_oat_code, &quick_code[0], code_size)); |
Logan Chien | eeb7edf | 2012-03-09 20:38:39 +0800 | [diff] [blame] | 87 | } |
| 88 | } |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 89 | |
| 90 | void SetupCompiler(Compiler::Kind compiler_kind, |
| 91 | InstructionSet insn_set, |
| 92 | const std::vector<std::string>& compiler_options, |
| 93 | /*out*/std::string* error_msg) { |
| 94 | ASSERT_TRUE(error_msg != nullptr); |
Andreas Gampe | 0415b4e | 2015-01-06 15:17:07 -0800 | [diff] [blame] | 95 | insn_features_ = InstructionSetFeatures::FromVariant(insn_set, "default", error_msg); |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 96 | ASSERT_TRUE(insn_features_ != nullptr) << error_msg; |
| 97 | compiler_options_.reset(new CompilerOptions); |
| 98 | for (const std::string& option : compiler_options) { |
| 99 | compiler_options_->ParseCompilerOption(option, Usage); |
| 100 | } |
| 101 | verification_results_.reset(new VerificationResults(compiler_options_.get())); |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 102 | callbacks_.reset(new QuickCompilerCallbacks(verification_results_.get(), |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 103 | CompilerCallbacks::CallbackMode::kCompileApp)); |
| 104 | Runtime::Current()->SetCompilerCallbacks(callbacks_.get()); |
| 105 | timer_.reset(new CumulativeLogger("Compilation times")); |
| 106 | compiler_driver_.reset(new CompilerDriver(compiler_options_.get(), |
| 107 | verification_results_.get(), |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 108 | compiler_kind, |
| 109 | insn_set, |
| 110 | insn_features_.get(), |
Vladimir Marko | 944da60 | 2016-02-19 12:27:55 +0000 | [diff] [blame] | 111 | /* image_classes */ nullptr, |
| 112 | /* compiled_classes */ nullptr, |
| 113 | /* compiled_methods */ nullptr, |
| 114 | /* thread_count */ 2, |
| 115 | /* dump_stats */ true, |
| 116 | /* dump_passes */ true, |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 117 | timer_.get(), |
Vladimir Marko | 944da60 | 2016-02-19 12:27:55 +0000 | [diff] [blame] | 118 | /* swap_fd */ -1, |
| 119 | /* profile_compilation_info */ nullptr)); |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 120 | } |
| 121 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 122 | bool WriteElf(File* vdex_file, |
| 123 | File* oat_file, |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 124 | const std::vector<const DexFile*>& dex_files, |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 125 | SafeMap<std::string, std::string>& key_value_store, |
| 126 | bool verify) { |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 127 | TimingLogger timings("WriteElf", false, false); |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 128 | OatWriter oat_writer(/*compiling_boot_image*/false, &timings); |
| 129 | for (const DexFile* dex_file : dex_files) { |
| 130 | ArrayRef<const uint8_t> raw_dex_file( |
| 131 | reinterpret_cast<const uint8_t*>(&dex_file->GetHeader()), |
| 132 | dex_file->GetHeader().file_size_); |
| 133 | if (!oat_writer.AddRawDexFileSource(raw_dex_file, |
| 134 | dex_file->GetLocation().c_str(), |
| 135 | dex_file->GetLocationChecksum())) { |
| 136 | return false; |
| 137 | } |
| 138 | } |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 139 | return DoWriteElf(vdex_file, oat_file, oat_writer, key_value_store, verify); |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 140 | } |
| 141 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 142 | bool WriteElf(File* vdex_file, |
| 143 | File* oat_file, |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 144 | const std::vector<const char*>& dex_filenames, |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 145 | SafeMap<std::string, std::string>& key_value_store, |
| 146 | bool verify) { |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 147 | TimingLogger timings("WriteElf", false, false); |
| 148 | OatWriter oat_writer(/*compiling_boot_image*/false, &timings); |
| 149 | for (const char* dex_filename : dex_filenames) { |
| 150 | if (!oat_writer.AddDexFileSource(dex_filename, dex_filename)) { |
| 151 | return false; |
| 152 | } |
| 153 | } |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 154 | return DoWriteElf(vdex_file, oat_file, oat_writer, key_value_store, verify); |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 155 | } |
| 156 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 157 | bool WriteElf(File* vdex_file, |
| 158 | File* oat_file, |
Andreas Gampe | 43e10b0 | 2016-07-15 17:17:34 -0700 | [diff] [blame] | 159 | File&& zip_fd, |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 160 | const char* location, |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 161 | SafeMap<std::string, std::string>& key_value_store, |
| 162 | bool verify) { |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 163 | TimingLogger timings("WriteElf", false, false); |
| 164 | OatWriter oat_writer(/*compiling_boot_image*/false, &timings); |
| 165 | if (!oat_writer.AddZippedDexFilesSource(std::move(zip_fd), location)) { |
| 166 | return false; |
| 167 | } |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 168 | return DoWriteElf(vdex_file, oat_file, oat_writer, key_value_store, verify); |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 169 | } |
| 170 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 171 | bool DoWriteElf(File* vdex_file, |
| 172 | File* oat_file, |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 173 | OatWriter& oat_writer, |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 174 | SafeMap<std::string, std::string>& key_value_store, |
| 175 | bool verify) { |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 176 | std::unique_ptr<ElfWriter> elf_writer = CreateElfWriterQuick( |
| 177 | compiler_driver_->GetInstructionSet(), |
David Srbecky | 5d81120 | 2016-03-08 13:21:22 +0000 | [diff] [blame] | 178 | compiler_driver_->GetInstructionSetFeatures(), |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 179 | &compiler_driver_->GetCompilerOptions(), |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 180 | oat_file); |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 181 | elf_writer->Start(); |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 182 | OutputStream* oat_rodata = elf_writer->StartRoData(); |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 183 | std::unique_ptr<MemMap> opened_dex_files_map; |
| 184 | std::vector<std::unique_ptr<const DexFile>> opened_dex_files; |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 185 | if (!oat_writer.WriteAndOpenDexFiles(kIsVdexEnabled ? vdex_file : oat_file, |
| 186 | oat_rodata, |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 187 | compiler_driver_->GetInstructionSet(), |
| 188 | compiler_driver_->GetInstructionSetFeatures(), |
| 189 | &key_value_store, |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 190 | verify, |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 191 | &opened_dex_files_map, |
| 192 | &opened_dex_files)) { |
| 193 | return false; |
| 194 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 195 | |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 196 | Runtime* runtime = Runtime::Current(); |
| 197 | ClassLinker* const class_linker = runtime->GetClassLinker(); |
| 198 | std::vector<const DexFile*> dex_files; |
| 199 | for (const std::unique_ptr<const DexFile>& dex_file : opened_dex_files) { |
| 200 | dex_files.push_back(dex_file.get()); |
| 201 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | f284d44 | 2016-06-02 11:48:30 -0700 | [diff] [blame] | 202 | class_linker->RegisterDexFile(*dex_file, nullptr); |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 203 | } |
Vladimir Marko | 944da60 | 2016-02-19 12:27:55 +0000 | [diff] [blame] | 204 | linker::MultiOatRelativePatcher patcher(compiler_driver_->GetInstructionSet(), |
| 205 | instruction_set_features_.get()); |
Nicolas Geoffray | 4acefd3 | 2016-10-24 13:14:58 +0100 | [diff] [blame] | 206 | oat_writer.Initialize(compiler_driver_.get(), nullptr, dex_files); |
| 207 | oat_writer.PrepareLayout(&patcher); |
Vladimir Marko | 944da60 | 2016-02-19 12:27:55 +0000 | [diff] [blame] | 208 | size_t rodata_size = oat_writer.GetOatHeader().GetExecutableOffset(); |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 209 | size_t text_size = oat_writer.GetOatSize() - rodata_size; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 210 | elf_writer->PrepareDynamicSection(rodata_size, |
| 211 | text_size, |
| 212 | oat_writer.GetBssSize(), |
| 213 | oat_writer.GetBssRootsOffset()); |
Vladimir Marko | 944da60 | 2016-02-19 12:27:55 +0000 | [diff] [blame] | 214 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 215 | if (!oat_writer.WriteRodata(oat_rodata)) { |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 216 | return false; |
| 217 | } |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 218 | elf_writer->EndRoData(oat_rodata); |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 219 | |
| 220 | OutputStream* text = elf_writer->StartText(); |
| 221 | if (!oat_writer.WriteCode(text)) { |
| 222 | return false; |
| 223 | } |
| 224 | elf_writer->EndText(text); |
| 225 | |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 226 | if (!oat_writer.WriteHeader(elf_writer->GetStream(), 42U, 4096U, 0)) { |
| 227 | return false; |
| 228 | } |
| 229 | |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 230 | elf_writer->WriteDynamicSection(); |
Vladimir Marko | 49b0f45 | 2015-12-10 13:49:19 +0000 | [diff] [blame] | 231 | elf_writer->WriteDebugInfo(oat_writer.GetMethodDebugInfo()); |
| 232 | elf_writer->WritePatchLocations(oat_writer.GetAbsolutePatchLocations()); |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 233 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 234 | if (!elf_writer->End()) { |
| 235 | return false; |
| 236 | } |
| 237 | |
| 238 | opened_dex_files_maps_.emplace_back(std::move(opened_dex_files_map)); |
| 239 | for (std::unique_ptr<const DexFile>& dex_file : opened_dex_files) { |
| 240 | opened_dex_files_.emplace_back(dex_file.release()); |
| 241 | } |
| 242 | return true; |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 243 | } |
| 244 | |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 245 | void TestDexFileInput(bool verify, bool low_4gb); |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 246 | void TestZipFileInput(bool verify); |
| 247 | |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 248 | std::unique_ptr<const InstructionSetFeatures> insn_features_; |
| 249 | std::unique_ptr<QuickCompilerCallbacks> callbacks_; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 250 | |
| 251 | std::vector<std::unique_ptr<MemMap>> opened_dex_files_maps_; |
| 252 | std::vector<std::unique_ptr<const DexFile>> opened_dex_files_; |
Logan Chien | eeb7edf | 2012-03-09 20:38:39 +0800 | [diff] [blame] | 253 | }; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 254 | |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 255 | class ZipBuilder { |
| 256 | public: |
| 257 | explicit ZipBuilder(File* zip_file) : zip_file_(zip_file) { } |
| 258 | |
| 259 | bool AddFile(const char* location, const void* data, size_t size) { |
| 260 | off_t offset = lseek(zip_file_->Fd(), 0, SEEK_CUR); |
| 261 | if (offset == static_cast<off_t>(-1)) { |
| 262 | return false; |
| 263 | } |
| 264 | |
| 265 | ZipFileHeader file_header; |
| 266 | file_header.crc32 = crc32(0u, reinterpret_cast<const Bytef*>(data), size); |
| 267 | file_header.compressed_size = size; |
| 268 | file_header.uncompressed_size = size; |
| 269 | file_header.filename_length = strlen(location); |
| 270 | |
| 271 | if (!zip_file_->WriteFully(&file_header, sizeof(file_header)) || |
| 272 | !zip_file_->WriteFully(location, file_header.filename_length) || |
| 273 | !zip_file_->WriteFully(data, size)) { |
| 274 | return false; |
| 275 | } |
| 276 | |
| 277 | CentralDirectoryFileHeader cdfh; |
| 278 | cdfh.crc32 = file_header.crc32; |
| 279 | cdfh.compressed_size = size; |
| 280 | cdfh.uncompressed_size = size; |
| 281 | cdfh.filename_length = file_header.filename_length; |
| 282 | cdfh.relative_offset_of_local_file_header = offset; |
| 283 | file_data_.push_back(FileData { cdfh, location }); |
| 284 | return true; |
| 285 | } |
| 286 | |
| 287 | bool Finish() { |
| 288 | off_t offset = lseek(zip_file_->Fd(), 0, SEEK_CUR); |
| 289 | if (offset == static_cast<off_t>(-1)) { |
| 290 | return false; |
| 291 | } |
| 292 | |
| 293 | size_t central_directory_size = 0u; |
| 294 | for (const FileData& file_data : file_data_) { |
| 295 | if (!zip_file_->WriteFully(&file_data.cdfh, sizeof(file_data.cdfh)) || |
| 296 | !zip_file_->WriteFully(file_data.location, file_data.cdfh.filename_length)) { |
| 297 | return false; |
| 298 | } |
| 299 | central_directory_size += sizeof(file_data.cdfh) + file_data.cdfh.filename_length; |
| 300 | } |
| 301 | EndOfCentralDirectoryRecord eocd_record; |
| 302 | eocd_record.number_of_central_directory_records_on_this_disk = file_data_.size(); |
| 303 | eocd_record.total_number_of_central_directory_records = file_data_.size(); |
| 304 | eocd_record.size_of_central_directory = central_directory_size; |
| 305 | eocd_record.offset_of_start_of_central_directory = offset; |
| 306 | return |
| 307 | zip_file_->WriteFully(&eocd_record, sizeof(eocd_record)) && |
| 308 | zip_file_->Flush() == 0; |
| 309 | } |
| 310 | |
| 311 | private: |
| 312 | struct PACKED(1) ZipFileHeader { |
| 313 | uint32_t signature = 0x04034b50; |
| 314 | uint16_t version_needed_to_extract = 10; |
| 315 | uint16_t general_purpose_bit_flag = 0; |
| 316 | uint16_t compression_method = 0; // 0 = store only. |
| 317 | uint16_t file_last_modification_time = 0u; |
| 318 | uint16_t file_last_modification_date = 0u; |
| 319 | uint32_t crc32; |
| 320 | uint32_t compressed_size; |
| 321 | uint32_t uncompressed_size; |
| 322 | uint16_t filename_length; |
| 323 | uint16_t extra_field_length = 0u; // No extra fields. |
| 324 | }; |
| 325 | |
| 326 | struct PACKED(1) CentralDirectoryFileHeader { |
| 327 | uint32_t signature = 0x02014b50; |
| 328 | uint16_t version_made_by = 10; |
| 329 | uint16_t version_needed_to_extract = 10; |
| 330 | uint16_t general_purpose_bit_flag = 0; |
| 331 | uint16_t compression_method = 0; // 0 = store only. |
| 332 | uint16_t file_last_modification_time = 0u; |
| 333 | uint16_t file_last_modification_date = 0u; |
| 334 | uint32_t crc32; |
| 335 | uint32_t compressed_size; |
| 336 | uint32_t uncompressed_size; |
| 337 | uint16_t filename_length; |
| 338 | uint16_t extra_field_length = 0u; // No extra fields. |
| 339 | uint16_t file_comment_length = 0u; // No file comment. |
| 340 | uint16_t disk_number_where_file_starts = 0u; |
| 341 | uint16_t internal_file_attributes = 0u; |
| 342 | uint32_t external_file_attributes = 0u; |
| 343 | uint32_t relative_offset_of_local_file_header; |
| 344 | }; |
| 345 | |
| 346 | struct PACKED(1) EndOfCentralDirectoryRecord { |
| 347 | uint32_t signature = 0x06054b50; |
| 348 | uint16_t number_of_this_disk = 0u; |
| 349 | uint16_t disk_where_central_directory_starts = 0u; |
| 350 | uint16_t number_of_central_directory_records_on_this_disk; |
| 351 | uint16_t total_number_of_central_directory_records; |
| 352 | uint32_t size_of_central_directory; |
| 353 | uint32_t offset_of_start_of_central_directory; |
| 354 | uint16_t comment_length = 0u; // No file comment. |
| 355 | }; |
| 356 | |
| 357 | struct FileData { |
| 358 | CentralDirectoryFileHeader cdfh; |
| 359 | const char* location; |
| 360 | }; |
| 361 | |
| 362 | File* zip_file_; |
| 363 | std::vector<FileData> file_data_; |
| 364 | }; |
| 365 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 366 | TEST_F(OatTest, WriteRead) { |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 367 | TimingLogger timings("OatTest::WriteRead", false, false); |
Jesse Wilson | 254db0f | 2011-11-16 16:44:11 -0500 | [diff] [blame] | 368 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 369 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 370 | // TODO: make selectable. |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 371 | Compiler::Kind compiler_kind = Compiler::kQuick; |
Ian Rogers | a073c67 | 2013-07-30 17:43:55 -0700 | [diff] [blame] | 372 | InstructionSet insn_set = kIsTargetBuild ? kThumb2 : kX86; |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 373 | std::string error_msg; |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 374 | SetupCompiler(compiler_kind, insn_set, std::vector<std::string>(), /*out*/ &error_msg); |
| 375 | |
Ian Rogers | d4c4d95 | 2014-10-16 20:31:53 -0700 | [diff] [blame] | 376 | jobject class_loader = nullptr; |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 377 | if (kCompile) { |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 378 | TimingLogger timings2("OatTest::WriteRead", false, false); |
Vladimir Marko | d1eaf0d | 2015-10-29 12:18:29 +0000 | [diff] [blame] | 379 | compiler_driver_->SetDexFilesForOatFile(class_linker->GetBootClassPath()); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 380 | compiler_driver_->CompileAll( |
| 381 | class_loader, class_linker->GetBootClassPath(), /* verifier_deps */ nullptr, &timings2); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 382 | } |
| 383 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 384 | ScratchFile tmp_oat, tmp_vdex(tmp_oat, ".vdex"); |
Andreas Gampe | 22f8e5c | 2014-07-09 11:38:21 -0700 | [diff] [blame] | 385 | SafeMap<std::string, std::string> key_value_store; |
| 386 | key_value_store.Put(OatHeader::kImageLocationKey, "lue.art"); |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 387 | bool success = WriteElf(tmp_vdex.GetFile(), |
| 388 | tmp_oat.GetFile(), |
| 389 | class_linker->GetBootClassPath(), |
| 390 | key_value_store, |
| 391 | false); |
Brian Carlstrom | c50d8e1 | 2013-07-23 22:35:16 -0700 | [diff] [blame] | 392 | ASSERT_TRUE(success); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 393 | |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 394 | if (kCompile) { // OatWriter strips the code, regenerate to compare |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 395 | compiler_driver_->CompileAll( |
| 396 | class_loader, class_linker->GetBootClassPath(), /* verifier_deps */ nullptr, &timings); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 397 | } |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 398 | std::unique_ptr<OatFile> oat_file(OatFile::Open(tmp_oat.GetFilename(), |
| 399 | tmp_oat.GetFilename(), |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 400 | nullptr, |
| 401 | nullptr, |
| 402 | false, |
| 403 | /*low_4gb*/true, |
| 404 | nullptr, |
| 405 | &error_msg)); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 406 | ASSERT_TRUE(oat_file.get() != nullptr) << error_msg; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 407 | const OatHeader& oat_header = oat_file->GetOatHeader(); |
Brian Carlstrom | f852fb2 | 2012-10-19 11:01:58 -0700 | [diff] [blame] | 408 | ASSERT_TRUE(oat_header.IsValid()); |
Yi Kong | 9515b51 | 2015-11-11 14:36:07 +0000 | [diff] [blame] | 409 | ASSERT_EQ(class_linker->GetBootClassPath().size(), oat_header.GetDexFileCount()); // core |
Brian Carlstrom | 28db012 | 2012-10-18 16:20:41 -0700 | [diff] [blame] | 410 | ASSERT_EQ(42U, oat_header.GetImageFileLocationOatChecksum()); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 411 | ASSERT_EQ(4096U, oat_header.GetImageFileLocationOatDataBegin()); |
Andreas Gampe | 22f8e5c | 2014-07-09 11:38:21 -0700 | [diff] [blame] | 412 | ASSERT_EQ("lue.art", std::string(oat_header.GetStoreValueByKey(OatHeader::kImageLocationKey))); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 413 | |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 414 | ASSERT_TRUE(java_lang_dex_file_ != nullptr); |
| 415 | const DexFile& dex_file = *java_lang_dex_file_; |
| 416 | uint32_t dex_file_checksum = dex_file.GetLocationChecksum(); |
| 417 | const OatFile::OatDexFile* oat_dex_file = oat_file->GetOatDexFile(dex_file.GetLocation().c_str(), |
Brian Carlstrom | 756ee4e | 2013-10-03 15:46:12 -0700 | [diff] [blame] | 418 | &dex_file_checksum); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 419 | ASSERT_TRUE(oat_dex_file != nullptr); |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 420 | CHECK_EQ(dex_file.GetLocationChecksum(), oat_dex_file->GetDexFileLocationChecksum()); |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 421 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 422 | auto pointer_size = class_linker->GetImagePointerSize(); |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 423 | for (size_t i = 0; i < dex_file.NumClassDefs(); i++) { |
| 424 | const DexFile::ClassDef& class_def = dex_file.GetClassDef(i); |
| 425 | const uint8_t* class_data = dex_file.GetClassData(class_def); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 426 | |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 427 | size_t num_virtual_methods = 0; |
Ian Rogers | d4c4d95 | 2014-10-16 20:31:53 -0700 | [diff] [blame] | 428 | if (class_data != nullptr) { |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 429 | ClassDataItemIterator it(dex_file, class_data); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 430 | num_virtual_methods = it.NumVirtualMethods(); |
| 431 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 432 | |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 433 | const char* descriptor = dex_file.GetClassDescriptor(class_def); |
Mathieu Chartier | 9865bde | 2015-12-21 09:58:16 -0800 | [diff] [blame] | 434 | mirror::Class* klass = class_linker->FindClass(soa.Self(), |
| 435 | descriptor, |
| 436 | ScopedNullHandle<mirror::ClassLoader>()); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 437 | |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 438 | const OatFile::OatClass oat_class = oat_dex_file->GetOatClass(i); |
| 439 | CHECK_EQ(mirror::Class::Status::kStatusNotReady, oat_class.GetStatus()) << descriptor; |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 440 | CHECK_EQ(kCompile ? OatClassType::kOatClassAllCompiled : OatClassType::kOatClassNoneCompiled, |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 441 | oat_class.GetType()) << descriptor; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 442 | |
| 443 | size_t method_index = 0; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 444 | for (auto& m : klass->GetDirectMethods(pointer_size)) { |
| 445 | CheckMethod(&m, oat_class.GetOatMethod(method_index), dex_file); |
| 446 | ++method_index; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 447 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 448 | size_t visited_virtuals = 0; |
Alex Light | e64300b | 2015-12-15 15:02:47 -0800 | [diff] [blame] | 449 | // TODO We should also check copied methods in this test. |
| 450 | for (auto& m : klass->GetDeclaredVirtualMethods(pointer_size)) { |
Alex Light | fcea56f | 2016-02-17 11:59:05 -0800 | [diff] [blame] | 451 | if (!klass->IsInterface()) { |
Alex Light | 3612149 | 2016-02-22 13:43:29 -0800 | [diff] [blame] | 452 | EXPECT_FALSE(m.IsCopied()); |
Alex Light | fcea56f | 2016-02-17 11:59:05 -0800 | [diff] [blame] | 453 | } |
Alex Light | e64300b | 2015-12-15 15:02:47 -0800 | [diff] [blame] | 454 | CheckMethod(&m, oat_class.GetOatMethod(method_index), dex_file); |
| 455 | ++method_index; |
| 456 | ++visited_virtuals; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 457 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 458 | EXPECT_EQ(visited_virtuals, num_virtual_methods); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
Brian Carlstrom | 341df94 | 2012-06-27 12:29:22 -0700 | [diff] [blame] | 462 | TEST_F(OatTest, OatHeaderSizeCheck) { |
| 463 | // If this test is failing and you have to update these constants, |
| 464 | // it is time to update OatHeader::kOatVersion |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 465 | EXPECT_EQ(72U, sizeof(OatHeader)); |
Mathieu Chartier | 957ca1c | 2014-11-21 16:51:29 -0800 | [diff] [blame] | 466 | EXPECT_EQ(4U, sizeof(OatMethodOffsets)); |
Vladimir Marko | 9d07e3d | 2016-03-31 12:02:28 +0100 | [diff] [blame] | 467 | EXPECT_EQ(20U, sizeof(OatQuickMethodHeader)); |
Igor Murashkin | af1e299 | 2016-10-12 17:44:50 -0700 | [diff] [blame] | 468 | EXPECT_EQ(164 * static_cast<size_t>(GetInstructionSetPointerSize(kRuntimeISA)), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 469 | sizeof(QuickEntryPoints)); |
Brian Carlstrom | 341df94 | 2012-06-27 12:29:22 -0700 | [diff] [blame] | 470 | } |
| 471 | |
Brian Carlstrom | f852fb2 | 2012-10-19 11:01:58 -0700 | [diff] [blame] | 472 | TEST_F(OatTest, OatHeaderIsValid) { |
Jeff Hao | 5d3baf6 | 2016-05-23 19:17:04 -0700 | [diff] [blame] | 473 | InstructionSet insn_set = kX86; |
| 474 | std::string error_msg; |
| 475 | std::unique_ptr<const InstructionSetFeatures> insn_features( |
| 476 | InstructionSetFeatures::FromVariant(insn_set, "default", &error_msg)); |
| 477 | ASSERT_TRUE(insn_features.get() != nullptr) << error_msg; |
| 478 | std::unique_ptr<OatHeader> oat_header(OatHeader::Create(insn_set, |
| 479 | insn_features.get(), |
| 480 | 0u, |
| 481 | nullptr)); |
| 482 | ASSERT_NE(oat_header.get(), nullptr); |
| 483 | ASSERT_TRUE(oat_header->IsValid()); |
Brian Carlstrom | f852fb2 | 2012-10-19 11:01:58 -0700 | [diff] [blame] | 484 | |
Jeff Hao | 5d3baf6 | 2016-05-23 19:17:04 -0700 | [diff] [blame] | 485 | char* magic = const_cast<char*>(oat_header->GetMagic()); |
| 486 | strcpy(magic, ""); // bad magic |
| 487 | ASSERT_FALSE(oat_header->IsValid()); |
| 488 | strcpy(magic, "oat\n000"); // bad version |
| 489 | ASSERT_FALSE(oat_header->IsValid()); |
Brian Carlstrom | f852fb2 | 2012-10-19 11:01:58 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 492 | TEST_F(OatTest, EmptyTextSection) { |
| 493 | TimingLogger timings("OatTest::EmptyTextSection", false, false); |
| 494 | |
| 495 | // TODO: make selectable. |
| 496 | Compiler::Kind compiler_kind = Compiler::kQuick; |
| 497 | InstructionSet insn_set = kRuntimeISA; |
| 498 | if (insn_set == kArm) insn_set = kThumb2; |
| 499 | std::string error_msg; |
| 500 | std::vector<std::string> compiler_options; |
| 501 | compiler_options.push_back("--compiler-filter=verify-at-runtime"); |
| 502 | SetupCompiler(compiler_kind, insn_set, compiler_options, /*out*/ &error_msg); |
| 503 | |
| 504 | jobject class_loader; |
| 505 | { |
| 506 | ScopedObjectAccess soa(Thread::Current()); |
| 507 | class_loader = LoadDex("Main"); |
| 508 | } |
| 509 | ASSERT_TRUE(class_loader != nullptr); |
| 510 | std::vector<const DexFile*> dex_files = GetDexFiles(class_loader); |
| 511 | ASSERT_TRUE(!dex_files.empty()); |
| 512 | |
| 513 | ClassLinker* const class_linker = Runtime::Current()->GetClassLinker(); |
| 514 | for (const DexFile* dex_file : dex_files) { |
| 515 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 516 | class_linker->RegisterDexFile(*dex_file, |
Mathieu Chartier | 1cc62e4 | 2016-10-03 18:01:28 -0700 | [diff] [blame] | 517 | soa.Decode<mirror::ClassLoader>(class_loader).Ptr()); |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 518 | } |
| 519 | compiler_driver_->SetDexFilesForOatFile(dex_files); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 520 | compiler_driver_->CompileAll(class_loader, dex_files, /* verifier_deps */ nullptr, &timings); |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 521 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 522 | ScratchFile tmp_oat, tmp_vdex(tmp_oat, ".vdex"); |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 523 | SafeMap<std::string, std::string> key_value_store; |
| 524 | key_value_store.Put(OatHeader::kImageLocationKey, "test.art"); |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 525 | bool success = WriteElf(tmp_vdex.GetFile(), tmp_oat.GetFile(), dex_files, key_value_store, false); |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 526 | ASSERT_TRUE(success); |
| 527 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 528 | std::unique_ptr<OatFile> oat_file(OatFile::Open(tmp_oat.GetFilename(), |
| 529 | tmp_oat.GetFilename(), |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 530 | nullptr, |
| 531 | nullptr, |
| 532 | false, |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 533 | /*low_4gb*/false, |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 534 | nullptr, |
| 535 | &error_msg)); |
| 536 | ASSERT_TRUE(oat_file != nullptr); |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 537 | EXPECT_LT(static_cast<size_t>(oat_file->Size()), |
| 538 | static_cast<size_t>(tmp_oat.GetFile()->GetLength())); |
Mathieu Chartier | 07ddb6f | 2015-11-05 11:16:34 -0800 | [diff] [blame] | 539 | } |
| 540 | |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 541 | static void MaybeModifyDexFileToFail(bool verify, std::unique_ptr<const DexFile>& data) { |
| 542 | // If in verify mode (= fail the verifier mode), make sure we fail early. We'll fail already |
| 543 | // because of the missing map, but that may lead to out of bounds reads. |
| 544 | if (verify) { |
| 545 | const_cast<DexFile::Header*>(&data->GetHeader())->checksum_++; |
| 546 | } |
| 547 | } |
| 548 | |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 549 | void OatTest::TestDexFileInput(bool verify, bool low_4gb) { |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 550 | TimingLogger timings("OatTest::DexFileInput", false, false); |
| 551 | |
| 552 | std::vector<const char*> input_filenames; |
| 553 | |
| 554 | ScratchFile dex_file1; |
| 555 | TestDexFileBuilder builder1; |
| 556 | builder1.AddField("Lsome.TestClass;", "int", "someField"); |
| 557 | builder1.AddMethod("Lsome.TestClass;", "()I", "foo"); |
| 558 | std::unique_ptr<const DexFile> dex_file1_data = builder1.Build(dex_file1.GetFilename()); |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 559 | |
| 560 | MaybeModifyDexFileToFail(verify, dex_file1_data); |
| 561 | |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 562 | bool success = dex_file1.GetFile()->WriteFully(&dex_file1_data->GetHeader(), |
| 563 | dex_file1_data->GetHeader().file_size_); |
| 564 | ASSERT_TRUE(success); |
| 565 | success = dex_file1.GetFile()->Flush() == 0; |
| 566 | ASSERT_TRUE(success); |
| 567 | input_filenames.push_back(dex_file1.GetFilename().c_str()); |
| 568 | |
| 569 | ScratchFile dex_file2; |
| 570 | TestDexFileBuilder builder2; |
| 571 | builder2.AddField("Land.AnotherTestClass;", "boolean", "someOtherField"); |
| 572 | builder2.AddMethod("Land.AnotherTestClass;", "()J", "bar"); |
| 573 | std::unique_ptr<const DexFile> dex_file2_data = builder2.Build(dex_file2.GetFilename()); |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 574 | |
| 575 | MaybeModifyDexFileToFail(verify, dex_file2_data); |
| 576 | |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 577 | success = dex_file2.GetFile()->WriteFully(&dex_file2_data->GetHeader(), |
| 578 | dex_file2_data->GetHeader().file_size_); |
| 579 | ASSERT_TRUE(success); |
| 580 | success = dex_file2.GetFile()->Flush() == 0; |
| 581 | ASSERT_TRUE(success); |
| 582 | input_filenames.push_back(dex_file2.GetFilename().c_str()); |
| 583 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 584 | ScratchFile oat_file, vdex_file(oat_file, ".vdex"); |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 585 | SafeMap<std::string, std::string> key_value_store; |
| 586 | key_value_store.Put(OatHeader::kImageLocationKey, "test.art"); |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 587 | success = WriteElf(vdex_file.GetFile(), |
| 588 | oat_file.GetFile(), |
| 589 | input_filenames, |
| 590 | key_value_store, |
| 591 | verify); |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 592 | |
| 593 | // In verify mode, we expect failure. |
| 594 | if (verify) { |
| 595 | ASSERT_FALSE(success); |
| 596 | return; |
| 597 | } |
| 598 | |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 599 | ASSERT_TRUE(success); |
| 600 | |
| 601 | std::string error_msg; |
| 602 | std::unique_ptr<OatFile> opened_oat_file(OatFile::Open(oat_file.GetFilename(), |
| 603 | oat_file.GetFilename(), |
| 604 | nullptr, |
| 605 | nullptr, |
| 606 | false, |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 607 | low_4gb, |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 608 | nullptr, |
| 609 | &error_msg)); |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 610 | if (low_4gb) { |
| 611 | uintptr_t begin = reinterpret_cast<uintptr_t>(opened_oat_file->Begin()); |
| 612 | EXPECT_EQ(begin, static_cast<uint32_t>(begin)); |
| 613 | } |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 614 | ASSERT_TRUE(opened_oat_file != nullptr); |
| 615 | ASSERT_EQ(2u, opened_oat_file->GetOatDexFiles().size()); |
| 616 | std::unique_ptr<const DexFile> opened_dex_file1 = |
| 617 | opened_oat_file->GetOatDexFiles()[0]->OpenDexFile(&error_msg); |
| 618 | std::unique_ptr<const DexFile> opened_dex_file2 = |
| 619 | opened_oat_file->GetOatDexFiles()[1]->OpenDexFile(&error_msg); |
| 620 | |
| 621 | ASSERT_EQ(dex_file1_data->GetHeader().file_size_, opened_dex_file1->GetHeader().file_size_); |
| 622 | ASSERT_EQ(0, memcmp(&dex_file1_data->GetHeader(), |
| 623 | &opened_dex_file1->GetHeader(), |
| 624 | dex_file1_data->GetHeader().file_size_)); |
| 625 | ASSERT_EQ(dex_file1_data->GetLocation(), opened_dex_file1->GetLocation()); |
| 626 | |
| 627 | ASSERT_EQ(dex_file2_data->GetHeader().file_size_, opened_dex_file2->GetHeader().file_size_); |
| 628 | ASSERT_EQ(0, memcmp(&dex_file2_data->GetHeader(), |
| 629 | &opened_dex_file2->GetHeader(), |
| 630 | dex_file2_data->GetHeader().file_size_)); |
| 631 | ASSERT_EQ(dex_file2_data->GetLocation(), opened_dex_file2->GetLocation()); |
| 632 | } |
| 633 | |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 634 | TEST_F(OatTest, DexFileInputCheckOutput) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 635 | TestDexFileInput(false, /*low_4gb*/false); |
| 636 | } |
| 637 | |
| 638 | TEST_F(OatTest, DexFileInputCheckOutputLow4GB) { |
| 639 | TestDexFileInput(false, /*low_4gb*/true); |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | TEST_F(OatTest, DexFileInputCheckVerifier) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 643 | TestDexFileInput(true, /*low_4gb*/false); |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | void OatTest::TestZipFileInput(bool verify) { |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 647 | TimingLogger timings("OatTest::DexFileInput", false, false); |
| 648 | |
| 649 | ScratchFile zip_file; |
| 650 | ZipBuilder zip_builder(zip_file.GetFile()); |
| 651 | |
| 652 | ScratchFile dex_file1; |
| 653 | TestDexFileBuilder builder1; |
| 654 | builder1.AddField("Lsome.TestClass;", "long", "someField"); |
| 655 | builder1.AddMethod("Lsome.TestClass;", "()D", "foo"); |
| 656 | std::unique_ptr<const DexFile> dex_file1_data = builder1.Build(dex_file1.GetFilename()); |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 657 | |
| 658 | MaybeModifyDexFileToFail(verify, dex_file1_data); |
| 659 | |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 660 | bool success = dex_file1.GetFile()->WriteFully(&dex_file1_data->GetHeader(), |
| 661 | dex_file1_data->GetHeader().file_size_); |
| 662 | ASSERT_TRUE(success); |
| 663 | success = dex_file1.GetFile()->Flush() == 0; |
| 664 | ASSERT_TRUE(success); |
| 665 | success = zip_builder.AddFile("classes.dex", |
| 666 | &dex_file1_data->GetHeader(), |
| 667 | dex_file1_data->GetHeader().file_size_); |
| 668 | ASSERT_TRUE(success); |
| 669 | |
| 670 | ScratchFile dex_file2; |
| 671 | TestDexFileBuilder builder2; |
| 672 | builder2.AddField("Land.AnotherTestClass;", "boolean", "someOtherField"); |
| 673 | builder2.AddMethod("Land.AnotherTestClass;", "()J", "bar"); |
| 674 | std::unique_ptr<const DexFile> dex_file2_data = builder2.Build(dex_file2.GetFilename()); |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 675 | |
| 676 | MaybeModifyDexFileToFail(verify, dex_file2_data); |
| 677 | |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 678 | success = dex_file2.GetFile()->WriteFully(&dex_file2_data->GetHeader(), |
| 679 | dex_file2_data->GetHeader().file_size_); |
| 680 | ASSERT_TRUE(success); |
| 681 | success = dex_file2.GetFile()->Flush() == 0; |
| 682 | ASSERT_TRUE(success); |
| 683 | success = zip_builder.AddFile("classes2.dex", |
| 684 | &dex_file2_data->GetHeader(), |
| 685 | dex_file2_data->GetHeader().file_size_); |
| 686 | ASSERT_TRUE(success); |
| 687 | |
| 688 | success = zip_builder.Finish(); |
| 689 | ASSERT_TRUE(success) << strerror(errno); |
| 690 | |
| 691 | SafeMap<std::string, std::string> key_value_store; |
| 692 | key_value_store.Put(OatHeader::kImageLocationKey, "test.art"); |
| 693 | { |
| 694 | // Test using the AddDexFileSource() interface with the zip file. |
| 695 | std::vector<const char*> input_filenames { zip_file.GetFilename().c_str() }; // NOLINT [readability/braces] [4] |
| 696 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 697 | ScratchFile oat_file, vdex_file(oat_file, ".vdex"); |
| 698 | success = WriteElf(vdex_file.GetFile(), oat_file.GetFile(), |
| 699 | input_filenames, key_value_store, verify); |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 700 | |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 701 | if (verify) { |
| 702 | ASSERT_FALSE(success); |
| 703 | } else { |
| 704 | ASSERT_TRUE(success); |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 705 | |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 706 | std::string error_msg; |
| 707 | std::unique_ptr<OatFile> opened_oat_file(OatFile::Open(oat_file.GetFilename(), |
| 708 | oat_file.GetFilename(), |
| 709 | nullptr, |
| 710 | nullptr, |
| 711 | false, |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 712 | /*low_4gb*/false, |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 713 | nullptr, |
| 714 | &error_msg)); |
| 715 | ASSERT_TRUE(opened_oat_file != nullptr); |
| 716 | ASSERT_EQ(2u, opened_oat_file->GetOatDexFiles().size()); |
| 717 | std::unique_ptr<const DexFile> opened_dex_file1 = |
| 718 | opened_oat_file->GetOatDexFiles()[0]->OpenDexFile(&error_msg); |
| 719 | std::unique_ptr<const DexFile> opened_dex_file2 = |
| 720 | opened_oat_file->GetOatDexFiles()[1]->OpenDexFile(&error_msg); |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 721 | |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 722 | ASSERT_EQ(dex_file1_data->GetHeader().file_size_, opened_dex_file1->GetHeader().file_size_); |
| 723 | ASSERT_EQ(0, memcmp(&dex_file1_data->GetHeader(), |
| 724 | &opened_dex_file1->GetHeader(), |
| 725 | dex_file1_data->GetHeader().file_size_)); |
| 726 | ASSERT_EQ(DexFile::GetMultiDexLocation(0, zip_file.GetFilename().c_str()), |
| 727 | opened_dex_file1->GetLocation()); |
| 728 | |
| 729 | ASSERT_EQ(dex_file2_data->GetHeader().file_size_, opened_dex_file2->GetHeader().file_size_); |
| 730 | ASSERT_EQ(0, memcmp(&dex_file2_data->GetHeader(), |
| 731 | &opened_dex_file2->GetHeader(), |
| 732 | dex_file2_data->GetHeader().file_size_)); |
| 733 | ASSERT_EQ(DexFile::GetMultiDexLocation(1, zip_file.GetFilename().c_str()), |
| 734 | opened_dex_file2->GetLocation()); |
| 735 | } |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | { |
| 739 | // Test using the AddZipDexFileSource() interface with the zip file handle. |
Andreas Gampe | 43e10b0 | 2016-07-15 17:17:34 -0700 | [diff] [blame] | 740 | File zip_fd(dup(zip_file.GetFd()), /* check_usage */ false); |
| 741 | ASSERT_NE(-1, zip_fd.Fd()); |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 742 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 743 | ScratchFile oat_file, vdex_file(oat_file, ".vdex"); |
| 744 | success = WriteElf(vdex_file.GetFile(), |
| 745 | oat_file.GetFile(), |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 746 | std::move(zip_fd), |
| 747 | zip_file.GetFilename().c_str(), |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 748 | key_value_store, |
| 749 | verify); |
| 750 | if (verify) { |
| 751 | ASSERT_FALSE(success); |
| 752 | } else { |
| 753 | ASSERT_TRUE(success); |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 754 | |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 755 | std::string error_msg; |
| 756 | std::unique_ptr<OatFile> opened_oat_file(OatFile::Open(oat_file.GetFilename(), |
| 757 | oat_file.GetFilename(), |
| 758 | nullptr, |
| 759 | nullptr, |
| 760 | false, |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 761 | /*low_4gb*/false, |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 762 | nullptr, |
| 763 | &error_msg)); |
| 764 | ASSERT_TRUE(opened_oat_file != nullptr); |
| 765 | ASSERT_EQ(2u, opened_oat_file->GetOatDexFiles().size()); |
| 766 | std::unique_ptr<const DexFile> opened_dex_file1 = |
| 767 | opened_oat_file->GetOatDexFiles()[0]->OpenDexFile(&error_msg); |
| 768 | std::unique_ptr<const DexFile> opened_dex_file2 = |
| 769 | opened_oat_file->GetOatDexFiles()[1]->OpenDexFile(&error_msg); |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 770 | |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 771 | ASSERT_EQ(dex_file1_data->GetHeader().file_size_, opened_dex_file1->GetHeader().file_size_); |
| 772 | ASSERT_EQ(0, memcmp(&dex_file1_data->GetHeader(), |
| 773 | &opened_dex_file1->GetHeader(), |
| 774 | dex_file1_data->GetHeader().file_size_)); |
| 775 | ASSERT_EQ(DexFile::GetMultiDexLocation(0, zip_file.GetFilename().c_str()), |
| 776 | opened_dex_file1->GetLocation()); |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 777 | |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 778 | ASSERT_EQ(dex_file2_data->GetHeader().file_size_, opened_dex_file2->GetHeader().file_size_); |
| 779 | ASSERT_EQ(0, memcmp(&dex_file2_data->GetHeader(), |
| 780 | &opened_dex_file2->GetHeader(), |
| 781 | dex_file2_data->GetHeader().file_size_)); |
| 782 | ASSERT_EQ(DexFile::GetMultiDexLocation(1, zip_file.GetFilename().c_str()), |
| 783 | opened_dex_file2->GetLocation()); |
| 784 | } |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 785 | } |
| 786 | } |
| 787 | |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 788 | TEST_F(OatTest, ZipFileInputCheckOutput) { |
| 789 | TestZipFileInput(false); |
| 790 | } |
| 791 | |
| 792 | TEST_F(OatTest, ZipFileInputCheckVerifier) { |
| 793 | TestZipFileInput(true); |
| 794 | } |
| 795 | |
Jeff Hao | 5d3baf6 | 2016-05-23 19:17:04 -0700 | [diff] [blame] | 796 | TEST_F(OatTest, UpdateChecksum) { |
| 797 | InstructionSet insn_set = kX86; |
| 798 | std::string error_msg; |
| 799 | std::unique_ptr<const InstructionSetFeatures> insn_features( |
| 800 | InstructionSetFeatures::FromVariant(insn_set, "default", &error_msg)); |
| 801 | ASSERT_TRUE(insn_features.get() != nullptr) << error_msg; |
| 802 | std::unique_ptr<OatHeader> oat_header(OatHeader::Create(insn_set, |
| 803 | insn_features.get(), |
| 804 | 0u, |
| 805 | nullptr)); |
| 806 | // The starting adler32 value is 1. |
| 807 | EXPECT_EQ(1U, oat_header->GetChecksum()); |
| 808 | |
| 809 | oat_header->UpdateChecksum(OatHeader::kOatMagic, sizeof(OatHeader::kOatMagic)); |
| 810 | EXPECT_EQ(64291151U, oat_header->GetChecksum()); |
| 811 | |
| 812 | // Make sure that null data does not reset the checksum. |
| 813 | oat_header->UpdateChecksum(nullptr, 0); |
| 814 | EXPECT_EQ(64291151U, oat_header->GetChecksum()); |
| 815 | |
| 816 | oat_header->UpdateChecksum(OatHeader::kOatMagic, sizeof(OatHeader::kOatMagic)); |
| 817 | EXPECT_EQ(216138397U, oat_header->GetChecksum()); |
| 818 | } |
| 819 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 820 | } // namespace art |