blob: 0f6f02f2bdbadbcabad10a1a277f5dd5fc5fde59 [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
Ian Rogers2c8f6532011-09-02 17:16:34 -07006#include "constants.h"
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -07007#include "dex_file.h"
Ian Rogers2c8f6532011-09-02 17:16:34 -07008#include "jni_compiler.h"
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -07009#include "object.h"
Ian Rogers1cb0a1d2011-10-06 15:24:35 -070010#include "runtime.h"
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070011
Ian Rogersd6b1f612011-09-27 13:38:14 -070012int oatVRegOffsetFromMethod(art::Method* method, int reg);
13
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070014namespace art {
15
16class Compiler {
17 public:
Shih-wei Liaoc486c112011-09-13 16:43:52 -070018 explicit Compiler(InstructionSet insns);
Ian Rogers2c8f6532011-09-02 17:16:34 -070019
Brian Carlstrom8a487412011-08-29 20:08:52 -070020 // Compile all Methods of all the Classes of all the DexFiles that are part of a ClassLoader.
21 void CompileAll(const ClassLoader* class_loader);
22
23 // Compile a single Method
24 void CompileOne(Method* method);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070025
Brian Carlstrom16192862011-09-12 17:50:06 -070026 void SetVerbose(bool verbose) {
27 verbose_ = verbose;
28 }
29
30 bool IsVerbose() const {
31 return verbose_;
32 }
33
Brian Carlstrome24fa612011-09-29 00:53:55 -070034 // Stub to throw AbstractMethodError
Brian Carlstrome24fa612011-09-29 00:53:55 -070035 static ByteArray* CreateAbstractMethodErrorStub(InstructionSet instruction_set);
36
Ian Rogersad25ac52011-10-04 19:13:33 -070037 // Generate the trampoline that's invoked by unresolved direct methods
Ian Rogers1cb0a1d2011-10-06 15:24:35 -070038 static ByteArray* CreateResolutionStub(InstructionSet instruction_set,
39 Runtime::TrampolineType type);
Ian Rogersad25ac52011-10-04 19:13:33 -070040
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070041 private:
42 // Attempt to resolve all type, methods, fields, and strings
43 // referenced from code in the dex file following PathClassLoader
44 // ordering semantics.
45 void Resolve(const ClassLoader* class_loader);
46 void ResolveDexFile(const ClassLoader* class_loader, const DexFile& dex_file);
47
jeffhao98eacac2011-09-14 16:11:53 -070048 void Verify(const ClassLoader* class_loader);
49 void VerifyDexFile(const ClassLoader* class_loader, const DexFile& dex_file);
50
Brian Carlstroma5a97a22011-09-15 14:08:49 -070051 void InitializeClassesWithoutClinit(const ClassLoader* class_loader);
52 void InitializeClassesWithoutClinit(const ClassLoader* class_loader, const DexFile& dex_file);
53
Brian Carlstrom83db7722011-08-26 17:32:56 -070054 void Compile(const ClassLoader* class_loader);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070055 void CompileDexFile(const ClassLoader* class_loader, const DexFile& dex_file);
56 void CompileClass(Class* klass);
57 void CompileMethod(Method* klass);
Brian Carlstrom83db7722011-08-26 17:32:56 -070058
59 // After compiling, walk all the DexCaches and set the code and
Brian Carlstrom9cc262e2011-08-28 12:45:30 -070060 // method pointers of CodeAndDirectMethods entries in the DexCaches.
61 void SetCodeAndDirectMethods(const ClassLoader* class_loader);
Brian Carlstrom8a487412011-08-29 20:08:52 -070062 void SetCodeAndDirectMethodsDexFile(const DexFile& dex_file);
Ian Rogers2c8f6532011-09-02 17:16:34 -070063
64 InstructionSet instruction_set_;
65 JniCompiler jni_compiler_;
66
Brian Carlstrom16192862011-09-12 17:50:06 -070067 bool verbose_;
68
Ian Rogers2c8f6532011-09-02 17:16:34 -070069 DISALLOW_COPY_AND_ASSIGN(Compiler);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070070};
71
72} // namespace art
73
74#endif // ART_SRC_COMPILER_H_