xref: /aosp_15_r20/art/compiler/compiler.cc (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2014 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker #include "compiler.h"
18*795d594fSAndroid Build Coastguard Worker 
19*795d594fSAndroid Build Coastguard Worker #include <android-base/logging.h>
20*795d594fSAndroid Build Coastguard Worker 
21*795d594fSAndroid Build Coastguard Worker #include "base/macros.h"
22*795d594fSAndroid Build Coastguard Worker #include "base/utils.h"
23*795d594fSAndroid Build Coastguard Worker #include "dex/code_item_accessors-inl.h"
24*795d594fSAndroid Build Coastguard Worker #include "dex/dex_file.h"
25*795d594fSAndroid Build Coastguard Worker #include "oat/oat.h"
26*795d594fSAndroid Build Coastguard Worker #include "optimizing/optimizing_compiler.h"
27*795d594fSAndroid Build Coastguard Worker 
28*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN {
29*795d594fSAndroid Build Coastguard Worker 
Create(const CompilerOptions & compiler_options,CompiledCodeStorage * storage)30*795d594fSAndroid Build Coastguard Worker Compiler* Compiler::Create(const CompilerOptions& compiler_options, CompiledCodeStorage* storage) {
31*795d594fSAndroid Build Coastguard Worker   // Check that oat version when runtime was compiled matches the oat version of the compiler.
32*795d594fSAndroid Build Coastguard Worker   constexpr std::array<uint8_t, 4> compiler_oat_version = OatHeader::kOatVersion;
33*795d594fSAndroid Build Coastguard Worker   OatHeader::CheckOatVersion(compiler_oat_version);
34*795d594fSAndroid Build Coastguard Worker   return CreateOptimizingCompiler(compiler_options, storage);
35*795d594fSAndroid Build Coastguard Worker }
36*795d594fSAndroid Build Coastguard Worker 
IsPathologicalCase(const dex::CodeItem & code_item,uint32_t method_idx,const DexFile & dex_file)37*795d594fSAndroid Build Coastguard Worker bool Compiler::IsPathologicalCase(const dex::CodeItem& code_item,
38*795d594fSAndroid Build Coastguard Worker                                   uint32_t method_idx,
39*795d594fSAndroid Build Coastguard Worker                                   const DexFile& dex_file) {
40*795d594fSAndroid Build Coastguard Worker   /*
41*795d594fSAndroid Build Coastguard Worker    * Skip compilation for pathologically large methods - either by instruction count or num vregs.
42*795d594fSAndroid Build Coastguard Worker    * Dalvik uses 16-bit uints for instruction and register counts.  We'll limit to a quarter
43*795d594fSAndroid Build Coastguard Worker    * of that, which also guarantees we cannot overflow our 16-bit internal Quick SSA name space.
44*795d594fSAndroid Build Coastguard Worker    */
45*795d594fSAndroid Build Coastguard Worker   CodeItemDataAccessor accessor(dex_file, &code_item);
46*795d594fSAndroid Build Coastguard Worker   if (accessor.InsnsSizeInCodeUnits() >= UINT16_MAX / 4) {
47*795d594fSAndroid Build Coastguard Worker     LOG(INFO) << "Method exceeds compiler instruction limit: "
48*795d594fSAndroid Build Coastguard Worker               << accessor.InsnsSizeInCodeUnits()
49*795d594fSAndroid Build Coastguard Worker               << " in " << dex_file.PrettyMethod(method_idx);
50*795d594fSAndroid Build Coastguard Worker     return true;
51*795d594fSAndroid Build Coastguard Worker   }
52*795d594fSAndroid Build Coastguard Worker   if (accessor.RegistersSize() >= UINT16_MAX / 4) {
53*795d594fSAndroid Build Coastguard Worker     LOG(INFO) << "Method exceeds compiler virtual register limit: "
54*795d594fSAndroid Build Coastguard Worker               << accessor.RegistersSize() << " in " << dex_file.PrettyMethod(method_idx);
55*795d594fSAndroid Build Coastguard Worker     return true;
56*795d594fSAndroid Build Coastguard Worker   }
57*795d594fSAndroid Build Coastguard Worker   return false;
58*795d594fSAndroid Build Coastguard Worker }
59*795d594fSAndroid Build Coastguard Worker 
60*795d594fSAndroid Build Coastguard Worker }  // namespace art
61