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