diff options
-rw-r--r-- | compiler/driver/compiler_driver.cc | 175 | ||||
-rw-r--r-- | compiler/driver/compiler_driver.h | 19 | ||||
-rw-r--r-- | oatdump/oatdump.cc | 132 | ||||
-rw-r--r-- | runtime/class_linker.cc | 342 | ||||
-rw-r--r-- | runtime/verifier/method_verifier.cc | 24 | ||||
-rw-r--r-- | runtime/verifier/method_verifier.h | 42 |
6 files changed, 404 insertions, 330 deletions
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc index 01e0ac4..b993015 100644 --- a/compiler/driver/compiler_driver.cc +++ b/compiler/driver/compiler_driver.cc @@ -350,10 +350,10 @@ CompilerDriver::CompilerDriver(const CompilerOptions* compiler_options, dump_stats_(dump_stats), dump_passes_(dump_passes), timings_logger_(timer), - compiler_library_(NULL), - compiler_context_(NULL), - compiler_enable_auto_elf_loading_(NULL), - compiler_get_method_code_addr_(NULL), + compiler_library_(nullptr), + compiler_context_(nullptr), + compiler_enable_auto_elf_loading_(nullptr), + compiler_get_method_code_addr_(nullptr), support_boot_image_fixup_(instruction_set != kMips), dedupe_code_("dedupe code"), dedupe_src_mapping_table_("dedupe source mapping table"), @@ -365,7 +365,7 @@ CompilerDriver::CompilerDriver(const CompilerOptions* compiler_options, DCHECK(verification_results_ != nullptr); DCHECK(method_inliner_map_ != nullptr); - CHECK_PTHREAD_CALL(pthread_key_create, (&tls_key_, NULL), "compiler tls key"); + CHECK_PTHREAD_CALL(pthread_key_create, (&tls_key_, nullptr), "compiler tls key"); dex_to_dex_compiler_ = reinterpret_cast<DexToDexCompilerFn>(ArtCompileDEX); @@ -445,7 +445,7 @@ CompilerDriver::~CompilerDriver() { CompilerTls* CompilerDriver::GetTls() { // Lazily create thread-local storage CompilerTls* res = static_cast<CompilerTls*>(pthread_getspecific(tls_key_)); - if (res == NULL) { + if (res == nullptr) { res = compiler_->CreateNewCompilerTls(); CHECK_PTHREAD_CALL(pthread_setspecific, (tls_key_, res), "compiler tls"); } @@ -520,20 +520,18 @@ static DexToDexCompilationLevel GetDexToDexCompilationlevel( const char* descriptor = dex_file.GetClassDescriptor(class_def); ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); mirror::Class* klass = class_linker->FindClass(self, descriptor, class_loader); - if (klass == NULL) { + if (klass == nullptr) { CHECK(self->IsExceptionPending()); self->ClearException(); return kDontDexToDexCompile; } - // The verifier can only run on "quick" instructions at runtime (see usage of - // FindAccessedFieldAtDexPc and FindInvokedMethodAtDexPc in ThrowNullPointerExceptionFromDexPC - // function). Since image classes can be verified again while compiling an application, - // we must prevent the DEX-to-DEX compiler from introducing them. - // TODO: find a way to enable "quick" instructions for image classes and remove this check. - bool compiling_image_classes = class_loader.Get() == nullptr; - if (compiling_image_classes) { - return kRequired; - } else if (klass->IsVerified()) { + // DexToDex at the kOptimize level may introduce quickened opcodes, which replace symbolic + // references with actual offsets. We cannot re-verify such instructions. + // + // We store the verification information in the class status in the oat file, which the linker + // can validate (checksums) and use to skip load-time verification. It is thus safe to + // optimize when a class has been fully verified before. + if (klass->IsVerified()) { // Class is verified so we can enable DEX-to-DEX compilation for performance. return kOptimize; } else if (klass->IsCompileTimeVerified()) { @@ -606,13 +604,14 @@ void CompilerDriver::PreCompile(jobject class_loader, const std::vector<const De ThreadPool* thread_pool, TimingLogger* timings) { LoadImageClasses(timings); + Resolve(class_loader, dex_files, thread_pool, timings); + if (!compiler_options_->IsVerificationEnabled()) { - VLOG(compiler) << "Verify none mode specified, skipping pre-compilation"; + VLOG(compiler) << "Verify none mode specified, skipping verification."; + SetVerified(class_loader, dex_files, thread_pool, timings); return; } - Resolve(class_loader, dex_files, thread_pool, timings); - Verify(class_loader, dex_files, thread_pool, timings); InitializeClasses(class_loader, dex_files, thread_pool, timings); @@ -632,7 +631,7 @@ static void ResolveExceptionsForMethod(MethodHelper* mh, std::set<std::pair<uint16_t, const DexFile*>>& exceptions_to_resolve) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { const DexFile::CodeItem* code_item = mh->GetMethod()->GetCodeItem(); - if (code_item == NULL) { + if (code_item == nullptr) { return; // native or abstract method } if (code_item->tries_size_ == 0) { @@ -710,7 +709,7 @@ void CompilerDriver::LoadImageClasses(TimingLogger* timings) StackHandleScope<1> hs(self); Handle<mirror::Class> klass( hs.NewHandle(class_linker->FindSystemClass(self, descriptor.c_str()))); - if (klass.Get() == NULL) { + if (klass.Get() == nullptr) { VLOG(compiler) << "Failed to find class " << descriptor; image_classes_->erase(it++); self->ClearException(); @@ -738,7 +737,7 @@ void CompilerDriver::LoadImageClasses(TimingLogger* timings) Handle<mirror::Class> klass(hs.NewHandle( class_linker->ResolveType(*dex_file, exception_type_idx, dex_cache, NullHandle<mirror::ClassLoader>()))); - if (klass.Get() == NULL) { + if (klass.Get() == nullptr) { const DexFile::TypeId& type_id = dex_file->GetTypeId(exception_type_idx); const char* descriptor = dex_file->GetTypeDescriptor(type_id); LOG(FATAL) << "Failed to resolve class " << descriptor; @@ -785,8 +784,8 @@ static void MaybeAddToImageClasses(Handle<mirror::Class> c, std::set<std::string } void CompilerDriver::FindClinitImageClassesCallback(mirror::Object* object, void* arg) { - DCHECK(object != NULL); - DCHECK(arg != NULL); + DCHECK(object != nullptr); + DCHECK(arg != nullptr); CompilerDriver* compiler_driver = reinterpret_cast<CompilerDriver*>(arg); StackHandleScope<1> hs(Thread::Current()); MaybeAddToImageClasses(hs.NewHandle(object->GetClass()), compiler_driver->image_classes_.get()); @@ -854,29 +853,29 @@ bool CompilerDriver::CanAccessTypeWithoutChecks(uint32_t referrer_idx, const Dex uint32_t type_idx, bool* type_known_final, bool* type_known_abstract, bool* equals_referrers_class) { - if (type_known_final != NULL) { + if (type_known_final != nullptr) { *type_known_final = false; } - if (type_known_abstract != NULL) { + if (type_known_abstract != nullptr) { *type_known_abstract = false; } - if (equals_referrers_class != NULL) { + if (equals_referrers_class != nullptr) { *equals_referrers_class = false; } ScopedObjectAccess soa(Thread::Current()); mirror::DexCache* dex_cache = Runtime::Current()->GetClassLinker()->FindDexCache(dex_file); // Get type from dex cache assuming it was populated by the verifier mirror::Class* resolved_class = dex_cache->GetResolvedType(type_idx); - if (resolved_class == NULL) { + if (resolved_class == nullptr) { stats_->TypeNeedsAccessCheck(); return false; // Unknown class needs access checks. } const DexFile::MethodId& method_id = dex_file.GetMethodId(referrer_idx); - if (equals_referrers_class != NULL) { + if (equals_referrers_class != nullptr) { *equals_referrers_class = (method_id.class_idx_ == type_idx); } mirror::Class* referrer_class = dex_cache->GetResolvedType(method_id.class_idx_); - if (referrer_class == NULL) { + if (referrer_class == nullptr) { stats_->TypeNeedsAccessCheck(); return false; // Incomplete referrer knowledge needs access check. } @@ -885,10 +884,10 @@ bool CompilerDriver::CanAccessTypeWithoutChecks(uint32_t referrer_idx, const Dex bool result = referrer_class->CanAccess(resolved_class); if (result) { stats_->TypeDoesntNeedAccessCheck(); - if (type_known_final != NULL) { + if (type_known_final != nullptr) { *type_known_final = resolved_class->IsFinal() && !resolved_class->IsArrayClass(); } - if (type_known_abstract != NULL) { + if (type_known_abstract != nullptr) { *type_known_abstract = resolved_class->IsAbstract() && !resolved_class->IsArrayClass(); } } else { @@ -904,13 +903,13 @@ bool CompilerDriver::CanAccessInstantiableTypeWithoutChecks(uint32_t referrer_id mirror::DexCache* dex_cache = Runtime::Current()->GetClassLinker()->FindDexCache(dex_file); // Get type from dex cache assuming it was populated by the verifier. mirror::Class* resolved_class = dex_cache->GetResolvedType(type_idx); - if (resolved_class == NULL) { + if (resolved_class == nullptr) { stats_->TypeNeedsAccessCheck(); return false; // Unknown class needs access checks. } const DexFile::MethodId& method_id = dex_file.GetMethodId(referrer_idx); mirror::Class* referrer_class = dex_cache->GetResolvedType(method_id.class_idx_); - if (referrer_class == NULL) { + if (referrer_class == nullptr) { stats_->TypeNeedsAccessCheck(); return false; // Incomplete referrer knowledge needs access check. } @@ -1310,6 +1309,10 @@ const VerifiedMethod* CompilerDriver::GetVerifiedMethod(const DexFile* dex_file, } bool CompilerDriver::IsSafeCast(const DexCompilationUnit* mUnit, uint32_t dex_pc) { + if (!compiler_options_->IsVerificationEnabled()) { + // If we didn't verify, every cast has to be treated as non-safe. + return false; + } DCHECK(mUnit->GetVerifiedMethod() != nullptr); bool result = mUnit->GetVerifiedMethod()->IsSafeCast(dex_pc); if (result) { @@ -1410,7 +1413,7 @@ class ParallelCompilationManager { thread_pool_(thread_pool) {} ClassLinker* GetClassLinker() const { - CHECK(class_linker_ != NULL); + CHECK(class_linker_ != nullptr); return class_linker_; } @@ -1419,12 +1422,12 @@ class ParallelCompilationManager { } CompilerDriver* GetCompiler() const { - CHECK(compiler_ != NULL); + CHECK(compiler_ != nullptr); return compiler_; } const DexFile* GetDexFile() const { - CHECK(dex_file_ != NULL); + CHECK(dex_file_ != nullptr); return dex_file_; } @@ -1499,10 +1502,10 @@ class ParallelCompilationManager { // that avoids the expensive FindInClassPath search. static bool SkipClass(jobject class_loader, const DexFile& dex_file, mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - DCHECK(klass != NULL); + DCHECK(klass != nullptr); const DexFile& original_dex_file = *klass->GetDexCache()->GetDexFile(); if (&dex_file != &original_dex_file) { - if (class_loader == NULL) { + if (class_loader == nullptr) { LOG(WARNING) << "Skipping class " << PrettyDescriptor(klass) << " from " << dex_file.GetLocation() << " previously found in " << original_dex_file.GetLocation(); @@ -1587,7 +1590,7 @@ static void ResolveClassFieldsAndMethods(const ParallelCompilationManager* manag // static fields, instance fields, direct methods, and virtual // methods. const byte* class_data = dex_file.GetClassData(class_def); - if (class_data == NULL) { + if (class_data == nullptr) { // Empty class such as a marker interface. requires_constructor_barrier = false; } else { @@ -1596,7 +1599,7 @@ static void ResolveClassFieldsAndMethods(const ParallelCompilationManager* manag if (resolve_fields_and_methods) { mirror::ArtField* field = class_linker->ResolveField(dex_file, it.GetMemberIndex(), dex_cache, class_loader, true); - if (field == NULL) { + if (field == nullptr) { CheckAndClearResolveException(soa.Self()); } } @@ -1611,7 +1614,7 @@ static void ResolveClassFieldsAndMethods(const ParallelCompilationManager* manag if (resolve_fields_and_methods) { mirror::ArtField* field = class_linker->ResolveField(dex_file, it.GetMemberIndex(), dex_cache, class_loader, false); - if (field == NULL) { + if (field == nullptr) { CheckAndClearResolveException(soa.Self()); } } @@ -1623,7 +1626,7 @@ static void ResolveClassFieldsAndMethods(const ParallelCompilationManager* manag dex_cache, class_loader, NullHandle<mirror::ArtMethod>(), it.GetMethodInvokeType(class_def)); - if (method == NULL) { + if (method == nullptr) { CheckAndClearResolveException(soa.Self()); } it.Next(); @@ -1633,7 +1636,7 @@ static void ResolveClassFieldsAndMethods(const ParallelCompilationManager* manag dex_cache, class_loader, NullHandle<mirror::ArtMethod>(), it.GetMethodInvokeType(class_def)); - if (method == NULL) { + if (method == nullptr) { CheckAndClearResolveException(soa.Self()); } it.Next(); @@ -1658,9 +1661,9 @@ static void ResolveType(const ParallelCompilationManager* manager, size_t type_i hs.NewHandle(soa.Decode<mirror::ClassLoader*>(manager->GetClassLoader()))); mirror::Class* klass = class_linker->ResolveType(dex_file, type_idx, dex_cache, class_loader); - if (klass == NULL) { + if (klass == nullptr) { CHECK(soa.Self()->IsExceptionPending()); - mirror::Throwable* exception = soa.Self()->GetException(NULL); + mirror::Throwable* exception = soa.Self()->GetException(nullptr); VLOG(compiler) << "Exception during type resolution: " << exception->Dump(); if (exception->GetClass()->DescriptorEquals("Ljava/lang/OutOfMemoryError;")) { // There's little point continuing compilation if the heap is exhausted. @@ -1691,11 +1694,20 @@ void CompilerDriver::ResolveDexFile(jobject class_loader, const DexFile& dex_fil context.ForAll(0, dex_file.NumClassDefs(), ResolveClassFieldsAndMethods, thread_count_); } +void CompilerDriver::SetVerified(jobject class_loader, const std::vector<const DexFile*>& dex_files, + ThreadPool* thread_pool, TimingLogger* timings) { + for (size_t i = 0; i != dex_files.size(); ++i) { + const DexFile* dex_file = dex_files[i]; + CHECK(dex_file != nullptr); + SetVerifiedDexFile(class_loader, *dex_file, dex_files, thread_pool, timings); + } +} + void CompilerDriver::Verify(jobject class_loader, const std::vector<const DexFile*>& dex_files, ThreadPool* thread_pool, TimingLogger* timings) { for (size_t i = 0; i != dex_files.size(); ++i) { const DexFile* dex_file = dex_files[i]; - CHECK(dex_file != NULL); + CHECK(dex_file != nullptr); VerifyDexFile(class_loader, *dex_file, dex_files, thread_pool, timings); } } @@ -1757,6 +1769,47 @@ void CompilerDriver::VerifyDexFile(jobject class_loader, const DexFile& dex_file context.ForAll(0, dex_file.NumClassDefs(), VerifyClass, thread_count_); } +static void SetVerifiedClass(const ParallelCompilationManager* manager, size_t class_def_index) + LOCKS_EXCLUDED(Locks::mutator_lock_) { + ATRACE_CALL(); + ScopedObjectAccess soa(Thread::Current()); + const DexFile& dex_file = *manager->GetDexFile(); + const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index); + const char* descriptor = dex_file.GetClassDescriptor(class_def); + ClassLinker* class_linker = manager->GetClassLinker(); + jobject jclass_loader = manager->GetClassLoader(); + StackHandleScope<3> hs(soa.Self()); + Handle<mirror::ClassLoader> class_loader( + hs.NewHandle(soa.Decode<mirror::ClassLoader*>(jclass_loader))); + Handle<mirror::Class> klass( + hs.NewHandle(class_linker->FindClass(soa.Self(), descriptor, class_loader))); + // Class might have failed resolution. Then don't set it to verified. + if (klass.Get() != nullptr) { + // Only do this if the class is resolved. If even resolution fails, quickening will go very, + // very wrong. + if (klass->IsResolved()) { + if (klass->GetStatus() < mirror::Class::kStatusVerified) { + ObjectLock<mirror::Class> lock(soa.Self(), klass); + klass->SetStatus(mirror::Class::kStatusVerified, soa.Self()); + } + // Record the final class status if necessary. + ClassReference ref(manager->GetDexFile(), class_def_index); + manager->GetCompiler()->RecordClassStatus(ref, klass->GetStatus()); + } + } + soa.Self()->AssertNoPendingException(); +} + +void CompilerDriver::SetVerifiedDexFile(jobject class_loader, const DexFile& dex_file, + const std::vector<const DexFile*>& dex_files, + ThreadPool* thread_pool, TimingLogger* timings) { + TimingLogger::ScopedTiming t("Verify Dex File", timings); + ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); + ParallelCompilationManager context(class_linker, class_loader, this, &dex_file, dex_files, + thread_pool); + context.ForAll(0, dex_file.NumClassDefs(), SetVerifiedClass, thread_count_); +} + static void InitializeClass(const ParallelCompilationManager* manager, size_t class_def_index) LOCKS_EXCLUDED(Locks::mutator_lock_) { ATRACE_CALL(); @@ -1865,7 +1918,7 @@ void CompilerDriver::InitializeClasses(jobject class_loader, ThreadPool* thread_pool, TimingLogger* timings) { for (size_t i = 0; i != dex_files.size(); ++i) { const DexFile* dex_file = dex_files[i]; - CHECK(dex_file != NULL); + CHECK(dex_file != nullptr); InitializeClasses(class_loader, *dex_file, dex_files, thread_pool, timings); } if (IsImage()) { @@ -1878,7 +1931,7 @@ void CompilerDriver::Compile(jobject class_loader, const std::vector<const DexFi ThreadPool* thread_pool, TimingLogger* timings) { for (size_t i = 0; i != dex_files.size(); ++i) { const DexFile* dex_file = dex_files[i]; - CHECK(dex_file != NULL); + CHECK(dex_file != nullptr); CompileDexFile(class_loader, *dex_file, dex_files, thread_pool, timings); } } @@ -1911,7 +1964,7 @@ void CompilerDriver::CompileClass(const ParallelCompilationManager* manager, siz return; } const byte* class_data = dex_file.GetClassData(class_def); - if (class_data == NULL) { + if (class_data == nullptr) { // empty class, probably a marker interface return; } @@ -1984,7 +2037,7 @@ void CompilerDriver::CompileMethod(const DexFile::CodeItem* code_item, uint32_t uint32_t method_idx, jobject class_loader, const DexFile& dex_file, DexToDexCompilationLevel dex_to_dex_compilation_level) { - CompiledMethod* compiled_method = NULL; + CompiledMethod* compiled_method = nullptr; uint64_t start_ns = kTimeCompileMethod ? NanoTime() : 0; if ((access_flags & kAccNative) != 0) { @@ -1994,14 +2047,14 @@ void CompilerDriver::CompileMethod(const DexFile::CodeItem* code_item, uint32_t // Leaving this empty will trigger the generic JNI version } else { compiled_method = compiler_->JniCompile(access_flags, method_idx, dex_file); - CHECK(compiled_method != NULL); + CHECK(compiled_method != nullptr); } } else if ((access_flags & kAccAbstract) != 0) { } else { MethodReference method_ref(&dex_file, method_idx); bool compile = verification_results_->IsCandidateForCompilation(method_ref, access_flags); if (compile) { - // NOTE: if compiler declines to compile this method, it will return NULL. + // NOTE: if compiler declines to compile this method, it will return nullptr. compiled_method = compiler_->Compile(code_item, access_flags, invoke_type, class_def_idx, method_idx, class_loader, dex_file); } @@ -2022,20 +2075,20 @@ void CompilerDriver::CompileMethod(const DexFile::CodeItem* code_item, uint32_t } Thread* self = Thread::Current(); - if (compiled_method != NULL) { + if (compiled_method != nullptr) { MethodReference ref(&dex_file, method_idx); - DCHECK(GetCompiledMethod(ref) == NULL) << PrettyMethod(method_idx, dex_file); + DCHECK(GetCompiledMethod(ref) == nullptr) << PrettyMethod(method_idx, dex_file); { MutexLock mu(self, compiled_methods_lock_); compiled_methods_.Put(ref, compiled_method); } - DCHECK(GetCompiledMethod(ref) != NULL) << PrettyMethod(method_idx, dex_file); + DCHECK(GetCompiledMethod(ref) != nullptr) << PrettyMethod(method_idx, dex_file); } if (self->IsExceptionPending()) { ScopedObjectAccess soa(self); LOG(FATAL) << "Unexpected exception compiling: " << PrettyMethod(method_idx, dex_file) << "\n" - << self->GetException(NULL)->Dump(); + << self->GetException(nullptr)->Dump(); } } @@ -2043,9 +2096,9 @@ CompiledClass* CompilerDriver::GetCompiledClass(ClassReference ref) const { MutexLock mu(Thread::Current(), compiled_classes_lock_); ClassTable::const_iterator it = compiled_classes_.find(ref); if (it == compiled_classes_.end()) { - return NULL; + return nullptr; } - CHECK(it->second != NULL); + CHECK(it->second != nullptr); return it->second; } @@ -2079,9 +2132,9 @@ CompiledMethod* CompilerDriver::GetCompiledMethod(MethodReference ref) const { MutexLock mu(Thread::Current(), compiled_methods_lock_); MethodTable::const_iterator it = compiled_methods_.find(ref); if (it == compiled_methods_.end()) { - return NULL; + return nullptr; } - CHECK(it->second != NULL); + CHECK(it->second != nullptr); return it->second; } diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h index 624947d..3c76098 100644 --- a/compiler/driver/compiler_driver.h +++ b/compiler/driver/compiler_driver.h @@ -81,7 +81,7 @@ class CompilerDriver { // Create a compiler targeting the requested "instruction_set". // "image" should be true if image specific optimizations should be // enabled. "image_classes" lets the compiler know what classes it - // can assume will be in the image, with NULL implying all available + // can assume will be in the image, with nullptr implying all available // classes. explicit CompilerDriver(const CompilerOptions* compiler_options, VerificationResults* verification_results, @@ -183,9 +183,9 @@ class CompilerDriver { // Are runtime access checks necessary in the compiled code? bool CanAccessTypeWithoutChecks(uint32_t referrer_idx, const DexFile& dex_file, - uint32_t type_idx, bool* type_known_final = NULL, - bool* type_known_abstract = NULL, - bool* equals_referrers_class = NULL) + uint32_t type_idx, bool* type_known_final = nullptr, + bool* type_known_abstract = nullptr, + bool* equals_referrers_class = nullptr) LOCKS_EXCLUDED(Locks::mutator_lock_); // Are runtime access and instantiable checks necessary in the code? @@ -436,7 +436,7 @@ class CompilerDriver { referrer_class_def_idx_(referrer_class_def_idx), referrer_method_idx_(referrer_method_idx), literal_offset_(literal_offset) { - CHECK(dex_file_ != NULL); + CHECK(dex_file_ != nullptr); } virtual ~PatchInformation() {} @@ -655,6 +655,13 @@ class CompilerDriver { ThreadPool* thread_pool, TimingLogger* timings) LOCKS_EXCLUDED(Locks::mutator_lock_); + void SetVerified(jobject class_loader, const std::vector<const DexFile*>& dex_files, + ThreadPool* thread_pool, TimingLogger* timings); + void SetVerifiedDexFile(jobject class_loader, const DexFile& dex_file, + const std::vector<const DexFile*>& dex_files, + ThreadPool* thread_pool, TimingLogger* timings) + LOCKS_EXCLUDED(Locks::mutator_lock_); + void InitializeClasses(jobject class_loader, const std::vector<const DexFile*>& dex_files, ThreadPool* thread_pool, TimingLogger* timings) LOCKS_EXCLUDED(Locks::mutator_lock_); @@ -712,7 +719,7 @@ class CompilerDriver { const bool image_; // If image_ is true, specifies the classes that will be included in - // the image. Note if image_classes_ is NULL, all classes are + // the image. Note if image_classes_ is nullptr, all classes are // included in the image. std::unique_ptr<std::set<std::string>> image_classes_; diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc index f1c0063..1cf7757 100644 --- a/oatdump/oatdump.cc +++ b/oatdump/oatdump.cc @@ -417,7 +417,7 @@ class OatDumper { for (size_t i = 0; i < oat_dex_files_.size(); i++) { const OatFile::OatDexFile* oat_dex_file = oat_dex_files_[i]; - CHECK(oat_dex_file != NULL); + CHECK(oat_dex_file != nullptr); DumpOatDexFile(os, *oat_dex_file); } } @@ -451,7 +451,7 @@ class OatDumper { } else { const DexFile::ClassDef* class_def = dex_file->FindClassDef(m->GetDeclaringClassDescriptor()); - if (class_def != NULL) { + if (class_def != nullptr) { uint16_t class_def_index = dex_file->GetIndexForClassDef(*class_def); const OatFile::OatClass oat_class = oat_dex_file->GetOatClass(class_def_index); size_t method_index = m->GetMethodIndex(); @@ -459,7 +459,7 @@ class OatDumper { } } } - return NULL; + return nullptr; } private: @@ -470,7 +470,7 @@ class OatDumper { // of a piece of code by using upper_bound to find the start of the next region. for (size_t i = 0; i < oat_dex_files_.size(); i++) { const OatFile::OatDexFile* oat_dex_file = oat_dex_files_[i]; - CHECK(oat_dex_file != NULL); + CHECK(oat_dex_file != nullptr); std::string error_msg; std::unique_ptr<const DexFile> dex_file(oat_dex_file->OpenDexFile(&error_msg)); if (dex_file.get() == nullptr) { @@ -485,7 +485,7 @@ class OatDumper { const DexFile::ClassDef& class_def = dex_file->GetClassDef(class_def_index); const OatFile::OatClass oat_class = oat_dex_file->GetOatClass(class_def_index); const byte* class_data = dex_file->GetClassData(class_def); - if (class_data != NULL) { + if (class_data != nullptr) { ClassDataItemIterator it(*dex_file, class_data); SkipAllFields(it); uint32_t class_method_index = 0; @@ -527,7 +527,7 @@ class OatDumper { std::string error_msg; std::unique_ptr<const DexFile> dex_file(oat_dex_file.OpenDexFile(&error_msg)); - if (dex_file.get() == NULL) { + if (dex_file.get() == nullptr) { os << "NOT FOUND: " << error_msg << "\n\n"; return; } @@ -561,7 +561,7 @@ class OatDumper { void DumpOatClass(std::ostream& os, const OatFile::OatClass& oat_class, const DexFile& dex_file, const DexFile::ClassDef& class_def) { const byte* class_data = dex_file.GetClassData(class_def); - if (class_data == NULL) { // empty class such as a marker interface? + if (class_data == nullptr) { // empty class such as a marker interface? return; } ClassDataItemIterator it(dex_file, class_data); @@ -601,10 +601,12 @@ class OatDumper { *indent1_os << "DEX CODE:\n"; DumpDexCode(*indent2_os, dex_file, code_item); } - if (Runtime::Current() != NULL) { + + std::unique_ptr<verifier::MethodVerifier> verifier; + if (Runtime::Current() != nullptr) { *indent1_os << "VERIFIER TYPE ANALYSIS:\n"; - DumpVerifier(*indent2_os, dex_method_idx, &dex_file, class_def, code_item, - method_access_flags); + verifier.reset(DumpVerifier(*indent2_os, dex_method_idx, &dex_file, class_def, code_item, + method_access_flags)); } { *indent1_os << "OAT DATA:\n"; @@ -650,22 +652,7 @@ class OatDumper { code_size, code != nullptr ? "..." : ""); - Runtime* runtime = Runtime::Current(); - if (runtime != nullptr) { - ScopedObjectAccess soa(Thread::Current()); - StackHandleScope<1> hs(soa.Self()); - Handle<mirror::DexCache> dex_cache( - hs.NewHandle(runtime->GetClassLinker()->FindDexCache(dex_file))); - verifier::MethodVerifier verifier(soa.Self(), &dex_file, dex_cache, - NullHandle<mirror::ClassLoader>(), - &class_def, code_item, dex_method_idx, - NullHandle<mirror::ArtMethod>(), method_access_flags, - true, true, true); - verifier.Verify(); - DumpCode(*indent2_os, &verifier, oat_method, code_item); - } else { - DumpCode(*indent2_os, nullptr, oat_method, code_item); - } + DumpCode(*indent2_os, verifier.get(), oat_method, code_item); } } @@ -694,7 +681,7 @@ class OatDumper { void DumpVmap(std::ostream& os, const OatFile::OatMethod& oat_method) { const uint8_t* raw_table = oat_method.GetVmapTable(); - if (raw_table != NULL) { + if (raw_table != nullptr) { const VmapTable vmap_table(raw_table); bool first = true; bool processing_fp = false; @@ -761,7 +748,7 @@ class OatDumper { void DescribeVReg(std::ostream& os, const OatFile::OatMethod& oat_method, const DexFile::CodeItem* code_item, size_t reg, VRegKind kind) { const uint8_t* raw_table = oat_method.GetVmapTable(); - if (raw_table != NULL) { + if (raw_table != nullptr) { const VmapTable vmap_table(raw_table); uint32_t vmap_offset; if (vmap_table.IsInContext(reg, kind, &vmap_offset)) { @@ -884,7 +871,7 @@ class OatDumper { void DumpGcMapAtNativePcOffset(std::ostream& os, const OatFile::OatMethod& oat_method, const DexFile::CodeItem* code_item, size_t native_pc_offset) { const uint8_t* gc_map_raw = oat_method.GetNativeGcMap(); - if (gc_map_raw != NULL) { + if (gc_map_raw != nullptr) { NativePcOffsetToReferenceMap map(gc_map_raw); if (map.HasEntry(native_pc_offset)) { size_t num_regs = map.RegWidth() * 8; @@ -949,7 +936,7 @@ class OatDumper { void DumpDexCode(std::ostream& os, const DexFile& dex_file, const DexFile::CodeItem* code_item) { - if (code_item != NULL) { + if (code_item != nullptr) { size_t i = 0; while (i < code_item->insns_size_in_code_units_) { const Instruction* instruction = Instruction::At(&code_item->insns_[i]); @@ -959,20 +946,25 @@ class OatDumper { } } - void DumpVerifier(std::ostream& os, uint32_t dex_method_idx, const DexFile* dex_file, - const DexFile::ClassDef& class_def, const DexFile::CodeItem* code_item, - uint32_t method_access_flags) { + verifier::MethodVerifier* DumpVerifier(std::ostream& os, uint32_t dex_method_idx, + const DexFile* dex_file, + const DexFile::ClassDef& class_def, + const DexFile::CodeItem* code_item, + uint32_t method_access_flags) { if ((method_access_flags & kAccNative) == 0) { ScopedObjectAccess soa(Thread::Current()); StackHandleScope<1> hs(soa.Self()); Handle<mirror::DexCache> dex_cache( hs.NewHandle(Runtime::Current()->GetClassLinker()->FindDexCache(*dex_file))); - verifier::MethodVerifier::VerifyMethodAndDump(soa.Self(), os, dex_method_idx, dex_file, - dex_cache, NullHandle<mirror::ClassLoader>(), - &class_def, code_item, - NullHandle<mirror::ArtMethod>(), - method_access_flags); + return verifier::MethodVerifier::VerifyMethodAndDump(soa.Self(), os, dex_method_idx, dex_file, + dex_cache, + NullHandle<mirror::ClassLoader>(), + &class_def, code_item, + NullHandle<mirror::ArtMethod>(), + method_access_flags); } + + return nullptr; } void DumpCode(std::ostream& os, verifier::MethodVerifier* verifier, @@ -1073,7 +1065,7 @@ class ImageDumper { indent2_os << StringPrintf("%d to %zd: ", i, i + run); i = i + run; } - if (value != NULL) { + if (value != nullptr) { PrettyObjectValue(indent2_os, value->GetClass(), value); } else { indent2_os << i << ": null\n"; @@ -1092,7 +1084,7 @@ class ImageDumper { std::string error_msg; const OatFile* oat_file = class_linker->FindOpenedOatFileFromOatLocation(oat_location); if (oat_file == nullptr) { - oat_file = OatFile::Open(oat_location, oat_location, NULL, false, &error_msg); + oat_file = OatFile::Open(oat_location, oat_location, nullptr, false, &error_msg); if (oat_file == nullptr) { os << "NOT FOUND: " << error_msg << "\n"; return; @@ -1106,7 +1098,7 @@ class ImageDumper { dump_raw_gc_map_)); for (const OatFile::OatDexFile* oat_dex_file : oat_file->GetOatDexFiles()) { - CHECK(oat_dex_file != NULL); + CHECK(oat_dex_file != nullptr); stats_.oat_dex_file_sizes.push_back(std::make_pair(oat_dex_file->GetDexFileLocation(), oat_dex_file->FileSize())); } @@ -1154,10 +1146,10 @@ class ImageDumper { } os << "STATS:\n" << std::flush; std::unique_ptr<File> file(OS::OpenFileForReading(image_filename.c_str())); - if (file.get() == NULL) { + if (file.get() == nullptr) { LOG(WARNING) << "Failed to find image in " << image_filename; } - if (file.get() != NULL) { + if (file.get() != nullptr) { stats_.file_bytes = file->GetLength(); } size_t header_bytes = sizeof(ImageHeader); @@ -1177,8 +1169,8 @@ class ImageDumper { private: static void PrettyObjectValue(std::ostream& os, mirror::Class* type, mirror::Object* value) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - CHECK(type != NULL); - if (value == NULL) { + CHECK(type != nullptr); + if (value == nullptr) { os << StringPrintf("null %s\n", PrettyDescriptor(type).c_str()); } else if (type->IsStringClass()) { mirror::String* string = value->AsString(); @@ -1231,14 +1223,14 @@ class ImageDumper { // Get the value, don't compute the type unless it is non-null as we don't want // to cause class loading. mirror::Object* value = field->GetObj(obj); - if (value == NULL) { + if (value == nullptr) { os << StringPrintf("null %s\n", PrettyDescriptor(descriptor).c_str()); } else { // Grab the field type without causing resolution. StackHandleScope<1> hs(Thread::Current()); FieldHelper fh(hs.NewHandle(field)); mirror::Class* field_type = fh.GetType(false); - if (field_type != NULL) { + if (field_type != nullptr) { PrettyObjectValue(os, field_type, value); } else { os << StringPrintf("%p %s\n", value, PrettyDescriptor(descriptor).c_str()); @@ -1250,11 +1242,11 @@ class ImageDumper { static void DumpFields(std::ostream& os, mirror::Object* obj, mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { mirror::Class* super = klass->GetSuperClass(); - if (super != NULL) { + if (super != nullptr) { DumpFields(os, obj, super); } mirror::ObjectArray<mirror::ArtField>* fields = klass->GetIFields(); - if (fields != NULL) { + if (fields != nullptr) { for (int32_t i = 0; i < fields->GetLength(); i++) { mirror::ArtField* field = fields->Get(i); PrintField(os, field, obj); @@ -1290,16 +1282,16 @@ class ImageDumper { const void* GetQuickOatCodeEnd(mirror::ArtMethod* m) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { const uint8_t* oat_code_begin = reinterpret_cast<const uint8_t*>(GetQuickOatCodeBegin(m)); - if (oat_code_begin == NULL) { - return NULL; + if (oat_code_begin == nullptr) { + return nullptr; } return oat_code_begin + GetQuickOatCodeSize(m); } static void Callback(mirror::Object* obj, void* arg) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - DCHECK(obj != NULL); - DCHECK(arg != NULL); + DCHECK(obj != nullptr); + DCHECK(arg != nullptr); ImageDumper* state = reinterpret_cast<ImageDumper*>(arg); if (!state->InDumpSpace(obj)) { return; @@ -1354,12 +1346,12 @@ class ImageDumper { i = i + run; } mirror::Class* value_class = - (value == NULL) ? obj_class->GetComponentType() : value->GetClass(); + (value == nullptr) ? obj_class->GetComponentType() : value->GetClass(); PrettyObjectValue(indent_os, value_class, value); } } else if (obj->IsClass()) { mirror::ObjectArray<mirror::ArtField>* sfields = obj->AsClass()->GetSFields(); - if (sfields != NULL) { + if (sfields != nullptr) { indent_os << "STATICS:\n"; Indenter indent2_filter(indent_os.rdbuf(), kIndentChar, kIndentBy1Count); std::ostream indent2_os(&indent2_filter); @@ -1387,8 +1379,8 @@ class ImageDumper { } else if (method->IsAbstract() || method->IsCalleeSaveMethod() || method->IsResolutionMethod() || method->IsImtConflictMethod() || method->IsClassInitializer()) { - DCHECK(method->GetNativeGcMap() == NULL) << PrettyMethod(method); - DCHECK(method->GetMappingTable() == NULL) << PrettyMethod(method); + DCHECK(method->GetNativeGcMap() == nullptr) << PrettyMethod(method); + DCHECK(method->GetMappingTable() == nullptr) << PrettyMethod(method); } else { const DexFile::CodeItem* code_item = method->GetCodeItem(); size_t dex_instruction_bytes = code_item->insns_size_in_code_units_ * 2; @@ -1757,9 +1749,9 @@ static int oatdump(int argc, char** argv) { usage(); } - const char* oat_filename = NULL; - const char* image_location = NULL; - const char* boot_image_location = NULL; + const char* oat_filename = nullptr; + const char* image_location = nullptr; + const char* boot_image_location = nullptr; InstructionSet instruction_set = kRuntimeISA; std::string elf_filename_prefix; std::ostream* os = &std::cout; @@ -1817,21 +1809,21 @@ static int oatdump(int argc, char** argv) { } } - if (image_location == NULL && oat_filename == NULL) { + if (image_location == nullptr && oat_filename == nullptr) { fprintf(stderr, "Either --image or --oat must be specified\n"); return EXIT_FAILURE; } - if (image_location != NULL && oat_filename != NULL) { + if (image_location != nullptr && oat_filename != nullptr) { fprintf(stderr, "Either --image or --oat must be specified but not both\n"); return EXIT_FAILURE; } - if (oat_filename != NULL) { + if (oat_filename != nullptr) { std::string error_msg; OatFile* oat_file = - OatFile::Open(oat_filename, oat_filename, NULL, false, &error_msg); - if (oat_file == NULL) { + OatFile::Open(oat_filename, oat_filename, nullptr, false, &error_msg); + if (oat_file == nullptr) { fprintf(stderr, "Failed to open oat file from '%s': %s\n", oat_filename, error_msg.c_str()); return EXIT_FAILURE; } @@ -1862,15 +1854,15 @@ static int oatdump(int argc, char** argv) { NoopCompilerCallbacks callbacks; options.push_back(std::make_pair("compilercallbacks", &callbacks)); - if (boot_image_location != NULL) { + if (boot_image_location != nullptr) { boot_image_option += "-Ximage:"; boot_image_option += boot_image_location; - options.push_back(std::make_pair(boot_image_option.c_str(), reinterpret_cast<void*>(NULL))); + options.push_back(std::make_pair(boot_image_option.c_str(), nullptr)); } - if (image_location != NULL) { + if (image_location != nullptr) { image_option += "-Ximage:"; image_option += image_location; - options.push_back(std::make_pair(image_option.c_str(), reinterpret_cast<void*>(NULL))); + options.push_back(std::make_pair(image_option.c_str(), nullptr)); } options.push_back( std::make_pair("imageinstructionset", @@ -1887,7 +1879,7 @@ static int oatdump(int argc, char** argv) { ScopedObjectAccess soa(Thread::Current()); gc::Heap* heap = Runtime::Current()->GetHeap(); gc::space::ImageSpace* image_space = heap->GetImageSpace(); - CHECK(image_space != NULL); + CHECK(image_space != nullptr); const ImageHeader& image_header = image_space->GetImageHeader(); if (!image_header.IsValid()) { fprintf(stderr, "Invalid image header %s\n", image_location); diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 6a6286f..74b262f 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -120,7 +120,7 @@ static void WrapExceptionInInitializer() SHARED_LOCKS_REQUIRED(Locks::mutator_lo JNIEnv* env = self->GetJniEnv(); ScopedLocalRef<jthrowable> cause(env, env->ExceptionOccurred()); - CHECK(cause.get() != NULL); + CHECK(cause.get() != nullptr); env->ExceptionClear(); bool is_error = env->IsInstanceOf(cause.get(), WellKnownClasses::java_lang_Error); @@ -129,7 +129,8 @@ static void WrapExceptionInInitializer() SHARED_LOCKS_REQUIRED(Locks::mutator_lo // We only wrap non-Error exceptions; an Error can just be used as-is. if (!is_error) { ThrowLocation throw_location = self->GetCurrentLocationForThrow(); - self->ThrowNewWrappedException(throw_location, "Ljava/lang/ExceptionInInitializerError;", NULL); + self->ThrowNewWrappedException(throw_location, "Ljava/lang/ExceptionInInitializerError;", + nullptr); } } @@ -306,7 +307,7 @@ void ClassLinker::InitWithoutImage(const std::vector<const DexFile*>& boot_class heap->AllocNonMovableObject<true>(self, nullptr, mirror::Class::ClassClassSize(), VoidFunctor())))); - CHECK(java_lang_Class.Get() != NULL); + CHECK(java_lang_Class.Get() != nullptr); mirror::Class::SetClassClass(java_lang_Class.Get()); java_lang_Class->SetClass(java_lang_Class.Get()); if (kUseBakerOrBrooksReadBarrier) { @@ -324,7 +325,7 @@ void ClassLinker::InitWithoutImage(const std::vector<const DexFile*>& boot_class // java_lang_Object comes next so that object_array_class can be created. Handle<mirror::Class> java_lang_Object(hs.NewHandle( AllocClass(self, java_lang_Class.Get(), mirror::Object::ClassSize()))); - CHECK(java_lang_Object.Get() != NULL); + CHECK(java_lang_Object.Get() != nullptr); // backfill Object as the super class of Class. java_lang_Class->SetSuperClass(java_lang_Object.Get()); java_lang_Object->SetStatus(mirror::Class::kStatusLoaded, self); @@ -405,7 +406,7 @@ void ClassLinker::InitWithoutImage(const std::vector<const DexFile*>& boot_class // that FindClass can link members. Handle<mirror::Class> java_lang_reflect_ArtField(hs.NewHandle( AllocClass(self, java_lang_Class.Get(), mirror::ArtField::ClassSize()))); - CHECK(java_lang_reflect_ArtField.Get() != NULL); + CHECK(java_lang_reflect_ArtField.Get() != nullptr); java_lang_reflect_ArtField->SetObjectSize(mirror::ArtField::InstanceSize()); SetClassRoot(kJavaLangReflectArtField, java_lang_reflect_ArtField.Get()); java_lang_reflect_ArtField->SetStatus(mirror::Class::kStatusResolved, self); @@ -413,7 +414,7 @@ void ClassLinker::InitWithoutImage(const std::vector<const DexFile*>& boot_class Handle<mirror::Class> java_lang_reflect_ArtMethod(hs.NewHandle( AllocClass(self, java_lang_Class.Get(), mirror::ArtMethod::ClassSize()))); - CHECK(java_lang_reflect_ArtMethod.Get() != NULL); + CHECK(java_lang_reflect_ArtMethod.Get() != nullptr); java_lang_reflect_ArtMethod->SetObjectSize(mirror::ArtMethod::InstanceSize()); SetClassRoot(kJavaLangReflectArtMethod, java_lang_reflect_ArtMethod.Get()); java_lang_reflect_ArtMethod->SetStatus(mirror::Class::kStatusResolved, self); @@ -445,7 +446,7 @@ void ClassLinker::InitWithoutImage(const std::vector<const DexFile*>& boot_class CHECK_NE(0U, boot_class_path.size()); for (size_t i = 0; i != boot_class_path.size(); ++i) { const DexFile* dex_file = boot_class_path[i]; - CHECK(dex_file != NULL); + CHECK(dex_file != nullptr); AppendToBootClassPath(self, *dex_file); } @@ -522,9 +523,9 @@ void ClassLinker::InitWithoutImage(const std::vector<const DexFile*>& boot_class // Setup the single, global copy of "iftable". mirror::Class* java_lang_Cloneable = FindSystemClass(self, "Ljava/lang/Cloneable;"); - CHECK(java_lang_Cloneable != NULL); + CHECK(java_lang_Cloneable != nullptr); mirror::Class* java_io_Serializable = FindSystemClass(self, "Ljava/io/Serializable;"); - CHECK(java_io_Serializable != NULL); + CHECK(java_io_Serializable != nullptr); // We assume that Cloneable/Serializable don't have superinterfaces -- normally we'd have to // crawl up and explicitly list all of the supers as well. { @@ -652,8 +653,8 @@ void ClassLinker::FinishInit(Thread* self) { for (size_t i = 0; i < kClassRootsMax; i++) { ClassRoot class_root = static_cast<ClassRoot>(i); mirror::Class* klass = GetClassRoot(class_root); - CHECK(klass != NULL); - DCHECK(klass->IsArrayClass() || klass->IsPrimitive() || klass->GetDexCache() != NULL); + CHECK(klass != nullptr); + DCHECK(klass->IsArrayClass() || klass->IsPrimitive() || klass->GetDexCache() != nullptr); // note SetClassRoot does additional validation. // if possible add new checks there to catch errors early } @@ -1051,7 +1052,7 @@ const OatFile* ClassLinker::FindOatFileInOatLocationForDexFile(const char* dex_l uint32_t dex_location_checksum, const char* oat_location, std::string* error_msg) { - std::unique_ptr<OatFile> oat_file(OatFile::Open(oat_location, oat_location, NULL, + std::unique_ptr<OatFile> oat_file(OatFile::Open(oat_location, oat_location, nullptr, !Runtime::Current()->IsCompiler(), error_msg)); if (oat_file.get() == nullptr) { @@ -1123,7 +1124,7 @@ const OatFile* ClassLinker::CreateOatFileForDexLocation(const char* dex_location error_msgs->push_back(error_msg); return nullptr; } - std::unique_ptr<OatFile> oat_file(OatFile::Open(oat_location, oat_location, NULL, + std::unique_ptr<OatFile> oat_file(OatFile::Open(oat_location, oat_location, nullptr, !Runtime::Current()->IsCompiler(), &error_msg)); if (oat_file.get() == nullptr) { @@ -1209,7 +1210,7 @@ bool ClassLinker::VerifyOatAndDexFileChecksums(const OatFile* oat_file, const OatFile::OatDexFile* oat_dex_file = oat_file->GetOatDexFile(dex_location, &dex_location_checksum); - if (oat_dex_file == NULL) { + if (oat_dex_file == nullptr) { *error_msg = StringPrintf("oat file '%s' does not contain contents for '%s' with checksum 0x%x", oat_file->GetLocation().c_str(), dex_location, dex_location_checksum); for (const OatFile::OatDexFile* oat_dex_file : oat_file->GetOatDexFiles()) { @@ -1236,7 +1237,7 @@ bool ClassLinker::VerifyOatWithDexFile(const OatFile* oat_file, // If no classes.dex found in dex_location, it has been stripped or is corrupt, assume oat is // up-to-date. This is the common case in user builds for jar's and apk's in the /system // directory. - const OatFile::OatDexFile* oat_dex_file = oat_file->GetOatDexFile(dex_location, NULL); + const OatFile::OatDexFile* oat_dex_file = oat_file->GetOatDexFile(dex_location, nullptr); if (oat_dex_file == nullptr) { *error_msg = StringPrintf("Dex checksum mismatch for location '%s' and failed to find oat " "dex file '%s': %s", oat_file->GetLocation().c_str(), dex_location, @@ -1369,7 +1370,7 @@ const OatFile* ClassLinker::OpenOatFileFromDexLocation(const std::string& dex_lo { // There is a high probability that these both these oat files map similar/the same address // spaces so we must scope them like this so they each gets its turn. - std::unique_ptr<OatFile> odex_oat_file(OatFile::Open(odex_filename, odex_filename, NULL, + std::unique_ptr<OatFile> odex_oat_file(OatFile::Open(odex_filename, odex_filename, nullptr, executable, &odex_error_msg)); if (odex_oat_file.get() != nullptr && CheckOatFile(odex_oat_file.get(), isa, &odex_checksum_verified, @@ -1391,7 +1392,7 @@ const OatFile* ClassLinker::OpenOatFileFromDexLocation(const std::string& dex_lo bool should_patch_cache = false; bool cache_checksum_verified = false; if (have_dalvik_cache) { - std::unique_ptr<OatFile> cache_oat_file(OatFile::Open(cache_filename, cache_filename, NULL, + std::unique_ptr<OatFile> cache_oat_file(OatFile::Open(cache_filename, cache_filename, nullptr, executable, &cache_error_msg)); if (cache_oat_file.get() != nullptr && CheckOatFile(cache_oat_file.get(), isa, &cache_checksum_verified, @@ -1468,7 +1469,7 @@ const OatFile* ClassLinker::GetInterpretedOnlyOat(const std::string& oat_path, InstructionSet isa, std::string* error_msg) { // We open it non-executable - std::unique_ptr<OatFile> output(OatFile::Open(oat_path, oat_path, NULL, false, error_msg)); + std::unique_ptr<OatFile> output(OatFile::Open(oat_path, oat_path, nullptr, false, error_msg)); if (output.get() == nullptr) { return nullptr; } @@ -1523,7 +1524,7 @@ const OatFile* ClassLinker::PatchAndRetrieveOat(const std::string& input_oat, LOG(INFO) << "Relocate Oat File: " << command_line; bool success = Exec(argv, error_msg); if (success) { - std::unique_ptr<OatFile> output(OatFile::Open(output_oat, output_oat, NULL, + std::unique_ptr<OatFile> output(OatFile::Open(output_oat, output_oat, nullptr, !Runtime::Current()->IsCompiler(), error_msg)); bool checksum_verified = false; if (output.get() != nullptr && CheckOatFile(output.get(), isa, &checksum_verified, error_msg)) { @@ -1632,20 +1633,16 @@ const OatFile* ClassLinker::FindOatFileFromOatLocation(const std::string& oat_lo return oat_file; } - oat_file = OatFile::Open(oat_location, oat_location, NULL, !Runtime::Current()->IsCompiler(), - error_msg); - if (oat_file == NULL) { - return NULL; - } - return oat_file; + return OatFile::Open(oat_location, oat_location, nullptr, !Runtime::Current()->IsCompiler(), + error_msg); } static void InitFromImageInterpretOnlyCallback(mirror::Object* obj, void* arg) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { ClassLinker* class_linker = reinterpret_cast<ClassLinker*>(arg); - DCHECK(obj != NULL); - DCHECK(class_linker != NULL); + DCHECK(obj != nullptr); + DCHECK(class_linker != nullptr); if (obj->IsArtMethod()) { mirror::ArtMethod* method = obj->AsArtMethod(); @@ -1667,7 +1664,7 @@ void ClassLinker::InitFromImage() { gc::Heap* heap = Runtime::Current()->GetHeap(); gc::space::ImageSpace* space = heap->GetImageSpace(); dex_cache_image_class_lookup_required_ = true; - CHECK(space != NULL); + CHECK(space != nullptr); OatFile& oat_file = GetImageOatFile(space); CHECK_EQ(oat_file.GetOatHeader().GetImageFileLocationOatChecksum(), 0U); CHECK_EQ(oat_file.GetOatHeader().GetImageFileLocationOatDataBegin(), 0U); @@ -1702,10 +1699,10 @@ void ClassLinker::InitFromImage() { const std::string& dex_file_location(dex_cache->GetLocation()->ToModifiedUtf8()); const OatFile::OatDexFile* oat_dex_file = oat_file.GetOatDexFile(dex_file_location.c_str(), nullptr); - CHECK(oat_dex_file != NULL) << oat_file.GetLocation() << " " << dex_file_location; + CHECK(oat_dex_file != nullptr) << oat_file.GetLocation() << " " << dex_file_location; std::string error_msg; const DexFile* dex_file = oat_dex_file->OpenDexFile(&error_msg); - if (dex_file == NULL) { + if (dex_file == nullptr) { LOG(FATAL) << "Failed to open dex file " << dex_file_location << " from within oat file " << oat_file.GetLocation() << " error '" << error_msg << "'"; @@ -1940,33 +1937,33 @@ mirror::DexCache* ClassLinker::AllocDexCache(Thread* self, const DexFile& dex_fi hs.NewHandle(down_cast<mirror::DexCache*>( heap->AllocObject<true>(self, dex_cache_class.Get(), dex_cache_class->GetObjectSize(), VoidFunctor())))); - if (dex_cache.Get() == NULL) { - return NULL; + if (dex_cache.Get() == nullptr) { + return nullptr; } Handle<mirror::String> location(hs.NewHandle(intern_table_->InternStrong(dex_file.GetLocation().c_str()))); - if (location.Get() == NULL) { - return NULL; + if (location.Get() == nullptr) { + return nullptr; } Handle<mirror::ObjectArray<mirror::String>> strings(hs.NewHandle(AllocStringArray(self, dex_file.NumStringIds()))); - if (strings.Get() == NULL) { - return NULL; + if (strings.Get() == nullptr) { + return nullptr; } Handle<mirror::ObjectArray<mirror::Class>> types(hs.NewHandle(AllocClassArray(self, dex_file.NumTypeIds()))); - if (types.Get() == NULL) { - return NULL; + if (types.Get() == nullptr) { + return nullptr; } Handle<mirror::ObjectArray<mirror::ArtMethod>> methods(hs.NewHandle(AllocArtMethodArray(self, dex_file.NumMethodIds()))); - if (methods.Get() == NULL) { - return NULL; + if (methods.Get() == nullptr) { + return nullptr; } Handle<mirror::ObjectArray<mirror::ArtField>> fields(hs.NewHandle(AllocArtFieldArray(self, dex_file.NumFieldIds()))); - if (fields.Get() == NULL) { - return NULL; + if (fields.Get() == nullptr) { + return nullptr; } dex_cache->Init(&dex_file, location.Get(), strings.Get(), types.Get(), methods.Get(), fields.Get()); @@ -2010,7 +2007,7 @@ mirror::ObjectArray<mirror::StackTraceElement>* ClassLinker::AllocStackTraceElem mirror::Class* ClassLinker::EnsureResolved(Thread* self, const char* descriptor, mirror::Class* klass) { - DCHECK(klass != NULL); + DCHECK(klass != nullptr); // For temporary classes we must wait for them to be retired. if (init_done_ && klass->IsTemp()) { @@ -2070,13 +2067,13 @@ ClassPathEntry FindInClassPath(const char* descriptor, for (size_t i = 0; i != class_path.size(); ++i) { const DexFile* dex_file = class_path[i]; const DexFile::ClassDef* dex_class_def = dex_file->FindClassDef(descriptor); - if (dex_class_def != NULL) { + if (dex_class_def != nullptr) { return ClassPathEntry(dex_file, dex_class_def); } } // TODO: remove reinterpret_cast when issue with -std=gnu++0x host issue resolved - return ClassPathEntry(reinterpret_cast<const DexFile*>(NULL), - reinterpret_cast<const DexFile::ClassDef*>(NULL)); + return ClassPathEntry(static_cast<const DexFile*>(nullptr), + static_cast<const DexFile::ClassDef*>(nullptr)); } mirror::Class* ClassLinker::FindClassInPathClassLoader(ScopedObjectAccessAlreadyRunnable& soa, @@ -2386,7 +2383,7 @@ uint32_t ClassLinker::SizeOfClassWithoutEmbeddedTables(const DexFile& dex_file, size_t num_16 = 0; size_t num_32 = 0; size_t num_64 = 0; - if (class_data != NULL) { + if (class_data != nullptr) { for (ClassDataItemIterator it(dex_file, class_data); it.HasNextStaticField(); it.Next()) { const DexFile::FieldId& field_id = dex_file.GetFieldId(it.GetMemberIndex()); const char* descriptor = dex_file.GetFieldTypeDescriptor(field_id); @@ -2436,7 +2433,7 @@ static uint32_t GetOatMethodIndexFromMethodIndex(const DexFile& dex_file, uint16 uint32_t method_idx) { const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_idx); const byte* class_data = dex_file.GetClassData(class_def); - CHECK(class_data != NULL); + CHECK(class_data != nullptr); ClassDataItemIterator it(dex_file, class_data); // Skip fields while (it.HasNextStaticField()) { @@ -2782,11 +2779,11 @@ void ClassLinker::LoadClass(Thread* self, const DexFile& dex_file, const DexFile::ClassDef& dex_class_def, ConstHandle<mirror::Class> klass, mirror::ClassLoader* class_loader) { - CHECK(klass.Get() != NULL); - CHECK(klass->GetDexCache() != NULL); + CHECK(klass.Get() != nullptr); + CHECK(klass->GetDexCache() != nullptr); CHECK_EQ(mirror::Class::kStatusNotReady, klass->GetStatus()); const char* descriptor = dex_file.GetClassDescriptor(dex_class_def); - CHECK(descriptor != NULL); + CHECK(descriptor != nullptr); klass->SetClass(GetClassRoot(kJavaLangClass)); if (kUseBakerOrBrooksReadBarrier) { @@ -2797,13 +2794,13 @@ void ClassLinker::LoadClass(Thread* self, const DexFile& dex_file, klass->SetAccessFlags(access_flags); klass->SetClassLoader(class_loader); DCHECK_EQ(klass->GetPrimitiveType(), Primitive::kPrimNot); - klass->SetStatus(mirror::Class::kStatusIdx, NULL); + klass->SetStatus(mirror::Class::kStatusIdx, nullptr); klass->SetDexClassDefIndex(dex_file.GetIndexForClassDef(dex_class_def)); klass->SetDexTypeIndex(dex_class_def.class_idx_); const byte* class_data = dex_file.GetClassData(dex_class_def); - if (class_data == NULL) { + if (class_data == nullptr) { return; // no fields or methods - for example a marker interface } @@ -2830,7 +2827,7 @@ void ClassLinker::LoadClassMembers(Thread* self, const DexFile& dex_file, ClassDataItemIterator it(dex_file, class_data); if (it.NumStaticFields() != 0) { mirror::ObjectArray<mirror::ArtField>* statics = AllocArtFieldArray(self, it.NumStaticFields()); - if (UNLIKELY(statics == NULL)) { + if (UNLIKELY(statics == nullptr)) { CHECK(self->IsExceptionPending()); // OOME. return; } @@ -2839,7 +2836,7 @@ void ClassLinker::LoadClassMembers(Thread* self, const DexFile& dex_file, if (it.NumInstanceFields() != 0) { mirror::ObjectArray<mirror::ArtField>* fields = AllocArtFieldArray(self, it.NumInstanceFields()); - if (UNLIKELY(fields == NULL)) { + if (UNLIKELY(fields == nullptr)) { CHECK(self->IsExceptionPending()); // OOME. return; } @@ -2849,7 +2846,7 @@ void ClassLinker::LoadClassMembers(Thread* self, const DexFile& dex_file, self->AllowThreadSuspension(); StackHandleScope<1> hs(self); Handle<mirror::ArtField> sfield(hs.NewHandle(AllocArtField(self))); - if (UNLIKELY(sfield.Get() == NULL)) { + if (UNLIKELY(sfield.Get() == nullptr)) { CHECK(self->IsExceptionPending()); // OOME. return; } @@ -2860,7 +2857,7 @@ void ClassLinker::LoadClassMembers(Thread* self, const DexFile& dex_file, self->AllowThreadSuspension(); StackHandleScope<1> hs(self); Handle<mirror::ArtField> ifield(hs.NewHandle(AllocArtField(self))); - if (UNLIKELY(ifield.Get() == NULL)) { + if (UNLIKELY(ifield.Get() == nullptr)) { CHECK(self->IsExceptionPending()); // OOME. return; } @@ -2873,7 +2870,7 @@ void ClassLinker::LoadClassMembers(Thread* self, const DexFile& dex_file, // TODO: append direct methods to class object mirror::ObjectArray<mirror::ArtMethod>* directs = AllocArtMethodArray(self, it.NumDirectMethods()); - if (UNLIKELY(directs == NULL)) { + if (UNLIKELY(directs == nullptr)) { CHECK(self->IsExceptionPending()); // OOME. return; } @@ -2883,7 +2880,7 @@ void ClassLinker::LoadClassMembers(Thread* self, const DexFile& dex_file, // TODO: append direct methods to class object mirror::ObjectArray<mirror::ArtMethod>* virtuals = AllocArtMethodArray(self, it.NumVirtualMethods()); - if (UNLIKELY(virtuals == NULL)) { + if (UNLIKELY(virtuals == nullptr)) { CHECK(self->IsExceptionPending()); // OOME. return; } @@ -2896,7 +2893,7 @@ void ClassLinker::LoadClassMembers(Thread* self, const DexFile& dex_file, self->AllowThreadSuspension(); StackHandleScope<1> hs(self); Handle<mirror::ArtMethod> method(hs.NewHandle(LoadMethod(self, dex_file, it, klass))); - if (UNLIKELY(method.Get() == NULL)) { + if (UNLIKELY(method.Get() == nullptr)) { CHECK(self->IsExceptionPending()); // OOME. return; } @@ -2917,7 +2914,7 @@ void ClassLinker::LoadClassMembers(Thread* self, const DexFile& dex_file, self->AllowThreadSuspension(); StackHandleScope<1> hs(self); Handle<mirror::ArtMethod> method(hs.NewHandle(LoadMethod(self, dex_file, it, klass))); - if (UNLIKELY(method.Get() == NULL)) { + if (UNLIKELY(method.Get() == nullptr)) { CHECK(self->IsExceptionPending()); // OOME. return; } @@ -2946,9 +2943,9 @@ mirror::ArtMethod* ClassLinker::LoadMethod(Thread* self, const DexFile& dex_file const char* method_name = dex_file.StringDataByIdx(method_id.name_idx_); mirror::ArtMethod* dst = AllocArtMethod(self); - if (UNLIKELY(dst == NULL)) { + if (UNLIKELY(dst == nullptr)) { CHECK(self->IsExceptionPending()); // OOME. - return NULL; + return nullptr; } DCHECK(dst->IsArtMethod()) << PrettyDescriptor(dst->GetClass()); @@ -2967,7 +2964,7 @@ mirror::ArtMethod* ClassLinker::LoadMethod(Thread* self, const DexFile& dex_file // Set finalizable flag on declaring class. if (strcmp("V", dex_file.GetShorty(method_id.proto_idx_)) == 0) { // Void return type. - if (klass->GetClassLoader() != NULL) { // All non-boot finalizer methods are flagged. + if (klass->GetClassLoader() != nullptr) { // All non-boot finalizer methods are flagged. klass->SetFinalizable(); } else { std::string temp; @@ -3006,13 +3003,14 @@ mirror::ArtMethod* ClassLinker::LoadMethod(Thread* self, const DexFile& dex_file void ClassLinker::AppendToBootClassPath(Thread* self, const DexFile& dex_file) { StackHandleScope<1> hs(self); Handle<mirror::DexCache> dex_cache(hs.NewHandle(AllocDexCache(self, dex_file))); - CHECK(dex_cache.Get() != NULL) << "Failed to allocate dex cache for " << dex_file.GetLocation(); + CHECK(dex_cache.Get() != nullptr) << "Failed to allocate dex cache for " + << dex_file.GetLocation(); AppendToBootClassPath(dex_file, dex_cache); } void ClassLinker::AppendToBootClassPath(const DexFile& dex_file, ConstHandle<mirror::DexCache> dex_cache) { - CHECK(dex_cache.Get() != NULL) << dex_file.GetLocation(); + CHECK(dex_cache.Get() != nullptr) << dex_file.GetLocation(); boot_class_path_.push_back(&dex_file); RegisterDexFile(dex_file, dex_cache); } @@ -3036,7 +3034,7 @@ bool ClassLinker::IsDexFileRegistered(const DexFile& dex_file) { void ClassLinker::RegisterDexFileLocked(const DexFile& dex_file, ConstHandle<mirror::DexCache> dex_cache) { dex_lock_.AssertExclusiveHeld(Thread::Current()); - CHECK(dex_cache.Get() != NULL) << dex_file.GetLocation(); + CHECK(dex_cache.Get() != nullptr) << dex_file.GetLocation(); CHECK(dex_cache->GetLocation()->Equals(dex_file.GetLocation())) << dex_cache->GetLocation()->ToModifiedUtf8() << " " << dex_file.GetLocation(); dex_caches_.push_back(GcRoot<mirror::DexCache>(dex_cache.Get())); @@ -3060,7 +3058,8 @@ void ClassLinker::RegisterDexFile(const DexFile& dex_file) { // get to a suspend point. StackHandleScope<1> hs(self); Handle<mirror::DexCache> dex_cache(hs.NewHandle(AllocDexCache(self, dex_file))); - CHECK(dex_cache.Get() != NULL) << "Failed to allocate dex cache for " << dex_file.GetLocation(); + CHECK(dex_cache.Get() != nullptr) << "Failed to allocate dex cache for " + << dex_file.GetLocation(); { WriterMutexLock mu(self, dex_lock_); if (IsDexFileRegisteredLocked(dex_file)) { @@ -3099,7 +3098,7 @@ mirror::DexCache* ClassLinker::FindDexCache(const DexFile& dex_file) { LOG(ERROR) << "Registered dex file " << i << " = " << dex_cache->GetDexFile()->GetLocation(); } LOG(FATAL) << "Failed to find DexCache for DexFile " << location; - return NULL; + return nullptr; } void ClassLinker::FixupDexCaches(mirror::ArtMethod* resolution_method) { @@ -3112,15 +3111,15 @@ void ClassLinker::FixupDexCaches(mirror::ArtMethod* resolution_method) { mirror::Class* ClassLinker::CreatePrimitiveClass(Thread* self, Primitive::Type type) { mirror::Class* klass = AllocClass(self, mirror::Class::PrimitiveClassSize()); - if (UNLIKELY(klass == NULL)) { - return NULL; + if (UNLIKELY(klass == nullptr)) { + return nullptr; } return InitializePrimitiveClass(klass, type); } mirror::Class* ClassLinker::InitializePrimitiveClass(mirror::Class* primitive_class, Primitive::Type type) { - CHECK(primitive_class != NULL); + CHECK(primitive_class != nullptr); // Must hold lock on object when initializing. Thread* self = Thread::Current(); StackHandleScope<1> hs(self); @@ -3131,7 +3130,7 @@ mirror::Class* ClassLinker::InitializePrimitiveClass(mirror::Class* primitive_cl primitive_class->SetStatus(mirror::Class::kStatusInitialized, self); const char* descriptor = Primitive::Descriptor(type); mirror::Class* existing = InsertClass(descriptor, primitive_class, Hash(descriptor)); - CHECK(existing == NULL) << "InitPrimitiveClass(" << type << ") failed"; + CHECK(existing == nullptr) << "InitPrimitiveClass(" << type << ") failed"; return primitive_class; } @@ -3147,7 +3146,7 @@ mirror::Class* ClassLinker::InitializePrimitiveClass(mirror::Class* primitive_cl // the right context. It does NOT become the class loader for the // array class; that always comes from the base element class. // -// Returns NULL with an exception raised on failure. +// Returns nullptr with an exception raised on failure. mirror::Class* ClassLinker::CreateArrayClass(Thread* self, const char* descriptor, ConstHandle<mirror::ClassLoader> class_loader) { // Identify the underlying component type @@ -3188,7 +3187,7 @@ mirror::Class* ClassLinker::CreateArrayClass(Thread* self, const char* descripto // other threads.) if (class_loader.Get() != component_type->GetClassLoader()) { mirror::Class* new_class = LookupClass(self, descriptor, component_type->GetClassLoader()); - if (new_class != NULL) { + if (new_class != nullptr) { return new_class; } } @@ -3230,7 +3229,7 @@ mirror::Class* ClassLinker::CreateArrayClass(Thread* self, const char* descripto new_class->SetComponentType(component_type.Get()); } ObjectLock<mirror::Class> lock(self, new_class); // Must hold lock on object when initializing. - DCHECK(new_class->GetComponentType() != NULL); + DCHECK(new_class->GetComponentType() != nullptr); mirror::Class* java_lang_Object = GetClassRoot(kJavaLangObject); new_class->SetSuperClass(java_lang_Object); new_class->SetVTable(java_lang_Object->GetVTable()); @@ -3310,7 +3309,7 @@ mirror::Class* ClassLinker::FindPrimitiveClass(char type) { } std::string printable_type(PrintableChar(type)); ThrowNoClassDefFoundError("Not a primitive type: %s", printable_type.c_str()); - return NULL; + return nullptr; } mirror::Class* ClassLinker::InsertClass(const char* descriptor, mirror::Class* klass, @@ -3318,7 +3317,7 @@ mirror::Class* ClassLinker::InsertClass(const char* descriptor, mirror::Class* k if (VLOG_IS_ON(class_linker)) { mirror::DexCache* dex_cache = klass->GetDexCache(); std::string source; - if (dex_cache != NULL) { + if (dex_cache != nullptr) { source += " from "; source += dex_cache->GetLocation()->ToModifiedUtf8(); } @@ -3327,15 +3326,15 @@ mirror::Class* ClassLinker::InsertClass(const char* descriptor, mirror::Class* k WriterMutexLock mu(Thread::Current(), *Locks::classlinker_classes_lock_); mirror::Class* existing = LookupClassFromTableLocked(descriptor, klass->GetClassLoader(), hash); - if (existing != NULL) { + if (existing != nullptr) { return existing; } - if (kIsDebugBuild && !klass->IsTemp() && klass->GetClassLoader() == NULL && + if (kIsDebugBuild && !klass->IsTemp() && klass->GetClassLoader() == nullptr && dex_cache_image_class_lookup_required_) { // Check a class loaded with the system class loader matches one in the image if the class // is in the image. existing = LookupClassFromImage(descriptor); - if (existing != NULL) { + if (existing != nullptr) { CHECK(klass == existing); } } @@ -3344,7 +3343,7 @@ mirror::Class* ClassLinker::InsertClass(const char* descriptor, mirror::Class* k if (log_new_class_table_roots_) { new_class_roots_.push_back(std::make_pair(hash, GcRoot<mirror::Class>(klass))); } - return NULL; + return nullptr; } mirror::Class* ClassLinker::UpdateClass(const char* descriptor, mirror::Class* klass, @@ -3362,8 +3361,8 @@ mirror::Class* ClassLinker::UpdateClass(const char* descriptor, mirror::Class* k CHECK(!existing->IsResolved()) << descriptor; CHECK_EQ(klass->GetStatus(), mirror::Class::kStatusResolving) << descriptor; - for (auto it = class_table_.lower_bound(hash), end = class_table_.end(); it != end && it->first == hash; - ++it) { + for (auto it = class_table_.lower_bound(hash), end = class_table_.end(); + it != end && it->first == hash; ++it) { mirror::Class* klass = it->second.Read(); if (klass == existing) { class_table_.erase(it); @@ -3412,16 +3411,16 @@ mirror::Class* ClassLinker::LookupClass(Thread* self, const char* descriptor, { ReaderMutexLock mu(self, *Locks::classlinker_classes_lock_); mirror::Class* result = LookupClassFromTableLocked(descriptor, class_loader, hash); - if (result != NULL) { + if (result != nullptr) { return result; } } - if (class_loader != NULL || !dex_cache_image_class_lookup_required_) { - return NULL; + if (class_loader != nullptr || !dex_cache_image_class_lookup_required_) { + return nullptr; } else { // Lookup failed but need to search dex_caches_. mirror::Class* result = LookupClassFromImage(descriptor); - if (result != NULL) { + if (result != nullptr) { InsertClass(descriptor, result, hash); } else { // Searching the image dex files/caches failed, we don't want to get into this situation @@ -3456,13 +3455,13 @@ mirror::Class* ClassLinker::LookupClassFromTableLocked(const char* descriptor, return klass; } } - return NULL; + return nullptr; } static mirror::ObjectArray<mirror::DexCache>* GetImageDexCaches() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { gc::space::ImageSpace* image = Runtime::Current()->GetHeap()->GetImageSpace(); - CHECK(image != NULL); + CHECK(image != nullptr); mirror::Object* root = image->GetImageHeader().GetImageRoot(ImageHeader::kDexCaches); return root->AsObjectArray<mirror::DexCache>(); } @@ -3482,12 +3481,12 @@ void ClassLinker::MoveImageClassesToClassTable() { mirror::ObjectArray<mirror::Class>* types = dex_cache->GetResolvedTypes(); for (int32_t j = 0; j < types->GetLength(); j++) { mirror::Class* klass = types->Get(j); - if (klass != NULL) { - DCHECK(klass->GetClassLoader() == NULL); + if (klass != nullptr) { + DCHECK(klass->GetClassLoader() == nullptr); const char* descriptor = klass->GetDescriptor(&temp); size_t hash = Hash(descriptor); - mirror::Class* existing = LookupClassFromTableLocked(descriptor, NULL, hash); - if (existing != NULL) { + mirror::Class* existing = LookupClassFromTableLocked(descriptor, nullptr, hash); + if (existing != nullptr) { CHECK(existing == klass) << PrettyClassAndClassLoader(existing) << " != " << PrettyClassAndClassLoader(klass); } else { @@ -3513,13 +3512,13 @@ mirror::Class* ClassLinker::LookupClassFromImage(const char* descriptor) { const DexFile* dex_file = dex_cache->GetDexFile(); // Try binary searching the string/type index. const DexFile::StringId* string_id = dex_file->FindStringId(descriptor); - if (string_id != NULL) { + if (string_id != nullptr) { const DexFile::TypeId* type_id = dex_file->FindTypeId(dex_file->GetIndexForStringId(*string_id)); - if (type_id != NULL) { + if (type_id != nullptr) { uint16_t type_idx = dex_file->GetIndexForTypeId(*type_id); mirror::Class* klass = dex_cache->GetResolvedType(type_idx); - if (klass != NULL) { + if (klass != nullptr) { self->EndAssertNoThreadSuspension(old_no_suspend_cause); return klass; } @@ -3527,7 +3526,7 @@ mirror::Class* ClassLinker::LookupClassFromImage(const char* descriptor) { } } self->EndAssertNoThreadSuspension(old_no_suspend_cause); - return NULL; + return nullptr; } void ClassLinker::LookupClasses(const char* descriptor, std::vector<mirror::Class*>& result) { @@ -3585,7 +3584,7 @@ void ClassLinker::VerifyClass(Thread* self, ConstHandle<mirror::Class> klass) { // Verify super class. StackHandleScope<2> hs(self); Handle<mirror::Class> super(hs.NewHandle(klass->GetSuperClass())); - if (super.Get() != NULL) { + if (super.Get() != nullptr) { // Acquire lock to prevent races on verifying the super class. ObjectLock<mirror::Class> lock(self, super); @@ -3647,7 +3646,7 @@ void ClassLinker::VerifyClass(Thread* self, ConstHandle<mirror::Class> klass) { if (verifier_failure == verifier::MethodVerifier::kNoFailure) { // Even though there were no verifier failures we need to respect whether the super-class // was verified or requiring runtime reverification. - if (super.Get() == NULL || super->IsVerified()) { + if (super.Get() == nullptr || super->IsVerified()) { klass->SetStatus(mirror::Class::kStatusVerified, self); } else { CHECK_EQ(super->GetStatus(), mirror::Class::kStatusRetryVerificationAtRuntime); @@ -3709,19 +3708,17 @@ bool ClassLinker::VerifyClassUsingOatFile(const DexFile& dex_file, mirror::Class // We are compiling an app (not the image). // Is this an app class? (I.e. not a bootclasspath class) - if (klass->GetClassLoader() != NULL) { + if (klass->GetClassLoader() != nullptr) { return false; } } const OatFile::OatDexFile* oat_dex_file = FindOpenedOatDexFileForDexFile(dex_file); - // Make this work with gtests, which do not set up the image properly. - // TODO: we should clean up gtests to set up the image path properly. - if (Runtime::Current()->IsCompiler() || (oat_dex_file == nullptr)) { + // In case we run without an image there won't be a backing oat file. + if (oat_dex_file == nullptr) { return false; } - CHECK(oat_dex_file != NULL) << dex_file.GetLocation() << " " << PrettyClass(klass); uint16_t class_def_index = klass->GetDexClassDefIndex(); oat_file_class_status = oat_dex_file->GetOatClass(class_def_index).GetStatus(); if (oat_file_class_status == mirror::Class::kStatusVerified || @@ -3782,7 +3779,7 @@ void ClassLinker::ResolveMethodExceptionHandlerTypes(const DexFile& dex_file, mirror::ArtMethod* method) { // similar to DexVerifier::ScanTryCatchBlocks and dex2oat's ResolveExceptionsForMethod. const DexFile::CodeItem* code_item = dex_file.GetCodeItem(method->GetCodeItemOffset()); - if (code_item == NULL) { + if (code_item == nullptr) { return; // native or abstract method } if (code_item->tries_size_ == 0) { @@ -3798,7 +3795,7 @@ void ClassLinker::ResolveMethodExceptionHandlerTypes(const DexFile& dex_file, // unresolved exception types will be ignored by exception delivery if (iterator.GetHandlerTypeIndex() != DexFile::kDexNoIndex16) { mirror::Class* exception_type = linker->ResolveType(iterator.GetHandlerTypeIndex(), method); - if (exception_type == NULL) { + if (exception_type == nullptr) { DCHECK(Thread::Current()->IsExceptionPending()); Thread::Current()->ClearException(); } @@ -3819,11 +3816,11 @@ mirror::Class* ClassLinker::CreateProxyClass(ScopedObjectAccessAlreadyRunnable& StackHandleScope<8> hs(self); Handle<mirror::Class> klass(hs.NewHandle( AllocClass(self, GetClassRoot(kJavaLangClass), sizeof(mirror::Class)))); - if (klass.Get() == NULL) { + if (klass.Get() == nullptr) { CHECK(self->IsExceptionPending()); // OOME. - return NULL; + return nullptr; } - DCHECK(klass->GetClass() != NULL); + DCHECK(klass->GetClass() != nullptr); klass->SetObjectSize(sizeof(mirror::Proxy)); // Set the class access flags incl. preverified, so we do not try to set the flag on the methods. klass->SetAccessFlags(kAccClassIsProxy | kAccPublic | kAccFinal | kAccPreverified); @@ -3837,9 +3834,9 @@ mirror::Class* ClassLinker::CreateProxyClass(ScopedObjectAccessAlreadyRunnable& // Instance fields are inherited, but we add a couple of static fields... { mirror::ObjectArray<mirror::ArtField>* sfields = AllocArtFieldArray(self, 2); - if (UNLIKELY(sfields == NULL)) { + if (UNLIKELY(sfields == nullptr)) { CHECK(self->IsExceptionPending()); // OOME. - return NULL; + return nullptr; } klass->SetSFields(sfields); } @@ -3887,9 +3884,9 @@ mirror::Class* ClassLinker::CreateProxyClass(ScopedObjectAccessAlreadyRunnable& { mirror::ObjectArray<mirror::ArtMethod>* virtuals = AllocArtMethodArray(self, num_virtual_methods); - if (UNLIKELY(virtuals == NULL)) { + if (UNLIKELY(virtuals == nullptr)) { CHECK(self->IsExceptionPending()); // OOME. - return NULL; + return nullptr; } klass->SetVirtualMethods(virtuals); } @@ -3913,7 +3910,8 @@ mirror::Class* ClassLinker::CreateProxyClass(ScopedObjectAccessAlreadyRunnable& std::string descriptor(GetDescriptorForProxy(klass.Get())); mirror::Class* new_class = nullptr; { - ObjectLock<mirror::Class> resolution_lock(self, klass); // Must hold lock on object when resolved. + // Must hold lock on object when resolved. + ObjectLock<mirror::Class> resolution_lock(self, klass); // Link the fields and virtual methods, creating vtable and iftables Handle<mirror::ObjectArray<mirror::Class> > h_interfaces( hs.NewHandle(soa.Decode<mirror::ObjectArray<mirror::Class>*>(interfaces))); @@ -3928,9 +3926,11 @@ mirror::Class* ClassLinker::CreateProxyClass(ScopedObjectAccessAlreadyRunnable& klass.Assign(new_class); CHECK_EQ(interfaces_sfield->GetDeclaringClass(), new_class); - interfaces_sfield->SetObject<false>(klass.Get(), soa.Decode<mirror::ObjectArray<mirror::Class>*>(interfaces)); + interfaces_sfield->SetObject<false>(klass.Get(), + soa.Decode<mirror::ObjectArray<mirror::Class>*>(interfaces)); CHECK_EQ(throws_sfield->GetDeclaringClass(), new_class); - throws_sfield->SetObject<false>(klass.Get(), soa.Decode<mirror::ObjectArray<mirror::ObjectArray<mirror::Class> >*>(throws)); + throws_sfield->SetObject<false>(klass.Get(), + soa.Decode<mirror::ObjectArray<mirror::ObjectArray<mirror::Class> >*>(throws)); { // Lock on klass is released. Lock new class object. @@ -3973,7 +3973,7 @@ mirror::Class* ClassLinker::CreateProxyClass(ScopedObjectAccessAlreadyRunnable& std::string ClassLinker::GetDescriptorForProxy(mirror::Class* proxy_class) { DCHECK(proxy_class->IsProxyClass()); mirror::String* name = proxy_class->GetName(); - DCHECK(name != NULL); + DCHECK(name != nullptr); return DotToDescriptor(name->ToModifiedUtf8().c_str()); } @@ -4045,9 +4045,9 @@ mirror::ArtMethod* ClassLinker::CreateProxyMethod(Thread* self, // We steal everything from the prototype (such as DexCache, invoke stub, etc.) then specialize // as necessary mirror::ArtMethod* method = down_cast<mirror::ArtMethod*>(prototype->Clone(self)); - if (UNLIKELY(method == NULL)) { + if (UNLIKELY(method == nullptr)) { CHECK(self->IsExceptionPending()); // OOME. - return NULL; + return nullptr; } // Set class to be the concrete proxy class and clear the abstract flag, modify exceptions to @@ -4097,13 +4097,13 @@ static bool CanWeInitializeClass(mirror::Class* klass, bool can_init_statics, if (!can_init_statics) { // Check if there's a class initializer. mirror::ArtMethod* clinit = klass->FindClassInitializer(); - if (clinit != NULL) { + if (clinit != nullptr) { return false; } // Check if there are encoded static values needing initialization. if (klass->NumStaticFields() != 0) { const DexFile::ClassDef* dex_class_def = klass->GetClassDef(); - DCHECK(dex_class_def != NULL); + DCHECK(dex_class_def != nullptr); if (dex_class_def->static_values_off_ != 0) { return false; } @@ -4225,7 +4225,7 @@ bool ClassLinker::InitializeClass(Thread* self, ConstHandle<mirror::Class> klass << PrettyDescriptor(handle_scope_super.Get()) << " that has unexpected status " << handle_scope_super->GetStatus() << "\nPending exception:\n" - << (self->GetException(NULL) != NULL ? self->GetException(NULL)->Dump() : ""); + << (self->GetException(nullptr) != nullptr ? self->GetException(nullptr)->Dump() : ""); ObjectLock<mirror::Class> lock(self, klass); // Initialization failed because the super-class is erroneous. klass->SetStatus(mirror::Class::kStatusError, self); @@ -4236,7 +4236,7 @@ bool ClassLinker::InitializeClass(Thread* self, ConstHandle<mirror::Class> klass if (klass->NumStaticFields() > 0) { const DexFile::ClassDef* dex_class_def = klass->GetClassDef(); - CHECK(dex_class_def != NULL); + CHECK(dex_class_def != nullptr); const DexFile& dex_file = klass->GetDexFile(); StackHandleScope<3> hs(self); Handle<mirror::ClassLoader> class_loader(hs.NewHandle(klass->GetClassLoader())); @@ -4263,10 +4263,10 @@ bool ClassLinker::InitializeClass(Thread* self, ConstHandle<mirror::Class> klass } mirror::ArtMethod* clinit = klass->FindClassInitializer(); - if (clinit != NULL) { + if (clinit != nullptr) { CHECK(can_init_statics); JValue result; - clinit->Invoke(self, NULL, 0, &result, "V"); + clinit->Invoke(self, nullptr, 0, &result, "V"); } self->AllowThreadSuspension(); @@ -4480,7 +4480,7 @@ bool ClassLinker::LinkClass(Thread* self, const char* descriptor, ConstHandle<mi CHECK(!klass->IsResolved()); // Retire the temporary class and create the correctly sized resolved class. *new_class = klass->CopyOf(self, class_size); - if (UNLIKELY(*new_class == NULL)) { + if (UNLIKELY(*new_class == nullptr)) { CHECK(self->IsExceptionPending()); // Expect an OOME. klass->SetStatus(mirror::Class::kStatusError, self); return false; @@ -4494,7 +4494,7 @@ bool ClassLinker::LinkClass(Thread* self, const char* descriptor, ConstHandle<mi FixupTemporaryDeclaringClass(klass.Get(), new_class_h.Get()); mirror::Class* existing = UpdateClass(descriptor, new_class_h.Get(), Hash(descriptor)); - CHECK(existing == NULL || existing == klass.Get()); + CHECK(existing == nullptr || existing == klass.Get()); // This will notify waiters on temp class that saw the not yet resolved class in the // class_table_ during EnsureResolved. @@ -4514,7 +4514,7 @@ bool ClassLinker::LoadSuperAndInterfaces(ConstHandle<mirror::Class> klass, const uint16_t super_class_idx = class_def.superclass_idx_; if (super_class_idx != DexFile::kDexNoIndex16) { mirror::Class* super_class = ResolveType(dex_file, super_class_idx, klass.Get()); - if (super_class == NULL) { + if (super_class == nullptr) { DCHECK(Thread::Current()->IsExceptionPending()); return false; } @@ -4529,11 +4529,11 @@ bool ClassLinker::LoadSuperAndInterfaces(ConstHandle<mirror::Class> klass, const klass->SetSuperClass(super_class); } const DexFile::TypeList* interfaces = dex_file.GetInterfacesList(class_def); - if (interfaces != NULL) { + if (interfaces != nullptr) { for (size_t i = 0; i < interfaces->Size(); i++) { uint16_t idx = interfaces->GetTypeItem(i).type_idx_; mirror::Class* interface = ResolveType(dex_file, idx, klass.Get()); - if (interface == NULL) { + if (interface == nullptr) { DCHECK(Thread::Current()->IsExceptionPending()); return false; } @@ -4548,7 +4548,7 @@ bool ClassLinker::LoadSuperAndInterfaces(ConstHandle<mirror::Class> klass, const } } // Mark the class as loaded. - klass->SetStatus(mirror::Class::kStatusLoaded, NULL); + klass->SetStatus(mirror::Class::kStatusLoaded, nullptr); return true; } @@ -4556,13 +4556,13 @@ bool ClassLinker::LinkSuperClass(ConstHandle<mirror::Class> klass) { CHECK(!klass->IsPrimitive()); mirror::Class* super = klass->GetSuperClass(); if (klass.Get() == GetClassRoot(kJavaLangObject)) { - if (super != NULL) { + if (super != nullptr) { ThrowClassFormatError(klass.Get(), "java.lang.Object must not have a superclass"); return false; } return true; } - if (super == NULL) { + if (super == nullptr) { ThrowLinkageError(klass.Get(), "No superclass defined for class %s", PrettyDescriptor(klass.Get()).c_str()); return false; @@ -4603,7 +4603,7 @@ bool ClassLinker::LinkSuperClass(ConstHandle<mirror::Class> klass) { if (kIsDebugBuild) { // Ensure super classes are fully resolved prior to resolving fields.. - while (super != NULL) { + while (super != nullptr) { CHECK(super->IsResolved()); super = super->GetSuperClass(); } @@ -4706,7 +4706,7 @@ bool ClassLinker::LinkVirtualMethods(Thread* self, ConstHandle<mirror::Class> kl CHECK_LE(actual_count, max_count); if (actual_count < max_count) { vtable.Assign(vtable->CopyOf(self, actual_count)); - if (UNLIKELY(vtable.Get() == NULL)) { + if (UNLIKELY(vtable.Get() == nullptr)) { CHECK(self->IsExceptionPending()); // OOME. return false; } @@ -4722,7 +4722,7 @@ bool ClassLinker::LinkVirtualMethods(Thread* self, ConstHandle<mirror::Class> kl StackHandleScope<1> hs(self); Handle<mirror::ObjectArray<mirror::ArtMethod>> vtable(hs.NewHandle(AllocArtMethodArray(self, num_virtual_methods))); - if (UNLIKELY(vtable.Get() == NULL)) { + if (UNLIKELY(vtable.Get() == nullptr)) { CHECK(self->IsExceptionPending()); // OOME. return false; } @@ -4760,7 +4760,7 @@ bool ClassLinker::LinkInterfaceMethods(ConstHandle<mirror::Class> klass, if (ifcount == 0) { // Class implements no interfaces. DCHECK_EQ(klass->GetIfTableCount(), 0); - DCHECK(klass->GetIfTable() == NULL); + DCHECK(klass->GetIfTable() == nullptr); return true; } if (ifcount == super_ifcount) { @@ -4781,7 +4781,7 @@ bool ClassLinker::LinkInterfaceMethods(ConstHandle<mirror::Class> klass, } StackHandleScope<5> hs(self); Handle<mirror::IfTable> iftable(hs.NewHandle(AllocIfTable(self, ifcount))); - if (UNLIKELY(iftable.Get() == NULL)) { + if (UNLIKELY(iftable.Get() == nullptr)) { CHECK(self->IsExceptionPending()); // OOME. return false; } @@ -4799,7 +4799,7 @@ bool ClassLinker::LinkInterfaceMethods(ConstHandle<mirror::Class> klass, mirror::Class* interface = interfaces.Get() == nullptr ? mirror::Class::GetDirectInterface(self, klass, i) : interfaces->Get(i); - DCHECK(interface != NULL); + DCHECK(interface != nullptr); if (!interface->IsInterface()) { std::string temp; ThrowIncompatibleClassChangeError(klass.Get(), "Class %s implements non-interface class %s", @@ -4840,7 +4840,7 @@ bool ClassLinker::LinkInterfaceMethods(ConstHandle<mirror::Class> klass, // Shrink iftable in case duplicates were found if (idx < ifcount) { iftable.Assign(down_cast<mirror::IfTable*>(iftable->CopyOf(self, idx * mirror::IfTable::kMax))); - if (UNLIKELY(iftable.Get() == NULL)) { + if (UNLIKELY(iftable.Get() == nullptr)) { CHECK(self->IsExceptionPending()); // OOME. return false; } @@ -4859,7 +4859,7 @@ bool ClassLinker::LinkInterfaceMethods(ConstHandle<mirror::Class> klass, bool imtable_changed = false; Handle<mirror::ObjectArray<mirror::ArtMethod>> imtable( hs.NewHandle(AllocArtMethodArray(self, mirror::Class::kImtSize))); - if (UNLIKELY(imtable.Get() == NULL)) { + if (UNLIKELY(imtable.Get() == nullptr)) { CHECK(self->IsExceptionPending()); // OOME. return false; } @@ -4911,7 +4911,7 @@ bool ClassLinker::LinkInterfaceMethods(ConstHandle<mirror::Class> klass, method_array->Set<false>(j, vtable_mh.Get()); // Place method in imt if entry is empty, place conflict otherwise. uint32_t imt_index = interface_mh.Get()->GetDexMethodIndex() % mirror::Class::kImtSize; - if (imtable->Get(imt_index) == NULL) { + if (imtable->Get(imt_index) == nullptr) { imtable->Set<false>(imt_index, vtable_mh.Get()); imtable_changed = true; } else { @@ -4932,10 +4932,10 @@ bool ClassLinker::LinkInterfaceMethods(ConstHandle<mirror::Class> klass, break; } } - if (miranda_method.Get() == NULL) { + if (miranda_method.Get() == nullptr) { // Point the interface table at a phantom slot. miranda_method.Assign(down_cast<mirror::ArtMethod*>(interface_mh.Get()->Clone(self))); - if (UNLIKELY(miranda_method.Get() == NULL)) { + if (UNLIKELY(miranda_method.Get() == nullptr)) { CHECK(self->IsExceptionPending()); // OOME. return false; } @@ -4951,7 +4951,7 @@ bool ClassLinker::LinkInterfaceMethods(ConstHandle<mirror::Class> klass, // Fill in empty entries in interface method table with conflict. mirror::ArtMethod* imt_conflict_method = runtime->GetImtConflictMethod(); for (size_t i = 0; i < mirror::Class::kImtSize; i++) { - if (imtable->Get(i) == NULL) { + if (imtable->Get(i) == nullptr) { imtable->Set<false>(i, imt_conflict_method); } } @@ -4966,7 +4966,7 @@ bool ClassLinker::LinkInterfaceMethods(ConstHandle<mirror::Class> klass, } else { virtuals = klass->GetVirtualMethods()->CopyOf(self, new_method_count); } - if (UNLIKELY(virtuals == NULL)) { + if (UNLIKELY(virtuals == nullptr)) { CHECK(self->IsExceptionPending()); // OOME. return false; } @@ -4975,11 +4975,11 @@ bool ClassLinker::LinkInterfaceMethods(ConstHandle<mirror::Class> klass, StackHandleScope<1> hs(self); Handle<mirror::ObjectArray<mirror::ArtMethod>> vtable( hs.NewHandle(klass->GetVTableDuringLinking())); - CHECK(vtable.Get() != NULL); + CHECK(vtable.Get() != nullptr); int old_vtable_count = vtable->GetLength(); int new_vtable_count = old_vtable_count + miranda_list_size; vtable.Assign(vtable->CopyOf(self, new_vtable_count)); - if (UNLIKELY(vtable.Get() == NULL)) { + if (UNLIKELY(vtable.Get() == nullptr)) { CHECK(self->IsExceptionPending()); // OOME. return false; } @@ -4997,7 +4997,7 @@ bool ClassLinker::LinkInterfaceMethods(ConstHandle<mirror::Class> klass, mirror::ObjectArray<mirror::ArtMethod>* vtable = klass->GetVTableDuringLinking(); for (int i = 0; i < vtable->GetLength(); ++i) { - CHECK(vtable->Get(i) != NULL); + CHECK(vtable->Get(i) != nullptr); } self->AllowThreadSuspension(); @@ -5006,12 +5006,12 @@ bool ClassLinker::LinkInterfaceMethods(ConstHandle<mirror::Class> klass, } bool ClassLinker::LinkInstanceFields(Thread* self, ConstHandle<mirror::Class> klass) { - CHECK(klass.Get() != NULL); + CHECK(klass.Get() != nullptr); return LinkFields(self, klass, false, nullptr); } bool ClassLinker::LinkStaticFields(Thread* self, ConstHandle<mirror::Class> klass, size_t* class_size) { - CHECK(klass.Get() != NULL); + CHECK(klass.Get() != nullptr); return LinkFields(self, klass, true, class_size); } @@ -5063,14 +5063,14 @@ bool ClassLinker::LinkFields(Thread* self, ConstHandle<mirror::Class> klass, boo field_offset = MemberOffset(base); } else { mirror::Class* super_class = klass->GetSuperClass(); - if (super_class != NULL) { + if (super_class != nullptr) { CHECK(super_class->IsResolved()) << PrettyClass(klass.Get()) << " " << PrettyClass(super_class); field_offset = MemberOffset(super_class->GetObjectSize()); } } - CHECK_EQ(num_fields == 0, fields == NULL) << PrettyClass(klass.Get()); + CHECK_EQ(num_fields == 0, fields == nullptr) << PrettyClass(klass.Get()); // we want a relatively stable order so that adding new fields // minimizes disruption of C++ version such as Class and Method. @@ -5079,7 +5079,7 @@ bool ClassLinker::LinkFields(Thread* self, ConstHandle<mirror::Class> klass, boo "Naked ArtField references in deque"); for (size_t i = 0; i < num_fields; i++) { mirror::ArtField* f = fields->Get(i); - CHECK(f != NULL) << PrettyClass(klass.Get()); + CHECK(f != nullptr) << PrettyClass(klass.Get()); grouped_and_sorted_fields.push_back(f); } std::sort(grouped_and_sorted_fields.begin(), grouped_and_sorted_fields.end(), @@ -5191,7 +5191,7 @@ bool ClassLinker::LinkFields(Thread* self, ConstHandle<mirror::Class> klass, boo void ClassLinker::CreateReferenceInstanceOffsets(ConstHandle<mirror::Class> klass) { uint32_t reference_offsets = 0; mirror::Class* super_class = klass->GetSuperClass(); - if (super_class != NULL) { + if (super_class != nullptr) { reference_offsets = super_class->GetReferenceInstanceOffsets(); // If our superclass overflowed, we don't stand a chance. if (reference_offsets == CLASS_WALK_SUPER) { @@ -5230,7 +5230,7 @@ mirror::String* ClassLinker::ResolveString(const DexFile& dex_file, uint32_t str ConstHandle<mirror::DexCache> dex_cache) { DCHECK(dex_cache.Get() != nullptr); mirror::String* resolved = dex_cache->GetResolvedString(string_idx); - if (resolved != NULL) { + if (resolved != nullptr) { return resolved; } uint32_t utf16_length; @@ -5251,13 +5251,13 @@ mirror::Class* ClassLinker::ResolveType(const DexFile& dex_file, uint16_t type_i mirror::Class* ClassLinker::ResolveType(const DexFile& dex_file, uint16_t type_idx, ConstHandle<mirror::DexCache> dex_cache, ConstHandle<mirror::ClassLoader> class_loader) { - DCHECK(dex_cache.Get() != NULL); + DCHECK(dex_cache.Get() != nullptr); mirror::Class* resolved = dex_cache->GetResolvedType(type_idx); - if (resolved == NULL) { + if (resolved == nullptr) { Thread* self = Thread::Current(); const char* descriptor = dex_file.StringByTypeIdx(type_idx); resolved = FindClass(self, descriptor, class_loader); - if (resolved != NULL) { + if (resolved != nullptr) { // TODO: we used to throw here if resolved's class loader was not the // boot class loader. This was to permit different classes with the // same name to be loaded simultaneously by different loaders @@ -5269,14 +5269,14 @@ mirror::Class* ClassLinker::ResolveType(const DexFile& dex_file, uint16_t type_i StackHandleScope<1> hs(self); Handle<mirror::Throwable> cause(hs.NewHandle(self->GetException(nullptr))); if (cause->InstanceOf(GetClassRoot(kJavaLangClassNotFoundException))) { - DCHECK(resolved == NULL); // No Handle needed to preserve resolved. + DCHECK(resolved == nullptr); // No Handle needed to preserve resolved. self->ClearException(); ThrowNoClassDefFoundError("Failed resolution of: %s", descriptor); - self->GetException(NULL)->SetCause(cause.Get()); + self->GetException(nullptr)->SetCause(cause.Get()); } } } - DCHECK((resolved == NULL) || resolved->IsResolved() || resolved->IsErroneous()) + DCHECK((resolved == nullptr) || resolved->IsResolved() || resolved->IsErroneous()) << PrettyDescriptor(resolved) << " " << resolved->GetStatus(); return resolved; } @@ -5469,7 +5469,7 @@ mirror::ArtField* ClassLinker::ResolveField(const DexFile& dex_file, uint32_t fi } if (resolved == nullptr) { ThrowNoSuchFieldError(is_static ? "static " : "instance ", klass.Get(), type, name); - return NULL; + return nullptr; } } dex_cache->SetResolvedField(field_idx, resolved); @@ -5490,16 +5490,16 @@ mirror::ArtField* ClassLinker::ResolveFieldJLS(const DexFile& dex_file, StackHandleScope<1> hs(self); Handle<mirror::Class> klass( hs.NewHandle(ResolveType(dex_file, field_id.class_idx_, dex_cache, class_loader))); - if (klass.Get() == NULL) { + if (klass.Get() == nullptr) { DCHECK(Thread::Current()->IsExceptionPending()); - return NULL; + return nullptr; } StringPiece name(dex_file.StringDataByIdx(field_id.name_idx_)); StringPiece type(dex_file.StringDataByIdx( dex_file.GetTypeId(field_id.type_idx_).descriptor_idx_)); resolved = mirror::Class::FindField(self, klass, name, type); - if (resolved != NULL) { + if (resolved != nullptr) { dex_cache->SetResolvedField(field_idx, resolved); } else { ThrowNoSuchFieldError("", klass.Get(), type, name); @@ -5565,12 +5565,12 @@ pid_t ClassLinker::GetDexLockOwner() { void ClassLinker::SetClassRoot(ClassRoot class_root, mirror::Class* klass) { DCHECK(!init_done_); - DCHECK(klass != NULL); - DCHECK(klass->GetClassLoader() == NULL); + DCHECK(klass != nullptr); + DCHECK(klass->GetClassLoader() == nullptr); mirror::ObjectArray<mirror::Class>* class_roots = class_roots_.Read(); - DCHECK(class_roots != NULL); - DCHECK(class_roots->Get(class_root) == NULL); + DCHECK(class_roots != nullptr); + DCHECK(class_roots->Get(class_root) == nullptr); class_roots->Set<false>(class_root, klass); } diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc index 0de1e76..1502978 100644 --- a/runtime/verifier/method_verifier.cc +++ b/runtime/verifier/method_verifier.cc @@ -297,7 +297,7 @@ MethodVerifier::FailureKind MethodVerifier::VerifyMethod(Thread* self, uint32_t return result; } -void MethodVerifier::VerifyMethodAndDump(Thread* self, std::ostream& os, uint32_t dex_method_idx, +MethodVerifier* MethodVerifier::VerifyMethodAndDump(Thread* self, std::ostream& os, uint32_t dex_method_idx, const DexFile* dex_file, ConstHandle<mirror::DexCache> dex_cache, ConstHandle<mirror::ClassLoader> class_loader, @@ -305,12 +305,15 @@ void MethodVerifier::VerifyMethodAndDump(Thread* self, std::ostream& os, uint32_ const DexFile::CodeItem* code_item, ConstHandle<mirror::ArtMethod> method, uint32_t method_access_flags) { - MethodVerifier verifier(self, dex_file, dex_cache, class_loader, class_def, code_item, - dex_method_idx, method, method_access_flags, true, true, true); - verifier.Verify(); - verifier.DumpFailures(os); - os << verifier.info_messages_.str(); - verifier.Dump(os); + MethodVerifier* verifier = new MethodVerifier(self, dex_file, dex_cache, class_loader, + class_def, code_item, dex_method_idx, method, + method_access_flags, true, true, true, true); + verifier->Verify(); + verifier->DumpFailures(os); + os << verifier->info_messages_.str(); + verifier->Dump(os); + + return verifier; } MethodVerifier::MethodVerifier(Thread* self, @@ -320,7 +323,7 @@ MethodVerifier::MethodVerifier(Thread* self, const DexFile::CodeItem* code_item, uint32_t dex_method_idx, ConstHandle<mirror::ArtMethod> method, uint32_t method_access_flags, bool can_load_classes, bool allow_soft_failures, - bool need_precise_constants) + bool need_precise_constants, bool verify_to_dump) : self_(self), reg_types_(can_load_classes), work_insn_idx_(-1), @@ -344,7 +347,8 @@ MethodVerifier::MethodVerifier(Thread* self, allow_soft_failures_(allow_soft_failures), need_precise_constants_(need_precise_constants), has_check_casts_(false), - has_virtual_or_interface_invokes_(false) { + has_virtual_or_interface_invokes_(false), + verify_to_dump_(verify_to_dump) { Runtime::Current()->AddMethodVerifier(this); DCHECK(class_def != nullptr); } @@ -774,7 +778,7 @@ bool MethodVerifier::VerifyInstruction(const Instruction* inst, uint32_t code_of result = false; break; } - if (inst->GetVerifyIsRuntimeOnly() && Runtime::Current()->IsCompiler()) { + if (inst->GetVerifyIsRuntimeOnly() && Runtime::Current()->IsCompiler() && !verify_to_dump_) { Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "opcode only expected at runtime " << inst->Name(); result = false; } diff --git a/runtime/verifier/method_verifier.h b/runtime/verifier/method_verifier.h index eef2b9e..9fb19d3 100644 --- a/runtime/verifier/method_verifier.h +++ b/runtime/verifier/method_verifier.h @@ -150,12 +150,14 @@ class MethodVerifier { bool allow_soft_failures, std::string* error) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - static void VerifyMethodAndDump(Thread* self, std::ostream& os, uint32_t method_idx, - const DexFile* dex_file, ConstHandle<mirror::DexCache> dex_cache, - ConstHandle<mirror::ClassLoader> class_loader, - const DexFile::ClassDef* class_def, - const DexFile::CodeItem* code_item, - ConstHandle<mirror::ArtMethod> method, uint32_t method_access_flags) + static MethodVerifier* VerifyMethodAndDump(Thread* self, std::ostream& os, uint32_t method_idx, + const DexFile* dex_file, + ConstHandle<mirror::DexCache> dex_cache, + ConstHandle<mirror::ClassLoader> class_loader, + const DexFile::ClassDef* class_def, + const DexFile::CodeItem* code_item, + ConstHandle<mirror::ArtMethod> method, + uint32_t method_access_flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); uint8_t EncodePcToReferenceMapData() const; @@ -209,8 +211,10 @@ class MethodVerifier { const DexFile::CodeItem* code_item, uint32_t method_idx, ConstHandle<mirror::ArtMethod> method, uint32_t access_flags, bool can_load_classes, bool allow_soft_failures, - bool need_precise_constants) - SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); + bool need_precise_constants) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) + : MethodVerifier(self, dex_file, dex_cache, class_loader, class_def, code_item, method_idx, + method, access_flags, can_load_classes, allow_soft_failures, + need_precise_constants, false) {} ~MethodVerifier(); @@ -240,6 +244,15 @@ class MethodVerifier { SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); private: + // Private constructor for dumping. + MethodVerifier(Thread* self, const DexFile* dex_file, ConstHandle<mirror::DexCache> dex_cache, + ConstHandle<mirror::ClassLoader> class_loader, const DexFile::ClassDef* class_def, + const DexFile::CodeItem* code_item, uint32_t method_idx, + ConstHandle<mirror::ArtMethod> method, uint32_t access_flags, + bool can_load_classes, bool allow_soft_failures, bool need_precise_constants, + bool verify_to_dump) + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); + // Adds the given string to the beginning of the last failure message. void PrependToLastFailMessage(std::string); @@ -264,7 +277,7 @@ class MethodVerifier { const DexFile::CodeItem* code_item, ConstHandle<mirror::ArtMethod> method, uint32_t method_access_flags, bool allow_soft_failures, bool need_precise_constants) - SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); void FindLocksAtDexPc() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); @@ -508,7 +521,7 @@ class MethodVerifier { bool is_primitive, bool is_static) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - // Returns the access field of a quick field access (iget/iput-quick) or NULL + // Returns the access field of a quick field access (iget/iput-quick) or nullptr // if it cannot be found. mirror::ArtField* GetQuickFieldAccess(const Instruction* inst, RegisterLine* reg_line) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); @@ -563,7 +576,7 @@ class MethodVerifier { * Widening conversions on integers and references are allowed, but * narrowing conversions are not. * - * Returns the resolved method on success, NULL on failure (with *failure + * Returns the resolved method on success, nullptr on failure (with *failure * set appropriately). */ mirror::ArtMethod* VerifyInvocationArgs(const Instruction* inst, @@ -664,7 +677,7 @@ class MethodVerifier { // The dex PC of a FindLocksAtDexPc request, -1 otherwise. uint32_t interesting_dex_pc_; // The container into which FindLocksAtDexPc should write the registers containing held locks, - // NULL if we're not doing FindLocksAtDexPc. + // nullptr if we're not doing FindLocksAtDexPc. std::vector<uint32_t>* monitor_enter_dex_pcs_; // The types of any error that occurs. @@ -706,6 +719,11 @@ class MethodVerifier { // Indicates the method being verified contains at least one invoke-virtual/range // or invoke-interface/range. bool has_virtual_or_interface_invokes_; + + // Indicates whether we verify to dump the info. In that case we accept quickened instructions + // even though we might detect to be a compiler. Should only be set when running + // VerifyMethodAndDump. + const bool verify_to_dump_; }; std::ostream& operator<<(std::ostream& os, const MethodVerifier::FailureKind& rhs); |