• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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 
17 #include "compiler.h"
18 
19 #include "base/logging.h"
20 #include "dex/quick/quick_compiler_factory.h"
21 #include "driver/compiler_driver.h"
22 #include "optimizing/optimizing_compiler.h"
23 #include "utils.h"
24 
25 namespace art {
26 
Create(CompilerDriver * driver,Compiler::Kind kind)27 Compiler* Compiler::Create(CompilerDriver* driver, Compiler::Kind kind) {
28   switch (kind) {
29     case kQuick:
30       return CreateQuickCompiler(driver);
31 
32     case kOptimizing:
33       return CreateOptimizingCompiler(driver);
34 
35     default:
36       LOG(FATAL) << "UNREACHABLE";
37       UNREACHABLE();
38   }
39 }
40 
IsPathologicalCase(const DexFile::CodeItem & code_item,uint32_t method_idx,const DexFile & dex_file)41 bool Compiler::IsPathologicalCase(const DexFile::CodeItem& code_item,
42                                   uint32_t method_idx,
43                                   const DexFile& dex_file) {
44   /*
45    * Skip compilation for pathologically large methods - either by instruction count or num vregs.
46    * Dalvik uses 16-bit uints for instruction and register counts.  We'll limit to a quarter
47    * of that, which also guarantees we cannot overflow our 16-bit internal Quick SSA name space.
48    */
49   if (code_item.insns_size_in_code_units_ >= UINT16_MAX / 4) {
50     LOG(INFO) << "Method exceeds compiler instruction limit: "
51               << code_item.insns_size_in_code_units_
52               << " in " << PrettyMethod(method_idx, dex_file);
53     return true;
54   }
55   if (code_item.registers_size_ >= UINT16_MAX / 4) {
56     LOG(INFO) << "Method exceeds compiler virtual register limit: "
57               << code_item.registers_size_ << " in " << PrettyMethod(method_idx, dex_file);
58     return true;
59   }
60   return false;
61 }
62 
63 }  // namespace art
64