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 enum Kind { 52 kQuick, 53 kOptimizing 54 }; 55 56 EXPORT static Compiler* Create(const CompilerOptions& compiler_options, 57 CompiledCodeStorage* storage, 58 Kind kind); 59 60 virtual bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file) const = 0; 61 62 virtual CompiledMethod* Compile(const dex::CodeItem* code_item, 63 uint32_t access_flags, 64 InvokeType invoke_type, 65 uint16_t class_def_idx, 66 uint32_t method_idx, 67 Handle<mirror::ClassLoader> class_loader, 68 const DexFile& dex_file, 69 Handle<mirror::DexCache> dex_cache) const = 0; 70 71 virtual CompiledMethod* JniCompile(uint32_t access_flags, 72 uint32_t method_idx, 73 const DexFile& dex_file, 74 Handle<mirror::DexCache> dex_cache) const = 0; 75 JitCompile(Thread * self ATTRIBUTE_UNUSED,jit::JitCodeCache * code_cache ATTRIBUTE_UNUSED,jit::JitMemoryRegion * region ATTRIBUTE_UNUSED,ArtMethod * method ATTRIBUTE_UNUSED,CompilationKind compilation_kind ATTRIBUTE_UNUSED,jit::JitLogger * jit_logger ATTRIBUTE_UNUSED)76 virtual bool JitCompile(Thread* self ATTRIBUTE_UNUSED, 77 jit::JitCodeCache* code_cache ATTRIBUTE_UNUSED, 78 jit::JitMemoryRegion* region ATTRIBUTE_UNUSED, 79 ArtMethod* method ATTRIBUTE_UNUSED, 80 CompilationKind compilation_kind ATTRIBUTE_UNUSED, 81 jit::JitLogger* jit_logger ATTRIBUTE_UNUSED) 82 REQUIRES_SHARED(Locks::mutator_lock_) { 83 return false; 84 } 85 86 virtual uintptr_t GetEntryPointOf(ArtMethod* method) const 87 REQUIRES_SHARED(Locks::mutator_lock_) = 0; 88 GetMaximumCompilationTimeBeforeWarning()89 uint64_t GetMaximumCompilationTimeBeforeWarning() const { 90 return maximum_compilation_time_before_warning_; 91 } 92 ~Compiler()93 virtual ~Compiler() {} 94 95 // Returns whether the method to compile is such a pathological case that 96 // it's not worth compiling. 97 static bool IsPathologicalCase(const dex::CodeItem& code_item, 98 uint32_t method_idx, 99 const DexFile& dex_file); 100 101 protected: Compiler(const CompilerOptions & compiler_options,CompiledCodeStorage * storage,uint64_t warning)102 Compiler(const CompilerOptions& compiler_options, 103 CompiledCodeStorage* storage, 104 uint64_t warning) : 105 compiler_options_(compiler_options), 106 storage_(storage), 107 maximum_compilation_time_before_warning_(warning) { 108 } 109 GetCompilerOptions()110 const CompilerOptions& GetCompilerOptions() const { 111 return compiler_options_; 112 } 113 GetCompiledCodeStorage()114 CompiledCodeStorage* GetCompiledCodeStorage() const { 115 return storage_; 116 } 117 118 private: 119 const CompilerOptions& compiler_options_; 120 CompiledCodeStorage* const storage_; 121 const uint64_t maximum_compilation_time_before_warning_; 122 123 DISALLOW_COPY_AND_ASSIGN(Compiler); 124 }; 125 126 } // namespace art 127 128 #endif // ART_COMPILER_COMPILER_H_ 129