• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef ART_COMPILER_COMPILER_H_
18 #define ART_COMPILER_COMPILER_H_
19 
20 #include "base/macros.h"
21 #include "base/mutex.h"
22 #include "base/os.h"
23 #include "compilation_kind.h"
24 #include "dex/invoke_type.h"
25 
26 namespace art HIDDEN {
27 
28 namespace dex {
29 struct CodeItem;
30 }  // namespace dex
31 namespace jit {
32 class JitCodeCache;
33 class JitLogger;
34 class JitMemoryRegion;
35 }  // namespace jit
36 namespace mirror {
37 class ClassLoader;
38 class DexCache;
39 }  // namespace mirror
40 
41 class ArtMethod;
42 class CompiledCodeStorage;
43 class CompiledMethod;
44 class CompilerOptions;
45 class DexFile;
46 template<class T> class Handle;
47 class Thread;
48 
49 class Compiler {
50  public:
51   EXPORT static Compiler* Create(const CompilerOptions& compiler_options,
52                                  CompiledCodeStorage* storage);
53 
54   virtual bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file) const = 0;
55 
56   virtual CompiledMethod* Compile(const dex::CodeItem* code_item,
57                                   uint32_t access_flags,
58                                   InvokeType invoke_type,
59                                   uint16_t class_def_idx,
60                                   uint32_t method_idx,
61                                   Handle<mirror::ClassLoader> class_loader,
62                                   const DexFile& dex_file,
63                                   Handle<mirror::DexCache> dex_cache) const = 0;
64 
65   virtual CompiledMethod* JniCompile(uint32_t access_flags,
66                                      uint32_t method_idx,
67                                      const DexFile& dex_file,
68                                      Handle<mirror::DexCache> dex_cache) const = 0;
69 
JitCompile(Thread * self,jit::JitCodeCache * code_cache,jit::JitMemoryRegion * region,ArtMethod * method,CompilationKind compilation_kind,jit::JitLogger * jit_logger)70   virtual bool JitCompile([[maybe_unused]] Thread* self,
71                           [[maybe_unused]] jit::JitCodeCache* code_cache,
72                           [[maybe_unused]] jit::JitMemoryRegion* region,
73                           [[maybe_unused]] ArtMethod* method,
74                           [[maybe_unused]] CompilationKind compilation_kind,
75                           [[maybe_unused]] jit::JitLogger* jit_logger)
76       REQUIRES_SHARED(Locks::mutator_lock_) {
77     return false;
78   }
79 
80   virtual uintptr_t GetEntryPointOf(ArtMethod* method) const
81      REQUIRES_SHARED(Locks::mutator_lock_) = 0;
82 
GetMaximumCompilationTimeBeforeWarning()83   uint64_t GetMaximumCompilationTimeBeforeWarning() const {
84     return maximum_compilation_time_before_warning_;
85   }
86 
~Compiler()87   virtual ~Compiler() {}
88 
89   // Returns whether the method to compile is such a pathological case that
90   // it's not worth compiling.
91   static bool IsPathologicalCase(const dex::CodeItem& code_item,
92                                  uint32_t method_idx,
93                                  const DexFile& dex_file);
94 
95  protected:
Compiler(const CompilerOptions & compiler_options,CompiledCodeStorage * storage,uint64_t warning)96   Compiler(const CompilerOptions& compiler_options,
97            CompiledCodeStorage* storage,
98            uint64_t warning) :
99       compiler_options_(compiler_options),
100       storage_(storage),
101       maximum_compilation_time_before_warning_(warning) {
102   }
103 
GetCompilerOptions()104   const CompilerOptions& GetCompilerOptions() const {
105     return compiler_options_;
106   }
107 
GetCompiledCodeStorage()108   CompiledCodeStorage* GetCompiledCodeStorage() const {
109     return storage_;
110   }
111 
112  private:
113   const CompilerOptions& compiler_options_;
114   CompiledCodeStorage* const storage_;
115   const uint64_t maximum_compilation_time_before_warning_;
116 
117   DISALLOW_COPY_AND_ASSIGN(Compiler);
118 };
119 
120 }  // namespace art
121 
122 #endif  // ART_COMPILER_COMPILER_H_
123