blob: 637578e6221a990670382b97b52858b5fbe18a16 [file] [log] [blame]
Vladimir Marko1352f132017-04-28 15:28:29 +01001/*
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 */
16
Vladimir Marko74527972016-11-29 15:57:32 +000017#ifndef ART_DEX2OAT_LINKER_IMAGE_TEST_H_
18#define ART_DEX2OAT_LINKER_IMAGE_TEST_H_
Vladimir Marko1352f132017-04-28 15:28:29 +010019
20#include "image.h"
21
22#include <memory>
23#include <string>
24#include <vector>
25
26#include "android-base/stringprintf.h"
27
28#include "art_method-inl.h"
David Sehr891a50e2017-10-27 17:01:07 -070029#include "base/file_utils.h"
Vladimir Marko1352f132017-04-28 15:28:29 +010030#include "base/unix_file/fd_file.h"
31#include "class_linker-inl.h"
Vladimir Marko1352f132017-04-28 15:28:29 +010032#include "common_compiler_test.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070033#include "compiler_callbacks.h"
Vladimir Marko1352f132017-04-28 15:28:29 +010034#include "debug/method_debug_info.h"
35#include "dex/quick_compiler_callbacks.h"
36#include "driver/compiler_options.h"
Vladimir Marko1352f132017-04-28 15:28:29 +010037#include "gc/space/image_space.h"
38#include "image_writer.h"
39#include "linker/buffered_output_stream.h"
Vladimir Marko74527972016-11-29 15:57:32 +000040#include "linker/elf_writer.h"
41#include "linker/elf_writer_quick.h"
Vladimir Marko1352f132017-04-28 15:28:29 +010042#include "linker/file_output_stream.h"
43#include "linker/multi_oat_relative_patcher.h"
44#include "lock_word.h"
45#include "mirror/object-inl.h"
46#include "oat_writer.h"
47#include "scoped_thread_state_change-inl.h"
48#include "signal_catcher.h"
49#include "utils.h"
50
51namespace art {
Vladimir Marko74527972016-11-29 15:57:32 +000052namespace linker {
Vladimir Marko1352f132017-04-28 15:28:29 +010053
54static const uintptr_t kRequestedImageBase = ART_BASE_ADDRESS;
55
56struct CompilationHelper {
57 std::vector<std::string> dex_file_locations;
58 std::vector<ScratchFile> image_locations;
59 std::vector<std::unique_ptr<const DexFile>> extra_dex_files;
60 std::vector<ScratchFile> image_files;
61 std::vector<ScratchFile> oat_files;
62 std::vector<ScratchFile> vdex_files;
63 std::string image_dir;
64
65 void Compile(CompilerDriver* driver,
66 ImageHeader::StorageMode storage_mode);
67
68 std::vector<size_t> GetImageObjectSectionSizes();
69
70 ~CompilationHelper();
71};
72
73class ImageTest : public CommonCompilerTest {
74 protected:
75 virtual void SetUp() {
76 ReserveImageSpace();
77 CommonCompilerTest::SetUp();
78 }
79
80 void TestWriteRead(ImageHeader::StorageMode storage_mode);
81
82 void Compile(ImageHeader::StorageMode storage_mode,
83 CompilationHelper& out_helper,
84 const std::string& extra_dex = "",
85 const std::initializer_list<std::string>& image_classes = {});
86
87 void SetUpRuntimeOptions(RuntimeOptions* options) OVERRIDE {
88 CommonCompilerTest::SetUpRuntimeOptions(options);
Mathieu Chartiere01b6f62017-07-19 16:55:04 -070089 QuickCompilerCallbacks* new_callbacks =
90 new QuickCompilerCallbacks(CompilerCallbacks::CallbackMode::kCompileBootImage);
91 new_callbacks->SetVerificationResults(verification_results_.get());
92 callbacks_.reset(new_callbacks);
Vladimir Marko1352f132017-04-28 15:28:29 +010093 options->push_back(std::make_pair("compilercallbacks", callbacks_.get()));
94 }
95
96 std::unordered_set<std::string>* GetImageClasses() OVERRIDE {
97 return new std::unordered_set<std::string>(image_classes_);
98 }
99
100 ArtMethod* FindCopiedMethod(ArtMethod* origin, mirror::Class* klass)
101 REQUIRES_SHARED(Locks::mutator_lock_) {
102 PointerSize pointer_size = class_linker_->GetImagePointerSize();
103 for (ArtMethod& m : klass->GetCopiedMethods(pointer_size)) {
104 if (strcmp(origin->GetName(), m.GetName()) == 0 &&
105 origin->GetSignature() == m.GetSignature()) {
106 return &m;
107 }
108 }
109 return nullptr;
110 }
111
112 private:
113 std::unordered_set<std::string> image_classes_;
114};
115
116inline CompilationHelper::~CompilationHelper() {
117 for (ScratchFile& image_file : image_files) {
118 image_file.Unlink();
119 }
120 for (ScratchFile& oat_file : oat_files) {
121 oat_file.Unlink();
122 }
123 for (ScratchFile& vdex_file : vdex_files) {
124 vdex_file.Unlink();
125 }
126 const int rmdir_result = rmdir(image_dir.c_str());
127 CHECK_EQ(0, rmdir_result);
128}
129
130inline std::vector<size_t> CompilationHelper::GetImageObjectSectionSizes() {
131 std::vector<size_t> ret;
132 for (ScratchFile& image_file : image_files) {
133 std::unique_ptr<File> file(OS::OpenFileForReading(image_file.GetFilename().c_str()));
134 CHECK(file.get() != nullptr);
135 ImageHeader image_header;
136 CHECK_EQ(file->ReadFully(&image_header, sizeof(image_header)), true);
137 CHECK(image_header.IsValid());
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +0100138 ret.push_back(image_header.GetObjectsSection().Size());
Vladimir Marko1352f132017-04-28 15:28:29 +0100139 }
140 return ret;
141}
142
143inline void CompilationHelper::Compile(CompilerDriver* driver,
144 ImageHeader::StorageMode storage_mode) {
145 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
146 std::vector<const DexFile*> class_path = class_linker->GetBootClassPath();
147
148 for (const std::unique_ptr<const DexFile>& dex_file : extra_dex_files) {
149 {
150 ScopedObjectAccess soa(Thread::Current());
151 // Inject in boot class path so that the compiler driver can see it.
152 class_linker->AppendToBootClassPath(soa.Self(), *dex_file.get());
153 }
154 class_path.push_back(dex_file.get());
155 }
156
157 // Enable write for dex2dex.
158 for (const DexFile* dex_file : class_path) {
159 dex_file_locations.push_back(dex_file->GetLocation());
160 if (dex_file->IsReadOnly()) {
161 dex_file->EnableWrite();
162 }
163 }
164 {
165 // Create a generic tmp file, to be the base of the .art and .oat temporary files.
166 ScratchFile location;
167 for (int i = 0; i < static_cast<int>(class_path.size()); ++i) {
168 std::string cur_location =
169 android::base::StringPrintf("%s-%d.art", location.GetFilename().c_str(), i);
170 image_locations.push_back(ScratchFile(cur_location));
171 }
172 }
173 std::vector<std::string> image_filenames;
174 for (ScratchFile& file : image_locations) {
175 std::string image_filename(GetSystemImageFilename(file.GetFilename().c_str(), kRuntimeISA));
176 image_filenames.push_back(image_filename);
177 size_t pos = image_filename.rfind('/');
178 CHECK_NE(pos, std::string::npos) << image_filename;
179 if (image_dir.empty()) {
180 image_dir = image_filename.substr(0, pos);
181 int mkdir_result = mkdir(image_dir.c_str(), 0700);
182 CHECK_EQ(0, mkdir_result) << image_dir;
183 }
184 image_files.push_back(ScratchFile(OS::CreateEmptyFile(image_filename.c_str())));
185 }
186
187 std::vector<std::string> oat_filenames;
188 std::vector<std::string> vdex_filenames;
189 for (const std::string& image_filename : image_filenames) {
190 std::string oat_filename = ReplaceFileExtension(image_filename, "oat");
191 oat_files.push_back(ScratchFile(OS::CreateEmptyFile(oat_filename.c_str())));
192 oat_filenames.push_back(oat_filename);
193 std::string vdex_filename = ReplaceFileExtension(image_filename, "vdex");
194 vdex_files.push_back(ScratchFile(OS::CreateEmptyFile(vdex_filename.c_str())));
195 vdex_filenames.push_back(vdex_filename);
196 }
197
198 std::unordered_map<const DexFile*, size_t> dex_file_to_oat_index_map;
199 std::vector<const char*> oat_filename_vector;
200 for (const std::string& file : oat_filenames) {
201 oat_filename_vector.push_back(file.c_str());
202 }
203 std::vector<const char*> image_filename_vector;
204 for (const std::string& file : image_filenames) {
205 image_filename_vector.push_back(file.c_str());
206 }
207 size_t image_idx = 0;
208 for (const DexFile* dex_file : class_path) {
209 dex_file_to_oat_index_map.emplace(dex_file, image_idx);
210 ++image_idx;
211 }
212 // TODO: compile_pic should be a test argument.
213 std::unique_ptr<ImageWriter> writer(new ImageWriter(*driver,
214 kRequestedImageBase,
215 /*compile_pic*/false,
216 /*compile_app_image*/false,
217 storage_mode,
218 oat_filename_vector,
Jeff Haoc23b0c02017-07-27 18:19:38 -0700219 dex_file_to_oat_index_map,
220 /*dirty_image_objects*/nullptr));
Vladimir Marko1352f132017-04-28 15:28:29 +0100221 {
222 {
223 jobject class_loader = nullptr;
224 TimingLogger timings("ImageTest::WriteRead", false, false);
225 TimingLogger::ScopedTiming t("CompileAll", &timings);
226 driver->SetDexFilesForOatFile(class_path);
Nicolas Geoffray1cfea7a2017-05-24 14:44:38 +0100227 driver->CompileAll(class_loader, class_path, &timings);
Vladimir Marko1352f132017-04-28 15:28:29 +0100228
229 t.NewTiming("WriteElf");
230 SafeMap<std::string, std::string> key_value_store;
231 std::vector<const char*> dex_filename_vector;
232 for (size_t i = 0; i < class_path.size(); ++i) {
233 dex_filename_vector.push_back("");
234 }
235 key_value_store.Put(OatHeader::kBootClassPathKey,
236 gc::space::ImageSpace::GetMultiImageBootClassPath(
237 dex_filename_vector,
238 oat_filename_vector,
239 image_filename_vector));
240
241 std::vector<std::unique_ptr<ElfWriter>> elf_writers;
242 std::vector<std::unique_ptr<OatWriter>> oat_writers;
243 for (ScratchFile& oat_file : oat_files) {
244 elf_writers.emplace_back(CreateElfWriterQuick(driver->GetInstructionSet(),
245 driver->GetInstructionSetFeatures(),
246 &driver->GetCompilerOptions(),
247 oat_file.GetFile()));
248 elf_writers.back()->Start();
249 oat_writers.emplace_back(new OatWriter(/*compiling_boot_image*/true,
250 &timings,
Mathieu Chartier603ccab2017-10-20 14:34:28 -0700251 /*profile_compilation_info*/nullptr,
252 CompactDexLevel::kCompactDexLevelNone));
Vladimir Marko1352f132017-04-28 15:28:29 +0100253 }
254
255 std::vector<OutputStream*> rodata;
Andreas Gampee166e672017-12-19 18:59:29 +0000256 std::vector<std::unique_ptr<MemMap>> opened_dex_files_map;
Vladimir Marko1352f132017-04-28 15:28:29 +0100257 std::vector<std::unique_ptr<const DexFile>> opened_dex_files;
258 // Now that we have finalized key_value_store_, start writing the oat file.
259 for (size_t i = 0, size = oat_writers.size(); i != size; ++i) {
260 const DexFile* dex_file = class_path[i];
261 rodata.push_back(elf_writers[i]->StartRoData());
262 ArrayRef<const uint8_t> raw_dex_file(
263 reinterpret_cast<const uint8_t*>(&dex_file->GetHeader()),
264 dex_file->GetHeader().file_size_);
265 oat_writers[i]->AddRawDexFileSource(raw_dex_file,
266 dex_file->GetLocation().c_str(),
267 dex_file->GetLocationChecksum());
268
Andreas Gampee166e672017-12-19 18:59:29 +0000269 std::unique_ptr<MemMap> cur_opened_dex_files_map;
Vladimir Marko1352f132017-04-28 15:28:29 +0100270 std::vector<std::unique_ptr<const DexFile>> cur_opened_dex_files;
271 bool dex_files_ok = oat_writers[i]->WriteAndOpenDexFiles(
Nicolas Geoffray8eaa8e52017-11-13 17:47:50 +0000272 vdex_files[i].GetFile(),
Vladimir Marko1352f132017-04-28 15:28:29 +0100273 rodata.back(),
274 driver->GetInstructionSet(),
275 driver->GetInstructionSetFeatures(),
276 &key_value_store,
277 /* verify */ false, // Dex files may be dex-to-dex-ed, don't verify.
278 /* update_input_vdex */ false,
Andreas Gampee166e672017-12-19 18:59:29 +0000279 &cur_opened_dex_files_map,
Vladimir Marko1352f132017-04-28 15:28:29 +0100280 &cur_opened_dex_files);
281 ASSERT_TRUE(dex_files_ok);
282
Andreas Gampee166e672017-12-19 18:59:29 +0000283 if (cur_opened_dex_files_map != nullptr) {
284 opened_dex_files_map.push_back(std::move(cur_opened_dex_files_map));
Vladimir Marko1352f132017-04-28 15:28:29 +0100285 for (std::unique_ptr<const DexFile>& cur_dex_file : cur_opened_dex_files) {
286 // dex_file_oat_index_map_.emplace(dex_file.get(), i);
287 opened_dex_files.push_back(std::move(cur_dex_file));
288 }
289 } else {
290 ASSERT_TRUE(cur_opened_dex_files.empty());
291 }
292 }
293 bool image_space_ok = writer->PrepareImageAddressSpace();
294 ASSERT_TRUE(image_space_ok);
295
David Brazdil93592f52017-12-08 10:53:27 +0000296 DCHECK_EQ(vdex_files.size(), oat_files.size());
Vladimir Marko1352f132017-04-28 15:28:29 +0100297 for (size_t i = 0, size = oat_files.size(); i != size; ++i) {
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100298 MultiOatRelativePatcher patcher(driver->GetInstructionSet(),
299 driver->GetInstructionSetFeatures());
Vladimir Marko1352f132017-04-28 15:28:29 +0100300 OatWriter* const oat_writer = oat_writers[i].get();
301 ElfWriter* const elf_writer = elf_writers[i].get();
302 std::vector<const DexFile*> cur_dex_files(1u, class_path[i]);
303 oat_writer->Initialize(driver, writer.get(), cur_dex_files);
David Brazdil93592f52017-12-08 10:53:27 +0000304
305 std::unique_ptr<BufferedOutputStream> vdex_out =
306 std::make_unique<BufferedOutputStream>(
307 std::make_unique<FileOutputStream>(vdex_files[i].GetFile()));
308 oat_writer->WriteVerifierDeps(vdex_out.get(), nullptr);
309 oat_writer->WriteQuickeningInfo(vdex_out.get());
310 oat_writer->WriteChecksumsAndVdexHeader(vdex_out.get());
311
Vladimir Marko1352f132017-04-28 15:28:29 +0100312 oat_writer->PrepareLayout(&patcher);
313 size_t rodata_size = oat_writer->GetOatHeader().GetExecutableOffset();
314 size_t text_size = oat_writer->GetOatSize() - rodata_size;
315 elf_writer->PrepareDynamicSection(rodata_size,
316 text_size,
317 oat_writer->GetBssSize(),
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100318 oat_writer->GetBssMethodsOffset(),
David Srbeckyec2cdf42017-12-08 16:21:25 +0000319 oat_writer->GetBssRootsOffset(),
320 oat_writer->GetVdexSize());
Vladimir Marko1352f132017-04-28 15:28:29 +0100321
322 writer->UpdateOatFileLayout(i,
323 elf_writer->GetLoadedSize(),
324 oat_writer->GetOatDataOffset(),
325 oat_writer->GetOatSize());
326
327 bool rodata_ok = oat_writer->WriteRodata(rodata[i]);
328 ASSERT_TRUE(rodata_ok);
329 elf_writer->EndRoData(rodata[i]);
330
331 OutputStream* text = elf_writer->StartText();
332 bool text_ok = oat_writer->WriteCode(text);
333 ASSERT_TRUE(text_ok);
334 elf_writer->EndText(text);
335
336 bool header_ok = oat_writer->WriteHeader(elf_writer->GetStream(), 0u, 0u, 0u);
337 ASSERT_TRUE(header_ok);
338
339 writer->UpdateOatFileHeader(i, oat_writer->GetOatHeader());
340
341 elf_writer->WriteDynamicSection();
David Srbecky32210b92017-12-04 14:39:21 +0000342 elf_writer->WriteDebugInfo(oat_writer->GetDebugInfo());
Vladimir Marko1352f132017-04-28 15:28:29 +0100343
344 bool success = elf_writer->End();
345 ASSERT_TRUE(success);
346 }
347 }
348
349 bool success_image = writer->Write(kInvalidFd,
350 image_filename_vector,
351 oat_filename_vector);
352 ASSERT_TRUE(success_image);
353
354 for (size_t i = 0, size = oat_filenames.size(); i != size; ++i) {
355 const char* oat_filename = oat_filenames[i].c_str();
356 std::unique_ptr<File> oat_file(OS::OpenFileReadWrite(oat_filename));
357 ASSERT_TRUE(oat_file != nullptr);
358 bool success_fixup = ElfWriter::Fixup(oat_file.get(),
359 writer->GetOatDataBegin(i));
360 ASSERT_TRUE(success_fixup);
361 ASSERT_EQ(oat_file->FlushCloseOrErase(), 0) << "Could not flush and close oat file "
362 << oat_filename;
363 }
364 }
365}
366
367inline void ImageTest::Compile(ImageHeader::StorageMode storage_mode,
368 CompilationHelper& helper,
369 const std::string& extra_dex,
370 const std::initializer_list<std::string>& image_classes) {
371 for (const std::string& image_class : image_classes) {
372 image_classes_.insert(image_class);
373 }
374 CreateCompilerDriver(Compiler::kOptimizing, kRuntimeISA, kIsTargetBuild ? 2U : 16U);
375 // Set inline filter values.
376 compiler_options_->SetInlineMaxCodeUnits(CompilerOptions::kDefaultInlineMaxCodeUnits);
377 image_classes_.clear();
378 if (!extra_dex.empty()) {
379 helper.extra_dex_files = OpenTestDexFiles(extra_dex.c_str());
380 }
381 helper.Compile(compiler_driver_.get(), storage_mode);
382 if (image_classes.begin() != image_classes.end()) {
383 // Make sure the class got initialized.
384 ScopedObjectAccess soa(Thread::Current());
385 ClassLinker* const class_linker = Runtime::Current()->GetClassLinker();
386 for (const std::string& image_class : image_classes) {
387 mirror::Class* klass = class_linker->FindSystemClass(Thread::Current(), image_class.c_str());
388 EXPECT_TRUE(klass != nullptr);
389 EXPECT_TRUE(klass->IsInitialized());
390 }
391 }
392}
393
394inline void ImageTest::TestWriteRead(ImageHeader::StorageMode storage_mode) {
395 CompilationHelper helper;
396 Compile(storage_mode, /*out*/ helper);
397 std::vector<uint64_t> image_file_sizes;
398 for (ScratchFile& image_file : helper.image_files) {
399 std::unique_ptr<File> file(OS::OpenFileForReading(image_file.GetFilename().c_str()));
400 ASSERT_TRUE(file.get() != nullptr);
401 ImageHeader image_header;
402 ASSERT_EQ(file->ReadFully(&image_header, sizeof(image_header)), true);
403 ASSERT_TRUE(image_header.IsValid());
Vladimir Markocd87c3e2017-09-05 13:11:57 +0100404 const auto& bitmap_section = image_header.GetImageBitmapSection();
Vladimir Marko1352f132017-04-28 15:28:29 +0100405 ASSERT_GE(bitmap_section.Offset(), sizeof(image_header));
406 ASSERT_NE(0U, bitmap_section.Size());
407
408 gc::Heap* heap = Runtime::Current()->GetHeap();
409 ASSERT_TRUE(heap->HaveContinuousSpaces());
410 gc::space::ContinuousSpace* space = heap->GetNonMovingSpace();
411 ASSERT_FALSE(space->IsImageSpace());
412 ASSERT_TRUE(space != nullptr);
413 ASSERT_TRUE(space->IsMallocSpace());
414 image_file_sizes.push_back(file->GetLength());
415 }
416
417 ASSERT_TRUE(compiler_driver_->GetImageClasses() != nullptr);
418 std::unordered_set<std::string> image_classes(*compiler_driver_->GetImageClasses());
419
420 // Need to delete the compiler since it has worker threads which are attached to runtime.
421 compiler_driver_.reset();
422
423 // Tear down old runtime before making a new one, clearing out misc state.
424
425 // Remove the reservation of the memory for use to load the image.
426 // Need to do this before we reset the runtime.
427 UnreserveImageSpace();
428
429 helper.extra_dex_files.clear();
430 runtime_.reset();
431 java_lang_dex_file_ = nullptr;
432
433 MemMap::Init();
434
435 RuntimeOptions options;
436 std::string image("-Ximage:");
437 image.append(helper.image_locations[0].GetFilename());
438 options.push_back(std::make_pair(image.c_str(), static_cast<void*>(nullptr)));
439 // By default the compiler this creates will not include patch information.
440 options.push_back(std::make_pair("-Xnorelocate", nullptr));
441
442 if (!Runtime::Create(options, false)) {
443 LOG(FATAL) << "Failed to create runtime";
444 return;
445 }
446 runtime_.reset(Runtime::Current());
447 // Runtime::Create acquired the mutator_lock_ that is normally given away when we Runtime::Start,
448 // give it away now and then switch to a more managable ScopedObjectAccess.
449 Thread::Current()->TransitionFromRunnableToSuspended(kNative);
450 ScopedObjectAccess soa(Thread::Current());
451 ASSERT_TRUE(runtime_.get() != nullptr);
452 class_linker_ = runtime_->GetClassLinker();
453
454 gc::Heap* heap = Runtime::Current()->GetHeap();
455 ASSERT_TRUE(heap->HasBootImageSpace());
456 ASSERT_TRUE(heap->GetNonMovingSpace()->IsMallocSpace());
457
458 // We loaded the runtime with an explicit image, so it must exist.
459 ASSERT_EQ(heap->GetBootImageSpaces().size(), image_file_sizes.size());
460 for (size_t i = 0; i < helper.dex_file_locations.size(); ++i) {
461 std::unique_ptr<const DexFile> dex(
462 LoadExpectSingleDexFile(helper.dex_file_locations[i].c_str()));
463 ASSERT_TRUE(dex != nullptr);
464 uint64_t image_file_size = image_file_sizes[i];
465 gc::space::ImageSpace* image_space = heap->GetBootImageSpaces()[i];
466 ASSERT_TRUE(image_space != nullptr);
467 if (storage_mode == ImageHeader::kStorageModeUncompressed) {
468 // Uncompressed, image should be smaller than file.
469 ASSERT_LE(image_space->GetImageHeader().GetImageSize(), image_file_size);
470 } else if (image_file_size > 16 * KB) {
471 // Compressed, file should be smaller than image. Not really valid for small images.
472 ASSERT_LE(image_file_size, image_space->GetImageHeader().GetImageSize());
473 }
474
475 image_space->VerifyImageAllocations();
476 uint8_t* image_begin = image_space->Begin();
477 uint8_t* image_end = image_space->End();
478 if (i == 0) {
479 // This check is only valid for image 0.
480 CHECK_EQ(kRequestedImageBase, reinterpret_cast<uintptr_t>(image_begin));
481 }
482 for (size_t j = 0; j < dex->NumClassDefs(); ++j) {
483 const DexFile::ClassDef& class_def = dex->GetClassDef(j);
484 const char* descriptor = dex->GetClassDescriptor(class_def);
485 mirror::Class* klass = class_linker_->FindSystemClass(soa.Self(), descriptor);
486 EXPECT_TRUE(klass != nullptr) << descriptor;
487 if (image_classes.find(descriptor) == image_classes.end()) {
488 EXPECT_TRUE(reinterpret_cast<uint8_t*>(klass) >= image_end ||
489 reinterpret_cast<uint8_t*>(klass) < image_begin) << descriptor;
490 } else {
491 // Image classes should be located inside the image.
492 EXPECT_LT(image_begin, reinterpret_cast<uint8_t*>(klass)) << descriptor;
493 EXPECT_LT(reinterpret_cast<uint8_t*>(klass), image_end) << descriptor;
494 }
495 EXPECT_TRUE(Monitor::IsValidLockWord(klass->GetLockWord(false)));
496 }
497 }
498}
499
Vladimir Marko74527972016-11-29 15:57:32 +0000500} // namespace linker
Vladimir Marko1352f132017-04-28 15:28:29 +0100501} // namespace art
502
Vladimir Marko74527972016-11-29 15:57:32 +0000503#endif // ART_DEX2OAT_LINKER_IMAGE_TEST_H_