diff options
332 files changed, 1764 insertions, 1274 deletions
diff --git a/build/Android.common_build.mk b/build/Android.common_build.mk index f5a95fa0cf..08962526dd 100644 --- a/build/Android.common_build.mk +++ b/build/Android.common_build.mk @@ -49,6 +49,11 @@ endif # Enable the read barrier by default. ART_USE_READ_BARRIER ?= true +# Default compact dex level to none. +ifeq ($(ART_DEFAULT_COMPACT_DEX_LEVEL),) +ART_DEFAULT_COMPACT_DEX_LEVEL := none +endif + ART_CPP_EXTENSION := .cc ifndef LIBART_IMG_HOST_BASE_ADDRESS diff --git a/build/art.go b/build/art.go index 5704b43834..3f598da00a 100644 --- a/build/art.go +++ b/build/art.go @@ -66,6 +66,9 @@ func globalFlags(ctx android.BaseContext) ([]string, []string) { "-DART_READ_BARRIER_TYPE_IS_"+barrierType+"=1") } + cdexLevel := envDefault(ctx, "ART_DEFAULT_COMPACT_DEX_LEVEL", "none") + cflags = append(cflags, "-DART_DEFAULT_COMPACT_DEX_LEVEL="+cdexLevel) + // We need larger stack overflow guards for ASAN, as the compiled code will have // larger frame sizes. For simplicity, just use global not-target-specific cflags. // Note: We increase this for both debug and non-debug, as the overflow gap will diff --git a/compiler/Android.bp b/compiler/Android.bp index 37a18cb9e9..fc19b54131 100644 --- a/compiler/Android.bp +++ b/compiler/Android.bp @@ -181,15 +181,10 @@ art_cc_defaults { ], }, }, - target: { - android: { - // For atrace. - shared_libs: ["libcutils"], - }, - }, generated_sources: ["art_compiler_operator_srcs"], shared_libs: [ "libbase", + "libcutils", // for atrace. "liblzma", ], include_dirs: ["art/disassembler"], diff --git a/compiler/compiler.cc b/compiler/compiler.cc index c500921ab3..bb614ae7b2 100644 --- a/compiler/compiler.cc +++ b/compiler/compiler.cc @@ -16,7 +16,9 @@ #include "compiler.h" -#include "base/logging.h" +#include <android-base/logging.h> + +#include "base/macros.h" #include "driver/compiler_driver.h" #include "optimizing/optimizing_compiler.h" #include "utils.h" diff --git a/compiler/debug/dwarf/writer.h b/compiler/debug/dwarf/writer.h index 95912ad6c9..afeb980352 100644 --- a/compiler/debug/dwarf/writer.h +++ b/compiler/debug/dwarf/writer.h @@ -19,8 +19,10 @@ #include <type_traits> #include <vector> + +#include <android-base/logging.h> + #include "base/bit_utils.h" -#include "base/logging.h" #include "leb128.h" namespace art { diff --git a/compiler/dex/dex_to_dex_compiler.cc b/compiler/dex/dex_to_dex_compiler.cc index cc452fc1ae..ead909af9a 100644 --- a/compiler/dex/dex_to_dex_compiler.cc +++ b/compiler/dex/dex_to_dex_compiler.cc @@ -16,11 +16,13 @@ #include "dex_to_dex_compiler.h" -#include "android-base/stringprintf.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> #include "art_field-inl.h" #include "art_method-inl.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG +#include "base/macros.h" #include "base/mutex.h" #include "bytecode_utils.h" #include "compiled_method.h" @@ -294,7 +296,6 @@ void DexCompiler::CompileInvokeVirtual(Instruction* inst, uint32_t dex_pc, ClassLinker* class_linker = unit_.GetClassLinker(); ArtMethod* resolved_method = class_linker->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>( - GetDexFile(), method_idx, unit_.GetDexCache(), unit_.GetClassLoader(), diff --git a/compiler/dex/verification_results.cc b/compiler/dex/verification_results.cc index 03c90d82c8..1e0b94de81 100644 --- a/compiler/dex/verification_results.cc +++ b/compiler/dex/verification_results.cc @@ -16,7 +16,8 @@ #include "verification_results.h" -#include "base/logging.h" +#include <android-base/logging.h> + #include "base/mutex-inl.h" #include "base/stl_util.h" #include "driver/compiler_driver.h" diff --git a/compiler/dex/verified_method.cc b/compiler/dex/verified_method.cc index 524b0a6911..8934201b10 100644 --- a/compiler/dex/verified_method.cc +++ b/compiler/dex/verified_method.cc @@ -19,7 +19,8 @@ #include <algorithm> #include <memory> -#include "base/logging.h" +#include <android-base/logging.h> + #include "code_item_accessors-inl.h" #include "dex_file.h" #include "dex_instruction-inl.h" diff --git a/compiler/driver/compiled_method_storage.cc b/compiler/driver/compiled_method_storage.cc index c739333cee..c8c2b6998f 100644 --- a/compiler/driver/compiled_method_storage.cc +++ b/compiler/driver/compiled_method_storage.cc @@ -19,7 +19,8 @@ #include "compiled_method_storage.h" -#include "base/logging.h" +#include <android-base/logging.h> + #include "compiled_method.h" #include "linker/linker_patch.h" #include "thread-current-inl.h" diff --git a/compiler/driver/compiler_driver-inl.h b/compiler/driver/compiler_driver-inl.h index b04392918d..294072d7e7 100644 --- a/compiler/driver/compiler_driver-inl.h +++ b/compiler/driver/compiler_driver-inl.h @@ -32,14 +32,16 @@ namespace art { -inline mirror::Class* CompilerDriver::ResolveClass( - const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, - Handle<mirror::ClassLoader> class_loader, dex::TypeIndex cls_index, +inline ObjPtr<mirror::Class> CompilerDriver::ResolveClass( + const ScopedObjectAccess& soa, + Handle<mirror::DexCache> dex_cache, + Handle<mirror::ClassLoader> class_loader, + dex::TypeIndex cls_index, const DexCompilationUnit* mUnit) { DCHECK_EQ(dex_cache->GetDexFile(), mUnit->GetDexFile()); DCHECK_EQ(class_loader.Get(), mUnit->GetClassLoader().Get()); - mirror::Class* cls = mUnit->GetClassLinker()->ResolveType( - *mUnit->GetDexFile(), cls_index, dex_cache, class_loader); + ObjPtr<mirror::Class> cls = + mUnit->GetClassLinker()->ResolveType(cls_index, dex_cache, class_loader); DCHECK_EQ(cls == nullptr, soa.Self()->IsExceptionPending()); if (UNLIKELY(cls == nullptr)) { // Clean up any exception left by type resolution. @@ -48,9 +50,11 @@ inline mirror::Class* CompilerDriver::ResolveClass( return cls; } -inline mirror::Class* CompilerDriver::ResolveCompilingMethodsClass( - const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, - Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit) { +inline ObjPtr<mirror::Class> CompilerDriver::ResolveCompilingMethodsClass( + const ScopedObjectAccess& soa, + Handle<mirror::DexCache> dex_cache, + Handle<mirror::ClassLoader> class_loader, + const DexCompilationUnit* mUnit) { DCHECK_EQ(dex_cache->GetDexFile(), mUnit->GetDexFile()); DCHECK_EQ(class_loader.Get(), mUnit->GetClassLoader().Get()); const DexFile::MethodId& referrer_method_id = @@ -58,13 +62,13 @@ inline mirror::Class* CompilerDriver::ResolveCompilingMethodsClass( return ResolveClass(soa, dex_cache, class_loader, referrer_method_id.class_idx_, mUnit); } -inline ArtField* CompilerDriver::ResolveFieldWithDexFile( - const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, - Handle<mirror::ClassLoader> class_loader, const DexFile* dex_file, - uint32_t field_idx, bool is_static) { - DCHECK_EQ(dex_cache->GetDexFile(), dex_file); +inline ArtField* CompilerDriver::ResolveField(const ScopedObjectAccess& soa, + Handle<mirror::DexCache> dex_cache, + Handle<mirror::ClassLoader> class_loader, + uint32_t field_idx, + bool is_static) { ArtField* resolved_field = Runtime::Current()->GetClassLinker()->ResolveField( - *dex_file, field_idx, dex_cache, class_loader, is_static); + field_idx, dex_cache, class_loader, is_static); DCHECK_EQ(resolved_field == nullptr, soa.Self()->IsExceptionPending()); if (UNLIKELY(resolved_field == nullptr)) { // Clean up any exception left by type resolution. @@ -79,18 +83,11 @@ inline ArtField* CompilerDriver::ResolveFieldWithDexFile( return resolved_field; } -inline ArtField* CompilerDriver::ResolveField( - const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, - Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit, - uint32_t field_idx, bool is_static) { - DCHECK_EQ(class_loader.Get(), mUnit->GetClassLoader().Get()); - return ResolveFieldWithDexFile(soa, dex_cache, class_loader, mUnit->GetDexFile(), field_idx, - is_static); -} - inline std::pair<bool, bool> CompilerDriver::IsFastInstanceField( - mirror::DexCache* dex_cache, mirror::Class* referrer_class, - ArtField* resolved_field, uint16_t field_idx) { + ObjPtr<mirror::DexCache> dex_cache, + ObjPtr<mirror::Class> referrer_class, + ArtField* resolved_field, + uint16_t field_idx) { DCHECK(!resolved_field->IsStatic()); ObjPtr<mirror::Class> fields_class = resolved_field->GetDeclaringClass(); bool fast_get = referrer_class != nullptr && @@ -112,7 +109,7 @@ inline ArtMethod* CompilerDriver::ResolveMethod( DCHECK_EQ(class_loader.Get(), mUnit->GetClassLoader().Get()); ArtMethod* resolved_method = mUnit->GetClassLinker()->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>( - *dex_cache->GetDexFile(), method_idx, dex_cache, class_loader, nullptr, invoke_type); + method_idx, dex_cache, class_loader, /* referrer */ nullptr, invoke_type); if (UNLIKELY(resolved_method == nullptr)) { DCHECK(soa.Self()->IsExceptionPending()); // Clean up any exception left by type resolution. diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc index 0ca3c8f613..0631c0f12c 100644 --- a/compiler/driver/compiler_driver.cc +++ b/compiler/driver/compiler_driver.cc @@ -32,6 +32,7 @@ #include "base/array_ref.h" #include "base/bit_vector.h" #include "base/enums.h" +#include "base/logging.h" // For VLOG #include "base/stl_util.h" #include "base/systrace.h" #include "base/time_utils.h" @@ -701,7 +702,6 @@ void CompilerDriver::Resolve(jobject class_loader, // stable order. static void ResolveConstStrings(Handle<mirror::DexCache> dex_cache, - const DexFile& dex_file, const DexFile::CodeItem* code_item) REQUIRES_SHARED(Locks::mutator_lock_) { if (code_item == nullptr) { @@ -717,7 +717,7 @@ static void ResolveConstStrings(Handle<mirror::DexCache> dex_cache, dex::StringIndex string_index((inst->Opcode() == Instruction::CONST_STRING) ? inst->VRegB_21c() : inst->VRegB_31c()); - mirror::String* string = class_linker->ResolveString(dex_file, string_index, dex_cache); + ObjPtr<mirror::String> string = class_linker->ResolveString(string_index, dex_cache); CHECK(string != nullptr) << "Could not allocate a string when forcing determinism"; break; } @@ -772,7 +772,7 @@ static void ResolveConstStrings(CompilerDriver* driver, continue; } previous_method_idx = method_idx; - ResolveConstStrings(dex_cache, *dex_file, it.GetMethodCodeItem()); + ResolveConstStrings(dex_cache, it.GetMethodCodeItem()); it.Next(); } DCHECK(!it.HasNext()); @@ -1048,22 +1048,21 @@ void CompilerDriver::LoadImageClasses(TimingLogger* timings) { for (const auto& exception_type : unresolved_exception_types) { dex::TypeIndex exception_type_idx = exception_type.first; const DexFile* dex_file = exception_type.second; - StackHandleScope<2> hs2(self); + StackHandleScope<1> hs2(self); Handle<mirror::DexCache> dex_cache(hs2.NewHandle(class_linker->RegisterDexFile(*dex_file, nullptr))); - Handle<mirror::Class> klass(hs2.NewHandle( + ObjPtr<mirror::Class> klass = (dex_cache != nullptr) - ? class_linker->ResolveType(*dex_file, - exception_type_idx, + ? class_linker->ResolveType(exception_type_idx, dex_cache, ScopedNullHandle<mirror::ClassLoader>()) - : nullptr)); + : nullptr; if (klass == 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; } - DCHECK(java_lang_Throwable->IsAssignableFrom(klass.Get())); + DCHECK(java_lang_Throwable->IsAssignableFrom(klass)); } // Resolving exceptions may load classes that reference more exceptions, iterate until no // more are found @@ -1367,17 +1366,18 @@ void CompilerDriver::ProcessedStaticField(bool resolved, bool local) { } ArtField* CompilerDriver::ComputeInstanceFieldInfo(uint32_t field_idx, - const DexCompilationUnit* mUnit, bool is_put, + const DexCompilationUnit* mUnit, + bool is_put, const ScopedObjectAccess& soa) { // Try to resolve the field and compiling method's class. ArtField* resolved_field; - mirror::Class* referrer_class; + ObjPtr<mirror::Class> referrer_class; Handle<mirror::DexCache> dex_cache(mUnit->GetDexCache()); { - Handle<mirror::ClassLoader> class_loader_handle = mUnit->GetClassLoader(); - resolved_field = ResolveField(soa, dex_cache, class_loader_handle, mUnit, field_idx, false); + Handle<mirror::ClassLoader> class_loader = mUnit->GetClassLoader(); + resolved_field = ResolveField(soa, dex_cache, class_loader, field_idx, /* is_static */ false); referrer_class = resolved_field != nullptr - ? ResolveCompilingMethodsClass(soa, dex_cache, class_loader_handle, mUnit) : nullptr; + ? ResolveCompilingMethodsClass(soa, dex_cache, class_loader, mUnit) : nullptr; } bool can_link = false; if (resolved_field != nullptr && referrer_class != nullptr) { @@ -1542,7 +1542,7 @@ class ParallelCompilationManager { // A fast version of SkipClass above if the class pointer is available // that avoids the expensive FindInClassPath search. -static bool SkipClass(jobject class_loader, const DexFile& dex_file, mirror::Class* klass) +static bool SkipClass(jobject class_loader, const DexFile& dex_file, ObjPtr<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_) { DCHECK(klass != nullptr); const DexFile& original_dex_file = *klass->GetDexCache()->GetDexFile(); @@ -1610,7 +1610,7 @@ class ResolveClassFieldsAndMethodsVisitor : public CompilationVisitor { : manager_(manager) {} void Visit(size_t class_def_index) OVERRIDE REQUIRES(!Locks::mutator_lock_) { - ATRACE_CALL(); + ScopedTrace trace(__FUNCTION__); Thread* const self = Thread::Current(); jobject jclass_loader = manager_->GetClassLoader(); const DexFile& dex_file = *manager_->GetDexFile(); @@ -1636,8 +1636,8 @@ class ResolveClassFieldsAndMethodsVisitor : public CompilationVisitor { Handle<mirror::DexCache> dex_cache(hs.NewHandle(class_linker->FindDexCache( soa.Self(), dex_file))); // Resolve the class. - mirror::Class* klass = class_linker->ResolveType(dex_file, class_def.class_idx_, dex_cache, - class_loader); + ObjPtr<mirror::Class> klass = + class_linker->ResolveType(class_def.class_idx_, dex_cache, class_loader); bool resolve_fields_and_methods; if (klass == nullptr) { // Class couldn't be resolved, for example, super-class is in a different dex file. Don't @@ -1663,8 +1663,8 @@ class ResolveClassFieldsAndMethodsVisitor : public CompilationVisitor { ClassDataItemIterator it(dex_file, class_data); while (it.HasNextStaticField()) { if (resolve_fields_and_methods) { - ArtField* field = class_linker->ResolveField(dex_file, it.GetMemberIndex(), - dex_cache, class_loader, true); + ArtField* field = class_linker->ResolveField( + it.GetMemberIndex(), dex_cache, class_loader, /* is_static */ true); if (field == nullptr) { CheckAndClearResolveException(soa.Self()); } @@ -1678,8 +1678,8 @@ class ResolveClassFieldsAndMethodsVisitor : public CompilationVisitor { requires_constructor_barrier = true; } if (resolve_fields_and_methods) { - ArtField* field = class_linker->ResolveField(dex_file, it.GetMemberIndex(), - dex_cache, class_loader, false); + ArtField* field = class_linker->ResolveField( + it.GetMemberIndex(), dex_cache, class_loader, /* is_static */ false); if (field == nullptr) { CheckAndClearResolveException(soa.Self()); } @@ -1689,7 +1689,10 @@ class ResolveClassFieldsAndMethodsVisitor : public CompilationVisitor { if (resolve_fields_and_methods) { while (it.HasNextMethod()) { ArtMethod* method = class_linker->ResolveMethod<ClassLinker::ResolveMode::kNoChecks>( - dex_file, it.GetMemberIndex(), dex_cache, class_loader, nullptr, + it.GetMemberIndex(), + dex_cache, + class_loader, + /* referrer */ nullptr, it.GetMethodInvokeType(class_def)); if (method == nullptr) { CheckAndClearResolveException(soa.Self()); @@ -1725,7 +1728,7 @@ class ResolveTypeVisitor : public CompilationVisitor { dex_file, class_loader.Get()))); ObjPtr<mirror::Class> klass = (dex_cache != nullptr) - ? class_linker->ResolveType(dex_file, dex::TypeIndex(type_idx), dex_cache, class_loader) + ? class_linker->ResolveType(dex::TypeIndex(type_idx), dex_cache, class_loader) : nullptr; if (klass == nullptr) { @@ -1955,7 +1958,7 @@ class VerifyClassVisitor : public CompilationVisitor { : manager_(manager), log_level_(log_level) {} virtual void Visit(size_t class_def_index) REQUIRES(!Locks::mutator_lock_) OVERRIDE { - ATRACE_CALL(); + ScopedTrace trace(__FUNCTION__); ScopedObjectAccess soa(Thread::Current()); const DexFile& dex_file = *manager_->GetDexFile(); const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index); @@ -2084,7 +2087,7 @@ class SetVerifiedClassVisitor : public CompilationVisitor { explicit SetVerifiedClassVisitor(const ParallelCompilationManager* manager) : manager_(manager) {} virtual void Visit(size_t class_def_index) REQUIRES(!Locks::mutator_lock_) OVERRIDE { - ATRACE_CALL(); + ScopedTrace trace(__FUNCTION__); ScopedObjectAccess soa(Thread::Current()); const DexFile& dex_file = *manager_->GetDexFile(); const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index); @@ -2148,7 +2151,7 @@ class InitializeClassVisitor : public CompilationVisitor { explicit InitializeClassVisitor(const ParallelCompilationManager* manager) : manager_(manager) {} void Visit(size_t class_def_index) OVERRIDE { - ATRACE_CALL(); + ScopedTrace trace(__FUNCTION__); jobject jclass_loader = manager_->GetClassLoader(); const DexFile& dex_file = *manager_->GetDexFile(); const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index); @@ -2328,22 +2331,20 @@ class InitializeClassVisitor : public CompilationVisitor { DCHECK(!klass->IsInitialized()); StackHandleScope<1> hs(Thread::Current()); - Handle<mirror::DexCache> h_dex_cache = hs.NewHandle(klass->GetDexCache()); - const DexFile* dex_file = manager_->GetDexFile(); + Handle<mirror::DexCache> dex_cache = hs.NewHandle(klass->GetDexCache()); const DexFile::ClassDef* class_def = klass->GetClassDef(); ClassLinker* class_linker = manager_->GetClassLinker(); // Check encoded final field values for strings and intern. - annotations::RuntimeEncodedStaticFieldValueIterator value_it(*dex_file, - &h_dex_cache, - &class_loader, + annotations::RuntimeEncodedStaticFieldValueIterator value_it(dex_cache, + class_loader, manager_->GetClassLinker(), *class_def); for ( ; value_it.HasNext(); value_it.Next()) { if (value_it.GetValueType() == annotations::RuntimeEncodedStaticFieldValueIterator::kString) { // Resolve the string. This will intern the string. art::ObjPtr<mirror::String> resolved = class_linker->ResolveString( - *dex_file, dex::StringIndex(value_it.GetJavaValue().i), h_dex_cache); + dex::StringIndex(value_it.GetJavaValue().i), dex_cache); CHECK(resolved != nullptr); } } @@ -2356,11 +2357,11 @@ class InitializeClassVisitor : public CompilationVisitor { for (const DexInstructionPcPair& inst : code_item->Instructions()) { if (inst->Opcode() == Instruction::CONST_STRING) { ObjPtr<mirror::String> s = class_linker->ResolveString( - *dex_file, dex::StringIndex(inst->VRegB_21c()), h_dex_cache); + dex::StringIndex(inst->VRegB_21c()), dex_cache); CHECK(s != nullptr); } else if (inst->Opcode() == Instruction::CONST_STRING_JUMBO) { ObjPtr<mirror::String> s = class_linker->ResolveString( - *dex_file, dex::StringIndex(inst->VRegB_31c()), h_dex_cache); + dex::StringIndex(inst->VRegB_31c()), dex_cache); CHECK(s != nullptr); } } @@ -2664,7 +2665,7 @@ class CompileClassVisitor : public CompilationVisitor { explicit CompileClassVisitor(const ParallelCompilationManager* manager) : manager_(manager) {} virtual void Visit(size_t class_def_index) REQUIRES(!Locks::mutator_lock_) OVERRIDE { - ATRACE_CALL(); + ScopedTrace trace(__FUNCTION__); const DexFile& dex_file = *manager_->GetDexFile(); const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index); ClassLinker* class_linker = manager_->GetClassLinker(); diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h index d2141e8bc7..e001726c95 100644 --- a/compiler/driver/compiler_driver.h +++ b/compiler/driver/compiler_driver.h @@ -219,36 +219,33 @@ class CompilerDriver { REQUIRES_SHARED(Locks::mutator_lock_); // Resolve compiling method's class. Returns null on failure. - mirror::Class* ResolveCompilingMethodsClass( - const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, - Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit) + ObjPtr<mirror::Class> ResolveCompilingMethodsClass(const ScopedObjectAccess& soa, + Handle<mirror::DexCache> dex_cache, + Handle<mirror::ClassLoader> class_loader, + const DexCompilationUnit* mUnit) REQUIRES_SHARED(Locks::mutator_lock_); - mirror::Class* ResolveClass( - const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, - Handle<mirror::ClassLoader> class_loader, dex::TypeIndex type_index, - const DexCompilationUnit* mUnit) + ObjPtr<mirror::Class> ResolveClass(const ScopedObjectAccess& soa, + Handle<mirror::DexCache> dex_cache, + Handle<mirror::ClassLoader> class_loader, + dex::TypeIndex type_index, + const DexCompilationUnit* mUnit) REQUIRES_SHARED(Locks::mutator_lock_); // Resolve a field. Returns null on failure, including incompatible class change. // NOTE: Unlike ClassLinker's ResolveField(), this method enforces is_static. - ArtField* ResolveField( - const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, - Handle<mirror::ClassLoader> class_loader, const DexCompilationUnit* mUnit, - uint32_t field_idx, bool is_static) - REQUIRES_SHARED(Locks::mutator_lock_); - - // Resolve a field with a given dex file. - ArtField* ResolveFieldWithDexFile( - const ScopedObjectAccess& soa, Handle<mirror::DexCache> dex_cache, - Handle<mirror::ClassLoader> class_loader, const DexFile* dex_file, - uint32_t field_idx, bool is_static) + ArtField* ResolveField(const ScopedObjectAccess& soa, + Handle<mirror::DexCache> dex_cache, + Handle<mirror::ClassLoader> class_loader, + uint32_t field_idx, + bool is_static) REQUIRES_SHARED(Locks::mutator_lock_); // Can we fast-path an IGET/IPUT access to an instance field? If yes, compute the field offset. - std::pair<bool, bool> IsFastInstanceField( - mirror::DexCache* dex_cache, mirror::Class* referrer_class, - ArtField* resolved_field, uint16_t field_idx) + std::pair<bool, bool> IsFastInstanceField(ObjPtr<mirror::DexCache> dex_cache, + ObjPtr<mirror::Class> referrer_class, + ArtField* resolved_field, + uint16_t field_idx) REQUIRES_SHARED(Locks::mutator_lock_); // Resolve a method. Returns null on failure, including incompatible class change. @@ -270,9 +267,9 @@ class CompilerDriver { REQUIRES(!Locks::mutator_lock_); ArtField* ComputeInstanceFieldInfo(uint32_t field_idx, - const DexCompilationUnit* mUnit, - bool is_put, - const ScopedObjectAccess& soa) + const DexCompilationUnit* mUnit, + bool is_put, + const ScopedObjectAccess& soa) REQUIRES_SHARED(Locks::mutator_lock_); diff --git a/compiler/jit/jit_compiler.cc b/compiler/jit/jit_compiler.cc index f33c5e1b97..88e3e5b230 100644 --- a/compiler/jit/jit_compiler.cc +++ b/compiler/jit/jit_compiler.cc @@ -21,7 +21,9 @@ #include "arch/instruction_set.h" #include "arch/instruction_set_features.h" #include "art_method-inl.h" +#include "base/logging.h" // For VLOG #include "base/stringpiece.h" +#include "base/systrace.h" #include "base/time_utils.h" #include "base/timing_logger.h" #include "base/unix_file/fd_file.h" @@ -162,6 +164,8 @@ JitCompiler::~JitCompiler() { } bool JitCompiler::CompileMethod(Thread* self, ArtMethod* method, bool osr) { + SCOPED_TRACE << "JIT compiling " << method->PrettyMethod(); + DCHECK(!method->IsProxyMethod()); DCHECK(method->GetDeclaringClass()->IsResolved()); diff --git a/compiler/jni/quick/arm/calling_convention_arm.cc b/compiler/jni/quick/arm/calling_convention_arm.cc index 3e637bcf43..54f193b551 100644 --- a/compiler/jni/quick/arm/calling_convention_arm.cc +++ b/compiler/jni/quick/arm/calling_convention_arm.cc @@ -16,7 +16,9 @@ #include "calling_convention_arm.h" -#include "base/logging.h" +#include <android-base/logging.h> + +#include "base/macros.h" #include "handle_scope-inl.h" #include "utils/arm/managed_register_arm.h" diff --git a/compiler/jni/quick/arm64/calling_convention_arm64.cc b/compiler/jni/quick/arm64/calling_convention_arm64.cc index 3afd7011ca..328ecbbc5c 100644 --- a/compiler/jni/quick/arm64/calling_convention_arm64.cc +++ b/compiler/jni/quick/arm64/calling_convention_arm64.cc @@ -16,7 +16,8 @@ #include "calling_convention_arm64.h" -#include "base/logging.h" +#include <android-base/logging.h> + #include "handle_scope-inl.h" #include "utils/arm64/managed_register_arm64.h" diff --git a/compiler/jni/quick/calling_convention.cc b/compiler/jni/quick/calling_convention.cc index 55c27d1a6a..ff814c8a6b 100644 --- a/compiler/jni/quick/calling_convention.cc +++ b/compiler/jni/quick/calling_convention.cc @@ -16,7 +16,7 @@ #include "calling_convention.h" -#include "base/logging.h" +#include <android-base/logging.h> #ifdef ART_ENABLE_CODEGEN_arm #include "jni/quick/arm/calling_convention_arm.h" diff --git a/compiler/jni/quick/jni_compiler.cc b/compiler/jni/quick/jni_compiler.cc index 37f7d632ca..136e3db062 100644 --- a/compiler/jni/quick/jni_compiler.cc +++ b/compiler/jni/quick/jni_compiler.cc @@ -25,7 +25,7 @@ #include "art_method.h" #include "base/arena_allocator.h" #include "base/enums.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "base/macros.h" #include "calling_convention.h" #include "class_linker.h" diff --git a/compiler/jni/quick/mips/calling_convention_mips.cc b/compiler/jni/quick/mips/calling_convention_mips.cc index 0e0716e911..5ec1addcb9 100644 --- a/compiler/jni/quick/mips/calling_convention_mips.cc +++ b/compiler/jni/quick/mips/calling_convention_mips.cc @@ -16,7 +16,8 @@ #include "calling_convention_mips.h" -#include "base/logging.h" +#include <android-base/logging.h> + #include "handle_scope-inl.h" #include "utils/mips/managed_register_mips.h" diff --git a/compiler/jni/quick/mips64/calling_convention_mips64.cc b/compiler/jni/quick/mips64/calling_convention_mips64.cc index afe6a762eb..a7012aefa8 100644 --- a/compiler/jni/quick/mips64/calling_convention_mips64.cc +++ b/compiler/jni/quick/mips64/calling_convention_mips64.cc @@ -16,7 +16,8 @@ #include "calling_convention_mips64.h" -#include "base/logging.h" +#include <android-base/logging.h> + #include "handle_scope-inl.h" #include "utils/mips64/managed_register_mips64.h" diff --git a/compiler/jni/quick/x86/calling_convention_x86.cc b/compiler/jni/quick/x86/calling_convention_x86.cc index 0bfcc3fb4d..ad58e3820d 100644 --- a/compiler/jni/quick/x86/calling_convention_x86.cc +++ b/compiler/jni/quick/x86/calling_convention_x86.cc @@ -16,7 +16,8 @@ #include "calling_convention_x86.h" -#include "base/logging.h" +#include <android-base/logging.h> + #include "handle_scope-inl.h" #include "utils/x86/managed_register_x86.h" diff --git a/compiler/jni/quick/x86_64/calling_convention_x86_64.cc b/compiler/jni/quick/x86_64/calling_convention_x86_64.cc index ba654f4750..e5e96d01fc 100644 --- a/compiler/jni/quick/x86_64/calling_convention_x86_64.cc +++ b/compiler/jni/quick/x86_64/calling_convention_x86_64.cc @@ -16,8 +16,9 @@ #include "calling_convention_x86_64.h" +#include <android-base/logging.h> + #include "base/bit_utils.h" -#include "base/logging.h" #include "handle_scope-inl.h" #include "utils/x86_64/managed_register_x86_64.h" diff --git a/compiler/linker/arm/relative_patcher_thumb2.cc b/compiler/linker/arm/relative_patcher_thumb2.cc index 48747fc379..78755176e4 100644 --- a/compiler/linker/arm/relative_patcher_thumb2.cc +++ b/compiler/linker/arm/relative_patcher_thumb2.cc @@ -16,6 +16,8 @@ #include "linker/arm/relative_patcher_thumb2.h" +#include <sstream> + #include "arch/arm/asm_support_arm.h" #include "art_method.h" #include "base/bit_utils.h" diff --git a/compiler/linker/error_delaying_output_stream.h b/compiler/linker/error_delaying_output_stream.h index 33e6b5ab23..659f1dc093 100644 --- a/compiler/linker/error_delaying_output_stream.h +++ b/compiler/linker/error_delaying_output_stream.h @@ -19,7 +19,9 @@ #include "output_stream.h" -#include "base/logging.h" +#include <android-base/logging.h> + +#include "base/macros.h" namespace art { namespace linker { diff --git a/compiler/linker/linker_patch.h b/compiler/linker/linker_patch.h index 0ac149029a..6f4e7746a6 100644 --- a/compiler/linker/linker_patch.h +++ b/compiler/linker/linker_patch.h @@ -20,8 +20,9 @@ #include <iosfwd> #include <stdint.h> +#include <android-base/logging.h> + #include "base/bit_utils.h" -#include "base/logging.h" #include "method_reference.h" namespace art { diff --git a/compiler/linker/output_stream_test.cc b/compiler/linker/output_stream_test.cc index ad298406be..f93ea7a709 100644 --- a/compiler/linker/output_stream_test.cc +++ b/compiler/linker/output_stream_test.cc @@ -17,7 +17,9 @@ #include "file_output_stream.h" #include "vector_output_stream.h" -#include "base/logging.h" +#include <android-base/logging.h> + +#include "base/macros.h" #include "base/unix_file/fd_file.h" #include "buffered_output_stream.h" #include "common_runtime_test.h" diff --git a/compiler/linker/vector_output_stream.cc b/compiler/linker/vector_output_stream.cc index 75f90e5f94..f2cae5b1d5 100644 --- a/compiler/linker/vector_output_stream.cc +++ b/compiler/linker/vector_output_stream.cc @@ -16,7 +16,7 @@ #include "vector_output_stream.h" -#include "base/logging.h" +#include <android-base/logging.h> namespace art { namespace linker { diff --git a/compiler/optimizing/block_builder.cc b/compiler/optimizing/block_builder.cc index ed000327ff..58f591bd1e 100644 --- a/compiler/optimizing/block_builder.cc +++ b/compiler/optimizing/block_builder.cc @@ -16,6 +16,7 @@ #include "block_builder.h" +#include "base/logging.h" // FOR VLOG. #include "bytecode_utils.h" #include "quicken_info.h" diff --git a/compiler/optimizing/code_generator_utils.cc b/compiler/optimizing/code_generator_utils.cc index 96fe2a17e6..dd47a1fc6c 100644 --- a/compiler/optimizing/code_generator_utils.cc +++ b/compiler/optimizing/code_generator_utils.cc @@ -15,9 +15,10 @@ */ #include "code_generator_utils.h" -#include "nodes.h" -#include "base/logging.h" +#include <android-base/logging.h> + +#include "nodes.h" namespace art { diff --git a/compiler/optimizing/data_type.h b/compiler/optimizing/data_type.h index d253036479..548fe28cee 100644 --- a/compiler/optimizing/data_type.h +++ b/compiler/optimizing/data_type.h @@ -19,7 +19,8 @@ #include <iosfwd> -#include "base/logging.h" +#include <android-base/logging.h> + #include "base/bit_utils.h" namespace art { diff --git a/compiler/optimizing/inliner.cc b/compiler/optimizing/inliner.cc index 560372e22e..8750910fe1 100644 --- a/compiler/optimizing/inliner.cc +++ b/compiler/optimizing/inliner.cc @@ -294,7 +294,7 @@ static dex::TypeIndex FindClassIndexIn(mirror::Class* cls, // as there may be different class loaders. So only return the index if it's // the right class already resolved with the class loader. if (index.IsValid()) { - ObjPtr<mirror::Class> resolved = ClassLinker::LookupResolvedType( + ObjPtr<mirror::Class> resolved = compilation_unit.GetClassLinker()->LookupResolvedType( index, compilation_unit.GetDexCache().Get(), compilation_unit.GetClassLoader().Get()); if (resolved != cls) { index = dex::TypeIndex::Invalid(); @@ -682,7 +682,7 @@ HInliner::InlineCacheType HInliner::ExtractClassesFromOfflineProfile( << "is invalid in location" << dex_cache->GetDexFile()->GetLocation(); return kInlineCacheNoData; } - ObjPtr<mirror::Class> clazz = ClassLinker::LookupResolvedType( + ObjPtr<mirror::Class> clazz = caller_compilation_unit_.GetClassLinker()->LookupResolvedType( class_ref.type_index, dex_cache, caller_compilation_unit_.GetClassLoader().Get()); @@ -876,9 +876,9 @@ HInstruction* HInliner::AddTypeGuard(HInstruction* receiver, load_class, codegen_, compiler_driver_, caller_compilation_unit_); DCHECK(kind != HLoadClass::LoadKind::kInvalid) << "We should always be able to reference a class for inline caches"; - // Insert before setting the kind, as setting the kind affects the inputs. - bb_cursor->InsertInstructionAfter(load_class, receiver_class); + // Load kind must be set before inserting the instruction into the graph. load_class->SetLoadKind(kind); + bb_cursor->InsertInstructionAfter(load_class, receiver_class); // In AOT mode, we will most likely load the class from BSS, which will involve a call // to the runtime. In this case, the load instruction will need an environment so copy // it from the invoke instruction. @@ -1932,7 +1932,7 @@ void HInliner::RunOptimizations(HGraph* callee_graph, // optimization that could lead to a HDeoptimize. The following optimizations do not. HDeadCodeElimination dce(callee_graph, inline_stats_, "dead_code_elimination$inliner"); HConstantFolding fold(callee_graph, "constant_folding$inliner"); - HSharpening sharpening(callee_graph, codegen_, dex_compilation_unit, compiler_driver_, handles_); + HSharpening sharpening(callee_graph, codegen_, compiler_driver_); InstructionSimplifier simplify(callee_graph, codegen_, compiler_driver_, inline_stats_); IntrinsicsRecognizer intrinsics(callee_graph, inline_stats_); diff --git a/compiler/optimizing/instruction_builder.cc b/compiler/optimizing/instruction_builder.cc index fc7b28c00f..e36d91fb05 100644 --- a/compiler/optimizing/instruction_builder.cc +++ b/compiler/optimizing/instruction_builder.cc @@ -794,7 +794,6 @@ ArtMethod* HInstructionBuilder::ResolveMethod(uint16_t method_idx, InvokeType in ArtMethod* resolved_method = class_linker->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>( - *dex_compilation_unit_->GetDexFile(), method_idx, dex_compilation_unit_->GetDexCache(), class_loader, @@ -829,7 +828,6 @@ ArtMethod* HInstructionBuilder::ResolveMethod(uint16_t method_idx, InvokeType in return nullptr; } ObjPtr<mirror::Class> referenced_class = class_linker->LookupResolvedType( - *dex_compilation_unit_->GetDexFile(), dex_compilation_unit_->GetDexFile()->GetMethodId(method_idx).class_idx_, dex_compilation_unit_->GetDexCache().Get(), class_loader.Get()); @@ -1126,7 +1124,7 @@ void HInstructionBuilder::BuildConstructorFenceForAllocation(HInstruction* alloc MethodCompilationStat::kConstructorFenceGeneratedNew); } -static bool IsSubClass(mirror::Class* to_test, mirror::Class* super_class) +static bool IsSubClass(ObjPtr<mirror::Class> to_test, ObjPtr<mirror::Class> super_class) REQUIRES_SHARED(Locks::mutator_lock_) { return to_test != nullptr && !to_test->IsInterface() && to_test->IsSubClass(super_class); } @@ -1422,8 +1420,8 @@ bool HInstructionBuilder::BuildInstanceFieldAccess(const Instruction& instructio return true; } -static mirror::Class* GetClassFrom(CompilerDriver* driver, - const DexCompilationUnit& compilation_unit) { +static ObjPtr<mirror::Class> GetClassFrom(CompilerDriver* driver, + const DexCompilationUnit& compilation_unit) { ScopedObjectAccess soa(Thread::Current()); Handle<mirror::ClassLoader> class_loader = compilation_unit.GetClassLoader(); Handle<mirror::DexCache> dex_cache = compilation_unit.GetDexCache(); @@ -1431,11 +1429,11 @@ static mirror::Class* GetClassFrom(CompilerDriver* driver, return driver->ResolveCompilingMethodsClass(soa, dex_cache, class_loader, &compilation_unit); } -mirror::Class* HInstructionBuilder::GetOutermostCompilingClass() const { +ObjPtr<mirror::Class> HInstructionBuilder::GetOutermostCompilingClass() const { return GetClassFrom(compiler_driver_, *outer_compilation_unit_); } -mirror::Class* HInstructionBuilder::GetCompilingClass() const { +ObjPtr<mirror::Class> HInstructionBuilder::GetCompilingClass() const { return GetClassFrom(compiler_driver_, *dex_compilation_unit_); } @@ -1482,8 +1480,7 @@ ArtField* HInstructionBuilder::ResolveField(uint16_t field_idx, bool is_static, Handle<mirror::ClassLoader> class_loader = dex_compilation_unit_->GetClassLoader(); Handle<mirror::Class> compiling_class(hs.NewHandle(GetCompilingClass())); - ArtField* resolved_field = class_linker->ResolveField(*dex_compilation_unit_->GetDexFile(), - field_idx, + ArtField* resolved_field = class_linker->ResolveField(field_idx, dex_compilation_unit_->GetDexCache(), class_loader, is_static); @@ -1797,6 +1794,17 @@ static TypeCheckKind ComputeTypeCheckKind(Handle<mirror::Class> cls) } } +void HInstructionBuilder::BuildLoadString(dex::StringIndex string_index, uint32_t dex_pc) { + HLoadString* load_string = + new (allocator_) HLoadString(graph_->GetCurrentMethod(), string_index, *dex_file_, dex_pc); + HSharpening::ProcessLoadString(load_string, + code_generator_, + compiler_driver_, + *dex_compilation_unit_, + handles_); + AppendInstruction(load_string); +} + HLoadClass* HInstructionBuilder::BuildLoadClass(dex::TypeIndex type_index, uint32_t dex_pc) { ScopedObjectAccess soa(Thread::Current()); const DexFile& dex_file = *dex_compilation_unit_->GetDexFile(); @@ -1809,7 +1817,7 @@ HLoadClass* HInstructionBuilder::BuildLoadClass(dex::TypeIndex type_index, uint3 if (klass->IsPublic()) { needs_access_check = false; } else { - mirror::Class* compiling_class = GetCompilingClass(); + ObjPtr<mirror::Class> compiling_class = GetCompilingClass(); if (compiling_class != nullptr && compiling_class->CanAccess(klass.Get())) { needs_access_check = false; } @@ -1854,9 +1862,9 @@ HLoadClass* HInstructionBuilder::BuildLoadClass(dex::TypeIndex type_index, // We actually cannot reference this class, we're forced to bail. return nullptr; } - // Append the instruction first, as setting the load kind affects the inputs. - AppendInstruction(load_class); + // Load kind must be set before inserting the instruction into the graph. load_class->SetLoadKind(load_kind); + AppendInstruction(load_class); return load_class; } @@ -2835,20 +2843,14 @@ bool HInstructionBuilder::ProcessDexInstruction(const Instruction& instruction, case Instruction::CONST_STRING: { dex::StringIndex string_index(instruction.VRegB_21c()); - AppendInstruction(new (allocator_) HLoadString(graph_->GetCurrentMethod(), - string_index, - *dex_file_, - dex_pc)); + BuildLoadString(string_index, dex_pc); UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction()); break; } case Instruction::CONST_STRING_JUMBO: { dex::StringIndex string_index(instruction.VRegB_31c()); - AppendInstruction(new (allocator_) HLoadString(graph_->GetCurrentMethod(), - string_index, - *dex_file_, - dex_pc)); + BuildLoadString(string_index, dex_pc); UpdateLocal(instruction.VRegA_31c(), current_block_->GetLastInstruction()); break; } @@ -2928,7 +2930,7 @@ bool HInstructionBuilder::ProcessDexInstruction(const Instruction& instruction, ObjPtr<mirror::Class> HInstructionBuilder::LookupResolvedType( dex::TypeIndex type_index, const DexCompilationUnit& compilation_unit) const { - return ClassLinker::LookupResolvedType( + return compilation_unit.GetClassLinker()->LookupResolvedType( type_index, compilation_unit.GetDexCache().Get(), compilation_unit.GetClassLoader().Get()); } diff --git a/compiler/optimizing/instruction_builder.h b/compiler/optimizing/instruction_builder.h index 2446ddb86a..0500d40cd3 100644 --- a/compiler/optimizing/instruction_builder.h +++ b/compiler/optimizing/instruction_builder.h @@ -240,9 +240,10 @@ class HInstructionBuilder : public ValueObject { // Builds an instruction sequence for a switch statement. void BuildSwitch(const Instruction& instruction, uint32_t dex_pc); - // Builds a `HLoadClass` loading the given `type_index`. If `outer` is true, - // this method will use the outer class's dex file to lookup the type at - // `type_index`. + // Builds a `HLoadString` loading the given `string_index`. + void BuildLoadString(dex::StringIndex string_index, uint32_t dex_pc); + + // Builds a `HLoadClass` loading the given `type_index`. HLoadClass* BuildLoadClass(dex::TypeIndex type_index, uint32_t dex_pc); HLoadClass* BuildLoadClass(dex::TypeIndex type_index, @@ -253,10 +254,10 @@ class HInstructionBuilder : public ValueObject { REQUIRES_SHARED(Locks::mutator_lock_); // Returns the outer-most compiling method's class. - mirror::Class* GetOutermostCompilingClass() const; + ObjPtr<mirror::Class> GetOutermostCompilingClass() const; // Returns the class whose method is being compiled. - mirror::Class* GetCompilingClass() const; + ObjPtr<mirror::Class> GetCompilingClass() const; // Returns whether `type_index` points to the outer-most compiling method's class. bool IsOutermostCompilingClass(dex::TypeIndex type_index) const; diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc index d117bfb67d..5f33ed6303 100644 --- a/compiler/optimizing/nodes.cc +++ b/compiler/optimizing/nodes.cc @@ -2831,21 +2831,6 @@ bool HLoadClass::InstructionDataEquals(const HInstruction* other) const { } } -void HLoadClass::SetLoadKind(LoadKind load_kind) { - SetPackedField<LoadKindField>(load_kind); - - if (load_kind != LoadKind::kRuntimeCall && - load_kind != LoadKind::kReferrersClass) { - RemoveAsUserOfInput(0u); - SetRawInputAt(0u, nullptr); - } - - if (!NeedsEnvironment()) { - RemoveEnvironment(); - SetSideEffects(SideEffects::None()); - } -} - std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs) { switch (rhs) { case HLoadClass::LoadKind::kReferrersClass: @@ -2888,21 +2873,6 @@ bool HLoadString::InstructionDataEquals(const HInstruction* other) const { } } -void HLoadString::SetLoadKind(LoadKind load_kind) { - // Once sharpened, the load kind should not be changed again. - DCHECK_EQ(GetLoadKind(), LoadKind::kRuntimeCall); - SetPackedField<LoadKindField>(load_kind); - - if (load_kind != LoadKind::kRuntimeCall) { - RemoveAsUserOfInput(0u); - SetRawInputAt(0u, nullptr); - } - if (!NeedsEnvironment()) { - RemoveEnvironment(); - SetSideEffects(SideEffects::None()); - } -} - std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs) { switch (rhs) { case HLoadString::LoadKind::kBootImageLinkTimePcRelative: diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h index 7fbd7f48a2..42a9d95b9a 100644 --- a/compiler/optimizing/nodes.h +++ b/compiler/optimizing/nodes.h @@ -6061,6 +6061,20 @@ class HLoadClass FINAL : public HInstruction { std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). +inline void HLoadClass::SetLoadKind(LoadKind load_kind) { + // The load kind should be determined before inserting the instruction to the graph. + DCHECK(GetBlock() == nullptr); + DCHECK(GetEnvironment() == nullptr); + SetPackedField<LoadKindField>(load_kind); + if (load_kind != LoadKind::kRuntimeCall && load_kind != LoadKind::kReferrersClass) { + special_input_ = HUserRecord<HInstruction*>(nullptr); + } + if (!NeedsEnvironment()) { + SetSideEffects(SideEffects::None()); + } +} + +// Note: defined outside class to see operator<<(., HLoadClass::LoadKind). inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { // The special input is used for PC-relative loads on some architectures, // including literal pool loads, which are PC-relative too. @@ -6208,6 +6222,21 @@ class HLoadString FINAL : public HInstruction { std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); // Note: defined outside class to see operator<<(., HLoadString::LoadKind). +inline void HLoadString::SetLoadKind(LoadKind load_kind) { + // The load kind should be determined before inserting the instruction to the graph. + DCHECK(GetBlock() == nullptr); + DCHECK(GetEnvironment() == nullptr); + DCHECK_EQ(GetLoadKind(), LoadKind::kRuntimeCall); + SetPackedField<LoadKindField>(load_kind); + if (load_kind != LoadKind::kRuntimeCall) { + special_input_ = HUserRecord<HInstruction*>(nullptr); + } + if (!NeedsEnvironment()) { + SetSideEffects(SideEffects::None()); + } +} + +// Note: defined outside class to see operator<<(., HLoadString::LoadKind). inline void HLoadString::AddSpecialInput(HInstruction* special_input) { // The special input is used for PC-relative loads on some architectures, // including literal pool loads, which are PC-relative too. diff --git a/compiler/optimizing/optimization.cc b/compiler/optimizing/optimization.cc index 7edb642c5b..7149d93d07 100644 --- a/compiler/optimizing/optimization.cc +++ b/compiler/optimizing/optimization.cc @@ -258,8 +258,7 @@ ArenaVector<HOptimization*> ConstructOptimizations( break; } case OptimizationPass::kSharpening: - opt = new (allocator) HSharpening( - graph, codegen, dex_compilation_unit, driver, handles, name); + opt = new (allocator) HSharpening(graph, codegen, driver, name); break; case OptimizationPass::kSelectGenerator: opt = new (allocator) HSelectGenerator(graph, handles, stats, name); diff --git a/compiler/optimizing/optimizing_compiler_stats.h b/compiler/optimizing/optimizing_compiler_stats.h index a2e92d2931..32a94ab5e4 100644 --- a/compiler/optimizing/optimizing_compiler_stats.h +++ b/compiler/optimizing/optimizing_compiler_stats.h @@ -23,6 +23,7 @@ #include <type_traits> #include "atomic.h" +#include "base/logging.h" // For VLOG_IS_ON. #include "globals.h" namespace art { diff --git a/compiler/optimizing/reference_type_propagation.cc b/compiler/optimizing/reference_type_propagation.cc index 7246129e25..8bb124e066 100644 --- a/compiler/optimizing/reference_type_propagation.cc +++ b/compiler/optimizing/reference_type_propagation.cc @@ -544,7 +544,7 @@ void ReferenceTypePropagation::RTPVisitor::SetClassAsTypeInfo(HInstruction* inst // the method is from the String class, the null loader is good enough. Handle<mirror::ClassLoader> loader(hs.NewHandle<mirror::ClassLoader>(nullptr)); ArtMethod* method = cl->ResolveMethod<ClassLinker::ResolveMode::kNoChecks>( - dex_file, invoke->GetDexMethodIndex(), dex_cache, loader, nullptr, kDirect); + invoke->GetDexMethodIndex(), dex_cache, loader, /* referrer */ nullptr, kDirect); DCHECK(method != nullptr); mirror::Class* declaring_class = method->GetDeclaringClass(); DCHECK(declaring_class != nullptr); @@ -576,8 +576,8 @@ void ReferenceTypePropagation::RTPVisitor::UpdateReferenceTypeInfo(HInstruction* ScopedObjectAccess soa(Thread::Current()); ObjPtr<mirror::DexCache> dex_cache = FindDexCacheWithHint(soa.Self(), dex_file, hint_dex_cache_); - ObjPtr<mirror::Class> klass = - ClassLinker::LookupResolvedType(type_idx, dex_cache, class_loader_.Get()); + ObjPtr<mirror::Class> klass = Runtime::Current()->GetClassLinker()->LookupResolvedType( + type_idx, dex_cache, class_loader_.Get()); SetClassAsTypeInfo(instr, klass, is_exact); } @@ -612,7 +612,7 @@ void ReferenceTypePropagation::RTPVisitor::UpdateFieldAccessTypeInfo(HInstructio // The field is unknown only during tests. if (info.GetField() != nullptr) { - klass = info.GetField()->LookupType(); + klass = info.GetField()->LookupResolvedType(); } SetClassAsTypeInfo(instr, klass, /* is_exact */ false); diff --git a/compiler/optimizing/sharpening.cc b/compiler/optimizing/sharpening.cc index e46c9a7081..1e49411c72 100644 --- a/compiler/optimizing/sharpening.cc +++ b/compiler/optimizing/sharpening.cc @@ -45,8 +45,6 @@ void HSharpening::Run() { SharpenInvokeStaticOrDirect(instruction->AsInvokeStaticOrDirect(), codegen_, compiler_driver_); - } else if (instruction->IsLoadString()) { - ProcessLoadString(instruction->AsLoadString()); } // TODO: Move the sharpening of invoke-virtual/-interface/-super from HGraphBuilder // here. Rewrite it to avoid the CompilerDriver's reliance on verifier data @@ -147,10 +145,11 @@ void HSharpening::SharpenInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke, invoke->SetDispatchInfo(dispatch_info); } -HLoadClass::LoadKind HSharpening::ComputeLoadClassKind(HLoadClass* load_class, - CodeGenerator* codegen, - CompilerDriver* compiler_driver, - const DexCompilationUnit& dex_compilation_unit) { +HLoadClass::LoadKind HSharpening::ComputeLoadClassKind( + HLoadClass* load_class, + CodeGenerator* codegen, + CompilerDriver* compiler_driver, + const DexCompilationUnit& dex_compilation_unit) { Handle<mirror::Class> klass = load_class->GetClass(); DCHECK(load_class->GetLoadKind() == HLoadClass::LoadKind::kRuntimeCall || load_class->GetLoadKind() == HLoadClass::LoadKind::kReferrersClass) @@ -237,7 +236,12 @@ HLoadClass::LoadKind HSharpening::ComputeLoadClassKind(HLoadClass* load_class, return load_kind; } -void HSharpening::ProcessLoadString(HLoadString* load_string) { +void HSharpening::ProcessLoadString( + HLoadString* load_string, + CodeGenerator* codegen, + CompilerDriver* compiler_driver, + const DexCompilationUnit& dex_compilation_unit, + VariableSizedHandleScope* handles) { DCHECK_EQ(load_string->GetLoadKind(), HLoadString::LoadKind::kRuntimeCall); const DexFile& dex_file = load_string->GetDexFile(); @@ -249,27 +253,27 @@ void HSharpening::ProcessLoadString(HLoadString* load_string) { ClassLinker* class_linker = runtime->GetClassLinker(); ScopedObjectAccess soa(Thread::Current()); StackHandleScope<1> hs(soa.Self()); - Handle<mirror::DexCache> dex_cache = IsSameDexFile(dex_file, *compilation_unit_.GetDexFile()) - ? compilation_unit_.GetDexCache() + Handle<mirror::DexCache> dex_cache = IsSameDexFile(dex_file, *dex_compilation_unit.GetDexFile()) + ? dex_compilation_unit.GetDexCache() : hs.NewHandle(class_linker->FindDexCache(soa.Self(), dex_file)); - mirror::String* string = nullptr; + ObjPtr<mirror::String> string = nullptr; - if (codegen_->GetCompilerOptions().IsBootImage()) { + if (codegen->GetCompilerOptions().IsBootImage()) { // Compiling boot image. Resolve the string and allocate it if needed, to ensure // the string will be added to the boot image. DCHECK(!runtime->UseJitCompilation()); - string = class_linker->ResolveString(dex_file, string_index, dex_cache); + string = class_linker->ResolveString(string_index, dex_cache); CHECK(string != nullptr); - if (compiler_driver_->GetSupportBootImageFixup()) { - DCHECK(ContainsElement(compiler_driver_->GetDexFilesForOatFile(), &dex_file)); + if (compiler_driver->GetSupportBootImageFixup()) { + DCHECK(ContainsElement(compiler_driver->GetDexFilesForOatFile(), &dex_file)); desired_load_kind = HLoadString::LoadKind::kBootImageLinkTimePcRelative; } else { // compiler_driver_test. Do not sharpen. desired_load_kind = HLoadString::LoadKind::kRuntimeCall; } } else if (runtime->UseJitCompilation()) { - DCHECK(!codegen_->GetCompilerOptions().GetCompilePic()); - string = class_linker->LookupString(dex_file, string_index, dex_cache.Get()); + DCHECK(!codegen->GetCompilerOptions().GetCompilePic()); + string = class_linker->LookupString(string_index, dex_cache.Get()); if (string != nullptr) { if (runtime->GetHeap()->ObjectIsInBootImageSpace(string)) { desired_load_kind = HLoadString::LoadKind::kBootImageAddress; @@ -281,9 +285,9 @@ void HSharpening::ProcessLoadString(HLoadString* load_string) { } } else { // AOT app compilation. Try to lookup the string without allocating if not found. - string = class_linker->LookupString(dex_file, string_index, dex_cache.Get()); + string = class_linker->LookupString(string_index, dex_cache.Get()); if (string != nullptr && runtime->GetHeap()->ObjectIsInBootImageSpace(string)) { - if (codegen_->GetCompilerOptions().GetCompilePic()) { + if (codegen->GetCompilerOptions().GetCompilePic()) { desired_load_kind = HLoadString::LoadKind::kBootImageInternTable; } else { desired_load_kind = HLoadString::LoadKind::kBootImageAddress; @@ -293,12 +297,12 @@ void HSharpening::ProcessLoadString(HLoadString* load_string) { } } if (string != nullptr) { - load_string->SetString(handles_->NewHandle(string)); + load_string->SetString(handles->NewHandle(string)); } } DCHECK_NE(desired_load_kind, static_cast<HLoadString::LoadKind>(-1)); - HLoadString::LoadKind load_kind = codegen_->GetSupportedLoadStringKind(desired_load_kind); + HLoadString::LoadKind load_kind = codegen->GetSupportedLoadStringKind(desired_load_kind); load_string->SetLoadKind(load_kind); } diff --git a/compiler/optimizing/sharpening.h b/compiler/optimizing/sharpening.h index bb1954eeeb..6df7d6d91e 100644 --- a/compiler/optimizing/sharpening.h +++ b/compiler/optimizing/sharpening.h @@ -34,26 +34,29 @@ class HSharpening : public HOptimization { public: HSharpening(HGraph* graph, CodeGenerator* codegen, - const DexCompilationUnit& compilation_unit, CompilerDriver* compiler_driver, - VariableSizedHandleScope* handles, const char* name = kSharpeningPassName) : HOptimization(graph, name), codegen_(codegen), - compilation_unit_(compilation_unit), - compiler_driver_(compiler_driver), - handles_(handles) { } + compiler_driver_(compiler_driver) { } void Run() OVERRIDE; static constexpr const char* kSharpeningPassName = "sharpening"; + // Used by the builder. + static void ProcessLoadString(HLoadString* load_string, + CodeGenerator* codegen, + CompilerDriver* compiler_driver, + const DexCompilationUnit& dex_compilation_unit, + VariableSizedHandleScope* handles); + // Used by the builder and the inliner. static HLoadClass::LoadKind ComputeLoadClassKind(HLoadClass* load_class, CodeGenerator* codegen, CompilerDriver* compiler_driver, const DexCompilationUnit& dex_compilation_unit) - REQUIRES_SHARED(Locks::mutator_lock_); + REQUIRES_SHARED(Locks::mutator_lock_); // Used by Sharpening and InstructionSimplifier. static void SharpenInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke, @@ -61,12 +64,8 @@ class HSharpening : public HOptimization { CompilerDriver* compiler_driver); private: - void ProcessLoadString(HLoadString* load_string); - CodeGenerator* codegen_; - const DexCompilationUnit& compilation_unit_; CompilerDriver* compiler_driver_; - VariableSizedHandleScope* handles_; }; } // namespace art diff --git a/compiler/utils/arm/assembler_arm_vixl.h b/compiler/utils/arm/assembler_arm_vixl.h index 0e73e6bf9e..1377e64073 100644 --- a/compiler/utils/arm/assembler_arm_vixl.h +++ b/compiler/utils/arm/assembler_arm_vixl.h @@ -17,8 +17,10 @@ #ifndef ART_COMPILER_UTILS_ARM_ASSEMBLER_ARM_VIXL_H_ #define ART_COMPILER_UTILS_ARM_ASSEMBLER_ARM_VIXL_H_ +#include <android-base/logging.h> + #include "base/arena_containers.h" -#include "base/logging.h" +#include "base/macros.h" #include "constants_arm.h" #include "offsets.h" #include "utils/arm/assembler_arm_shared.h" diff --git a/compiler/utils/arm/constants_arm.h b/compiler/utils/arm/constants_arm.h index 5b87e3e7f8..66252bed86 100644 --- a/compiler/utils/arm/constants_arm.h +++ b/compiler/utils/arm/constants_arm.h @@ -21,9 +21,10 @@ #include <iosfwd> +#include <android-base/logging.h> + #include "arch/arm/registers_arm.h" #include "base/casts.h" -#include "base/logging.h" #include "globals.h" namespace art { diff --git a/compiler/utils/arm/jni_macro_assembler_arm_vixl.h b/compiler/utils/arm/jni_macro_assembler_arm_vixl.h index c13c9af819..4bc5d69f4d 100644 --- a/compiler/utils/arm/jni_macro_assembler_arm_vixl.h +++ b/compiler/utils/arm/jni_macro_assembler_arm_vixl.h @@ -17,8 +17,10 @@ #ifndef ART_COMPILER_UTILS_ARM_JNI_MACRO_ASSEMBLER_ARM_VIXL_H_ #define ART_COMPILER_UTILS_ARM_JNI_MACRO_ASSEMBLER_ARM_VIXL_H_ +#include <android-base/logging.h> + #include "base/arena_containers.h" -#include "base/logging.h" +#include "base/macros.h" #include "constants_arm.h" #include "offsets.h" #include "utils/arm/assembler_arm_shared.h" diff --git a/compiler/utils/arm/managed_register_arm.h b/compiler/utils/arm/managed_register_arm.h index 2be2d5638e..26f23b2ed6 100644 --- a/compiler/utils/arm/managed_register_arm.h +++ b/compiler/utils/arm/managed_register_arm.h @@ -17,7 +17,8 @@ #ifndef ART_COMPILER_UTILS_ARM_MANAGED_REGISTER_ARM_H_ #define ART_COMPILER_UTILS_ARM_MANAGED_REGISTER_ARM_H_ -#include "base/logging.h" +#include <android-base/logging.h> + #include "constants_arm.h" #include "debug/dwarf/register.h" #include "utils/managed_register.h" diff --git a/compiler/utils/arm64/assembler_arm64.cc b/compiler/utils/arm64/assembler_arm64.cc index bb989588d6..c83fd4404a 100644 --- a/compiler/utils/arm64/assembler_arm64.cc +++ b/compiler/utils/arm64/assembler_arm64.cc @@ -15,7 +15,6 @@ */ #include "assembler_arm64.h" -#include "base/logging.h" #include "entrypoints/quick/quick_entrypoints.h" #include "heap_poisoning.h" #include "offsets.h" diff --git a/compiler/utils/arm64/assembler_arm64.h b/compiler/utils/arm64/assembler_arm64.h index e5ec24add0..8983af2677 100644 --- a/compiler/utils/arm64/assembler_arm64.h +++ b/compiler/utils/arm64/assembler_arm64.h @@ -21,8 +21,10 @@ #include <memory> #include <vector> +#include <android-base/logging.h> + #include "base/arena_containers.h" -#include "base/logging.h" +#include "base/macros.h" #include "offsets.h" #include "utils/arm64/managed_register_arm64.h" #include "utils/assembler.h" diff --git a/compiler/utils/arm64/jni_macro_assembler_arm64.cc b/compiler/utils/arm64/jni_macro_assembler_arm64.cc index 573bb6d4be..a5aa1c12b3 100644 --- a/compiler/utils/arm64/jni_macro_assembler_arm64.cc +++ b/compiler/utils/arm64/jni_macro_assembler_arm64.cc @@ -16,7 +16,6 @@ #include "jni_macro_assembler_arm64.h" -#include "base/logging.h" #include "entrypoints/quick/quick_entrypoints.h" #include "managed_register_arm64.h" #include "offsets.h" diff --git a/compiler/utils/arm64/jni_macro_assembler_arm64.h b/compiler/utils/arm64/jni_macro_assembler_arm64.h index ce39a13692..f531b2aa51 100644 --- a/compiler/utils/arm64/jni_macro_assembler_arm64.h +++ b/compiler/utils/arm64/jni_macro_assembler_arm64.h @@ -21,10 +21,12 @@ #include <memory> #include <vector> +#include <android-base/logging.h> + #include "assembler_arm64.h" #include "base/arena_containers.h" #include "base/enums.h" -#include "base/logging.h" +#include "base/macros.h" #include "offsets.h" #include "utils/assembler.h" #include "utils/jni_macro_assembler.h" diff --git a/compiler/utils/arm64/managed_register_arm64.h b/compiler/utils/arm64/managed_register_arm64.h index 7378a0a081..9ce7ec9a97 100644 --- a/compiler/utils/arm64/managed_register_arm64.h +++ b/compiler/utils/arm64/managed_register_arm64.h @@ -17,8 +17,9 @@ #ifndef ART_COMPILER_UTILS_ARM64_MANAGED_REGISTER_ARM64_H_ #define ART_COMPILER_UTILS_ARM64_MANAGED_REGISTER_ARM64_H_ +#include <android-base/logging.h> + #include "arch/arm64/registers_arm64.h" -#include "base/logging.h" #include "debug/dwarf/register.h" #include "utils/managed_register.h" diff --git a/compiler/utils/assembler.h b/compiler/utils/assembler.h index e0cef859e1..5b0cd6baa8 100644 --- a/compiler/utils/assembler.h +++ b/compiler/utils/assembler.h @@ -19,6 +19,8 @@ #include <vector> +#include <android-base/logging.h> + #include "arch/instruction_set.h" #include "arch/instruction_set_features.h" #include "arm/constants_arm.h" @@ -26,7 +28,6 @@ #include "base/arena_object.h" #include "base/array_ref.h" #include "base/enums.h" -#include "base/logging.h" #include "base/macros.h" #include "debug/dwarf/debug_frame_opcode_writer.h" #include "label.h" diff --git a/compiler/utils/intrusive_forward_list.h b/compiler/utils/intrusive_forward_list.h index 5a358ac2c4..ccdd32aad4 100644 --- a/compiler/utils/intrusive_forward_list.h +++ b/compiler/utils/intrusive_forward_list.h @@ -23,8 +23,9 @@ #include <memory> #include <type_traits> +#include <android-base/logging.h> + #include "base/casts.h" -#include "base/logging.h" #include "base/macros.h" namespace art { diff --git a/compiler/utils/jni_macro_assembler.h b/compiler/utils/jni_macro_assembler.h index 0fc1353bf5..f5df926749 100644 --- a/compiler/utils/jni_macro_assembler.h +++ b/compiler/utils/jni_macro_assembler.h @@ -19,12 +19,13 @@ #include <vector> +#include <android-base/logging.h> + #include "arch/instruction_set.h" #include "base/arena_allocator.h" #include "base/arena_object.h" #include "base/array_ref.h" #include "base/enums.h" -#include "base/logging.h" #include "base/macros.h" #include "managed_register.h" #include "offsets.h" diff --git a/compiler/utils/label.h b/compiler/utils/label.h index b9d4e9c521..3c91b2ffd1 100644 --- a/compiler/utils/label.h +++ b/compiler/utils/label.h @@ -17,8 +17,8 @@ #ifndef ART_COMPILER_UTILS_LABEL_H_ #define ART_COMPILER_UTILS_LABEL_H_ -#include "base/logging.h" -#include "base/macros.h" +#include <android-base/logging.h> +#include <android-base/macros.h> namespace art { diff --git a/compiler/utils/mips/constants_mips.h b/compiler/utils/mips/constants_mips.h index b4dfdbd8d3..016c0dbb2e 100644 --- a/compiler/utils/mips/constants_mips.h +++ b/compiler/utils/mips/constants_mips.h @@ -19,8 +19,9 @@ #include <iosfwd> +#include <android-base/logging.h> + #include "arch/mips/registers_mips.h" -#include "base/logging.h" #include "base/macros.h" #include "globals.h" diff --git a/compiler/utils/mips64/constants_mips64.h b/compiler/utils/mips64/constants_mips64.h index bc8e40b437..310f23c287 100644 --- a/compiler/utils/mips64/constants_mips64.h +++ b/compiler/utils/mips64/constants_mips64.h @@ -19,8 +19,9 @@ #include <iosfwd> +#include <android-base/logging.h> + #include "arch/mips64/registers_mips64.h" -#include "base/logging.h" #include "base/macros.h" #include "globals.h" diff --git a/compiler/utils/swap_space.cc b/compiler/utils/swap_space.cc index 12d113d420..1f9ad4242d 100644 --- a/compiler/utils/swap_space.cc +++ b/compiler/utils/swap_space.cc @@ -22,7 +22,6 @@ #include <numeric> #include "base/bit_utils.h" -#include "base/logging.h" #include "base/macros.h" #include "base/mutex.h" #include "thread-current-inl.h" diff --git a/compiler/utils/swap_space.h b/compiler/utils/swap_space.h index 2280f8b993..76df527108 100644 --- a/compiler/utils/swap_space.h +++ b/compiler/utils/swap_space.h @@ -24,7 +24,8 @@ #include <set> #include <vector> -#include "base/logging.h" +#include <android-base/logging.h> + #include "base/macros.h" #include "base/mutex.h" diff --git a/compiler/utils/test_dex_file_builder.h b/compiler/utils/test_dex_file_builder.h index 0da30fe768..441ef8e117 100644 --- a/compiler/utils/test_dex_file_builder.h +++ b/compiler/utils/test_dex_file_builder.h @@ -24,8 +24,9 @@ #include <set> #include <vector> +#include <android-base/logging.h> + #include "base/bit_utils.h" -#include "base/logging.h" #include "dex_file_loader.h" #include "standard_dex_file.h" diff --git a/compiler/utils/x86/constants_x86.h b/compiler/utils/x86/constants_x86.h index 0bc1560ed7..2e03b9fc3c 100644 --- a/compiler/utils/x86/constants_x86.h +++ b/compiler/utils/x86/constants_x86.h @@ -19,8 +19,9 @@ #include <iosfwd> +#include <android-base/logging.h> + #include "arch/x86/registers_x86.h" -#include "base/logging.h" #include "base/macros.h" #include "globals.h" diff --git a/compiler/utils/x86_64/constants_x86_64.h b/compiler/utils/x86_64/constants_x86_64.h index cc508a196b..2af3e7be16 100644 --- a/compiler/utils/x86_64/constants_x86_64.h +++ b/compiler/utils/x86_64/constants_x86_64.h @@ -19,8 +19,9 @@ #include <iosfwd> +#include <android-base/logging.h> + #include "arch/x86_64/registers_x86_64.h" -#include "base/logging.h" #include "base/macros.h" #include "globals.h" diff --git a/compiler/verifier_deps_test.cc b/compiler/verifier_deps_test.cc index 4709fd0e9e..ee1d7c69bc 100644 --- a/compiler/verifier_deps_test.cc +++ b/compiler/verifier_deps_test.cc @@ -158,11 +158,10 @@ class VerifierDepsTest : public CommonCompilerTest { while (it.HasNextDirectMethod()) { ArtMethod* resolved_method = class_linker_->ResolveMethod<ClassLinker::ResolveMode::kNoChecks>( - *primary_dex_file_, it.GetMemberIndex(), dex_cache_handle, class_loader_handle, - nullptr, + /* referrer */ nullptr, it.GetMethodInvokeType(*class_def)); CHECK(resolved_method != nullptr); if (method_name == resolved_method->GetName()) { diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc index 27bec1d3e1..7cb04f2aa8 100644 --- a/dex2oat/dex2oat.cc +++ b/dex2oat/dex2oat.cc @@ -345,7 +345,7 @@ NO_RETURN static void Usage(const char* fmt, ...) { CompilerOptions::kDefaultInlineMaxCodeUnits); UsageError(" Default: %d", CompilerOptions::kDefaultInlineMaxCodeUnits); UsageError(""); - UsageError(" --dump-timing: display a breakdown of where time was spent"); + UsageError(" --dump-timings: display a breakdown of where time was spent"); UsageError(""); UsageError(" -g"); UsageError(" --generate-debug-info: Generate debug information for native debugging,"); @@ -2814,7 +2814,7 @@ class Dex2Oat FINAL { // Dex files we are compiling, does not include the class path dex files. std::vector<const DexFile*> dex_files_; std::string no_inline_from_string_; - CompactDexLevel compact_dex_level_ = CompactDexLevel::kCompactDexLevelNone; + CompactDexLevel compact_dex_level_ = kDefaultCompactDexLevel; std::vector<std::unique_ptr<linker::ElfWriter>> elf_writers_; std::vector<std::unique_ptr<linker::OatWriter>> oat_writers_; diff --git a/dex2oat/dex2oat_image_test.cc b/dex2oat/dex2oat_image_test.cc index a02fbf862f..035b395300 100644 --- a/dex2oat/dex2oat_image_test.cc +++ b/dex2oat/dex2oat_image_test.cc @@ -22,10 +22,11 @@ #include <sys/wait.h> #include <unistd.h> +#include <android-base/logging.h> + #include "common_runtime_test.h" #include "base/file_utils.h" -#include "base/logging.h" #include "base/macros.h" #include "base/unix_file/fd_file.h" #include "dex_file-inl.h" diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc index ad287b0745..8805aa1d14 100644 --- a/dex2oat/dex2oat_test.cc +++ b/dex2oat/dex2oat_test.cc @@ -22,11 +22,11 @@ #include <sys/wait.h> #include <unistd.h> -#include "android-base/stringprintf.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> #include "common_runtime_test.h" -#include "base/logging.h" #include "base/macros.h" #include "base/mutex-inl.h" #include "bytecode_utils.h" diff --git a/dex2oat/linker/elf_writer_quick.cc b/dex2oat/linker/elf_writer_quick.cc index b139a12fd4..5fc33ddf8b 100644 --- a/dex2oat/linker/elf_writer_quick.cc +++ b/dex2oat/linker/elf_writer_quick.cc @@ -20,8 +20,9 @@ #include <unordered_map> #include <unordered_set> +#include <android-base/logging.h> + #include "base/casts.h" -#include "base/logging.h" #include "compiled_method.h" #include "debug/elf_debug_writer.h" #include "debug/method_debug_info.h" diff --git a/dex2oat/linker/image_writer.cc b/dex2oat/linker/image_writer.cc index 5ade583b88..738bbf8e9d 100644 --- a/dex2oat/linker/image_writer.cc +++ b/dex2oat/linker/image_writer.cc @@ -29,7 +29,7 @@ #include "art_method-inl.h" #include "base/callee_save_type.h" #include "base/enums.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "base/unix_file/fd_file.h" #include "class_linker-inl.h" #include "compiled_method.h" @@ -1050,8 +1050,7 @@ void ImageWriter::PruneAndPreloadDexCache(ObjPtr<mirror::DexCache> dex_cache, const DexFile::MethodId& method_id = dex_file.GetMethodId(i); if (method_id.class_idx_ != last_class_idx) { last_class_idx = method_id.class_idx_; - last_class = class_linker->LookupResolvedType( - dex_file, last_class_idx, dex_cache, class_loader); + last_class = class_linker->LookupResolvedType(last_class_idx, dex_cache, class_loader); if (last_class != nullptr && !KeepClass(last_class)) { last_class = nullptr; } @@ -1096,8 +1095,7 @@ void ImageWriter::PruneAndPreloadDexCache(ObjPtr<mirror::DexCache> dex_cache, const DexFile::FieldId& field_id = dex_file.GetFieldId(i); if (field_id.class_idx_ != last_class_idx) { last_class_idx = field_id.class_idx_; - last_class = class_linker->LookupResolvedType( - dex_file, last_class_idx, dex_cache, class_loader); + last_class = class_linker->LookupResolvedType(last_class_idx, dex_cache, class_loader); if (last_class != nullptr && !KeepClass(last_class)) { last_class = nullptr; } @@ -1130,7 +1128,7 @@ void ImageWriter::PruneAndPreloadDexCache(ObjPtr<mirror::DexCache> dex_cache, uint32_t stored_index = pair.index; ObjPtr<mirror::Class> klass = pair.object.Read(); if (klass == nullptr || i < stored_index) { - klass = class_linker->LookupResolvedType(dex_file, type_idx, dex_cache, class_loader); + klass = class_linker->LookupResolvedType(type_idx, dex_cache, class_loader); if (klass != nullptr) { DCHECK_EQ(dex_cache->GetResolvedType(type_idx), klass); stored_index = i; // For correct clearing below if not keeping the `klass`. @@ -1148,7 +1146,7 @@ void ImageWriter::PruneAndPreloadDexCache(ObjPtr<mirror::DexCache> dex_cache, uint32_t stored_index = pair.index; ObjPtr<mirror::String> string = pair.object.Read(); if (string == nullptr || i < stored_index) { - string = class_linker->LookupString(dex_file, string_idx, dex_cache); + string = class_linker->LookupString(string_idx, dex_cache); DCHECK(string == nullptr || dex_cache->GetResolvedString(string_idx) == string); } } diff --git a/dex2oat/linker/index_bss_mapping_encoder.h b/dex2oat/linker/index_bss_mapping_encoder.h index 9bc14329ff..c6326ed1cf 100644 --- a/dex2oat/linker/index_bss_mapping_encoder.h +++ b/dex2oat/linker/index_bss_mapping_encoder.h @@ -17,9 +17,10 @@ #ifndef ART_DEX2OAT_LINKER_INDEX_BSS_MAPPING_ENCODER_H_ #define ART_DEX2OAT_LINKER_INDEX_BSS_MAPPING_ENCODER_H_ +#include <android-base/logging.h> + #include "base/bit_utils.h" #include "base/bit_vector-inl.h" -#include "base/logging.h" #include "index_bss_mapping.h" namespace art { diff --git a/dex2oat/linker/multi_oat_relative_patcher.cc b/dex2oat/linker/multi_oat_relative_patcher.cc index 178a78f0bb..1abaf7dfd1 100644 --- a/dex2oat/linker/multi_oat_relative_patcher.cc +++ b/dex2oat/linker/multi_oat_relative_patcher.cc @@ -16,8 +16,9 @@ #include "multi_oat_relative_patcher.h" +#include <android-base/logging.h> + #include "base/bit_utils.h" -#include "base/logging.h" #include "globals.h" namespace art { diff --git a/dex2oat/linker/oat_writer.cc b/dex2oat/linker/oat_writer.cc index 260888e818..d4fc59c6c2 100644 --- a/dex2oat/linker/oat_writer.cc +++ b/dex2oat/linker/oat_writer.cc @@ -26,6 +26,7 @@ #include "base/bit_vector-inl.h" #include "base/enums.h" #include "base/file_magic.h" +#include "base/logging.h" // For VLOG #include "base/stl_util.h" #include "base/unix_file/fd_file.h" #include "class_linker.h" @@ -1591,11 +1592,10 @@ class OatWriter::InitImageMethodVisitor : public OatDexMethodVisitor { ScopedObjectAccessUnchecked soa(self); StackHandleScope<1> hs(self); method = class_linker_->ResolveMethod<ClassLinker::ResolveMode::kNoChecks>( - *dex_file_, it.GetMemberIndex(), hs.NewHandle(dex_cache), ScopedNullHandle<mirror::ClassLoader>(), - nullptr, + /* referrer */ nullptr, invoke_type); if (method == nullptr) { LOG(FATAL_WITHOUT_ABORT) << "Unexpected failure to resolve a method: " @@ -1951,20 +1951,21 @@ class OatWriter::WriteCodeMethodVisitor : public OrderedMethodVisitor { : class_linker_->FindDexCache(Thread::Current(), *target_dex_file); } - mirror::Class* GetTargetType(const LinkerPatch& patch) REQUIRES_SHARED(Locks::mutator_lock_) { + ObjPtr<mirror::Class> GetTargetType(const LinkerPatch& patch) + REQUIRES_SHARED(Locks::mutator_lock_) { DCHECK(writer_->HasImage()); ObjPtr<mirror::DexCache> dex_cache = GetDexCache(patch.TargetTypeDexFile()); ObjPtr<mirror::Class> type = - ClassLinker::LookupResolvedType(patch.TargetTypeIndex(), dex_cache, class_loader_); + class_linker_->LookupResolvedType(patch.TargetTypeIndex(), dex_cache, class_loader_); CHECK(type != nullptr); - return type.Ptr(); + return type; } - mirror::String* GetTargetString(const LinkerPatch& patch) REQUIRES_SHARED(Locks::mutator_lock_) { + ObjPtr<mirror::String> GetTargetString(const LinkerPatch& patch) + REQUIRES_SHARED(Locks::mutator_lock_) { ClassLinker* linker = Runtime::Current()->GetClassLinker(); - mirror::String* string = linker->LookupString(*patch.TargetStringDexFile(), - patch.TargetStringIndex(), - GetDexCache(patch.TargetStringDexFile())); + ObjPtr<mirror::String> string = + linker->LookupString(patch.TargetStringIndex(), GetDexCache(patch.TargetStringDexFile())); DCHECK(string != nullptr); DCHECK(writer_->HasBootImage() || Runtime::Current()->GetHeap()->ObjectIsInBootImageSpace(string)); @@ -1980,13 +1981,14 @@ class OatWriter::WriteCodeMethodVisitor : public OrderedMethodVisitor { return static_cast<uint32_t>(reinterpret_cast<uintptr_t>(method) - oat_data_begin); } - uint32_t GetTargetObjectOffset(mirror::Object* object) REQUIRES_SHARED(Locks::mutator_lock_) { + uint32_t GetTargetObjectOffset(ObjPtr<mirror::Object> object) + REQUIRES_SHARED(Locks::mutator_lock_) { DCHECK(writer_->HasBootImage()); - object = writer_->image_writer_->GetImageAddress(object); + object = writer_->image_writer_->GetImageAddress(object.Ptr()); size_t oat_index = writer_->image_writer_->GetOatIndexForDexFile(dex_file_); uintptr_t oat_data_begin = writer_->image_writer_->GetOatDataBegin(oat_index); // TODO: Clean up offset types. The target offset must be treated as signed. - return static_cast<uint32_t>(reinterpret_cast<uintptr_t>(object) - oat_data_begin); + return static_cast<uint32_t>(reinterpret_cast<uintptr_t>(object.Ptr()) - oat_data_begin); } void PatchObjectAddress(std::vector<uint8_t>* code, uint32_t offset, mirror::Object* object) diff --git a/dexdump/dexdump_cfg.cc b/dexdump/dexdump_cfg.cc index 62c970de8a..23ecf93447 100644 --- a/dexdump/dexdump_cfg.cc +++ b/dexdump/dexdump_cfg.cc @@ -23,6 +23,7 @@ #include <map> #include <ostream> #include <set> +#include <sstream> #include "dex_file-inl.h" #include "dex_instruction-inl.h" diff --git a/dexdump/dexdump_main.cc b/dexdump/dexdump_main.cc index 43c3d12de5..382b551a1a 100644 --- a/dexdump/dexdump_main.cc +++ b/dexdump/dexdump_main.cc @@ -28,7 +28,9 @@ #include <string.h> #include <unistd.h> -#include "base/logging.h" +#include <android-base/logging.h> + +#include <base/logging.h> // For InitLogging. #include "mem_map.h" #include "runtime.h" diff --git a/dexlayout/dex_ir.cc b/dexlayout/dex_ir.cc index 2af579c73c..90df2d7bb9 100644 --- a/dexlayout/dex_ir.cc +++ b/dexlayout/dex_ir.cc @@ -674,20 +674,20 @@ CodeItem* Collections::CreateCodeItem(const DexFile& dex_file, // Add "fixup" references to types, strings, methods, and fields. // This is temporary, as we will probably want more detailed parsing of the // instructions here. - std::unique_ptr<std::vector<TypeId*>> type_ids(new std::vector<TypeId*>()); - std::unique_ptr<std::vector<StringId*>> string_ids(new std::vector<StringId*>()); - std::unique_ptr<std::vector<MethodId*>> method_ids(new std::vector<MethodId*>()); - std::unique_ptr<std::vector<FieldId*>> field_ids(new std::vector<FieldId*>()); + std::vector<TypeId*> type_ids; + std::vector<StringId*> string_ids; + std::vector<MethodId*> method_ids; + std::vector<FieldId*> field_ids; if (GetIdsFromByteCode(*this, code_item, - type_ids.get(), - string_ids.get(), - method_ids.get(), - field_ids.get())) { - CodeFixups* fixups = new CodeFixups(type_ids.release(), - string_ids.release(), - method_ids.release(), - field_ids.release()); + /*out*/ &type_ids, + /*out*/ &string_ids, + /*out*/ &method_ids, + /*out*/ &field_ids)) { + CodeFixups* fixups = new CodeFixups(std::move(type_ids), + std::move(string_ids), + std::move(method_ids), + std::move(field_ids)); code_item->SetCodeFixups(fixups); } diff --git a/dexlayout/dex_ir.h b/dexlayout/dex_ir.h index 8421774104..b25e1645dd 100644 --- a/dexlayout/dex_ir.h +++ b/dexlayout/dex_ir.h @@ -1013,25 +1013,25 @@ using TryItemVector = std::vector<std::unique_ptr<const TryItem>>; class CodeFixups { public: - CodeFixups(std::vector<TypeId*>* type_ids, - std::vector<StringId*>* string_ids, - std::vector<MethodId*>* method_ids, - std::vector<FieldId*>* field_ids) - : type_ids_(type_ids), - string_ids_(string_ids), - method_ids_(method_ids), - field_ids_(field_ids) { } - - std::vector<TypeId*>* TypeIds() const { return type_ids_.get(); } - std::vector<StringId*>* StringIds() const { return string_ids_.get(); } - std::vector<MethodId*>* MethodIds() const { return method_ids_.get(); } - std::vector<FieldId*>* FieldIds() const { return field_ids_.get(); } + CodeFixups(std::vector<TypeId*> type_ids, + std::vector<StringId*> string_ids, + std::vector<MethodId*> method_ids, + std::vector<FieldId*> field_ids) + : type_ids_(std::move(type_ids)), + string_ids_(std::move(string_ids)), + method_ids_(std::move(method_ids)), + field_ids_(std::move(field_ids)) { } + + const std::vector<TypeId*>& TypeIds() const { return type_ids_; } + const std::vector<StringId*>& StringIds() const { return string_ids_; } + const std::vector<MethodId*>& MethodIds() const { return method_ids_; } + const std::vector<FieldId*>& FieldIds() const { return field_ids_; } private: - std::unique_ptr<std::vector<TypeId*>> type_ids_; - std::unique_ptr<std::vector<StringId*>> string_ids_; - std::unique_ptr<std::vector<MethodId*>> method_ids_; - std::unique_ptr<std::vector<FieldId*>> field_ids_; + std::vector<TypeId*> type_ids_; + std::vector<StringId*> string_ids_; + std::vector<MethodId*> method_ids_; + std::vector<FieldId*> field_ids_; DISALLOW_COPY_AND_ASSIGN(CodeFixups); }; diff --git a/dexlayout/dex_visualize.cc b/dexlayout/dex_visualize.cc index 4b46341ada..e4ed69b8d2 100644 --- a/dexlayout/dex_visualize.cc +++ b/dexlayout/dex_visualize.cc @@ -188,20 +188,16 @@ class Dumper { DumpAddressRange(code_item, class_index); const dex_ir::CodeFixups* fixups = code_item->GetCodeFixups(); if (fixups != nullptr) { - std::vector<dex_ir::TypeId*>* type_ids = fixups->TypeIds(); - for (dex_ir::TypeId* type_id : *type_ids) { + for (dex_ir::TypeId* type_id : fixups->TypeIds()) { DumpTypeId(type_id, class_index); } - std::vector<dex_ir::StringId*>* string_ids = fixups->StringIds(); - for (dex_ir::StringId* string_id : *string_ids) { + for (dex_ir::StringId* string_id : fixups->StringIds()) { DumpStringId(string_id, class_index); } - std::vector<dex_ir::MethodId*>* method_ids = fixups->MethodIds(); - for (dex_ir::MethodId* method_id : *method_ids) { + for (dex_ir::MethodId* method_id : fixups->MethodIds()) { DumpMethodId(method_id, class_index); } - std::vector<dex_ir::FieldId*>* field_ids = fixups->FieldIds(); - for (dex_ir::FieldId* field_id : *field_ids) { + for (dex_ir::FieldId* field_id : fixups->FieldIds()) { DumpFieldId(field_id, class_index); } } diff --git a/dexlayout/dexdiag.cc b/dexlayout/dexdiag.cc index e83f98ee6b..b2507015e9 100644 --- a/dexlayout/dexdiag.cc +++ b/dexlayout/dexdiag.cc @@ -26,6 +26,7 @@ #include "android-base/stringprintf.h" +#include "base/logging.h" // For InitLogging. #include "base/stringpiece.h" #include "dex_file.h" diff --git a/dexlayout/dexlayout.cc b/dexlayout/dexlayout.cc index d904a52f0c..33155b686b 100644 --- a/dexlayout/dexlayout.cc +++ b/dexlayout/dexlayout.cc @@ -33,6 +33,7 @@ #include "android-base/stringprintf.h" +#include "base/logging.h" // For VLOG_IS_ON. #include "dex_file-inl.h" #include "dex_file_layout.h" #include "dex_file_loader.h" @@ -1656,11 +1657,11 @@ void DexLayout::LayoutStringData(const DexFile* dex_file) { continue; } // Add const-strings. - for (dex_ir::StringId* id : *fixups->StringIds()) { + for (dex_ir::StringId* id : fixups->StringIds()) { from_hot_method[id->GetIndex()] = true; } // Add field classes, names, and types. - for (dex_ir::FieldId* id : *fixups->FieldIds()) { + for (dex_ir::FieldId* id : fixups->FieldIds()) { // TODO: Only visit field ids from static getters and setters. from_hot_method[id->Class()->GetStringId()->GetIndex()] = true; from_hot_method[id->Name()->GetIndex()] = true; @@ -1668,7 +1669,7 @@ void DexLayout::LayoutStringData(const DexFile* dex_file) { } // For clinits, add referenced method classes, names, and protos. if (is_clinit) { - for (dex_ir::MethodId* id : *fixups->MethodIds()) { + for (dex_ir::MethodId* id : fixups->MethodIds()) { from_hot_method[id->Class()->GetStringId()->GetIndex()] = true; from_hot_method[id->Name()->GetIndex()] = true; is_shorty[id->Proto()->Shorty()->GetIndex()] = true; diff --git a/dexlayout/dexlayout_main.cc b/dexlayout/dexlayout_main.cc index 17097f1728..5bb7196531 100644 --- a/dexlayout/dexlayout_main.cc +++ b/dexlayout/dexlayout_main.cc @@ -29,7 +29,9 @@ #include <sys/types.h> #include <unistd.h> -#include "base/logging.h" +#include <android-base/logging.h> + +#include "base/logging.h" // For InitLogging. #include "jit/profile_compilation_info.h" #include "mem_map.h" #include "runtime.h" diff --git a/dexlist/dexlist.cc b/dexlist/dexlist.cc index 4bf0475494..4c13ed6410 100644 --- a/dexlist/dexlist.cc +++ b/dexlist/dexlist.cc @@ -26,6 +26,7 @@ #include <stdio.h> #include <stdlib.h> +#include "base/logging.h" // For InitLogging. #include "dex_file-inl.h" #include "dex_file_loader.h" #include "mem_map.h" diff --git a/dexoptanalyzer/dexoptanalyzer.cc b/dexoptanalyzer/dexoptanalyzer.cc index 39c9b9993b..eead2dcf83 100644 --- a/dexoptanalyzer/dexoptanalyzer.cc +++ b/dexoptanalyzer/dexoptanalyzer.cc @@ -16,9 +16,11 @@ #include <string> +#include "base/logging.h" // For InitLogging. #include "android-base/stringprintf.h" #include "android-base/strings.h" #include "base/file_utils.h" +#include "base/logging.h" // For InitLogging. #include "compiler_filter.h" #include "class_loader_context.h" #include "dex_file.h" diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc index 2c15087612..1b4485b233 100644 --- a/oatdump/oatdump.cc +++ b/oatdump/oatdump.cc @@ -2269,7 +2269,7 @@ class ImageDumper { os << StringPrintf("null %s\n", PrettyDescriptor(field->GetTypeDescriptor()).c_str()); } else { // Grab the field type without causing resolution. - ObjPtr<mirror::Class> field_type = field->LookupType(); + ObjPtr<mirror::Class> field_type = field->LookupResolvedType(); if (field_type != nullptr) { PrettyObjectValue(os, field_type, value); } else { diff --git a/openjdkjvm/OpenjdkJvm.cc b/openjdkjvm/OpenjdkJvm.cc index 29ebefddea..1b8233aae8 100644 --- a/openjdkjvm/OpenjdkJvm.cc +++ b/openjdkjvm/OpenjdkJvm.cc @@ -40,9 +40,10 @@ #include <sys/time.h> #include <unistd.h> +#include <android-base/logging.h> + #include "../../libcore/ojluni/src/main/native/jvm.h" // TODO(narayan): fix it -#include "base/logging.h" #include "base/macros.h" #include "common_throws.h" #include "gc/heap.h" diff --git a/openjdkjvmti/OpenjdkJvmTi.cc b/openjdkjvmti/OpenjdkJvmTi.cc index 6b2d5d6a5c..aae805569f 100644 --- a/openjdkjvmti/OpenjdkJvmTi.cc +++ b/openjdkjvmti/OpenjdkJvmTi.cc @@ -33,12 +33,14 @@ #include <type_traits> #include <vector> +#include <android-base/logging.h> + #include <jni.h> #include "jvmti.h" #include "art_jvmti.h" -#include "base/logging.h" +#include "base/logging.h" // For gLogVerbosity. #include "base/mutex.h" #include "events-inl.h" #include "jni_env_ext-inl.h" diff --git a/openjdkjvmti/art_jvmti.h b/openjdkjvmti/art_jvmti.h index e8e62c2b40..2a8c2e91df 100644 --- a/openjdkjvmti/art_jvmti.h +++ b/openjdkjvmti/art_jvmti.h @@ -39,9 +39,10 @@ #include <jni.h> +#include <android-base/logging.h> + #include "deopt_manager.h" #include "base/casts.h" -#include "base/logging.h" #include "base/macros.h" #include "base/strlcpy.h" #include "base/mutex.h" diff --git a/openjdkjvmti/events.cc b/openjdkjvmti/events.cc index 912e7548db..330a3de99c 100644 --- a/openjdkjvmti/events.cc +++ b/openjdkjvmti/events.cc @@ -36,7 +36,6 @@ #include "art_field-inl.h" #include "art_jvmti.h" #include "art_method-inl.h" -#include "base/logging.h" #include "deopt_manager.h" #include "dex_file_types.h" #include "gc/allocation_listener.h" diff --git a/openjdkjvmti/events.h b/openjdkjvmti/events.h index 7bdd9a58ec..81edb931cd 100644 --- a/openjdkjvmti/events.h +++ b/openjdkjvmti/events.h @@ -20,7 +20,10 @@ #include <bitset> #include <vector> -#include "base/logging.h" +#include <android-base/logging.h> + +#include "base/macros.h" +#include "base/mutex.h" #include "jvmti.h" #include "thread.h" diff --git a/openjdkjvmti/jvmti_allocator.h b/openjdkjvmti/jvmti_allocator.h index 11af7b67e7..bd4c85bd7c 100644 --- a/openjdkjvmti/jvmti_allocator.h +++ b/openjdkjvmti/jvmti_allocator.h @@ -32,8 +32,9 @@ #ifndef ART_OPENJDKJVMTI_JVMTI_ALLOCATOR_H_ #define ART_OPENJDKJVMTI_JVMTI_ALLOCATOR_H_ -#include "base/logging.h" -#include "base/macros.h" +#include <android-base/logging.h> +#include <android-base/macros.h> + #include "jvmti.h" #include "ti_allocator.h" diff --git a/openjdkjvmti/jvmti_weak_table-inl.h b/openjdkjvmti/jvmti_weak_table-inl.h index 5d20946070..699004298e 100644 --- a/openjdkjvmti/jvmti_weak_table-inl.h +++ b/openjdkjvmti/jvmti_weak_table-inl.h @@ -36,8 +36,9 @@ #include <limits> +#include <android-base/logging.h> + #include "art_jvmti.h" -#include "base/logging.h" #include "gc/allocation_listener.h" #include "instrumentation.h" #include "jni_env_ext-inl.h" diff --git a/openjdkjvmti/ti_class_loader.cc b/openjdkjvmti/ti_class_loader.cc index b551b55e18..701ba80fd5 100644 --- a/openjdkjvmti/ti_class_loader.cc +++ b/openjdkjvmti/ti_class_loader.cc @@ -33,11 +33,11 @@ #include <limits> -#include "android-base/stringprintf.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> #include "art_field-inl.h" #include "art_jvmti.h" -#include "base/logging.h" #include "dex_file.h" #include "dex_file_types.h" #include "events-inl.h" diff --git a/openjdkjvmti/ti_redefine.cc b/openjdkjvmti/ti_redefine.cc index 5b125f6990..c18b354675 100644 --- a/openjdkjvmti/ti_redefine.cc +++ b/openjdkjvmti/ti_redefine.cc @@ -33,13 +33,13 @@ #include <limits> -#include "android-base/stringprintf.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> #include "art_field-inl.h" #include "art_jvmti.h" #include "art_method-inl.h" #include "base/array_ref.h" -#include "base/logging.h" #include "base/stringpiece.h" #include "class_linker-inl.h" #include "debugger.h" diff --git a/openjdkjvmti/ti_thread.cc b/openjdkjvmti/ti_thread.cc index b7b81ce358..555c5a725b 100644 --- a/openjdkjvmti/ti_thread.cc +++ b/openjdkjvmti/ti_thread.cc @@ -31,10 +31,11 @@ #include "ti_thread.h" -#include "android-base/strings.h" +#include <android-base/logging.h> +#include <android-base/strings.h> + #include "art_field-inl.h" #include "art_jvmti.h" -#include "base/logging.h" #include "base/mutex.h" #include "events-inl.h" #include "gc/system_weak.h" diff --git a/patchoat/patchoat.cc b/patchoat/patchoat.cc index ae82d72c0f..eb648cba18 100644 --- a/patchoat/patchoat.cc +++ b/patchoat/patchoat.cc @@ -30,6 +30,7 @@ #include "art_field-inl.h" #include "art_method-inl.h" #include "base/dumpable.h" +#include "base/logging.h" // For InitLogging. #include "base/memory_tool.h" #include "base/scoped_flock.h" #include "base/stringpiece.h" diff --git a/profman/profman.cc b/profman/profman.cc index a5a5546323..0bef205de6 100644 --- a/profman/profman.cc +++ b/profman/profman.cc @@ -32,6 +32,7 @@ #include "android-base/strings.h" #include "base/dumpable.h" +#include "base/logging.h" // For InitLogging. #include "base/scoped_flock.h" #include "base/stringpiece.h" #include "base/time_utils.h" diff --git a/runtime/Android.bp b/runtime/Android.bp index a136ccb9d0..6477347a6e 100644 --- a/runtime/Android.bp +++ b/runtime/Android.bp @@ -39,6 +39,7 @@ cc_defaults { "base/hex_dump.cc", "base/logging.cc", "base/mutex.cc", + "base/runtime_debug.cc", "base/safe_copy.cc", "base/scoped_arena_allocator.cc", "base/scoped_flock.cc", diff --git a/runtime/arch/arm/context_arm.h b/runtime/arch/arm/context_arm.h index fa9aa46d4d..b9802967fe 100644 --- a/runtime/arch/arm/context_arm.h +++ b/runtime/arch/arm/context_arm.h @@ -17,8 +17,9 @@ #ifndef ART_RUNTIME_ARCH_ARM_CONTEXT_ARM_H_ #define ART_RUNTIME_ARCH_ARM_CONTEXT_ARM_H_ +#include <android-base/logging.h> + #include "arch/context.h" -#include "base/logging.h" #include "base/macros.h" #include "registers_arm.h" diff --git a/runtime/arch/arm/fault_handler_arm.cc b/runtime/arch/arm/fault_handler_arm.cc index ef2b34236f..315bf957cc 100644 --- a/runtime/arch/arm/fault_handler_arm.cc +++ b/runtime/arch/arm/fault_handler_arm.cc @@ -21,7 +21,7 @@ #include "art_method.h" #include "base/enums.h" #include "base/hex_dump.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "base/macros.h" #include "globals.h" #include "thread-current-inl.h" diff --git a/runtime/arch/arm/instruction_set_features_arm.cc b/runtime/arch/arm/instruction_set_features_arm.cc index b789fc7481..801254fd30 100644 --- a/runtime/arch/arm/instruction_set_features_arm.cc +++ b/runtime/arch/arm/instruction_set_features_arm.cc @@ -25,10 +25,9 @@ #include <fstream> -#include "android-base/stringprintf.h" -#include "android-base/strings.h" - -#include "base/logging.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> +#include <android-base/strings.h> #if defined(__arm__) extern "C" bool artCheckForArmSdivInstruction(); diff --git a/runtime/arch/arm/thread_arm.cc b/runtime/arch/arm/thread_arm.cc index ff4f81be0f..18585c7973 100644 --- a/runtime/arch/arm/thread_arm.cc +++ b/runtime/arch/arm/thread_arm.cc @@ -16,9 +16,10 @@ #include "thread.h" +#include <android-base/logging.h> + #include "asm_support_arm.h" #include "base/enums.h" -#include "base/logging.h" namespace art { diff --git a/runtime/arch/arm64/context_arm64.h b/runtime/arch/arm64/context_arm64.h index 36aded07c4..e64cfb86ea 100644 --- a/runtime/arch/arm64/context_arm64.h +++ b/runtime/arch/arm64/context_arm64.h @@ -17,8 +17,9 @@ #ifndef ART_RUNTIME_ARCH_ARM64_CONTEXT_ARM64_H_ #define ART_RUNTIME_ARCH_ARM64_CONTEXT_ARM64_H_ +#include <android-base/logging.h> + #include "arch/context.h" -#include "base/logging.h" #include "base/macros.h" #include "registers_arm64.h" diff --git a/runtime/arch/arm64/fault_handler_arm64.cc b/runtime/arch/arm64/fault_handler_arm64.cc index d535c7e3c6..d282c8cfc0 100644 --- a/runtime/arch/arm64/fault_handler_arm64.cc +++ b/runtime/arch/arm64/fault_handler_arm64.cc @@ -21,7 +21,7 @@ #include "art_method.h" #include "base/enums.h" #include "base/hex_dump.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "base/macros.h" #include "globals.h" #include "registers_arm64.h" diff --git a/runtime/arch/arm64/instruction_set_features_arm64.cc b/runtime/arch/arm64/instruction_set_features_arm64.cc index d830ccffbb..9e9cb16008 100644 --- a/runtime/arch/arm64/instruction_set_features_arm64.cc +++ b/runtime/arch/arm64/instruction_set_features_arm64.cc @@ -19,10 +19,10 @@ #include <fstream> #include <sstream> -#include "android-base/stringprintf.h" -#include "android-base/strings.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> +#include <android-base/strings.h> -#include "base/logging.h" #include "base/stl_util.h" namespace art { diff --git a/runtime/arch/arm64/thread_arm64.cc b/runtime/arch/arm64/thread_arm64.cc index 3483b704ea..19c4a6ac85 100644 --- a/runtime/arch/arm64/thread_arm64.cc +++ b/runtime/arch/arm64/thread_arm64.cc @@ -16,9 +16,10 @@ #include "thread.h" +#include <android-base/logging.h> + #include "asm_support_arm64.h" #include "base/enums.h" -#include "base/logging.h" namespace art { diff --git a/runtime/arch/code_offset.h b/runtime/arch/code_offset.h index ab04b1eaa7..8e8dde4c4c 100644 --- a/runtime/arch/code_offset.h +++ b/runtime/arch/code_offset.h @@ -19,8 +19,10 @@ #include <iosfwd> +#include <android-base/logging.h> + #include "base/bit_utils.h" -#include "base/logging.h" +#include "base/macros.h" #include "instruction_set.h" namespace art { diff --git a/runtime/arch/instruction_set_features_test.cc b/runtime/arch/instruction_set_features_test.cc index 67e2f358c8..1e3275cc00 100644 --- a/runtime/arch/instruction_set_features_test.cc +++ b/runtime/arch/instruction_set_features_test.cc @@ -19,12 +19,11 @@ #include <gtest/gtest.h> #ifdef ART_TARGET_ANDROID -#include "android-base/properties.h" +#include <android-base/properties.h> #endif -#include "android-base/stringprintf.h" - -#include "base/logging.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> namespace art { diff --git a/runtime/arch/mips/context_mips.h b/runtime/arch/mips/context_mips.h index 7dcff630d1..7e073b288a 100644 --- a/runtime/arch/mips/context_mips.h +++ b/runtime/arch/mips/context_mips.h @@ -17,8 +17,9 @@ #ifndef ART_RUNTIME_ARCH_MIPS_CONTEXT_MIPS_H_ #define ART_RUNTIME_ARCH_MIPS_CONTEXT_MIPS_H_ +#include <android-base/logging.h> + #include "arch/context.h" -#include "base/logging.h" #include "base/macros.h" #include "registers_mips.h" diff --git a/runtime/arch/mips/entrypoints_init_mips.cc b/runtime/arch/mips/entrypoints_init_mips.cc index dca3382664..209f36705a 100644 --- a/runtime/arch/mips/entrypoints_init_mips.cc +++ b/runtime/arch/mips/entrypoints_init_mips.cc @@ -18,6 +18,7 @@ #include "arch/mips/asm_support_mips.h" #include "atomic.h" +#include "base/logging.h" #include "entrypoints/entrypoint_utils.h" #include "entrypoints/jni/jni_entrypoints.h" #include "entrypoints/math_entrypoints.h" diff --git a/runtime/arch/mips/fault_handler_mips.cc b/runtime/arch/mips/fault_handler_mips.cc index 6dce54e5c5..f82dc08cb2 100644 --- a/runtime/arch/mips/fault_handler_mips.cc +++ b/runtime/arch/mips/fault_handler_mips.cc @@ -20,7 +20,7 @@ #include "art_method.h" #include "base/callee_save_type.h" #include "base/hex_dump.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "base/macros.h" #include "globals.h" #include "quick_method_frame_info_mips.h" diff --git a/runtime/arch/mips/instruction_set_features_mips.cc b/runtime/arch/mips/instruction_set_features_mips.cc index 6d4145bc98..952ed250d2 100644 --- a/runtime/arch/mips/instruction_set_features_mips.cc +++ b/runtime/arch/mips/instruction_set_features_mips.cc @@ -19,10 +19,9 @@ #include <fstream> #include <sstream> -#include "android-base/stringprintf.h" -#include "android-base/strings.h" +#include <android-base/stringprintf.h> +#include <android-base/strings.h> -#include "base/logging.h" #include "base/stl_util.h" namespace art { diff --git a/runtime/arch/mips/instruction_set_features_mips.h b/runtime/arch/mips/instruction_set_features_mips.h index ee539edf3a..76bc639277 100644 --- a/runtime/arch/mips/instruction_set_features_mips.h +++ b/runtime/arch/mips/instruction_set_features_mips.h @@ -17,8 +17,9 @@ #ifndef ART_RUNTIME_ARCH_MIPS_INSTRUCTION_SET_FEATURES_MIPS_H_ #define ART_RUNTIME_ARCH_MIPS_INSTRUCTION_SET_FEATURES_MIPS_H_ +#include <android-base/logging.h> + #include "arch/instruction_set_features.h" -#include "base/logging.h" #include "base/macros.h" namespace art { diff --git a/runtime/arch/mips/registers_mips.h b/runtime/arch/mips/registers_mips.h index 57af150b33..f500b5881a 100644 --- a/runtime/arch/mips/registers_mips.h +++ b/runtime/arch/mips/registers_mips.h @@ -19,7 +19,8 @@ #include <iosfwd> -#include "base/logging.h" +#include <android-base/logging.h> + #include "base/macros.h" #include "globals.h" diff --git a/runtime/arch/mips/thread_mips.cc b/runtime/arch/mips/thread_mips.cc index 0a9ab7aacd..0be7a7f4cb 100644 --- a/runtime/arch/mips/thread_mips.cc +++ b/runtime/arch/mips/thread_mips.cc @@ -16,9 +16,10 @@ #include "thread.h" +#include <android-base/logging.h> + #include "asm_support_mips.h" #include "base/enums.h" -#include "base/logging.h" namespace art { diff --git a/runtime/arch/mips64/context_mips64.h b/runtime/arch/mips64/context_mips64.h index 89fbf8ffc3..b2a6138471 100644 --- a/runtime/arch/mips64/context_mips64.h +++ b/runtime/arch/mips64/context_mips64.h @@ -17,8 +17,9 @@ #ifndef ART_RUNTIME_ARCH_MIPS64_CONTEXT_MIPS64_H_ #define ART_RUNTIME_ARCH_MIPS64_CONTEXT_MIPS64_H_ +#include <android-base/logging.h> + #include "arch/context.h" -#include "base/logging.h" #include "base/macros.h" #include "registers_mips64.h" diff --git a/runtime/arch/mips64/fault_handler_mips64.cc b/runtime/arch/mips64/fault_handler_mips64.cc index bdce520937..ba6fff05ad 100644 --- a/runtime/arch/mips64/fault_handler_mips64.cc +++ b/runtime/arch/mips64/fault_handler_mips64.cc @@ -21,7 +21,7 @@ #include "art_method.h" #include "base/callee_save_type.h" #include "base/hex_dump.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "base/macros.h" #include "globals.h" #include "quick_method_frame_info_mips64.h" diff --git a/runtime/arch/mips64/registers_mips64.h b/runtime/arch/mips64/registers_mips64.h index 30de2cc009..bca260a6a4 100644 --- a/runtime/arch/mips64/registers_mips64.h +++ b/runtime/arch/mips64/registers_mips64.h @@ -19,7 +19,8 @@ #include <iosfwd> -#include "base/logging.h" +#include <android-base/logging.h> + #include "base/macros.h" #include "globals.h" diff --git a/runtime/arch/mips64/thread_mips64.cc b/runtime/arch/mips64/thread_mips64.cc index 3ce5e50d57..c1c390beeb 100644 --- a/runtime/arch/mips64/thread_mips64.cc +++ b/runtime/arch/mips64/thread_mips64.cc @@ -16,9 +16,10 @@ #include "thread.h" +#include <android-base/logging.h> + #include "asm_support_mips64.h" #include "base/enums.h" -#include "base/logging.h" namespace art { diff --git a/runtime/arch/x86/context_x86.h b/runtime/arch/x86/context_x86.h index 303dfe361c..0ebb22bd6d 100644 --- a/runtime/arch/x86/context_x86.h +++ b/runtime/arch/x86/context_x86.h @@ -17,8 +17,9 @@ #ifndef ART_RUNTIME_ARCH_X86_CONTEXT_X86_H_ #define ART_RUNTIME_ARCH_X86_CONTEXT_X86_H_ +#include <android-base/logging.h> + #include "arch/context.h" -#include "base/logging.h" #include "base/macros.h" #include "registers_x86.h" diff --git a/runtime/arch/x86/fault_handler_x86.cc b/runtime/arch/x86/fault_handler_x86.cc index 527332fe9a..e6a91247cb 100644 --- a/runtime/arch/x86/fault_handler_x86.cc +++ b/runtime/arch/x86/fault_handler_x86.cc @@ -21,7 +21,7 @@ #include "art_method.h" #include "base/enums.h" #include "base/hex_dump.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "base/macros.h" #include "base/safe_copy.h" #include "globals.h" diff --git a/runtime/arch/x86/instruction_set_features_x86.cc b/runtime/arch/x86/instruction_set_features_x86.cc index ea5a90d8ee..98462512da 100644 --- a/runtime/arch/x86/instruction_set_features_x86.cc +++ b/runtime/arch/x86/instruction_set_features_x86.cc @@ -19,11 +19,11 @@ #include <fstream> #include <sstream> -#include "android-base/stringprintf.h" -#include "android-base/strings.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> +#include <android-base/strings.h> #include "arch/x86_64/instruction_set_features_x86_64.h" -#include "base/logging.h" namespace art { diff --git a/runtime/arch/x86/registers_x86.h b/runtime/arch/x86/registers_x86.h index 23027ed7d7..ded3520c76 100644 --- a/runtime/arch/x86/registers_x86.h +++ b/runtime/arch/x86/registers_x86.h @@ -19,7 +19,8 @@ #include <iosfwd> -#include "base/logging.h" +#include <android-base/logging.h> + #include "base/macros.h" #include "globals.h" diff --git a/runtime/arch/x86_64/context_x86_64.h b/runtime/arch/x86_64/context_x86_64.h index f8e2845983..d242693f81 100644 --- a/runtime/arch/x86_64/context_x86_64.h +++ b/runtime/arch/x86_64/context_x86_64.h @@ -17,8 +17,9 @@ #ifndef ART_RUNTIME_ARCH_X86_64_CONTEXT_X86_64_H_ #define ART_RUNTIME_ARCH_X86_64_CONTEXT_X86_64_H_ +#include <android-base/logging.h> + #include "arch/context.h" -#include "base/logging.h" #include "base/macros.h" #include "registers_x86_64.h" diff --git a/runtime/arch/x86_64/registers_x86_64.h b/runtime/arch/x86_64/registers_x86_64.h index dda1d5f569..4f2243170e 100644 --- a/runtime/arch/x86_64/registers_x86_64.h +++ b/runtime/arch/x86_64/registers_x86_64.h @@ -19,7 +19,8 @@ #include <iosfwd> -#include "base/logging.h" +#include <android-base/logging.h> + #include "base/macros.h" #include "globals.h" diff --git a/runtime/art_field-inl.h b/runtime/art_field-inl.h index 4a328e8d60..2b18577ed0 100644 --- a/runtime/art_field-inl.h +++ b/runtime/art_field-inl.h @@ -19,7 +19,8 @@ #include "art_field.h" -#include "base/logging.h" +#include <android-base/logging.h> + #include "class_linker.h" #include "dex_file-inl.h" #include "gc/accounting/card_table-inl.h" @@ -299,23 +300,17 @@ inline bool ArtField::IsPrimitiveType() REQUIRES_SHARED(Locks::mutator_lock_) { return GetTypeAsPrimitiveType() != Primitive::kPrimNot; } -inline ObjPtr<mirror::Class> ArtField::LookupType() { +inline ObjPtr<mirror::Class> ArtField::LookupResolvedType() { ScopedAssertNoThreadSuspension ants(__FUNCTION__); const uint32_t field_index = GetDexFieldIndex(); ObjPtr<mirror::Class> declaring_class = GetDeclaringClass(); if (UNLIKELY(declaring_class->IsProxyClass())) { return ProxyFindSystemClass(GetTypeDescriptor()); } - ObjPtr<mirror::DexCache> dex_cache = declaring_class->GetDexCache(); - const DexFile* const dex_file = dex_cache->GetDexFile(); - dex::TypeIndex type_idx = dex_file->GetFieldId(field_index).type_idx_; - ObjPtr<mirror::Class> type = dex_cache->GetResolvedType(type_idx); - if (UNLIKELY(type == nullptr)) { - type = Runtime::Current()->GetClassLinker()->LookupResolvedType( - *dex_file, type_idx, dex_cache, declaring_class->GetClassLoader()); - DCHECK(!Thread::Current()->IsExceptionPending()); - } - return type.Ptr(); + ObjPtr<mirror::Class> type = Runtime::Current()->GetClassLinker()->LookupResolvedType( + declaring_class->GetDexFile().GetFieldId(field_index).type_idx_, declaring_class); + DCHECK(!Thread::Current()->IsExceptionPending()); + return type; } inline ObjPtr<mirror::Class> ArtField::ResolveType() { @@ -324,15 +319,9 @@ inline ObjPtr<mirror::Class> ArtField::ResolveType() { if (UNLIKELY(declaring_class->IsProxyClass())) { return ProxyFindSystemClass(GetTypeDescriptor()); } - auto* dex_cache = declaring_class->GetDexCache(); - const DexFile* const dex_file = dex_cache->GetDexFile(); - dex::TypeIndex type_idx = dex_file->GetFieldId(field_index).type_idx_; - ObjPtr<mirror::Class> type = dex_cache->GetResolvedType(type_idx); - if (UNLIKELY(type == nullptr)) { - ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); - type = class_linker->ResolveType(*dex_file, type_idx, declaring_class); - DCHECK_EQ(type == nullptr, Thread::Current()->IsExceptionPending()); - } + ObjPtr<mirror::Class> type = Runtime::Current()->GetClassLinker()->ResolveType( + declaring_class->GetDexFile().GetFieldId(field_index).type_idx_, declaring_class); + DCHECK_EQ(type == nullptr, Thread::Current()->IsExceptionPending()); return type; } @@ -352,11 +341,10 @@ inline ObjPtr<mirror::String> ArtField::GetStringName(Thread* self, bool resolve auto dex_field_index = GetDexFieldIndex(); CHECK_NE(dex_field_index, dex::kDexNoIndex); ObjPtr<mirror::DexCache> dex_cache = GetDexCache(); - const auto* dex_file = dex_cache->GetDexFile(); - const auto& field_id = dex_file->GetFieldId(dex_field_index); + const DexFile::FieldId& field_id = dex_cache->GetDexFile()->GetFieldId(dex_field_index); ObjPtr<mirror::String> name = dex_cache->GetResolvedString(field_id.name_idx_); if (resolve && name == nullptr) { - name = ResolveGetStringName(self, *dex_file, field_id.name_idx_, dex_cache); + name = ResolveGetStringName(self, field_id.name_idx_, dex_cache); } return name; } diff --git a/runtime/art_field.cc b/runtime/art_field.cc index bc728f4476..dbba2b0918 100644 --- a/runtime/art_field.cc +++ b/runtime/art_field.cc @@ -45,17 +45,17 @@ void ArtField::SetOffset(MemberOffset num_bytes) { ObjPtr<mirror::Class> ArtField::ProxyFindSystemClass(const char* descriptor) { DCHECK(GetDeclaringClass()->IsProxyClass()); - return Runtime::Current()->GetClassLinker()->FindSystemClass(Thread::Current(), descriptor); + ObjPtr<mirror::Class> klass = Runtime::Current()->GetClassLinker()->LookupClass( + Thread::Current(), descriptor, /* class_loader */ nullptr); + DCHECK(klass != nullptr); + return klass; } ObjPtr<mirror::String> ArtField::ResolveGetStringName(Thread* self, - const DexFile& dex_file, dex::StringIndex string_idx, ObjPtr<mirror::DexCache> dex_cache) { StackHandleScope<1> hs(self); - return Runtime::Current()->GetClassLinker()->ResolveString(dex_file, - string_idx, - hs.NewHandle(dex_cache)); + return Runtime::Current()->GetClassLinker()->ResolveString(string_idx, hs.NewHandle(dex_cache)); } std::string ArtField::PrettyField(ArtField* f, bool with_type) { diff --git a/runtime/art_field.h b/runtime/art_field.h index 866bf0bc70..8d2f9ff71b 100644 --- a/runtime/art_field.h +++ b/runtime/art_field.h @@ -205,7 +205,7 @@ class ArtField FINAL { bool IsPrimitiveType() REQUIRES_SHARED(Locks::mutator_lock_); - ObjPtr<mirror::Class> LookupType() REQUIRES_SHARED(Locks::mutator_lock_); + ObjPtr<mirror::Class> LookupResolvedType() REQUIRES_SHARED(Locks::mutator_lock_); ObjPtr<mirror::Class> ResolveType() REQUIRES_SHARED(Locks::mutator_lock_); size_t FieldSize() REQUIRES_SHARED(Locks::mutator_lock_); @@ -234,7 +234,6 @@ class ArtField FINAL { ObjPtr<mirror::Class> ProxyFindSystemClass(const char* descriptor) REQUIRES_SHARED(Locks::mutator_lock_); ObjPtr<mirror::String> ResolveGetStringName(Thread* self, - const DexFile& dex_file, dex::StringIndex string_idx, ObjPtr<mirror::DexCache> dex_cache) REQUIRES_SHARED(Locks::mutator_lock_); diff --git a/runtime/art_method-inl.h b/runtime/art_method-inl.h index 31abf94889..869394c388 100644 --- a/runtime/art_method-inl.h +++ b/runtime/art_method-inl.h @@ -21,7 +21,6 @@ #include "art_field.h" #include "base/callee_save_type.h" -#include "base/logging.h" #include "class_linker-inl.h" #include "code_item_accessors-inl.h" #include "common_throws.h" @@ -107,23 +106,16 @@ inline uint32_t ArtMethod::GetDexMethodIndex() { inline ObjPtr<mirror::Class> ArtMethod::LookupResolvedClassFromTypeIndex(dex::TypeIndex type_idx) { ScopedAssertNoThreadSuspension ants(__FUNCTION__); - ObjPtr<mirror::DexCache> dex_cache = GetDexCache(); - ObjPtr<mirror::Class> type = dex_cache->GetResolvedType(type_idx); - if (UNLIKELY(type == nullptr)) { - type = Runtime::Current()->GetClassLinker()->LookupResolvedType( - *dex_cache->GetDexFile(), type_idx, dex_cache, GetClassLoader()); - } - return type.Ptr(); + ObjPtr<mirror::Class> type = + Runtime::Current()->GetClassLinker()->LookupResolvedType(type_idx, this); + DCHECK(!Thread::Current()->IsExceptionPending()); + return type; } inline ObjPtr<mirror::Class> ArtMethod::ResolveClassFromTypeIndex(dex::TypeIndex type_idx) { - ObjPtr<mirror::DexCache> dex_cache = GetDexCache(); - ObjPtr<mirror::Class> type = dex_cache->GetResolvedType(type_idx); - if (UNLIKELY(type == nullptr)) { - type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, this); - CHECK(type != nullptr || Thread::Current()->IsExceptionPending()); - } - return type.Ptr(); + ObjPtr<mirror::Class> type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, this); + DCHECK_EQ(type == nullptr, Thread::Current()->IsExceptionPending()); + return type; } inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) { @@ -306,9 +298,7 @@ inline const DexFile::ClassDef& ArtMethod::GetClassDef() { inline const char* ArtMethod::GetReturnTypeDescriptor() { DCHECK(!IsProxyMethod()); const DexFile* dex_file = GetDexFile(); - const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex()); - const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id); - return dex_file->GetTypeDescriptor(dex_file->GetTypeId(proto_id.return_type_idx_)); + return dex_file->GetTypeDescriptor(dex_file->GetTypeId(GetReturnTypeIndex())); } inline Primitive::Type ArtMethod::GetReturnTypePrimitive() { diff --git a/runtime/art_method.cc b/runtime/art_method.cc index 43a51391b9..9005120eb0 100644 --- a/runtime/art_method.cc +++ b/runtime/art_method.cc @@ -134,15 +134,14 @@ uint16_t ArtMethod::FindObsoleteDexClassDefIndex() { return dex_file->GetIndexForClassDef(*class_def); } -mirror::String* ArtMethod::GetNameAsString(Thread* self) { +ObjPtr<mirror::String> ArtMethod::GetNameAsString(Thread* self) { CHECK(!IsProxyMethod()); StackHandleScope<1> hs(self); Handle<mirror::DexCache> dex_cache(hs.NewHandle(GetDexCache())); auto* dex_file = dex_cache->GetDexFile(); uint32_t dex_method_idx = GetDexMethodIndex(); const DexFile::MethodId& method_id = dex_file->GetMethodId(dex_method_idx); - return Runtime::Current()->GetClassLinker()->ResolveString(*dex_file, method_id.name_idx_, - dex_cache); + return Runtime::Current()->GetClassLinker()->ResolveString(method_id.name_idx_, dex_cache); } void ArtMethod::ThrowInvocationTimeError() { @@ -550,8 +549,8 @@ bool ArtMethod::EqualParameters(Handle<mirror::ObjectArray<mirror::Class>> param } auto* cl = Runtime::Current()->GetClassLinker(); for (size_t i = 0; i < count; ++i) { - auto type_idx = proto_params->GetTypeItem(i).type_idx_; - auto* type = cl->ResolveType(type_idx, this); + dex::TypeIndex type_idx = proto_params->GetTypeItem(i).type_idx_; + ObjPtr<mirror::Class> type = cl->ResolveType(type_idx, this); if (type == nullptr) { Thread::Current()->AssertPendingException(); return false; diff --git a/runtime/art_method.h b/runtime/art_method.h index 0a592e0528..f433223ebf 100644 --- a/runtime/art_method.h +++ b/runtime/art_method.h @@ -19,11 +19,14 @@ #include <cstddef> +#include <android-base/logging.h> + #include "base/bit_utils.h" #include "base/casts.h" #include "base/enums.h" #include "base/iteration_range.h" -#include "base/logging.h" +#include "base/macros.h" +#include "base/runtime_debug.h" #include "dex_file.h" #include "dex_instruction_iterator.h" #include "gc_root.h" @@ -575,7 +578,7 @@ class ArtMethod FINAL { ALWAYS_INLINE const char* GetName() REQUIRES_SHARED(Locks::mutator_lock_); - mirror::String* GetNameAsString(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_); + ObjPtr<mirror::String> GetNameAsString(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_); const DexFile::CodeItem* GetCodeItem() REQUIRES_SHARED(Locks::mutator_lock_); diff --git a/runtime/atomic.h b/runtime/atomic.h index d8621cc2e6..ec3eb6d609 100644 --- a/runtime/atomic.h +++ b/runtime/atomic.h @@ -22,8 +22,9 @@ #include <limits> #include <vector> +#include <android-base/logging.h> + #include "arch/instruction_set.h" -#include "base/logging.h" #include "base/macros.h" namespace art { diff --git a/runtime/barrier.cc b/runtime/barrier.cc index 9bcda35a9d..4329a5a245 100644 --- a/runtime/barrier.cc +++ b/runtime/barrier.cc @@ -16,7 +16,9 @@ #include "barrier.h" -#include "base/logging.h" +#include <android-base/logging.h> + +#include "base/aborting.h" #include "base/mutex.h" #include "base/time_utils.h" #include "thread.h" diff --git a/runtime/base/aborting.h b/runtime/base/aborting.h new file mode 100644 index 0000000000..8906c96ea7 --- /dev/null +++ b/runtime/base/aborting.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ART_RUNTIME_BASE_ABORTING_H_ +#define ART_RUNTIME_BASE_ABORTING_H_ + +#include <atomic> + +namespace art { + +// 0 if not abort, non-zero if an abort is in progress. Used on fatal exit to prevents recursive +// aborts. Global declaration allows us to disable some error checking to ensure fatal shutdown +// makes forward progress. +extern std::atomic<unsigned int> gAborting; + +} // namespace art + +#endif // ART_RUNTIME_BASE_ABORTING_H_ diff --git a/runtime/base/allocator.cc b/runtime/base/allocator.cc index bb006389fa..2da88c3830 100644 --- a/runtime/base/allocator.cc +++ b/runtime/base/allocator.cc @@ -19,8 +19,9 @@ #include <inttypes.h> #include <stdlib.h> +#include <android-base/logging.h> + #include "atomic.h" -#include "base/logging.h" namespace art { diff --git a/runtime/base/arena_allocator.cc b/runtime/base/arena_allocator.cc index 2e35f8ac4f..cc413c5ab9 100644 --- a/runtime/base/arena_allocator.cc +++ b/runtime/base/arena_allocator.cc @@ -23,7 +23,8 @@ #include <iomanip> #include <numeric> -#include "logging.h" +#include <android-base/logging.h> + #include "mem_map.h" #include "mutex.h" #include "systrace.h" diff --git a/runtime/base/arena_allocator.h b/runtime/base/arena_allocator.h index a327cb0a8b..9e03658aef 100644 --- a/runtime/base/arena_allocator.h +++ b/runtime/base/arena_allocator.h @@ -20,11 +20,11 @@ #include <stddef.h> #include <stdint.h> -#include "base/bit_utils.h" -#include "base/dchecked_vector.h" -#include "base/memory_tool.h" +#include "bit_utils.h" +#include "dchecked_vector.h" #include "debug_stack.h" #include "macros.h" +#include "memory_tool.h" #include "mutex.h" namespace art { diff --git a/runtime/base/arena_object.h b/runtime/base/arena_object.h index ed00babd62..06884c23d4 100644 --- a/runtime/base/arena_object.h +++ b/runtime/base/arena_object.h @@ -17,8 +17,10 @@ #ifndef ART_RUNTIME_BASE_ARENA_OBJECT_H_ #define ART_RUNTIME_BASE_ARENA_OBJECT_H_ -#include "base/arena_allocator.h" -#include "base/logging.h" +#include <android-base/logging.h> + +#include "arena_allocator.h" +#include "macros.h" #include "scoped_arena_allocator.h" namespace art { diff --git a/runtime/base/array_ref.h b/runtime/base/array_ref.h index 630a036f3d..ef86512cf7 100644 --- a/runtime/base/array_ref.h +++ b/runtime/base/array_ref.h @@ -20,7 +20,7 @@ #include <type_traits> #include <vector> -#include "base/logging.h" +#include <android-base/logging.h> namespace art { diff --git a/runtime/base/bit_field.h b/runtime/base/bit_field.h index a80ca28d2e..86007d6a35 100644 --- a/runtime/base/bit_field.h +++ b/runtime/base/bit_field.h @@ -17,8 +17,9 @@ #ifndef ART_RUNTIME_BASE_BIT_FIELD_H_ #define ART_RUNTIME_BASE_BIT_FIELD_H_ +#include <android-base/logging.h> + #include "globals.h" -#include "logging.h" namespace art { diff --git a/runtime/base/bit_utils.h b/runtime/base/bit_utils.h index 5d836545e9..34cddbff6a 100644 --- a/runtime/base/bit_utils.h +++ b/runtime/base/bit_utils.h @@ -20,7 +20,8 @@ #include <limits> #include <type_traits> -#include "base/logging.h" +#include <android-base/logging.h> + #include "base/stl_util_identity.h" namespace art { diff --git a/runtime/base/bit_utils_iterator.h b/runtime/base/bit_utils_iterator.h index 8514de6b75..2d3d0508cc 100644 --- a/runtime/base/bit_utils_iterator.h +++ b/runtime/base/bit_utils_iterator.h @@ -21,9 +21,10 @@ #include <limits> #include <type_traits> +#include <android-base/logging.h> + #include "base/bit_utils.h" #include "base/iteration_range.h" -#include "base/logging.h" #include "base/stl_util.h" namespace art { diff --git a/runtime/base/bit_vector-inl.h b/runtime/base/bit_vector-inl.h index 0e67f77e19..e67d4e25eb 100644 --- a/runtime/base/bit_vector-inl.h +++ b/runtime/base/bit_vector-inl.h @@ -17,9 +17,11 @@ #ifndef ART_RUNTIME_BASE_BIT_VECTOR_INL_H_ #define ART_RUNTIME_BASE_BIT_VECTOR_INL_H_ -#include "base/bit_utils.h" #include "bit_vector.h" -#include "logging.h" + +#include <android-base/logging.h> + +#include "base/bit_utils.h" namespace art { diff --git a/runtime/base/bounded_fifo.h b/runtime/base/bounded_fifo.h index 7bcd382022..1520770fe6 100644 --- a/runtime/base/bounded_fifo.h +++ b/runtime/base/bounded_fifo.h @@ -17,8 +17,9 @@ #ifndef ART_RUNTIME_BASE_BOUNDED_FIFO_H_ #define ART_RUNTIME_BASE_BOUNDED_FIFO_H_ +#include <android-base/logging.h> + #include "base/bit_utils.h" -#include "base/logging.h" namespace art { diff --git a/runtime/base/casts.h b/runtime/base/casts.h index 92c493ace7..ac1a10c24f 100644 --- a/runtime/base/casts.h +++ b/runtime/base/casts.h @@ -24,8 +24,7 @@ #include <limits> #include <type_traits> -#include "base/logging.h" -#include "base/macros.h" +#include <android-base/logging.h> namespace art { diff --git a/runtime/base/dchecked_vector.h b/runtime/base/dchecked_vector.h index 77f0ea2b7c..7236ac301a 100644 --- a/runtime/base/dchecked_vector.h +++ b/runtime/base/dchecked_vector.h @@ -21,7 +21,7 @@ #include <type_traits> #include <vector> -#include "base/logging.h" +#include <android-base/logging.h> namespace art { diff --git a/runtime/base/debug_stack.h b/runtime/base/debug_stack.h index 886065db30..1331e10a02 100644 --- a/runtime/base/debug_stack.h +++ b/runtime/base/debug_stack.h @@ -17,8 +17,9 @@ #ifndef ART_RUNTIME_BASE_DEBUG_STACK_H_ #define ART_RUNTIME_BASE_DEBUG_STACK_H_ -#include "base/logging.h" -#include "base/macros.h" +#include <android-base/logging.h> +#include <android-base/macros.h> + #include "globals.h" namespace art { diff --git a/runtime/base/file_magic.cc b/runtime/base/file_magic.cc index dffb9b43a1..ac2e184163 100644 --- a/runtime/base/file_magic.cc +++ b/runtime/base/file_magic.cc @@ -20,9 +20,9 @@ #include <sys/stat.h> #include <sys/types.h> -#include "android-base/stringprintf.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> -#include "base/logging.h" #include "base/unix_file/fd_file.h" #include "dex_file.h" diff --git a/runtime/base/file_utils.cc b/runtime/base/file_utils.cc index 323a06519d..db498600d9 100644 --- a/runtime/base/file_utils.cc +++ b/runtime/base/file_utils.cc @@ -89,7 +89,7 @@ bool ReadFileToString(const std::string& file_name, std::string* result) { } } -bool PrintFileToLog(const std::string& file_name, LogSeverity level) { +bool PrintFileToLog(const std::string& file_name, android::base::LogSeverity level) { File file(file_name, O_RDONLY, false); if (!file.IsOpened()) { return false; diff --git a/runtime/base/file_utils.h b/runtime/base/file_utils.h index 007f3b443d..e4555ad3cb 100644 --- a/runtime/base/file_utils.h +++ b/runtime/base/file_utils.h @@ -21,13 +21,14 @@ #include <string> +#include <android-base/logging.h> + #include "arch/instruction_set.h" -#include "base/logging.h" namespace art { bool ReadFileToString(const std::string& file_name, std::string* result); -bool PrintFileToLog(const std::string& file_name, LogSeverity level); +bool PrintFileToLog(const std::string& file_name, android::base::LogSeverity level); // Find $ANDROID_ROOT, /system, or abort. std::string GetAndroidRoot(); diff --git a/runtime/base/hash_set.h b/runtime/base/hash_set.h index c743342a98..47e6d93346 100644 --- a/runtime/base/hash_set.h +++ b/runtime/base/hash_set.h @@ -25,8 +25,10 @@ #include <type_traits> #include <utility> +#include <android-base/logging.h> + #include "bit_utils.h" -#include "logging.h" +#include "macros.h" namespace art { diff --git a/runtime/base/histogram-inl.h b/runtime/base/histogram-inl.h index be2092040d..3ce0140c84 100644 --- a/runtime/base/histogram-inl.h +++ b/runtime/base/histogram-inl.h @@ -24,6 +24,8 @@ #include "histogram.h" +#include <android-base/logging.h> + #include "base/bit_utils.h" #include "base/time_utils.h" #include "utils.h" diff --git a/runtime/base/histogram.h b/runtime/base/histogram.h index e0c921e408..7544a9c918 100644 --- a/runtime/base/histogram.h +++ b/runtime/base/histogram.h @@ -19,7 +19,7 @@ #include <string> #include <vector> -#include "base/logging.h" +#include <android-base/macros.h> namespace art { diff --git a/runtime/base/logging.cc b/runtime/base/logging.cc index 4776357fdf..90eb74c75c 100644 --- a/runtime/base/logging.cc +++ b/runtime/base/logging.cc @@ -20,7 +20,8 @@ #include <limits> #include <sstream> -#include "base/mutex.h" +#include "aborting.h" +#include "mutex.h" #include "thread-current-inl.h" #include "utils.h" @@ -34,55 +35,6 @@ namespace art { -// We test here that the runtime-debug-checks are actually a no-op constexpr false in release -// builds, as we can't check that in gtests (which are always debug). - -#ifdef NDEBUG -namespace { -DECLARE_RUNTIME_DEBUG_FLAG(kTestForConstexpr); -static_assert(!kTestForConstexpr, "Issue with DECLARE_RUNTIME_DEBUG_FLAG in NDEBUG."); -} -#endif - -// Implementation of runtime debug flags. This should be compile-time optimized away in release -// builds. -namespace { -bool gSlowEnabled = false; // Default for slow flags is "off." - -// Use a function with a static to ensure our vector storage doesn't have initialization order -// issues. -std::vector<bool*>& GetFlagPtrs() { - static std::vector<bool*> g_flag_ptrs; - return g_flag_ptrs; -} - -bool RegisterRuntimeDebugFlagImpl(bool* flag_ptr) { - GetFlagPtrs().push_back(flag_ptr); - return gSlowEnabled; -} - -void SetRuntimeDebugFlagsEnabledImpl(bool enabled) { - gSlowEnabled = enabled; - for (bool* flag_ptr : GetFlagPtrs()) { - *flag_ptr = enabled; - } -} - -} // namespace - -bool RegisterRuntimeDebugFlag(bool* flag_ptr) { - if (kIsDebugBuild) { - return RegisterRuntimeDebugFlagImpl(flag_ptr); - } - return false; -} - -void SetRuntimeDebugFlagsEnabled(bool enabled) { - if (kIsDebugBuild) { - SetRuntimeDebugFlagsEnabledImpl(enabled); - } -} - LogVerbosity gLogVerbosity; std::atomic<unsigned int> gAborting(0); diff --git a/runtime/base/logging.h b/runtime/base/logging.h index 5703b3c746..c562bdf59f 100644 --- a/runtime/base/logging.h +++ b/runtime/base/logging.h @@ -63,48 +63,6 @@ struct LogVerbosity { // Global log verbosity setting, initialized by InitLogging. extern LogVerbosity gLogVerbosity; -// Runtime debug flags are flags that have a runtime component, that is, their value can be changed. -// This is meant to implement fast vs slow debug builds, in that certain debug flags can be turned -// on and off. To that effect, expose two macros to help implement and globally drive these flags: -// -// In the header, declare a (class) flag like this: -// -// class C { -// DECLARE_RUNTIME_DEBUG_FLAG(kFlag); -// }; -// -// This will declare a flag kFlag that is a constexpr false in release builds, and a static field -// in debug builds. Usage is than uniform as C::kFlag. -// -// In the cc file, define the flag like this: -// -// DEFINE_RUNTIME_DEBUG_FLAG(C, kFlag); -// -// This will define the static storage, as necessary, and register the flag with the runtime -// infrastructure to toggle the value. - -#ifdef NDEBUG -#define DECLARE_RUNTIME_DEBUG_FLAG(x) \ - static constexpr bool x = false; -// Note: the static_assert in the following only works for public flags. Fix this when we cross -// the line at some point. -#define DEFINE_RUNTIME_DEBUG_FLAG(C, x) \ - static_assert(!C::x, "Unexpected enabled flag in release build"); -#else -#define DECLARE_RUNTIME_DEBUG_FLAG(x) \ - static bool x; -#define DEFINE_RUNTIME_DEBUG_FLAG(C, x) \ - bool C::x = RegisterRuntimeDebugFlag(&C::x); -#endif // NDEBUG - -bool RegisterRuntimeDebugFlag(bool* runtime_debug_flag); -void SetRuntimeDebugFlagsEnabled(bool enabled); - -// 0 if not abort, non-zero if an abort is in progress. Used on fatal exit to prevents recursive -// aborts. Global declaration allows us to disable some error checking to ensure fatal shutdown -// makes forward progress. -extern std::atomic<unsigned int> gAborting; - // Configure logging based on ANDROID_LOG_TAGS environment variable. // We need to parse a string that looks like // diff --git a/runtime/base/logging_test.cc b/runtime/base/logging_test.cc index d380b9eccc..404e080b03 100644 --- a/runtime/base/logging_test.cc +++ b/runtime/base/logging_test.cc @@ -22,6 +22,7 @@ #include "base/bit_utils.h" #include "base/macros.h" #include "common_runtime_test.h" +#include "runtime_debug.h" namespace art { diff --git a/runtime/base/macros.h b/runtime/base/macros.h index 6cd7d60253..512e5ce651 100644 --- a/runtime/base/macros.h +++ b/runtime/base/macros.h @@ -59,6 +59,10 @@ template<typename T> ART_FRIEND_TEST(test_set_name, individual_test) #define QUOTE(x) #x #define STRINGIFY(x) QUOTE(x) +// Append tokens after evaluating. +#define APPEND_TOKENS_AFTER_EVAL_2(a, b) a ## b +#define APPEND_TOKENS_AFTER_EVAL(a, b) APPEND_TOKENS_AFTER_EVAL_2(a, b) + #ifndef NDEBUG #define ALWAYS_INLINE #else diff --git a/runtime/base/mutex.h b/runtime/base/mutex.h index c0cf4872de..7077298ca9 100644 --- a/runtime/base/mutex.h +++ b/runtime/base/mutex.h @@ -24,8 +24,10 @@ #include <iosfwd> #include <string> +#include <android-base/logging.h> + #include "atomic.h" -#include "base/logging.h" +#include "base/aborting.h" #include "base/macros.h" #include "globals.h" diff --git a/runtime/base/runtime_debug.cc b/runtime/base/runtime_debug.cc new file mode 100644 index 0000000000..4f8a8ec9c6 --- /dev/null +++ b/runtime/base/runtime_debug.cc @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "runtime_debug.h" + +#include <vector> + +#include "globals.h" + +namespace art { + +// We test here that the runtime-debug-checks are actually a no-op constexpr false in release +// builds, as we can't check that in gtests (which are always debug). + +#ifdef NDEBUG +namespace { +DECLARE_RUNTIME_DEBUG_FLAG(kTestForConstexpr); +static_assert(!kTestForConstexpr, "Issue with DECLARE_RUNTIME_DEBUG_FLAG in NDEBUG."); +} +#endif + +// Implementation of runtime debug flags. This should be compile-time optimized away in release +// builds. +namespace { +bool gSlowEnabled = false; // Default for slow flags is "off." + +// Use a function with a static to ensure our vector storage doesn't have initialization order +// issues. +std::vector<bool*>& GetFlagPtrs() { + static std::vector<bool*> g_flag_ptrs; + return g_flag_ptrs; +} + +bool RegisterRuntimeDebugFlagImpl(bool* flag_ptr) { + GetFlagPtrs().push_back(flag_ptr); + return gSlowEnabled; +} + +void SetRuntimeDebugFlagsEnabledImpl(bool enabled) { + gSlowEnabled = enabled; + for (bool* flag_ptr : GetFlagPtrs()) { + *flag_ptr = enabled; + } +} + +} // namespace + +bool RegisterRuntimeDebugFlag(bool* flag_ptr) { + if (kIsDebugBuild) { + return RegisterRuntimeDebugFlagImpl(flag_ptr); + } + return false; +} + +void SetRuntimeDebugFlagsEnabled(bool enabled) { + if (kIsDebugBuild) { + SetRuntimeDebugFlagsEnabledImpl(enabled); + } +} + +} // namespace art diff --git a/runtime/base/runtime_debug.h b/runtime/base/runtime_debug.h new file mode 100644 index 0000000000..89a0361fa7 --- /dev/null +++ b/runtime/base/runtime_debug.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ART_RUNTIME_BASE_RUNTIME_DEBUG_H_ +#define ART_RUNTIME_BASE_RUNTIME_DEBUG_H_ + +namespace art { + +// Runtime debug flags are flags that have a runtime component, that is, their value can be changed. +// This is meant to implement fast vs slow debug builds, in that certain debug flags can be turned +// on and off. To that effect, expose two macros to help implement and globally drive these flags: +// +// In the header, declare a (class) flag like this: +// +// class C { +// DECLARE_RUNTIME_DEBUG_FLAG(kFlag); +// }; +// +// This will declare a flag kFlag that is a constexpr false in release builds, and a static field +// in debug builds. Usage is than uniform as C::kFlag. +// +// In the cc file, define the flag like this: +// +// DEFINE_RUNTIME_DEBUG_FLAG(C, kFlag); +// +// This will define the static storage, as necessary, and register the flag with the runtime +// infrastructure to toggle the value. + +#ifdef NDEBUG +#define DECLARE_RUNTIME_DEBUG_FLAG(x) \ + static constexpr bool x = false; +// Note: the static_assert in the following only works for public flags. Fix this when we cross +// the line at some point. +#define DEFINE_RUNTIME_DEBUG_FLAG(C, x) \ + static_assert(!C::x, "Unexpected enabled flag in release build"); +#else +#define DECLARE_RUNTIME_DEBUG_FLAG(x) \ + static bool x; +#define DEFINE_RUNTIME_DEBUG_FLAG(C, x) \ + bool C::x = RegisterRuntimeDebugFlag(&C::x); +#endif // NDEBUG + +bool RegisterRuntimeDebugFlag(bool* runtime_debug_flag); +void SetRuntimeDebugFlagsEnabled(bool enabled); + +} // namespace art + +#endif // ART_RUNTIME_BASE_RUNTIME_DEBUG_H_ diff --git a/runtime/base/scoped_arena_allocator.h b/runtime/base/scoped_arena_allocator.h index 8f50fd443b..35e337f0d6 100644 --- a/runtime/base/scoped_arena_allocator.h +++ b/runtime/base/scoped_arena_allocator.h @@ -17,10 +17,11 @@ #ifndef ART_RUNTIME_BASE_SCOPED_ARENA_ALLOCATOR_H_ #define ART_RUNTIME_BASE_SCOPED_ARENA_ALLOCATOR_H_ +#include <android-base/logging.h> + #include "arena_allocator.h" #include "debug_stack.h" #include "globals.h" -#include "logging.h" #include "macros.h" namespace art { diff --git a/runtime/base/scoped_flock.cc b/runtime/base/scoped_flock.cc index b8df6897e4..514b97bfb1 100644 --- a/runtime/base/scoped_flock.cc +++ b/runtime/base/scoped_flock.cc @@ -19,9 +19,9 @@ #include <sys/file.h> #include <sys/stat.h> -#include "android-base/stringprintf.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> -#include "base/logging.h" #include "base/unix_file/fd_file.h" namespace art { diff --git a/runtime/base/scoped_flock.h b/runtime/base/scoped_flock.h index 1b933c07f3..db6c819c6c 100644 --- a/runtime/base/scoped_flock.h +++ b/runtime/base/scoped_flock.h @@ -20,9 +20,8 @@ #include <memory> #include <string> -#include "android-base/unique_fd.h" +#include <android-base/unique_fd.h> -#include "base/logging.h" #include "base/macros.h" #include "base/unix_file/fd_file.h" #include "os.h" diff --git a/runtime/base/stl_util.h b/runtime/base/stl_util.h index b27297241d..02f37652cf 100644 --- a/runtime/base/stl_util.h +++ b/runtime/base/stl_util.h @@ -21,7 +21,7 @@ #include <set> #include <sstream> -#include "base/logging.h" +#include <android-base/logging.h> namespace art { diff --git a/runtime/base/stringpiece.cc b/runtime/base/stringpiece.cc index 2570bad85d..672431cf9d 100644 --- a/runtime/base/stringpiece.cc +++ b/runtime/base/stringpiece.cc @@ -19,7 +19,7 @@ #include <ostream> #include <utility> -#include "logging.h" +#include <android-base/logging.h> namespace art { diff --git a/runtime/base/systrace.h b/runtime/base/systrace.h index c6b6ff1d43..dc2206e420 100644 --- a/runtime/base/systrace.h +++ b/runtime/base/systrace.h @@ -19,8 +19,8 @@ #define ATRACE_TAG ATRACE_TAG_DALVIK #include <cutils/trace.h> -#include <utils/Trace.h> +#include <sstream> #include <string> #include "android-base/stringprintf.h" @@ -46,10 +46,37 @@ class ScopedTrace { } }; -#define SCOPED_TRACE(fmtstr, ...) \ - ::art::ScopedTrace trace ## __LINE__([&]() { \ - return ::android::base::StringPrintf((fmtstr), __VA_ARGS__); \ - }) +// Helper for the SCOPED_TRACE macro. Do not use directly. +class ScopedTraceNoStart { + public: + ScopedTraceNoStart() { + } + + ~ScopedTraceNoStart() { + ATRACE_END(); + } + + // Message helper for the macro. Do not use directly. + class ScopedTraceMessageHelper { + public: + ScopedTraceMessageHelper() { + } + ~ScopedTraceMessageHelper() { + ATRACE_BEGIN(buffer_.str().c_str()); + } + + std::ostream& stream() { + return buffer_; + } + + private: + std::ostringstream buffer_; + }; +}; + +#define SCOPED_TRACE \ + ::art::ScopedTraceNoStart trace ## __LINE__; \ + (ATRACE_ENABLED()) && ::art::ScopedTraceNoStart::ScopedTraceMessageHelper().stream() } // namespace art diff --git a/runtime/base/timing_logger.cc b/runtime/base/timing_logger.cc index b8d6931a83..23ec3e1aea 100644 --- a/runtime/base/timing_logger.cc +++ b/runtime/base/timing_logger.cc @@ -18,8 +18,9 @@ #include "timing_logger.h" +#include <android-base/logging.h> + #include "base/histogram-inl.h" -#include "base/logging.h" #include "base/stl_util.h" #include "base/systrace.h" #include "base/time_utils.h" diff --git a/runtime/base/unix_file/fd_file.cc b/runtime/base/unix_file/fd_file.cc index 792c58172e..37f239da23 100644 --- a/runtime/base/unix_file/fd_file.cc +++ b/runtime/base/unix_file/fd_file.cc @@ -23,7 +23,7 @@ #include <limits> -#include "base/logging.h" +#include <android-base/logging.h> // Includes needed for FdFile::Copy(). #ifdef __linux__ diff --git a/runtime/cdex/compact_dex_level.h b/runtime/cdex/compact_dex_level.h index b824462bf0..5aec00195d 100644 --- a/runtime/cdex/compact_dex_level.h +++ b/runtime/cdex/compact_dex_level.h @@ -17,6 +17,9 @@ #ifndef ART_RUNTIME_CDEX_COMPACT_DEX_LEVEL_H_ #define ART_RUNTIME_CDEX_COMPACT_DEX_LEVEL_H_ +#include <string> + +#include "base/macros.h" #include "dex_file.h" namespace art { @@ -29,6 +32,19 @@ enum class CompactDexLevel { kCompactDexLevelFast, }; +#ifndef ART_DEFAULT_COMPACT_DEX_LEVEL +#error ART_DEFAULT_COMPACT_DEX_LEVEL not specified. +#else +#define ART_DEFAULT_COMPACT_DEX_LEVEL_VALUE_fast CompactDexLevel::kCompactDexLevelFast +#define ART_DEFAULT_COMPACT_DEX_LEVEL_VALUE_none CompactDexLevel::kCompactDexLevelNone + +#define ART_DEFAULT_COMPACT_DEX_LEVEL_DEFAULT APPEND_TOKENS_AFTER_EVAL( \ + ART_DEFAULT_COMPACT_DEX_LEVEL_VALUE_, \ + ART_DEFAULT_COMPACT_DEX_LEVEL) + +static constexpr CompactDexLevel kDefaultCompactDexLevel = ART_DEFAULT_COMPACT_DEX_LEVEL_DEFAULT; +#endif + } // namespace art #endif // ART_RUNTIME_CDEX_COMPACT_DEX_LEVEL_H_ diff --git a/runtime/cha.cc b/runtime/cha.cc index 6c011e8e39..a53d7e5b25 100644 --- a/runtime/cha.cc +++ b/runtime/cha.cc @@ -17,6 +17,7 @@ #include "cha.h" #include "art_method-inl.h" +#include "base/logging.h" // For VLOG #include "jit/jit.h" #include "jit/jit_code_cache.h" #include "linear_alloc.h" diff --git a/runtime/check_jni.cc b/runtime/check_jni.cc index c3dd702446..0b9bf225d4 100644 --- a/runtime/check_jni.cc +++ b/runtime/check_jni.cc @@ -21,11 +21,12 @@ #include <iomanip> -#include "android-base/stringprintf.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> #include "art_field-inl.h" #include "art_method-inl.h" -#include "base/logging.h" +#include "base/macros.h" #include "base/to_str.h" #include "class_linker-inl.h" #include "class_linker.h" diff --git a/runtime/class_linker-inl.h b/runtime/class_linker-inl.h index d6f003027b..4b317f886f 100644 --- a/runtime/class_linker-inl.h +++ b/runtime/class_linker-inl.h @@ -61,33 +61,94 @@ inline mirror::Class* ClassLinker::FindArrayClass(Thread* self, return array_class.Ptr(); } -inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType( - dex::TypeIndex type_idx, - ObjPtr<mirror::DexCache> dex_cache, - ObjPtr<mirror::ClassLoader> class_loader) { - ObjPtr<mirror::Class> type = dex_cache->GetResolvedType(type_idx); - if (type == nullptr) { - type = Runtime::Current()->GetClassLinker()->LookupResolvedType( - *dex_cache->GetDexFile(), type_idx, dex_cache, class_loader); +inline ObjPtr<mirror::Class> ClassLinker::ResolveType(dex::TypeIndex type_idx, + ObjPtr<mirror::Class> referrer) { + if (kObjPtrPoisoning) { + StackHandleScope<1> hs(Thread::Current()); + HandleWrapperObjPtr<mirror::Class> referrer_wrapper = hs.NewHandleWrapper(&referrer); + Thread::Current()->PoisonObjectPointers(); } - return type; + if (kIsDebugBuild) { + Thread::Current()->AssertNoPendingException(); + } + // We do not need the read barrier for getting the DexCache for the initial resolved type + // lookup as both from-space and to-space copies point to the same native resolved types array. + ObjPtr<mirror::Class> resolved_type = + referrer->GetDexCache<kDefaultVerifyFlags, kWithoutReadBarrier>()->GetResolvedType(type_idx); + if (resolved_type == nullptr) { + StackHandleScope<2> hs(Thread::Current()); + Handle<mirror::DexCache> h_dex_cache(hs.NewHandle(referrer->GetDexCache())); + Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referrer->GetClassLoader())); + resolved_type = DoResolveType(type_idx, h_dex_cache, class_loader); + } + return resolved_type; } -inline mirror::Class* ClassLinker::ResolveType(dex::TypeIndex type_idx, ArtMethod* referrer) { +inline ObjPtr<mirror::Class> ClassLinker::ResolveType(dex::TypeIndex type_idx, + ArtMethod* referrer) { Thread::PoisonObjectPointersIfDebug(); if (kIsDebugBuild) { Thread::Current()->AssertNoPendingException(); } - ObjPtr<mirror::Class> resolved_type = referrer->GetDexCache()->GetResolvedType(type_idx); + // We do not need the read barrier for getting the DexCache for the initial resolved type + // lookup as both from-space and to-space copies point to the same native resolved types array. + ObjPtr<mirror::Class> resolved_type = + referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedType(type_idx); if (UNLIKELY(resolved_type == nullptr)) { StackHandleScope<2> hs(Thread::Current()); - ObjPtr<mirror::Class> declaring_class = referrer->GetDeclaringClass(); + ObjPtr<mirror::Class> referring_class = referrer->GetDeclaringClass(); Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache())); - Handle<mirror::ClassLoader> class_loader(hs.NewHandle(declaring_class->GetClassLoader())); - const DexFile& dex_file = *dex_cache->GetDexFile(); - resolved_type = ResolveType(dex_file, type_idx, dex_cache, class_loader); + Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referring_class->GetClassLoader())); + resolved_type = DoResolveType(type_idx, dex_cache, class_loader); + } + return resolved_type; +} + +inline ObjPtr<mirror::Class> ClassLinker::ResolveType(dex::TypeIndex type_idx, + Handle<mirror::DexCache> dex_cache, + Handle<mirror::ClassLoader> class_loader) { + DCHECK(dex_cache != nullptr); + Thread::PoisonObjectPointersIfDebug(); + ObjPtr<mirror::Class> resolved = dex_cache->GetResolvedType(type_idx); + if (resolved == nullptr) { + resolved = DoResolveType(type_idx, dex_cache, class_loader); + } + return resolved; +} + +inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(dex::TypeIndex type_idx, + ObjPtr<mirror::Class> referrer) { + // We do not need the read barrier for getting the DexCache for the initial resolved type + // lookup as both from-space and to-space copies point to the same native resolved types array. + ObjPtr<mirror::Class> type = + referrer->GetDexCache<kDefaultVerifyFlags, kWithoutReadBarrier>()->GetResolvedType(type_idx); + if (type == nullptr) { + type = DoLookupResolvedType(type_idx, referrer->GetDexCache(), referrer->GetClassLoader()); + } + return type; +} + +inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(dex::TypeIndex type_idx, + ArtMethod* referrer) { + // We do not need the read barrier for getting the DexCache for the initial resolved type + // lookup as both from-space and to-space copies point to the same native resolved types array. + ObjPtr<mirror::Class> type = + referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedType(type_idx); + if (type == nullptr) { + type = DoLookupResolvedType(type_idx, referrer->GetDexCache(), referrer->GetClassLoader()); + } + return type; +} + +inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType( + dex::TypeIndex type_idx, + ObjPtr<mirror::DexCache> dex_cache, + ObjPtr<mirror::ClassLoader> class_loader) { + ObjPtr<mirror::Class> type = dex_cache->GetResolvedType(type_idx); + if (type == nullptr) { + type = DoLookupResolvedType(type_idx, dex_cache, class_loader); } - return resolved_type.Ptr(); + return type; } template <bool kThrowOnError, typename ClassGetter> @@ -147,10 +208,9 @@ inline bool ClassLinker::CheckInvokeClassMismatch(ObjPtr<mirror::DexCache> dex_c dex_cache, type, [this, dex_cache, method_idx, class_loader]() REQUIRES_SHARED(Locks::mutator_lock_) { - const DexFile& dex_file = *dex_cache->GetDexFile(); - const DexFile::MethodId& method_id = dex_file.GetMethodId(method_idx); + const DexFile::MethodId& method_id = dex_cache->GetDexFile()->GetMethodId(method_idx); ObjPtr<mirror::Class> klass = - LookupResolvedType(dex_file, method_id.class_idx_, dex_cache, class_loader); + LookupResolvedType(method_id.class_idx_, dex_cache, class_loader); DCHECK(klass != nullptr); return klass; }); @@ -186,6 +246,8 @@ inline ArtMethod* ClassLinker::GetResolvedMethod(uint32_t method_idx, ArtMethod* // lookup in the context of the original method from where it steals the code. // However, we delay the GetInterfaceMethodIfProxy() until needed. DCHECK(!referrer->IsProxyMethod() || referrer->IsConstructor()); + // We do not need the read barrier for getting the DexCache for the initial resolved method + // lookup as both from-space and to-space copies point to the same native resolved methods array. ArtMethod* resolved_method = referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedMethod( method_idx, image_pointer_size_); if (resolved_method == nullptr) { @@ -227,6 +289,8 @@ inline ArtMethod* ClassLinker::ResolveMethod(Thread* self, // However, we delay the GetInterfaceMethodIfProxy() until needed. DCHECK(!referrer->IsProxyMethod() || referrer->IsConstructor()); Thread::PoisonObjectPointersIfDebug(); + // We do not need the read barrier for getting the DexCache for the initial resolved method + // lookup as both from-space and to-space copies point to the same native resolved methods array. ArtMethod* resolved_method = referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedMethod( method_idx, image_pointer_size_); DCHECK(resolved_method == nullptr || !resolved_method->IsRuntimeMethod()); @@ -236,9 +300,7 @@ inline ArtMethod* ClassLinker::ResolveMethod(Thread* self, StackHandleScope<2> hs(self); Handle<mirror::DexCache> h_dex_cache(hs.NewHandle(referrer->GetDexCache())); Handle<mirror::ClassLoader> h_class_loader(hs.NewHandle(declaring_class->GetClassLoader())); - const DexFile* dex_file = h_dex_cache->GetDexFile(); - resolved_method = ResolveMethod<kResolveMode>(*dex_file, - method_idx, + resolved_method = ResolveMethod<kResolveMode>(method_idx, h_dex_cache, h_class_loader, referrer, @@ -279,10 +341,13 @@ inline ArtMethod* ClassLinker::ResolveMethod(Thread* self, inline ArtField* ClassLinker::LookupResolvedField(uint32_t field_idx, ArtMethod* referrer, bool is_static) { - ObjPtr<mirror::DexCache> dex_cache = referrer->GetDexCache(); - ArtField* field = dex_cache->GetResolvedField(field_idx, image_pointer_size_); + // We do not need the read barrier for getting the DexCache for the initial resolved field + // lookup as both from-space and to-space copies point to the same native resolved fields array. + ArtField* field = referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedField( + field_idx, image_pointer_size_); if (field == nullptr) { - field = LookupResolvedField(field_idx, dex_cache, referrer->GetClassLoader(), is_static); + ObjPtr<mirror::ClassLoader> class_loader = referrer->GetDeclaringClass()->GetClassLoader(); + field = LookupResolvedField(field_idx, referrer->GetDexCache(), class_loader, is_static); } return field; } @@ -291,15 +356,16 @@ inline ArtField* ClassLinker::ResolveField(uint32_t field_idx, ArtMethod* referrer, bool is_static) { Thread::PoisonObjectPointersIfDebug(); - ObjPtr<mirror::Class> declaring_class = referrer->GetDeclaringClass(); - ArtField* resolved_field = - referrer->GetDexCache()->GetResolvedField(field_idx, image_pointer_size_); + // We do not need the read barrier for getting the DexCache for the initial resolved field + // lookup as both from-space and to-space copies point to the same native resolved fields array. + ArtField* resolved_field = referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedField( + field_idx, image_pointer_size_); if (UNLIKELY(resolved_field == nullptr)) { StackHandleScope<2> hs(Thread::Current()); + ObjPtr<mirror::Class> referring_class = referrer->GetDeclaringClass(); Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache())); - Handle<mirror::ClassLoader> class_loader(hs.NewHandle(declaring_class->GetClassLoader())); - const DexFile& dex_file = *dex_cache->GetDexFile(); - resolved_field = ResolveField(dex_file, field_idx, dex_cache, class_loader, is_static); + Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referring_class->GetClassLoader())); + resolved_field = ResolveField(field_idx, dex_cache, class_loader, is_static); // Note: We cannot check here to see whether we added the field to the cache. The type // might be an erroneous class, which results in it being hidden from us. } diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index b633972b3d..55fa6328f5 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -4818,7 +4818,6 @@ bool ClassLinker::InitializeClass(Thread* self, Handle<mirror::Class> klass, if (num_static_fields > 0) { const DexFile::ClassDef* dex_class_def = klass->GetClassDef(); CHECK(dex_class_def != nullptr); - const DexFile& dex_file = klass->GetDexFile(); StackHandleScope<3> hs(self); Handle<mirror::ClassLoader> class_loader(hs.NewHandle(klass->GetClassLoader())); Handle<mirror::DexCache> dex_cache(hs.NewHandle(klass->GetDexCache())); @@ -4836,11 +4835,11 @@ bool ClassLinker::InitializeClass(Thread* self, Handle<mirror::Class> klass, } } - annotations::RuntimeEncodedStaticFieldValueIterator value_it(dex_file, - &dex_cache, - &class_loader, + annotations::RuntimeEncodedStaticFieldValueIterator value_it(dex_cache, + class_loader, this, *dex_class_def); + const DexFile& dex_file = *dex_cache->GetDexFile(); const uint8_t* class_data = dex_file.GetClassData(*dex_class_def); ClassDataItemIterator field_it(dex_file, class_data); if (value_it.HasNext()) { @@ -4848,7 +4847,7 @@ bool ClassLinker::InitializeClass(Thread* self, Handle<mirror::Class> klass, CHECK(can_init_statics); for ( ; value_it.HasNext(); value_it.Next(), field_it.Next()) { ArtField* field = ResolveField( - dex_file, field_it.GetMemberIndex(), dex_cache, class_loader, true); + field_it.GetMemberIndex(), dex_cache, class_loader, /* is_static */ true); if (Runtime::Current()->IsActiveTransaction()) { value_it.ReadValueToField<true>(field); } else { @@ -5467,7 +5466,7 @@ bool ClassLinker::LoadSuperAndInterfaces(Handle<mirror::Class> klass, const DexF return false; } - ObjPtr<mirror::Class> super_class = ResolveType(dex_file, super_class_idx, klass.Get()); + ObjPtr<mirror::Class> super_class = ResolveType(super_class_idx, klass.Get()); if (super_class == nullptr) { DCHECK(Thread::Current()->IsExceptionPending()); return false; @@ -5486,7 +5485,7 @@ bool ClassLinker::LoadSuperAndInterfaces(Handle<mirror::Class> klass, const DexF if (interfaces != nullptr) { for (size_t i = 0; i < interfaces->Size(); i++) { dex::TypeIndex idx = interfaces->GetTypeItem(i).type_idx_; - ObjPtr<mirror::Class> interface = ResolveType(dex_file, idx, klass.Get()); + ObjPtr<mirror::Class> interface = ResolveType(idx, klass.Get()); if (interface == nullptr) { DCHECK(Thread::Current()->IsExceptionPending()); return false; @@ -7727,32 +7726,32 @@ void ClassLinker::CreateReferenceInstanceOffsets(Handle<mirror::Class> klass) { klass->SetReferenceInstanceOffsets(reference_offsets); } -mirror::String* ClassLinker::ResolveString(const DexFile& dex_file, - dex::StringIndex string_idx, - Handle<mirror::DexCache> dex_cache) { +ObjPtr<mirror::String> ClassLinker::ResolveString(dex::StringIndex string_idx, + Handle<mirror::DexCache> dex_cache) { DCHECK(dex_cache != nullptr); Thread::PoisonObjectPointersIfDebug(); ObjPtr<mirror::String> resolved = dex_cache->GetResolvedString(string_idx); if (resolved != nullptr) { - return resolved.Ptr(); + return resolved; } + const DexFile& dex_file = *dex_cache->GetDexFile(); uint32_t utf16_length; const char* utf8_data = dex_file.StringDataAndUtf16LengthByIdx(string_idx, &utf16_length); ObjPtr<mirror::String> string = intern_table_->InternStrong(utf16_length, utf8_data); if (string != nullptr) { dex_cache->SetResolvedString(string_idx, string); } - return string.Ptr(); + return string; } -mirror::String* ClassLinker::LookupString(const DexFile& dex_file, - dex::StringIndex string_idx, - ObjPtr<mirror::DexCache> dex_cache) { +ObjPtr<mirror::String> ClassLinker::LookupString(dex::StringIndex string_idx, + ObjPtr<mirror::DexCache> dex_cache) { DCHECK(dex_cache != nullptr); ObjPtr<mirror::String> resolved = dex_cache->GetResolvedString(string_idx); if (resolved != nullptr) { - return resolved.Ptr(); + return resolved; } + const DexFile& dex_file = *dex_cache->GetDexFile(); uint32_t utf16_length; const char* utf8_data = dex_file.StringDataAndUtf16LengthByIdx(string_idx, &utf16_length); ObjPtr<mirror::String> string = @@ -7760,82 +7759,64 @@ mirror::String* ClassLinker::LookupString(const DexFile& dex_file, if (string != nullptr) { dex_cache->SetResolvedString(string_idx, string); } - return string.Ptr(); + return string; } -ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(const DexFile& dex_file, - dex::TypeIndex type_idx, - ObjPtr<mirror::DexCache> dex_cache, - ObjPtr<mirror::ClassLoader> class_loader) { - ObjPtr<mirror::Class> type = dex_cache->GetResolvedType(type_idx); - if (type == nullptr) { - const char* descriptor = dex_file.StringByTypeIdx(type_idx); - DCHECK_NE(*descriptor, '\0') << "descriptor is empty string"; - if (descriptor[1] == '\0') { - // only the descriptors of primitive types should be 1 character long, also avoid class lookup - // for primitive classes that aren't backed by dex files. - type = FindPrimitiveClass(descriptor[0]); +ObjPtr<mirror::Class> ClassLinker::DoLookupResolvedType(dex::TypeIndex type_idx, + ObjPtr<mirror::DexCache> dex_cache, + ObjPtr<mirror::ClassLoader> class_loader) { + const DexFile& dex_file = *dex_cache->GetDexFile(); + const char* descriptor = dex_file.StringByTypeIdx(type_idx); + DCHECK_NE(*descriptor, '\0') << "descriptor is empty string"; + ObjPtr<mirror::Class> type = nullptr; + if (descriptor[1] == '\0') { + // only the descriptors of primitive types should be 1 character long, also avoid class lookup + // for primitive classes that aren't backed by dex files. + type = FindPrimitiveClass(descriptor[0]); + } else { + Thread* const self = Thread::Current(); + DCHECK(self != nullptr); + const size_t hash = ComputeModifiedUtf8Hash(descriptor); + // Find the class in the loaded classes table. + type = LookupClass(self, descriptor, hash, class_loader.Ptr()); + } + if (type != nullptr) { + if (type->IsResolved()) { + dex_cache->SetResolvedType(type_idx, type); } else { - Thread* const self = Thread::Current(); - DCHECK(self != nullptr); - const size_t hash = ComputeModifiedUtf8Hash(descriptor); - // Find the class in the loaded classes table. - type = LookupClass(self, descriptor, hash, class_loader.Ptr()); - } - if (type != nullptr) { - if (type->IsResolved()) { - dex_cache->SetResolvedType(type_idx, type); - } else { - type = nullptr; - } + type = nullptr; } } - DCHECK(type == nullptr || type->IsResolved()); return type; } -mirror::Class* ClassLinker::ResolveType(const DexFile& dex_file, - dex::TypeIndex type_idx, - ObjPtr<mirror::Class> referrer) { - StackHandleScope<2> hs(Thread::Current()); - Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache())); - Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referrer->GetClassLoader())); - return ResolveType(dex_file, type_idx, dex_cache, class_loader); -} - -mirror::Class* ClassLinker::ResolveType(const DexFile& dex_file, - dex::TypeIndex type_idx, - Handle<mirror::DexCache> dex_cache, - Handle<mirror::ClassLoader> class_loader) { - DCHECK(dex_cache != nullptr); - Thread::PoisonObjectPointersIfDebug(); - ObjPtr<mirror::Class> resolved = dex_cache->GetResolvedType(type_idx); - if (resolved == nullptr) { - Thread* self = Thread::Current(); - const char* descriptor = dex_file.StringByTypeIdx(type_idx); - resolved = FindClass(self, descriptor, class_loader); - 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 - dex_cache->SetResolvedType(type_idx, resolved); - } else { - CHECK(self->IsExceptionPending()) - << "Expected pending exception for failed resolution of: " << descriptor; - // Convert a ClassNotFoundException to a NoClassDefFoundError. - StackHandleScope<1> hs(self); - Handle<mirror::Throwable> cause(hs.NewHandle(self->GetException())); - if (cause->InstanceOf(GetClassRoot(kJavaLangClassNotFoundException))) { - DCHECK(resolved == nullptr); // No Handle needed to preserve resolved. - self->ClearException(); - ThrowNoClassDefFoundError("Failed resolution of: %s", descriptor); - self->GetException()->SetCause(cause.Get()); - } +ObjPtr<mirror::Class> ClassLinker::DoResolveType(dex::TypeIndex type_idx, + Handle<mirror::DexCache> dex_cache, + Handle<mirror::ClassLoader> class_loader) { + Thread* self = Thread::Current(); + const char* descriptor = dex_cache->GetDexFile()->StringByTypeIdx(type_idx); + ObjPtr<mirror::Class> resolved = FindClass(self, descriptor, class_loader); + 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 + dex_cache->SetResolvedType(type_idx, resolved); + } else { + CHECK(self->IsExceptionPending()) + << "Expected pending exception for failed resolution of: " << descriptor; + // Convert a ClassNotFoundException to a NoClassDefFoundError. + StackHandleScope<1> hs(self); + Handle<mirror::Throwable> cause(hs.NewHandle(self->GetException())); + if (cause->InstanceOf(GetClassRoot(kJavaLangClassNotFoundException))) { + DCHECK(resolved == nullptr); // No Handle needed to preserve resolved. + self->ClearException(); + ThrowNoClassDefFoundError("Failed resolution of: %s", descriptor); + self->GetException()->SetCause(cause.Get()); } } DCHECK((resolved == nullptr) || resolved->IsResolved()) << resolved->PrettyDescriptor() << " " << resolved->GetStatus(); - return resolved.Ptr(); + return resolved; } std::string DescribeSpace(ObjPtr<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_) { @@ -7939,8 +7920,7 @@ std::string DescribeLoaders(ObjPtr<mirror::ClassLoader> loader, const char* clas } template <ClassLinker::ResolveMode kResolveMode> -ArtMethod* ClassLinker::ResolveMethod(const DexFile& dex_file, - uint32_t method_idx, +ArtMethod* ClassLinker::ResolveMethod(uint32_t method_idx, Handle<mirror::DexCache> dex_cache, Handle<mirror::ClassLoader> class_loader, ArtMethod* referrer, @@ -7958,12 +7938,13 @@ ArtMethod* ClassLinker::ResolveMethod(const DexFile& dex_file, DCHECK(resolved->GetDeclaringClassUnchecked() != nullptr) << resolved->GetDexMethodIndex(); return resolved; } + const DexFile& dex_file = *dex_cache->GetDexFile(); const DexFile::MethodId& method_id = dex_file.GetMethodId(method_idx); ObjPtr<mirror::Class> klass = nullptr; if (valid_dex_cache_method) { // We have a valid method from the DexCache but we need to perform ICCE and IAE checks. DCHECK(resolved->GetDeclaringClassUnchecked() != nullptr) << resolved->GetDexMethodIndex(); - klass = LookupResolvedType(dex_file, method_id.class_idx_, dex_cache.Get(), class_loader.Get()); + klass = LookupResolvedType(method_id.class_idx_, dex_cache.Get(), class_loader.Get()); if (UNLIKELY(klass == nullptr)) { const char* descriptor = dex_file.StringByTypeIdx(method_id.class_idx_); LOG(FATAL) << "Check failed: klass != nullptr Bug: 64759619 Method: " @@ -7974,7 +7955,7 @@ ArtMethod* ClassLinker::ResolveMethod(const DexFile& dex_file, } } else { // The method was not in the DexCache, resolve the declaring class. - klass = ResolveType(dex_file, method_id.class_idx_, dex_cache, class_loader); + klass = ResolveType(method_id.class_idx_, dex_cache, class_loader); if (klass == nullptr) { DCHECK(Thread::Current()->IsExceptionPending()); return nullptr; @@ -8049,8 +8030,7 @@ ArtMethod* ClassLinker::ResolveMethod(const DexFile& dex_file, } } -ArtMethod* ClassLinker::ResolveMethodWithoutInvokeType(const DexFile& dex_file, - uint32_t method_idx, +ArtMethod* ClassLinker::ResolveMethodWithoutInvokeType(uint32_t method_idx, Handle<mirror::DexCache> dex_cache, Handle<mirror::ClassLoader> class_loader) { ArtMethod* resolved = dex_cache->GetResolvedMethod(method_idx, image_pointer_size_); @@ -8061,9 +8041,8 @@ ArtMethod* ClassLinker::ResolveMethodWithoutInvokeType(const DexFile& dex_file, return resolved; } // Fail, get the declaring class. - const DexFile::MethodId& method_id = dex_file.GetMethodId(method_idx); - ObjPtr<mirror::Class> klass = - ResolveType(dex_file, method_id.class_idx_, dex_cache, class_loader); + const DexFile::MethodId& method_id = dex_cache->GetDexFile()->GetMethodId(method_idx); + ObjPtr<mirror::Class> klass = ResolveType(method_id.class_idx_, dex_cache, class_loader); if (klass == nullptr) { Thread::Current()->AssertPendingException(); return nullptr; @@ -8085,7 +8064,7 @@ ArtField* ClassLinker::LookupResolvedField(uint32_t field_idx, const DexFile::FieldId& field_id = dex_file.GetFieldId(field_idx); ObjPtr<mirror::Class> klass = dex_cache->GetResolvedType(field_id.class_idx_); if (klass == nullptr) { - klass = LookupResolvedType(dex_file, field_id.class_idx_, dex_cache, class_loader); + klass = LookupResolvedType(field_id.class_idx_, dex_cache, class_loader); } if (klass == nullptr) { // The class has not been resolved yet, so the field is also unresolved. @@ -8114,8 +8093,7 @@ ArtField* ClassLinker::LookupResolvedField(uint32_t field_idx, return resolved_field; } -ArtField* ClassLinker::ResolveField(const DexFile& dex_file, - uint32_t field_idx, +ArtField* ClassLinker::ResolveField(uint32_t field_idx, Handle<mirror::DexCache> dex_cache, Handle<mirror::ClassLoader> class_loader, bool is_static) { @@ -8125,9 +8103,10 @@ ArtField* ClassLinker::ResolveField(const DexFile& dex_file, if (resolved != nullptr) { return resolved; } + const DexFile& dex_file = *dex_cache->GetDexFile(); const DexFile::FieldId& field_id = dex_file.GetFieldId(field_idx); Thread* const self = Thread::Current(); - ObjPtr<mirror::Class> klass = ResolveType(dex_file, field_id.class_idx_, dex_cache, class_loader); + ObjPtr<mirror::Class> klass = ResolveType(field_id.class_idx_, dex_cache, class_loader); if (klass == nullptr) { DCHECK(Thread::Current()->IsExceptionPending()); return nullptr; @@ -8156,8 +8135,7 @@ ArtField* ClassLinker::ResolveField(const DexFile& dex_file, return resolved; } -ArtField* ClassLinker::ResolveFieldJLS(const DexFile& dex_file, - uint32_t field_idx, +ArtField* ClassLinker::ResolveFieldJLS(uint32_t field_idx, Handle<mirror::DexCache> dex_cache, Handle<mirror::ClassLoader> class_loader) { DCHECK(dex_cache != nullptr); @@ -8166,9 +8144,10 @@ ArtField* ClassLinker::ResolveFieldJLS(const DexFile& dex_file, if (resolved != nullptr) { return resolved; } + const DexFile& dex_file = *dex_cache->GetDexFile(); const DexFile::FieldId& field_id = dex_file.GetFieldId(field_idx); Thread* self = Thread::Current(); - ObjPtr<mirror::Class> klass(ResolveType(dex_file, field_id.class_idx_, dex_cache, class_loader)); + ObjPtr<mirror::Class> klass = ResolveType(field_id.class_idx_, dex_cache, class_loader); if (klass == nullptr) { DCHECK(Thread::Current()->IsExceptionPending()); return nullptr; @@ -8185,11 +8164,11 @@ ArtField* ClassLinker::ResolveFieldJLS(const DexFile& dex_file, return resolved; } -mirror::MethodType* ClassLinker::ResolveMethodType(Thread* self, - const DexFile& dex_file, - uint32_t proto_idx, - Handle<mirror::DexCache> dex_cache, - Handle<mirror::ClassLoader> class_loader) { +ObjPtr<mirror::MethodType> ClassLinker::ResolveMethodType( + Thread* self, + uint32_t proto_idx, + Handle<mirror::DexCache> dex_cache, + Handle<mirror::ClassLoader> class_loader) { DCHECK(Runtime::Current()->IsMethodHandlesEnabled()); DCHECK(dex_cache != nullptr); @@ -8201,9 +8180,10 @@ mirror::MethodType* ClassLinker::ResolveMethodType(Thread* self, StackHandleScope<4> hs(self); // First resolve the return type. + const DexFile& dex_file = *dex_cache->GetDexFile(); const DexFile::ProtoId& proto_id = dex_file.GetProtoId(proto_idx); Handle<mirror::Class> return_type(hs.NewHandle( - ResolveType(dex_file, proto_id.return_type_idx_, dex_cache, class_loader))); + ResolveType(proto_id.return_type_idx_, dex_cache, class_loader))); if (return_type == nullptr) { DCHECK(self->IsExceptionPending()); return nullptr; @@ -8229,7 +8209,7 @@ mirror::MethodType* ClassLinker::ResolveMethodType(Thread* self, MutableHandle<mirror::Class> param_class = hs.NewHandle<mirror::Class>(nullptr); for (; it.HasNext(); it.Next()) { const dex::TypeIndex type_idx = it.GetTypeIdx(); - param_class.Assign(ResolveType(dex_file, type_idx, dex_cache, class_loader)); + param_class.Assign(ResolveType(type_idx, dex_cache, class_loader)); if (param_class == nullptr) { DCHECK(self->IsExceptionPending()); return nullptr; @@ -8247,14 +8227,13 @@ mirror::MethodType* ClassLinker::ResolveMethodType(Thread* self, return type.Get(); } -mirror::MethodType* ClassLinker::ResolveMethodType(Thread* self, - uint32_t proto_idx, - ArtMethod* referrer) { +ObjPtr<mirror::MethodType> ClassLinker::ResolveMethodType(Thread* self, + uint32_t proto_idx, + ArtMethod* referrer) { StackHandleScope<2> hs(self); - const DexFile* dex_file = referrer->GetDexFile(); Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache())); Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referrer->GetClassLoader())); - return ResolveMethodType(self, *dex_file, proto_idx, dex_cache, class_loader); + return ResolveMethodType(self, proto_idx, dex_cache, class_loader); } mirror::MethodHandle* ClassLinker::ResolveMethodHandleForField( @@ -8432,8 +8411,7 @@ mirror::MethodHandle* ClassLinker::ResolveMethodHandleForMethod( // the invocation type to determine if the method is private. We // then resolve again specifying the intended invocation type to // force the appropriate checks. - target_method = ResolveMethodWithoutInvokeType(*dex_file, - method_handle.field_or_method_idx_, + target_method = ResolveMethodWithoutInvokeType(method_handle.field_or_method_idx_, hs.NewHandle(referrer->GetDexCache()), hs.NewHandle(referrer->GetClassLoader())); if (UNLIKELY(target_method == nullptr)) { @@ -8516,7 +8494,7 @@ mirror::MethodHandle* ClassLinker::ResolveMethodHandleForMethod( DexFileParameterIterator it(*dex_file, target_method->GetPrototype()); while (it.HasNext()) { const dex::TypeIndex type_idx = it.GetTypeIdx(); - mirror::Class* klass = ResolveType(*dex_file, type_idx, dex_cache, class_loader); + ObjPtr<mirror::Class> klass = ResolveType(type_idx, dex_cache, class_loader); if (nullptr == klass) { DCHECK(self->IsExceptionPending()); return nullptr; @@ -8549,9 +8527,9 @@ mirror::MethodHandle* ClassLinker::ResolveMethodHandleForMethod( return mirror::MethodHandleImpl::Create(self, target, kind, method_type); } -mirror::MethodHandle* ClassLinker::ResolveMethodHandle(Thread* self, - uint32_t method_handle_idx, - ArtMethod* referrer) +ObjPtr<mirror::MethodHandle> ClassLinker::ResolveMethodHandle(Thread* self, + uint32_t method_handle_idx, + ArtMethod* referrer) REQUIRES_SHARED(Locks::mutator_lock_) { const DexFile* const dex_file = referrer->GetDexFile(); const DexFile::MethodHandleItem& method_handle = dex_file->GetMethodHandle(method_handle_idx); @@ -8765,10 +8743,10 @@ jobject ClassLinker::CreateWellKnownClassLoader(Thread* self, DCHECK_EQ(h_dex_element_class.Get(), element_file_field->GetDeclaringClass()); ArtField* cookie_field = jni::DecodeArtField(WellKnownClasses::dalvik_system_DexFile_cookie); - DCHECK_EQ(cookie_field->GetDeclaringClass(), element_file_field->LookupType()); + DCHECK_EQ(cookie_field->GetDeclaringClass(), element_file_field->LookupResolvedType()); ArtField* file_name_field = jni::DecodeArtField(WellKnownClasses::dalvik_system_DexFile_fileName); - DCHECK_EQ(file_name_field->GetDeclaringClass(), element_file_field->LookupType()); + DCHECK_EQ(file_name_field->GetDeclaringClass(), element_file_field->LookupResolvedType()); // Fill the elements array. int32_t index = 0; @@ -9034,14 +9012,12 @@ mirror::IfTable* ClassLinker::AllocIfTable(Thread* self, size_t ifcount) { // Instantiate ResolveMethod. template ArtMethod* ClassLinker::ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>( - const DexFile& dex_file, uint32_t method_idx, Handle<mirror::DexCache> dex_cache, Handle<mirror::ClassLoader> class_loader, ArtMethod* referrer, InvokeType type); template ArtMethod* ClassLinker::ResolveMethod<ClassLinker::ResolveMode::kNoChecks>( - const DexFile& dex_file, uint32_t method_idx, Handle<mirror::DexCache> dex_cache, Handle<mirror::ClassLoader> class_loader, diff --git a/runtime/class_linker.h b/runtime/class_linker.h index a4c4f3d9ab..10562f0890 100644 --- a/runtime/class_linker.h +++ b/runtime/class_linker.h @@ -243,58 +243,61 @@ class ClassLinker { REQUIRES(!Locks::classlinker_classes_lock_) REQUIRES_SHARED(Locks::mutator_lock_); - // Resolve a String with the given index from the DexFile, storing the - // result in the DexCache. - mirror::String* ResolveString(const DexFile& dex_file, - dex::StringIndex string_idx, - Handle<mirror::DexCache> dex_cache) - REQUIRES_SHARED(Locks::mutator_lock_); - - // Find a String with the given index from the DexFile, storing the - // result in the DexCache if found. Return null if not found. - mirror::String* LookupString(const DexFile& dex_file, - dex::StringIndex string_idx, - ObjPtr<mirror::DexCache> dex_cache) - REQUIRES_SHARED(Locks::mutator_lock_); - - // Resolve a Type with the given index from the DexFile, storing the - // result in the DexCache. The referrer is used to identify the - // target DexCache and ClassLoader to use for resolution. - mirror::Class* ResolveType(const DexFile& dex_file, - dex::TypeIndex type_idx, - ObjPtr<mirror::Class> referrer) + // Resolve a String with the given index from the DexFile associated with the given DexCache, + // storing the result in the DexCache. + ObjPtr<mirror::String> ResolveString(dex::StringIndex string_idx, + Handle<mirror::DexCache> dex_cache) + REQUIRES_SHARED(Locks::mutator_lock_); + + // Find a String with the given index from the DexFile associated with the given DexCache, + // storing the result in the DexCache if found. Return null if not found. + ObjPtr<mirror::String> LookupString(dex::StringIndex string_idx, + ObjPtr<mirror::DexCache> dex_cache) + REQUIRES_SHARED(Locks::mutator_lock_); + + // Resolve a Type with the given index from the DexFile associated with the given `referrer`, + // storing the result in the DexCache. The `referrer` is used to identify the target DexCache + // and ClassLoader to use for resolution. + ObjPtr<mirror::Class> ResolveType(dex::TypeIndex type_idx, ObjPtr<mirror::Class> referrer) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); - // Resolve a Type with the given index from the DexFile, storing the - // result in the DexCache. The referrer is used to identify the - // target DexCache and ClassLoader to use for resolution. - mirror::Class* ResolveType(dex::TypeIndex type_idx, ArtMethod* referrer) + // Resolve a type with the given index from the DexFile associated with the given `referrer`, + // storing the result in the DexCache. The `referrer` is used to identify the target DexCache + // and ClassLoader to use for resolution. + ObjPtr<mirror::Class> ResolveType(dex::TypeIndex type_idx, ArtMethod* referrer) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); - // Look up a resolved type with the given ID from the DexFile. The ClassLoader is used to search - // for the type, since it may be referenced from but not contained within the given DexFile. - ObjPtr<mirror::Class> LookupResolvedType(const DexFile& dex_file, - dex::TypeIndex type_idx, - ObjPtr<mirror::DexCache> dex_cache, - ObjPtr<mirror::ClassLoader> class_loader) + // Resolve a type with the given index from the DexFile associated with the given DexCache + // and ClassLoader, storing the result in DexCache. The ClassLoader is used to search for + // the type, since it may be referenced from but not contained within the DexFile. + ObjPtr<mirror::Class> ResolveType(dex::TypeIndex type_idx, + Handle<mirror::DexCache> dex_cache, + Handle<mirror::ClassLoader> class_loader) + REQUIRES_SHARED(Locks::mutator_lock_) + REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); + + // Look up a resolved type with the given index from the DexFile associated with the given + // `referrer`, storing the result in the DexCache. The `referrer` is used to identify the + // target DexCache and ClassLoader to use for lookup. + ObjPtr<mirror::Class> LookupResolvedType(dex::TypeIndex type_idx, + ObjPtr<mirror::Class> referrer) REQUIRES_SHARED(Locks::mutator_lock_); - static ObjPtr<mirror::Class> LookupResolvedType(dex::TypeIndex type_idx, - ObjPtr<mirror::DexCache> dex_cache, - ObjPtr<mirror::ClassLoader> class_loader) + + // Look up a resolved type with the given index from the DexFile associated with the given + // `referrer`, storing the result in the DexCache. The `referrer` is used to identify the + // target DexCache and ClassLoader to use for lookup. + ObjPtr<mirror::Class> LookupResolvedType(dex::TypeIndex type_idx, ArtMethod* referrer) REQUIRES_SHARED(Locks::mutator_lock_); - // Resolve a type with the given ID from the DexFile, storing the - // result in DexCache. The ClassLoader is used to search for the - // type, since it may be referenced from but not contained within - // the given DexFile. - mirror::Class* ResolveType(const DexFile& dex_file, - dex::TypeIndex type_idx, - Handle<mirror::DexCache> dex_cache, - Handle<mirror::ClassLoader> class_loader) - REQUIRES_SHARED(Locks::mutator_lock_) - REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); + // Look up a resolved type with the given index from the DexFile associated with the given + // DexCache and ClassLoader. The ClassLoader is used to search for the type, since it may + // be referenced from but not contained within the DexFile. + ObjPtr<mirror::Class> LookupResolvedType(dex::TypeIndex type_idx, + ObjPtr<mirror::DexCache> dex_cache, + ObjPtr<mirror::ClassLoader> class_loader) + REQUIRES_SHARED(Locks::mutator_lock_); // Determine whether a dex cache result should be trusted, or an IncompatibleClassChangeError // check and IllegalAccessError check should be performed even after a hit. @@ -309,14 +312,12 @@ class ClassLinker { ObjPtr<mirror::ClassLoader> class_loader) REQUIRES_SHARED(Locks::mutator_lock_); - // Resolve a method with a given ID from the DexFile, storing the - // result in DexCache. The ClassLinker and ClassLoader are used as - // in ResolveType. What is unique is the method type argument which - // is used to determine if this method is a direct, static, or - // virtual method. + // Resolve a method with a given ID from the DexFile associated with the given DexCache + // and ClassLoader, storing the result in DexCache. The ClassLinker and ClassLoader are + // used as in ResolveType. What is unique is the method type argument which is used to + // determine if this method is a direct, static, or virtual method. template <ResolveMode kResolveMode> - ArtMethod* ResolveMethod(const DexFile& dex_file, - uint32_t method_idx, + ArtMethod* ResolveMethod(uint32_t method_idx, Handle<mirror::DexCache> dex_cache, Handle<mirror::ClassLoader> class_loader, ArtMethod* referrer, @@ -332,8 +333,7 @@ class ClassLinker { ArtMethod* ResolveMethod(Thread* self, uint32_t method_idx, ArtMethod* referrer, InvokeType type) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); - ArtMethod* ResolveMethodWithoutInvokeType(const DexFile& dex_file, - uint32_t method_idx, + ArtMethod* ResolveMethodWithoutInvokeType(uint32_t method_idx, Handle<mirror::DexCache> dex_cache, Handle<mirror::ClassLoader> class_loader) REQUIRES_SHARED(Locks::mutator_lock_) @@ -345,47 +345,47 @@ class ClassLinker { REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); - // Resolve a field with a given ID from the DexFile, storing the - // result in DexCache. The ClassLinker and ClassLoader are used as - // in ResolveType. What is unique is the is_static argument which is - // used to determine if we are resolving a static or non-static - // field. - ArtField* ResolveField(const DexFile& dex_file, uint32_t field_idx, + // Resolve a field with a given ID from the DexFile associated with the given DexCache + // and ClassLoader, storing the result in DexCache. The ClassLinker and ClassLoader + // are used as in ResolveType. What is unique is the is_static argument which is used + // to determine if we are resolving a static or non-static field. + ArtField* ResolveField(uint32_t field_idx, Handle<mirror::DexCache> dex_cache, - Handle<mirror::ClassLoader> class_loader, bool is_static) + Handle<mirror::ClassLoader> class_loader, + bool is_static) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); - // Resolve a field with a given ID from the DexFile, storing the - // result in DexCache. The ClassLinker and ClassLoader are used as - // in ResolveType. No is_static argument is provided so that Java + // Resolve a field with a given ID from the DexFile associated with the given DexCache + // and ClassLoader, storing the result in DexCache. The ClassLinker and ClassLoader + // are used as in ResolveType. No is_static argument is provided so that Java // field resolution semantics are followed. - ArtField* ResolveFieldJLS(const DexFile& dex_file, - uint32_t field_idx, + ArtField* ResolveFieldJLS(uint32_t field_idx, Handle<mirror::DexCache> dex_cache, Handle<mirror::ClassLoader> class_loader) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); - // Resolve a method type with a given ID from the DexFile, storing - // the result in the DexCache. - mirror::MethodType* ResolveMethodType(Thread* self, - const DexFile& dex_file, - uint32_t proto_idx, - Handle<mirror::DexCache> dex_cache, - Handle<mirror::ClassLoader> class_loader) + // Resolve a method type with a given ID from the DexFile associated with a given DexCache + // and ClassLoader, storing the result in the DexCache. + ObjPtr<mirror::MethodType> ResolveMethodType(Thread* self, + uint32_t proto_idx, + Handle<mirror::DexCache> dex_cache, + Handle<mirror::ClassLoader> class_loader) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); - mirror::MethodType* ResolveMethodType(Thread* self, uint32_t proto_idx, ArtMethod* referrer) + ObjPtr<mirror::MethodType> ResolveMethodType(Thread* self, + uint32_t proto_idx, + ArtMethod* referrer) REQUIRES_SHARED(Locks::mutator_lock_); // Resolve a method handle with a given ID from the DexFile. The // result is not cached in the DexCache as the instance will only be // used once in most circumstances. - mirror::MethodHandle* ResolveMethodHandle(Thread* self, - uint32_t method_handle_idx, - ArtMethod* referrer) + ObjPtr<mirror::MethodHandle> ResolveMethodHandle(Thread* self, + uint32_t method_handle_idx, + ArtMethod* referrer) REQUIRES_SHARED(Locks::mutator_lock_); // Returns true on success, false if there's an exception pending. @@ -881,6 +881,19 @@ class ClassLinker { REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_); + // Implementation of LookupResolvedType() called when the type was not found in the dex cache. + ObjPtr<mirror::Class> DoLookupResolvedType(dex::TypeIndex type_idx, + ObjPtr<mirror::DexCache> dex_cache, + ObjPtr<mirror::ClassLoader> class_loader) + REQUIRES_SHARED(Locks::mutator_lock_); + + // Implementation of ResolveType() called when the type was not found in the dex cache. + ObjPtr<mirror::Class> DoResolveType(dex::TypeIndex type_idx, + Handle<mirror::DexCache> dex_cache, + Handle<mirror::ClassLoader> class_loader) + REQUIRES_SHARED(Locks::mutator_lock_) + REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); + // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded // by the given 'class_loader'. Uses the provided hash for the descriptor. mirror::Class* LookupClass(Thread* self, diff --git a/runtime/class_linker_test.cc b/runtime/class_linker_test.cc index 892a850997..246f89e5cc 100644 --- a/runtime/class_linker_test.cc +++ b/runtime/class_linker_test.cc @@ -954,15 +954,14 @@ TEST_F(ClassLinkerTest, LookupResolvedType) { ObjPtr<mirror::Class> klass = class_linker_->FindClass(soa.Self(), "LMyClass;", class_loader); dex::TypeIndex type_idx = klass->GetClassDef()->class_idx_; ObjPtr<mirror::DexCache> dex_cache = klass->GetDexCache(); - const DexFile& dex_file = klass->GetDexFile(); EXPECT_OBJ_PTR_EQ( - class_linker_->LookupResolvedType(dex_file, type_idx, dex_cache, class_loader.Get()), + class_linker_->LookupResolvedType(type_idx, dex_cache, class_loader.Get()), klass); // Zero out the resolved type and make sure LookupResolvedType still finds it. dex_cache->ClearResolvedType(type_idx); EXPECT_TRUE(dex_cache->GetResolvedType(type_idx) == nullptr); EXPECT_OBJ_PTR_EQ( - class_linker_->LookupResolvedType(dex_file, type_idx, dex_cache, class_loader.Get()), + class_linker_->LookupResolvedType(type_idx, dex_cache, class_loader.Get()), klass); } @@ -983,7 +982,7 @@ TEST_F(ClassLinkerTest, LookupResolvedTypeArray) { dex::TypeIndex array_idx = dex_file.GetIndexForTypeId(*array_id); // Check that the array class wasn't resolved yet. EXPECT_OBJ_PTR_EQ( - class_linker_->LookupResolvedType(dex_file, array_idx, dex_cache.Get(), class_loader.Get()), + class_linker_->LookupResolvedType(array_idx, dex_cache.Get(), class_loader.Get()), ObjPtr<mirror::Class>(nullptr)); // Resolve the array class we want to test. ObjPtr<mirror::Class> array_klass @@ -991,13 +990,13 @@ TEST_F(ClassLinkerTest, LookupResolvedTypeArray) { ASSERT_OBJ_PTR_NE(array_klass, ObjPtr<mirror::Class>(nullptr)); // Test that LookupResolvedType() finds the array class. EXPECT_OBJ_PTR_EQ( - class_linker_->LookupResolvedType(dex_file, array_idx, dex_cache.Get(), class_loader.Get()), + class_linker_->LookupResolvedType(array_idx, dex_cache.Get(), class_loader.Get()), array_klass); // Zero out the resolved type and make sure LookupResolvedType() still finds it. dex_cache->ClearResolvedType(array_idx); EXPECT_TRUE(dex_cache->GetResolvedType(array_idx) == nullptr); EXPECT_OBJ_PTR_EQ( - class_linker_->LookupResolvedType(dex_file, array_idx, dex_cache.Get(), class_loader.Get()), + class_linker_->LookupResolvedType(array_idx, dex_cache.Get(), class_loader.Get()), array_klass); } @@ -1012,15 +1011,14 @@ TEST_F(ClassLinkerTest, LookupResolvedTypeErroneousInit) { ASSERT_OBJ_PTR_NE(klass.Get(), ObjPtr<mirror::Class>(nullptr)); dex::TypeIndex type_idx = klass->GetClassDef()->class_idx_; Handle<mirror::DexCache> dex_cache = hs.NewHandle(klass->GetDexCache()); - const DexFile& dex_file = klass->GetDexFile(); EXPECT_OBJ_PTR_EQ( - class_linker_->LookupResolvedType(dex_file, type_idx, dex_cache.Get(), class_loader.Get()), + class_linker_->LookupResolvedType(type_idx, dex_cache.Get(), class_loader.Get()), klass.Get()); // Zero out the resolved type and make sure LookupResolvedType still finds it. dex_cache->ClearResolvedType(type_idx); EXPECT_TRUE(dex_cache->GetResolvedType(type_idx) == nullptr); EXPECT_OBJ_PTR_EQ( - class_linker_->LookupResolvedType(dex_file, type_idx, dex_cache.Get(), class_loader.Get()), + class_linker_->LookupResolvedType(type_idx, dex_cache.Get(), class_loader.Get()), klass.Get()); // Force initialization to turn the class erroneous. bool initialized = class_linker_->EnsureInitialized(soa.Self(), @@ -1032,13 +1030,13 @@ TEST_F(ClassLinkerTest, LookupResolvedTypeErroneousInit) { soa.Self()->ClearException(); // Check that the LookupResolvedType() can still find the resolved type. EXPECT_OBJ_PTR_EQ( - class_linker_->LookupResolvedType(dex_file, type_idx, dex_cache.Get(), class_loader.Get()), + class_linker_->LookupResolvedType(type_idx, dex_cache.Get(), class_loader.Get()), klass.Get()); // Zero out the resolved type and make sure LookupResolvedType() still finds it. dex_cache->ClearResolvedType(type_idx); EXPECT_TRUE(dex_cache->GetResolvedType(type_idx) == nullptr); EXPECT_OBJ_PTR_EQ( - class_linker_->LookupResolvedType(dex_file, type_idx, dex_cache.Get(), class_loader.Get()), + class_linker_->LookupResolvedType(type_idx, dex_cache.Get(), class_loader.Get()), klass.Get()); } @@ -1304,10 +1302,18 @@ TEST_F(ClassLinkerTest, ResolveVerifyAndClinit) { const DexFile::TypeId* type_id = dex_file->FindTypeId("LStaticsFromCode;"); ASSERT_TRUE(type_id != nullptr); dex::TypeIndex type_idx = dex_file->GetIndexForTypeId(*type_id); - mirror::Class* uninit = ResolveVerifyAndClinit(type_idx, clinit, soa.Self(), true, false); + ObjPtr<mirror::Class> uninit = ResolveVerifyAndClinit(type_idx, + clinit, + soa.Self(), + /* can_run_clinit */ true, + /* verify_access */ false); EXPECT_TRUE(uninit != nullptr); EXPECT_FALSE(uninit->IsInitialized()); - mirror::Class* init = ResolveVerifyAndClinit(type_idx, getS0, soa.Self(), true, false); + ObjPtr<mirror::Class> init = ResolveVerifyAndClinit(type_idx, + getS0, + soa.Self(), + /* can_run_clinit */ true, + /* verify_access */ false); EXPECT_TRUE(init != nullptr); EXPECT_TRUE(init->IsInitialized()); } @@ -1541,11 +1547,7 @@ TEST_F(ClassLinkerMethodHandlesTest, TestResolveMethodTypes) { // Its RType = Ljava/lang/String; // Its PTypes = { Ljava/lang/String; } Handle<mirror::MethodType> method1_type = hs.NewHandle( - class_linker_->ResolveMethodType(soa.Self(), - dex_file, - method1_id.proto_idx_, - dex_cache, - class_loader)); + class_linker_->ResolveMethodType(soa.Self(), method1_id.proto_idx_, dex_cache, class_loader)); // Assert that the method type was resolved successfully. ASSERT_TRUE(method1_type != nullptr); @@ -1559,11 +1561,7 @@ TEST_F(ClassLinkerMethodHandlesTest, TestResolveMethodTypes) { // Resolve the method type again and assert that we get back the same value. Handle<mirror::MethodType> method1_type2 = hs.NewHandle( - class_linker_->ResolveMethodType(soa.Self(), - dex_file, - method1_id.proto_idx_, - dex_cache, - class_loader)); + class_linker_->ResolveMethodType(soa.Self(), method1_id.proto_idx_, dex_cache, class_loader)); ASSERT_EQ(method1_type.Get(), method1_type2.Get()); // Resolve the MethodType associated with a different method signature @@ -1576,11 +1574,7 @@ TEST_F(ClassLinkerMethodHandlesTest, TestResolveMethodTypes) { ASSERT_FALSE(method2->IsDirect()); const DexFile::MethodId& method2_id = dex_file.GetMethodId(method2->GetDexMethodIndex()); Handle<mirror::MethodType> method2_type = hs.NewHandle( - class_linker_->ResolveMethodType(soa.Self(), - dex_file, - method2_id.proto_idx_, - dex_cache, - class_loader)); + class_linker_->ResolveMethodType(soa.Self(), method2_id.proto_idx_, dex_cache, class_loader)); ASSERT_TRUE(method1_type.Get() != method2_type.Get()); } diff --git a/runtime/common_runtime_test.cc b/runtime/common_runtime_test.cc index ef1647caf3..6db4d92708 100644 --- a/runtime/common_runtime_test.cc +++ b/runtime/common_runtime_test.cc @@ -30,6 +30,7 @@ #include "base/file_utils.h" #include "base/logging.h" #include "base/macros.h" +#include "base/runtime_debug.h" #include "base/stl_util.h" #include "base/unix_file/fd_file.h" #include "class_linker.h" diff --git a/runtime/common_runtime_test.h b/runtime/common_runtime_test.h index 5be8d5b55c..0f931e3dff 100644 --- a/runtime/common_runtime_test.h +++ b/runtime/common_runtime_test.h @@ -22,6 +22,8 @@ #include <string> +#include <android-base/logging.h> + #include "arch/instruction_set.h" #include "base/mutex.h" #include "globals.h" @@ -32,6 +34,9 @@ namespace art { +using LogSeverity = android::base::LogSeverity; +using ScopedLogSeverity = android::base::ScopedLogSeverity; + // OBJ pointer helpers to avoid needing .Decode everywhere. #define EXPECT_OBJ_PTR_EQ(a, b) EXPECT_EQ(MakeObjPtr(a).Ptr(), MakeObjPtr(b).Ptr()); #define ASSERT_OBJ_PTR_EQ(a, b) ASSERT_EQ(MakeObjPtr(a).Ptr(), MakeObjPtr(b).Ptr()); diff --git a/runtime/common_throws.cc b/runtime/common_throws.cc index cd52bb6551..575d18e26a 100644 --- a/runtime/common_throws.cc +++ b/runtime/common_throws.cc @@ -18,11 +18,11 @@ #include <sstream> -#include "android-base/stringprintf.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> #include "art_field-inl.h" #include "art_method-inl.h" -#include "base/logging.h" #include "class_linker-inl.h" #include "dex_file-inl.h" #include "dex_instruction-inl.h" @@ -441,7 +441,7 @@ static bool IsValidReadBarrierImplicitCheck(uintptr_t addr) { return addr == monitor_offset; } -static bool IsValidImplicitCheck(uintptr_t addr, ArtMethod* method, const Instruction& instr) +static bool IsValidImplicitCheck(uintptr_t addr, const Instruction& instr) REQUIRES_SHARED(Locks::mutator_lock_) { if (!CanDoImplicitNullCheckOn(addr)) { return false; @@ -483,9 +483,10 @@ static bool IsValidImplicitCheck(uintptr_t addr, ArtMethod* method, const Instru case Instruction::IPUT_BYTE: case Instruction::IPUT_CHAR: case Instruction::IPUT_SHORT: { - ArtField* field = - Runtime::Current()->GetClassLinker()->ResolveField(instr.VRegC_22c(), method, false); - return (addr == 0) || (addr == field->GetOffset().Uint32Value()); + // We might be doing an implicit null check with an offset that doesn't correspond + // to the instruction, for example with two field accesses and the first one being + // eliminated or re-ordered. + return true; } case Instruction::IGET_OBJECT_QUICK: @@ -506,7 +507,10 @@ static bool IsValidImplicitCheck(uintptr_t addr, ArtMethod* method, const Instru case Instruction::IPUT_SHORT_QUICK: case Instruction::IPUT_WIDE_QUICK: case Instruction::IPUT_OBJECT_QUICK: { - return (addr == 0u) || (addr == instr.VRegC_22c()); + // We might be doing an implicit null check with an offset that doesn't correspond + // to the instruction, for example with two field accesses and the first one being + // eliminated or re-ordered. + return true; } case Instruction::AGET_OBJECT: @@ -550,7 +554,7 @@ void ThrowNullPointerExceptionFromDexPC(bool check_address, uintptr_t addr) { const DexFile::CodeItem* code = method->GetCodeItem(); CHECK_LT(throw_dex_pc, code->insns_size_in_code_units_); const Instruction* instr = Instruction::At(&code->insns_[throw_dex_pc]); - if (check_address && !IsValidImplicitCheck(addr, method, *instr)) { + if (check_address && !IsValidImplicitCheck(addr, *instr)) { const DexFile* dex_file = method->GetDeclaringClass()->GetDexCache()->GetDexFile(); LOG(FATAL) << "Invalid address for an implicit NullPointerException check: " << "0x" << std::hex << addr << std::dec diff --git a/runtime/dex_file-inl.h b/runtime/dex_file-inl.h index 1c76a32f61..a6f762120c 100644 --- a/runtime/dex_file-inl.h +++ b/runtime/dex_file-inl.h @@ -19,7 +19,6 @@ #include "base/bit_utils.h" #include "base/casts.h" -#include "base/logging.h" #include "base/stringpiece.h" #include "cdex/compact_dex_file.h" #include "dex_file.h" diff --git a/runtime/dex_file.cc b/runtime/dex_file.cc index af79207834..2d02415ba4 100644 --- a/runtime/dex_file.cc +++ b/runtime/dex_file.cc @@ -29,7 +29,6 @@ #include "android-base/stringprintf.h" #include "base/enums.h" -#include "base/logging.h" #include "base/stl_util.h" #include "dex_file-inl.h" #include "leb128.h" diff --git a/runtime/dex_file.h b/runtime/dex_file.h index 91ec630f0c..de3af8a289 100644 --- a/runtime/dex_file.h +++ b/runtime/dex_file.h @@ -21,8 +21,10 @@ #include <string> #include <vector> +#include <android-base/logging.h> + #include "base/iteration_range.h" -#include "base/logging.h" +#include "base/macros.h" #include "base/value_object.h" #include "dex_file_types.h" #include "dex_instruction_iterator.h" diff --git a/runtime/dex_file_annotations.cc b/runtime/dex_file_annotations.cc index 837291b023..72b18fb420 100644 --- a/runtime/dex_file_annotations.cc +++ b/runtime/dex_file_annotations.cc @@ -343,8 +343,7 @@ mirror::Object* ProcessEncodedAnnotation(const ClassData& klass, const uint8_t** StackHandleScope<4> hs(self); ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); Handle<mirror::Class> annotation_class(hs.NewHandle( - class_linker->ResolveType(klass.GetDexFile(), - dex::TypeIndex(type_index), + class_linker->ResolveType(dex::TypeIndex(type_index), hs.NewHandle(klass.GetDexCache()), hs.NewHandle(klass.GetClassLoader())))); if (annotation_class == nullptr) { @@ -458,7 +457,7 @@ bool ProcessAnnotationValue(const ClassData& klass, } else { StackHandleScope<1> hs(self); element_object = Runtime::Current()->GetClassLinker()->ResolveString( - klass.GetDexFile(), dex::StringIndex(index), hs.NewHandle(klass.GetDexCache())); + dex::StringIndex(index), hs.NewHandle(klass.GetDexCache())); set_object = true; if (element_object == nullptr) { return false; @@ -474,7 +473,6 @@ bool ProcessAnnotationValue(const ClassData& klass, dex::TypeIndex type_index(index); StackHandleScope<2> hs(self); element_object = Runtime::Current()->GetClassLinker()->ResolveType( - klass.GetDexFile(), type_index, hs.NewHandle(klass.GetDexCache()), hs.NewHandle(klass.GetClassLoader())); @@ -501,7 +499,6 @@ bool ProcessAnnotationValue(const ClassData& klass, ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); StackHandleScope<2> hs(self); ArtMethod* method = class_linker->ResolveMethodWithoutInvokeType( - klass.GetDexFile(), index, hs.NewHandle(klass.GetDexCache()), hs.NewHandle(klass.GetClassLoader())); @@ -540,7 +537,6 @@ bool ProcessAnnotationValue(const ClassData& klass, } else { StackHandleScope<2> hs(self); ArtField* field = Runtime::Current()->GetClassLinker()->ResolveFieldJLS( - klass.GetDexFile(), index, hs.NewHandle(klass.GetDexCache()), hs.NewHandle(klass.GetClassLoader())); @@ -569,7 +565,6 @@ bool ProcessAnnotationValue(const ClassData& klass, } else { StackHandleScope<3> hs(self); ArtField* enum_field = Runtime::Current()->GetClassLinker()->ResolveField( - klass.GetDexFile(), index, hs.NewHandle(klass.GetDexCache()), hs.NewHandle(klass.GetClassLoader()), @@ -783,10 +778,8 @@ const DexFile::AnnotationItem* GetAnnotationItemFromAnnotationSet( uint32_t type_index = DecodeUnsignedLeb128(&annotation); ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); Thread* self = Thread::Current(); - mirror::Class* resolved_class; StackHandleScope<2> hs(self); - resolved_class = class_linker->ResolveType( - klass.GetDexFile(), + ObjPtr<mirror::Class> resolved_class = class_linker->ResolveType( dex::TypeIndex(type_index), hs.NewHandle(klass.GetDexCache()), hs.NewHandle(klass.GetClassLoader())); @@ -1401,7 +1394,6 @@ mirror::Class* GetEnclosingClass(Handle<mirror::Class> klass) { } StackHandleScope<2> hs(Thread::Current()); ArtMethod* method = Runtime::Current()->GetClassLinker()->ResolveMethodWithoutInvokeType( - data.GetDexFile(), annotation_value.value_.GetI(), hs.NewHandle(data.GetDexCache()), hs.NewHandle(data.GetClassLoader())); @@ -1579,7 +1571,6 @@ int32_t GetLineNumFromPC(const DexFile* dex_file, ArtMethod* method, uint32_t re template<bool kTransactionActive> void RuntimeEncodedStaticFieldValueIterator::ReadValueToField(ArtField* field) const { DCHECK(dex_cache_ != nullptr); - DCHECK(class_loader_ != nullptr); switch (type_) { case kBoolean: field->SetBoolean<kTransactionActive>(field->GetDeclaringClass(), jval_.z); break; @@ -1592,17 +1583,15 @@ void RuntimeEncodedStaticFieldValueIterator::ReadValueToField(ArtField* field) c case kDouble: field->SetDouble<kTransactionActive>(field->GetDeclaringClass(), jval_.d); break; case kNull: field->SetObject<kTransactionActive>(field->GetDeclaringClass(), nullptr); break; case kString: { - mirror::String* resolved = linker_->ResolveString(dex_file_, - dex::StringIndex(jval_.i), - *dex_cache_); + ObjPtr<mirror::String> resolved = linker_->ResolveString(dex::StringIndex(jval_.i), + dex_cache_); field->SetObject<kTransactionActive>(field->GetDeclaringClass(), resolved); break; } case kType: { - mirror::Class* resolved = linker_->ResolveType(dex_file_, - dex::TypeIndex(jval_.i), - *dex_cache_, - *class_loader_); + ObjPtr<mirror::Class> resolved = linker_->ResolveType(dex::TypeIndex(jval_.i), + dex_cache_, + class_loader_); field->SetObject<kTransactionActive>(field->GetDeclaringClass(), resolved); break; } diff --git a/runtime/dex_file_annotations.h b/runtime/dex_file_annotations.h index a934a4f99c..9ff0929176 100644 --- a/runtime/dex_file_annotations.h +++ b/runtime/dex_file_annotations.h @@ -19,18 +19,18 @@ #include "dex_file.h" +#include "handle.h" +#include "mirror/dex_cache.h" #include "mirror/object_array.h" namespace art { namespace mirror { class ClassLoader; -class DexCache; } // namespace mirror class ArtField; class ArtMethod; class ClassLinker; -template<class T> class MutableHandle; namespace annotations { @@ -116,13 +116,12 @@ int32_t GetLineNumFromPC(const DexFile* dex_file, ArtMethod* method, uint32_t re class RuntimeEncodedStaticFieldValueIterator : public EncodedStaticFieldValueIterator { public: // A constructor meant to be called from runtime code. - RuntimeEncodedStaticFieldValueIterator(const DexFile& dex_file, - Handle<mirror::DexCache>* dex_cache, - Handle<mirror::ClassLoader>* class_loader, + RuntimeEncodedStaticFieldValueIterator(Handle<mirror::DexCache> dex_cache, + Handle<mirror::ClassLoader> class_loader, ClassLinker* linker, const DexFile::ClassDef& class_def) REQUIRES_SHARED(Locks::mutator_lock_) - : EncodedStaticFieldValueIterator(dex_file, class_def), + : EncodedStaticFieldValueIterator(*dex_cache->GetDexFile(), class_def), dex_cache_(dex_cache), class_loader_(class_loader), linker_(linker) { @@ -132,9 +131,9 @@ class RuntimeEncodedStaticFieldValueIterator : public EncodedStaticFieldValueIte void ReadValueToField(ArtField* field) const REQUIRES_SHARED(Locks::mutator_lock_); private: - Handle<mirror::DexCache>* const dex_cache_; // Dex cache to resolve literal objects. - Handle<mirror::ClassLoader>* const class_loader_; // ClassLoader to resolve types. - ClassLinker* linker_; // Linker to resolve literal objects. + const Handle<mirror::DexCache> dex_cache_; // Dex cache to resolve literal objects. + const Handle<mirror::ClassLoader> class_loader_; // ClassLoader to resolve types. + ClassLinker* const linker_; // Linker to resolve literal objects. DISALLOW_IMPLICIT_CONSTRUCTORS(RuntimeEncodedStaticFieldValueIterator); }; diff --git a/runtime/dex_file_layout.h b/runtime/dex_file_layout.h index 4c960c3ff5..9fac5f8458 100644 --- a/runtime/dex_file_layout.h +++ b/runtime/dex_file_layout.h @@ -21,7 +21,7 @@ #include <cstdint> #include <iosfwd> -#include "base/logging.h" +#include <android-base/logging.h> namespace art { diff --git a/runtime/dex_file_tracking_registrar.cc b/runtime/dex_file_tracking_registrar.cc index 874d8ea905..4de43760d4 100644 --- a/runtime/dex_file_tracking_registrar.cc +++ b/runtime/dex_file_tracking_registrar.cc @@ -19,6 +19,8 @@ #include <deque> #include <tuple> +#include <android-base/logging.h> + // For dex tracking through poisoning. Note: Requires forcing sanitization. This is the reason for // the ifdefs and early include. #ifdef ART_DEX_FILE_ACCESS_TRACKING @@ -28,7 +30,6 @@ #endif #include "base/memory_tool.h" -#include "base/logging.h" #include "dex_file-inl.h" namespace art { diff --git a/runtime/dex_instruction.h b/runtime/dex_instruction.h index 4041820616..3ced6920e2 100644 --- a/runtime/dex_instruction.h +++ b/runtime/dex_instruction.h @@ -17,7 +17,8 @@ #ifndef ART_RUNTIME_DEX_INSTRUCTION_H_ #define ART_RUNTIME_DEX_INSTRUCTION_H_ -#include "base/logging.h" +#include <android-base/logging.h> + #include "base/macros.h" #include "globals.h" diff --git a/runtime/dex_instruction_iterator.h b/runtime/dex_instruction_iterator.h index be583a2533..eabe009a0b 100644 --- a/runtime/dex_instruction_iterator.h +++ b/runtime/dex_instruction_iterator.h @@ -19,8 +19,10 @@ #include <iterator> +#include <android-base/logging.h> + #include "dex_instruction.h" -#include "base/logging.h" +#include "base/macros.h" namespace art { diff --git a/runtime/dex_to_dex_decompiler.cc b/runtime/dex_to_dex_decompiler.cc index a5ebaded5f..a4e4fb50c5 100644 --- a/runtime/dex_to_dex_decompiler.cc +++ b/runtime/dex_to_dex_decompiler.cc @@ -16,7 +16,9 @@ #include "dex_to_dex_decompiler.h" -#include "base/logging.h" +#include <android-base/logging.h> + +#include "base/macros.h" #include "base/mutex.h" #include "bytecode_utils.h" #include "dex_file-inl.h" diff --git a/runtime/elf_file.cc b/runtime/elf_file.cc index afe4eeb059..d057ff3b1a 100644 --- a/runtime/elf_file.cc +++ b/runtime/elf_file.cc @@ -25,7 +25,6 @@ #include "android-base/strings.h" #include "arch/instruction_set.h" -#include "base/logging.h" #include "base/stl_util.h" #include "base/unix_file/fd_file.h" #include "elf_file_impl.h" diff --git a/runtime/elf_utils.h b/runtime/elf_utils.h index 418d937b12..0cac8e8d02 100644 --- a/runtime/elf_utils.h +++ b/runtime/elf_utils.h @@ -19,11 +19,11 @@ #include <sys/cdefs.h> +#include <android-base/logging.h> + // Explicitly include our own elf.h to avoid Linux and other dependencies. #include "./elf.h" -#include "base/logging.h" - namespace art { // Architecture dependent flags for the ELF header. diff --git a/runtime/entrypoints/entrypoint_utils-inl.h b/runtime/entrypoints/entrypoint_utils-inl.h index 8253739427..9e5085067c 100644 --- a/runtime/entrypoints/entrypoint_utils-inl.h +++ b/runtime/entrypoints/entrypoint_utils-inl.h @@ -245,7 +245,7 @@ inline mirror::Class* CheckArrayAlloc(dex::TypeIndex type_idx, *slow_path = true; return nullptr; // Failure } - mirror::Class* klass = method->GetDexCache()->GetResolvedType(type_idx); + ObjPtr<mirror::Class> klass = method->GetDexCache()->GetResolvedType(type_idx); if (UNLIKELY(klass == nullptr)) { // Not in dex cache so try to resolve ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); klass = class_linker->ResolveType(type_idx, method); @@ -264,7 +264,7 @@ inline mirror::Class* CheckArrayAlloc(dex::TypeIndex type_idx, return nullptr; // Failure } } - return klass; + return klass.Ptr(); } // Given the context of a calling Method, use its DexCache to resolve a type to an array Class. If @@ -349,8 +349,7 @@ inline ArtField* FindFieldFromCode(uint32_t field_idx, Handle<mirror::DexCache> h_dex_cache(hs.NewHandle(method->GetDexCache())); Handle<mirror::ClassLoader> h_class_loader(hs.NewHandle(method->GetClassLoader())); - resolved_field = class_linker->ResolveFieldJLS(*method->GetDexFile(), - field_idx, + resolved_field = class_linker->ResolveFieldJLS(field_idx, h_dex_cache, h_class_loader); } else { @@ -500,7 +499,8 @@ inline ArtMethod* FindMethodFromCode(uint32_t method_idx, Handle<mirror::Class> h_referring_class(hs2.NewHandle(referrer->GetDeclaringClass())); const dex::TypeIndex method_type_idx = referrer->GetDexFile()->GetMethodId(method_idx).class_idx_; - mirror::Class* method_reference_class = class_linker->ResolveType(method_type_idx, referrer); + ObjPtr<mirror::Class> method_reference_class = + class_linker->ResolveType(method_type_idx, referrer); if (UNLIKELY(method_reference_class == nullptr)) { // Bad type idx. CHECK(self->IsExceptionPending()); @@ -682,7 +682,7 @@ inline ArtMethod* FindMethodFast(uint32_t method_idx, } else if (type == kSuper) { // TODO This lookup is rather slow. dex::TypeIndex method_type_idx = dex_cache->GetDexFile()->GetMethodId(method_idx).class_idx_; - ObjPtr<mirror::Class> method_reference_class = ClassLinker::LookupResolvedType( + ObjPtr<mirror::Class> method_reference_class = linker->LookupResolvedType( method_type_idx, dex_cache, referrer->GetClassLoader()); if (method_reference_class == nullptr) { // Need to do full type resolution... @@ -711,13 +711,13 @@ inline ArtMethod* FindMethodFast(uint32_t method_idx, } } -inline mirror::Class* ResolveVerifyAndClinit(dex::TypeIndex type_idx, - ArtMethod* referrer, - Thread* self, - bool can_run_clinit, - bool verify_access) { +inline ObjPtr<mirror::Class> ResolveVerifyAndClinit(dex::TypeIndex type_idx, + ArtMethod* referrer, + Thread* self, + bool can_run_clinit, + bool verify_access) { ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); - mirror::Class* klass = class_linker->ResolveType(type_idx, referrer); + ObjPtr<mirror::Class> klass = class_linker->ResolveType(type_idx, referrer); if (UNLIKELY(klass == nullptr)) { CHECK(self->IsExceptionPending()); return nullptr; // Failure - Indicate to caller to deliver exception @@ -748,32 +748,31 @@ inline mirror::Class* ResolveVerifyAndClinit(dex::TypeIndex type_idx, return h_class.Get(); } -static inline mirror::String* ResolveString(ClassLinker* class_linker, - dex::StringIndex string_idx, - ArtMethod* referrer) +static inline ObjPtr<mirror::String> ResolveString(ClassLinker* class_linker, + dex::StringIndex string_idx, + ArtMethod* referrer) REQUIRES_SHARED(Locks::mutator_lock_) { Thread::PoisonObjectPointersIfDebug(); ObjPtr<mirror::String> string = referrer->GetDexCache()->GetResolvedString(string_idx); if (UNLIKELY(string == nullptr)) { StackHandleScope<1> hs(Thread::Current()); Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache())); - const DexFile& dex_file = *dex_cache->GetDexFile(); - string = class_linker->ResolveString(dex_file, string_idx, dex_cache); + string = class_linker->ResolveString(string_idx, dex_cache); } - return string.Ptr(); + return string; } -inline mirror::String* ResolveStringFromCode(ArtMethod* referrer, dex::StringIndex string_idx) { +inline ObjPtr<mirror::String> ResolveStringFromCode(ArtMethod* referrer, + dex::StringIndex string_idx) { Thread::PoisonObjectPointersIfDebug(); ObjPtr<mirror::String> string = referrer->GetDexCache()->GetResolvedString(string_idx); if (UNLIKELY(string == nullptr)) { StackHandleScope<1> hs(Thread::Current()); Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache())); - const DexFile& dex_file = *dex_cache->GetDexFile(); ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); - string = class_linker->ResolveString(dex_file, string_idx, dex_cache); + string = class_linker->ResolveString(string_idx, dex_cache); } - return string.Ptr(); + return string; } inline void UnlockJniSynchronizedMethod(jobject locked, Thread* self) { diff --git a/runtime/entrypoints/entrypoint_utils.h b/runtime/entrypoints/entrypoint_utils.h index cda70ea265..830ef84250 100644 --- a/runtime/entrypoints/entrypoint_utils.h +++ b/runtime/entrypoints/entrypoint_utils.h @@ -143,15 +143,16 @@ inline ArtMethod* FindMethodFast(uint32_t method_idx, ArtMethod* referrer) REQUIRES_SHARED(Locks::mutator_lock_); -inline mirror::Class* ResolveVerifyAndClinit(dex::TypeIndex type_idx, - ArtMethod* referrer, - Thread* self, - bool can_run_clinit, - bool verify_access) +inline ObjPtr<mirror::Class> ResolveVerifyAndClinit(dex::TypeIndex type_idx, + ArtMethod* referrer, + Thread* self, + bool can_run_clinit, + bool verify_access) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_); -inline mirror::String* ResolveStringFromCode(ArtMethod* referrer, dex::StringIndex string_idx) +inline ObjPtr<mirror::String> ResolveStringFromCode(ArtMethod* referrer, + dex::StringIndex string_idx) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_); diff --git a/runtime/entrypoints/jni/jni_entrypoints.cc b/runtime/entrypoints/jni/jni_entrypoints.cc index 7ec360a93c..780e221129 100644 --- a/runtime/entrypoints/jni/jni_entrypoints.cc +++ b/runtime/entrypoints/jni/jni_entrypoints.cc @@ -14,8 +14,9 @@ * limitations under the License. */ +#include <android-base/logging.h> + #include "art_method-inl.h" -#include "base/logging.h" #include "entrypoints/entrypoint_utils.h" #include "java_vm_ext.h" #include "mirror/object-inl.h" diff --git a/runtime/entrypoints/quick/quick_default_init_entrypoints.h b/runtime/entrypoints/quick/quick_default_init_entrypoints.h index 8acaa90053..8c90800463 100644 --- a/runtime/entrypoints/quick/quick_default_init_entrypoints.h +++ b/runtime/entrypoints/quick/quick_default_init_entrypoints.h @@ -17,7 +17,7 @@ #ifndef ART_RUNTIME_ENTRYPOINTS_QUICK_QUICK_DEFAULT_INIT_ENTRYPOINTS_H_ #define ART_RUNTIME_ENTRYPOINTS_QUICK_QUICK_DEFAULT_INIT_ENTRYPOINTS_H_ -#include "base/logging.h" +#include "base/logging.h" // FOR VLOG_IS_ON. #include "entrypoints/jni/jni_entrypoints.h" #include "entrypoints/runtime_asm_entrypoints.h" #include "quick_alloc_entrypoints.h" diff --git a/runtime/entrypoints/quick/quick_deoptimization_entrypoints.cc b/runtime/entrypoints/quick/quick_deoptimization_entrypoints.cc index 5f40711753..c782c9c949 100644 --- a/runtime/entrypoints/quick/quick_deoptimization_entrypoints.cc +++ b/runtime/entrypoints/quick/quick_deoptimization_entrypoints.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "base/logging.h" +#include "base/logging.h" // For VLOG_IS_ON. #include "base/mutex.h" #include "base/systrace.h" #include "callee_save_frame.h" diff --git a/runtime/entrypoints/quick/quick_dexcache_entrypoints.cc b/runtime/entrypoints/quick/quick_dexcache_entrypoints.cc index 238ada94ff..98378382c5 100644 --- a/runtime/entrypoints/quick/quick_dexcache_entrypoints.cc +++ b/runtime/entrypoints/quick/quick_dexcache_entrypoints.cc @@ -138,15 +138,15 @@ extern "C" mirror::Class* artInitializeStaticStorageFromCode(uint32_t type_idx, auto caller_and_outer = GetCalleeSaveMethodCallerAndOuterMethod( self, CalleeSaveType::kSaveEverythingForClinit); ArtMethod* caller = caller_and_outer.caller; - mirror::Class* result = ResolveVerifyAndClinit(dex::TypeIndex(type_idx), - caller, - self, - /* can_run_clinit */ true, - /* verify_access */ false); + ObjPtr<mirror::Class> result = ResolveVerifyAndClinit(dex::TypeIndex(type_idx), + caller, + self, + /* can_run_clinit */ true, + /* verify_access */ false); if (LIKELY(result != nullptr) && CanReferenceBss(caller_and_outer.outer_method, caller)) { StoreTypeInBss(caller_and_outer.outer_method, dex::TypeIndex(type_idx), result); } - return result; + return result.Ptr(); } extern "C" mirror::Class* artInitializeTypeFromCode(uint32_t type_idx, Thread* self) @@ -156,15 +156,15 @@ extern "C" mirror::Class* artInitializeTypeFromCode(uint32_t type_idx, Thread* s auto caller_and_outer = GetCalleeSaveMethodCallerAndOuterMethod( self, CalleeSaveType::kSaveEverythingForClinit); ArtMethod* caller = caller_and_outer.caller; - mirror::Class* result = ResolveVerifyAndClinit(dex::TypeIndex(type_idx), - caller, - self, - /* can_run_clinit */ false, - /* verify_access */ false); + ObjPtr<mirror::Class> result = ResolveVerifyAndClinit(dex::TypeIndex(type_idx), + caller, + self, + /* can_run_clinit */ false, + /* verify_access */ false); if (LIKELY(result != nullptr) && CanReferenceBss(caller_and_outer.outer_method, caller)) { StoreTypeInBss(caller_and_outer.outer_method, dex::TypeIndex(type_idx), result); } - return result; + return result.Ptr(); } extern "C" mirror::Class* artInitializeTypeAndVerifyAccessFromCode(uint32_t type_idx, Thread* self) @@ -174,13 +174,13 @@ extern "C" mirror::Class* artInitializeTypeAndVerifyAccessFromCode(uint32_t type auto caller_and_outer = GetCalleeSaveMethodCallerAndOuterMethod(self, CalleeSaveType::kSaveEverything); ArtMethod* caller = caller_and_outer.caller; - mirror::Class* result = ResolveVerifyAndClinit(dex::TypeIndex(type_idx), - caller, - self, - /* can_run_clinit */ false, - /* verify_access */ true); + ObjPtr<mirror::Class> result = ResolveVerifyAndClinit(dex::TypeIndex(type_idx), + caller, + self, + /* can_run_clinit */ false, + /* verify_access */ true); // Do not StoreTypeInBss(); access check entrypoint is never used together with .bss. - return result; + return result.Ptr(); } extern "C" mirror::String* artResolveStringFromCode(int32_t string_idx, Thread* self) @@ -189,11 +189,11 @@ extern "C" mirror::String* artResolveStringFromCode(int32_t string_idx, Thread* auto caller_and_outer = GetCalleeSaveMethodCallerAndOuterMethod(self, CalleeSaveType::kSaveEverything); ArtMethod* caller = caller_and_outer.caller; - mirror::String* result = ResolveStringFromCode(caller, dex::StringIndex(string_idx)); + ObjPtr<mirror::String> result = ResolveStringFromCode(caller, dex::StringIndex(string_idx)); if (LIKELY(result != nullptr) && CanReferenceBss(caller_and_outer.outer_method, caller)) { StoreStringInBss(caller_and_outer.outer_method, dex::StringIndex(string_idx), result); } - return result; + return result.Ptr(); } } // namespace art diff --git a/runtime/entrypoints/quick/quick_jni_entrypoints.cc b/runtime/entrypoints/quick/quick_jni_entrypoints.cc index 29a62c86ee..b13b6fbcae 100644 --- a/runtime/entrypoints/quick/quick_jni_entrypoints.cc +++ b/runtime/entrypoints/quick/quick_jni_entrypoints.cc @@ -14,9 +14,10 @@ * limitations under the License. */ +#include <android-base/logging.h> + #include "art_method-inl.h" #include "base/casts.h" -#include "base/logging.h" #include "entrypoints/entrypoint_utils-inl.h" #include "indirect_reference_table.h" #include "mirror/object-inl.h" diff --git a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc index 0a76cddf5e..ca5b79921c 100644 --- a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc +++ b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc @@ -1250,17 +1250,8 @@ extern "C" const void* artQuickResolutionTrampoline( } else { DCHECK_EQ(invoke_type, kSuper); CHECK(caller != nullptr) << invoke_type; - StackHandleScope<2> hs(self); - Handle<mirror::DexCache> dex_cache( - hs.NewHandle(caller->GetDeclaringClass()->GetDexCache())); - Handle<mirror::ClassLoader> class_loader( - hs.NewHandle(caller->GetDeclaringClass()->GetClassLoader())); - // TODO Maybe put this into a mirror::Class function. ObjPtr<mirror::Class> ref_class = linker->LookupResolvedType( - *dex_cache->GetDexFile(), - dex_cache->GetDexFile()->GetMethodId(called_method.index).class_idx_, - dex_cache.Get(), - class_loader.Get()); + caller->GetDexFile()->GetMethodId(called_method.index).class_idx_, caller); if (ref_class->IsInterface()) { called = ref_class->FindVirtualMethodForInterfaceSuper(called, kRuntimePointerSize); } else { @@ -2580,9 +2571,8 @@ extern "C" uintptr_t artInvokePolymorphic( const Instruction& inst = code->InstructionAt(dex_pc); DCHECK(inst.Opcode() == Instruction::INVOKE_POLYMORPHIC || inst.Opcode() == Instruction::INVOKE_POLYMORPHIC_RANGE); - const DexFile* dex_file = caller_method->GetDexFile(); const uint32_t proto_idx = inst.VRegH(); - const char* shorty = dex_file->GetShorty(proto_idx); + const char* shorty = caller_method->GetDexFile()->GetShorty(proto_idx); const size_t shorty_length = strlen(shorty); static const bool kMethodIsStatic = false; // invoke() and invokeExact() are not static. RememberForGcArgumentVisitor gc_visitor(sp, kMethodIsStatic, shorty, shorty_length, &soa); diff --git a/runtime/fault_handler.cc b/runtime/fault_handler.cc index 6a4e5b5f01..f66836f147 100644 --- a/runtime/fault_handler.cc +++ b/runtime/fault_handler.cc @@ -21,6 +21,7 @@ #include <sys/ucontext.h> #include "art_method-inl.h" +#include "base/logging.h" // For VLOG #include "base/safe_copy.h" #include "base/stl_util.h" #include "dex_file_types.h" diff --git a/runtime/gc/accounting/atomic_stack.h b/runtime/gc/accounting/atomic_stack.h index 3d0e8172b6..e5b5694413 100644 --- a/runtime/gc/accounting/atomic_stack.h +++ b/runtime/gc/accounting/atomic_stack.h @@ -23,8 +23,9 @@ #include <memory> #include <string> +#include <android-base/logging.h> + #include "atomic.h" -#include "base/logging.h" #include "base/macros.h" #include "mem_map.h" #include "stack_reference.h" diff --git a/runtime/gc/accounting/bitmap-inl.h b/runtime/gc/accounting/bitmap-inl.h index cd3923abbe..ca6b4794de 100644 --- a/runtime/gc/accounting/bitmap-inl.h +++ b/runtime/gc/accounting/bitmap-inl.h @@ -21,9 +21,10 @@ #include <memory> +#include <android-base/logging.h> + #include "atomic.h" #include "base/bit_utils.h" -#include "base/logging.h" namespace art { namespace gc { diff --git a/runtime/gc/accounting/card_table-inl.h b/runtime/gc/accounting/card_table-inl.h index 6ff53597e4..5f2f2dda42 100644 --- a/runtime/gc/accounting/card_table-inl.h +++ b/runtime/gc/accounting/card_table-inl.h @@ -17,10 +17,12 @@ #ifndef ART_RUNTIME_GC_ACCOUNTING_CARD_TABLE_INL_H_ #define ART_RUNTIME_GC_ACCOUNTING_CARD_TABLE_INL_H_ +#include "card_table.h" + +#include <android-base/logging.h> + #include "atomic.h" #include "base/bit_utils.h" -#include "base/logging.h" -#include "card_table.h" #include "mem_map.h" #include "space_bitmap.h" diff --git a/runtime/gc/accounting/card_table.cc b/runtime/gc/accounting/card_table.cc index 01b5896650..934e57a61b 100644 --- a/runtime/gc/accounting/card_table.cc +++ b/runtime/gc/accounting/card_table.cc @@ -18,7 +18,6 @@ #include <sys/mman.h> -#include "base/logging.h" #include "base/systrace.h" #include "card_table-inl.h" #include "gc/heap.h" diff --git a/runtime/gc/accounting/heap_bitmap.h b/runtime/gc/accounting/heap_bitmap.h index 4237e7ee3f..c997f8dbfc 100644 --- a/runtime/gc/accounting/heap_bitmap.h +++ b/runtime/gc/accounting/heap_bitmap.h @@ -17,8 +17,11 @@ #ifndef ART_RUNTIME_GC_ACCOUNTING_HEAP_BITMAP_H_ #define ART_RUNTIME_GC_ACCOUNTING_HEAP_BITMAP_H_ +#include <android-base/logging.h> + #include "base/allocator.h" -#include "base/logging.h" +#include "base/macros.h" +#include "base/mutex.h" #include "space_bitmap.h" namespace art { diff --git a/runtime/gc/accounting/mod_union_table.cc b/runtime/gc/accounting/mod_union_table.cc index 1b3d0dadae..0dd05cd6f0 100644 --- a/runtime/gc/accounting/mod_union_table.cc +++ b/runtime/gc/accounting/mod_union_table.cc @@ -18,6 +18,7 @@ #include <memory> +#include "base/logging.h" // For VLOG #include "base/stl_util.h" #include "bitmap-inl.h" #include "card_table-inl.h" diff --git a/runtime/gc/accounting/space_bitmap-inl.h b/runtime/gc/accounting/space_bitmap-inl.h index b37dd965fc..ba833693f6 100644 --- a/runtime/gc/accounting/space_bitmap-inl.h +++ b/runtime/gc/accounting/space_bitmap-inl.h @@ -21,9 +21,10 @@ #include <memory> +#include <android-base/logging.h> + #include "atomic.h" #include "base/bit_utils.h" -#include "base/logging.h" namespace art { namespace gc { diff --git a/runtime/gc/allocation_record.cc b/runtime/gc/allocation_record.cc index 2257b81e09..2ee4239e8a 100644 --- a/runtime/gc/allocation_record.cc +++ b/runtime/gc/allocation_record.cc @@ -18,6 +18,7 @@ #include "art_method-inl.h" #include "base/enums.h" +#include "base/logging.h" // For VLOG #include "base/stl_util.h" #include "obj_ptr-inl.h" #include "object_callbacks.h" diff --git a/runtime/gc/allocator/dlmalloc.cc b/runtime/gc/allocator/dlmalloc.cc index ef916f8745..65062208d6 100644 --- a/runtime/gc/allocator/dlmalloc.cc +++ b/runtime/gc/allocator/dlmalloc.cc @@ -16,8 +16,9 @@ #include "dlmalloc.h" +#include <android-base/logging.h> + #include "base/bit_utils.h" -#include "base/logging.h" // ART specific morecore implementation defined in space.cc. static void* art_heap_morecore(void* m, intptr_t increment); diff --git a/runtime/gc/allocator/rosalloc.cc b/runtime/gc/allocator/rosalloc.cc index b742ac4a7c..928abe873e 100644 --- a/runtime/gc/allocator/rosalloc.cc +++ b/runtime/gc/allocator/rosalloc.cc @@ -23,6 +23,7 @@ #include "android-base/stringprintf.h" +#include "base/logging.h" // For VLOG #include "base/memory_tool.h" #include "base/mutex-inl.h" #include "gc/space/memory_tool_settings.h" diff --git a/runtime/gc/allocator/rosalloc.h b/runtime/gc/allocator/rosalloc.h index 2c90773b8f..6e5cf0ede8 100644 --- a/runtime/gc/allocator/rosalloc.h +++ b/runtime/gc/allocator/rosalloc.h @@ -26,9 +26,10 @@ #include <unordered_set> #include <vector> +#include <android-base/logging.h> + #include "base/allocator.h" #include "base/bit_utils.h" -#include "base/logging.h" #include "base/mutex.h" #include "globals.h" #include "thread.h" diff --git a/runtime/gc/collector/garbage_collector.cc b/runtime/gc/collector/garbage_collector.cc index c5a341fc80..fa34270d95 100644 --- a/runtime/gc/collector/garbage_collector.cc +++ b/runtime/gc/collector/garbage_collector.cc @@ -22,7 +22,7 @@ #include "base/dumpable.h" #include "base/histogram-inl.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG_IS_ON. #include "base/mutex-inl.h" #include "base/systrace.h" #include "base/time_utils.h" diff --git a/runtime/gc/collector/immune_spaces.cc b/runtime/gc/collector/immune_spaces.cc index 1024050409..3b5961899f 100644 --- a/runtime/gc/collector/immune_spaces.cc +++ b/runtime/gc/collector/immune_spaces.cc @@ -19,6 +19,7 @@ #include <tuple> #include <vector> +#include "base/logging.h" // For VLOG. #include "gc/space/space-inl.h" #include "mirror/object.h" #include "oat_file.h" diff --git a/runtime/gc/collector/mark_compact.cc b/runtime/gc/collector/mark_compact.cc index aef98dee58..34cc129ce8 100644 --- a/runtime/gc/collector/mark_compact.cc +++ b/runtime/gc/collector/mark_compact.cc @@ -16,7 +16,9 @@ #include "mark_compact.h" -#include "base/logging.h" +#include <android-base/logging.h> + +#include "base/macros.h" #include "base/mutex-inl.h" #include "base/timing_logger.h" #include "gc/accounting/heap_bitmap-inl.h" diff --git a/runtime/gc/collector/mark_sweep.cc b/runtime/gc/collector/mark_sweep.cc index c6caf4b08e..fdfe949265 100644 --- a/runtime/gc/collector/mark_sweep.cc +++ b/runtime/gc/collector/mark_sweep.cc @@ -25,7 +25,7 @@ #include "base/bounded_fifo.h" #include "base/enums.h" #include "base/file_utils.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "base/macros.h" #include "base/mutex-inl.h" #include "base/systrace.h" diff --git a/runtime/gc/collector/semi_space.cc b/runtime/gc/collector/semi_space.cc index 9fb37b6138..3150781a5a 100644 --- a/runtime/gc/collector/semi_space.cc +++ b/runtime/gc/collector/semi_space.cc @@ -22,7 +22,7 @@ #include <sstream> #include <vector> -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "base/macros.h" #include "base/mutex-inl.h" #include "base/timing_logger.h" diff --git a/runtime/gc/gc_cause.cc b/runtime/gc/gc_cause.cc index 871208037a..d88fcdcc95 100644 --- a/runtime/gc/gc_cause.cc +++ b/runtime/gc/gc_cause.cc @@ -15,7 +15,10 @@ */ #include "gc_cause.h" -#include "base/logging.h" + +#include <android-base/logging.h> + +#include "base/macros.h" #include "globals.h" #include <ostream> diff --git a/runtime/gc/heap-inl.h b/runtime/gc/heap-inl.h index 2047646413..52dd104ac8 100644 --- a/runtime/gc/heap-inl.h +++ b/runtime/gc/heap-inl.h @@ -401,8 +401,7 @@ inline bool Heap::IsOutOfMemoryOnAllocation(AllocatorType allocator_type, return true; } // TODO: Grow for allocation is racy, fix it. - VLOG(heap) << "Growing heap from " << PrettySize(max_allowed_footprint_) << " to " - << PrettySize(new_footprint) << " for a " << PrettySize(alloc_size) << " allocation"; + VlogHeapGrowth(max_allowed_footprint_, new_footprint, alloc_size); max_allowed_footprint_ = new_footprint; } } diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc index f29ae92e2d..f7be4c8d5a 100644 --- a/runtime/gc/heap.cc +++ b/runtime/gc/heap.cc @@ -30,6 +30,7 @@ #include "base/dumpable.h" #include "base/file_utils.h" #include "base/histogram-inl.h" +#include "base/logging.h" // For VLOG. #include "base/memory_tool.h" #include "base/stl_util.h" #include "base/systrace.h" @@ -799,12 +800,11 @@ void Heap::IncrementDisableThreadFlip(Thread* self) { bool has_waited = false; uint64_t wait_start = NanoTime(); if (thread_flip_running_) { - ATRACE_BEGIN("IncrementDisableThreadFlip"); + ScopedTrace trace("IncrementDisableThreadFlip"); while (thread_flip_running_) { has_waited = true; thread_flip_cond_->Wait(self); } - ATRACE_END(); } ++disable_thread_flip_count_; if (has_waited) { @@ -4156,5 +4156,10 @@ const Verification* Heap::GetVerification() const { return verification_.get(); } +void Heap::VlogHeapGrowth(size_t max_allowed_footprint, size_t new_footprint, size_t alloc_size) { + VLOG(heap) << "Growing heap from " << PrettySize(max_allowed_footprint) << " to " + << PrettySize(new_footprint) << " for a " << PrettySize(alloc_size) << " allocation"; +} + } // namespace gc } // namespace art diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h index ac0d82e12a..0d11658e01 100644 --- a/runtime/gc/heap.h +++ b/runtime/gc/heap.h @@ -22,11 +22,14 @@ #include <unordered_set> #include <vector> +#include <android-base/logging.h> + #include "allocator_type.h" #include "arch/instruction_set.h" #include "atomic.h" -#include "base/logging.h" +#include "base/macros.h" #include "base/mutex.h" +#include "base/runtime_debug.h" #include "base/time_utils.h" #include "gc/collector/gc_type.h" #include "gc/collector/iteration.h" @@ -1096,6 +1099,9 @@ class Heap { void TraceHeapSize(size_t heap_size); + // Remove a vlog code from heap-inl.h which is transitively included in half the world. + static void VlogHeapGrowth(size_t max_allowed_footprint, size_t new_footprint, size_t alloc_size); + // All-known continuous spaces, where objects lie within fixed bounds. std::vector<space::ContinuousSpace*> continuous_spaces_ GUARDED_BY(Locks::mutator_lock_); diff --git a/runtime/gc/space/dlmalloc_space.cc b/runtime/gc/space/dlmalloc_space.cc index 576a35c52d..a3eef90e3a 100644 --- a/runtime/gc/space/dlmalloc_space.cc +++ b/runtime/gc/space/dlmalloc_space.cc @@ -16,6 +16,7 @@ #include "dlmalloc_space-inl.h" +#include "base/logging.h" // For VLOG. #include "base/time_utils.h" #include "gc/accounting/card_table.h" #include "gc/accounting/space_bitmap-inl.h" diff --git a/runtime/gc/space/image_space_fs.h b/runtime/gc/space/image_space_fs.h index a0ecb95ac7..6ce81e9209 100644 --- a/runtime/gc/space/image_space_fs.h +++ b/runtime/gc/space/image_space_fs.h @@ -23,7 +23,7 @@ #include "android-base/stringprintf.h" #include "base/file_utils.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "base/macros.h" #include "base/unix_file/fd_file.h" #include "globals.h" diff --git a/runtime/gc/space/large_object_space.cc b/runtime/gc/space/large_object_space.cc index 45f4f82448..d2efb102e9 100644 --- a/runtime/gc/space/large_object_space.cc +++ b/runtime/gc/space/large_object_space.cc @@ -20,7 +20,9 @@ #include <memory> -#include "base/logging.h" +#include <android-base/logging.h> + +#include "base/macros.h" #include "base/memory_tool.h" #include "base/mutex-inl.h" #include "base/stl_util.h" diff --git a/runtime/gc/space/malloc_space.cc b/runtime/gc/space/malloc_space.cc index dcb783782f..17274b508d 100644 --- a/runtime/gc/space/malloc_space.cc +++ b/runtime/gc/space/malloc_space.cc @@ -18,6 +18,7 @@ #include "android-base/stringprintf.h" +#include "base/logging.h" // For VLOG #include "gc/accounting/card_table-inl.h" #include "gc/accounting/space_bitmap-inl.h" #include "gc/heap.h" diff --git a/runtime/gc/space/rosalloc_space.cc b/runtime/gc/space/rosalloc_space.cc index 5d1f191e4d..3a685cb82d 100644 --- a/runtime/gc/space/rosalloc_space.cc +++ b/runtime/gc/space/rosalloc_space.cc @@ -17,6 +17,7 @@ #include "rosalloc_space-inl.h" +#include "base/logging.h" // For VLOG. #include "base/time_utils.h" #include "gc/accounting/card_table.h" #include "gc/accounting/space_bitmap-inl.h" diff --git a/runtime/gc/space/space.cc b/runtime/gc/space/space.cc index 74ce273abf..2c6afa7eb8 100644 --- a/runtime/gc/space/space.cc +++ b/runtime/gc/space/space.cc @@ -16,7 +16,9 @@ #include "space.h" -#include "base/logging.h" +#include <android-base/logging.h> + +#include "base/macros.h" #include "gc/accounting/heap_bitmap.h" #include "gc/accounting/space_bitmap-inl.h" #include "gc/heap.h" diff --git a/runtime/gc/verification.cc b/runtime/gc/verification.cc index 3cd04a61e9..d99b37762f 100644 --- a/runtime/gc/verification.cc +++ b/runtime/gc/verification.cc @@ -86,7 +86,7 @@ void Verification::LogHeapCorruption(ObjPtr<mirror::Object> holder, mirror::Object* ref, bool fatal) const { // Lowest priority logging first: - PrintFileToLog("/proc/self/maps", LogSeverity::FATAL_WITHOUT_ABORT); + PrintFileToLog("/proc/self/maps", android::base::LogSeverity::FATAL_WITHOUT_ABORT); MemMap::DumpMaps(LOG_STREAM(FATAL_WITHOUT_ABORT), true); // Buffer the output in the string stream since it is more important than the stack traces // and we want it to have log priority. The stack traces are printed from Runtime::Abort diff --git a/runtime/handle.h b/runtime/handle.h index ccff575495..18e503d1de 100644 --- a/runtime/handle.h +++ b/runtime/handle.h @@ -17,8 +17,9 @@ #ifndef ART_RUNTIME_HANDLE_H_ #define ART_RUNTIME_HANDLE_H_ +#include <android-base/logging.h> + #include "base/casts.h" -#include "base/logging.h" #include "base/macros.h" #include "base/mutex.h" #include "base/value_object.h" diff --git a/runtime/handle_scope.h b/runtime/handle_scope.h index f248a118e9..28a230291d 100644 --- a/runtime/handle_scope.h +++ b/runtime/handle_scope.h @@ -19,8 +19,9 @@ #include <stack> +#include <android-base/logging.h> + #include "base/enums.h" -#include "base/logging.h" #include "base/macros.h" #include "base/mutex.h" #include "handle.h" diff --git a/runtime/hprof/hprof.cc b/runtime/hprof/hprof.cc index 6a1a8c7271..f4fc85b8e5 100644 --- a/runtime/hprof/hprof.cc +++ b/runtime/hprof/hprof.cc @@ -36,11 +36,13 @@ #include <set> -#include "android-base/stringprintf.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> #include "art_field-inl.h" #include "art_method-inl.h" -#include "base/logging.h" +#include "base/macros.h" +#include "base/mutex.h" #include "base/time_utils.h" #include "base/unix_file/fd_file.h" #include "class_linker.h" diff --git a/runtime/indenter.h b/runtime/indenter.h index 69b973252d..6361dd2092 100644 --- a/runtime/indenter.h +++ b/runtime/indenter.h @@ -20,7 +20,8 @@ #include <ostream> #include <streambuf> -#include "base/logging.h" +#include <android-base/logging.h> + #include "base/macros.h" namespace art { diff --git a/runtime/index_bss_mapping.h b/runtime/index_bss_mapping.h index d9f4e663a7..dcbc05c195 100644 --- a/runtime/index_bss_mapping.h +++ b/runtime/index_bss_mapping.h @@ -17,8 +17,9 @@ #ifndef ART_RUNTIME_INDEX_BSS_MAPPING_H_ #define ART_RUNTIME_INDEX_BSS_MAPPING_H_ +#include <android-base/logging.h> + #include "base/bit_utils.h" -#include "base/logging.h" namespace art { diff --git a/runtime/indirect_reference_table.h b/runtime/indirect_reference_table.h index 6675099523..00184e2ed0 100644 --- a/runtime/indirect_reference_table.h +++ b/runtime/indirect_reference_table.h @@ -23,8 +23,10 @@ #include <limits> #include <string> +#include <android-base/logging.h> + #include "base/bit_utils.h" -#include "base/logging.h" +#include "base/macros.h" #include "base/mutex.h" #include "gc_root.h" #include "obj_ptr.h" diff --git a/runtime/interpreter/interpreter_common.cc b/runtime/interpreter/interpreter_common.cc index d2d017e118..122d1a816b 100644 --- a/runtime/interpreter/interpreter_common.cc +++ b/runtime/interpreter/interpreter_common.cc @@ -1062,7 +1062,7 @@ static ObjPtr<mirror::CallSite> InvokeBootstrapMethod(Thread* self, // The second parameter is the name to lookup. { dex::StringIndex name_idx(static_cast<uint32_t>(it.GetJavaValue().i)); - ObjPtr<mirror::String> name = class_linker->ResolveString(*dex_file, name_idx, dex_cache); + ObjPtr<mirror::String> name = class_linker->ResolveString(name_idx, dex_cache); if (name.IsNull()) { DCHECK(self->IsExceptionPending()); return nullptr; @@ -1073,12 +1073,8 @@ static ObjPtr<mirror::CallSite> InvokeBootstrapMethod(Thread* self, // The third parameter is the method type associated with the name. uint32_t method_type_idx = static_cast<uint32_t>(it.GetJavaValue().i); - Handle<mirror::MethodType> - method_type(hs.NewHandle(class_linker->ResolveMethodType(self, - *dex_file, - method_type_idx, - dex_cache, - class_loader))); + Handle<mirror::MethodType> method_type(hs.NewHandle( + class_linker->ResolveMethodType(self, method_type_idx, dex_cache, class_loader))); if (method_type.IsNull()) { DCHECK(self->IsExceptionPending()); return nullptr; @@ -1113,7 +1109,7 @@ static ObjPtr<mirror::CallSite> InvokeBootstrapMethod(Thread* self, case EncodedArrayValueIterator::ValueType::kMethodType: { uint32_t idx = static_cast<uint32_t>(jvalue.i); ObjPtr<mirror::MethodType> ref = - class_linker->ResolveMethodType(self, *dex_file, idx, dex_cache, class_loader); + class_linker->ResolveMethodType(self, idx, dex_cache, class_loader); if (ref.IsNull()) { DCHECK(self->IsExceptionPending()); return nullptr; @@ -1136,7 +1132,7 @@ static ObjPtr<mirror::CallSite> InvokeBootstrapMethod(Thread* self, } case EncodedArrayValueIterator::ValueType::kString: { dex::StringIndex idx(static_cast<uint32_t>(jvalue.i)); - ObjPtr<mirror::String> ref = class_linker->ResolveString(*dex_file, idx, dex_cache); + ObjPtr<mirror::String> ref = class_linker->ResolveString(idx, dex_cache); if (ref.IsNull()) { DCHECK(self->IsExceptionPending()); return nullptr; @@ -1147,8 +1143,7 @@ static ObjPtr<mirror::CallSite> InvokeBootstrapMethod(Thread* self, } case EncodedArrayValueIterator::ValueType::kType: { dex::TypeIndex idx(static_cast<uint32_t>(jvalue.i)); - ObjPtr<mirror::Class> ref = - class_linker->ResolveType(*dex_file, idx, dex_cache, class_loader); + ObjPtr<mirror::Class> ref = class_linker->ResolveType(idx, dex_cache, class_loader); if (ref.IsNull()) { DCHECK(self->IsExceptionPending()); return nullptr; diff --git a/runtime/interpreter/interpreter_common.h b/runtime/interpreter/interpreter_common.h index f097bc71b9..269b013caf 100644 --- a/runtime/interpreter/interpreter_common.h +++ b/runtime/interpreter/interpreter_common.h @@ -26,13 +26,14 @@ #include <iostream> #include <sstream> -#include "android-base/stringprintf.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> #include "art_field-inl.h" #include "art_method-inl.h" #include "base/enums.h" -#include "base/logging.h" #include "base/macros.h" +#include "base/mutex.h" #include "class_linker-inl.h" #include "common_dex_operations.h" #include "common_throws.h" @@ -206,17 +207,17 @@ static inline bool DoInvoke(Thread* self, } } -static inline mirror::MethodHandle* ResolveMethodHandle(Thread* self, - uint32_t method_handle_index, - ArtMethod* referrer) +static inline ObjPtr<mirror::MethodHandle> ResolveMethodHandle(Thread* self, + uint32_t method_handle_index, + ArtMethod* referrer) REQUIRES_SHARED(Locks::mutator_lock_) { ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); return class_linker->ResolveMethodHandle(self, method_handle_index, referrer); } -static inline mirror::MethodType* ResolveMethodType(Thread* self, - uint32_t method_type_index, - ArtMethod* referrer) +static inline ObjPtr<mirror::MethodType> ResolveMethodType(Thread* self, + uint32_t method_type_index, + ArtMethod* referrer) REQUIRES_SHARED(Locks::mutator_lock_) { ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); return class_linker->ResolveMethodType(self, method_type_index, referrer); @@ -348,9 +349,7 @@ static inline ObjPtr<mirror::String> ResolveString(Thread* self, if (UNLIKELY(string_ptr == nullptr)) { StackHandleScope<1> hs(self); Handle<mirror::DexCache> dex_cache(hs.NewHandle(method->GetDexCache())); - string_ptr = Runtime::Current()->GetClassLinker()->ResolveString(*dex_cache->GetDexFile(), - string_idx, - dex_cache); + string_ptr = Runtime::Current()->GetClassLinker()->ResolveString(string_idx, dex_cache); } return string_ptr; } diff --git a/runtime/interpreter/mterp/mterp.cc b/runtime/interpreter/mterp/mterp.cc index 987298bd8a..9c7645af9e 100644 --- a/runtime/interpreter/mterp/mterp.cc +++ b/runtime/interpreter/mterp/mterp.cc @@ -376,15 +376,15 @@ extern "C" size_t MterpConstClass(uint32_t index, ShadowFrame* shadow_frame, Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) { - mirror::Class* c = ResolveVerifyAndClinit(dex::TypeIndex(index), - shadow_frame->GetMethod(), - self, - false, - false); + ObjPtr<mirror::Class> c = ResolveVerifyAndClinit(dex::TypeIndex(index), + shadow_frame->GetMethod(), + self, + /* can_run_clinit */ false, + /* verify_access */ false); if (UNLIKELY(c == nullptr)) { return true; } - shadow_frame->SetVRegReference(tgt_vreg, c); + shadow_frame->SetVRegReference(tgt_vreg, c.Ptr()); return false; } @@ -463,17 +463,17 @@ extern "C" size_t MterpNewInstance(ShadowFrame* shadow_frame, Thread* self, uint REQUIRES_SHARED(Locks::mutator_lock_) { const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr()); mirror::Object* obj = nullptr; - mirror::Class* c = ResolveVerifyAndClinit(dex::TypeIndex(inst->VRegB_21c()), - shadow_frame->GetMethod(), - self, - false, - false); + ObjPtr<mirror::Class> c = ResolveVerifyAndClinit(dex::TypeIndex(inst->VRegB_21c()), + shadow_frame->GetMethod(), + self, + /* can_run_clinit */ false, + /* verify_access */ false); if (LIKELY(c != nullptr)) { if (UNLIKELY(c->IsStringClass())) { gc::AllocatorType allocator_type = Runtime::Current()->GetHeap()->GetCurrentAllocator(); obj = mirror::String::AllocEmptyString<true>(self, allocator_type); } else { - obj = AllocObjectFromCode<true>(c, + obj = AllocObjectFromCode<true>(c.Ptr(), self, Runtime::Current()->GetHeap()->GetCurrentAllocator()); } diff --git a/runtime/interpreter/unstarted_runtime.cc b/runtime/interpreter/unstarted_runtime.cc index 31e7986770..dece830f1a 100644 --- a/runtime/interpreter/unstarted_runtime.cc +++ b/runtime/interpreter/unstarted_runtime.cc @@ -26,12 +26,12 @@ #include <locale> #include <unordered_map> -#include "android-base/stringprintf.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> #include "art_method-inl.h" #include "base/casts.h" #include "base/enums.h" -#include "base/logging.h" #include "base/macros.h" #include "class_linker.h" #include "common_throws.h" diff --git a/runtime/jdwp/jdwp.h b/runtime/jdwp/jdwp.h index aeeda1e791..d712b10bc2 100644 --- a/runtime/jdwp/jdwp.h +++ b/runtime/jdwp/jdwp.h @@ -18,6 +18,7 @@ #define ART_RUNTIME_JDWP_JDWP_H_ #include "atomic.h" +#include "base/logging.h" // For VLOG. #include "base/mutex.h" #include "jdwp/jdwp_bits.h" #include "jdwp/jdwp_constants.h" diff --git a/runtime/jdwp/jdwp_adb.cc b/runtime/jdwp/jdwp_adb.cc index ede4f9edb7..d68430f3ac 100644 --- a/runtime/jdwp/jdwp_adb.cc +++ b/runtime/jdwp/jdwp_adb.cc @@ -22,7 +22,7 @@ #include "android-base/stringprintf.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "jdwp/jdwp_priv.h" #include "thread-current-inl.h" diff --git a/runtime/jdwp/jdwp_event.cc b/runtime/jdwp/jdwp_event.cc index 41cb64276c..9409b7661f 100644 --- a/runtime/jdwp/jdwp_event.cc +++ b/runtime/jdwp/jdwp_event.cc @@ -25,7 +25,7 @@ #include "art_field-inl.h" #include "art_method-inl.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "debugger.h" #include "jdwp/jdwp_constants.h" #include "jdwp/jdwp_expand_buf.h" diff --git a/runtime/jdwp/jdwp_expand_buf.cc b/runtime/jdwp/jdwp_expand_buf.cc index f0b8c918dc..4b4ca0e4a3 100644 --- a/runtime/jdwp/jdwp_expand_buf.cc +++ b/runtime/jdwp/jdwp_expand_buf.cc @@ -23,7 +23,8 @@ #include <stdlib.h> #include <string.h> -#include "base/logging.h" +#include <android-base/logging.h> + #include "jdwp/jdwp.h" #include "jdwp/jdwp_bits.h" diff --git a/runtime/jdwp/jdwp_handler.cc b/runtime/jdwp/jdwp_handler.cc index 618332b7ef..89eef88b88 100644 --- a/runtime/jdwp/jdwp_handler.cc +++ b/runtime/jdwp/jdwp_handler.cc @@ -24,7 +24,7 @@ #include "atomic.h" #include "base/hex_dump.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "base/macros.h" #include "debugger.h" #include "jdwp/jdwp_constants.h" diff --git a/runtime/jdwp/jdwp_main.cc b/runtime/jdwp/jdwp_main.cc index e6c60685cc..e275554721 100644 --- a/runtime/jdwp/jdwp_main.cc +++ b/runtime/jdwp/jdwp_main.cc @@ -23,7 +23,7 @@ #include "android-base/stringprintf.h" #include "atomic.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "base/time_utils.h" #include "debugger.h" #include "jdwp/jdwp_priv.h" diff --git a/runtime/jdwp/jdwp_socket.cc b/runtime/jdwp/jdwp_socket.cc index 97662f0727..673a942517 100644 --- a/runtime/jdwp/jdwp_socket.cc +++ b/runtime/jdwp/jdwp_socket.cc @@ -28,7 +28,7 @@ #include "android-base/stringprintf.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "jdwp/jdwp_priv.h" namespace art { diff --git a/runtime/jit/debugger_interface.cc b/runtime/jit/debugger_interface.cc index 135d9b1f51..4d1c85a1c2 100644 --- a/runtime/jit/debugger_interface.cc +++ b/runtime/jit/debugger_interface.cc @@ -16,7 +16,8 @@ #include "debugger_interface.h" -#include "base/logging.h" +#include <android-base/logging.h> + #include "base/mutex.h" #include "thread-current-inl.h" #include "thread.h" diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc index 0d95bc6e64..783d05df34 100644 --- a/runtime/jit/jit.cc +++ b/runtime/jit/jit.cc @@ -20,8 +20,9 @@ #include "art_method-inl.h" #include "base/enums.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "base/memory_tool.h" +#include "base/runtime_debug.h" #include "debugger.h" #include "entrypoints/runtime_asm_entrypoints.h" #include "interpreter/interpreter.h" diff --git a/runtime/jit/jit_code_cache.cc b/runtime/jit/jit_code_cache.cc index a5c167eee8..6f03a688e6 100644 --- a/runtime/jit/jit_code_cache.cc +++ b/runtime/jit/jit_code_cache.cc @@ -21,6 +21,7 @@ #include "arch/context.h" #include "art_method-inl.h" #include "base/enums.h" +#include "base/logging.h" // For VLOG. #include "base/stl_util.h" #include "base/systrace.h" #include "base/time_utils.h" diff --git a/runtime/jit/profile_compilation_info.cc b/runtime/jit/profile_compilation_info.cc index bb0048de0b..7754777eb6 100644 --- a/runtime/jit/profile_compilation_info.cc +++ b/runtime/jit/profile_compilation_info.cc @@ -35,6 +35,7 @@ #include "base/arena_allocator.h" #include "base/dumpable.h" #include "base/file_utils.h" +#include "base/logging.h" // For VLOG. #include "base/mutex.h" #include "base/scoped_flock.h" #include "base/stl_util.h" diff --git a/runtime/jit/profile_saver.cc b/runtime/jit/profile_saver.cc index acbc6e63a4..ee11cfddb0 100644 --- a/runtime/jit/profile_saver.cc +++ b/runtime/jit/profile_saver.cc @@ -25,6 +25,7 @@ #include "art_method-inl.h" #include "base/enums.h" +#include "base/logging.h" // For VLOG. #include "base/scoped_arena_containers.h" #include "base/stl_util.h" #include "base/systrace.h" diff --git a/runtime/jni_internal.cc b/runtime/jni_internal.cc index 1e55158a34..48fc5f730b 100644 --- a/runtime/jni_internal.cc +++ b/runtime/jni_internal.cc @@ -28,7 +28,7 @@ #include "atomic.h" #include "base/allocator.h" #include "base/enums.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "base/mutex.h" #include "base/stl_util.h" #include "class_linker-inl.h" diff --git a/runtime/leb128.h b/runtime/leb128.h index 31459af3a0..2bfed7f539 100644 --- a/runtime/leb128.h +++ b/runtime/leb128.h @@ -19,8 +19,10 @@ #include <vector> +#include <android-base/logging.h> + #include "base/bit_utils.h" -#include "base/logging.h" +#include "base/macros.h" #include "globals.h" namespace art { diff --git a/runtime/lock_word.h b/runtime/lock_word.h index b9aa0b793b..fac1a7597d 100644 --- a/runtime/lock_word.h +++ b/runtime/lock_word.h @@ -20,8 +20,9 @@ #include <cstdint> #include <iosfwd> +#include <android-base/logging.h> + #include "base/bit_utils.h" -#include "base/logging.h" #include "read_barrier.h" namespace art { diff --git a/runtime/managed_stack.h b/runtime/managed_stack.h index 07078ecb13..d1c230fd8f 100644 --- a/runtime/managed_stack.h +++ b/runtime/managed_stack.h @@ -21,7 +21,8 @@ #include <cstring> #include <string> -#include "base/logging.h" +#include <android-base/logging.h> + #include "base/macros.h" #include "base/mutex.h" #include "base/bit_utils.h" diff --git a/runtime/mem_map.cc b/runtime/mem_map.cc index f5d12d5f7b..8abf8a6003 100644 --- a/runtime/mem_map.cc +++ b/runtime/mem_map.cc @@ -35,6 +35,7 @@ #include "base/allocator.h" #include "base/bit_utils.h" #include "base/file_utils.h" +#include "base/logging.h" // For VLOG_IS_ON. #include "base/memory_tool.h" #include "globals.h" #include "utils.h" diff --git a/runtime/memory_region.cc b/runtime/memory_region.cc index 13cc5c99bc..862ff73639 100644 --- a/runtime/memory_region.cc +++ b/runtime/memory_region.cc @@ -19,9 +19,6 @@ #include <stdint.h> #include <string.h> -#include "base/logging.h" -#include "globals.h" - namespace art { void MemoryRegion::CopyFrom(size_t offset, const MemoryRegion& from) const { diff --git a/runtime/memory_region.h b/runtime/memory_region.h index 7cf5d49d70..23e0aecbda 100644 --- a/runtime/memory_region.h +++ b/runtime/memory_region.h @@ -20,10 +20,11 @@ #include <stdint.h> #include <type_traits> +#include <android-base/logging.h> + #include "arch/instruction_set.h" #include "base/bit_utils.h" #include "base/casts.h" -#include "base/logging.h" #include "base/macros.h" #include "base/value_object.h" #include "globals.h" diff --git a/runtime/method_info.h b/runtime/method_info.h index 5a72125be4..6485af992d 100644 --- a/runtime/method_info.h +++ b/runtime/method_info.h @@ -17,7 +17,9 @@ #ifndef ART_RUNTIME_METHOD_INFO_H_ #define ART_RUNTIME_METHOD_INFO_H_ -#include "base/logging.h" +#include <android-base/logging.h> + +#include "base/macros.h" #include "leb128.h" #include "memory_region.h" diff --git a/runtime/mirror/array-inl.h b/runtime/mirror/array-inl.h index 22812454d1..636c84c759 100644 --- a/runtime/mirror/array-inl.h +++ b/runtime/mirror/array-inl.h @@ -19,11 +19,11 @@ #include "array.h" -#include "android-base/stringprintf.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> #include "base/bit_utils.h" #include "base/casts.h" -#include "base/logging.h" #include "class.h" #include "gc/heap-inl.h" #include "obj_ptr-inl.h" diff --git a/runtime/mirror/class-inl.h b/runtime/mirror/class-inl.h index eb54f7fb1f..b4f5d81067 100644 --- a/runtime/mirror/class-inl.h +++ b/runtime/mirror/class-inl.h @@ -440,7 +440,6 @@ inline bool Class::ResolvedFieldAccessTest(ObjPtr<Class> access_to, // cache. Use LookupResolveType here to search the class table if it is not in the dex cache. // should be no thread suspension due to the class being resolved. ObjPtr<Class> dex_access_to = Runtime::Current()->GetClassLinker()->LookupResolvedType( - *dex_cache->GetDexFile(), class_idx, dex_cache, access_to->GetClassLoader()); @@ -477,7 +476,6 @@ inline bool Class::ResolvedMethodAccessTest(ObjPtr<Class> access_to, // The referenced class has already been resolved with the method, but may not be in the dex // cache. ObjPtr<Class> dex_access_to = Runtime::Current()->GetClassLinker()->LookupResolvedType( - *dex_cache->GetDexFile(), class_idx, dex_cache, access_to->GetClassLoader()); diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc index 892c03912a..e0a341da67 100644 --- a/runtime/mirror/class.cc +++ b/runtime/mirror/class.cc @@ -20,6 +20,7 @@ #include "art_field-inl.h" #include "art_method-inl.h" +#include "base/logging.h" // For VLOG. #include "class-inl.h" #include "class_ext.h" #include "class_linker-inl.h" @@ -1034,7 +1035,7 @@ ObjPtr<Class> Class::GetDirectInterface(Thread* self, ObjPtr<Class> klass, uint3 return interfaces->Get(idx); } else { dex::TypeIndex type_idx = klass->GetDirectInterfaceTypeIdx(idx); - ObjPtr<Class> interface = ClassLinker::LookupResolvedType( + ObjPtr<Class> interface = Runtime::Current()->GetClassLinker()->LookupResolvedType( type_idx, klass->GetDexCache(), klass->GetClassLoader()); return interface; } @@ -1046,9 +1047,7 @@ ObjPtr<Class> Class::ResolveDirectInterface(Thread* self, Handle<Class> klass, u DCHECK(!klass->IsArrayClass()); DCHECK(!klass->IsProxyClass()); dex::TypeIndex type_idx = klass->GetDirectInterfaceTypeIdx(idx); - interface = Runtime::Current()->GetClassLinker()->ResolveType(klass->GetDexFile(), - type_idx, - klass.Get()); + interface = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, klass.Get()); CHECK(interface != nullptr || self->IsExceptionPending()); } return interface; diff --git a/runtime/mirror/dex_cache-inl.h b/runtime/mirror/dex_cache-inl.h index 8b11c1290d..8d4d44b6f9 100644 --- a/runtime/mirror/dex_cache-inl.h +++ b/runtime/mirror/dex_cache-inl.h @@ -19,11 +19,12 @@ #include "dex_cache.h" +#include <android-base/logging.h> + #include "art_field.h" #include "art_method.h" #include "base/casts.h" #include "base/enums.h" -#include "base/logging.h" #include "class_linker.h" #include "dex_file.h" #include "gc/heap-inl.h" diff --git a/runtime/mirror/dex_cache.cc b/runtime/mirror/dex_cache.cc index 2f63dff3be..eb4db00ccd 100644 --- a/runtime/mirror/dex_cache.cc +++ b/runtime/mirror/dex_cache.cc @@ -17,7 +17,6 @@ #include "dex_cache-inl.h" #include "art_method-inl.h" -#include "base/logging.h" #include "class_linker.h" #include "gc/accounting/card_table-inl.h" #include "gc/heap.h" diff --git a/runtime/mirror/dex_cache.h b/runtime/mirror/dex_cache.h index f75786b521..509db0292e 100644 --- a/runtime/mirror/dex_cache.h +++ b/runtime/mirror/dex_cache.h @@ -19,6 +19,7 @@ #include "array.h" #include "base/bit_utils.h" +#include "base/mutex.h" #include "dex_file_types.h" #include "object.h" #include "object_array.h" diff --git a/runtime/mirror/dex_cache_test.cc b/runtime/mirror/dex_cache_test.cc index 8198636b3d..d2bff2c19a 100644 --- a/runtime/mirror/dex_cache_test.cc +++ b/runtime/mirror/dex_cache_test.cc @@ -150,13 +150,11 @@ TEST_F(DexCacheMethodHandlesTest, TestResolvedMethodTypes) { const DexFile::MethodId& method2_id = dex_file.GetMethodId(method2->GetDexMethodIndex()); Handle<mirror::MethodType> method1_type = hs.NewHandle( class_linker_->ResolveMethodType(soa.Self(), - dex_file, method1_id.proto_idx_, dex_cache, class_loader)); Handle<mirror::MethodType> method2_type = hs.NewHandle( class_linker_->ResolveMethodType(soa.Self(), - dex_file, method2_id.proto_idx_, dex_cache, class_loader)); diff --git a/runtime/mirror/object.cc b/runtime/mirror/object.cc index 87cc620309..97fb793530 100644 --- a/runtime/mirror/object.cc +++ b/runtime/mirror/object.cc @@ -240,7 +240,7 @@ void Object::CheckFieldAssignmentImpl(MemberOffset field_offset, ObjPtr<Object> CHECK_NE(field.GetTypeAsPrimitiveType(), Primitive::kPrimNot); // TODO: resolve the field type for moving GC. ObjPtr<mirror::Class> field_type = - kMovingCollector ? field.LookupType() : field.ResolveType(); + kMovingCollector ? field.LookupResolvedType() : field.ResolveType(); if (field_type != nullptr) { CHECK(field_type->IsAssignableFrom(new_value->GetClass())); } @@ -258,7 +258,7 @@ void Object::CheckFieldAssignmentImpl(MemberOffset field_offset, ObjPtr<Object> CHECK_NE(field.GetTypeAsPrimitiveType(), Primitive::kPrimNot); // TODO: resolve the field type for moving GC. ObjPtr<mirror::Class> field_type = - kMovingCollector ? field.LookupType() : field.ResolveType(); + kMovingCollector ? field.LookupResolvedType() : field.ResolveType(); if (field_type != nullptr) { CHECK(field_type->IsAssignableFrom(new_value->GetClass())); } diff --git a/runtime/monitor.cc b/runtime/monitor.cc index d5520d9aca..12529058e2 100644 --- a/runtime/monitor.cc +++ b/runtime/monitor.cc @@ -21,6 +21,7 @@ #include "android-base/stringprintf.h" #include "art_method-inl.h" +#include "base/logging.h" // For VLOG. #include "base/mutex.h" #include "base/stl_util.h" #include "base/systrace.h" diff --git a/runtime/monitor_pool.cc b/runtime/monitor_pool.cc index d00f979379..cf5934b6a0 100644 --- a/runtime/monitor_pool.cc +++ b/runtime/monitor_pool.cc @@ -16,7 +16,7 @@ #include "monitor_pool.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "base/mutex-inl.h" #include "monitor.h" #include "thread-current-inl.h" diff --git a/runtime/native/dalvik_system_VMRuntime.cc b/runtime/native/dalvik_system_VMRuntime.cc index 2d1f886896..1b5c535c87 100644 --- a/runtime/native/dalvik_system_VMRuntime.cc +++ b/runtime/native/dalvik_system_VMRuntime.cc @@ -375,8 +375,8 @@ static void PreloadDexCachesResolveField(ObjPtr<mirror::DexCache> dex_cache, } const DexFile* dex_file = dex_cache->GetDexFile(); const DexFile::FieldId& field_id = dex_file->GetFieldId(field_idx); - ObjPtr<mirror::Class> klass = - ClassLinker::LookupResolvedType(field_id.class_idx_, dex_cache, nullptr); + ObjPtr<mirror::Class> klass = Runtime::Current()->GetClassLinker()->LookupResolvedType( + field_id.class_idx_, dex_cache, /* class_loader */ nullptr); if (klass == nullptr) { return; } @@ -401,8 +401,8 @@ static void PreloadDexCachesResolveMethod(ObjPtr<mirror::DexCache> dex_cache, ui } const DexFile* dex_file = dex_cache->GetDexFile(); const DexFile::MethodId& method_id = dex_file->GetMethodId(method_idx); - ObjPtr<mirror::Class> klass = - ClassLinker::LookupResolvedType(method_id.class_idx_, dex_cache, nullptr); + ObjPtr<mirror::Class> klass = Runtime::Current()->GetClassLinker()->LookupResolvedType( + method_id.class_idx_, dex_cache, /* class_loader */ nullptr); if (klass == nullptr) { return; } diff --git a/runtime/native/dalvik_system_ZygoteHooks.cc b/runtime/native/dalvik_system_ZygoteHooks.cc index a7bee39a81..fd80aaeaf7 100644 --- a/runtime/native/dalvik_system_ZygoteHooks.cc +++ b/runtime/native/dalvik_system_ZygoteHooks.cc @@ -18,11 +18,14 @@ #include <stdlib.h> -#include "android-base/stringprintf.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> #include "arch/instruction_set.h" #include "art_method-inl.h" -#include "base/logging.h" +#include "base/macros.h" +#include "base/mutex.h" +#include "base/runtime_debug.h" #include "debugger.h" #include "java_vm_ext.h" #include "jit/jit.h" diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc index 9359ffc7fd..da5cee1ddc 100644 --- a/runtime/native/java_lang_Class.cc +++ b/runtime/native/java_lang_Class.cc @@ -146,11 +146,11 @@ static jobjectArray Class_getInterfacesInternal(JNIEnv* env, jobject javaThis) { // with kActiveTransaction == false. DCHECK(!Runtime::Current()->IsActiveTransaction()); + ClassLinker* linker = Runtime::Current()->GetClassLinker(); MutableHandle<mirror::Class> interface(hs.NewHandle<mirror::Class>(nullptr)); for (uint32_t i = 0; i < num_ifaces; ++i) { const dex::TypeIndex type_idx = iface_list->GetTypeItem(i).type_idx_; - interface.Assign(ClassLinker::LookupResolvedType( - type_idx, klass->GetDexCache(), klass->GetClassLoader())); + interface.Assign(linker->LookupResolvedType(type_idx, klass.Get())); ifaces->SetWithoutChecks<false>(i, interface.Get()); } diff --git a/runtime/native/org_apache_harmony_dalvik_ddmc_DdmServer.cc b/runtime/native/org_apache_harmony_dalvik_ddmc_DdmServer.cc index c79f51b51e..8f8fd71727 100644 --- a/runtime/native/org_apache_harmony_dalvik_ddmc_DdmServer.cc +++ b/runtime/native/org_apache_harmony_dalvik_ddmc_DdmServer.cc @@ -16,8 +16,9 @@ #include "org_apache_harmony_dalvik_ddmc_DdmServer.h" +#include <android-base/logging.h> + #include "base/array_ref.h" -#include "base/logging.h" #include "debugger.h" #include "jni_internal.h" #include "native_util.h" diff --git a/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc b/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc index f5057b013a..7b733824c5 100644 --- a/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc +++ b/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc @@ -16,8 +16,9 @@ #include "org_apache_harmony_dalvik_ddmc_DdmVmInternal.h" +#include <android-base/logging.h> + #include "base/file_utils.h" -#include "base/logging.h" #include "base/mutex.h" #include "debugger.h" #include "gc/heap.h" diff --git a/runtime/native_bridge_art_interface.cc b/runtime/native_bridge_art_interface.cc index cd8315cdf9..10d10912f1 100644 --- a/runtime/native_bridge_art_interface.cc +++ b/runtime/native_bridge_art_interface.cc @@ -22,7 +22,7 @@ #include "art_method-inl.h" #include "base/enums.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "base/macros.h" #include "dex_file-inl.h" #include "jni_internal.h" diff --git a/runtime/native_stack_dump.cc b/runtime/native_stack_dump.cc index f166714b79..ec9455289f 100644 --- a/runtime/native_stack_dump.cc +++ b/runtime/native_stack_dump.cc @@ -40,6 +40,7 @@ #include "android-base/stringprintf.h" #include "arch/instruction_set.h" +#include "base/aborting.h" #include "base/file_utils.h" #include "base/memory_tool.h" #include "base/mutex.h" diff --git a/runtime/non_debuggable_classes.cc b/runtime/non_debuggable_classes.cc index 7db199cd06..8484e2cde7 100644 --- a/runtime/non_debuggable_classes.cc +++ b/runtime/non_debuggable_classes.cc @@ -16,7 +16,6 @@ #include "non_debuggable_classes.h" -#include "base/logging.h" #include "jni_internal.h" #include "mirror/class-inl.h" #include "nativehelper/scoped_local_ref.h" diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc index c82df7119f..32f8df7010 100644 --- a/runtime/oat_file.cc +++ b/runtime/oat_file.cc @@ -39,6 +39,7 @@ #include "base/bit_vector.h" #include "base/enums.h" #include "base/file_utils.h" +#include "base/logging.h" // For VLOG_IS_ON. #include "base/stl_util.h" #include "base/systrace.h" #include "base/unix_file/fd_file.h" @@ -314,7 +315,7 @@ bool OatFileBase::ComputeFields(uint8_t* requested_base, if (requested_base != nullptr && begin_ != requested_base) { // Host can fail this check. Do not dump there to avoid polluting the output. if (kIsTargetBuild && (kIsDebugBuild || VLOG_IS_ON(oat))) { - PrintFileToLog("/proc/self/maps", LogSeverity::WARNING); + PrintFileToLog("/proc/self/maps", android::base::LogSeverity::WARNING); } *error_msg = StringPrintf("Failed to find oatdata symbol at expected address: " "oatdata=%p != expected=%p. See process maps in the log.", @@ -1068,7 +1069,7 @@ void DlOpenOatFile::PreSetup(const std::string& elf_filename) { dl_iterate_context context0 = { Begin(), &dlopen_mmaps_, 0, 0}; if (dl_iterate_phdr(dl_iterate_context::callback, &context0) == 0) { // OK, give up and print an error. - PrintFileToLog("/proc/self/maps", LogSeverity::WARNING); + PrintFileToLog("/proc/self/maps", android::base::LogSeverity::WARNING); LOG(ERROR) << "File " << elf_filename << " loaded with dlopen but cannot find its mmaps."; } } diff --git a/runtime/oat_file_assistant.cc b/runtime/oat_file_assistant.cc index cd18ce102e..8707e736bd 100644 --- a/runtime/oat_file_assistant.cc +++ b/runtime/oat_file_assistant.cc @@ -24,7 +24,7 @@ #include "android-base/strings.h" #include "base/file_utils.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "base/stl_util.h" #include "class_linker.h" #include "compiler_filter.h" diff --git a/runtime/oat_file_manager.cc b/runtime/oat_file_manager.cc index b86f479eed..91a138a259 100644 --- a/runtime/oat_file_manager.cc +++ b/runtime/oat_file_manager.cc @@ -26,7 +26,7 @@ #include "art_field-inl.h" #include "base/bit_vector-inl.h" #include "base/file_utils.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "base/stl_util.h" #include "base/systrace.h" #include "class_linker.h" diff --git a/runtime/os_linux.cc b/runtime/os_linux.cc index a463f700d8..1b3e0000da 100644 --- a/runtime/os_linux.cc +++ b/runtime/os_linux.cc @@ -23,7 +23,8 @@ #include <cstddef> #include <memory> -#include "base/logging.h" +#include <android-base/logging.h> + #include "base/unix_file/fd_file.h" namespace art { diff --git a/runtime/parsed_options.cc b/runtime/parsed_options.cc index 85af560ce3..a3c00364a1 100644 --- a/runtime/parsed_options.cc +++ b/runtime/parsed_options.cc @@ -18,8 +18,10 @@ #include <sstream> +#include <android-base/logging.h> + #include "base/file_utils.h" -#include "base/logging.h" +#include "base/macros.h" #include "base/stringpiece.h" #include "debugger.h" #include "gc/heap.h" diff --git a/runtime/plugin.cc b/runtime/plugin.cc index 6aa078771b..7d86f1d5dc 100644 --- a/runtime/plugin.cc +++ b/runtime/plugin.cc @@ -20,8 +20,6 @@ #include "android-base/stringprintf.h" -#include "base/logging.h" - namespace art { using android::base::StringPrintf; diff --git a/runtime/plugin.h b/runtime/plugin.h index f077aaf3fb..909c710a96 100644 --- a/runtime/plugin.h +++ b/runtime/plugin.h @@ -18,7 +18,8 @@ #define ART_RUNTIME_PLUGIN_H_ #include <string> -#include "base/logging.h" + +#include <android-base/logging.h> namespace art { diff --git a/runtime/primitive.h b/runtime/primitive.h index a429914d5c..5b163d8cbe 100644 --- a/runtime/primitive.h +++ b/runtime/primitive.h @@ -19,7 +19,8 @@ #include <sys/types.h> -#include "base/logging.h" +#include <android-base/logging.h> + #include "base/macros.h" namespace art { diff --git a/runtime/quick_exception_handler.cc b/runtime/quick_exception_handler.cc index f94923e065..a7771abc26 100644 --- a/runtime/quick_exception_handler.cc +++ b/runtime/quick_exception_handler.cc @@ -19,6 +19,7 @@ #include "arch/context.h" #include "art_method-inl.h" #include "base/enums.h" +#include "base/logging.h" // For VLOG_IS_ON. #include "dex_file_types.h" #include "dex_instruction.h" #include "entrypoints/entrypoint_utils.h" diff --git a/runtime/quick_exception_handler.h b/runtime/quick_exception_handler.h index 12b63c933d..1103dab52c 100644 --- a/runtime/quick_exception_handler.h +++ b/runtime/quick_exception_handler.h @@ -17,7 +17,8 @@ #ifndef ART_RUNTIME_QUICK_EXCEPTION_HANDLER_H_ #define ART_RUNTIME_QUICK_EXCEPTION_HANDLER_H_ -#include "base/logging.h" +#include <android-base/logging.h> + #include "base/macros.h" #include "base/mutex.h" #include "deoptimization_kind.h" diff --git a/runtime/read_barrier.h b/runtime/read_barrier.h index d4b9f4311f..e8df2ad4ce 100644 --- a/runtime/read_barrier.h +++ b/runtime/read_barrier.h @@ -17,9 +17,11 @@ #ifndef ART_RUNTIME_READ_BARRIER_H_ #define ART_RUNTIME_READ_BARRIER_H_ -#include "base/logging.h" +#include <android-base/logging.h> + #include "base/macros.h" #include "base/mutex.h" +#include "base/runtime_debug.h" #include "gc_root.h" #include "jni.h" #include "mirror/object_reference.h" diff --git a/runtime/runtime.cc b/runtime/runtime.cc index d15de38b0a..7239ad3213 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -57,6 +57,7 @@ #include "asm_support.h" #include "asm_support_check.h" #include "atomic.h" +#include "base/aborting.h" #include "base/arena_allocator.h" #include "base/dumpable.h" #include "base/enums.h" diff --git a/runtime/runtime_common.cc b/runtime/runtime_common.cc index eb69d91dad..59af9187f9 100644 --- a/runtime/runtime_common.cc +++ b/runtime/runtime_common.cc @@ -23,10 +23,12 @@ #include <sstream> #include <string> -#include "android-base/stringprintf.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> +#include "base/aborting.h" #include "base/file_utils.h" -#include "base/logging.h" +#include "base/logging.h" // For LogHelper, GetCmdLine. #include "base/macros.h" #include "base/mutex.h" #include "native_stack_dump.h" @@ -430,7 +432,7 @@ void HandleUnexpectedSignalCommon(int signal_number, logger(LOG_STREAM(FATAL_WITHOUT_ABORT)); } if (kIsDebugBuild && signal_number == SIGSEGV) { - PrintFileToLog("/proc/self/maps", LogSeverity::FATAL_WITHOUT_ABORT); + PrintFileToLog("/proc/self/maps", android::base::LogSeverity::FATAL_WITHOUT_ABORT); } Runtime* runtime = Runtime::Current(); diff --git a/runtime/safe_map.h b/runtime/safe_map.h index f29869172e..33e45bdbd8 100644 --- a/runtime/safe_map.h +++ b/runtime/safe_map.h @@ -21,8 +21,9 @@ #include <memory> #include <type_traits> +#include <android-base/logging.h> + #include "base/allocator.h" -#include "base/logging.h" namespace art { diff --git a/runtime/scoped_thread_state_change-inl.h b/runtime/scoped_thread_state_change-inl.h index aa96871145..a9702a70bc 100644 --- a/runtime/scoped_thread_state_change-inl.h +++ b/runtime/scoped_thread_state_change-inl.h @@ -19,6 +19,8 @@ #include "scoped_thread_state_change.h" +#include <android-base/logging.h> + #include "base/casts.h" #include "jni_env_ext-inl.h" #include "obj_ptr-inl.h" diff --git a/runtime/scoped_thread_state_change.cc b/runtime/scoped_thread_state_change.cc index 94354fc586..6a86cc6411 100644 --- a/runtime/scoped_thread_state_change.cc +++ b/runtime/scoped_thread_state_change.cc @@ -19,7 +19,6 @@ #include <type_traits> #include "base/casts.h" -#include "base/logging.h" #include "java_vm_ext.h" #include "obj_ptr-inl.h" #include "runtime-inl.h" diff --git a/runtime/signal_catcher.cc b/runtime/signal_catcher.cc index bf5d718113..d9c4da9b96 100644 --- a/runtime/signal_catcher.cc +++ b/runtime/signal_catcher.cc @@ -35,6 +35,7 @@ #include "arch/instruction_set.h" #include "base/file_utils.h" +#include "base/logging.h" // For GetCmdLine. #include "base/time_utils.h" #include "base/unix_file/fd_file.h" #include "class_linker.h" diff --git a/runtime/signal_set.h b/runtime/signal_set.h index 6f888525cb..53613236fa 100644 --- a/runtime/signal_set.h +++ b/runtime/signal_set.h @@ -19,7 +19,7 @@ #include <signal.h> -#include "base/logging.h" +#include <android-base/logging.h> namespace art { diff --git a/runtime/stride_iterator.h b/runtime/stride_iterator.h index 0560c33eee..511c2c66f2 100644 --- a/runtime/stride_iterator.h +++ b/runtime/stride_iterator.h @@ -19,7 +19,7 @@ #include <iterator> -#include "base/logging.h" +#include <android-base/logging.h> namespace art { diff --git a/runtime/string_reference.h b/runtime/string_reference.h index d0ab4e40d0..24a425371b 100644 --- a/runtime/string_reference.h +++ b/runtime/string_reference.h @@ -19,7 +19,8 @@ #include <stdint.h> -#include "base/logging.h" +#include <android-base/logging.h> + #include "dex_file-inl.h" #include "dex_file_reference.h" #include "dex_file_types.h" diff --git a/runtime/thread-inl.h b/runtime/thread-inl.h index b5a962691b..62b0789a43 100644 --- a/runtime/thread-inl.h +++ b/runtime/thread-inl.h @@ -19,6 +19,7 @@ #include "thread.h" +#include "base/aborting.h" #include "base/casts.h" #include "base/mutex-inl.h" #include "base/time_utils.h" diff --git a/runtime/thread_linux.cc b/runtime/thread_linux.cc index b922d94617..9673eee795 100644 --- a/runtime/thread_linux.cc +++ b/runtime/thread_linux.cc @@ -14,9 +14,11 @@ * limitations under the License. */ +#include "thread.h" + #include <signal.h> -#include "thread.h" +#include "base/logging.h" // For VLOG. #include "utils.h" namespace art { diff --git a/runtime/thread_list.cc b/runtime/thread_list.cc index 9f553147c4..e43b9f4b96 100644 --- a/runtime/thread_list.cc +++ b/runtime/thread_list.cc @@ -28,6 +28,7 @@ #include "nativehelper/scoped_local_ref.h" #include "nativehelper/scoped_utf_chars.h" +#include "base/aborting.h" #include "base/histogram-inl.h" #include "base/mutex-inl.h" #include "base/systrace.h" @@ -364,11 +365,11 @@ size_t ThreadList::RunCheckpoint(Closure* checkpoint_function, Closure* callback // Run the checkpoint on the suspended threads. for (const auto& thread : suspended_count_modified_threads) { if (!thread->IsSuspended()) { - if (ATRACE_ENABLED()) { + ScopedTrace trace([&]() { std::ostringstream oss; thread->ShortDump(oss); - ATRACE_BEGIN((std::string("Waiting for suspension of thread ") + oss.str()).c_str()); - } + return std::string("Waiting for suspension of thread ") + oss.str(); + }); // Busy wait until the thread is suspended. const uint64_t start_time = NanoTime(); do { @@ -377,7 +378,6 @@ size_t ThreadList::RunCheckpoint(Closure* checkpoint_function, Closure* callback const uint64_t total_delay = NanoTime() - start_time; // Shouldn't need to wait for longer than 1000 microseconds. constexpr uint64_t kLongWaitThreshold = MsToNs(1); - ATRACE_END(); if (UNLIKELY(total_delay > kLongWaitThreshold)) { LOG(WARNING) << "Long wait of " << PrettyDuration(total_delay) << " for " << *thread << " suspension!"; diff --git a/runtime/thread_pool.cc b/runtime/thread_pool.cc index cffaffc045..386cdf006a 100644 --- a/runtime/thread_pool.cc +++ b/runtime/thread_pool.cc @@ -22,11 +22,11 @@ #include <pthread.h> -#include "android-base/stringprintf.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> #include "base/bit_utils.h" #include "base/casts.h" -#include "base/logging.h" #include "base/stl_util.h" #include "base/time_utils.h" #include "runtime.h" diff --git a/runtime/transaction.cc b/runtime/transaction.cc index e923aff439..c9766bc9ca 100644 --- a/runtime/transaction.cc +++ b/runtime/transaction.cc @@ -16,7 +16,8 @@ #include "transaction.h" -#include "base/logging.h" +#include <android-base/logging.h> + #include "base/stl_util.h" #include "gc/accounting/card_table-inl.h" #include "gc_root-inl.h" diff --git a/runtime/transaction_test.cc b/runtime/transaction_test.cc index e52dd08540..304017eadb 100644 --- a/runtime/transaction_test.cc +++ b/runtime/transaction_test.cc @@ -493,7 +493,7 @@ TEST_F(TransactionTest, ResolveString) { dex::StringIndex string_idx = dex_file->GetIndexForStringId(*string_id); ASSERT_TRUE(string_idx.IsValid()); // String should only get resolved by the initializer. - EXPECT_TRUE(class_linker_->LookupString(*dex_file, string_idx, h_dex_cache.Get()) == nullptr); + EXPECT_TRUE(class_linker_->LookupString(string_idx, h_dex_cache.Get()) == nullptr); EXPECT_TRUE(h_dex_cache->GetResolvedString(string_idx) == nullptr); // Do the transaction, then roll back. Runtime::Current()->EnterTransactionMode(); @@ -502,14 +502,15 @@ TEST_F(TransactionTest, ResolveString) { ASSERT_TRUE(h_klass->IsInitialized()); // Make sure the string got resolved by the transaction. { - mirror::String* s = class_linker_->LookupString(*dex_file, string_idx, h_dex_cache.Get()); + ObjPtr<mirror::String> s = + class_linker_->LookupString(string_idx, h_dex_cache.Get()); ASSERT_TRUE(s != nullptr); EXPECT_STREQ(s->ToModifiedUtf8().c_str(), kResolvedString); - EXPECT_EQ(s, h_dex_cache->GetResolvedString(string_idx)); + EXPECT_EQ(s.Ptr(), h_dex_cache->GetResolvedString(string_idx)); } Runtime::Current()->RollbackAndExitTransactionMode(); // Check that the string did not stay resolved. - EXPECT_TRUE(class_linker_->LookupString(*dex_file, string_idx, h_dex_cache.Get()) == nullptr); + EXPECT_TRUE(class_linker_->LookupString(string_idx, h_dex_cache.Get()) == nullptr); EXPECT_TRUE(h_dex_cache->GetResolvedString(string_idx) == nullptr); ASSERT_FALSE(h_klass->IsInitialized()); ASSERT_FALSE(soa.Self()->IsExceptionPending()); diff --git a/runtime/type_reference.h b/runtime/type_reference.h index f7daa2bd58..10a67b1798 100644 --- a/runtime/type_reference.h +++ b/runtime/type_reference.h @@ -19,7 +19,8 @@ #include <stdint.h> -#include "base/logging.h" +#include <android-base/logging.h> + #include "dex_file_types.h" #include "string_reference.h" diff --git a/runtime/utf.cc b/runtime/utf.cc index 7e06482635..93fcb32136 100644 --- a/runtime/utf.cc +++ b/runtime/utf.cc @@ -16,7 +16,8 @@ #include "utf.h" -#include "base/logging.h" +#include <android-base/logging.h> + #include "mirror/array.h" #include "mirror/object-inl.h" #include "utf-inl.h" diff --git a/runtime/utils.h b/runtime/utils.h index ede32dc57a..789498ce09 100644 --- a/runtime/utils.h +++ b/runtime/utils.h @@ -23,9 +23,10 @@ #include <random> #include <string> +#include <android-base/logging.h> + #include "arch/instruction_set.h" #include "base/casts.h" -#include "base/logging.h" #include "base/stringpiece.h" #include "globals.h" #include "primitive.h" diff --git a/runtime/utils/dex_cache_arrays_layout-inl.h b/runtime/utils/dex_cache_arrays_layout-inl.h index 9d4e9fb96c..855b856187 100644 --- a/runtime/utils/dex_cache_arrays_layout-inl.h +++ b/runtime/utils/dex_cache_arrays_layout-inl.h @@ -19,8 +19,9 @@ #include "dex_cache_arrays_layout.h" +#include <android-base/logging.h> + #include "base/bit_utils.h" -#include "base/logging.h" #include "gc_root.h" #include "globals.h" #include "mirror/dex_cache.h" diff --git a/runtime/vdex_file.cc b/runtime/vdex_file.cc index fb9d24f9bc..fe768a1fd5 100644 --- a/runtime/vdex_file.cc +++ b/runtime/vdex_file.cc @@ -20,8 +20,9 @@ #include <memory> +#include <android-base/logging.h> + #include "base/bit_utils.h" -#include "base/logging.h" #include "base/stl_util.h" #include "base/unix_file/fd_file.h" #include "dex_file.h" diff --git a/runtime/verifier/method_verifier-inl.h b/runtime/verifier/method_verifier-inl.h index a7fa9f34d1..445a6ff7de 100644 --- a/runtime/verifier/method_verifier-inl.h +++ b/runtime/verifier/method_verifier-inl.h @@ -19,7 +19,8 @@ #include "method_verifier.h" -#include "base/logging.h" +#include <android-base/logging.h> + #include "handle_scope-inl.h" #include "mirror/class_loader.h" #include "mirror/dex_cache.h" diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc index cd428272e7..4ff49edb90 100644 --- a/runtime/verifier/method_verifier.cc +++ b/runtime/verifier/method_verifier.cc @@ -22,8 +22,9 @@ #include "art_field-inl.h" #include "art_method-inl.h" +#include "base/aborting.h" #include "base/enums.h" -#include "base/logging.h" +#include "base/logging.h" // For VLOG. #include "base/mutex-inl.h" #include "base/stl_util.h" #include "base/systrace.h" @@ -229,7 +230,7 @@ MethodVerifier::FailureData MethodVerifier::VerifyMethods(Thread* self, previous_method_idx = method_idx; InvokeType type = it->GetMethodInvokeType(class_def); ArtMethod* method = linker->ResolveMethod<ClassLinker::ResolveMode::kNoChecks>( - *dex_file, method_idx, dex_cache, class_loader, nullptr, type); + method_idx, dex_cache, class_loader, /* referrer */ nullptr, type); if (method == nullptr) { DCHECK(self->IsExceptionPending()); // We couldn't resolve the method, but continue regardless. @@ -282,7 +283,7 @@ FailureKind MethodVerifier::VerifyClass(Thread* self, bool allow_soft_failures, HardFailLogMode log_level, std::string* error) { - SCOPED_TRACE("VerifyClass %s", PrettyDescriptor(dex_file->GetClassDescriptor(class_def)).c_str()); + SCOPED_TRACE << "VerifyClass " << PrettyDescriptor(dex_file->GetClassDescriptor(class_def)); // A class must not be abstract and final. if ((class_def.access_flags_ & (kAccAbstract | kAccFinal)) == (kAccAbstract | kAccFinal)) { @@ -1076,9 +1077,8 @@ bool MethodVerifier::ScanTryCatchBlocks() { // Ensure exception types are resolved so that they don't need resolution to be delivered, // unresolved exception types will be ignored by exception delivery if (iterator.GetHandlerTypeIndex().IsValid()) { - mirror::Class* exception_type = linker->ResolveType(*dex_file_, - iterator.GetHandlerTypeIndex(), - dex_cache_, class_loader_); + ObjPtr<mirror::Class> exception_type = + linker->ResolveType(iterator.GetHandlerTypeIndex(), dex_cache_, class_loader_); if (exception_type == nullptr) { DCHECK(self_->IsExceptionPending()); self_->ClearException(); @@ -2433,8 +2433,8 @@ bool MethodVerifier::CodeFlowVerifyInstruction(uint32_t* start_guess) { const RegType& res_type = ResolveClass<CheckAccess::kYes>(type_idx); if (res_type.IsConflict()) { // If this is a primitive type, fail HARD. - ObjPtr<mirror::Class> klass = - ClassLinker::LookupResolvedType(type_idx, dex_cache_.Get(), class_loader_.Get()); + ObjPtr<mirror::Class> klass = Runtime::Current()->GetClassLinker()->LookupResolvedType( + type_idx, dex_cache_.Get(), class_loader_.Get()); if (klass != nullptr && klass->IsPrimitive()) { Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "using primitive type " << dex_file_->StringByTypeIdx(type_idx) << " in instanceof in " @@ -3641,8 +3641,8 @@ bool MethodVerifier::CodeFlowVerifyInstruction(uint32_t* start_guess) { has_catch_all_handler = true; } else { // It is also a catch-all if it is java.lang.Throwable. - mirror::Class* klass = linker->ResolveType(*dex_file_, handler_type_idx, dex_cache_, - class_loader_); + ObjPtr<mirror::Class> klass = + linker->ResolveType(handler_type_idx, dex_cache_, class_loader_); if (klass != nullptr) { if (klass == mirror::Throwable::GetJavaLangThrowable()) { has_catch_all_handler = true; @@ -3760,16 +3760,16 @@ void MethodVerifier::UninstantiableError(const char* descriptor) { << "non-instantiable klass " << descriptor; } -inline bool MethodVerifier::IsInstantiableOrPrimitive(mirror::Class* klass) { +inline bool MethodVerifier::IsInstantiableOrPrimitive(ObjPtr<mirror::Class> klass) { return klass->IsInstantiable() || klass->IsPrimitive(); } template <MethodVerifier::CheckAccess C> const RegType& MethodVerifier::ResolveClass(dex::TypeIndex class_idx) { - mirror::Class* klass = can_load_classes_ - ? Runtime::Current()->GetClassLinker()->ResolveType( - *dex_file_, class_idx, dex_cache_, class_loader_) - : ClassLinker::LookupResolvedType(class_idx, dex_cache_.Get(), class_loader_.Get()).Ptr(); + ClassLinker* linker = Runtime::Current()->GetClassLinker(); + ObjPtr<mirror::Class> klass = can_load_classes_ + ? linker->ResolveType(class_idx, dex_cache_, class_loader_) + : linker->LookupResolvedType(class_idx, dex_cache_.Get(), class_loader_.Get()); if (can_load_classes_ && klass == nullptr) { DCHECK(self_->IsExceptionPending()); self_->ClearException(); @@ -3782,10 +3782,10 @@ const RegType& MethodVerifier::ResolveClass(dex::TypeIndex class_idx) { UninstantiableError(descriptor); precise = false; } - result = reg_types_.FindClass(klass, precise); + result = reg_types_.FindClass(klass.Ptr(), precise); if (result == nullptr) { const char* descriptor = dex_file_->StringByTypeIdx(class_idx); - result = reg_types_.InsertClass(descriptor, klass, precise); + result = reg_types_.InsertClass(descriptor, klass.Ptr(), precise); } } else { const char* descriptor = dex_file_->StringByTypeIdx(class_idx); @@ -3800,7 +3800,7 @@ const RegType& MethodVerifier::ResolveClass(dex::TypeIndex class_idx) { } // Record result of class resolution attempt. - VerifierDeps::MaybeRecordClassResolution(*dex_file_, class_idx, klass); + VerifierDeps::MaybeRecordClassResolution(*dex_file_, class_idx, klass.Ptr()); // If requested, check if access is allowed. Unresolved types are included in this check, as the // interpreter only tests whether access is allowed when a class is not pre-verified and runs in @@ -4883,7 +4883,7 @@ ArtField* MethodVerifier::GetStaticField(int field_idx) { return nullptr; // Can't resolve Class so no more to do here, will do checking at runtime. } ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); - ArtField* field = class_linker->ResolveFieldJLS(*dex_file_, field_idx, dex_cache_, class_loader_); + ArtField* field = class_linker->ResolveFieldJLS(field_idx, dex_cache_, class_loader_); // Record result of the field resolution attempt. VerifierDeps::MaybeRecordFieldResolution(*dex_file_, field_idx, field); @@ -4924,7 +4924,7 @@ ArtField* MethodVerifier::GetInstanceField(const RegType& obj_type, int field_id return nullptr; // Can't resolve Class so no more to do here } ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); - ArtField* field = class_linker->ResolveFieldJLS(*dex_file_, field_idx, dex_cache_, class_loader_); + ArtField* field = class_linker->ResolveFieldJLS(field_idx, dex_cache_, class_loader_); // Record result of the field resolution attempt. VerifierDeps::MaybeRecordFieldResolution(*dex_file_, field_idx, field); @@ -5048,7 +5048,7 @@ void MethodVerifier::VerifyISFieldAccess(const Instruction* inst, const RegType& } ObjPtr<mirror::Class> field_type_class = - can_load_classes_ ? field->ResolveType() : field->LookupType(); + can_load_classes_ ? field->ResolveType() : field->LookupResolvedType(); if (field_type_class != nullptr) { field_type = &FromClass(field->GetTypeDescriptor(), field_type_class.Ptr(), @@ -5197,7 +5197,7 @@ void MethodVerifier::VerifyQuickFieldAccess(const Instruction* inst, const RegTy const RegType* field_type; { ObjPtr<mirror::Class> field_type_class = - can_load_classes_ ? field->ResolveType() : field->LookupType(); + can_load_classes_ ? field->ResolveType() : field->LookupResolvedType(); if (field_type_class != nullptr) { field_type = &FromClass(field->GetTypeDescriptor(), diff --git a/runtime/verifier/method_verifier.h b/runtime/verifier/method_verifier.h index c885914633..f26f3e2655 100644 --- a/runtime/verifier/method_verifier.h +++ b/runtime/verifier/method_verifier.h @@ -257,7 +257,8 @@ class MethodVerifier { REQUIRES_SHARED(Locks::mutator_lock_); void UninstantiableError(const char* descriptor); - static bool IsInstantiableOrPrimitive(mirror::Class* klass) REQUIRES_SHARED(Locks::mutator_lock_); + static bool IsInstantiableOrPrimitive(ObjPtr<mirror::Class> klass) + REQUIRES_SHARED(Locks::mutator_lock_); // Is the method being verified a constructor? See the comment on the field. bool IsConstructor() const { diff --git a/runtime/verifier/reg_type_cache.cc b/runtime/verifier/reg_type_cache.cc index a3f08c8580..c68fa0f0d6 100644 --- a/runtime/verifier/reg_type_cache.cc +++ b/runtime/verifier/reg_type_cache.cc @@ -18,6 +18,7 @@ #include <type_traits> +#include "base/aborting.h" #include "base/arena_bit_vector.h" #include "base/bit_vector-inl.h" #include "base/casts.h" diff --git a/runtime/verifier/register_line-inl.h b/runtime/verifier/register_line-inl.h index a9c9428581..39d73f54d8 100644 --- a/runtime/verifier/register_line-inl.h +++ b/runtime/verifier/register_line-inl.h @@ -19,6 +19,7 @@ #include "register_line.h" +#include "base/logging.h" // For VLOG. #include "method_verifier.h" #include "reg_type_cache-inl.h" @@ -192,6 +193,27 @@ inline RegisterLine::RegisterLine(size_t num_regs, MethodVerifier* verifier) SetResultTypeToUnknown(verifier); } +inline void RegisterLine::ClearRegToLockDepth(size_t reg, size_t depth) { + CHECK_LT(depth, 32u); + DCHECK(IsSetLockDepth(reg, depth)); + auto it = reg_to_lock_depths_.find(reg); + DCHECK(it != reg_to_lock_depths_.end()); + uint32_t depths = it->second ^ (1 << depth); + if (depths != 0) { + it->second = depths; + } else { + reg_to_lock_depths_.erase(it); + } + // Need to unlock every register at the same lock depth. These are aliased locks. + uint32_t mask = 1 << depth; + for (auto& pair : reg_to_lock_depths_) { + if ((pair.second & mask) != 0) { + VLOG(verifier) << "Also unlocking " << pair.first; + pair.second ^= mask; + } + } +} + inline void RegisterLineArenaDelete::operator()(RegisterLine* ptr) const { if (ptr != nullptr) { ptr->~RegisterLine(); diff --git a/runtime/verifier/register_line.h b/runtime/verifier/register_line.h index 71eb4d6ac7..82f63b281a 100644 --- a/runtime/verifier/register_line.h +++ b/runtime/verifier/register_line.h @@ -20,6 +20,8 @@ #include <memory> #include <vector> +#include <android-base/logging.h> + #include "base/scoped_arena_containers.h" #include "safe_map.h" @@ -401,26 +403,7 @@ class RegisterLine { return true; } - void ClearRegToLockDepth(size_t reg, size_t depth) { - CHECK_LT(depth, 32u); - DCHECK(IsSetLockDepth(reg, depth)); - auto it = reg_to_lock_depths_.find(reg); - DCHECK(it != reg_to_lock_depths_.end()); - uint32_t depths = it->second ^ (1 << depth); - if (depths != 0) { - it->second = depths; - } else { - reg_to_lock_depths_.erase(it); - } - // Need to unlock every register at the same lock depth. These are aliased locks. - uint32_t mask = 1 << depth; - for (auto& pair : reg_to_lock_depths_) { - if ((pair.second & mask) != 0) { - VLOG(verifier) << "Also unlocking " << pair.first; - pair.second ^= mask; - } - } - } + void ClearRegToLockDepth(size_t reg, size_t depth); void ClearAllRegToLockDepths(size_t reg) { reg_to_lock_depths_.erase(reg); diff --git a/runtime/well_known_classes.cc b/runtime/well_known_classes.cc index 9722db9641..5a653fe3a1 100644 --- a/runtime/well_known_classes.cc +++ b/runtime/well_known_classes.cc @@ -20,9 +20,9 @@ #include <sstream> -#include "android-base/stringprintf.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> -#include "base/logging.h" #include "entrypoints/quick/quick_entrypoints_enum.h" #include "jni_internal.h" #include "mirror/class.h" diff --git a/runtime/zip_archive.h b/runtime/zip_archive.h index 821cc5ceb1..75f8757f6c 100644 --- a/runtime/zip_archive.h +++ b/runtime/zip_archive.h @@ -21,7 +21,8 @@ #include <memory> #include <string> -#include "base/logging.h" +#include <android-base/logging.h> + #include "base/unix_file/random_access_file.h" #include "globals.h" #include "mem_map.h" diff --git a/simulator/code_simulator_arm64.cc b/simulator/code_simulator_arm64.cc index 939d2e287f..a64bd0bc0b 100644 --- a/simulator/code_simulator_arm64.cc +++ b/simulator/code_simulator_arm64.cc @@ -16,7 +16,7 @@ #include "code_simulator_arm64.h" -#include "base/logging.h" +#include <android-base/logging.h> using namespace vixl::aarch64; // NOLINT(build/namespaces) diff --git a/simulator/code_simulator_container.cc b/simulator/code_simulator_container.cc index a5f05dc8fc..9f52b320f2 100644 --- a/simulator/code_simulator_container.cc +++ b/simulator/code_simulator_container.cc @@ -18,6 +18,7 @@ #include "code_simulator_container.h" +#include "base/logging.h" // For VLOG. #include "code_simulator.h" #include "globals.h" diff --git a/simulator/code_simulator_container.h b/simulator/code_simulator_container.h index 31a915e4f1..a21971508a 100644 --- a/simulator/code_simulator_container.h +++ b/simulator/code_simulator_container.h @@ -17,8 +17,9 @@ #ifndef ART_SIMULATOR_CODE_SIMULATOR_CONTAINER_H_ #define ART_SIMULATOR_CODE_SIMULATOR_CONTAINER_H_ +#include <android-base/logging.h> + #include "arch/instruction_set.h" -#include "base/logging.h" namespace art { diff --git a/test/004-JniTest/jni_test.cc b/test/004-JniTest/jni_test.cc index bc5a0a64e8..4561895509 100644 --- a/test/004-JniTest/jni_test.cc +++ b/test/004-JniTest/jni_test.cc @@ -20,8 +20,10 @@ #include <iostream> #include <vector> +#include <android-base/logging.h> + #include "art_method-inl.h" -#include "base/logging.h" +#include "base/runtime_debug.h" #include "jni.h" namespace art { diff --git a/test/044-proxy/native_proxy.cc b/test/044-proxy/native_proxy.cc index f168719bf5..f3178f9c2a 100644 --- a/test/044-proxy/native_proxy.cc +++ b/test/044-proxy/native_proxy.cc @@ -16,7 +16,7 @@ #include "jni.h" -#include "base/logging.h" +#include <android-base/logging.h> namespace art { diff --git a/test/137-cfi/cfi.cc b/test/137-cfi/cfi.cc index 66270fd5c7..ef758e86e1 100644 --- a/test/137-cfi/cfi.cc +++ b/test/137-cfi/cfi.cc @@ -25,11 +25,11 @@ #include "jni.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> #include <backtrace/Backtrace.h> -#include "android-base/stringprintf.h" #include "base/file_utils.h" -#include "base/logging.h" #include "base/macros.h" #include "gc/heap.h" #include "gc/space/image_space.h" diff --git a/test/552-checker-sharpening/src/Main.java b/test/552-checker-sharpening/src/Main.java index 55873eabf0..3173afdfcd 100644 --- a/test/552-checker-sharpening/src/Main.java +++ b/test/552-checker-sharpening/src/Main.java @@ -44,24 +44,11 @@ public class Main { /// CHECK-START: int Main.testSimple(int) sharpening (before) /// CHECK: InvokeStaticOrDirect method_load_kind:RuntimeCall - /// CHECK-START-ARM: int Main.testSimple(int) sharpening (after) + /// CHECK-START-{ARM,ARM64,MIPS,MIPS64,X86,X86_64}: int Main.testSimple(int) sharpening (after) /// CHECK: InvokeStaticOrDirect method_load_kind:BssEntry - /// CHECK-START-ARM64: int Main.testSimple(int) sharpening (after) - /// CHECK: InvokeStaticOrDirect method_load_kind:BssEntry - - /// CHECK-START-MIPS: int Main.testSimple(int) sharpening (after) - /// CHECK: InvokeStaticOrDirect method_load_kind:BssEntry - - /// CHECK-START-MIPS64: int Main.testSimple(int) sharpening (after) - /// CHECK: InvokeStaticOrDirect method_load_kind:BssEntry - - /// CHECK-START-X86: int Main.testSimple(int) sharpening (after) + /// CHECK-START-X86: int Main.testSimple(int) pc_relative_fixups_x86 (before) /// CHECK-NOT: X86ComputeBaseMethodAddress - /// CHECK: InvokeStaticOrDirect method_load_kind:BssEntry - - /// CHECK-START-X86_64: int Main.testSimple(int) sharpening (after) - /// CHECK: InvokeStaticOrDirect method_load_kind:BssEntry /// CHECK-START-X86: int Main.testSimple(int) pc_relative_fixups_x86 (after) /// CHECK: X86ComputeBaseMethodAddress @@ -74,31 +61,14 @@ public class Main { /// CHECK-START: int Main.testDiamond(boolean, int) sharpening (before) /// CHECK: InvokeStaticOrDirect method_load_kind:RuntimeCall + /// CHECK: InvokeStaticOrDirect method_load_kind:RuntimeCall - /// CHECK-START-ARM: int Main.testDiamond(boolean, int) sharpening (after) - /// CHECK: InvokeStaticOrDirect method_load_kind:BssEntry - /// CHECK: InvokeStaticOrDirect method_load_kind:BssEntry - - /// CHECK-START-ARM64: int Main.testDiamond(boolean, int) sharpening (after) - /// CHECK: InvokeStaticOrDirect method_load_kind:BssEntry - /// CHECK: InvokeStaticOrDirect method_load_kind:BssEntry - - /// CHECK-START-MIPS: int Main.testDiamond(boolean, int) sharpening (after) - /// CHECK: InvokeStaticOrDirect method_load_kind:BssEntry - /// CHECK: InvokeStaticOrDirect method_load_kind:BssEntry - - /// CHECK-START-MIPS64: int Main.testDiamond(boolean, int) sharpening (after) + /// CHECK-START-{ARM,ARM64,MIPS,MIPS64,X86,X86_64}: int Main.testDiamond(boolean, int) sharpening (after) /// CHECK: InvokeStaticOrDirect method_load_kind:BssEntry /// CHECK: InvokeStaticOrDirect method_load_kind:BssEntry - /// CHECK-START-X86: int Main.testDiamond(boolean, int) sharpening (after) + /// CHECK-START-X86: int Main.testDiamond(boolean, int) pc_relative_fixups_x86 (before) /// CHECK-NOT: X86ComputeBaseMethodAddress - /// CHECK: InvokeStaticOrDirect method_load_kind:BssEntry - /// CHECK: InvokeStaticOrDirect method_load_kind:BssEntry - - /// CHECK-START-X86_64: int Main.testDiamond(boolean, int) sharpening (after) - /// CHECK: InvokeStaticOrDirect method_load_kind:BssEntry - /// CHECK: InvokeStaticOrDirect method_load_kind:BssEntry /// CHECK-START-X86: int Main.testDiamond(boolean, int) pc_relative_fixups_x86 (after) /// CHECK: X86ComputeBaseMethodAddress @@ -169,30 +139,7 @@ public class Main { return x; } - /// CHECK-START: java.lang.String Main.$noinline$getBootImageString() sharpening (before) - /// CHECK: LoadString load_kind:RuntimeCall - - /// CHECK-START-X86: java.lang.String Main.$noinline$getBootImageString() sharpening (after) - // Note: load kind depends on PIC/non-PIC - /// CHECK: LoadString load_kind:{{BootImageAddress|BootImageInternTable}} - - /// CHECK-START-X86_64: java.lang.String Main.$noinline$getBootImageString() sharpening (after) - // Note: load kind depends on PIC/non-PIC - /// CHECK: LoadString load_kind:{{BootImageAddress|BootImageInternTable}} - - /// CHECK-START-ARM: java.lang.String Main.$noinline$getBootImageString() sharpening (after) - // Note: load kind depends on PIC/non-PIC - /// CHECK: LoadString load_kind:{{BootImageAddress|BootImageInternTable}} - - /// CHECK-START-ARM64: java.lang.String Main.$noinline$getBootImageString() sharpening (after) - // Note: load kind depends on PIC/non-PIC - /// CHECK: LoadString load_kind:{{BootImageAddress|BootImageInternTable}} - - /// CHECK-START-MIPS: java.lang.String Main.$noinline$getBootImageString() sharpening (after) - // Note: load kind depends on PIC/non-PIC - /// CHECK: LoadString load_kind:{{BootImageAddress|BootImageInternTable}} - - /// CHECK-START-MIPS64: java.lang.String Main.$noinline$getBootImageString() sharpening (after) + /// CHECK-START-{ARM,ARM64,MIPS,MIPS64,X86,X86_64}: java.lang.String Main.$noinline$getBootImageString() builder (after) // Note: load kind depends on PIC/non-PIC /// CHECK: LoadString load_kind:{{BootImageAddress|BootImageInternTable}} @@ -203,31 +150,16 @@ public class Main { return ""; } - /// CHECK-START: java.lang.String Main.$noinline$getNonBootImageString() sharpening (before) - /// CHECK: LoadString load_kind:RuntimeCall - - /// CHECK-START-X86: java.lang.String Main.$noinline$getNonBootImageString() sharpening (after) + /// CHECK-START-{ARM,ARM64,MIPS,MIPS64,X86,X86_64}: java.lang.String Main.$noinline$getNonBootImageString() builder (after) /// CHECK: LoadString load_kind:BssEntry + /// CHECK-START-X86: java.lang.String Main.$noinline$getNonBootImageString() pc_relative_fixups_x86 (before) + /// CHECK-NOT: X86ComputeBaseMethodAddress + /// CHECK-START-X86: java.lang.String Main.$noinline$getNonBootImageString() pc_relative_fixups_x86 (after) /// CHECK-DAG: X86ComputeBaseMethodAddress /// CHECK-DAG: LoadString load_kind:BssEntry - /// CHECK-START-X86_64: java.lang.String Main.$noinline$getNonBootImageString() sharpening (after) - /// CHECK: LoadString load_kind:BssEntry - - /// CHECK-START-ARM: java.lang.String Main.$noinline$getNonBootImageString() sharpening (after) - /// CHECK: LoadString load_kind:BssEntry - - /// CHECK-START-ARM64: java.lang.String Main.$noinline$getNonBootImageString() sharpening (after) - /// CHECK: LoadString load_kind:BssEntry - - /// CHECK-START-MIPS: java.lang.String Main.$noinline$getNonBootImageString() sharpening (after) - /// CHECK: LoadString load_kind:BssEntry - - /// CHECK-START-MIPS64: java.lang.String Main.$noinline$getNonBootImageString() sharpening (after) - /// CHECK: LoadString load_kind:BssEntry - public static String $noinline$getNonBootImageString() { // Prevent inlining to avoid the string comparison being optimized away. if (doThrow) { throw new Error(); } @@ -235,27 +167,7 @@ public class Main { return "non-boot-image-string"; } - /// CHECK-START-X86: java.lang.Class Main.$noinline$getStringClass() sharpening (after) - // Note: load kind depends on PIC/non-PIC - /// CHECK: LoadClass load_kind:{{BootImageAddress|BootImageClassTable}} class_name:java.lang.String - - /// CHECK-START-X86_64: java.lang.Class Main.$noinline$getStringClass() sharpening (after) - // Note: load kind depends on PIC/non-PIC - /// CHECK: LoadClass load_kind:{{BootImageAddress|BootImageClassTable}} class_name:java.lang.String - - /// CHECK-START-ARM: java.lang.Class Main.$noinline$getStringClass() sharpening (after) - // Note: load kind depends on PIC/non-PIC - /// CHECK: LoadClass load_kind:{{BootImageAddress|BootImageClassTable}} class_name:java.lang.String - - /// CHECK-START-ARM64: java.lang.Class Main.$noinline$getStringClass() sharpening (after) - // Note: load kind depends on PIC/non-PIC - /// CHECK: LoadClass load_kind:{{BootImageAddress|BootImageClassTable}} class_name:java.lang.String - - /// CHECK-START-MIPS: java.lang.Class Main.$noinline$getStringClass() sharpening (after) - // Note: load kind depends on PIC/non-PIC - /// CHECK: LoadClass load_kind:{{BootImageAddress|BootImageClassTable}} class_name:java.lang.String - - /// CHECK-START-MIPS64: java.lang.Class Main.$noinline$getStringClass() sharpening (after) + /// CHECK-START-{ARM,ARM64,MIPS,MIPS64,X86,X86_64}: java.lang.Class Main.$noinline$getStringClass() builder (after) // Note: load kind depends on PIC/non-PIC /// CHECK: LoadClass load_kind:{{BootImageAddress|BootImageClassTable}} class_name:java.lang.String @@ -266,28 +178,16 @@ public class Main { return String.class; } - /// CHECK-START-X86: java.lang.Class Main.$noinline$getOtherClass() sharpening (after) + /// CHECK-START-{ARM,ARM64,MIPS,MIPS64,X86,X86_64}: java.lang.Class Main.$noinline$getOtherClass() builder (after) /// CHECK: LoadClass load_kind:BssEntry class_name:Other + /// CHECK-START-X86: java.lang.Class Main.$noinline$getOtherClass() pc_relative_fixups_x86 (before) + /// CHECK-NOT: X86ComputeBaseMethodAddress + /// CHECK-START-X86: java.lang.Class Main.$noinline$getOtherClass() pc_relative_fixups_x86 (after) /// CHECK-DAG: X86ComputeBaseMethodAddress /// CHECK-DAG: LoadClass load_kind:BssEntry class_name:Other - /// CHECK-START-X86_64: java.lang.Class Main.$noinline$getOtherClass() sharpening (after) - /// CHECK: LoadClass load_kind:BssEntry class_name:Other - - /// CHECK-START-ARM: java.lang.Class Main.$noinline$getOtherClass() sharpening (after) - /// CHECK: LoadClass load_kind:BssEntry class_name:Other - - /// CHECK-START-ARM64: java.lang.Class Main.$noinline$getOtherClass() sharpening (after) - /// CHECK: LoadClass load_kind:BssEntry class_name:Other - - /// CHECK-START-MIPS: java.lang.Class Main.$noinline$getOtherClass() sharpening (after) - /// CHECK: LoadClass load_kind:BssEntry class_name:Other - - /// CHECK-START-MIPS64: java.lang.Class Main.$noinline$getOtherClass() sharpening (after) - /// CHECK: LoadClass load_kind:BssEntry class_name:Other - public static Class<?> $noinline$getOtherClass() { // Prevent inlining to avoid the string comparison being optimized away. if (doThrow) { throw new Error(); } diff --git a/test/642-fp-callees/fp_callees.cc b/test/642-fp-callees/fp_callees.cc index 600f9690eb..17bb55b70d 100644 --- a/test/642-fp-callees/fp_callees.cc +++ b/test/642-fp-callees/fp_callees.cc @@ -14,8 +14,9 @@ * limitations under the License. */ +#include <android-base/logging.h> + #include "base/casts.h" -#include "base/logging.h" #include "jni.h" namespace art { diff --git a/test/667-jit-jni-stub/src/Main.java b/test/667-jit-jni-stub/src/Main.java index b867970eab..794308d6e1 100644 --- a/test/667-jit-jni-stub/src/Main.java +++ b/test/667-jit-jni-stub/src/Main.java @@ -135,13 +135,16 @@ public class Main { int count = 0; while (!hasJitCompiledEntrypoint(Main.class, "callThrough")) { // If `call` is true, also exercise the `callThrough()` method to increase hotness. - int limit = call ? 1 << Math.min(count, 12) : 0; + // Ramp-up the number of calls we do up to 1 << 12. + final int rampUpCutOff = 12; + int limit = call ? 1 << Math.min(count, rampUpCutOff) : 0; for (int i = 0; i < limit; ++i) { callThrough(Main.class, "doNothing"); } try { - // Sleep to give a chance for the JIT to compile `hasJit` stub. - Thread.sleep(100); + // Sleep to give a chance for the JIT to compile `callThrough` stub. + // After the ramp-up phase, give the JIT even more time to compile. + Thread.sleep(count >= rampUpCutOff ? 200 : 100); } catch (Exception e) { // Ignore } diff --git a/test/671-npe-field-opts/expected.txt b/test/671-npe-field-opts/expected.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/671-npe-field-opts/expected.txt diff --git a/test/671-npe-field-opts/info.txt b/test/671-npe-field-opts/info.txt new file mode 100644 index 0000000000..f1e584633f --- /dev/null +++ b/test/671-npe-field-opts/info.txt @@ -0,0 +1,3 @@ +Regression test for the compiler, which used to +re-order or remove field access in a way that would confuse the runtime +when validating a NPE. diff --git a/test/671-npe-field-opts/src/Main.java b/test/671-npe-field-opts/src/Main.java new file mode 100644 index 0000000000..a5e81ce672 --- /dev/null +++ b/test/671-npe-field-opts/src/Main.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public class Main { + static Main obj; + // Make 'doCheck' volatile to prevent optimizations + // in $noinline$bar like LICM that could hoist the null check + // out of the loop. + static volatile boolean doCheck = true; + + float floatField; + int intField; + + public static void main(String[] args) { + try { + $noinline$bar(); + throw new Error("Expected NPE"); + } catch (NullPointerException e) { + check(e, 29, 52, "$noinline$bar"); + } + + try { + $noinline$foo(); + throw new Error("Expected NPE"); + } catch (NullPointerException e) { + check(e, 36, 44, "$noinline$foo"); + } + } + + public static float $noinline$foo() { + int v1 = obj.intField; + float v2 = obj.floatField; + return v2; + } + + public static float $noinline$bar() { + float a = 0; + while (doCheck) { + float f = obj.floatField; + int i = obj.intField; + a = (float)i + f; + } + return a; + } + + static void check(NullPointerException npe, int mainLine, int methodLine, String methodName) { + StackTraceElement[] trace = npe.getStackTrace(); + checkElement(trace[0], "Main", methodName, "Main.java", methodLine); + checkElement(trace[1], "Main", "main", "Main.java", mainLine); + } + + static void checkElement(StackTraceElement element, + String declaringClass, String methodName, + String fileName, int lineNumber) { + assertEquals(declaringClass, element.getClassName()); + assertEquals(methodName, element.getMethodName()); + assertEquals(fileName, element.getFileName()); + assertEquals(lineNumber, element.getLineNumber()); + } + + static void assertEquals(Object expected, Object actual) { + if (!expected.equals(actual)) { + String msg = "Expected \"" + expected + "\" but got \"" + actual + "\""; + throw new AssertionError(msg); + } + } + + static void assertEquals(int expected, int actual) { + if (expected != actual) { + throw new AssertionError("Expected " + expected + " got " + actual); + } + } +} diff --git a/test/900-hello-plugin/load_unload.cc b/test/900-hello-plugin/load_unload.cc index 19312b4d71..cab0abf58b 100644 --- a/test/900-hello-plugin/load_unload.cc +++ b/test/900-hello-plugin/load_unload.cc @@ -17,9 +17,10 @@ #include <jni.h> #include <stdio.h> +#include <android-base/logging.h> +#include <android-base/macros.h> + #include "art_method-inl.h" -#include "base/logging.h" -#include "base/macros.h" #include "java_vm_ext.h" #include "runtime.h" diff --git a/test/936-search-onload/search_onload.cc b/test/936-search-onload/search_onload.cc index 90d87e0e7b..23cea83be6 100644 --- a/test/936-search-onload/search_onload.cc +++ b/test/936-search-onload/search_onload.cc @@ -18,8 +18,9 @@ #include <inttypes.h> -#include "android-base/stringprintf.h" -#include "base/logging.h" +#include <android-base/macros.h> +#include <android-base/stringprintf.h> + #include "base/macros.h" #include "jni.h" #include "jvmti.h" diff --git a/test/983-source-transform-verify/source_transform.cc b/test/983-source-transform-verify/source_transform.cc index ca3f88b347..3010d7a1a4 100644 --- a/test/983-source-transform-verify/source_transform.cc +++ b/test/983-source-transform-verify/source_transform.cc @@ -25,7 +25,6 @@ #include "jni.h" #include "jvmti.h" -#include "base/logging.h" #include "base/macros.h" #include "bytecode_utils.h" #include "dex_file.h" diff --git a/test/common/runtime_state.cc b/test/common/runtime_state.cc index 34580800cc..1eed80ec91 100644 --- a/test/common/runtime_state.cc +++ b/test/common/runtime_state.cc @@ -16,9 +16,11 @@ #include "jni.h" +#include <android-base/logging.h> +#include <android-base/macros.h> + #include "art_method-inl.h" #include "base/enums.h" -#include "base/logging.h" #include "dex_file-inl.h" #include "instrumentation.h" #include "jit/jit.h" diff --git a/test/common/stack_inspect.cc b/test/common/stack_inspect.cc index 80a278012d..046b1fbcdd 100644 --- a/test/common/stack_inspect.cc +++ b/test/common/stack_inspect.cc @@ -16,7 +16,9 @@ #include "jni.h" -#include "base/logging.h" +#include <android-base/logging.h> + +#include "base/mutex.h" #include "dex_file-inl.h" #include "jni_internal.h" #include "mirror/class-inl.h" diff --git a/test/etc/run-test-jar b/test/etc/run-test-jar index 31f43fc536..4844d1e758 100755 --- a/test/etc/run-test-jar +++ b/test/etc/run-test-jar @@ -184,6 +184,10 @@ while true; do elif [ "x$1" = "x--prebuild" ]; then PREBUILD="y" shift + elif [ "x$1" = "x--compact-dex-level" ]; then + shift + COMPILE_FLAGS="${COMPILE_FLAGS} --compact-dex-level=$1" + shift elif [ "x$1" = "x--jvmti-redefine-stress" ]; then # APP_IMAGE doesn't really work with jvmti redefine stress USE_JVMTI="y" diff --git a/test/knownfailures.json b/test/knownfailures.json index 5cd788816a..ae1830af5c 100644 --- a/test/knownfailures.json +++ b/test/knownfailures.json @@ -383,7 +383,7 @@ "tests": ["629-vdex-speed", "634-vdex-duplicate"], "description": ["Profile driven dexlayout does not work with vdex or dex verifier."], - "variant": "speed-profile" + "variant": "speed-profile | cdex-fast" }, { "test_patterns": ["616-cha.*"], @@ -649,5 +649,11 @@ "tests": "661-oat-writer-layout", "variant": "interp-ac | interpreter | jit | no-dex2oat | no-prebuild | no-image | trace", "description": ["Test is designed to only check --compiler-filter=speed"] + }, + { + "tests": ["628-vdex", "975-iface-private"], + "variant": "cdex-fast", + "description": ["CompactDex doesn't yet work with input-vdex or 975-iface private"] } + ] diff --git a/test/run-test b/test/run-test index fdb2ee47a7..75fe15c919 100755 --- a/test/run-test +++ b/test/run-test @@ -225,6 +225,11 @@ while true; do run_args="${run_args} --prebuild" prebuild_mode="yes" shift; + elif [ "x$1" = "x--compact-dex-level" ]; then + option="$1" + shift + run_args="${run_args} $option $1" + shift; elif [ "x$1" = "x--strip-dex" ]; then run_args="${run_args} --strip-dex" shift; @@ -660,6 +665,7 @@ if [ "$usage" = "yes" ]; then echo " -Xcompiler-option Pass an option to the compiler." echo " --build-option Pass an option to the build script." echo " --runtime-option Pass an option to the runtime." + echo " --compact-dex-level Specify a compact dex level to the compiler." echo " --debug Wait for the default debugger to attach." echo " --debug-agent <agent-path>" echo " Wait for the given debugger agent to attach. Currently" diff --git a/test/testrunner/testrunner.py b/test/testrunner/testrunner.py index 554b8a5429..93998579f3 100755 --- a/test/testrunner/testrunner.py +++ b/test/testrunner/testrunner.py @@ -141,6 +141,7 @@ def gather_test_info(): VARIANT_TYPE_DICT['debuggable'] = {'ndebuggable', 'debuggable'} VARIANT_TYPE_DICT['gc'] = {'gcstress', 'gcverify', 'cms'} VARIANT_TYPE_DICT['prebuild'] = {'no-prebuild', 'no-dex2oat', 'prebuild'} + VARIANT_TYPE_DICT['cdex_level'] = {'cdex-none', 'cdex-fast'} VARIANT_TYPE_DICT['relocate'] = {'relocate-npatchoat', 'relocate', 'no-relocate'} VARIANT_TYPE_DICT['jni'] = {'jni', 'forcecopy', 'checkjni'} VARIANT_TYPE_DICT['address_sizes'] = {'64', '32'} @@ -183,6 +184,9 @@ def setup_test_env(): if not _user_input_variants['prebuild']: # Default _user_input_variants['prebuild'].add('prebuild') + if not _user_input_variants['cdex_level']: # Default + _user_input_variants['cdex_level'].add('cdex-none') + # By default only run without jvmti if not _user_input_variants['jvmti']: _user_input_variants['jvmti'].add('no-jvmti') @@ -339,10 +343,11 @@ def run_tests(tests): _user_input_variants['relocate'], _user_input_variants['trace'], _user_input_variants['gc'], _user_input_variants['jni'], _user_input_variants['image'], _user_input_variants['pictest'], - _user_input_variants['debuggable'], _user_input_variants['jvmti']) + _user_input_variants['debuggable'], _user_input_variants['jvmti'], + _user_input_variants['cdex_level']) for test, target, run, prebuild, compiler, relocate, trace, gc, \ - jni, image, pictest, debuggable, jvmti in config: + jni, image, pictest, debuggable, jvmti, cdex_level in config: for address_size in _user_input_variants['address_sizes_target'][target]: if stop_testrunner: # When ART_TEST_KEEP_GOING is set to false, then as soon as a test @@ -356,6 +361,7 @@ def run_tests(tests): test_name += target + '-run-test-' test_name += run + '-' test_name += prebuild + '-' + test_name += cdex_level + '-' test_name += compiler + '-' test_name += relocate + '-' test_name += trace + '-' @@ -369,7 +375,7 @@ def run_tests(tests): test_name += address_size variant_set = {target, run, prebuild, compiler, relocate, trace, gc, jni, - image, pictest, debuggable, jvmti, address_size} + image, pictest, debuggable, jvmti, cdex_level, address_size} options_test = options_all @@ -386,6 +392,9 @@ def run_tests(tests): elif prebuild == 'no-dex2oat': options_test += ' --no-prebuild --no-dex2oat' + # Add option and remove the cdex- prefix. + options_test += ' --compact-dex-level ' + cdex_level.replace('cdex-','') + if compiler == 'optimizing': options_test += ' --optimizing' elif compiler == 'regalloc_gc': @@ -806,6 +815,7 @@ def parse_test_name(test_name): regex += '(' + '|'.join(VARIANT_TYPE_DICT['pictest']) + ')-' regex += '(' + '|'.join(VARIANT_TYPE_DICT['debuggable']) + ')-' regex += '(' + '|'.join(VARIANT_TYPE_DICT['jvmti']) + ')-' + regex += '(' + '|'.join(VARIANT_TYPE_DICT['cdex_level']) + ')-' regex += '(' + '|'.join(RUN_TEST_SET) + ')' regex += '(' + '|'.join(VARIANT_TYPE_DICT['address_sizes']) + ')$' match = re.match(regex, test_name) @@ -822,8 +832,9 @@ def parse_test_name(test_name): _user_input_variants['pictest'].add(match.group(10)) _user_input_variants['debuggable'].add(match.group(11)) _user_input_variants['jvmti'].add(match.group(12)) - _user_input_variants['address_sizes'].add(match.group(14)) - return {match.group(13)} + _user_input_variants['cdex_level'].add(match.group(13)) + _user_input_variants['address_sizes'].add(match.group(15)) + return {match.group(14)} raise ValueError(test_name + " is not a valid test") diff --git a/test/ti-agent/common_load.cc b/test/ti-agent/common_load.cc index d85f33a05d..9a7352e479 100644 --- a/test/ti-agent/common_load.cc +++ b/test/ti-agent/common_load.cc @@ -17,7 +17,8 @@ #include <jni.h> #include <stdio.h> -#include "base/logging.h" +#include <android-base/logging.h> + #include "base/macros.h" #include "jni_binder.h" diff --git a/tools/jfuzz/README.md b/tools/jfuzz/README.md index 10d175b83d..4edfe1b35b 100644 --- a/tools/jfuzz/README.md +++ b/tools/jfuzz/README.md @@ -28,6 +28,8 @@ where (higher values yield deeper nested conditionals) -n : defines a fuzzing nest for for/while/do-while loops (higher values yield deeper nested loops) + -t : defines a fuzzing nest for try-catch-finally blocks + (higher values yield deeper nested try-catch-finally blocks) -v : prints version number and exits -h : prints help and exits diff --git a/tools/jfuzz/jfuzz.cc b/tools/jfuzz/jfuzz.cc index 7990c6cf8e..a6034c8c3a 100644 --- a/tools/jfuzz/jfuzz.cc +++ b/tools/jfuzz/jfuzz.cc @@ -31,8 +31,6 @@ namespace { * Operators. */ -#define EMIT(x) fputs((x)[random0(sizeof(x)/sizeof(const char*))], out_); - static constexpr const char* kIncDecOps[] = { "++", "--" }; static constexpr const char* kIntUnaryOps[] = { "+", "-", "~" }; static constexpr const char* kFpUnaryOps[] = { "+", "-" }; @@ -51,11 +49,21 @@ static constexpr const char* kBoolRelOps[] = { "==", "!=" }; static constexpr const char* kRelOps[] = { "==", "!=", ">", ">=", "<", "<=" }; /* + * Exceptions. + */ +static const char* kExceptionTypes[] = { + "IllegalStateException", + "NullPointerException", + "IllegalArgumentException", + "ArrayIndexOutOfBoundsException" +}; + +/* * Version of JFuzz. Increase this each time changes are made to the program * to preserve the property that a given version of JFuzz yields the same * fuzzed program for a deterministic random seed. */ -const char* VERSION = "1.4"; +const char* VERSION = "1.5"; /* * Maximum number of array dimensions, together with corresponding maximum size @@ -64,6 +72,14 @@ const char* VERSION = "1.4"; static const uint32_t kMaxDim = 10; static const uint32_t kMaxDimSize[kMaxDim + 1] = { 0, 1000, 32, 10, 6, 4, 3, 3, 2, 2, 2 }; +/* + * Utility function to return the number of elements in an array. + */ +template <typename T, uint32_t N> +constexpr uint32_t countof(T const (&)[N]) { + return N; +} + /** * A class that generates a random program that compiles correctly. The program * is generated using rules that generate various programming constructs. Each rule @@ -78,7 +94,8 @@ class JFuzz { uint32_t expr_depth, uint32_t stmt_length, uint32_t if_nest, - uint32_t loop_nest) + uint32_t loop_nest, + uint32_t try_nest) : out_(out), fuzz_random_engine_(seed), fuzz_seed_(seed), @@ -86,6 +103,7 @@ class JFuzz { fuzz_stmt_length_(stmt_length), fuzz_if_nest_(if_nest), fuzz_loop_nest_(loop_nest), + fuzz_try_nest_(try_nest), return_type_(randomType()), array_type_(randomType()), array_dim_(random1(kMaxDim)), @@ -97,6 +115,7 @@ class JFuzz { loop_nest_(0), switch_nest_(0), do_nest_(0), + try_nest_(0), boolean_local_(0), int_local_(0), long_local_(0), @@ -168,6 +187,12 @@ class JFuzz { } } + // Emits a random strong selected from an array of operator strings. + template <std::uint32_t N> + inline void emitOneOf(const char* const (&ops)[N]) { + fputs(ops[random0(N)], out_); + } + // // Expressions. // @@ -177,9 +202,9 @@ class JFuzz { if (tp == kBoolean) { fputc('!', out_); } else if (isInteger(tp)) { - EMIT(kIntUnaryOps); + emitOneOf(kIntUnaryOps); } else { // isFP(tp) - EMIT(kFpUnaryOps); + emitOneOf(kFpUnaryOps); } } @@ -188,38 +213,38 @@ class JFuzz { if (tp == kBoolean) { // Not applicable, just leave "as is". } else { // isInteger(tp) || isFP(tp) - EMIT(kIncDecOps); + emitOneOf(kIncDecOps); } } // Emit a binary operator (same type in-out). void emitBinaryOp(Type tp) { if (tp == kBoolean) { - EMIT(kBoolBinOps); + emitOneOf(kBoolBinOps); } else if (isInteger(tp)) { - EMIT(kIntBinOps); + emitOneOf(kIntBinOps); } else { // isFP(tp) - EMIT(kFpBinOps); + emitOneOf(kFpBinOps); } } // Emit an assignment operator (same type in-out). void emitAssignmentOp(Type tp) { if (tp == kBoolean) { - EMIT(kBoolAssignOps); + emitOneOf(kBoolAssignOps); } else if (isInteger(tp)) { - EMIT(kIntAssignOps); + emitOneOf(kIntAssignOps); } else { // isFP(tp) - EMIT(kFpAssignOps); + emitOneOf(kFpAssignOps); } } // Emit a relational operator (one type in, boolean out). void emitRelationalOp(Type tp) { if (tp == kBoolean) { - EMIT(kBoolRelOps); + emitOneOf(kBoolRelOps); } else { // isInteger(tp) || isFP(tp) - EMIT(kRelOps); + emitOneOf(kRelOps); } } @@ -808,7 +833,7 @@ class JFuzz { fputs("{\n", out_); indentation_ += 2; emitIndentation(); - fprintf(out_, "int i%u = %d;", loop_nest_, isWhile ? -1 : 0); + fprintf(out_, "int i%u = %d;\n", loop_nest_, isWhile ? -1 : 0); emitIndentation(); if (isWhile) { fprintf(out_, "while (++i%u < ", loop_nest_); @@ -871,6 +896,73 @@ class JFuzz { return mayFollowTrue || mayFollowFalse; } + bool emitTry() { + fputs("try {\n", out_); + indentation_ += 2; + bool mayFollow = emitStatementList(); + indentation_ -= 2; + emitIndentation(); + fputc('}', out_); + return mayFollow; + } + + bool emitCatch() { + uint32_t count = random1(countof(kExceptionTypes)); + bool mayFollow = false; + for (uint32_t i = 0; i < count; ++i) { + fprintf(out_, " catch (%s ex%u_%u) {\n", kExceptionTypes[i], try_nest_, i); + indentation_ += 2; + mayFollow |= emitStatementList(); + indentation_ -= 2; + emitIndentation(); + fputc('}', out_); + } + return mayFollow; + } + + bool emitFinally() { + fputs(" finally {\n", out_); + indentation_ += 2; + bool mayFollow = emitStatementList(); + indentation_ -= 2; + emitIndentation(); + fputc('}', out_); + return mayFollow; + } + + // Emit a try-catch-finally block. + bool emitTryCatchFinally() { + // Apply a hard limit on the number of catch blocks. This is for + // javac which fails if blocks within try-catch-finally are too + // large (much less than you'd expect). + if (try_nest_ > fuzz_try_nest_) { + return emitAssignment(); // fall back + } + + ++try_nest_; // Entering try-catch-finally + + bool mayFollow = emitTry(); + switch (random0(3)) { + case 0: // try..catch + mayFollow |= emitCatch(); + break; + case 1: // try..finally + mayFollow &= emitFinally(); + break; + case 2: // try..catch..finally + // When determining whether code may follow, we observe that a + // finally block always follows after try and catch + // block. Code may only follow if the finally block permits + // and either the try or catch block allows code to follow. + mayFollow = (mayFollow | emitCatch()) & emitFinally(); + break; + } + fputc('\n', out_); + + --try_nest_; // Leaving try-catch-finally + return mayFollow; + } + // Emit a switch statement. bool emitSwitch() { // Continuing if nest becomes less likely as the depth grows. @@ -915,6 +1007,11 @@ class JFuzz { return mayFollow; } + bool emitNopCall() { + fputs("nop();\n", out_); + return true; + } + // Emit an assignment statement. bool emitAssignment() { Type tp = randomType(); @@ -930,16 +1027,18 @@ class JFuzz { // Emit a single statement. Returns true if statements may follow. bool emitStatement() { switch (random1(16)) { // favor assignments - case 1: return emitReturn(false); break; - case 2: return emitContinue(); break; - case 3: return emitBreak(); break; - case 4: return emitScope(); break; - case 5: return emitArrayInit(); break; - case 6: return emitForLoop(); break; - case 7: return emitDoLoop(); break; - case 8: return emitIfStmt(); break; - case 9: return emitSwitch(); break; - default: return emitAssignment(); break; + case 1: return emitReturn(false); break; + case 2: return emitContinue(); break; + case 3: return emitBreak(); break; + case 4: return emitScope(); break; + case 5: return emitArrayInit(); break; + case 6: return emitForLoop(); break; + case 7: return emitDoLoop(); break; + case 8: return emitIfStmt(); break; + case 9: return emitSwitch(); break; + case 10: return emitTryCatchFinally(); break; + case 11: return emitNopCall(); break; + default: return emitAssignment(); break; } } @@ -1109,6 +1208,11 @@ class JFuzz { fputs(" }\n", out_); } + // Emit a static void method. + void emitStaticNopMethod() { + fputs(" public static void nop() {}\n", out_); + } + // Emit program header. Emit command line options in the comments. void emitHeader() { fputs("\n/**\n * AOSP JFuzz Tester.\n", out_); @@ -1133,6 +1237,7 @@ class JFuzz { emitArrayDecl(); emitTestConstructor(); emitTestMethod(); + emitStaticNopMethod(); emitMainMethod(); indentation_ -= 2; fputs("}\n\n", out_); @@ -1167,6 +1272,7 @@ class JFuzz { const uint32_t fuzz_stmt_length_; const uint32_t fuzz_if_nest_; const uint32_t fuzz_loop_nest_; + const uint32_t fuzz_try_nest_; // Return and array setup. const Type return_type_; @@ -1182,6 +1288,7 @@ class JFuzz { uint32_t loop_nest_; uint32_t switch_nest_; uint32_t do_nest_; + uint32_t try_nest_; uint32_t boolean_local_; uint32_t int_local_; uint32_t long_local_; @@ -1203,6 +1310,7 @@ int32_t main(int32_t argc, char** argv) { uint32_t stmt_length = 8; uint32_t if_nest = 2; uint32_t loop_nest = 3; + uint32_t try_nest = 2; // Parse options. while (1) { @@ -1226,6 +1334,9 @@ int32_t main(int32_t argc, char** argv) { case 'n': loop_nest = strtoul(optarg, nullptr, 0); break; + case 't': + try_nest = strtoul(optarg, nullptr, 0); + break; case 'v': fprintf(stderr, "jfuzz version %s\n", VERSION); return 0; @@ -1234,7 +1345,7 @@ int32_t main(int32_t argc, char** argv) { fprintf(stderr, "usage: %s [-s seed] " "[-d expr-depth] [-l stmt-length] " - "[-i if-nest] [-n loop-nest] [-v] [-h]\n", + "[-i if-nest] [-n loop-nest] [-t try-nest] [-v] [-h]\n", argv[0]); return 1; } @@ -1244,7 +1355,7 @@ int32_t main(int32_t argc, char** argv) { srand(seed); // Generate fuzzed program. - JFuzz fuzz(stdout, seed, expr_depth, stmt_length, if_nest, loop_nest); + JFuzz fuzz(stdout, seed, expr_depth, stmt_length, if_nest, loop_nest, try_nest); fuzz.emitProgram(); return 0; } diff --git a/tools/libjdwp_oj_art_failures.txt b/tools/libjdwp_oj_art_failures.txt index e1cc831303..145022e7eb 100644 --- a/tools/libjdwp_oj_art_failures.txt +++ b/tools/libjdwp_oj_art_failures.txt @@ -79,5 +79,11 @@ result: EXEC_FAILED, bug: 69591477, name: "org.apache.harmony.jpda.tests.jdwp.VirtualMachine.ExitTest#testExit001" +}, +{ + description: "Test times out on fugu-debug", + result: EXEC_FAILED, + bug: 70459916, + name: "org.apache.harmony.jpda.tests.jdwp.VMDebug.VMDebugTest#testVMDebug" } ] |