1 /*
2  * Copyright 2015 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_JIT_JIT_COMPILER_H_
18 #define ART_COMPILER_JIT_JIT_COMPILER_H_
19 
20 #include "base/macros.h"
21 #include "base/mutex.h"
22 #include "compilation_kind.h"
23 
24 #include "jit/jit.h"
25 
26 namespace art HIDDEN {
27 
28 class ArtMethod;
29 class Compiler;
30 class CompilerOptions;
31 class Thread;
32 
33 namespace jit {
34 
35 class JitLogger;
36 class JitMemoryRegion;
37 
38 class JitCompiler : public JitCompilerInterface {
39  public:
40   static JitCompiler* Create();
41   virtual ~JitCompiler();
42 
43   // Compilation entrypoint. Returns whether the compilation succeeded.
44   bool CompileMethod(
45       Thread* self, JitMemoryRegion* region, ArtMethod* method, CompilationKind kind)
46       REQUIRES_SHARED(Locks::mutator_lock_) override;
47 
GetCompilerOptions()48   const CompilerOptions& GetCompilerOptions() const {
49     return *compiler_options_.get();
50   }
51 
52   bool IsBaselineCompiler() const override;
53 
54   void SetDebuggableCompilerOption(bool val) override;
55 
56   bool GenerateDebugInfo() override;
57 
58   void ParseCompilerOptions() override;
59 
60   void TypesLoaded(mirror::Class**, size_t count) REQUIRES_SHARED(Locks::mutator_lock_) override;
61 
62   std::vector<uint8_t> PackElfFileForJIT(ArrayRef<const JITCodeEntry*> elf_files,
63                                          ArrayRef<const void*> removed_symbols,
64                                          bool compress,
65                                          /*out*/ size_t* num_symbols) override;
66 
67   uint32_t GetInlineMaxCodeUnits() const override;
68 
69  private:
70   std::unique_ptr<CompilerOptions> compiler_options_;
71   std::unique_ptr<Compiler> compiler_;
72   std::unique_ptr<JitLogger> jit_logger_;
73 
74   JitCompiler();
75 
76   DISALLOW_COPY_AND_ASSIGN(JitCompiler);
77 };
78 
79 }  // namespace jit
80 }  // namespace art
81 
82 #endif  // ART_COMPILER_JIT_JIT_COMPILER_H_
83