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 | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 24 | #include "dex/dex_file.h" |
David Srbecky | e5d93b5 | 2019-02-27 15:10:52 +0000 | [diff] [blame] | 25 | #include "oat.h" |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 26 | #include "optimizing/optimizing_compiler.h" |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 27 | |
| 28 | namespace art { |
| 29 | |
Vladimir Marko | 038924b | 2019-02-19 15:09:35 +0000 | [diff] [blame] | 30 | Compiler* Compiler::Create(const CompilerOptions& compiler_options, |
| 31 | CompiledMethodStorage* storage, |
| 32 | Compiler::Kind kind) { |
David Srbecky | e5d93b5 | 2019-02-27 15:10:52 +0000 | [diff] [blame] | 33 | // Check that oat version when runtime was compiled matches the oat version of the compiler. |
| 34 | constexpr std::array<uint8_t, 4> compiler_oat_version = OatHeader::kOatVersion; |
| 35 | OatHeader::CheckOatVersion(compiler_oat_version); |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 36 | switch (kind) { |
| 37 | case kQuick: |
Nicolas Geoffray | 3c94f09 | 2016-03-21 17:10:24 +0000 | [diff] [blame] | 38 | // TODO: Remove Quick in options. |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 39 | case kOptimizing: |
Vladimir Marko | 038924b | 2019-02-19 15:09:35 +0000 | [diff] [blame] | 40 | return CreateOptimizingCompiler(compiler_options, storage); |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 41 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 42 | default: |
| 43 | LOG(FATAL) << "UNREACHABLE"; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 44 | UNREACHABLE(); |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 45 | } |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 48 | bool Compiler::IsPathologicalCase(const dex::CodeItem& code_item, |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 49 | uint32_t method_idx, |
| 50 | const DexFile& dex_file) { |
| 51 | /* |
| 52 | * Skip compilation for pathologically large methods - either by instruction count or num vregs. |
| 53 | * Dalvik uses 16-bit uints for instruction and register counts. We'll limit to a quarter |
| 54 | * of that, which also guarantees we cannot overflow our 16-bit internal Quick SSA name space. |
| 55 | */ |
Mathieu Chartier | 698ebbc | 2018-01-05 11:00:42 -0800 | [diff] [blame] | 56 | CodeItemDataAccessor accessor(dex_file, &code_item); |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 57 | if (accessor.InsnsSizeInCodeUnits() >= UINT16_MAX / 4) { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 58 | LOG(INFO) << "Method exceeds compiler instruction limit: " |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 59 | << accessor.InsnsSizeInCodeUnits() |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 60 | << " in " << dex_file.PrettyMethod(method_idx); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 61 | return true; |
| 62 | } |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 63 | if (accessor.RegistersSize() >= UINT16_MAX / 4) { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 64 | LOG(INFO) << "Method exceeds compiler virtual register limit: " |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 65 | << accessor.RegistersSize() << " in " << dex_file.PrettyMethod(method_idx); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 66 | return true; |
| 67 | } |
| 68 | return false; |
| 69 | } |
| 70 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 71 | } // namespace art |