blob: a429c8738c91a4c1dbc1af3311cf019c566d6dbb [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 {
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
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
41inline 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
49inline uint32_t OatFile::OatMethod::GetQuickCodeSizeOffset() const {
50 const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
51 if (method_header == nullptr) {
52 return 0u;
53 }
Ian Rogers13735952014-10-08 12:43:28 -070054 return reinterpret_cast<const uint8_t*>(&method_header->code_size_) - begin_;
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070055}
56
Vladimir Marko7624d252014-05-02 14:40:15 +010057inline 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
65inline 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
73inline 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
Mathieu Chartier957ca1c2014-11-21 16:51:29 -080081const 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
93uint32_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
98uint32_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 uint8_t*>(&method_header->gc_map_offset_) - begin_;
104}
105
Vladimir Marko8a630572014-04-09 18:45:35 +0100106inline 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
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700111inline uint32_t OatFile::OatMethod::GetMappingTableOffsetOffset() const {
112 const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
113 if (method_header == nullptr) {
114 return 0u;
115 }
Ian Rogers13735952014-10-08 12:43:28 -0700116 return reinterpret_cast<const uint8_t*>(&method_header->mapping_table_offset_) - begin_;
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700117}
118
Vladimir Marko8a630572014-04-09 18:45:35 +0100119inline 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
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700124inline uint32_t OatFile::OatMethod::GetVmapTableOffsetOffset() const {
125 const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
126 if (method_header == nullptr) {
127 return 0u;
128 }
Ian Rogers13735952014-10-08 12:43:28 -0700129 return reinterpret_cast<const uint8_t*>(&method_header->vmap_table_offset_) - begin_;
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700130}
131
Vladimir Marko8a630572014-04-09 18:45:35 +0100132inline const uint8_t* OatFile::OatMethod::GetMappingTable() const {
133 const void* code = mirror::ArtMethod::EntryPointToCodePointer(GetQuickCode());
134 if (code == nullptr) {
135 return nullptr;
136 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100137 uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].mapping_table_offset_;
Vladimir Marko8a630572014-04-09 18:45:35 +0100138 if (UNLIKELY(offset == 0u)) {
139 return nullptr;
140 }
141 return reinterpret_cast<const uint8_t*>(code) - offset;
142}
143
144inline const uint8_t* OatFile::OatMethod::GetVmapTable() const {
145 const void* code = mirror::ArtMethod::EntryPointToCodePointer(GetQuickCode());
146 if (code == nullptr) {
147 return nullptr;
148 }
Vladimir Marko7624d252014-05-02 14:40:15 +0100149 uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].vmap_table_offset_;
Vladimir Marko8a630572014-04-09 18:45:35 +0100150 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_