Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 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" |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 18 | |
Andreas Gampe | 5794381 | 2017-12-06 21:39:13 -0800 | [diff] [blame] | 19 | #include <android-base/logging.h> |
| 20 | |
| 21 | #include "base/macros.h" |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 22 | #include "base/utils.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 23 | #include "dex/code_item_accessors-inl.h" |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 24 | #include "driver/compiler_driver.h" |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 25 | #include "optimizing/optimizing_compiler.h" |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 26 | |
| 27 | namespace art { |
| 28 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 29 | Compiler* Compiler::Create(CompilerDriver* driver, Compiler::Kind kind) { |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 30 | switch (kind) { |
| 31 | case kQuick: |
Nicolas Geoffray | 3c94f09 | 2016-03-21 17:10:24 +0000 | [diff] [blame] | 32 | // TODO: Remove Quick in options. |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 33 | case kOptimizing: |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 34 | return CreateOptimizingCompiler(driver); |
| 35 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 36 | default: |
| 37 | LOG(FATAL) << "UNREACHABLE"; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 38 | UNREACHABLE(); |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 39 | } |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 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 | */ |
Mathieu Chartier | 698ebbc | 2018-01-05 11:00:42 -0800 | [diff] [blame] | 50 | CodeItemDataAccessor accessor(dex_file, &code_item); |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 51 | if (accessor.InsnsSizeInCodeUnits() >= UINT16_MAX / 4) { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 52 | LOG(INFO) << "Method exceeds compiler instruction limit: " |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 53 | << accessor.InsnsSizeInCodeUnits() |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 54 | << " in " << dex_file.PrettyMethod(method_idx); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 55 | return true; |
| 56 | } |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 57 | if (accessor.RegistersSize() >= UINT16_MAX / 4) { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 58 | LOG(INFO) << "Method exceeds compiler virtual register limit: " |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 59 | << accessor.RegistersSize() << " in " << dex_file.PrettyMethod(method_idx); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 60 | return true; |
| 61 | } |
| 62 | return false; |
| 63 | } |
| 64 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 65 | } // namespace art |