blob: 2528a6c5a17d8836987d4dadc9d8173bee37d3e8 [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;
54 ~OatDexFile();
55 private:
56 OatDexFile(const OatFile* oat_file,
57 std::string dex_file_location,
58 uint32_t dex_file_checksum,
59 uint32_t* classes_pointer);
60
61 const OatFile* oat_file_;
62 std::string dex_file_location_;
63 uint32_t dex_file_checksum_;
64 const uint32_t* classes_pointer_;
65
66 friend class OatFile;
67 DISALLOW_COPY_AND_ASSIGN(OatDexFile);
68 };
69
70 const OatDexFile& GetOatDexFile(const DexFile& dex_file);
71
72 size_t GetSize() const {
73 return GetLimit() - GetBase();
74 }
75
76 private:
77 OatFile(const std::string& filename);
78 bool Read(const std::string& filename, byte* requested_base);
79
80 const byte* GetBase() const;
81 const byte* GetLimit() const;
82
83 // The oat file name.
84 //
85 // The image will embed this to link its associated oat file.
86 const std::string location_;
87
88 // backing memory map for oat file
89 UniquePtr<MemMap> mem_map_;
90
91 typedef std::map<std::string, const OatDexFile*> Table;
92 Table oat_dex_files_;
93
94 friend class OatClass;
95 friend class OatDexFile;
96 DISALLOW_COPY_AND_ASSIGN(OatFile);
97};
98
99} // namespace art
100
101#endif // ART_SRC_OAT_WRITER_H_