diff options
Diffstat (limited to 'src/class_linker.h')
| -rw-r--r-- | src/class_linker.h | 95 |
1 files changed, 72 insertions, 23 deletions
diff --git a/src/class_linker.h b/src/class_linker.h index 47f8c24017..d7bb1916c0 100644 --- a/src/class_linker.h +++ b/src/class_linker.h @@ -7,64 +7,90 @@ #include <utility> #include <vector> -#include "src/macros.h" -#include "src/thread.h" -#include "src/object.h" +#include "macros.h" +#include "raw_dex_file.h" +#include "thread.h" +#include "object.h" +#include "gtest/gtest.h" namespace art { class ClassLinker { public: // Initializes the class linker. - static ClassLinker* Create(); + static ClassLinker* Create(std::vector<RawDexFile*> boot_class_path); ~ClassLinker() {} + DexFile* AllocDexFile(); Class* AllocClass(DexFile* dex_file); StaticField* AllocStaticField(); InstanceField* AllocInstanceField(); Method* AllocMethod(); + ObjectArray* AllocObjectArray(size_t length); // Finds a class by its descriptor name. + // If raw_dex_file is null, searches boot_class_path_. Class* FindClass(const StringPiece& descriptor, - Object* class_loader); + Object* class_loader, + const RawDexFile* raw_dex_file); Class* FindSystemClass(const StringPiece& descriptor) { - return FindClass(descriptor, NULL); + return FindClass(descriptor, NULL, NULL); } - Class* FindPrimitiveClass(char type); - bool InitializeClass(Class* klass); Class* LookupClass(const StringPiece& descriptor, Object* class_loader); - Class* ResolveClass(const Class* referring, uint32_t class_idx); + Class* ResolveClass(const Class* referring, + uint32_t class_idx, + const RawDexFile* raw_dex_file); String* ResolveString(const Class* referring, uint32_t string_idx); - typedef std::pair<DexFile*, const RawDexFile::ClassDef*> ClassPathEntry; - - ClassPathEntry FindInClassPath(const StringPiece& descriptor); - - void AppendToClassPath(DexFile* dex_file); + void RegisterDexFile(RawDexFile* raw_dex_file); private: ClassLinker() {} - void Init(); + void Init(std::vector<RawDexFile*> boot_class_path_); Class* CreatePrimitiveClass(const StringPiece& descriptor); - Class* CreateArrayClass(const StringPiece& descriptor, Object* class_loader); + Class* CreateArrayClass(const StringPiece& descriptor, + Object* class_loader, + const RawDexFile* raw_dex_file); + + Class* FindPrimitiveClass(char type); + + const RawDexFile* FindRawDexFile(const DexFile* dex_file) const; + + DexFile* FindDexFile(const RawDexFile* raw_dex_file) const; + + typedef std::pair<const RawDexFile*, const RawDexFile::ClassDef*> ClassPathEntry; + + void AppendToBootClassPath(RawDexFile* raw_dex_file); + + ClassPathEntry FindInBootClassPath(const StringPiece& descriptor); - void LoadClass(const RawDexFile::ClassDef& class_def, Class* klass); + void LoadClass(const RawDexFile& raw_dex_file, + const RawDexFile::ClassDef& class_def, + Class* klass); - void LoadInterfaces(const RawDexFile::ClassDef& class_def, Class *klass); + void LoadInterfaces(const RawDexFile& raw_dex_file, + const RawDexFile::ClassDef& class_def, + Class *klass); - void LoadField(Class* klass, const RawDexFile::Field& src, Field* dst); + void LoadField(const RawDexFile& raw_dex_file, + const RawDexFile::Field& src, + Class* klass, + Field* dst); - void LoadMethod(Class* klass, const RawDexFile::Method& src, Method* dst); + void LoadMethod(const RawDexFile& raw_dex_file, + const RawDexFile::Method& src, + Class* klass, + Method* dst); // Inserts a class into the class table. Returns true if the class // was inserted. @@ -84,11 +110,27 @@ class ClassLinker { const Class* klass1, const Class* klass2); - bool LinkClass(Class* klass); + bool HasSameNameAndPrototype(const Method* m1, const Method* m2) const { + return HasSameName(m1, m2) && HasSamePrototype(m1, m2); + } + + bool HasSameName(const Method* m1, const Method* m2) const { + return m1->GetName() == m2->GetName(); + } + + bool HasSamePrototype(const Method* m1, const Method* m2) const { + return HasSameReturnType(m1, m2) && HasSameArgumentTypes(m1, m2); + } + + bool HasSameReturnType(const Method* m1, const Method* m2) const; + + bool HasSameArgumentTypes(const Method* m1, const Method* m2) const; + + bool LinkClass(Class* klass, const RawDexFile* raw_dex_file); bool LinkSuperClass(Class* klass); - bool LinkInterfaces(Class* klass); + bool LinkInterfaces(Class* klass, const RawDexFile* raw_dex_file); bool LinkMethods(Class* klass); @@ -102,7 +144,11 @@ class ClassLinker { void CreateReferenceOffsets(Class* klass); - std::vector<DexFile*> class_path_; + std::vector<RawDexFile*> boot_class_path_; + + std::vector<RawDexFile*> raw_dex_files_; + + std::vector<DexFile*> dex_files_; // TODO: multimap typedef std::map<const StringPiece, Class*> Table; @@ -131,8 +177,11 @@ class ClassLinker { Class* primitive_long_; Class* primitive_void_; + Class* object_array_class_; Class* char_array_class_; + FRIEND_TEST(ClassLinkerTest, ProtoCompare); + FRIEND_TEST(ClassLinkerTest, ProtoCompare2); DISALLOW_COPY_AND_ASSIGN(ClassLinker); }; |