Prevent verifier from creating unused compilation data.
The verifier used to create data which may be unused like GC map. This is the
case for non-compiled method (which are interpreted). This CL aims to optimize
this.
Here are the changes:
- Move compilation selection to MethodVerifier::IsCandidateForCompilation.
- Compiler and verifier use this method to know if a method must be compiled.
- Only create compilation data while compiling using Runtime::IsCompiler.
- Do not create internal structures concerning GC map, ... in Runtime::Init and
Runtime::Shutdown when we are not compiling.
- Checks we are compiling when accessing these structures.
- Add missing destruction of MethodVerifier::safecast_map_lock_ and
MethodVerifier::safecast_map_ in Runtime::Shutdown.
- Call Runtime::Shutdown just before Runtime instance is destroyed to avoid a
crash.
- Add missing "GUARDED_BY" macro for MethodVerifier::rejected_classes_ field.
- Add "has_check_casts" to avoid the safecast pass if there is no check-cast
instruction.
- Add "has_virtual_or_interface_invokes" to avoid the devirtualization pass if
there is no invoke-virtual/range nor invoke-interface/range instructions.
Bug: 9987437
Change-Id: I418ee99f63e4203409cf5b7d2c2295b22fcf24c1
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index 2aa2a98..8ce0aa9 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -2240,18 +2240,8 @@
CHECK(compiled_method != NULL);
} else if ((access_flags & kAccAbstract) != 0) {
} else {
- // In small mode we only compile image classes.
- bool dont_compile = (Runtime::Current()->IsSmallMode() &&
- ((image_classes_.get() == NULL) || (image_classes_->size() == 0)));
-
- // Don't compile class initializers, ever.
- if (((access_flags & kAccConstructor) != 0) && ((access_flags & kAccStatic) != 0)) {
- dont_compile = true;
- } else if (code_item->insns_size_in_code_units_ < Runtime::Current()->GetSmallModeMethodDexSizeLimit()) {
- // Do compile small methods.
- dont_compile = false;
- }
- if (!dont_compile) {
+ bool compile = verifier::MethodVerifier::IsCandidateForCompilation(code_item, access_flags);
+ if (compile) {
CompilerFn compiler = compiler_;
#ifdef ART_SEA_IR_MODE
bool use_sea = Runtime::Current()->IsSeaIRMode();