Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 17 | #include "compiler.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 18 | #include "compiler_internals.h" |
| 19 | #include "driver/compiler_driver.h" |
Dave Allison | 39c3bfb | 2014-01-28 18:33:52 -0800 | [diff] [blame] | 20 | #include "driver/compiler_options.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 21 | #include "dataflow_iterator-inl.h" |
| 22 | #include "leb128.h" |
| 23 | #include "mirror/object.h" |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 24 | #include "pass_driver.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 25 | #include "runtime.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 26 | #include "base/logging.h" |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 27 | #include "base/timing_logger.h" |
Dave Allison | 39c3bfb | 2014-01-28 18:33:52 -0800 | [diff] [blame] | 28 | #include "driver/compiler_options.h" |
Vladimir Marko | 5c96e6b | 2013-11-14 15:34:17 +0000 | [diff] [blame] | 29 | #include "dex/quick/dex_file_to_method_inliner_map.h" |
| 30 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 31 | namespace art { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 32 | |
Vladimir Marko | 867a2b3 | 2013-12-10 13:01:13 +0000 | [diff] [blame] | 33 | extern "C" void ArtInitQuickCompilerContext(art::CompilerDriver& driver) { |
| 34 | CHECK(driver.GetCompilerContext() == NULL); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Vladimir Marko | 867a2b3 | 2013-12-10 13:01:13 +0000 | [diff] [blame] | 37 | extern "C" void ArtUnInitQuickCompilerContext(art::CompilerDriver& driver) { |
Vladimir Marko | 5816ed4 | 2013-11-27 17:04:20 +0000 | [diff] [blame] | 38 | CHECK(driver.GetCompilerContext() == NULL); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | /* Default optimizer/debug setting for the compiler. */ |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 42 | static uint32_t kCompilerOptimizerDisableFlags = 0 | // Disable specific optimizations |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame^] | 43 | (1 << kLoadStoreElimination) | // TODO: this pass has been broken for awhile - fix or delete. |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 44 | // (1 << kLoadHoisting) | |
| 45 | // (1 << kSuppressLoads) | |
| 46 | // (1 << kNullCheckElimination) | |
Vladimir Marko | bfea9c2 | 2014-01-17 17:49:33 +0000 | [diff] [blame] | 47 | // (1 << kClassInitCheckElimination) | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 48 | // (1 << kPromoteRegs) | |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame^] | 49 | (1 << kTrackLiveTemps) | // FIXME: disable until liveness issue fixed. |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 50 | // (1 << kSafeOptimizations) | |
| 51 | // (1 << kBBOpt) | |
| 52 | // (1 << kMatch) | |
| 53 | // (1 << kPromoteCompilerTemps) | |
buzbee | 17189ac | 2013-11-08 11:07:02 -0800 | [diff] [blame] | 54 | // (1 << kSuppressExceptionEdges) | |
Vladimir Marko | 9820b7c | 2014-01-02 16:40:37 +0000 | [diff] [blame] | 55 | // (1 << kSuppressMethodInlining) | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 56 | 0; |
| 57 | |
| 58 | static uint32_t kCompilerDebugFlags = 0 | // Enable debug/testing modes |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 59 | // (1 << kDebugDisplayMissingTargets) | |
| 60 | // (1 << kDebugVerbose) | |
| 61 | // (1 << kDebugDumpCFG) | |
| 62 | // (1 << kDebugSlowFieldPath) | |
| 63 | // (1 << kDebugSlowInvokePath) | |
| 64 | // (1 << kDebugSlowStringPath) | |
| 65 | // (1 << kDebugSlowestFieldPath) | |
| 66 | // (1 << kDebugSlowestStringPath) | |
| 67 | // (1 << kDebugExerciseResolveMethod) | |
| 68 | // (1 << kDebugVerifyDataflow) | |
| 69 | // (1 << kDebugShowMemoryUsage) | |
| 70 | // (1 << kDebugShowNops) | |
| 71 | // (1 << kDebugCountOpcodes) | |
| 72 | // (1 << kDebugDumpCheckStats) | |
| 73 | // (1 << kDebugDumpBitcodeFile) | |
| 74 | // (1 << kDebugVerifyBitcode) | |
| 75 | // (1 << kDebugShowSummaryMemoryUsage) | |
buzbee | ee17e0a | 2013-07-31 10:47:37 -0700 | [diff] [blame] | 76 | // (1 << kDebugShowFilterStats) | |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 77 | // (1 << kDebugTimings) | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 78 | 0; |
| 79 | |
Vladimir Marko | 25724ef | 2013-11-12 15:09:20 +0000 | [diff] [blame] | 80 | CompilationUnit::CompilationUnit(ArenaPool* pool) |
| 81 | : compiler_driver(NULL), |
| 82 | class_linker(NULL), |
| 83 | dex_file(NULL), |
| 84 | class_loader(NULL), |
| 85 | class_def_idx(0), |
| 86 | method_idx(0), |
| 87 | code_item(NULL), |
| 88 | access_flags(0), |
| 89 | invoke_type(kDirect), |
| 90 | shorty(NULL), |
| 91 | disable_opt(0), |
| 92 | enable_debug(0), |
| 93 | verbose(false), |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 94 | compiler(NULL), |
Vladimir Marko | 25724ef | 2013-11-12 15:09:20 +0000 | [diff] [blame] | 95 | instruction_set(kNone), |
| 96 | num_dalvik_registers(0), |
| 97 | insns(NULL), |
| 98 | num_ins(0), |
| 99 | num_outs(0), |
| 100 | num_regs(0), |
Vladimir Marko | 25724ef | 2013-11-12 15:09:20 +0000 | [diff] [blame] | 101 | compiler_flip_match(false), |
| 102 | arena(pool), |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 103 | arena_stack(pool), |
Vladimir Marko | 25724ef | 2013-11-12 15:09:20 +0000 | [diff] [blame] | 104 | mir_graph(NULL), |
| 105 | cg(NULL), |
| 106 | timings("QuickCompiler", true, false) { |
| 107 | } |
| 108 | |
| 109 | CompilationUnit::~CompilationUnit() { |
| 110 | } |
| 111 | |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 112 | void CompilationUnit::StartTimingSplit(const char* label) { |
Nicolas Geoffray | ea3fa0b | 2014-02-10 11:59:41 +0000 | [diff] [blame] | 113 | if (compiler_driver->GetDumpPasses()) { |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 114 | timings.StartSplit(label); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | void CompilationUnit::NewTimingSplit(const char* label) { |
Nicolas Geoffray | ea3fa0b | 2014-02-10 11:59:41 +0000 | [diff] [blame] | 119 | if (compiler_driver->GetDumpPasses()) { |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 120 | timings.NewSplit(label); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | void CompilationUnit::EndTiming() { |
Nicolas Geoffray | ea3fa0b | 2014-02-10 11:59:41 +0000 | [diff] [blame] | 125 | if (compiler_driver->GetDumpPasses()) { |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 126 | timings.EndSplit(); |
Nicolas Geoffray | ea3fa0b | 2014-02-10 11:59:41 +0000 | [diff] [blame] | 127 | if (enable_debug & (1 << kDebugTimings)) { |
| 128 | LOG(INFO) << "TIMINGS " << PrettyMethod(method_idx, *dex_file); |
| 129 | LOG(INFO) << Dumpable<TimingLogger>(timings); |
| 130 | } |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 134 | static CompiledMethod* CompileMethod(CompilerDriver& driver, |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 135 | Compiler* compiler, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 136 | const DexFile::CodeItem* code_item, |
| 137 | uint32_t access_flags, InvokeType invoke_type, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 138 | uint16_t class_def_idx, uint32_t method_idx, |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 139 | jobject class_loader, const DexFile& dex_file, |
| 140 | void* llvm_compilation_unit) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 141 | VLOG(compiler) << "Compiling " << PrettyMethod(method_idx, dex_file) << "..."; |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 142 | if (code_item->insns_size_in_code_units_ >= 0x10000) { |
| 143 | LOG(INFO) << "Method size exceeds compiler limits: " << code_item->insns_size_in_code_units_ |
| 144 | << " in " << PrettyMethod(method_idx, dex_file); |
| 145 | return NULL; |
| 146 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 147 | |
Jeff Hao | 4a200f5 | 2014-04-01 14:58:49 -0700 | [diff] [blame] | 148 | if (!driver.GetCompilerOptions().IsCompilationEnabled()) { |
Ian Rogers | a03de6d | 2014-03-08 23:37:07 +0000 | [diff] [blame] | 149 | return nullptr; |
| 150 | } |
| 151 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 152 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 153 | CompilationUnit cu(driver.GetArenaPool()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 154 | |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 155 | cu.compiler_driver = &driver; |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 156 | cu.class_linker = class_linker; |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 157 | cu.instruction_set = driver.GetInstructionSet(); |
Mathieu Chartier | 53bee42 | 2014-04-04 16:10:05 -0700 | [diff] [blame] | 158 | if (cu.instruction_set == kArm) { |
| 159 | cu.instruction_set = kThumb2; |
| 160 | } |
Andreas Gampe | af13ad9 | 2014-04-11 12:07:48 -0700 | [diff] [blame] | 161 | cu.target64 = Is64BitInstructionSet(cu.instruction_set); |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 162 | cu.compiler = compiler; |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 163 | // TODO: x86_64 & arm64 are not yet implemented. |
Mathieu Chartier | 53bee42 | 2014-04-04 16:10:05 -0700 | [diff] [blame] | 164 | CHECK((cu.instruction_set == kThumb2) || |
| 165 | (cu.instruction_set == kX86) || |
| 166 | (cu.instruction_set == kX86_64) || |
| 167 | (cu.instruction_set == kMips)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 168 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 169 | /* Adjust this value accordingly once inlining is performed */ |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 170 | cu.num_dalvik_registers = code_item->registers_size_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 171 | // TODO: set this from command line |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 172 | cu.compiler_flip_match = false; |
| 173 | bool use_match = !cu.compiler_method_match.empty(); |
| 174 | bool match = use_match && (cu.compiler_flip_match ^ |
| 175 | (PrettyMethod(method_idx, dex_file).find(cu.compiler_method_match) != |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 176 | std::string::npos)); |
| 177 | if (!use_match || match) { |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 178 | cu.disable_opt = kCompilerOptimizerDisableFlags; |
| 179 | cu.enable_debug = kCompilerDebugFlags; |
| 180 | cu.verbose = VLOG_IS_ON(compiler) || |
| 181 | (cu.enable_debug & (1 << kDebugVerbose)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Mingyao Yang | 42d65c5 | 2014-04-18 16:49:39 -0700 | [diff] [blame] | 184 | if (gVerboseMethods.size() != 0) { |
| 185 | cu.verbose = false; |
| 186 | for (size_t i = 0; i < gVerboseMethods.size(); ++i) { |
| 187 | if (PrettyMethod(method_idx, dex_file).find(gVerboseMethods[i]) |
| 188 | != std::string::npos) { |
| 189 | cu.verbose = true; |
| 190 | break; |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 195 | /* |
| 196 | * TODO: rework handling of optimization and debug flags. Should we split out |
| 197 | * MIR and backend flags? Need command-line setting as well. |
| 198 | */ |
| 199 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 200 | compiler->InitCompilationUnit(cu); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 201 | |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 202 | if (cu.instruction_set == kMips) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 203 | // Disable some optimizations for mips for now |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 204 | cu.disable_opt |= ( |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 205 | (1 << kLoadStoreElimination) | |
| 206 | (1 << kLoadHoisting) | |
| 207 | (1 << kSuppressLoads) | |
| 208 | (1 << kNullCheckElimination) | |
| 209 | (1 << kPromoteRegs) | |
| 210 | (1 << kTrackLiveTemps) | |
| 211 | (1 << kSafeOptimizations) | |
| 212 | (1 << kBBOpt) | |
| 213 | (1 << kMatch) | |
| 214 | (1 << kPromoteCompilerTemps)); |
| 215 | } |
| 216 | |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 217 | cu.StartTimingSplit("BuildMIRGraph"); |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 218 | cu.mir_graph.reset(new MIRGraph(&cu, &cu.arena)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 219 | |
Razvan A Lupusoru | da7a69b | 2014-01-08 15:09:50 -0800 | [diff] [blame] | 220 | /* |
| 221 | * After creation of the MIR graph, also create the code generator. |
| 222 | * The reason we do this is that optimizations on the MIR graph may need to get information |
| 223 | * that is only available if a CG exists. |
| 224 | */ |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 225 | cu.cg.reset(compiler->GetCodeGenerator(&cu, llvm_compilation_unit)); |
Razvan A Lupusoru | da7a69b | 2014-01-08 15:09:50 -0800 | [diff] [blame] | 226 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 227 | /* Gathering opcode stats? */ |
| 228 | if (kCompilerDebugFlags & (1 << kDebugCountOpcodes)) { |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 229 | cu.mir_graph->EnableOpcodeCounting(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Dave Allison | 39c3bfb | 2014-01-28 18:33:52 -0800 | [diff] [blame] | 232 | // Check early if we should skip this compilation if using the profiled filter. |
| 233 | if (cu.compiler_driver->ProfilePresent()) { |
| 234 | std::string methodname = PrettyMethod(method_idx, dex_file); |
| 235 | if (cu.mir_graph->SkipCompilation(methodname)) { |
| 236 | return NULL; |
| 237 | } |
| 238 | } |
| 239 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 240 | /* Build the raw MIR graph */ |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 241 | cu.mir_graph->InlineMethod(code_item, access_flags, invoke_type, class_def_idx, method_idx, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 242 | class_loader, dex_file); |
| 243 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 244 | cu.NewTimingSplit("MIROpt:CheckFilters"); |
Jeff Hao | 4a200f5 | 2014-04-01 14:58:49 -0700 | [diff] [blame] | 245 | if (cu.mir_graph->SkipCompilation()) { |
| 246 | return NULL; |
buzbee | ee17e0a | 2013-07-31 10:47:37 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 249 | /* Create the pass driver and launch it */ |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 250 | PassDriver pass_driver(&cu); |
| 251 | pass_driver.Launch(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 252 | |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 253 | if (cu.enable_debug & (1 << kDebugDumpCheckStats)) { |
| 254 | cu.mir_graph->DumpCheckStats(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | if (kCompilerDebugFlags & (1 << kDebugCountOpcodes)) { |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 258 | cu.mir_graph->ShowOpcodeStats(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 259 | } |
| 260 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 261 | /* Reassociate sreg names with original Dalvik vreg names. */ |
| 262 | cu.mir_graph->RemapRegLocations(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 263 | |
Vladimir Marko | 53b6afc | 2014-03-21 14:21:20 +0000 | [diff] [blame] | 264 | /* Free Arenas from the cu.arena_stack for reuse by the cu.arena in the codegen. */ |
| 265 | if (cu.enable_debug & (1 << kDebugShowMemoryUsage)) { |
| 266 | if (cu.arena_stack.PeakBytesAllocated() > 256 * 1024) { |
| 267 | MemStats stack_stats(cu.arena_stack.GetPeakStats()); |
| 268 | LOG(INFO) << PrettyMethod(method_idx, dex_file) << " " << Dumpable<MemStats>(stack_stats); |
| 269 | } |
| 270 | } |
| 271 | cu.arena_stack.Reset(); |
| 272 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 273 | CompiledMethod* result = NULL; |
| 274 | |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 275 | cu.cg->Materialize(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 276 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 277 | cu.NewTimingSplit("Dedupe"); /* deduping takes up the vast majority of time in GetCompiledMethod(). */ |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 278 | result = cu.cg->GetCompiledMethod(); |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 279 | cu.NewTimingSplit("Cleanup"); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 280 | |
| 281 | if (result) { |
| 282 | VLOG(compiler) << "Compiled " << PrettyMethod(method_idx, dex_file); |
| 283 | } else { |
| 284 | VLOG(compiler) << "Deferred " << PrettyMethod(method_idx, dex_file); |
| 285 | } |
| 286 | |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 287 | if (cu.enable_debug & (1 << kDebugShowMemoryUsage)) { |
Vladimir Marko | 53b6afc | 2014-03-21 14:21:20 +0000 | [diff] [blame] | 288 | if (cu.arena.BytesAllocated() > (1 * 1024 *1024)) { |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 289 | MemStats mem_stats(cu.arena.GetMemStats()); |
Vladimir Marko | 53b6afc | 2014-03-21 14:21:20 +0000 | [diff] [blame] | 290 | LOG(INFO) << PrettyMethod(method_idx, dex_file) << " " << Dumpable<MemStats>(mem_stats); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 294 | if (cu.enable_debug & (1 << kDebugShowSummaryMemoryUsage)) { |
| 295 | LOG(INFO) << "MEMINFO " << cu.arena.BytesAllocated() << " " << cu.mir_graph->GetNumBlocks() |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 296 | << " " << PrettyMethod(method_idx, dex_file); |
| 297 | } |
| 298 | |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 299 | cu.EndTiming(); |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 300 | driver.GetTimingsLogger()->AddLogger(cu.timings); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 301 | return result; |
| 302 | } |
| 303 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 304 | CompiledMethod* CompileOneMethod(CompilerDriver& driver, |
| 305 | Compiler* compiler, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 306 | const DexFile::CodeItem* code_item, |
| 307 | uint32_t access_flags, |
| 308 | InvokeType invoke_type, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 309 | uint16_t class_def_idx, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 310 | uint32_t method_idx, |
| 311 | jobject class_loader, |
| 312 | const DexFile& dex_file, |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 313 | void* compilation_unit) { |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 314 | return CompileMethod(driver, compiler, code_item, access_flags, invoke_type, class_def_idx, |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 315 | method_idx, class_loader, dex_file, compilation_unit); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | } // namespace art |
| 319 | |
| 320 | extern "C" art::CompiledMethod* |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 321 | ArtQuickCompileMethod(art::CompilerDriver& driver, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 322 | const art::DexFile::CodeItem* code_item, |
| 323 | uint32_t access_flags, art::InvokeType invoke_type, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 324 | uint16_t class_def_idx, uint32_t method_idx, jobject class_loader, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 325 | const art::DexFile& dex_file) { |
| 326 | // TODO: check method fingerprint here to determine appropriate backend type. Until then, use build default |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 327 | art::Compiler* compiler = driver.GetCompiler(); |
| 328 | return art::CompileOneMethod(driver, compiler, code_item, access_flags, invoke_type, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 329 | class_def_idx, method_idx, class_loader, dex_file, |
| 330 | NULL /* use thread llvm_info */); |
| 331 | } |