1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ART_RUNTIME_OAT_FILE_INL_H_
18 #define ART_RUNTIME_OAT_FILE_INL_H_
19 
20 #include "oat_file.h"
21 
22 namespace art {
23 
GetOatQuickMethodHeader()24 inline const OatQuickMethodHeader* OatFile::OatMethod::GetOatQuickMethodHeader() const {
25   const void* code = mirror::ArtMethod::EntryPointToCodePointer(GetQuickCode());
26   if (code == nullptr) {
27     return nullptr;
28   }
29   // Return a pointer to the packed struct before the code.
30   return reinterpret_cast<const OatQuickMethodHeader*>(code) - 1;
31 }
32 
GetOatQuickMethodHeaderOffset()33 inline uint32_t OatFile::OatMethod::GetOatQuickMethodHeaderOffset() const {
34   const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
35   if (method_header == nullptr) {
36     return 0u;
37   }
38   return reinterpret_cast<const byte*>(method_header) - begin_;
39 }
40 
GetQuickCodeSize()41 inline uint32_t OatFile::OatMethod::GetQuickCodeSize() const {
42   const void* code = mirror::ArtMethod::EntryPointToCodePointer(GetQuickCode());
43   if (code == nullptr) {
44     return 0u;
45   }
46   return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_;
47 }
48 
GetQuickCodeSizeOffset()49 inline uint32_t OatFile::OatMethod::GetQuickCodeSizeOffset() const {
50   const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
51   if (method_header == nullptr) {
52     return 0u;
53   }
54   return reinterpret_cast<const byte*>(&method_header->code_size_) - begin_;
55 }
56 
GetFrameSizeInBytes()57 inline size_t OatFile::OatMethod::GetFrameSizeInBytes() const {
58   const void* code = mirror::ArtMethod::EntryPointToCodePointer(GetQuickCode());
59   if (code == nullptr) {
60     return 0u;
61   }
62   return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].frame_info_.FrameSizeInBytes();
63 }
64 
GetCoreSpillMask()65 inline uint32_t OatFile::OatMethod::GetCoreSpillMask() const {
66   const void* code = mirror::ArtMethod::EntryPointToCodePointer(GetQuickCode());
67   if (code == nullptr) {
68     return 0u;
69   }
70   return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].frame_info_.CoreSpillMask();
71 }
72 
GetFpSpillMask()73 inline uint32_t OatFile::OatMethod::GetFpSpillMask() const {
74   const void* code = mirror::ArtMethod::EntryPointToCodePointer(GetQuickCode());
75   if (code == nullptr) {
76     return 0u;
77   }
78   return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].frame_info_.FpSpillMask();
79 }
80 
GetGcMap()81 const uint8_t* OatFile::OatMethod::GetGcMap() const {
82   const void* code = mirror::ArtMethod::EntryPointToCodePointer(GetQuickCode());
83   if (code == nullptr) {
84     return nullptr;
85   }
86   uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].gc_map_offset_;
87   if (UNLIKELY(offset == 0u)) {
88     return nullptr;
89   }
90   return reinterpret_cast<const uint8_t*>(code) - offset;
91 }
92 
GetGcMapOffset()93 uint32_t OatFile::OatMethod::GetGcMapOffset() const {
94   const uint8_t* gc_map = GetGcMap();
95   return static_cast<uint32_t>(gc_map != nullptr ? gc_map - begin_ : 0u);
96 }
97 
GetGcMapOffsetOffset()98 uint32_t OatFile::OatMethod::GetGcMapOffsetOffset() const {
99   const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
100   if (method_header == nullptr) {
101     return 0u;
102   }
103   return reinterpret_cast<const byte*>(&method_header->gc_map_offset_) - begin_;
104 }
105 
GetMappingTableOffset()106 inline uint32_t OatFile::OatMethod::GetMappingTableOffset() const {
107   const uint8_t* mapping_table = GetMappingTable();
108   return static_cast<uint32_t>(mapping_table != nullptr ? mapping_table - begin_ : 0u);
109 }
110 
GetMappingTableOffsetOffset()111 inline uint32_t OatFile::OatMethod::GetMappingTableOffsetOffset() const {
112   const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
113   if (method_header == nullptr) {
114     return 0u;
115   }
116   return reinterpret_cast<const byte*>(&method_header->mapping_table_offset_) - begin_;
117 }
118 
GetVmapTableOffset()119 inline uint32_t OatFile::OatMethod::GetVmapTableOffset() const {
120   const uint8_t* vmap_table = GetVmapTable();
121   return static_cast<uint32_t>(vmap_table != nullptr ? vmap_table - begin_ : 0u);
122 }
123 
GetVmapTableOffsetOffset()124 inline uint32_t OatFile::OatMethod::GetVmapTableOffsetOffset() const {
125   const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
126   if (method_header == nullptr) {
127     return 0u;
128   }
129   return reinterpret_cast<const byte*>(&method_header->vmap_table_offset_) - begin_;
130 }
131 
GetMappingTable()132 inline const uint8_t* OatFile::OatMethod::GetMappingTable() const {
133   const void* code = mirror::ArtMethod::EntryPointToCodePointer(GetQuickCode());
134   if (code == nullptr) {
135     return nullptr;
136   }
137   uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].mapping_table_offset_;
138   if (UNLIKELY(offset == 0u)) {
139     return nullptr;
140   }
141   return reinterpret_cast<const uint8_t*>(code) - offset;
142 }
143 
GetVmapTable()144 inline const uint8_t* OatFile::OatMethod::GetVmapTable() const {
145   const void* code = mirror::ArtMethod::EntryPointToCodePointer(GetQuickCode());
146   if (code == nullptr) {
147     return nullptr;
148   }
149   uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].vmap_table_offset_;
150   if (UNLIKELY(offset == 0u)) {
151     return nullptr;
152   }
153   return reinterpret_cast<const uint8_t*>(code) - offset;
154 }
155 
156 }  // namespace art
157 
158 #endif  // ART_RUNTIME_OAT_FILE_INL_H_
159