blob: 7b92120fde9d7bb08103160c8d22d49cd1a6b7fd [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"
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010021#include "oat_quick_method_header.h"
Vladimir Marko8a630572014-04-09 18:45:35 +010022
23namespace art {
24
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070025inline const OatQuickMethodHeader* OatFile::OatMethod::GetOatQuickMethodHeader() const {
Nicolas Geoffray6bc43742015-10-12 18:11:10 +010026 const void* code = EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_));
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070027 if (code == nullptr) {
28 return nullptr;
29 }
30 // Return a pointer to the packed struct before the code.
31 return reinterpret_cast<const OatQuickMethodHeader*>(code) - 1;
32}
33
34inline uint32_t OatFile::OatMethod::GetOatQuickMethodHeaderOffset() const {
35 const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
36 if (method_header == nullptr) {
37 return 0u;
38 }
Ian Rogers13735952014-10-08 12:43:28 -070039 return reinterpret_cast<const uint8_t*>(method_header) - begin_;
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070040}
41
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070042inline uint32_t OatFile::OatMethod::GetQuickCodeSizeOffset() const {
43 const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
44 if (method_header == nullptr) {
45 return 0u;
46 }
Ian Rogers13735952014-10-08 12:43:28 -070047 return reinterpret_cast<const uint8_t*>(&method_header->code_size_) - begin_;
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070048}
49
Vladimir Marko7624d252014-05-02 14:40:15 +010050inline size_t OatFile::OatMethod::GetFrameSizeInBytes() const {
Nicolas Geoffray6bc43742015-10-12 18:11:10 +010051 const void* code = EntryPointToCodePointer(GetQuickCode());
Vladimir Marko7624d252014-05-02 14:40:15 +010052 if (code == nullptr) {
53 return 0u;
54 }
55 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].frame_info_.FrameSizeInBytes();
56}
57
58inline uint32_t OatFile::OatMethod::GetCoreSpillMask() const {
Nicolas Geoffray6bc43742015-10-12 18:11:10 +010059 const void* code = EntryPointToCodePointer(GetQuickCode());
Vladimir Marko7624d252014-05-02 14:40:15 +010060 if (code == nullptr) {
61 return 0u;
62 }
63 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].frame_info_.CoreSpillMask();
64}
65
66inline uint32_t OatFile::OatMethod::GetFpSpillMask() const {
Nicolas Geoffray6bc43742015-10-12 18:11:10 +010067 const void* code = EntryPointToCodePointer(GetQuickCode());
Vladimir Marko7624d252014-05-02 14:40:15 +010068 if (code == nullptr) {
69 return 0u;
70 }
71 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].frame_info_.FpSpillMask();
72}
73
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +010074inline const uint8_t* OatFile::OatMethod::GetGcMap() const {
Nicolas Geoffray6bc43742015-10-12 18:11:10 +010075 const void* code = EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_));
Mathieu Chartier957ca1c2014-11-21 16:51:29 -080076 if (code == nullptr) {
77 return nullptr;
78 }
79 uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].gc_map_offset_;
80 if (UNLIKELY(offset == 0u)) {
81 return nullptr;
82 }
83 return reinterpret_cast<const uint8_t*>(code) - offset;
84}
85
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +010086inline uint32_t OatFile::OatMethod::GetGcMapOffset() const {
Mathieu Chartier957ca1c2014-11-21 16:51:29 -080087 const uint8_t* gc_map = GetGcMap();
88 return static_cast<uint32_t>(gc_map != nullptr ? gc_map - begin_ : 0u);
89}
90
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +010091inline uint32_t OatFile::OatMethod::GetGcMapOffsetOffset() const {
Mathieu Chartier957ca1c2014-11-21 16:51:29 -080092 const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
93 if (method_header == nullptr) {
94 return 0u;
95 }
96 return reinterpret_cast<const uint8_t*>(&method_header->gc_map_offset_) - begin_;
97}
98
Vladimir Marko8a630572014-04-09 18:45:35 +010099inline uint32_t OatFile::OatMethod::GetMappingTableOffset() const {
100 const uint8_t* mapping_table = GetMappingTable();
101 return static_cast<uint32_t>(mapping_table != nullptr ? mapping_table - begin_ : 0u);
102}
103
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700104inline uint32_t OatFile::OatMethod::GetMappingTableOffsetOffset() const {
105 const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
106 if (method_header == nullptr) {
107 return 0u;
108 }
Ian Rogers13735952014-10-08 12:43:28 -0700109 return reinterpret_cast<const uint8_t*>(&method_header->mapping_table_offset_) - begin_;
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700110}
111
Vladimir Marko8a630572014-04-09 18:45:35 +0100112inline uint32_t OatFile::OatMethod::GetVmapTableOffset() const {
113 const uint8_t* vmap_table = GetVmapTable();
114 return static_cast<uint32_t>(vmap_table != nullptr ? vmap_table - begin_ : 0u);
115}
116
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700117inline uint32_t OatFile::OatMethod::GetVmapTableOffsetOffset() const {
118 const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
119 if (method_header == nullptr) {
120 return 0u;
121 }
Ian Rogers13735952014-10-08 12:43:28 -0700122 return reinterpret_cast<const uint8_t*>(&method_header->vmap_table_offset_) - begin_;
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700123}
124
Vladimir Marko8a630572014-04-09 18:45:35 +0100125inline const uint8_t* OatFile::OatMethod::GetMappingTable() const {
Nicolas Geoffray6bc43742015-10-12 18:11:10 +0100126 const void* code = EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_));
Vladimir Marko8a630572014-04-09 18:45:35 +0100127 if (code == nullptr) {
128 return nullptr;
129 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100130 uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].mapping_table_offset_;
Vladimir Marko8a630572014-04-09 18:45:35 +0100131 if (UNLIKELY(offset == 0u)) {
132 return nullptr;
133 }
134 return reinterpret_cast<const uint8_t*>(code) - offset;
135}
136
137inline const uint8_t* OatFile::OatMethod::GetVmapTable() const {
Nicolas Geoffray6bc43742015-10-12 18:11:10 +0100138 const void* code = EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_));
Vladimir Marko8a630572014-04-09 18:45:35 +0100139 if (code == nullptr) {
140 return nullptr;
141 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100142 uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].vmap_table_offset_;
Vladimir Marko8a630572014-04-09 18:45:35 +0100143 if (UNLIKELY(offset == 0u)) {
144 return nullptr;
145 }
146 return reinterpret_cast<const uint8_t*>(code) - offset;
147}
148
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100149inline uint32_t OatFile::OatMethod::GetQuickCodeSize() const {
Nicolas Geoffray6bc43742015-10-12 18:11:10 +0100150 const void* code = EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_));
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100151 if (code == nullptr) {
152 return 0u;
153 }
154 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_;
155}
156
157inline uint32_t OatFile::OatMethod::GetCodeOffset() const {
158 return (GetQuickCodeSize() == 0) ? 0 : code_offset_;
159}
160
161inline const void* OatFile::OatMethod::GetQuickCode() const {
162 return GetOatPointer<const void*>(GetCodeOffset());
163}
164
Vladimir Marko8a630572014-04-09 18:45:35 +0100165} // namespace art
166
167#endif // ART_RUNTIME_OAT_FILE_INL_H_