blob: fd42e45dce637bba1f1085cb8fde90cded859384 [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"
Andreas Gampe97b28112018-12-04 09:09:12 -080021
22#include "base/utils.h"
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010023#include "oat_quick_method_header.h"
Santiago Aboy Solanes69a87e32022-03-08 16:43:54 +000024#include "runtime-inl.h"
Vladimir Marko8a630572014-04-09 18:45:35 +010025
26namespace art {
27
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070028inline const OatQuickMethodHeader* OatFile::OatMethod::GetOatQuickMethodHeader() const {
Peter Collingbourne584b1972022-02-08 17:48:42 -080029 const void* code = EntryPointToCodePointer(GetQuickCode());
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070030 if (code == nullptr) {
31 return nullptr;
32 }
33 // Return a pointer to the packed struct before the code.
34 return reinterpret_cast<const OatQuickMethodHeader*>(code) - 1;
35}
36
37inline uint32_t OatFile::OatMethod::GetOatQuickMethodHeaderOffset() const {
38 const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
39 if (method_header == nullptr) {
40 return 0u;
41 }
Ian Rogers13735952014-10-08 12:43:28 -070042 return reinterpret_cast<const uint8_t*>(method_header) - begin_;
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070043}
44
Vladimir Marko7624d252014-05-02 14:40:15 +010045inline size_t OatFile::OatMethod::GetFrameSizeInBytes() const {
Nicolas Geoffray6bc43742015-10-12 18:11:10 +010046 const void* code = EntryPointToCodePointer(GetQuickCode());
Vladimir Marko7624d252014-05-02 14:40:15 +010047 if (code == nullptr) {
48 return 0u;
49 }
Mingyao Yang063fc772016-08-02 11:02:54 -070050 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetFrameInfo().FrameSizeInBytes();
Vladimir Marko7624d252014-05-02 14:40:15 +010051}
52
53inline uint32_t OatFile::OatMethod::GetCoreSpillMask() const {
Nicolas Geoffray6bc43742015-10-12 18:11:10 +010054 const void* code = EntryPointToCodePointer(GetQuickCode());
Vladimir Marko7624d252014-05-02 14:40:15 +010055 if (code == nullptr) {
56 return 0u;
57 }
Mingyao Yang063fc772016-08-02 11:02:54 -070058 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetFrameInfo().CoreSpillMask();
Vladimir Marko7624d252014-05-02 14:40:15 +010059}
60
61inline uint32_t OatFile::OatMethod::GetFpSpillMask() const {
Nicolas Geoffray6bc43742015-10-12 18:11:10 +010062 const void* code = EntryPointToCodePointer(GetQuickCode());
Vladimir Marko7624d252014-05-02 14:40:15 +010063 if (code == nullptr) {
64 return 0u;
65 }
Mingyao Yang063fc772016-08-02 11:02:54 -070066 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetFrameInfo().FpSpillMask();
Vladimir Marko7624d252014-05-02 14:40:15 +010067}
68
Vladimir Marko8a630572014-04-09 18:45:35 +010069inline uint32_t OatFile::OatMethod::GetVmapTableOffset() const {
70 const uint8_t* vmap_table = GetVmapTable();
71 return static_cast<uint32_t>(vmap_table != nullptr ? vmap_table - begin_ : 0u);
72}
73
Vladimir Marko8a630572014-04-09 18:45:35 +010074inline const uint8_t* OatFile::OatMethod::GetVmapTable() const {
Peter Collingbourne584b1972022-02-08 17:48:42 -080075 const void* code = EntryPointToCodePointer(GetQuickCode());
Vladimir Marko8a630572014-04-09 18:45:35 +010076 if (code == nullptr) {
77 return nullptr;
78 }
David Srbecky113d6ea2021-03-02 22:49:46 +000079 uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetCodeInfoOffset();
Vladimir Marko8a630572014-04-09 18:45:35 +010080 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::GetQuickCodeSize() const {
Peter Collingbourne584b1972022-02-08 17:48:42 -080087 const void* code = EntryPointToCodePointer(GetQuickCode());
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +010088 if (code == nullptr) {
89 return 0u;
90 }
Mingyao Yang063fc772016-08-02 11:02:54 -070091 return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetCodeSize();
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +010092}
93
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +010094inline const void* OatFile::OatMethod::GetQuickCode() const {
Peter Collingbourne584b1972022-02-08 17:48:42 -080095 if (code_offset_ == 0) {
96 return nullptr;
97 }
98 return reinterpret_cast<const void *>(begin_ + code_offset_);
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +010099}
100
Santiago Aboy Solanes69a87e32022-03-08 16:43:54 +0000101inline const OatFile::BssMappingInfo* OatFile::FindBcpMappingInfo(const DexFile* dex_file) const {
102 ArrayRef<const OatFile::BssMappingInfo> mapping_info_vector(GetBcpBssInfo());
103 ArrayRef<const DexFile* const> bcp_dexfiles(
104 Runtime::Current()->GetClassLinker()->GetBootClassPath());
105 // Create a sub array to limit search range.
106 bcp_dexfiles = bcp_dexfiles.SubArray(/*pos=*/ 0u, mapping_info_vector.size());
107 auto it = std::find(bcp_dexfiles.begin(), bcp_dexfiles.end(), dex_file);
108 if (it != bcp_dexfiles.end()) {
109 return &mapping_info_vector[std::distance(bcp_dexfiles.begin(), it)];
110 } else {
111 return nullptr;
112 }
113}
114
Vladimir Marko8a630572014-04-09 18:45:35 +0100115} // namespace art
116
117#endif // ART_RUNTIME_OAT_FILE_INL_H_