blob: 98d73396bc54ea03d5ddb645a9ceb8d3fbd41b29 [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 Gampe57943812017-12-06 21:39:13 -080019#include <android-base/logging.h>
20
21#include "base/macros.h"
David Sehrc431b9d2018-03-02 12:01:51 -080022#include "base/utils.h"
David Sehr9e734c72018-01-04 17:56:19 -080023#include "dex/code_item_accessors-inl.h"
Andreas Gampe3f1dcd32018-12-28 09:39:56 -080024#include "dex/dex_file.h"
David Srbeckye5d93b52019-02-27 15:10:52 +000025#include "oat.h"
Andreas Gampe53c913b2014-08-12 23:19:23 -070026#include "optimizing/optimizing_compiler.h"
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000027
28namespace art {
29
Vladimir Marko038924b2019-02-19 15:09:35 +000030Compiler* Compiler::Create(const CompilerOptions& compiler_options,
31 CompiledMethodStorage* storage,
32 Compiler::Kind kind) {
David Srbeckye5d93b52019-02-27 15:10:52 +000033 // 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 Geoffrayb34f69a2014-03-07 15:28:39 +000036 switch (kind) {
37 case kQuick:
Nicolas Geoffray3c94f092016-03-21 17:10:24 +000038 // TODO: Remove Quick in options.
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000039 case kOptimizing:
Vladimir Marko038924b2019-02-19 15:09:35 +000040 return CreateOptimizingCompiler(compiler_options, storage);
Andreas Gampe53c913b2014-08-12 23:19:23 -070041
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000042 default:
43 LOG(FATAL) << "UNREACHABLE";
Ian Rogers2c4257b2014-10-24 14:20:06 -070044 UNREACHABLE();
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000045 }
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000046}
47
Andreas Gampe3f1dcd32018-12-28 09:39:56 -080048bool Compiler::IsPathologicalCase(const dex::CodeItem& code_item,
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +000049 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 Chartier698ebbc2018-01-05 11:00:42 -080056 CodeItemDataAccessor accessor(dex_file, &code_item);
Mathieu Chartier808c7a52017-12-15 11:19:33 -080057 if (accessor.InsnsSizeInCodeUnits() >= UINT16_MAX / 4) {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +000058 LOG(INFO) << "Method exceeds compiler instruction limit: "
Mathieu Chartier808c7a52017-12-15 11:19:33 -080059 << accessor.InsnsSizeInCodeUnits()
David Sehr709b0702016-10-13 09:12:37 -070060 << " in " << dex_file.PrettyMethod(method_idx);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +000061 return true;
62 }
Mathieu Chartier808c7a52017-12-15 11:19:33 -080063 if (accessor.RegistersSize() >= UINT16_MAX / 4) {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +000064 LOG(INFO) << "Method exceeds compiler virtual register limit: "
Mathieu Chartier808c7a52017-12-15 11:19:33 -080065 << accessor.RegistersSize() << " in " << dex_file.PrettyMethod(method_idx);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +000066 return true;
67 }
68 return false;
69}
70
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000071} // namespace art