• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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_OAT_FILE_INL_H_
18 #define ART_RUNTIME_OAT_OAT_FILE_INL_H_
19 
20 #include "oat_file.h"
21 
22 #include "base/utils.h"
23 #include "oat_quick_method_header.h"
24 #include "runtime-inl.h"
25 
26 namespace art HIDDEN {
27 
GetOatQuickMethodHeader()28 inline const OatQuickMethodHeader* OatFile::OatMethod::GetOatQuickMethodHeader() const {
29   const void* code = EntryPointToCodePointer(GetQuickCode());
30   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 
GetOatQuickMethodHeaderOffset()37 inline uint32_t OatFile::OatMethod::GetOatQuickMethodHeaderOffset() const {
38   const OatQuickMethodHeader* method_header = GetOatQuickMethodHeader();
39   if (method_header == nullptr) {
40     return 0u;
41   }
42   return reinterpret_cast<const uint8_t*>(method_header) - begin_;
43 }
44 
GetFrameSizeInBytes()45 inline size_t OatFile::OatMethod::GetFrameSizeInBytes() const {
46   const void* code = EntryPointToCodePointer(GetQuickCode());
47   if (code == nullptr) {
48     return 0u;
49   }
50   return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetFrameInfo().FrameSizeInBytes();
51 }
52 
GetCoreSpillMask()53 inline uint32_t OatFile::OatMethod::GetCoreSpillMask() const {
54   const void* code = EntryPointToCodePointer(GetQuickCode());
55   if (code == nullptr) {
56     return 0u;
57   }
58   return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetFrameInfo().CoreSpillMask();
59 }
60 
GetFpSpillMask()61 inline uint32_t OatFile::OatMethod::GetFpSpillMask() const {
62   const void* code = EntryPointToCodePointer(GetQuickCode());
63   if (code == nullptr) {
64     return 0u;
65   }
66   return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetFrameInfo().FpSpillMask();
67 }
68 
GetVmapTableOffset()69 inline 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 
GetVmapTable()74 inline const uint8_t* OatFile::OatMethod::GetVmapTable() const {
75   const void* code = EntryPointToCodePointer(GetQuickCode());
76   if (code == nullptr) {
77     return nullptr;
78   }
79   uint32_t offset = reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetCodeInfoOffset();
80   if (UNLIKELY(offset == 0u)) {
81     return nullptr;
82   }
83   return reinterpret_cast<const uint8_t*>(code) - offset;
84 }
85 
GetQuickCodeSize()86 inline uint32_t OatFile::OatMethod::GetQuickCodeSize() const {
87   const void* code = EntryPointToCodePointer(GetQuickCode());
88   if (code == nullptr) {
89     return 0u;
90   }
91   return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].GetCodeSize();
92 }
93 
GetQuickCode()94 inline const void* OatFile::OatMethod::GetQuickCode() const {
95   if (code_offset_ == 0) {
96     return nullptr;
97   }
98   return reinterpret_cast<const void *>(begin_ + code_offset_);
99 }
100 
FindBcpMappingInfo(const DexFile * dex_file)101 inline 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 
115 }  // namespace art
116 
117 #endif  // ART_RUNTIME_OAT_OAT_FILE_INL_H_
118