diff options
author | 2021-07-14 14:59:25 +0100 | |
---|---|---|
committer | 2021-07-14 17:13:08 +0000 | |
commit | 9e050ab1a061d9660eb0c1daa01a823ad75b0f05 (patch) | |
tree | 714f2ba3b11406310416e85357f45450634846b2 /compiler/optimizing | |
parent | 4f990714b13e0b4446305a5411648a1a9ae42a7a (diff) |
Remove the need of VerifiedMethod in the compiler.
The compiler only needs to know if a method is compilable or not. So
just record a set of uncompilable methods (in some cases, we cannot have
an ArtMethod, but the method can still be compiled).
Test: test.py
Bug: 28313047
Change-Id: Ic4235bc8160ec91daa5ebf6504741089b43e99cb
Diffstat (limited to 'compiler/optimizing')
-rw-r--r-- | compiler/optimizing/builder.cc | 1 | ||||
-rw-r--r-- | compiler/optimizing/code_generator.cc | 1 | ||||
-rw-r--r-- | compiler/optimizing/inliner.cc | 19 | ||||
-rw-r--r-- | compiler/optimizing/optimizing_compiler.cc | 163 | ||||
-rw-r--r-- | compiler/optimizing/optimizing_compiler_stats.h | 2 |
5 files changed, 74 insertions, 112 deletions
diff --git a/compiler/optimizing/builder.cc b/compiler/optimizing/builder.cc index 3263e9ca3a..e7826bbba3 100644 --- a/compiler/optimizing/builder.cc +++ b/compiler/optimizing/builder.cc @@ -23,7 +23,6 @@ #include "block_builder.h" #include "code_generator.h" #include "data_type-inl.h" -#include "dex/verified_method.h" #include "driver/compiler_options.h" #include "driver/dex_compilation_unit.h" #include "instruction_builder.h" diff --git a/compiler/optimizing/code_generator.cc b/compiler/optimizing/code_generator.cc index a096338ee2..ca35d99f24 100644 --- a/compiler/optimizing/code_generator.cc +++ b/compiler/optimizing/code_generator.cc @@ -42,7 +42,6 @@ #include "compiled_method.h" #include "dex/bytecode_utils.h" #include "dex/code_item_accessors-inl.h" -#include "dex/verified_method.h" #include "graph_visualizer.h" #include "image.h" #include "gc/space/image_space.h" diff --git a/compiler/optimizing/inliner.cc b/compiler/optimizing/inliner.cc index 664126a54d..74eae430ad 100644 --- a/compiler/optimizing/inliner.cc +++ b/compiler/optimizing/inliner.cc @@ -26,8 +26,6 @@ #include "data_type-inl.h" #include "dead_code_elimination.h" #include "dex/inline_method_analyser.h" -#include "dex/verification_results.h" -#include "dex/verified_method.h" #include "driver/compiler_options.h" #include "driver/dex_compilation_unit.h" #include "instruction_simplifier.h" @@ -388,24 +386,9 @@ static bool IsMethodUnverified(const CompilerOptions& compiler_options, ArtMetho // We're at runtime, we know this is cold code if the class // is not verified, so don't bother analyzing. return true; - } - uint16_t class_def_idx = method->GetDeclaringClass()->GetDexClassDefIndex(); - - const VerifiedMethod* verified_method = - compiler_options.GetVerifiedMethod(method->GetDexFile(), method->GetDexMethodIndex()); - if (verified_method != nullptr && verified_method->HasRuntimeThrow()) { - // Compiler doesn't handle dead code as nicely as verifier. + } else if (!method->GetDeclaringClass()->IsVerifiedNeedsAccessChecks()) { return true; } - if (!compiler_options.IsMethodVerifiedWithoutFailures(method->GetDexMethodIndex(), - class_def_idx, - *method->GetDexFile())) { - if (verified_method == nullptr || - !verifier::CanCompilerHandleVerificationFailure( - verified_method->GetEncounteredVerificationFailures())) { - return true; - } - } } return false; } diff --git a/compiler/optimizing/optimizing_compiler.cc b/compiler/optimizing/optimizing_compiler.cc index b6ab9fb1b5..16abf9d37d 100644 --- a/compiler/optimizing/optimizing_compiler.cc +++ b/compiler/optimizing/optimizing_compiler.cc @@ -38,8 +38,6 @@ #include "debug/elf_debug_writer.h" #include "debug/method_debug_info.h" #include "dex/dex_file_types.h" -#include "dex/verification_results.h" -#include "dex/verified_method.h" #include "driver/compiled_method_storage.h" #include "driver/compiler_options.h" #include "driver/dex_compilation_unit.h" @@ -63,7 +61,6 @@ #include "ssa_phi_elimination.h" #include "stack_map_stream.h" #include "utils/assembler.h" -#include "verifier/verifier_compiler_binding.h" namespace art { @@ -1017,98 +1014,84 @@ CompiledMethod* OptimizingCompiler::Compile(const dex::CodeItem* code_item, CompiledMethod* compiled_method = nullptr; Runtime* runtime = Runtime::Current(); DCHECK(runtime->IsAotCompiler()); - const VerifiedMethod* verified_method = compiler_options.GetVerifiedMethod(&dex_file, method_idx); - DCHECK(!verified_method->HasRuntimeThrow()); - if (compiler_options.IsMethodVerifiedWithoutFailures(method_idx, class_def_idx, dex_file) || - verifier::CanCompilerHandleVerificationFailure( - verified_method->GetEncounteredVerificationFailures())) { - ArenaAllocator allocator(runtime->GetArenaPool()); - ArenaStack arena_stack(runtime->GetArenaPool()); - CodeVectorAllocator code_allocator(&allocator); - std::unique_ptr<CodeGenerator> codegen; - bool compiled_intrinsic = false; - { - ScopedObjectAccess soa(Thread::Current()); - ArtMethod* method = - runtime->GetClassLinker()->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>( - method_idx, dex_cache, jclass_loader, /*referrer=*/ nullptr, invoke_type); - DCHECK_EQ(method == nullptr, soa.Self()->IsExceptionPending()); - soa.Self()->ClearException(); // Suppress exception if any. - VariableSizedHandleScope handles(soa.Self()); - Handle<mirror::Class> compiling_class = - handles.NewHandle(method != nullptr ? method->GetDeclaringClass() : nullptr); - DexCompilationUnit dex_compilation_unit( - jclass_loader, - runtime->GetClassLinker(), - dex_file, - code_item, - class_def_idx, - method_idx, - access_flags, - /*verified_method=*/ nullptr, // Not needed by the Optimizing compiler. - dex_cache, - compiling_class); - // All signature polymorphic methods are native. - DCHECK(method == nullptr || !method->IsSignaturePolymorphic()); - // Go to native so that we don't block GC during compilation. - ScopedThreadSuspension sts(soa.Self(), kNative); - // Try to compile a fully intrinsified implementation. - if (method != nullptr && UNLIKELY(method->IsIntrinsic())) { - DCHECK(compiler_options.IsBootImage()); - codegen.reset( - TryCompileIntrinsic(&allocator, - &arena_stack, - &code_allocator, - dex_compilation_unit, - method, - &handles)); - if (codegen != nullptr) { - compiled_intrinsic = true; - } - } - if (codegen == nullptr) { - codegen.reset( - TryCompile(&allocator, - &arena_stack, - &code_allocator, - dex_compilation_unit, - method, - compiler_options.IsBaseline() - ? CompilationKind::kBaseline - : CompilationKind::kOptimized, - &handles)); + ArenaAllocator allocator(runtime->GetArenaPool()); + ArenaStack arena_stack(runtime->GetArenaPool()); + CodeVectorAllocator code_allocator(&allocator); + std::unique_ptr<CodeGenerator> codegen; + bool compiled_intrinsic = false; + { + ScopedObjectAccess soa(Thread::Current()); + ArtMethod* method = + runtime->GetClassLinker()->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>( + method_idx, dex_cache, jclass_loader, /*referrer=*/ nullptr, invoke_type); + DCHECK_EQ(method == nullptr, soa.Self()->IsExceptionPending()); + soa.Self()->ClearException(); // Suppress exception if any. + VariableSizedHandleScope handles(soa.Self()); + Handle<mirror::Class> compiling_class = + handles.NewHandle(method != nullptr ? method->GetDeclaringClass() : nullptr); + DexCompilationUnit dex_compilation_unit( + jclass_loader, + runtime->GetClassLinker(), + dex_file, + code_item, + class_def_idx, + method_idx, + access_flags, + /*verified_method=*/ nullptr, // Not needed by the Optimizing compiler. + dex_cache, + compiling_class); + // All signature polymorphic methods are native. + DCHECK(method == nullptr || !method->IsSignaturePolymorphic()); + // Go to native so that we don't block GC during compilation. + ScopedThreadSuspension sts(soa.Self(), kNative); + // Try to compile a fully intrinsified implementation. + if (method != nullptr && UNLIKELY(method->IsIntrinsic())) { + DCHECK(compiler_options.IsBootImage()); + codegen.reset( + TryCompileIntrinsic(&allocator, + &arena_stack, + &code_allocator, + dex_compilation_unit, + method, + &handles)); + if (codegen != nullptr) { + compiled_intrinsic = true; } } - if (codegen.get() != nullptr) { - compiled_method = Emit(&allocator, - &code_allocator, - codegen.get(), - compiled_intrinsic ? nullptr : code_item); - if (compiled_intrinsic) { - compiled_method->MarkAsIntrinsic(); - } + if (codegen == nullptr) { + codegen.reset( + TryCompile(&allocator, + &arena_stack, + &code_allocator, + dex_compilation_unit, + method, + compiler_options.IsBaseline() + ? CompilationKind::kBaseline + : CompilationKind::kOptimized, + &handles)); + } + } + if (codegen.get() != nullptr) { + compiled_method = Emit(&allocator, + &code_allocator, + codegen.get(), + compiled_intrinsic ? nullptr : code_item); + if (compiled_intrinsic) { + compiled_method->MarkAsIntrinsic(); + } - if (kArenaAllocatorCountAllocations) { - codegen.reset(); // Release codegen's ScopedArenaAllocator for memory accounting. - size_t total_allocated = allocator.BytesAllocated() + arena_stack.PeakBytesAllocated(); - if (total_allocated > kArenaAllocatorMemoryReportThreshold) { - MemStats mem_stats(allocator.GetMemStats()); - MemStats peak_stats(arena_stack.GetPeakStats()); - LOG(INFO) << "Used " << total_allocated << " bytes of arena memory for compiling " - << dex_file.PrettyMethod(method_idx) - << "\n" << Dumpable<MemStats>(mem_stats) - << "\n" << Dumpable<MemStats>(peak_stats); - } + if (kArenaAllocatorCountAllocations) { + codegen.reset(); // Release codegen's ScopedArenaAllocator for memory accounting. + size_t total_allocated = allocator.BytesAllocated() + arena_stack.PeakBytesAllocated(); + if (total_allocated > kArenaAllocatorMemoryReportThreshold) { + MemStats mem_stats(allocator.GetMemStats()); + MemStats peak_stats(arena_stack.GetPeakStats()); + LOG(INFO) << "Used " << total_allocated << " bytes of arena memory for compiling " + << dex_file.PrettyMethod(method_idx) + << "\n" << Dumpable<MemStats>(mem_stats) + << "\n" << Dumpable<MemStats>(peak_stats); } } - } else { - MethodCompilationStat method_stat; - if (compiler_options.VerifyAtRuntime()) { - method_stat = MethodCompilationStat::kNotCompiledVerifyAtRuntime; - } else { - method_stat = MethodCompilationStat::kNotCompiledVerificationError; - } - MaybeRecordStat(compilation_stats_.get(), method_stat); } if (kIsDebugBuild && diff --git a/compiler/optimizing/optimizing_compiler_stats.h b/compiler/optimizing/optimizing_compiler_stats.h index 3d0815f1eb..24d01539df 100644 --- a/compiler/optimizing/optimizing_compiler_stats.h +++ b/compiler/optimizing/optimizing_compiler_stats.h @@ -58,8 +58,6 @@ enum class MethodCompilationStat { kNotCompiledSpaceFilter, kNotCompiledUnhandledInstruction, kNotCompiledUnsupportedIsa, - kNotCompiledVerificationError, - kNotCompiledVerifyAtRuntime, kNotCompiledIrreducibleLoopAndStringInit, kNotCompiledPhiEquivalentInOsr, kInlinedMonomorphicCall, |