blob: afa0dbab6009575f6ca7d23e38ced521b196ddfd [file] [log] [blame]
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +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
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000017#ifndef ART_COMPILER_COMPILER_H_
18#define ART_COMPILER_COMPILER_H_
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000019
David Sehr7f019712016-10-26 16:09:13 -070020#include "base/mutex.h"
David Sehrc431b9d2018-03-02 12:01:51 -080021#include "base/os.h"
Nicolas Geoffray0d60a2b2020-06-17 14:31:56 +010022#include "compilation_kind.h"
Andreas Gampe3f1dcd32018-12-28 09:39:56 -080023#include "dex/invoke_type.h"
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000024
25namespace art {
26
Andreas Gampe3f1dcd32018-12-28 09:39:56 -080027namespace dex {
28struct CodeItem;
29} // namespace dex
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000030namespace jit {
Igor Murashkin2ffb7032017-11-08 13:35:21 -080031class JitCodeCache;
32class JitLogger;
Nicolas Geoffray7f7539b2019-06-06 16:20:54 +010033class JitMemoryRegion;
Andreas Gampedeae7db2017-05-30 09:56:41 -070034} // namespace jit
David Sehr9323e6e2016-09-13 08:58:35 -070035namespace mirror {
Igor Murashkin2ffb7032017-11-08 13:35:21 -080036class ClassLoader;
37class DexCache;
Andreas Gampedeae7db2017-05-30 09:56:41 -070038} // namespace mirror
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000039
Mathieu Chartiere401d142015-04-22 13:56:20 -070040class ArtMethod;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000041class CompiledMethod;
Vladimir Marko038924b2019-02-19 15:09:35 +000042class CompiledMethodStorage;
43class CompilerOptions;
Andreas Gampe3f1dcd32018-12-28 09:39:56 -080044class DexFile;
David Sehr9323e6e2016-09-13 08:58:35 -070045template<class T> class Handle;
David Sehr7f019712016-10-26 16:09:13 -070046class Thread;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000047
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000048class Compiler {
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000049 public:
50 enum Kind {
51 kQuick,
Elliott Hughes956af0f2014-12-11 14:34:28 -080052 kOptimizing
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000053 };
54
Vladimir Marko038924b2019-02-19 15:09:35 +000055 static Compiler* Create(const CompilerOptions& compiler_options,
56 CompiledMethodStorage* storage,
57 Kind kind);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000058
Vladimir Markodf739842016-03-23 16:59:07 +000059 virtual bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file) const = 0;
Andreas Gampe53c913b2014-08-12 23:19:23 -070060
Andreas Gampe3f1dcd32018-12-28 09:39:56 -080061 virtual CompiledMethod* Compile(const dex::CodeItem* code_item,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000062 uint32_t access_flags,
63 InvokeType invoke_type,
64 uint16_t class_def_idx,
65 uint32_t method_idx,
Vladimir Marko8d6768d2017-03-14 10:13:21 +000066 Handle<mirror::ClassLoader> class_loader,
Mathieu Chartier736b5602015-09-02 14:54:11 -070067 const DexFile& dex_file,
68 Handle<mirror::DexCache> dex_cache) const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000069
Ian Rogers72d32622014-05-06 16:20:11 -070070 virtual CompiledMethod* JniCompile(uint32_t access_flags,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000071 uint32_t method_idx,
Vladimir Marko92f7f3c2017-10-31 11:38:30 +000072 const DexFile& dex_file,
73 Handle<mirror::DexCache> dex_cache) const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000074
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000075 virtual bool JitCompile(Thread* self ATTRIBUTE_UNUSED,
76 jit::JitCodeCache* code_cache ATTRIBUTE_UNUSED,
Nicolas Geoffray7f7539b2019-06-06 16:20:54 +010077 jit::JitMemoryRegion* region ATTRIBUTE_UNUSED,
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +000078 ArtMethod* method ATTRIBUTE_UNUSED,
Nicolas Geoffray0d60a2b2020-06-17 14:31:56 +010079 CompilationKind compilation_kind ATTRIBUTE_UNUSED,
Nicolas Geoffray01db5f72017-07-19 15:05:49 +010080 jit::JitLogger* jit_logger ATTRIBUTE_UNUSED)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070081 REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000082 return false;
83 }
84
Mathieu Chartiere401d142015-04-22 13:56:20 -070085 virtual uintptr_t GetEntryPointOf(ArtMethod* method) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070086 REQUIRES_SHARED(Locks::mutator_lock_) = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000087
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000088 uint64_t GetMaximumCompilationTimeBeforeWarning() const {
89 return maximum_compilation_time_before_warning_;
90 }
91
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000092 virtual ~Compiler() {}
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000093
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +000094 // Returns whether the method to compile is such a pathological case that
95 // it's not worth compiling.
Andreas Gampe3f1dcd32018-12-28 09:39:56 -080096 static bool IsPathologicalCase(const dex::CodeItem& code_item,
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +000097 uint32_t method_idx,
98 const DexFile& dex_file);
99
Ian Rogers72d32622014-05-06 16:20:11 -0700100 protected:
Vladimir Marko038924b2019-02-19 15:09:35 +0000101 Compiler(const CompilerOptions& compiler_options,
102 CompiledMethodStorage* storage,
103 uint64_t warning) :
104 compiler_options_(compiler_options),
105 storage_(storage),
106 maximum_compilation_time_before_warning_(warning) {
Ian Rogers72d32622014-05-06 16:20:11 -0700107 }
108
Vladimir Marko038924b2019-02-19 15:09:35 +0000109 const CompilerOptions& GetCompilerOptions() const {
110 return compiler_options_;
111 }
112
113 CompiledMethodStorage* GetCompiledMethodStorage() const {
114 return storage_;
Ian Rogers72d32622014-05-06 16:20:11 -0700115 }
116
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000117 private:
Vladimir Marko038924b2019-02-19 15:09:35 +0000118 const CompilerOptions& compiler_options_;
119 CompiledMethodStorage* const storage_;
Ian Rogers3d504072014-03-01 09:16:49 -0800120 const uint64_t maximum_compilation_time_before_warning_;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000121
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000122 DISALLOW_COPY_AND_ASSIGN(Compiler);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000123};
124
125} // namespace art
126
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000127#endif // ART_COMPILER_COMPILER_H_