blob: 5763cec43f945260a82c1c94970b5bd81db0da52 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 Carlstromdb4d5402011-08-09 12:18:28 -070016
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080017#include "image.h"
18
Ian Rogers700a4022014-05-19 16:49:03 -070019#include <memory>
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070020#include <string>
21#include <vector>
22
Ian Rogerse63db272014-07-15 15:36:11 -070023#include "base/unix_file/fd_file.h"
Vladimir Marko3481ba22015-04-13 12:22:36 +010024#include "class_linker-inl.h"
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080025#include "common_compiler_test.h"
David Srbecky4fda4eb2016-02-05 13:34:46 +000026#include "debug/method_debug_info.h"
Tong Shen62d1ca32014-09-03 17:24:56 -070027#include "elf_writer.h"
Vladimir Marko10c13562015-11-25 14:33:36 +000028#include "elf_writer_quick.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070029#include "gc/space/image_space.h"
Ian Rogerse63db272014-07-15 15:36:11 -070030#include "image_writer.h"
Vladimir Marko944da602016-02-19 12:27:55 +000031#include "linker/multi_oat_relative_patcher.h"
Ian Rogersd9c4fc92013-10-01 19:45:43 -070032#include "lock_word.h"
33#include "mirror/object-inl.h"
Ian Rogerse63db272014-07-15 15:36:11 -070034#include "oat_writer.h"
35#include "scoped_thread_state_change.h"
Brian Carlstrom51c24672013-07-11 16:00:56 -070036#include "signal_catcher.h"
buzbeec143c552011-08-20 17:38:58 -070037#include "utils.h"
Brian Carlstromdb4d5402011-08-09 12:18:28 -070038
Brian Carlstromdb4d5402011-08-09 12:18:28 -070039namespace art {
40
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080041class ImageTest : public CommonCompilerTest {
Ian Rogers10c5b782013-01-10 10:40:53 -080042 protected:
43 virtual void SetUp() {
Brian Carlstrom700c8d32012-11-05 10:42:02 -080044 ReserveImageSpace();
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080045 CommonCompilerTest::SetUp();
Ian Rogers10c5b782013-01-10 10:40:53 -080046 }
Mathieu Chartierceb07b32015-12-10 09:33:21 -080047 void TestWriteRead(ImageHeader::StorageMode storage_mode);
Ian Rogers10c5b782013-01-10 10:40:53 -080048};
Brian Carlstromdb4d5402011-08-09 12:18:28 -070049
Mathieu Chartierceb07b32015-12-10 09:33:21 -080050void ImageTest::TestWriteRead(ImageHeader::StorageMode storage_mode) {
51 // TODO: Test does not currently work with optimizing.
52 CreateCompilerDriver(Compiler::kQuick, kRuntimeISA);
53 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
54 // Enable write for dex2dex.
55 for (const DexFile* dex_file : class_linker->GetBootClassPath()) {
56 dex_file->EnableWrite();
57 }
Brian Carlstrom0e12bdc2014-05-14 17:44:28 -070058 // Create a generic location tmp file, to be the base of the .art and .oat temporary files.
59 ScratchFile location;
60 ScratchFile image_location(location, ".art");
61
62 std::string image_filename(GetSystemImageFilename(image_location.GetFilename().c_str(),
63 kRuntimeISA));
64 size_t pos = image_filename.rfind('/');
65 CHECK_NE(pos, std::string::npos) << image_filename;
66 std::string image_dir(image_filename, 0, pos);
67 int mkdir_result = mkdir(image_dir.c_str(), 0700);
68 CHECK_EQ(0, mkdir_result) << image_dir;
69 ScratchFile image_file(OS::CreateEmptyFile(image_filename.c_str()));
70
71 std::string oat_filename(image_filename, 0, image_filename.size() - 3);
72 oat_filename += "oat";
73 ScratchFile oat_file(OS::CreateEmptyFile(oat_filename.c_str()));
74
Vladimir Markof4da6752014-08-01 19:04:18 +010075 const uintptr_t requested_image_base = ART_BASE_ADDRESS;
Vladimir Marko944da602016-02-19 12:27:55 +000076 std::unordered_map<const DexFile*, size_t> dex_file_to_oat_index_map;
Jeff Haodcdc85b2015-12-04 14:06:18 -080077 std::vector<const char*> oat_filename_vector(1, oat_filename.c_str());
78 for (const DexFile* dex_file : class_linker->GetBootClassPath()) {
Vladimir Marko944da602016-02-19 12:27:55 +000079 dex_file_to_oat_index_map.emplace(dex_file, 0);
Jeff Haodcdc85b2015-12-04 14:06:18 -080080 }
Mathieu Chartierda5b28a2015-11-05 08:03:47 -080081 std::unique_ptr<ImageWriter> writer(new ImageWriter(*compiler_driver_,
82 requested_image_base,
83 /*compile_pic*/false,
Mathieu Chartierceb07b32015-12-10 09:33:21 -080084 /*compile_app_image*/false,
Jeff Haodcdc85b2015-12-04 14:06:18 -080085 storage_mode,
86 oat_filename_vector,
Vladimir Marko944da602016-02-19 12:27:55 +000087 dex_file_to_oat_index_map));
Igor Murashkin46774762014-10-22 11:37:02 -070088 // TODO: compile_pic should be a test argument.
Ian Rogers00f7d0e2012-07-19 15:28:27 -070089 {
Brian Carlstrom700c8d32012-11-05 10:42:02 -080090 {
Mathieu Chartier2cebb242015-04-21 16:50:40 -070091 jobject class_loader = nullptr;
Ian Rogers5fe9af72013-11-14 00:17:20 -080092 TimingLogger timings("ImageTest::WriteRead", false, false);
Mathieu Chartierf5997b42014-06-20 10:37:54 -070093 TimingLogger::ScopedTiming t("CompileAll", &timings);
Vladimir Markod1eaf0d2015-10-29 12:18:29 +000094 compiler_driver_->SetDexFilesForOatFile(class_linker->GetBootClassPath());
Ian Rogers3d504072014-03-01 09:16:49 -080095 compiler_driver_->CompileAll(class_loader, class_linker->GetBootClassPath(), &timings);
Brian Carlstrom96391602013-06-13 19:49:50 -070096
Mathieu Chartierf5997b42014-06-20 10:37:54 -070097 t.NewTiming("WriteElf");
Andreas Gampe22f8e5c2014-07-09 11:38:21 -070098 SafeMap<std::string, std::string> key_value_store;
Vladimir Marko9bdf1082016-01-21 12:15:52 +000099 const std::vector<const DexFile*>& dex_files = class_linker->GetBootClassPath();
Vladimir Marko10c13562015-11-25 14:33:36 +0000100 std::unique_ptr<ElfWriter> elf_writer = CreateElfWriterQuick(
101 compiler_driver_->GetInstructionSet(),
102 &compiler_driver_->GetCompilerOptions(),
103 oat_file.GetFile());
Vladimir Marko919f5532016-01-20 19:13:01 +0000104 elf_writer->Start();
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000105 OatWriter oat_writer(/*compiling_boot_image*/true, &timings);
Vladimir Marko919f5532016-01-20 19:13:01 +0000106 OutputStream* rodata = elf_writer->StartRoData();
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000107 for (const DexFile* dex_file : dex_files) {
108 ArrayRef<const uint8_t> raw_dex_file(
109 reinterpret_cast<const uint8_t*>(&dex_file->GetHeader()),
110 dex_file->GetHeader().file_size_);
111 oat_writer.AddRawDexFileSource(raw_dex_file,
112 dex_file->GetLocation().c_str(),
113 dex_file->GetLocationChecksum());
114 }
115 std::unique_ptr<MemMap> opened_dex_files_map;
116 std::vector<std::unique_ptr<const DexFile>> opened_dex_files;
117 bool dex_files_ok = oat_writer.WriteAndOpenDexFiles(
118 rodata,
119 oat_file.GetFile(),
120 compiler_driver_->GetInstructionSet(),
121 compiler_driver_->GetInstructionSetFeatures(),
122 &key_value_store,
Andreas Gampe3a2bd292016-01-26 17:23:47 -0800123 /* verify */ false, // Dex files may be dex-to-dex-ed, don't verify.
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000124 &opened_dex_files_map,
125 &opened_dex_files);
126 ASSERT_TRUE(dex_files_ok);
Vladimir Marko944da602016-02-19 12:27:55 +0000127
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000128 bool image_space_ok = writer->PrepareImageAddressSpace();
129 ASSERT_TRUE(image_space_ok);
130
Vladimir Marko944da602016-02-19 12:27:55 +0000131 linker::MultiOatRelativePatcher patcher(compiler_driver_->GetInstructionSet(),
132 instruction_set_features_.get());
133 oat_writer.PrepareLayout(compiler_driver_.get(), writer.get(), dex_files, &patcher);
134 size_t rodata_size = oat_writer.GetOatHeader().GetExecutableOffset();
135 size_t text_size = oat_writer.GetSize() - rodata_size;
136 elf_writer->SetLoadedSectionSizes(rodata_size, text_size, oat_writer.GetBssSize());
137
138 writer->UpdateOatFileLayout(/* oat_index */ 0u,
139 elf_writer->GetLoadedSize(),
140 oat_writer.GetOatDataOffset(),
141 oat_writer.GetSize());
142
Vladimir Marko10c13562015-11-25 14:33:36 +0000143 bool rodata_ok = oat_writer.WriteRodata(rodata);
144 ASSERT_TRUE(rodata_ok);
145 elf_writer->EndRoData(rodata);
146
147 OutputStream* text = elf_writer->StartText();
148 bool text_ok = oat_writer.WriteCode(text);
149 ASSERT_TRUE(text_ok);
150 elf_writer->EndText(text);
151
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000152 bool header_ok = oat_writer.WriteHeader(elf_writer->GetStream(), 0u, 0u, 0u);
153 ASSERT_TRUE(header_ok);
154
Vladimir Marko944da602016-02-19 12:27:55 +0000155 writer->UpdateOatFileHeader(/* oat_index */ 0u, oat_writer.GetOatHeader());
156
Vladimir Marko10c13562015-11-25 14:33:36 +0000157 elf_writer->WriteDynamicSection();
Vladimir Marko49b0f452015-12-10 13:49:19 +0000158 elf_writer->WriteDebugInfo(oat_writer.GetMethodDebugInfo());
159 elf_writer->WritePatchLocations(oat_writer.GetAbsolutePatchLocations());
Vladimir Marko10c13562015-11-25 14:33:36 +0000160
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000161 bool success = elf_writer->End();
Brian Carlstromc50d8e12013-07-23 22:35:16 -0700162 ASSERT_TRUE(success);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700163 }
Ian Rogers0571d352011-11-03 19:51:38 -0700164 }
Brian Carlstrom0e12bdc2014-05-14 17:44:28 -0700165 // Workound bug that mcld::Linker::emit closes oat_file by reopening as dup_oat.
Ian Rogers700a4022014-05-19 16:49:03 -0700166 std::unique_ptr<File> dup_oat(OS::OpenFileReadWrite(oat_file.GetFilename().c_str()));
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700167 ASSERT_TRUE(dup_oat.get() != nullptr);
Mathieu Chartier357e9be2012-08-01 11:00:14 -0700168
jeffhao8161c032012-10-31 15:50:00 -0700169 {
Jeff Haodcdc85b2015-12-04 14:06:18 -0800170 std::vector<const char*> dup_oat_filename(1, dup_oat->GetPath().c_str());
171 std::vector<const char*> dup_image_filename(1, image_file.GetFilename().c_str());
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800172 bool success_image = writer->Write(kInvalidFd,
173 dup_image_filename,
Vladimir Marko944da602016-02-19 12:27:55 +0000174 dup_oat_filename);
jeffhao8161c032012-10-31 15:50:00 -0700175 ASSERT_TRUE(success_image);
Jeff Haodcdc85b2015-12-04 14:06:18 -0800176 bool success_fixup = ElfWriter::Fixup(dup_oat.get(),
Vladimir Marko944da602016-02-19 12:27:55 +0000177 writer->GetOatDataBegin(0));
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800178 ASSERT_TRUE(success_fixup);
Andreas Gampe4303ba92014-11-06 01:00:46 -0800179
180 ASSERT_EQ(dup_oat->FlushCloseOrErase(), 0) << "Could not flush and close oat file "
181 << oat_file.GetFilename();
jeffhao8161c032012-10-31 15:50:00 -0700182 }
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700183
Mathieu Chartier68c868e2015-06-01 16:33:53 -0700184 uint64_t image_file_size;
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700185 {
Ian Rogers700a4022014-05-19 16:49:03 -0700186 std::unique_ptr<File> file(OS::OpenFileForReading(image_file.GetFilename().c_str()));
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700187 ASSERT_TRUE(file.get() != nullptr);
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700188 ImageHeader image_header;
Andreas Gampe4303ba92014-11-06 01:00:46 -0800189 ASSERT_EQ(file->ReadFully(&image_header, sizeof(image_header)), true);
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700190 ASSERT_TRUE(image_header.IsValid());
Mathieu Chartiere401d142015-04-22 13:56:20 -0700191 const auto& bitmap_section = image_header.GetImageSection(ImageHeader::kSectionImageBitmap);
192 ASSERT_GE(bitmap_section.Offset(), sizeof(image_header));
193 ASSERT_NE(0U, bitmap_section.Size());
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700194
Ian Rogers1d54e732013-05-02 21:10:01 -0700195 gc::Heap* heap = Runtime::Current()->GetHeap();
Mathieu Chartiera9d82fe2016-01-25 20:06:11 -0800196 ASSERT_TRUE(heap->HaveContinuousSpaces());
Mathieu Chartier590fee92013-09-13 13:46:47 -0700197 gc::space::ContinuousSpace* space = heap->GetNonMovingSpace();
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700198 ASSERT_FALSE(space->IsImageSpace());
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700199 ASSERT_TRUE(space != nullptr);
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700200 ASSERT_TRUE(space->IsMallocSpace());
Mathieu Chartier68c868e2015-06-01 16:33:53 -0700201
202 image_file_size = file->GetLength();
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700203 }
Brian Carlstrom8a436592011-08-15 21:27:23 -0700204
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700205 ASSERT_TRUE(compiler_driver_->GetImageClasses() != nullptr);
Andreas Gampeb1fcead2015-04-20 18:53:51 -0700206 std::unordered_set<std::string> image_classes(*compiler_driver_->GetImageClasses());
Brian Carlstrom96391602013-06-13 19:49:50 -0700207
Mathieu Chartier0e4627e2012-10-23 16:13:36 -0700208 // Need to delete the compiler since it has worker threads which are attached to runtime.
Ian Rogers1212a022013-03-04 10:48:41 -0800209 compiler_driver_.reset();
Mathieu Chartier0e4627e2012-10-23 16:13:36 -0700210
Ian Rogers10c5b782013-01-10 10:40:53 -0800211 // Tear down old runtime before making a new one, clearing out misc state.
Mathieu Chartier6e88ef62014-10-14 15:01:24 -0700212
213 // Remove the reservation of the memory for use to load the image.
214 // Need to do this before we reset the runtime.
215 UnreserveImageSpace();
216 writer.reset(nullptr);
217
Ian Rogers10c5b782013-01-10 10:40:53 -0800218 runtime_.reset();
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700219 java_lang_dex_file_ = nullptr;
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700220
Mathieu Chartier6e88ef62014-10-14 15:01:24 -0700221 MemMap::Init();
Przemyslaw Szczepaniak5c0cf122015-09-30 17:41:38 +0100222 std::unique_ptr<const DexFile> dex(LoadExpectSingleDexFile(GetLibCoreDexFileNames()[0].c_str()));
Brian Carlstrom8a436592011-08-15 21:27:23 -0700223
Ian Rogerse63db272014-07-15 15:36:11 -0700224 RuntimeOptions options;
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700225 std::string image("-Ximage:");
Brian Carlstrom0e12bdc2014-05-14 17:44:28 -0700226 image.append(image_location.GetFilename());
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700227 options.push_back(std::make_pair(image.c_str(), static_cast<void*>(nullptr)));
Alex Light6e183f22014-07-18 14:57:04 -0700228 // By default the compiler this creates will not include patch information.
229 options.push_back(std::make_pair("-Xnorelocate", nullptr));
Brian Carlstrom8a436592011-08-15 21:27:23 -0700230
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700231 if (!Runtime::Create(options, false)) {
232 LOG(FATAL) << "Failed to create runtime";
233 return;
234 }
235 runtime_.reset(Runtime::Current());
236 // Runtime::Create acquired the mutator_lock_ that is normally given away when we Runtime::Start,
237 // give it away now and then switch to a more managable ScopedObjectAccess.
238 Thread::Current()->TransitionFromRunnableToSuspended(kNative);
239 ScopedObjectAccess soa(Thread::Current());
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700240 ASSERT_TRUE(runtime_.get() != nullptr);
Brian Carlstrom8a436592011-08-15 21:27:23 -0700241 class_linker_ = runtime_->GetClassLinker();
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700242
Ian Rogers1d54e732013-05-02 21:10:01 -0700243 gc::Heap* heap = Runtime::Current()->GetHeap();
Jeff Haodcdc85b2015-12-04 14:06:18 -0800244 ASSERT_TRUE(heap->HasBootImageSpace());
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700245 ASSERT_TRUE(heap->GetNonMovingSpace()->IsMallocSpace());
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700246
Jeff Haodcdc85b2015-12-04 14:06:18 -0800247 // We loaded the runtime with an explicit image, so it must exist.
248 gc::space::ImageSpace* image_space = heap->GetBootImageSpaces()[0];
Mathieu Chartier68c868e2015-06-01 16:33:53 -0700249 ASSERT_TRUE(image_space != nullptr);
Mathieu Chartierceb07b32015-12-10 09:33:21 -0800250 if (storage_mode == ImageHeader::kStorageModeUncompressed) {
251 // Uncompressed, image should be smaller than file.
252 ASSERT_LE(image_space->Size(), image_file_size);
253 } else {
254 // Compressed, file should be smaller than image.
255 ASSERT_LE(image_file_size, image_space->Size());
256 }
Mathieu Chartier68c868e2015-06-01 16:33:53 -0700257
Mathieu Chartier31e89252013-08-28 11:29:12 -0700258 image_space->VerifyImageAllocations();
Ian Rogers13735952014-10-08 12:43:28 -0700259 uint8_t* image_begin = image_space->Begin();
260 uint8_t* image_end = image_space->End();
Ian Rogers30fab402012-01-23 15:43:46 -0800261 CHECK_EQ(requested_image_base, reinterpret_cast<uintptr_t>(image_begin));
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800262 for (size_t i = 0; i < dex->NumClassDefs(); ++i) {
Brian Carlstromd2fbb2b2011-08-23 11:57:08 -0700263 const DexFile::ClassDef& class_def = dex->GetClassDef(i);
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700264 const char* descriptor = dex->GetClassDescriptor(class_def);
Ian Rogers98379392014-02-24 16:53:16 -0800265 mirror::Class* klass = class_linker_->FindSystemClass(soa.Self(), descriptor);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800266 EXPECT_TRUE(klass != nullptr) << descriptor;
Brian Carlstrom96391602013-06-13 19:49:50 -0700267 if (image_classes.find(descriptor) != image_classes.end()) {
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800268 // Image classes should be located inside the image.
Ian Rogers13735952014-10-08 12:43:28 -0700269 EXPECT_LT(image_begin, reinterpret_cast<uint8_t*>(klass)) << descriptor;
270 EXPECT_LT(reinterpret_cast<uint8_t*>(klass), image_end) << descriptor;
Brian Carlstrom96391602013-06-13 19:49:50 -0700271 } else {
Ian Rogers13735952014-10-08 12:43:28 -0700272 EXPECT_TRUE(reinterpret_cast<uint8_t*>(klass) >= image_end ||
273 reinterpret_cast<uint8_t*>(klass) < image_begin) << descriptor;
Brian Carlstrom96391602013-06-13 19:49:50 -0700274 }
Mathieu Chartier4d7f61d2014-04-17 14:43:39 -0700275 EXPECT_TRUE(Monitor::IsValidLockWord(klass->GetLockWord(false)));
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700276 }
Brian Carlstrom0e12bdc2014-05-14 17:44:28 -0700277
278 image_file.Unlink();
279 oat_file.Unlink();
280 int rmdir_result = rmdir(image_dir.c_str());
281 CHECK_EQ(0, rmdir_result);
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700282}
283
Mathieu Chartierceb07b32015-12-10 09:33:21 -0800284TEST_F(ImageTest, WriteReadUncompressed) {
285 TestWriteRead(ImageHeader::kStorageModeUncompressed);
286}
287
288TEST_F(ImageTest, WriteReadLZ4) {
289 TestWriteRead(ImageHeader::kStorageModeLZ4);
290}
291
Mathieu Chartiera6e81ed2016-02-25 13:52:10 -0800292TEST_F(ImageTest, WriteReadLZ4HC) {
293 TestWriteRead(ImageHeader::kStorageModeLZ4HC);
294}
295
296
Brian Carlstrom179486a2013-09-03 11:51:42 -0700297TEST_F(ImageTest, ImageHeaderIsValid) {
298 uint32_t image_begin = ART_BASE_ADDRESS;
299 uint32_t image_size_ = 16 * KB;
Brian Carlstrom179486a2013-09-03 11:51:42 -0700300 uint32_t image_roots = ART_BASE_ADDRESS + (1 * KB);
301 uint32_t oat_checksum = 0;
302 uint32_t oat_file_begin = ART_BASE_ADDRESS + (4 * KB); // page aligned
303 uint32_t oat_data_begin = ART_BASE_ADDRESS + (8 * KB); // page aligned
304 uint32_t oat_data_end = ART_BASE_ADDRESS + (9 * KB);
305 uint32_t oat_file_end = ART_BASE_ADDRESS + (10 * KB);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700306 ImageSection sections[ImageHeader::kSectionCount];
Brian Carlstrom179486a2013-09-03 11:51:42 -0700307 ImageHeader image_header(image_begin,
308 image_size_,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700309 sections,
Brian Carlstrom179486a2013-09-03 11:51:42 -0700310 image_roots,
311 oat_checksum,
312 oat_file_begin,
313 oat_data_begin,
314 oat_data_end,
Igor Murashkin46774762014-10-22 11:37:02 -0700315 oat_file_end,
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800316 /*boot_image_begin*/0U,
317 /*boot_image_size*/0U,
318 /*boot_oat_begin*/0U,
319 /*boot_oat_size_*/0U,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700320 sizeof(void*),
Mathieu Chartierceb07b32015-12-10 09:33:21 -0800321 /*compile_pic*/false,
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800322 /*is_pic*/false,
Mathieu Chartierceb07b32015-12-10 09:33:21 -0800323 ImageHeader::kDefaultStorageMode,
324 /*data_size*/0u);
Brian Carlstrom179486a2013-09-03 11:51:42 -0700325 ASSERT_TRUE(image_header.IsValid());
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800326 ASSERT_TRUE(!image_header.IsAppImage());
Brian Carlstrom179486a2013-09-03 11:51:42 -0700327
328 char* magic = const_cast<char*>(image_header.GetMagic());
329 strcpy(magic, ""); // bad magic
330 ASSERT_FALSE(image_header.IsValid());
331 strcpy(magic, "art\n000"); // bad version
332 ASSERT_FALSE(image_header.IsValid());
333}
334
Brian Carlstromdb4d5402011-08-09 12:18:28 -0700335} // namespace art