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 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 19 | #include <dlfcn.h> |
| 20 | |
Elliott Hughes | 1aa246d | 2012-12-13 09:29:36 -0800 | [diff] [blame] | 21 | #include "base/stl_util.h" |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 22 | #include "base/unix_file/fd_file.h" |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 23 | #include "elf_file.h" |
| 24 | #include "oat.h" |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 25 | #include "mirror/art_method.h" |
| 26 | #include "mirror/art_method-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 27 | #include "mirror/class.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 28 | #include "mirror/object-inl.h" |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 29 | #include "os.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 30 | #include "utils.h" |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 31 | #include "vmap_table.h" |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 32 | |
| 33 | namespace art { |
| 34 | |
Brian Carlstrom | 30e2ea4 | 2013-06-19 23:25:37 -0700 | [diff] [blame] | 35 | std::string OatFile::DexFilenameToOdexFilename(const std::string& location) { |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 36 | CHECK_GE(location.size(), 4U) << location; // must be at least .123 |
| 37 | size_t dot_index = location.size() - 3 - 1; // 3=dex or zip or apk |
| 38 | CHECK_EQ('.', location[dot_index]) << location; |
Brian Carlstrom | 30e2ea4 | 2013-06-19 23:25:37 -0700 | [diff] [blame] | 39 | std::string odex_location(location); |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 40 | odex_location.resize(dot_index + 1); |
| 41 | CHECK_EQ('.', odex_location[odex_location.size()-1]) << location << " " << odex_location; |
Brian Carlstrom | 30e2ea4 | 2013-06-19 23:25:37 -0700 | [diff] [blame] | 42 | odex_location += "odex"; |
| 43 | return odex_location; |
Brian Carlstrom | b7bbba4 | 2011-10-13 14:58:47 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 46 | void OatFile::CheckLocation(const std::string& location) { |
Brian Carlstrom | 7a967b3 | 2012-03-28 15:23:10 -0700 | [diff] [blame] | 47 | CHECK(!location.empty()); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 48 | } |
| 49 | |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 50 | OatFile* OatFile::OpenMemory(std::vector<uint8_t>& oat_contents, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 51 | const std::string& location, |
| 52 | std::string* error_msg) { |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 53 | CHECK(!oat_contents.empty()) << location; |
| 54 | CheckLocation(location); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 55 | UniquePtr<OatFile> oat_file(new OatFile(location)); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 56 | oat_file->begin_ = &oat_contents[0]; |
| 57 | oat_file->end_ = &oat_contents[oat_contents.size()]; |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 58 | return oat_file->Setup(error_msg) ? oat_file.release() : nullptr; |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | OatFile* OatFile::Open(const std::string& filename, |
| 62 | const std::string& location, |
Brian Carlstrom | f1d3455 | 2013-07-12 20:22:23 -0700 | [diff] [blame] | 63 | byte* requested_base, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 64 | bool executable, |
| 65 | std::string* error_msg) { |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 66 | CHECK(!filename.empty()) << location; |
Brian Carlstrom | 30e2ea4 | 2013-06-19 23:25:37 -0700 | [diff] [blame] | 67 | CheckLocation(filename); |
Brian Carlstrom | eeb9888 | 2013-10-03 15:53:49 -0700 | [diff] [blame] | 68 | #ifdef ART_USE_PORTABLE_COMPILER |
| 69 | // If we are using PORTABLE, use dlopen to deal with relocations. |
| 70 | // |
| 71 | // We use our own ELF loader for Quick to deal with legacy apps that |
| 72 | // open a generated dex file by name, remove the file, then open |
| 73 | // another generated dex file with the same name. http://b/10614658 |
Brian Carlstrom | f1d3455 | 2013-07-12 20:22:23 -0700 | [diff] [blame] | 74 | if (executable) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 75 | return OpenDlopen(filename, location, requested_base, error_msg); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 76 | } |
Brian Carlstrom | eeb9888 | 2013-10-03 15:53:49 -0700 | [diff] [blame] | 77 | #endif |
Brian Carlstrom | f1d3455 | 2013-07-12 20:22:23 -0700 | [diff] [blame] | 78 | // If we aren't trying to execute, we just use our own ElfFile loader for a couple reasons: |
| 79 | // |
| 80 | // On target, dlopen may fail when compiling due to selinux restrictions on installd. |
| 81 | // |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 82 | // On host, dlopen is expected to fail when cross compiling, so fall back to OpenElfFile. |
| 83 | // This won't work for portable runtime execution because it doesn't process relocations. |
Brian Carlstrom | 7571e8b | 2013-08-12 17:04:14 -0700 | [diff] [blame] | 84 | UniquePtr<File> file(OS::OpenFileForReading(filename.c_str())); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 85 | if (file.get() == NULL) { |
| 86 | return NULL; |
| 87 | } |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 88 | return OpenElfFile(file.get(), location, requested_base, false, executable, error_msg); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 89 | } |
| 90 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 91 | OatFile* OatFile::OpenWritable(File* file, const std::string& location, std::string* error_msg) { |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 92 | CheckLocation(location); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 93 | return OpenElfFile(file, location, NULL, true, false, error_msg); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | OatFile* OatFile::OpenDlopen(const std::string& elf_filename, |
| 97 | const std::string& location, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 98 | byte* requested_base, |
| 99 | std::string* error_msg) { |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 100 | UniquePtr<OatFile> oat_file(new OatFile(location)); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 101 | bool success = oat_file->Dlopen(elf_filename, requested_base, error_msg); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 102 | if (!success) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 103 | return nullptr; |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 104 | } |
| 105 | return oat_file.release(); |
| 106 | } |
| 107 | |
| 108 | OatFile* OatFile::OpenElfFile(File* file, |
| 109 | const std::string& location, |
| 110 | byte* requested_base, |
Brian Carlstrom | f1d3455 | 2013-07-12 20:22:23 -0700 | [diff] [blame] | 111 | bool writable, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 112 | bool executable, |
| 113 | std::string* error_msg) { |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 114 | UniquePtr<OatFile> oat_file(new OatFile(location)); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 115 | bool success = oat_file->ElfFileOpen(file, requested_base, writable, executable, error_msg); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 116 | if (!success) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 117 | CHECK(!error_msg->empty()); |
| 118 | return nullptr; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 119 | } |
| 120 | return oat_file.release(); |
| 121 | } |
| 122 | |
Logan Chien | 0c717dd | 2012-03-28 18:31:07 +0800 | [diff] [blame] | 123 | OatFile::OatFile(const std::string& location) |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 124 | : location_(location), begin_(NULL), end_(NULL), dlopen_handle_(NULL) { |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 125 | CHECK(!location_.empty()); |
| 126 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 127 | |
| 128 | OatFile::~OatFile() { |
| 129 | STLDeleteValues(&oat_dex_files_); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 130 | if (dlopen_handle_ != NULL) { |
| 131 | dlclose(dlopen_handle_); |
| 132 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 135 | bool OatFile::Dlopen(const std::string& elf_filename, byte* requested_base, |
| 136 | std::string* error_msg) { |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 137 | char* absolute_path = realpath(elf_filename.c_str(), NULL); |
| 138 | if (absolute_path == NULL) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 139 | *error_msg = StringPrintf("Failed to find absolute path for '%s'", elf_filename.c_str()); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 140 | return false; |
| 141 | } |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 142 | dlopen_handle_ = dlopen(absolute_path, RTLD_NOW); |
| 143 | free(absolute_path); |
| 144 | if (dlopen_handle_ == NULL) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 145 | *error_msg = StringPrintf("Failed to dlopen '%s': %s", elf_filename.c_str(), dlerror()); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 146 | return false; |
| 147 | } |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 148 | begin_ = reinterpret_cast<byte*>(dlsym(dlopen_handle_, "oatdata")); |
| 149 | if (begin_ == NULL) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 150 | *error_msg = StringPrintf("Failed to find oatdata symbol in '%s': %s", elf_filename.c_str(), |
| 151 | dlerror()); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 152 | return false; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 153 | } |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 154 | if (requested_base != NULL && begin_ != requested_base) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 155 | *error_msg = StringPrintf("Failed to find oatdata symbol at expected address: " |
| 156 | "oatdata=%p != expected=%p /proc/self/maps:\n", |
| 157 | begin_, requested_base); |
| 158 | ReadFileToString("/proc/self/maps", error_msg); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 159 | return false; |
| 160 | } |
| 161 | end_ = reinterpret_cast<byte*>(dlsym(dlopen_handle_, "oatlastword")); |
| 162 | if (end_ == NULL) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 163 | *error_msg = StringPrintf("Failed to find oatlastword symbol in '%s': %s", elf_filename.c_str(), |
| 164 | dlerror()); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 165 | return false; |
| 166 | } |
| 167 | // Readjust to be non-inclusive upper bound. |
| 168 | end_ += sizeof(uint32_t); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 169 | return Setup(error_msg); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 170 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 171 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 172 | bool OatFile::ElfFileOpen(File* file, byte* requested_base, bool writable, bool executable, |
| 173 | std::string* error_msg) { |
| 174 | elf_file_.reset(ElfFile::Open(file, writable, true, error_msg)); |
| 175 | if (elf_file_.get() == nullptr) { |
| 176 | DCHECK(!error_msg->empty()); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 177 | return false; |
| 178 | } |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 179 | bool loaded = elf_file_->Load(executable, error_msg); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 180 | if (!loaded) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 181 | DCHECK(!error_msg->empty()); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 182 | return false; |
| 183 | } |
| 184 | begin_ = elf_file_->FindDynamicSymbolAddress("oatdata"); |
| 185 | if (begin_ == NULL) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 186 | *error_msg = StringPrintf("Failed to find oatdata symbol in '%s'", file->GetPath().c_str()); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 187 | return false; |
| 188 | } |
| 189 | if (requested_base != NULL && begin_ != requested_base) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 190 | *error_msg = StringPrintf("Failed to find oatdata symbol at expected address: " |
| 191 | "oatdata=%p != expected=%p /proc/self/maps:\n", |
| 192 | begin_, requested_base); |
| 193 | ReadFileToString("/proc/self/maps", error_msg); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 194 | return false; |
| 195 | } |
| 196 | end_ = elf_file_->FindDynamicSymbolAddress("oatlastword"); |
| 197 | if (end_ == NULL) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 198 | *error_msg = StringPrintf("Failed to find oatlastword symbol in '%s'", file->GetPath().c_str()); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 199 | return false; |
| 200 | } |
| 201 | // Readjust to be non-inclusive upper bound. |
| 202 | end_ += sizeof(uint32_t); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 203 | return Setup(error_msg); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 204 | } |
Brian Carlstrom | 6e3b1d9 | 2012-01-11 01:36:32 -0800 | [diff] [blame] | 205 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 206 | bool OatFile::Setup(std::string* error_msg) { |
Brian Carlstrom | f1b3030 | 2013-03-28 10:35:32 -0700 | [diff] [blame] | 207 | if (!GetOatHeader().IsValid()) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 208 | *error_msg = StringPrintf("Invalid oat magic for '%s'", GetLocation().c_str()); |
Brian Carlstrom | f1b3030 | 2013-03-28 10:35:32 -0700 | [diff] [blame] | 209 | return false; |
| 210 | } |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 211 | const byte* oat = Begin(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 212 | oat += sizeof(OatHeader); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 213 | if (oat > End()) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 214 | *error_msg = StringPrintf("In oat file '%s' found truncated OatHeader", GetLocation().c_str()); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 215 | return false; |
| 216 | } |
Brian Carlstrom | 81f3ca1 | 2012-03-17 00:27:35 -0700 | [diff] [blame] | 217 | |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 218 | oat += GetOatHeader().GetImageFileLocationSize(); |
| 219 | if (oat > End()) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 220 | *error_msg = StringPrintf("In oat file '%s' found truncated image file location: " |
| 221 | "%p + %zd + %ud <= %p", GetLocation().c_str(), |
| 222 | Begin(), sizeof(OatHeader), GetOatHeader().GetImageFileLocationSize(), |
| 223 | End()); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 224 | return false; |
| 225 | } |
| 226 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 227 | for (size_t i = 0; i < GetOatHeader().GetDexFileCount(); i++) { |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 228 | size_t dex_file_location_size = *reinterpret_cast<const uint32_t*>(oat); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 229 | if (UNLIKELY(dex_file_location_size == 0U)) { |
| 230 | *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zd with empty location name", |
| 231 | GetLocation().c_str(), i); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 232 | return false; |
| 233 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 234 | oat += sizeof(dex_file_location_size); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 235 | if (UNLIKELY(oat > End())) { |
| 236 | *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zd truncated after dex file " |
| 237 | "location size", GetLocation().c_str(), i); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 238 | return false; |
| 239 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 240 | |
| 241 | const char* dex_file_location_data = reinterpret_cast<const char*>(oat); |
| 242 | oat += dex_file_location_size; |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 243 | if (UNLIKELY(oat > End())) { |
| 244 | *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zd with truncated dex file " |
| 245 | "location", GetLocation().c_str(), i); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 246 | return false; |
| 247 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 248 | |
| 249 | std::string dex_file_location(dex_file_location_data, dex_file_location_size); |
| 250 | |
| 251 | uint32_t dex_file_checksum = *reinterpret_cast<const uint32_t*>(oat); |
| 252 | oat += sizeof(dex_file_checksum); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 253 | if (UNLIKELY(oat > End())) { |
| 254 | *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zd for '%s' truncated after " |
| 255 | "dex file checksum", GetLocation().c_str(), i, |
| 256 | dex_file_location.c_str()); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 257 | return false; |
| 258 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 259 | |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 260 | uint32_t dex_file_offset = *reinterpret_cast<const uint32_t*>(oat); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 261 | if (UNLIKELY(dex_file_offset == 0U)) { |
| 262 | *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zd for '%s' with zero dex " |
| 263 | "file offset", GetLocation().c_str(), i, dex_file_location.c_str()); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 264 | return false; |
| 265 | } |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 266 | if (UNLIKELY(dex_file_offset > Size())) { |
| 267 | *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zd for '%s' with dex file " |
| 268 | "offset %ud > %zd", GetLocation().c_str(), i, |
| 269 | dex_file_location.c_str(), dex_file_offset, Size()); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 270 | return false; |
| 271 | } |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 272 | oat += sizeof(dex_file_offset); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 273 | if (UNLIKELY(oat > End())) { |
| 274 | *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zd for '%s' truncated " |
| 275 | " after dex file offsets", GetLocation().c_str(), i, |
| 276 | dex_file_location.c_str()); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 277 | return false; |
| 278 | } |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 279 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 280 | const uint8_t* dex_file_pointer = Begin() + dex_file_offset; |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 281 | if (UNLIKELY(!DexFile::IsMagicValid(dex_file_pointer))) { |
| 282 | *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zd for '%s' with invalid " |
| 283 | " dex file magic '%s'", GetLocation().c_str(), i, |
| 284 | dex_file_location.c_str(), dex_file_pointer); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 285 | return false; |
| 286 | } |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 287 | if (UNLIKELY(!DexFile::IsVersionValid(dex_file_pointer))) { |
| 288 | *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zd for '%s' with invalid " |
| 289 | " dex file version '%s'", GetLocation().c_str(), i, |
| 290 | dex_file_location.c_str(), dex_file_pointer); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 291 | return false; |
| 292 | } |
Brian Carlstrom | 6e3b1d9 | 2012-01-11 01:36:32 -0800 | [diff] [blame] | 293 | const DexFile::Header* header = reinterpret_cast<const DexFile::Header*>(dex_file_pointer); |
| 294 | const uint32_t* methods_offsets_pointer = reinterpret_cast<const uint32_t*>(oat); |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 295 | |
Brian Carlstrom | 6e3b1d9 | 2012-01-11 01:36:32 -0800 | [diff] [blame] | 296 | oat += (sizeof(*methods_offsets_pointer) * header->class_defs_size_); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 297 | if (UNLIKELY(oat > End())) { |
| 298 | *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zd for '%s' with truncated " |
| 299 | " method offsets", GetLocation().c_str(), i, |
| 300 | dex_file_location.c_str()); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 301 | return false; |
| 302 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 303 | |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 304 | oat_dex_files_.Put(dex_file_location, new OatDexFile(this, |
| 305 | dex_file_location, |
| 306 | dex_file_checksum, |
| 307 | dex_file_pointer, |
| 308 | methods_offsets_pointer)); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 309 | } |
Brian Carlstrom | f1b3030 | 2013-03-28 10:35:32 -0700 | [diff] [blame] | 310 | return true; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | const OatHeader& OatFile::GetOatHeader() const { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 314 | return *reinterpret_cast<const OatHeader*>(Begin()); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 317 | const byte* OatFile::Begin() const { |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 318 | CHECK(begin_ != NULL); |
| 319 | return begin_; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 322 | const byte* OatFile::End() const { |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 323 | CHECK(end_ != NULL); |
| 324 | return end_; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 327 | const OatFile::OatDexFile* OatFile::GetOatDexFile(const char* dex_location, |
| 328 | const uint32_t* dex_location_checksum, |
Ian Rogers | 7fe2c69 | 2011-12-06 16:35:59 -0800 | [diff] [blame] | 329 | bool warn_if_not_found) const { |
Brian Carlstrom | 756ee4e | 2013-10-03 15:46:12 -0700 | [diff] [blame] | 330 | Table::const_iterator it = oat_dex_files_.find(dex_location); |
| 331 | if (it != oat_dex_files_.end()) { |
| 332 | const OatFile::OatDexFile* oat_dex_file = it->second; |
| 333 | if (dex_location_checksum == NULL || |
| 334 | oat_dex_file->GetDexFileLocationChecksum() == *dex_location_checksum) { |
| 335 | return oat_dex_file; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | if (warn_if_not_found) { |
| 340 | LOG(WARNING) << "Failed to find OatDexFile for DexFile " << dex_location |
| 341 | << " in OatFile " << GetLocation(); |
| 342 | if (kIsDebugBuild) { |
| 343 | for (Table::const_iterator it = oat_dex_files_.begin(); it != oat_dex_files_.end(); ++it) { |
| 344 | LOG(WARNING) << "OatFile " << GetLocation() |
| 345 | << " contains OatDexFile " << it->second->GetDexFileLocation(); |
Brian Carlstrom | 7571e8b | 2013-08-12 17:04:14 -0700 | [diff] [blame] | 346 | } |
Ian Rogers | 7fe2c69 | 2011-12-06 16:35:59 -0800 | [diff] [blame] | 347 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 348 | } |
Brian Carlstrom | 756ee4e | 2013-10-03 15:46:12 -0700 | [diff] [blame] | 349 | return NULL; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | std::vector<const OatFile::OatDexFile*> OatFile::GetOatDexFiles() const { |
| 353 | std::vector<const OatFile::OatDexFile*> result; |
Elliott Hughes | 362f9bc | 2011-10-17 18:56:41 -0700 | [diff] [blame] | 354 | 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] | 355 | result.push_back(it->second); |
| 356 | } |
| 357 | return result; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | OatFile::OatDexFile::OatDexFile(const OatFile* oat_file, |
Elliott Hughes | aa6a588 | 2012-01-13 19:39:16 -0800 | [diff] [blame] | 361 | const std::string& dex_file_location, |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 362 | uint32_t dex_file_location_checksum, |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 363 | const byte* dex_file_pointer, |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 364 | const uint32_t* oat_class_offsets_pointer) |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 365 | : oat_file_(oat_file), |
| 366 | dex_file_location_(dex_file_location), |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 367 | dex_file_location_checksum_(dex_file_location_checksum), |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 368 | dex_file_pointer_(dex_file_pointer), |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 369 | oat_class_offsets_pointer_(oat_class_offsets_pointer) {} |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 370 | |
| 371 | OatFile::OatDexFile::~OatDexFile() {} |
| 372 | |
Ian Rogers | 05f28c6 | 2012-10-23 18:12:13 -0700 | [diff] [blame] | 373 | size_t OatFile::OatDexFile::FileSize() const { |
| 374 | return reinterpret_cast<const DexFile::Header*>(dex_file_pointer_)->file_size_; |
| 375 | } |
| 376 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 377 | const DexFile* OatFile::OatDexFile::OpenDexFile(std::string* error_msg) const { |
Ian Rogers | 05f28c6 | 2012-10-23 18:12:13 -0700 | [diff] [blame] | 378 | return DexFile::Open(dex_file_pointer_, FileSize(), dex_file_location_, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 379 | dex_file_location_checksum_, error_msg); |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 380 | } |
| 381 | |
Ian Rogers | ee39a10 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 382 | const OatFile::OatClass* OatFile::OatDexFile::GetOatClass(uint16_t class_def_index) const { |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 383 | uint32_t oat_class_offset = oat_class_offsets_pointer_[class_def_index]; |
| 384 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 385 | const byte* oat_class_pointer = oat_file_->Begin() + oat_class_offset; |
Brian Carlstrom | 7571e8b | 2013-08-12 17:04:14 -0700 | [diff] [blame] | 386 | CHECK_LT(oat_class_pointer, oat_file_->End()) << oat_file_->GetLocation(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 387 | mirror::Class::Status status = *reinterpret_cast<const mirror::Class::Status*>(oat_class_pointer); |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 388 | |
| 389 | const byte* methods_pointer = oat_class_pointer + sizeof(status); |
Brian Carlstrom | 7571e8b | 2013-08-12 17:04:14 -0700 | [diff] [blame] | 390 | CHECK_LT(methods_pointer, oat_file_->End()) << oat_file_->GetLocation(); |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 391 | |
| 392 | return new OatClass(oat_file_, |
| 393 | status, |
| 394 | reinterpret_cast<const OatMethodOffsets*>(methods_pointer)); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 397 | OatFile::OatClass::OatClass(const OatFile* oat_file, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 398 | mirror::Class::Status status, |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 399 | const OatMethodOffsets* methods_pointer) |
| 400 | : oat_file_(oat_file), status_(status), methods_pointer_(methods_pointer) {} |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 401 | |
| 402 | OatFile::OatClass::~OatClass() {} |
| 403 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 404 | mirror::Class::Status OatFile::OatClass::GetStatus() const { |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 405 | return status_; |
| 406 | } |
| 407 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 408 | const OatFile::OatMethod OatFile::OatClass::GetOatMethod(uint32_t method_index) const { |
| 409 | const OatMethodOffsets& oat_method_offsets = methods_pointer_[method_index]; |
| 410 | return OatMethod( |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 411 | oat_file_->Begin(), |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 412 | oat_method_offsets.code_offset_, |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 413 | oat_method_offsets.frame_size_in_bytes_, |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 414 | oat_method_offsets.core_spill_mask_, |
| 415 | oat_method_offsets.fp_spill_mask_, |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 416 | oat_method_offsets.mapping_table_offset_, |
| 417 | oat_method_offsets.vmap_table_offset_, |
Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 418 | oat_method_offsets.gc_map_offset_); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 419 | } |
| 420 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 421 | OatFile::OatMethod::OatMethod(const byte* base, |
| 422 | const uint32_t code_offset, |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 423 | const size_t frame_size_in_bytes, |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 424 | const uint32_t core_spill_mask, |
| 425 | const uint32_t fp_spill_mask, |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 426 | const uint32_t mapping_table_offset, |
| 427 | const uint32_t vmap_table_offset, |
Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 428 | const uint32_t gc_map_offset) |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 429 | : begin_(base), |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 430 | code_offset_(code_offset), |
Brian Carlstrom | 0dd7dda | 2011-10-25 15:47:53 -0700 | [diff] [blame] | 431 | frame_size_in_bytes_(frame_size_in_bytes), |
Brian Carlstrom | 0dd7dda | 2011-10-25 15:47:53 -0700 | [diff] [blame] | 432 | core_spill_mask_(core_spill_mask), |
| 433 | fp_spill_mask_(fp_spill_mask), |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 434 | mapping_table_offset_(mapping_table_offset), |
| 435 | vmap_table_offset_(vmap_table_offset), |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 436 | native_gc_map_offset_(gc_map_offset) { |
Brian Carlstrom | 0dd7dda | 2011-10-25 15:47:53 -0700 | [diff] [blame] | 437 | #ifndef NDEBUG |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 438 | if (mapping_table_offset_ != 0) { // implies non-native, non-stub code |
| 439 | if (vmap_table_offset_ == 0) { |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 440 | DCHECK_EQ(0U, static_cast<uint32_t>(__builtin_popcount(core_spill_mask_) + |
| 441 | __builtin_popcount(fp_spill_mask_))); |
Brian Carlstrom | 0dd7dda | 2011-10-25 15:47:53 -0700 | [diff] [blame] | 442 | } else { |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 443 | VmapTable vmap_table(reinterpret_cast<const uint8_t*>(begin_ + vmap_table_offset_)); |
| 444 | |
| 445 | DCHECK_EQ(vmap_table.Size(), static_cast<uint32_t>(__builtin_popcount(core_spill_mask_) + |
| 446 | __builtin_popcount(fp_spill_mask_))); |
Brian Carlstrom | 0dd7dda | 2011-10-25 15:47:53 -0700 | [diff] [blame] | 447 | } |
| 448 | } else { |
Elliott Hughes | ba8eee1 | 2012-01-24 20:25:24 -0800 | [diff] [blame] | 449 | DCHECK_EQ(vmap_table_offset_, 0U); |
Brian Carlstrom | 0dd7dda | 2011-10-25 15:47:53 -0700 | [diff] [blame] | 450 | } |
| 451 | #endif |
| 452 | } |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 453 | |
| 454 | OatFile::OatMethod::~OatMethod() {} |
| 455 | |
Logan Chien | 0c717dd | 2012-03-28 18:31:07 +0800 | [diff] [blame] | 456 | const void* OatFile::OatMethod::GetCode() const { |
Logan Chien | 971bf3f | 2012-05-01 15:47:55 +0800 | [diff] [blame] | 457 | return GetOatPointer<const void*>(code_offset_); |
Logan Chien | 0c717dd | 2012-03-28 18:31:07 +0800 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | uint32_t OatFile::OatMethod::GetCodeSize() const { |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 461 | #if defined(ART_USE_PORTABLE_COMPILER) |
| 462 | // TODO: With Quick, we store the size before the code. With |
| 463 | // Portable, the code is in a .o file we don't manage ourselves. ELF |
| 464 | // symbols do have a concept of size, so we could capture that and |
| 465 | // store it somewhere, such as the OatMethod. |
| 466 | return 0; |
| 467 | #else |
Logan Chien | 971bf3f | 2012-05-01 15:47:55 +0800 | [diff] [blame] | 468 | uintptr_t code = reinterpret_cast<uint32_t>(GetCode()); |
Logan Chien | 0c717dd | 2012-03-28 18:31:07 +0800 | [diff] [blame] | 469 | |
Logan Chien | 971bf3f | 2012-05-01 15:47:55 +0800 | [diff] [blame] | 470 | if (code == 0) { |
Logan Chien | 0c717dd | 2012-03-28 18:31:07 +0800 | [diff] [blame] | 471 | return 0; |
| 472 | } |
Logan Chien | 971bf3f | 2012-05-01 15:47:55 +0800 | [diff] [blame] | 473 | // TODO: make this Thumb2 specific |
| 474 | code &= ~0x1; |
| 475 | return reinterpret_cast<uint32_t*>(code)[-1]; |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 476 | #endif |
Logan Chien | 0c717dd | 2012-03-28 18:31:07 +0800 | [diff] [blame] | 477 | } |
| 478 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 479 | void OatFile::OatMethod::LinkMethod(mirror::ArtMethod* method) const { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 480 | CHECK(method != NULL); |
Jeff Hao | aa4a793 | 2013-05-13 11:28:27 -0700 | [diff] [blame] | 481 | method->SetEntryPointFromCompiledCode(GetCode()); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 482 | method->SetFrameSizeInBytes(frame_size_in_bytes_); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 483 | method->SetCoreSpillMask(core_spill_mask_); |
| 484 | method->SetFpSpillMask(fp_spill_mask_); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 485 | method->SetMappingTable(GetMappingTable()); |
| 486 | method->SetVmapTable(GetVmapTable()); |
Brian Carlstrom | fb331d7 | 2013-07-25 22:00:16 -0700 | [diff] [blame] | 487 | method->SetNativeGcMap(GetNativeGcMap()); // Used by native methods in work around JNI mode. |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 488 | } |
| 489 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 490 | } // namespace art |