blob: ce785bb769a2720b24c88bd7dcf4eb1bfd9a6a38 [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
Vladimir Markobdbee062022-11-16 12:44:15 +000020#include "base/macros.h"
David Sehr7f019712016-10-26 16:09:13 -070021#include "base/mutex.h"
David Sehrc431b9d2018-03-02 12:01:51 -080022#include "base/os.h"
Nicolas Geoffray0d60a2b2020-06-17 14:31:56 +010023#include "compilation_kind.h"
Andreas Gampe3f1dcd32018-12-28 09:39:56 -080024#include "dex/invoke_type.h"
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000025
Vladimir Markobdbee062022-11-16 12:44:15 +000026namespace art HIDDEN {
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000027
Andreas Gampe3f1dcd32018-12-28 09:39:56 -080028namespace dex {
29struct CodeItem;
30} // namespace dex
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000031namespace jit {
Igor Murashkin2ffb7032017-11-08 13:35:21 -080032class JitCodeCache;
33class JitLogger;
Nicolas Geoffray7f7539b2019-06-06 16:20:54 +010034class JitMemoryRegion;
Andreas Gampedeae7db2017-05-30 09:56:41 -070035} // namespace jit
David Sehr9323e6e2016-09-13 08:58:35 -070036namespace mirror {
Igor Murashkin2ffb7032017-11-08 13:35:21 -080037class ClassLoader;
38class DexCache;
Andreas Gampedeae7db2017-05-30 09:56:41 -070039} // namespace mirror
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000040
Mathieu Chartiere401d142015-04-22 13:56:20 -070041class ArtMethod;
Vladimir Markod5a43192022-09-30 16:18:02 +020042class CompiledCodeStorage;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000043class CompiledMethod;
Vladimir Marko038924b2019-02-19 15:09:35 +000044class CompilerOptions;
Andreas Gampe3f1dcd32018-12-28 09:39:56 -080045class DexFile;
David Sehr9323e6e2016-09-13 08:58:35 -070046template<class T> class Handle;
David Sehr7f019712016-10-26 16:09:13 -070047class Thread;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000048
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000049class Compiler {
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000050 public:
51 enum Kind {
52 kQuick,
Elliott Hughes956af0f2014-12-11 14:34:28 -080053 kOptimizing
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000054 };
55
Vladimir Markobdbee062022-11-16 12:44:15 +000056 EXPORT static Compiler* Create(const CompilerOptions& compiler_options,
57 CompiledCodeStorage* storage,
58 Kind kind);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000059
Vladimir Markodf739842016-03-23 16:59:07 +000060 virtual bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file) const = 0;
Andreas Gampe53c913b2014-08-12 23:19:23 -070061
Andreas Gampe3f1dcd32018-12-28 09:39:56 -080062 virtual CompiledMethod* Compile(const dex::CodeItem* code_item,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000063 uint32_t access_flags,
64 InvokeType invoke_type,
65 uint16_t class_def_idx,
66 uint32_t method_idx,
Vladimir Marko8d6768d2017-03-14 10:13:21 +000067 Handle<mirror::ClassLoader> class_loader,
Mathieu Chartier736b5602015-09-02 14:54:11 -070068 const DexFile& dex_file,
69 Handle<mirror::DexCache> dex_cache) const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000070
Ian Rogers72d32622014-05-06 16:20:11 -070071 virtual CompiledMethod* JniCompile(uint32_t access_flags,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000072 uint32_t method_idx,
Vladimir Marko92f7f3c2017-10-31 11:38:30 +000073 const DexFile& dex_file,
74 Handle<mirror::DexCache> dex_cache) const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000075
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000076 virtual bool JitCompile(Thread* self ATTRIBUTE_UNUSED,
77 jit::JitCodeCache* code_cache ATTRIBUTE_UNUSED,
Nicolas Geoffray7f7539b2019-06-06 16:20:54 +010078 jit::JitMemoryRegion* region ATTRIBUTE_UNUSED,
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +000079 ArtMethod* method ATTRIBUTE_UNUSED,
Nicolas Geoffray0d60a2b2020-06-17 14:31:56 +010080 CompilationKind compilation_kind ATTRIBUTE_UNUSED,
Nicolas Geoffray01db5f72017-07-19 15:05:49 +010081 jit::JitLogger* jit_logger ATTRIBUTE_UNUSED)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070082 REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000083 return false;
84 }
85
Mathieu Chartiere401d142015-04-22 13:56:20 -070086 virtual uintptr_t GetEntryPointOf(ArtMethod* method) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070087 REQUIRES_SHARED(Locks::mutator_lock_) = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000088
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000089 uint64_t GetMaximumCompilationTimeBeforeWarning() const {
90 return maximum_compilation_time_before_warning_;
91 }
92
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000093 virtual ~Compiler() {}
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000094
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +000095 // Returns whether the method to compile is such a pathological case that
96 // it's not worth compiling.
Andreas Gampe3f1dcd32018-12-28 09:39:56 -080097 static bool IsPathologicalCase(const dex::CodeItem& code_item,
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +000098 uint32_t method_idx,
99 const DexFile& dex_file);
100
Ian Rogers72d32622014-05-06 16:20:11 -0700101 protected:
Vladimir Marko038924b2019-02-19 15:09:35 +0000102 Compiler(const CompilerOptions& compiler_options,
Vladimir Markod5a43192022-09-30 16:18:02 +0200103 CompiledCodeStorage* storage,
Vladimir Marko038924b2019-02-19 15:09:35 +0000104 uint64_t warning) :
105 compiler_options_(compiler_options),
106 storage_(storage),
107 maximum_compilation_time_before_warning_(warning) {
Ian Rogers72d32622014-05-06 16:20:11 -0700108 }
109
Vladimir Marko038924b2019-02-19 15:09:35 +0000110 const CompilerOptions& GetCompilerOptions() const {
111 return compiler_options_;
112 }
113
Vladimir Markod5a43192022-09-30 16:18:02 +0200114 CompiledCodeStorage* GetCompiledCodeStorage() const {
Vladimir Marko038924b2019-02-19 15:09:35 +0000115 return storage_;
Ian Rogers72d32622014-05-06 16:20:11 -0700116 }
117
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000118 private:
Vladimir Marko038924b2019-02-19 15:09:35 +0000119 const CompilerOptions& compiler_options_;
Vladimir Markod5a43192022-09-30 16:18:02 +0200120 CompiledCodeStorage* const storage_;
Ian Rogers3d504072014-03-01 09:16:49 -0800121 const uint64_t maximum_compilation_time_before_warning_;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000122
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000123 DISALLOW_COPY_AND_ASSIGN(Compiler);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000124};
125
126} // namespace art
127
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000128#endif // ART_COMPILER_COMPILER_H_