blob: 721fab993f9e7ba26bc363c077e46902676cebcb [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 }
Mingyao Yang063fc772016-08-02 11:02:54 -070047 return reinterpret_cast<const uint8_t*>(method_header->GetCodeSizeAddr()) - 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 }
Mingyao Yang063fc772016-08-02 11:02:54 -070055 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetFrameInfo().FrameSizeInBytes();
Vladimir Marko7624d252014-05-02 14:40:15 +010056}
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 }
Mingyao Yang063fc772016-08-02 11:02:54 -070063 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetFrameInfo().CoreSpillMask();
Vladimir Marko7624d252014-05-02 14:40:15 +010064}
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 }
Mingyao Yang063fc772016-08-02 11:02:54 -070071 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetFrameInfo().FpSpillMask();
Vladimir Marko7624d252014-05-02 14:40:15 +010072}
73
Vladimir Marko8a630572014-04-09 18:45:35 +010074inline uint32_t OatFile::OatMethod::GetVmapTableOffset() const {
75 const uint8_t* vmap_table = GetVmapTable();
76 return static_cast<uint32_t>(vmap_table != nullptr ? vmap_table - begin_ : 0u);
77}
78
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070079inline uint32_t OatFile::OatMethod::GetVmapTableOffsetOffset() const {
80 const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
81 if (method_header == nullptr) {
82 return 0u;
83 }
Mingyao Yang063fc772016-08-02 11:02:54 -070084 return reinterpret_cast<const uint8_t*>(method_header->GetVmapTableOffsetAddr()) - begin_;
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070085}
86
Vladimir Marko8a630572014-04-09 18:45:35 +010087inline const uint8_t* OatFile::OatMethod::GetVmapTable() const {
Nicolas Geoffray6bc43742015-10-12 18:11:10 +010088 const void* code = EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_));
Vladimir Marko8a630572014-04-09 18:45:35 +010089 if (code == nullptr) {
90 return nullptr;
91 }
Mingyao Yang063fc772016-08-02 11:02:54 -070092 uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetVmapTableOffset();
Vladimir Marko8a630572014-04-09 18:45:35 +010093 if (UNLIKELY(offset == 0u)) {
94 return nullptr;
95 }
96 return reinterpret_cast<const uint8_t*>(code) - offset;
97}
98
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +010099inline uint32_t OatFile::OatMethod::GetQuickCodeSize() const {
Nicolas Geoffray6bc43742015-10-12 18:11:10 +0100100 const void* code = EntryPointToCodePointer(GetOatPointer<const void*>(code_offset_));
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100101 if (code == nullptr) {
102 return 0u;
103 }
Mingyao Yang063fc772016-08-02 11:02:54 -0700104 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetCodeSize();
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100105}
106
107inline uint32_t OatFile::OatMethod::GetCodeOffset() const {
108 return (GetQuickCodeSize() == 0) ? 0 : code_offset_;
109}
110
111inline const void* OatFile::OatMethod::GetQuickCode() const {
112 return GetOatPointer<const void*>(GetCodeOffset());
113}
114
Vladimir Marko8a630572014-04-09 18:45:35 +0100115} // namespace art
116
117#endif // ART_RUNTIME_OAT_FILE_INL_H_