blob: 6059a2a0e255427b7519ae153d221fcde70d6913 [file] [log] [blame]
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#ifndef ART_SRC_COMPILER_H_
4#define ART_SRC_COMPILER_H_
5
Brian Carlstrom3320cf42011-10-04 14:58:28 -07006#include "compiled_method.h"
Ian Rogers2c8f6532011-09-02 17:16:34 -07007#include "constants.h"
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -07008#include "dex_file.h"
Ian Rogers2c8f6532011-09-02 17:16:34 -07009#include "jni_compiler.h"
Brian Carlstrom3320cf42011-10-04 14:58:28 -070010#include "oat_file.h"
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070011#include "object.h"
Ian Rogers1cb0a1d2011-10-06 15:24:35 -070012#include "runtime.h"
Brian Carlstrom3320cf42011-10-04 14:58:28 -070013#include "unordered_map.h"
Ian Rogersd6b1f612011-09-27 13:38:14 -070014
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070015namespace art {
16
17class Compiler {
18 public:
Brian Carlstrom3320cf42011-10-04 14:58:28 -070019 explicit Compiler(InstructionSet instruction_set);
20
21 ~Compiler();
Ian Rogers2c8f6532011-09-02 17:16:34 -070022
Brian Carlstrom8a487412011-08-29 20:08:52 -070023 // Compile all Methods of all the Classes of all the DexFiles that are part of a ClassLoader.
24 void CompileAll(const ClassLoader* class_loader);
25
26 // Compile a single Method
Brian Carlstrom3320cf42011-10-04 14:58:28 -070027 void CompileOne(const Method* method);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070028
Brian Carlstrom16192862011-09-12 17:50:06 -070029 void SetVerbose(bool verbose) {
30 verbose_ = verbose;
31 }
32
Brian Carlstrom3320cf42011-10-04 14:58:28 -070033 InstructionSet GetInstructionSet() const {
34 return instruction_set_;
35 }
36
Brian Carlstrom16192862011-09-12 17:50:06 -070037 bool IsVerbose() const {
38 return verbose_;
39 }
40
Brian Carlstrome24fa612011-09-29 00:53:55 -070041 // Stub to throw AbstractMethodError
Brian Carlstrome24fa612011-09-29 00:53:55 -070042 static ByteArray* CreateAbstractMethodErrorStub(InstructionSet instruction_set);
43
Brian Carlstrom3320cf42011-10-04 14:58:28 -070044
Ian Rogersad25ac52011-10-04 19:13:33 -070045 // Generate the trampoline that's invoked by unresolved direct methods
Ian Rogers1cb0a1d2011-10-06 15:24:35 -070046 static ByteArray* CreateResolutionStub(InstructionSet instruction_set,
47 Runtime::TrampolineType type);
Ian Rogersad25ac52011-10-04 19:13:33 -070048
Brian Carlstrom3320cf42011-10-04 14:58:28 -070049 const CompiledMethod* GetCompiledMethod(const Method* method) const;
50 const CompiledInvokeStub* GetCompiledInvokeStub(const Method* method) const;
51
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070052 private:
53 // Attempt to resolve all type, methods, fields, and strings
54 // referenced from code in the dex file following PathClassLoader
55 // ordering semantics.
56 void Resolve(const ClassLoader* class_loader);
57 void ResolveDexFile(const ClassLoader* class_loader, const DexFile& dex_file);
58
jeffhao98eacac2011-09-14 16:11:53 -070059 void Verify(const ClassLoader* class_loader);
60 void VerifyDexFile(const ClassLoader* class_loader, const DexFile& dex_file);
61
Brian Carlstroma5a97a22011-09-15 14:08:49 -070062 void InitializeClassesWithoutClinit(const ClassLoader* class_loader);
63 void InitializeClassesWithoutClinit(const ClassLoader* class_loader, const DexFile& dex_file);
64
Brian Carlstrom83db7722011-08-26 17:32:56 -070065 void Compile(const ClassLoader* class_loader);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070066 void CompileDexFile(const ClassLoader* class_loader, const DexFile& dex_file);
Brian Carlstrom3320cf42011-10-04 14:58:28 -070067 void CompileClass(const Class* klass);
68 void CompileMethod(const Method* method);
Brian Carlstrom83db7722011-08-26 17:32:56 -070069
70 // After compiling, walk all the DexCaches and set the code and
Brian Carlstrom9cc262e2011-08-28 12:45:30 -070071 // method pointers of CodeAndDirectMethods entries in the DexCaches.
72 void SetCodeAndDirectMethods(const ClassLoader* class_loader);
Brian Carlstrom8a487412011-08-29 20:08:52 -070073 void SetCodeAndDirectMethodsDexFile(const DexFile& dex_file);
Ian Rogers2c8f6532011-09-02 17:16:34 -070074
75 InstructionSet instruction_set_;
76 JniCompiler jni_compiler_;
77
Brian Carlstrom3320cf42011-10-04 14:58:28 -070078 typedef std::tr1::unordered_map<const Method*, CompiledMethod*, ObjectIdentityHash> MethodTable;
79 MethodTable compiled_methods_;
80
81 typedef std::tr1::unordered_map<const Method*, CompiledInvokeStub*, ObjectIdentityHash> InvokeStubTable;
82 InvokeStubTable compiled_invoke_stubs_;
83
Brian Carlstrom16192862011-09-12 17:50:06 -070084 bool verbose_;
85
Ian Rogers2c8f6532011-09-02 17:16:34 -070086 DISALLOW_COPY_AND_ASSIGN(Compiler);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070087};
88
89} // namespace art
90
91#endif // ART_SRC_COMPILER_H_