xref: /aosp_15_r20/art/compiler/compiler.h (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2014 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker #ifndef ART_COMPILER_COMPILER_H_
18*795d594fSAndroid Build Coastguard Worker #define ART_COMPILER_COMPILER_H_
19*795d594fSAndroid Build Coastguard Worker 
20*795d594fSAndroid Build Coastguard Worker #include "base/macros.h"
21*795d594fSAndroid Build Coastguard Worker #include "base/mutex.h"
22*795d594fSAndroid Build Coastguard Worker #include "base/os.h"
23*795d594fSAndroid Build Coastguard Worker #include "compilation_kind.h"
24*795d594fSAndroid Build Coastguard Worker #include "dex/invoke_type.h"
25*795d594fSAndroid Build Coastguard Worker 
26*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN {
27*795d594fSAndroid Build Coastguard Worker 
28*795d594fSAndroid Build Coastguard Worker namespace dex {
29*795d594fSAndroid Build Coastguard Worker struct CodeItem;
30*795d594fSAndroid Build Coastguard Worker }  // namespace dex
31*795d594fSAndroid Build Coastguard Worker namespace jit {
32*795d594fSAndroid Build Coastguard Worker class JitCodeCache;
33*795d594fSAndroid Build Coastguard Worker class JitLogger;
34*795d594fSAndroid Build Coastguard Worker class JitMemoryRegion;
35*795d594fSAndroid Build Coastguard Worker }  // namespace jit
36*795d594fSAndroid Build Coastguard Worker namespace mirror {
37*795d594fSAndroid Build Coastguard Worker class ClassLoader;
38*795d594fSAndroid Build Coastguard Worker class DexCache;
39*795d594fSAndroid Build Coastguard Worker }  // namespace mirror
40*795d594fSAndroid Build Coastguard Worker 
41*795d594fSAndroid Build Coastguard Worker class ArtMethod;
42*795d594fSAndroid Build Coastguard Worker class CompiledCodeStorage;
43*795d594fSAndroid Build Coastguard Worker class CompiledMethod;
44*795d594fSAndroid Build Coastguard Worker class CompilerOptions;
45*795d594fSAndroid Build Coastguard Worker class DexFile;
46*795d594fSAndroid Build Coastguard Worker template<class T> class Handle;
47*795d594fSAndroid Build Coastguard Worker class Thread;
48*795d594fSAndroid Build Coastguard Worker 
49*795d594fSAndroid Build Coastguard Worker class Compiler {
50*795d594fSAndroid Build Coastguard Worker  public:
51*795d594fSAndroid Build Coastguard Worker   EXPORT static Compiler* Create(const CompilerOptions& compiler_options,
52*795d594fSAndroid Build Coastguard Worker                                  CompiledCodeStorage* storage);
53*795d594fSAndroid Build Coastguard Worker 
54*795d594fSAndroid Build Coastguard Worker   virtual bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file) const = 0;
55*795d594fSAndroid Build Coastguard Worker 
56*795d594fSAndroid Build Coastguard Worker   virtual CompiledMethod* Compile(const dex::CodeItem* code_item,
57*795d594fSAndroid Build Coastguard Worker                                   uint32_t access_flags,
58*795d594fSAndroid Build Coastguard Worker                                   uint16_t class_def_idx,
59*795d594fSAndroid Build Coastguard Worker                                   uint32_t method_idx,
60*795d594fSAndroid Build Coastguard Worker                                   Handle<mirror::ClassLoader> class_loader,
61*795d594fSAndroid Build Coastguard Worker                                   const DexFile& dex_file,
62*795d594fSAndroid Build Coastguard Worker                                   Handle<mirror::DexCache> dex_cache) const = 0;
63*795d594fSAndroid Build Coastguard Worker 
64*795d594fSAndroid Build Coastguard Worker   virtual CompiledMethod* JniCompile(uint32_t access_flags,
65*795d594fSAndroid Build Coastguard Worker                                      uint32_t method_idx,
66*795d594fSAndroid Build Coastguard Worker                                      const DexFile& dex_file,
67*795d594fSAndroid Build Coastguard Worker                                      Handle<mirror::DexCache> dex_cache) const = 0;
68*795d594fSAndroid Build Coastguard Worker 
JitCompile(Thread * self,jit::JitCodeCache * code_cache,jit::JitMemoryRegion * region,ArtMethod * method,CompilationKind compilation_kind,jit::JitLogger * jit_logger)69*795d594fSAndroid Build Coastguard Worker   virtual bool JitCompile([[maybe_unused]] Thread* self,
70*795d594fSAndroid Build Coastguard Worker                           [[maybe_unused]] jit::JitCodeCache* code_cache,
71*795d594fSAndroid Build Coastguard Worker                           [[maybe_unused]] jit::JitMemoryRegion* region,
72*795d594fSAndroid Build Coastguard Worker                           [[maybe_unused]] ArtMethod* method,
73*795d594fSAndroid Build Coastguard Worker                           [[maybe_unused]] CompilationKind compilation_kind,
74*795d594fSAndroid Build Coastguard Worker                           [[maybe_unused]] jit::JitLogger* jit_logger)
75*795d594fSAndroid Build Coastguard Worker       REQUIRES_SHARED(Locks::mutator_lock_) {
76*795d594fSAndroid Build Coastguard Worker     return false;
77*795d594fSAndroid Build Coastguard Worker   }
78*795d594fSAndroid Build Coastguard Worker 
79*795d594fSAndroid Build Coastguard Worker   virtual uintptr_t GetEntryPointOf(ArtMethod* method) const
80*795d594fSAndroid Build Coastguard Worker      REQUIRES_SHARED(Locks::mutator_lock_) = 0;
81*795d594fSAndroid Build Coastguard Worker 
GetMaximumCompilationTimeBeforeWarning()82*795d594fSAndroid Build Coastguard Worker   uint64_t GetMaximumCompilationTimeBeforeWarning() const {
83*795d594fSAndroid Build Coastguard Worker     return maximum_compilation_time_before_warning_;
84*795d594fSAndroid Build Coastguard Worker   }
85*795d594fSAndroid Build Coastguard Worker 
~Compiler()86*795d594fSAndroid Build Coastguard Worker   virtual ~Compiler() {}
87*795d594fSAndroid Build Coastguard Worker 
88*795d594fSAndroid Build Coastguard Worker   // Returns whether the method to compile is such a pathological case that
89*795d594fSAndroid Build Coastguard Worker   // it's not worth compiling.
90*795d594fSAndroid Build Coastguard Worker   static bool IsPathologicalCase(const dex::CodeItem& code_item,
91*795d594fSAndroid Build Coastguard Worker                                  uint32_t method_idx,
92*795d594fSAndroid Build Coastguard Worker                                  const DexFile& dex_file);
93*795d594fSAndroid Build Coastguard Worker 
94*795d594fSAndroid Build Coastguard Worker  protected:
Compiler(const CompilerOptions & compiler_options,CompiledCodeStorage * storage,uint64_t warning)95*795d594fSAndroid Build Coastguard Worker   Compiler(const CompilerOptions& compiler_options,
96*795d594fSAndroid Build Coastguard Worker            CompiledCodeStorage* storage,
97*795d594fSAndroid Build Coastguard Worker            uint64_t warning) :
98*795d594fSAndroid Build Coastguard Worker       compiler_options_(compiler_options),
99*795d594fSAndroid Build Coastguard Worker       storage_(storage),
100*795d594fSAndroid Build Coastguard Worker       maximum_compilation_time_before_warning_(warning) {
101*795d594fSAndroid Build Coastguard Worker   }
102*795d594fSAndroid Build Coastguard Worker 
GetCompilerOptions()103*795d594fSAndroid Build Coastguard Worker   const CompilerOptions& GetCompilerOptions() const {
104*795d594fSAndroid Build Coastguard Worker     return compiler_options_;
105*795d594fSAndroid Build Coastguard Worker   }
106*795d594fSAndroid Build Coastguard Worker 
GetCompiledCodeStorage()107*795d594fSAndroid Build Coastguard Worker   CompiledCodeStorage* GetCompiledCodeStorage() const {
108*795d594fSAndroid Build Coastguard Worker     return storage_;
109*795d594fSAndroid Build Coastguard Worker   }
110*795d594fSAndroid Build Coastguard Worker 
111*795d594fSAndroid Build Coastguard Worker  private:
112*795d594fSAndroid Build Coastguard Worker   const CompilerOptions& compiler_options_;
113*795d594fSAndroid Build Coastguard Worker   CompiledCodeStorage* const storage_;
114*795d594fSAndroid Build Coastguard Worker   const uint64_t maximum_compilation_time_before_warning_;
115*795d594fSAndroid Build Coastguard Worker 
116*795d594fSAndroid Build Coastguard Worker   DISALLOW_COPY_AND_ASSIGN(Compiler);
117*795d594fSAndroid Build Coastguard Worker };
118*795d594fSAndroid Build Coastguard Worker 
119*795d594fSAndroid Build Coastguard Worker }  // namespace art
120*795d594fSAndroid Build Coastguard Worker 
121*795d594fSAndroid Build Coastguard Worker #endif  // ART_COMPILER_COMPILER_H_
122