blob: 6027ddaac22d66fe7f4cb9db371875f235caf68e [file] [log] [blame]
Brian Carlstrome24fa612011-09-29 00:53:55 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#ifndef ART_SRC_OAT_FILE_H_
4#define ART_SRC_OAT_FILE_H_
5
6#include <vector>
7
8#include "dex_file.h"
9#include "mem_map.h"
10#include "oat.h"
11
12namespace art {
13
14class OatFile {
15 public:
16
17 // Open an oat file. Returns NULL on failure. Requested base can
18 // optionally be used to request where the file should be loaded.
19 static OatFile* Open(const std::string& filename,
20 const std::string& strip_location_prefix,
21 byte* requested_base);
22
23 ~OatFile();
24
25 const std::string& GetLocation() const {
26 return location_;
27 }
28
29 const OatHeader& GetOatHeader() const;
30
31 class OatDexFile;
32
33 class OatClass {
34 public:
35 // get the code for the method based on its index into the class
36 // defintion. direct methods come first, followed by virtual
37 // methods. note that runtime created methods such as miranda
38 // methods are not included.
39 const void* GetMethodCode(uint32_t method_index) const;
40 ~OatClass();
41
42 private:
43 OatClass(const OatFile* oat_file, const uint32_t* methods_pointer);
44
45 const OatFile* oat_file_;
46 const uint32_t* methods_pointer_;
47
48 friend class OatDexFile;
49 };
50
51 class OatDexFile {
52 public:
53 const OatClass GetOatClass(uint32_t class_def_index) const;
Brian Carlstrom58ae9412011-10-04 00:56:06 -070054
55 uint32_t GetDexFileChecksum() const {
56 return dex_file_checksum_;
57 }
58
Brian Carlstrome24fa612011-09-29 00:53:55 -070059 ~OatDexFile();
60 private:
61 OatDexFile(const OatFile* oat_file,
62 std::string dex_file_location,
63 uint32_t dex_file_checksum,
64 uint32_t* classes_pointer);
65
66 const OatFile* oat_file_;
67 std::string dex_file_location_;
68 uint32_t dex_file_checksum_;
69 const uint32_t* classes_pointer_;
70
71 friend class OatFile;
72 DISALLOW_COPY_AND_ASSIGN(OatDexFile);
73 };
74
Brian Carlstrom58ae9412011-10-04 00:56:06 -070075 const OatDexFile& GetOatDexFile(const std::string& dex_file_location);
Brian Carlstrome24fa612011-09-29 00:53:55 -070076
77 size_t GetSize() const {
78 return GetLimit() - GetBase();
79 }
80
81 private:
82 OatFile(const std::string& filename);
83 bool Read(const std::string& filename, byte* requested_base);
84
85 const byte* GetBase() const;
86 const byte* GetLimit() const;
87
88 // The oat file name.
89 //
90 // The image will embed this to link its associated oat file.
91 const std::string location_;
92
93 // backing memory map for oat file
94 UniquePtr<MemMap> mem_map_;
95
96 typedef std::map<std::string, const OatDexFile*> Table;
97 Table oat_dex_files_;
98
99 friend class OatClass;
100 friend class OatDexFile;
101 DISALLOW_COPY_AND_ASSIGN(OatFile);
102};
103
104} // namespace art
105
106#endif // ART_SRC_OAT_WRITER_H_