blob: 5df652579fe12ce408cf74fc8be0a89aa94d110d [file] [log] [blame]
Vladimir Marko8a630572014-04-09 18:45:35 +01001/*
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
22namespace art {
23
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070024inline const OatQuickMethodHeader* OatFile::OatMethod::GetOatQuickMethodHeader() const {
Nicolas Geoffray0a5cd122015-07-16 14:15:05 +010025 const void* code = ArtMethod::EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_));
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070026 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
33inline uint32_t OatFile::OatMethod::GetOatQuickMethodHeaderOffset() const {
34 const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
35 if (method_header == nullptr) {
36 return 0u;
37 }
Ian Rogers13735952014-10-08 12:43:28 -070038 return reinterpret_cast<const uint8_t*>(method_header) - begin_;
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070039}
40
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070041inline uint32_t OatFile::OatMethod::GetQuickCodeSizeOffset() const {
42 const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
43 if (method_header == nullptr) {
44 return 0u;
45 }
Ian Rogers13735952014-10-08 12:43:28 -070046 return reinterpret_cast<const uint8_t*>(&method_header->code_size_) - begin_;
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070047}
48
Vladimir Marko7624d252014-05-02 14:40:15 +010049inline size_t OatFile::OatMethod::GetFrameSizeInBytes() const {
Mathieu Chartiere401d142015-04-22 13:56:20 -070050 const void* code = ArtMethod::EntryPointToCodePointer(GetQuickCode());
Vladimir Marko7624d252014-05-02 14:40:15 +010051 if (code == nullptr) {
52 return 0u;
53 }
54 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].frame_info_.FrameSizeInBytes();
55}
56
57inline uint32_t OatFile::OatMethod::GetCoreSpillMask() const {
Mathieu Chartiere401d142015-04-22 13:56:20 -070058 const void* code = ArtMethod::EntryPointToCodePointer(GetQuickCode());
Vladimir Marko7624d252014-05-02 14:40:15 +010059 if (code == nullptr) {
60 return 0u;
61 }
62 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].frame_info_.CoreSpillMask();
63}
64
65inline uint32_t OatFile::OatMethod::GetFpSpillMask() const {
Mathieu Chartiere401d142015-04-22 13:56:20 -070066 const void* code = ArtMethod::EntryPointToCodePointer(GetQuickCode());
Vladimir Marko7624d252014-05-02 14:40:15 +010067 if (code == nullptr) {
68 return 0u;
69 }
70 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].frame_info_.FpSpillMask();
71}
72
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +010073inline const uint8_t* OatFile::OatMethod::GetGcMap() const {
Nicolas Geoffray0a5cd122015-07-16 14:15:05 +010074 const void* code = ArtMethod::EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_));
Mathieu Chartier957ca1c2014-11-21 16:51:29 -080075 if (code == nullptr) {
76 return nullptr;
77 }
78 uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].gc_map_offset_;
79 if (UNLIKELY(offset == 0u)) {
80 return nullptr;
81 }
82 return reinterpret_cast<const uint8_t*>(code) - offset;
83}
84
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +010085inline uint32_t OatFile::OatMethod::GetGcMapOffset() const {
Mathieu Chartier957ca1c2014-11-21 16:51:29 -080086 const uint8_t* gc_map = GetGcMap();
87 return static_cast<uint32_t>(gc_map != nullptr ? gc_map - begin_ : 0u);
88}
89
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +010090inline uint32_t OatFile::OatMethod::GetGcMapOffsetOffset() const {
Mathieu Chartier957ca1c2014-11-21 16:51:29 -080091 const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
92 if (method_header == nullptr) {
93 return 0u;
94 }
95 return reinterpret_cast<const uint8_t*>(&method_header->gc_map_offset_) - begin_;
96}
97
Vladimir Marko8a630572014-04-09 18:45:35 +010098inline uint32_t OatFile::OatMethod::GetMappingTableOffset() const {
99 const uint8_t* mapping_table = GetMappingTable();
100 return static_cast<uint32_t>(mapping_table != nullptr ? mapping_table - begin_ : 0u);
101}
102
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700103inline uint32_t OatFile::OatMethod::GetMappingTableOffsetOffset() const {
104 const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
105 if (method_header == nullptr) {
106 return 0u;
107 }
Ian Rogers13735952014-10-08 12:43:28 -0700108 return reinterpret_cast<const uint8_t*>(&method_header->mapping_table_offset_) - begin_;
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700109}
110
Vladimir Marko8a630572014-04-09 18:45:35 +0100111inline uint32_t OatFile::OatMethod::GetVmapTableOffset() const {
112 const uint8_t* vmap_table = GetVmapTable();
113 return static_cast<uint32_t>(vmap_table != nullptr ? vmap_table - begin_ : 0u);
114}
115
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700116inline uint32_t OatFile::OatMethod::GetVmapTableOffsetOffset() const {
117 const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
118 if (method_header == nullptr) {
119 return 0u;
120 }
Ian Rogers13735952014-10-08 12:43:28 -0700121 return reinterpret_cast<const uint8_t*>(&method_header->vmap_table_offset_) - begin_;
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700122}
123
Vladimir Marko8a630572014-04-09 18:45:35 +0100124inline const uint8_t* OatFile::OatMethod::GetMappingTable() const {
Nicolas Geoffray0a5cd122015-07-16 14:15:05 +0100125 const void* code = ArtMethod::EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_));
Vladimir Marko8a630572014-04-09 18:45:35 +0100126 if (code == nullptr) {
127 return nullptr;
128 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100129 uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].mapping_table_offset_;
Vladimir Marko8a630572014-04-09 18:45:35 +0100130 if (UNLIKELY(offset == 0u)) {
131 return nullptr;
132 }
133 return reinterpret_cast<const uint8_t*>(code) - offset;
134}
135
136inline const uint8_t* OatFile::OatMethod::GetVmapTable() const {
Nicolas Geoffray0a5cd122015-07-16 14:15:05 +0100137 const void* code = ArtMethod::EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_));
Vladimir Marko8a630572014-04-09 18:45:35 +0100138 if (code == nullptr) {
139 return nullptr;
140 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100141 uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].vmap_table_offset_;
Vladimir Marko8a630572014-04-09 18:45:35 +0100142 if (UNLIKELY(offset == 0u)) {
143 return nullptr;
144 }
145 return reinterpret_cast<const uint8_t*>(code) - offset;
146}
147
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100148inline uint32_t OatFile::OatMethod::GetQuickCodeSize() const {
149 const void* code = ArtMethod::EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_));
150 if (code == nullptr) {
151 return 0u;
152 }
153 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_;
154}
155
156inline uint32_t OatFile::OatMethod::GetCodeOffset() const {
157 return (GetQuickCodeSize() == 0) ? 0 : code_offset_;
158}
159
160inline const void* OatFile::OatMethod::GetQuickCode() const {
161 return GetOatPointer<const void*>(GetCodeOffset());
162}
163
Vladimir Marko8a630572014-04-09 18:45:35 +0100164} // namespace art
165
166#endif // ART_RUNTIME_OAT_FILE_INL_H_