Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | */ |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 16 | |
| 17 | #include "oat_file.h" |
| 18 | |
| 19 | #include <sys/mman.h> |
| 20 | |
| 21 | #include "file.h" |
| 22 | #include "os.h" |
| 23 | #include "stl_util.h" |
| 24 | |
| 25 | namespace art { |
| 26 | |
jeffhao | 262bf46 | 2011-10-20 18:36:32 -0700 | [diff] [blame] | 27 | std::string OatFile::DexFilenameToOatFilename(const std::string& location) { |
jeffhao | 262bf46 | 2011-10-20 18:36:32 -0700 | [diff] [blame] | 28 | CHECK(IsValidDexFilename(location) || IsValidZipFilename(location)); |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 29 | std::string oat_location(location); |
| 30 | oat_location += ".oat"; |
jeffhao | 262bf46 | 2011-10-20 18:36:32 -0700 | [diff] [blame] | 31 | return oat_location; |
Brian Carlstrom | b7bbba4 | 2011-10-13 14:58:47 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 34 | OatFile* OatFile::Open(const std::string& filename, |
| 35 | const std::string& strip_location_prefix, |
| 36 | byte* requested_base) { |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 37 | StringPiece location(filename); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 38 | if (!location.starts_with(strip_location_prefix)) { |
| 39 | LOG(ERROR) << filename << " does not start with " << strip_location_prefix; |
| 40 | return NULL; |
| 41 | } |
| 42 | location.remove_prefix(strip_location_prefix.size()); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 43 | UniquePtr<File> file(OS::OpenFile(filename.c_str(), false)); |
| 44 | if (file.get() == NULL) { |
| 45 | return false; |
| 46 | } |
| 47 | return Open(*file.get(), location.ToString(), requested_base); |
| 48 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 49 | |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 50 | OatFile* OatFile::Open(File& file, |
| 51 | const std::string& location, |
| 52 | byte* requested_base) { |
| 53 | UniquePtr<OatFile> oat_file(new OatFile(location)); |
| 54 | bool success = oat_file->Read(file, requested_base); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 55 | if (!success) { |
| 56 | return NULL; |
| 57 | } |
| 58 | return oat_file.release(); |
| 59 | } |
| 60 | |
| 61 | OatFile::OatFile(const std::string& filename) : location_(filename) {} |
| 62 | |
| 63 | OatFile::~OatFile() { |
| 64 | STLDeleteValues(&oat_dex_files_); |
| 65 | } |
| 66 | |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 67 | bool OatFile::Read(File& file, byte* requested_base) { |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 68 | |
| 69 | OatHeader oat_header; |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 70 | bool success = file.ReadFully(&oat_header, sizeof(oat_header)); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 71 | if (!success || !oat_header.IsValid()) { |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 72 | LOG(WARNING) << "Invalid oat header " << GetLocation(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 73 | return false; |
| 74 | } |
| 75 | |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 76 | int flags = MAP_PRIVATE | ((requested_base != NULL) ? MAP_FIXED : 0); |
| 77 | UniquePtr<MemMap> map(MemMap::MapFileAtAddress(requested_base, |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 78 | file.Length(), |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 79 | PROT_READ, |
| 80 | flags, |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 81 | file.Fd(), |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 82 | 0)); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 83 | if (map.get() == NULL) { |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 84 | LOG(WARNING) << "Failed to map oat file " << GetLocation(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 85 | return false; |
| 86 | } |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 87 | CHECK(requested_base == 0 || requested_base == map->Begin()) |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 88 | << GetLocation() << " " << reinterpret_cast<void*>(map->Begin()); |
| 89 | DCHECK_EQ(0, memcmp(&oat_header, map->Begin(), sizeof(OatHeader))) << GetLocation(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 90 | |
Elliott Hughes | e689d51 | 2012-01-18 23:39:47 -0800 | [diff] [blame] | 91 | off_t code_offset = oat_header.GetExecutableOffset(); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 92 | if (code_offset < file.Length()) { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 93 | byte* code_address = map->Begin() + code_offset; |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 94 | size_t code_length = file.Length() - code_offset; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 95 | if (mprotect(code_address, code_length, PROT_READ | PROT_EXEC) != 0) { |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 96 | PLOG(ERROR) << "Failed to make oat code executable in " << GetLocation(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 97 | return false; |
| 98 | } |
| 99 | } else { |
| 100 | // its possible to have no code if all the methods were abstract, native, etc |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 101 | DCHECK_EQ(code_offset, RoundUp(file.Length(), kPageSize)) << GetLocation(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 104 | const byte* oat = map->Begin(); |
Brian Carlstrom | 6e3b1d9 | 2012-01-11 01:36:32 -0800 | [diff] [blame] | 105 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 106 | oat += sizeof(OatHeader); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 107 | CHECK_LE(oat, map->End()) << GetLocation(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 108 | for (size_t i = 0; i < oat_header.GetDexFileCount(); i++) { |
| 109 | size_t dex_file_location_size = *reinterpret_cast<const uint32_t*>(oat); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 110 | CHECK_GT(dex_file_location_size, 0U) << GetLocation(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 111 | oat += sizeof(dex_file_location_size); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 112 | CHECK_LT(oat, map->End()) << GetLocation(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 113 | |
| 114 | const char* dex_file_location_data = reinterpret_cast<const char*>(oat); |
| 115 | oat += dex_file_location_size; |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 116 | CHECK_LT(oat, map->End()) << GetLocation(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 117 | |
| 118 | std::string dex_file_location(dex_file_location_data, dex_file_location_size); |
| 119 | |
| 120 | uint32_t dex_file_checksum = *reinterpret_cast<const uint32_t*>(oat); |
| 121 | oat += sizeof(dex_file_checksum); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 122 | CHECK_LT(oat, map->End()) << GetLocation(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 123 | |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 124 | uint32_t dex_file_offset = *reinterpret_cast<const uint32_t*>(oat); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 125 | CHECK_GT(dex_file_offset, 0U) << GetLocation(); |
| 126 | CHECK_LT(dex_file_offset, static_cast<uint32_t>(file.Length())) << GetLocation(); |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 127 | oat += sizeof(dex_file_offset); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 128 | CHECK_LT(oat, map->End()) << GetLocation(); |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 129 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 130 | uint8_t* dex_file_pointer = map->Begin() + dex_file_offset; |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 131 | CHECK(DexFile::IsMagicValid(dex_file_pointer)) << GetLocation() << " " << dex_file_pointer; |
| 132 | CHECK(DexFile::IsVersionValid(dex_file_pointer)) << GetLocation() << " " << dex_file_pointer; |
Brian Carlstrom | 6e3b1d9 | 2012-01-11 01:36:32 -0800 | [diff] [blame] | 133 | const DexFile::Header* header = reinterpret_cast<const DexFile::Header*>(dex_file_pointer); |
| 134 | const uint32_t* methods_offsets_pointer = reinterpret_cast<const uint32_t*>(oat); |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 135 | |
Brian Carlstrom | 6e3b1d9 | 2012-01-11 01:36:32 -0800 | [diff] [blame] | 136 | oat += (sizeof(*methods_offsets_pointer) * header->class_defs_size_); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 137 | CHECK_LE(oat, map->End()) << GetLocation(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 138 | |
| 139 | oat_dex_files_[dex_file_location] = new OatDexFile(this, |
| 140 | dex_file_location, |
| 141 | dex_file_checksum, |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 142 | dex_file_pointer, |
Brian Carlstrom | 6e3b1d9 | 2012-01-11 01:36:32 -0800 | [diff] [blame] | 143 | methods_offsets_pointer); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | mem_map_.reset(map.release()); |
| 147 | return true; |
| 148 | } |
| 149 | |
| 150 | const OatHeader& OatFile::GetOatHeader() const { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 151 | return *reinterpret_cast<const OatHeader*>(Begin()); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 154 | const byte* OatFile::Begin() const { |
| 155 | CHECK(mem_map_->Begin() != NULL); |
| 156 | return mem_map_->Begin(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 159 | const byte* OatFile::End() const { |
| 160 | CHECK(mem_map_->End() != NULL); |
| 161 | return mem_map_->End(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Ian Rogers | 7fe2c69 | 2011-12-06 16:35:59 -0800 | [diff] [blame] | 164 | const OatFile::OatDexFile* OatFile::GetOatDexFile(const std::string& dex_file_location, |
| 165 | bool warn_if_not_found) const { |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 166 | Table::const_iterator it = oat_dex_files_.find(dex_file_location); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 167 | if (it == oat_dex_files_.end()) { |
Ian Rogers | 7fe2c69 | 2011-12-06 16:35:59 -0800 | [diff] [blame] | 168 | if (warn_if_not_found) { |
| 169 | LOG(WARNING) << "Failed to find OatDexFile for DexFile " << dex_file_location; |
| 170 | } |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 171 | return NULL; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 172 | } |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 173 | return it->second; |
| 174 | } |
| 175 | |
| 176 | std::vector<const OatFile::OatDexFile*> OatFile::GetOatDexFiles() const { |
| 177 | std::vector<const OatFile::OatDexFile*> result; |
Elliott Hughes | 362f9bc | 2011-10-17 18:56:41 -0700 | [diff] [blame] | 178 | for (Table::const_iterator it = oat_dex_files_.begin(); it != oat_dex_files_.end(); ++it) { |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 179 | result.push_back(it->second); |
| 180 | } |
| 181 | return result; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | OatFile::OatDexFile::OatDexFile(const OatFile* oat_file, |
Elliott Hughes | aa6a588 | 2012-01-13 19:39:16 -0800 | [diff] [blame] | 185 | const std::string& dex_file_location, |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 186 | uint32_t dex_file_location_checksum, |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 187 | byte* dex_file_pointer, |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 188 | const uint32_t* oat_class_offsets_pointer) |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 189 | : oat_file_(oat_file), |
| 190 | dex_file_location_(dex_file_location), |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 191 | dex_file_location_checksum_(dex_file_location_checksum), |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 192 | dex_file_pointer_(dex_file_pointer), |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 193 | oat_class_offsets_pointer_(oat_class_offsets_pointer) {} |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 194 | |
| 195 | OatFile::OatDexFile::~OatDexFile() {} |
| 196 | |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 197 | const DexFile* OatFile::OatDexFile::OpenDexFile() const { |
| 198 | size_t length = reinterpret_cast<const DexFile::Header*>(dex_file_pointer_)->file_size_; |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame^] | 199 | return DexFile::Open(dex_file_pointer_, length, dex_file_location_, dex_file_location_checksum_); |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 200 | } |
| 201 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 202 | const OatFile::OatClass* OatFile::OatDexFile::GetOatClass(uint32_t class_def_index) const { |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 203 | uint32_t oat_class_offset = oat_class_offsets_pointer_[class_def_index]; |
| 204 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 205 | const byte* oat_class_pointer = oat_file_->Begin() + oat_class_offset; |
| 206 | CHECK_LT(oat_class_pointer, oat_file_->End()); |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 207 | Class::Status status = *reinterpret_cast<const Class::Status*>(oat_class_pointer); |
| 208 | |
| 209 | const byte* methods_pointer = oat_class_pointer + sizeof(status); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 210 | CHECK_LT(methods_pointer, oat_file_->End()); |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 211 | |
| 212 | return new OatClass(oat_file_, |
| 213 | status, |
| 214 | reinterpret_cast<const OatMethodOffsets*>(methods_pointer)); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 217 | OatFile::OatClass::OatClass(const OatFile* oat_file, |
| 218 | Class::Status status, |
| 219 | const OatMethodOffsets* methods_pointer) |
| 220 | : oat_file_(oat_file), status_(status), methods_pointer_(methods_pointer) {} |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 221 | |
| 222 | OatFile::OatClass::~OatClass() {} |
| 223 | |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 224 | Class::Status OatFile::OatClass::GetStatus() const { |
| 225 | return status_; |
| 226 | } |
| 227 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 228 | const OatFile::OatMethod OatFile::OatClass::GetOatMethod(uint32_t method_index) const { |
| 229 | const OatMethodOffsets& oat_method_offsets = methods_pointer_[method_index]; |
| 230 | return OatMethod( |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 231 | oat_file_->Begin(), |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 232 | oat_method_offsets.code_offset_, |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 233 | oat_method_offsets.frame_size_in_bytes_, |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 234 | oat_method_offsets.core_spill_mask_, |
| 235 | oat_method_offsets.fp_spill_mask_, |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 236 | oat_method_offsets.mapping_table_offset_, |
| 237 | oat_method_offsets.vmap_table_offset_, |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 238 | oat_method_offsets.gc_map_offset_, |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 239 | oat_method_offsets.invoke_stub_offset_); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 242 | OatFile::OatMethod::OatMethod(const byte* base, |
| 243 | const uint32_t code_offset, |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 244 | const size_t frame_size_in_bytes, |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 245 | const uint32_t core_spill_mask, |
| 246 | const uint32_t fp_spill_mask, |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 247 | const uint32_t mapping_table_offset, |
| 248 | const uint32_t vmap_table_offset, |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 249 | const uint32_t gc_map_offset, |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 250 | const uint32_t invoke_stub_offset) |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 251 | : begin_(base), |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 252 | code_offset_(code_offset), |
Brian Carlstrom | 0dd7dda | 2011-10-25 15:47:53 -0700 | [diff] [blame] | 253 | frame_size_in_bytes_(frame_size_in_bytes), |
Brian Carlstrom | 0dd7dda | 2011-10-25 15:47:53 -0700 | [diff] [blame] | 254 | core_spill_mask_(core_spill_mask), |
| 255 | fp_spill_mask_(fp_spill_mask), |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 256 | mapping_table_offset_(mapping_table_offset), |
| 257 | vmap_table_offset_(vmap_table_offset), |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 258 | gc_map_offset_(gc_map_offset), |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 259 | invoke_stub_offset_(invoke_stub_offset) { |
Brian Carlstrom | 0dd7dda | 2011-10-25 15:47:53 -0700 | [diff] [blame] | 260 | #ifndef NDEBUG |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 261 | if (mapping_table_offset_ != 0) { // implies non-native, non-stub code |
| 262 | if (vmap_table_offset_ == 0) { |
Brian Carlstrom | 0dd7dda | 2011-10-25 15:47:53 -0700 | [diff] [blame] | 263 | DCHECK_EQ(0U, static_cast<uint32_t>(__builtin_popcount(core_spill_mask_) + __builtin_popcount(fp_spill_mask_))); |
| 264 | } else { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 265 | const uint16_t* vmap_table_ = reinterpret_cast<const uint16_t*>(begin_ + vmap_table_offset_); |
Brian Carlstrom | 0dd7dda | 2011-10-25 15:47:53 -0700 | [diff] [blame] | 266 | DCHECK_EQ(vmap_table_[0], static_cast<uint32_t>(__builtin_popcount(core_spill_mask_) + __builtin_popcount(fp_spill_mask_))); |
| 267 | } |
| 268 | } else { |
Elliott Hughes | ba8eee1 | 2012-01-24 20:25:24 -0800 | [diff] [blame] | 269 | DCHECK_EQ(vmap_table_offset_, 0U); |
Brian Carlstrom | 0dd7dda | 2011-10-25 15:47:53 -0700 | [diff] [blame] | 270 | } |
| 271 | #endif |
| 272 | } |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 273 | |
| 274 | OatFile::OatMethod::~OatMethod() {} |
| 275 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 276 | void OatFile::OatMethod::LinkMethodPointers(Method* method) const { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 277 | CHECK(method != NULL); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 278 | method->SetCode(GetCode()); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 279 | method->SetFrameSizeInBytes(frame_size_in_bytes_); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 280 | method->SetCoreSpillMask(core_spill_mask_); |
| 281 | method->SetFpSpillMask(fp_spill_mask_); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 282 | method->SetMappingTable(GetMappingTable()); |
| 283 | method->SetVmapTable(GetVmapTable()); |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 284 | method->SetGcMap(GetGcMap()); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 285 | method->SetInvokeStub(GetInvokeStub()); |
| 286 | } |
| 287 | |
| 288 | void OatFile::OatMethod::LinkMethodOffsets(Method* method) const { |
| 289 | CHECK(method != NULL); |
| 290 | method->SetOatCodeOffset(GetCodeOffset()); |
| 291 | method->SetFrameSizeInBytes(GetFrameSizeInBytes()); |
| 292 | method->SetCoreSpillMask(GetCoreSpillMask()); |
| 293 | method->SetFpSpillMask(GetFpSpillMask()); |
| 294 | method->SetOatMappingTableOffset(GetMappingTableOffset()); |
| 295 | method->SetOatVmapTableOffset(GetVmapTableOffset()); |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 296 | method->SetOatGcMapOffset(GetGcMapOffset()); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 297 | method->SetOatInvokeStubOffset(GetInvokeStubOffset()); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | } // namespace art |