blob: 3796dc2da19925c95499bc97492858492b0e3ffd [file] [log] [blame]
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#ifndef ART_SRC_CLASS_LINKER_H_
4#define ART_SRC_CLASS_LINKER_H_
5
6#include <map>
7#include <utility>
8#include <vector>
9
10#include "src/macros.h"
11#include "src/thread.h"
12#include "src/object.h"
13
14namespace art {
15
16class ClassLinker {
17 public:
18 ClassLinker() {}
19 ~ClassLinker() {}
20
Carl Shapiro565f5072011-07-10 13:39:43 -070021 // Initializes the class linker.
22 void Init();
23
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070024 // Finds a class by its descriptor name.
25 Class* FindClass(const char* descriptor,
26 Object* class_loader,
27 DexFile* dex_file);
28
Carl Shapiro565f5072011-07-10 13:39:43 -070029 Class* FindSystemClass(const char* descriptor) {
30 return FindClass(descriptor, NULL, NULL);
31 }
32
Brian Carlstrom934486c2011-07-12 23:42:50 -070033 bool LoadClass(const char* descriptor, Class* klass);
34
35 bool LoadClass(const RawDexFile::ClassDef& class_def, Class* klass);
36
Carl Shapiro565f5072011-07-10 13:39:43 -070037 Class* FindPrimitiveClass(JType type);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070038
39 bool InitializeClass(Class* klass);
40
41 Class* LookupClass(const char* descriptor, Object* class_loader);
42
Carl Shapiro5fafe2b2011-07-09 15:34:41 -070043 Class* ResolveClass(const Class* referring, uint32_t class_idx);
44
45 String* ResolveString(const Class* referring, uint32_t string_idx);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070046
47 DexFile* FindInClassPath(const char* descriptor);
48
49 void AppendToClassPath(DexFile* dex_file);
50
51 private:
Carl Shapiro565f5072011-07-10 13:39:43 -070052 Class* CreatePrimitiveClass(JType type, const char* descriptor);
53
Brian Carlstrom934486c2011-07-12 23:42:50 -070054 void LoadInterfaces(const RawDexFile::ClassDef& class_def, Class *klass);
55
56 void LoadField(Class* klass, const RawDexFile::Field& src, Field* dst);
57
58 void LoadMethod(Class* klass, const RawDexFile::Method& src, Method* dst);
59
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070060 // Inserts a class into the class table. Returns true if the class
61 // was inserted.
62 bool InsertClass(Class* klass);
63
64 bool InitializeSuperClass(Class* klass);
65
66 void InitializeStaticFields(Class* klass);
67
68 bool ValidateSuperClassDescriptors(const Class* klass);
69
70 bool HasSameDescriptorClasses(const char* descriptor,
71 const Class* klass1,
72 const Class* klass2);
73
74 bool HasSameMethodDescriptorClasses(const Method* descriptor,
75 const Class* klass1,
76 const Class* klass2);
77
78 bool LinkClass(Class* klass);
79
80 bool LinkSuperClass(Class* klass);
81
82 bool LinkInterfaces(Class* klass);
83
84 bool LinkMethods(Class* klass);
85
86 bool LinkVirtualMethods(Class* klass);
87
88 bool LinkInterfaceMethods(Class* klass);
89
90 void LinkAbstractMethods(Class* klass);
91
92 bool LinkInstanceFields(Class* klass);
93
94 void CreateReferenceOffsets(Class* klass);
95
96 std::vector<DexFile*> class_path_;
97
98 // TODO: multimap
99 typedef std::map<const char*, Class*, CStringLt> Table;
100
101 Table classes_;
102
103 Mutex* classes_lock_;
104
105 // TODO: classpath
106
Carl Shapiro565f5072011-07-10 13:39:43 -0700107 Class* primitive_boolean_;
108 Class* primitive_char_;
109 Class* primitive_float_;
110 Class* primitive_double_;
111 Class* primitive_byte_;
112 Class* primitive_short_;
113 Class* primitive_int_;
114 Class* primitive_long_;
115 Class* primitive_void_;
116
Brian Carlstrom934486c2011-07-12 23:42:50 -0700117 Class* java_lang_Object_;
Carl Shapiro565f5072011-07-10 13:39:43 -0700118 Class* java_lang_Class_;
119
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700120 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
121};
122
123} // namespace art
124
125#endif // ART_SRC_CLASS_LINKER_H_