blob: 5e8ec1e01bf9c836c3a9f8cf219599e15cd6a495 [file] [log] [blame]
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +00001/*
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"
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000018
Andreas Gampe53c913b2014-08-12 23:19:23 -070019#include "base/logging.h"
Mathieu Chartier5bdab122015-01-26 18:30:19 -080020#include "dex/quick/quick_compiler_factory.h"
Andreas Gampe53c913b2014-08-12 23:19:23 -070021#include "driver/compiler_driver.h"
Andreas Gampe53c913b2014-08-12 23:19:23 -070022#include "optimizing/optimizing_compiler.h"
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000023
24namespace art {
25
Ian Rogers72d32622014-05-06 16:20:11 -070026Compiler* Compiler::Create(CompilerDriver* driver, Compiler::Kind kind) {
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000027 switch (kind) {
28 case kQuick:
Andreas Gampe53c913b2014-08-12 23:19:23 -070029 return CreateQuickCompiler(driver);
30
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000031 case kOptimizing:
Andreas Gampe53c913b2014-08-12 23:19:23 -070032 return CreateOptimizingCompiler(driver);
33
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000034 default:
35 LOG(FATAL) << "UNREACHABLE";
Ian Rogers2c4257b2014-10-24 14:20:06 -070036 UNREACHABLE();
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000037 }
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000038}
39
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +000040bool Compiler::IsPathologicalCase(const DexFile::CodeItem& code_item,
41 uint32_t method_idx,
42 const DexFile& dex_file) {
43 /*
44 * Skip compilation for pathologically large methods - either by instruction count or num vregs.
45 * Dalvik uses 16-bit uints for instruction and register counts. We'll limit to a quarter
46 * of that, which also guarantees we cannot overflow our 16-bit internal Quick SSA name space.
47 */
48 if (code_item.insns_size_in_code_units_ >= UINT16_MAX / 4) {
49 LOG(INFO) << "Method exceeds compiler instruction limit: "
50 << code_item.insns_size_in_code_units_
51 << " in " << PrettyMethod(method_idx, dex_file);
52 return true;
53 }
54 if (code_item.registers_size_ >= UINT16_MAX / 4) {
55 LOG(INFO) << "Method exceeds compiler virtual register limit: "
56 << code_item.registers_size_ << " in " << PrettyMethod(method_idx, dex_file);
57 return true;
58 }
59 return false;
60}
61
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000062} // namespace art