Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -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 | */ |
| 16 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 17 | #include "art_method.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 18 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 19 | #include "arch/context.h" |
Ian Rogers | 62f0512 | 2014-03-21 11:21:29 -0700 | [diff] [blame] | 20 | #include "art_field-inl.h" |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 21 | #include "art_method-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 22 | #include "base/stringpiece.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 23 | #include "class-inl.h" |
| 24 | #include "dex_file-inl.h" |
Ian Rogers | c449aa8 | 2013-07-29 14:35:46 -0700 | [diff] [blame] | 25 | #include "dex_instruction.h" |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 26 | #include "entrypoints/entrypoint_utils.h" |
| 27 | #include "entrypoints/runtime_asm_entrypoints.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 28 | #include "gc/accounting/card_table-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 29 | #include "interpreter/interpreter.h" |
| 30 | #include "jni_internal.h" |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 31 | #include "mapping_table.h" |
Ian Rogers | f224751 | 2014-12-02 16:17:08 -0800 | [diff] [blame^] | 32 | #include "method_helper.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 33 | #include "object_array-inl.h" |
Ian Rogers | 22d5e73 | 2014-07-15 22:23:51 -0700 | [diff] [blame] | 34 | #include "object_array.h" |
| 35 | #include "object-inl.h" |
Ian Rogers | 62f0512 | 2014-03-21 11:21:29 -0700 | [diff] [blame] | 36 | #include "scoped_thread_state_change.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 37 | #include "string.h" |
Ian Rogers | 62f0512 | 2014-03-21 11:21:29 -0700 | [diff] [blame] | 38 | #include "well_known_classes.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 39 | |
| 40 | namespace art { |
| 41 | namespace mirror { |
| 42 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 43 | extern "C" void art_portable_invoke_stub(ArtMethod*, uint32_t*, uint32_t, Thread*, JValue*, char); |
Ian Rogers | 0177e53 | 2014-02-11 16:30:46 -0800 | [diff] [blame] | 44 | extern "C" void art_quick_invoke_stub(ArtMethod*, uint32_t*, uint32_t, Thread*, JValue*, |
| 45 | const char*); |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 46 | #if defined(__LP64__) || defined(__arm__) |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 47 | extern "C" void art_quick_invoke_static_stub(ArtMethod*, uint32_t*, uint32_t, Thread*, JValue*, |
| 48 | const char*); |
| 49 | #endif |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 50 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 51 | // TODO: get global references for these |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 52 | GcRoot<Class> ArtMethod::java_lang_reflect_ArtMethod_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 53 | |
Mathieu Chartier | 2b7c4d1 | 2014-05-19 10:52:16 -0700 | [diff] [blame] | 54 | ArtMethod* ArtMethod::FromReflectedMethod(const ScopedObjectAccessAlreadyRunnable& soa, |
| 55 | jobject jlr_method) { |
Ian Rogers | 62f0512 | 2014-03-21 11:21:29 -0700 | [diff] [blame] | 56 | mirror::ArtField* f = |
| 57 | soa.DecodeField(WellKnownClasses::java_lang_reflect_AbstractMethod_artMethod); |
| 58 | mirror::ArtMethod* method = f->GetObject(soa.Decode<mirror::Object*>(jlr_method))->AsArtMethod(); |
| 59 | DCHECK(method != nullptr); |
| 60 | return method; |
| 61 | } |
| 62 | |
| 63 | |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 64 | void ArtMethod::VisitRoots(RootCallback* callback, void* arg) { |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 65 | if (!java_lang_reflect_ArtMethod_.IsNull()) { |
| 66 | java_lang_reflect_ArtMethod_.VisitRoot(callback, arg, 0, kRootStickyClass); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
Ian Rogers | 6b14d55 | 2014-10-28 21:50:58 -0700 | [diff] [blame] | 70 | mirror::String* ArtMethod::GetNameAsString(Thread* self) { |
| 71 | mirror::ArtMethod* method = GetInterfaceMethodIfProxy(); |
| 72 | const DexFile* dex_file = method->GetDexFile(); |
| 73 | uint32_t dex_method_idx = method->GetDexMethodIndex(); |
| 74 | const DexFile::MethodId& method_id = dex_file->GetMethodId(dex_method_idx); |
| 75 | StackHandleScope<1> hs(self); |
| 76 | Handle<mirror::DexCache> dex_cache(hs.NewHandle(method->GetDexCache())); |
| 77 | return Runtime::Current()->GetClassLinker()->ResolveString(*dex_file, method_id.name_idx_, |
| 78 | dex_cache); |
| 79 | } |
| 80 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 81 | InvokeType ArtMethod::GetInvokeType() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 82 | // TODO: kSuper? |
| 83 | if (GetDeclaringClass()->IsInterface()) { |
| 84 | return kInterface; |
| 85 | } else if (IsStatic()) { |
| 86 | return kStatic; |
| 87 | } else if (IsDirect()) { |
| 88 | return kDirect; |
| 89 | } else { |
| 90 | return kVirtual; |
| 91 | } |
| 92 | } |
| 93 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 94 | void ArtMethod::SetClass(Class* java_lang_reflect_ArtMethod) { |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 95 | CHECK(java_lang_reflect_ArtMethod_.IsNull()); |
Ian Rogers | f224751 | 2014-12-02 16:17:08 -0800 | [diff] [blame^] | 96 | CHECK(java_lang_reflect_ArtMethod != nullptr); |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 97 | java_lang_reflect_ArtMethod_ = GcRoot<Class>(java_lang_reflect_ArtMethod); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 100 | void ArtMethod::ResetClass() { |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 101 | CHECK(!java_lang_reflect_ArtMethod_.IsNull()); |
| 102 | java_lang_reflect_ArtMethod_ = GcRoot<Class>(nullptr); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 103 | } |
| 104 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 105 | size_t ArtMethod::NumArgRegisters(const StringPiece& shorty) { |
Ian Rogers | 6b604a1 | 2014-09-25 15:35:37 -0700 | [diff] [blame] | 106 | CHECK_LE(1U, shorty.length()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 107 | uint32_t num_registers = 0; |
Ian Rogers | 6b604a1 | 2014-09-25 15:35:37 -0700 | [diff] [blame] | 108 | for (size_t i = 1; i < shorty.length(); ++i) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 109 | char ch = shorty[i]; |
| 110 | if (ch == 'D' || ch == 'J') { |
| 111 | num_registers += 2; |
| 112 | } else { |
| 113 | num_registers += 1; |
| 114 | } |
| 115 | } |
| 116 | return num_registers; |
| 117 | } |
| 118 | |
Ian Rogers | f224751 | 2014-12-02 16:17:08 -0800 | [diff] [blame^] | 119 | static bool HasSameNameAndSignature(ArtMethod* method1, ArtMethod* method2) |
| 120 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 121 | ScopedAssertNoThreadSuspension ants(Thread::Current(), "HasSameNameAndSignature"); |
| 122 | const DexFile* dex_file = method1->GetDexFile(); |
| 123 | const DexFile::MethodId& mid = dex_file->GetMethodId(method1->GetDexMethodIndex()); |
| 124 | if (method1->GetDexCache() == method2->GetDexCache()) { |
| 125 | const DexFile::MethodId& mid2 = dex_file->GetMethodId(method2->GetDexMethodIndex()); |
| 126 | return mid.name_idx_ == mid2.name_idx_ && mid.proto_idx_ == mid2.proto_idx_; |
| 127 | } |
| 128 | const DexFile* dex_file2 = method2->GetDexFile(); |
| 129 | const DexFile::MethodId& mid2 = dex_file2->GetMethodId(method2->GetDexMethodIndex()); |
| 130 | if (!DexFileStringEquals(dex_file, mid.name_idx_, dex_file2, mid2.name_idx_)) { |
| 131 | return false; // Name mismatch. |
| 132 | } |
| 133 | return dex_file->GetMethodSignature(mid) == dex_file2->GetMethodSignature(mid2); |
| 134 | } |
| 135 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 136 | ArtMethod* ArtMethod::FindOverriddenMethod() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 137 | if (IsStatic()) { |
Ian Rogers | f224751 | 2014-12-02 16:17:08 -0800 | [diff] [blame^] | 138 | return nullptr; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 139 | } |
| 140 | Class* declaring_class = GetDeclaringClass(); |
| 141 | Class* super_class = declaring_class->GetSuperClass(); |
| 142 | uint16_t method_index = GetMethodIndex(); |
Ian Rogers | f224751 | 2014-12-02 16:17:08 -0800 | [diff] [blame^] | 143 | ArtMethod* result = nullptr; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 144 | // Did this method override a super class method? If so load the result from the super class' |
| 145 | // vtable |
Mingyao Yang | 2cdbad7 | 2014-07-16 10:44:41 -0700 | [diff] [blame] | 146 | if (super_class->HasVTable() && method_index < super_class->GetVTableLength()) { |
| 147 | result = super_class->GetVTableEntry(method_index); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 148 | } else { |
| 149 | // Method didn't override superclass method so search interfaces |
| 150 | if (IsProxyMethod()) { |
| 151 | result = GetDexCacheResolvedMethods()->Get(GetDexMethodIndex()); |
| 152 | CHECK_EQ(result, |
| 153 | Runtime::Current()->GetClassLinker()->FindMethodForProxy(GetDeclaringClass(), this)); |
| 154 | } else { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 155 | IfTable* iftable = GetDeclaringClass()->GetIfTable(); |
Ian Rogers | f224751 | 2014-12-02 16:17:08 -0800 | [diff] [blame^] | 156 | for (size_t i = 0; i < iftable->Count() && result == nullptr; i++) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 157 | Class* interface = iftable->GetInterface(i); |
| 158 | for (size_t j = 0; j < interface->NumVirtualMethods(); ++j) { |
Ian Rogers | f224751 | 2014-12-02 16:17:08 -0800 | [diff] [blame^] | 159 | mirror::ArtMethod* interface_method = interface->GetVirtualMethod(j); |
| 160 | if (HasSameNameAndSignature(this, interface_method)) { |
| 161 | result = interface_method; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 162 | break; |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | } |
Jeff Hao | f0a3f09 | 2014-07-24 16:26:09 -0700 | [diff] [blame] | 168 | if (kIsDebugBuild) { |
Ian Rogers | f224751 | 2014-12-02 16:17:08 -0800 | [diff] [blame^] | 169 | DCHECK(result == nullptr || HasSameNameAndSignature(this, result)); |
Jeff Hao | f0a3f09 | 2014-07-24 16:26:09 -0700 | [diff] [blame] | 170 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 171 | return result; |
| 172 | } |
| 173 | |
Ian Rogers | e0a02da | 2014-12-02 14:10:53 -0800 | [diff] [blame] | 174 | uint32_t ArtMethod::FindDexMethodIndexInOtherDexFile(const DexFile& other_dexfile, |
| 175 | uint32_t name_and_signature_idx) { |
| 176 | const DexFile* dexfile = GetDexFile(); |
| 177 | const uint32_t dex_method_idx = GetDexMethodIndex(); |
| 178 | const DexFile::MethodId& mid = dexfile->GetMethodId(dex_method_idx); |
| 179 | const DexFile::MethodId& name_and_sig_mid = other_dexfile.GetMethodId(name_and_signature_idx); |
| 180 | DCHECK_STREQ(dexfile->GetMethodName(mid), other_dexfile.GetMethodName(name_and_sig_mid)); |
| 181 | DCHECK_EQ(dexfile->GetMethodSignature(mid), other_dexfile.GetMethodSignature(name_and_sig_mid)); |
| 182 | if (dexfile == &other_dexfile) { |
| 183 | return dex_method_idx; |
| 184 | } |
| 185 | const char* mid_declaring_class_descriptor = dexfile->StringByTypeIdx(mid.class_idx_); |
| 186 | const DexFile::StringId* other_descriptor = |
| 187 | other_dexfile.FindStringId(mid_declaring_class_descriptor); |
| 188 | if (other_descriptor != nullptr) { |
| 189 | const DexFile::TypeId* other_type_id = |
| 190 | other_dexfile.FindTypeId(other_dexfile.GetIndexForStringId(*other_descriptor)); |
| 191 | if (other_type_id != nullptr) { |
| 192 | const DexFile::MethodId* other_mid = other_dexfile.FindMethodId( |
| 193 | *other_type_id, other_dexfile.GetStringId(name_and_sig_mid.name_idx_), |
| 194 | other_dexfile.GetProtoId(name_and_sig_mid.proto_idx_)); |
| 195 | if (other_mid != nullptr) { |
| 196 | return other_dexfile.GetIndexForMethodId(*other_mid); |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | return DexFile::kDexNoIndex; |
| 201 | } |
| 202 | |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 203 | uint32_t ArtMethod::ToDexPc(const uintptr_t pc, bool abort_on_failure) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 204 | if (IsPortableCompiled()) { |
| 205 | // Portable doesn't use the machine pc, we just use dex pc instead. |
| 206 | return static_cast<uint32_t>(pc); |
| 207 | } |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 208 | const void* entry_point = GetQuickOatEntryPoint(sizeof(void*)); |
| 209 | MappingTable table(entry_point != nullptr ? |
| 210 | GetMappingTable(EntryPointToCodePointer(entry_point), sizeof(void*)) : nullptr); |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 211 | if (table.TotalSize() == 0) { |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 212 | // NOTE: Special methods (see Mir2Lir::GenSpecialCase()) have an empty mapping |
| 213 | // but they have no suspend checks and, consequently, we never call ToDexPc() for them. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 214 | DCHECK(IsNative() || IsCalleeSaveMethod() || IsProxyMethod()) << PrettyMethod(this); |
| 215 | return DexFile::kDexNoIndex; // Special no mapping case |
| 216 | } |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 217 | uint32_t sought_offset = pc - reinterpret_cast<uintptr_t>(entry_point); |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 218 | // Assume the caller wants a pc-to-dex mapping so check here first. |
| 219 | typedef MappingTable::PcToDexIterator It; |
| 220 | for (It cur = table.PcToDexBegin(), end = table.PcToDexEnd(); cur != end; ++cur) { |
| 221 | if (cur.NativePcOffset() == sought_offset) { |
| 222 | return cur.DexPc(); |
| 223 | } |
| 224 | } |
| 225 | // Now check dex-to-pc mappings. |
| 226 | typedef MappingTable::DexToPcIterator It2; |
| 227 | for (It2 cur = table.DexToPcBegin(), end = table.DexToPcEnd(); cur != end; ++cur) { |
| 228 | if (cur.NativePcOffset() == sought_offset) { |
| 229 | return cur.DexPc(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 230 | } |
| 231 | } |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 232 | if (abort_on_failure) { |
| 233 | LOG(FATAL) << "Failed to find Dex offset for PC offset " << reinterpret_cast<void*>(sought_offset) |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 234 | << "(PC " << reinterpret_cast<void*>(pc) << ", entry_point=" << entry_point |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 235 | << ") in " << PrettyMethod(this); |
| 236 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 237 | return DexFile::kDexNoIndex; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 238 | } |
| 239 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 240 | uintptr_t ArtMethod::ToNativeQuickPc(const uint32_t dex_pc, bool abort_on_failure) { |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 241 | const void* entry_point = GetQuickOatEntryPoint(sizeof(void*)); |
| 242 | MappingTable table(entry_point != nullptr ? |
| 243 | GetMappingTable(EntryPointToCodePointer(entry_point), sizeof(void*)) : nullptr); |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 244 | if (table.TotalSize() == 0) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 245 | DCHECK_EQ(dex_pc, 0U); |
| 246 | return 0; // Special no mapping/pc == 0 case |
| 247 | } |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 248 | // Assume the caller wants a dex-to-pc mapping so check here first. |
| 249 | typedef MappingTable::DexToPcIterator It; |
| 250 | for (It cur = table.DexToPcBegin(), end = table.DexToPcEnd(); cur != end; ++cur) { |
| 251 | if (cur.DexPc() == dex_pc) { |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 252 | return reinterpret_cast<uintptr_t>(entry_point) + cur.NativePcOffset(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 253 | } |
| 254 | } |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 255 | // Now check pc-to-dex mappings. |
| 256 | typedef MappingTable::PcToDexIterator It2; |
| 257 | for (It2 cur = table.PcToDexBegin(), end = table.PcToDexEnd(); cur != end; ++cur) { |
| 258 | if (cur.DexPc() == dex_pc) { |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 259 | return reinterpret_cast<uintptr_t>(entry_point) + cur.NativePcOffset(); |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 260 | } |
| 261 | } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 262 | if (abort_on_failure) { |
| 263 | LOG(FATAL) << "Failed to find native offset for dex pc 0x" << std::hex << dex_pc |
| 264 | << " in " << PrettyMethod(this); |
| 265 | } |
| 266 | return UINTPTR_MAX; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 267 | } |
| 268 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 269 | uint32_t ArtMethod::FindCatchBlock(Handle<ArtMethod> h_this, Handle<Class> exception_type, |
| 270 | uint32_t dex_pc, bool* has_no_move_exception) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 271 | const DexFile::CodeItem* code_item = h_this->GetCodeItem(); |
Jeff Hao | aa96191 | 2014-04-22 13:54:32 -0700 | [diff] [blame] | 272 | // Set aside the exception while we resolve its type. |
| 273 | Thread* self = Thread::Current(); |
| 274 | ThrowLocation throw_location; |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 275 | StackHandleScope<1> hs(self); |
| 276 | Handle<mirror::Throwable> exception(hs.NewHandle(self->GetException(&throw_location))); |
Sebastien Hertz | 9f10203 | 2014-05-23 08:59:42 +0200 | [diff] [blame] | 277 | bool is_exception_reported = self->IsExceptionReportedToInstrumentation(); |
Jeff Hao | aa96191 | 2014-04-22 13:54:32 -0700 | [diff] [blame] | 278 | self->ClearException(); |
Ian Rogers | 9e8f45e | 2013-07-31 10:58:53 -0700 | [diff] [blame] | 279 | // Default to handler not found. |
| 280 | uint32_t found_dex_pc = DexFile::kDexNoIndex; |
| 281 | // Iterate over the catch handlers associated with dex_pc. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 282 | for (CatchHandlerIterator it(*code_item, dex_pc); it.HasNext(); it.Next()) { |
| 283 | uint16_t iter_type_idx = it.GetHandlerTypeIndex(); |
| 284 | // Catch all case |
| 285 | if (iter_type_idx == DexFile::kDexNoIndex16) { |
Ian Rogers | 9e8f45e | 2013-07-31 10:58:53 -0700 | [diff] [blame] | 286 | found_dex_pc = it.GetHandlerAddress(); |
| 287 | break; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 288 | } |
| 289 | // Does this catch exception type apply? |
Ian Rogers | a048560 | 2014-12-02 15:48:04 -0800 | [diff] [blame] | 290 | Class* iter_exception_type = h_this->GetClassFromTypeIndex(iter_type_idx, true); |
Ian Rogers | 822266b | 2014-05-29 16:55:06 -0700 | [diff] [blame] | 291 | if (UNLIKELY(iter_exception_type == nullptr)) { |
| 292 | // Now have a NoClassDefFoundError as exception. Ignore in case the exception class was |
| 293 | // removed by a pro-guard like tool. |
Andreas Gampe | 72b3e43 | 2014-05-13 21:42:05 -0700 | [diff] [blame] | 294 | // Note: this is not RI behavior. RI would have failed when loading the class. |
Ian Rogers | 822266b | 2014-05-29 16:55:06 -0700 | [diff] [blame] | 295 | self->ClearException(); |
| 296 | // Delete any long jump context as this routine is called during a stack walk which will |
| 297 | // release its in use context at the end. |
| 298 | delete self->GetLongJumpContext(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 299 | LOG(WARNING) << "Unresolved exception class when finding catch block: " |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 300 | << DescriptorToDot(h_this->GetTypeDescriptorFromTypeIdx(iter_type_idx)); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 301 | } else if (iter_exception_type->IsAssignableFrom(exception_type.Get())) { |
Ian Rogers | 9e8f45e | 2013-07-31 10:58:53 -0700 | [diff] [blame] | 302 | found_dex_pc = it.GetHandlerAddress(); |
| 303 | break; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 304 | } |
| 305 | } |
Ian Rogers | 9e8f45e | 2013-07-31 10:58:53 -0700 | [diff] [blame] | 306 | if (found_dex_pc != DexFile::kDexNoIndex) { |
| 307 | const Instruction* first_catch_instr = |
Jeff Hao | aa96191 | 2014-04-22 13:54:32 -0700 | [diff] [blame] | 308 | Instruction::At(&code_item->insns_[found_dex_pc]); |
Ian Rogers | 9e8f45e | 2013-07-31 10:58:53 -0700 | [diff] [blame] | 309 | *has_no_move_exception = (first_catch_instr->Opcode() != Instruction::MOVE_EXCEPTION); |
| 310 | } |
Jeff Hao | aa96191 | 2014-04-22 13:54:32 -0700 | [diff] [blame] | 311 | // Put the exception back. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 312 | if (exception.Get() != nullptr) { |
| 313 | self->SetException(throw_location, exception.Get()); |
Sebastien Hertz | 9f10203 | 2014-05-23 08:59:42 +0200 | [diff] [blame] | 314 | self->SetExceptionReportedToInstrumentation(is_exception_reported); |
Jeff Hao | aa96191 | 2014-04-22 13:54:32 -0700 | [diff] [blame] | 315 | } |
Ian Rogers | 9e8f45e | 2013-07-31 10:58:53 -0700 | [diff] [blame] | 316 | return found_dex_pc; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 317 | } |
| 318 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 319 | void ArtMethod::AssertPcIsWithinQuickCode(uintptr_t pc) { |
| 320 | if (IsNative() || IsRuntimeMethod() || IsProxyMethod()) { |
| 321 | return; |
| 322 | } |
| 323 | if (pc == reinterpret_cast<uintptr_t>(GetQuickInstrumentationExitPc())) { |
| 324 | return; |
| 325 | } |
| 326 | const void* code = GetEntryPointFromQuickCompiledCode(); |
| 327 | if (code == GetQuickInstrumentationEntryPoint()) { |
| 328 | return; |
| 329 | } |
| 330 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 331 | if (class_linker->IsQuickToInterpreterBridge(code) || |
| 332 | class_linker->IsQuickResolutionStub(code)) { |
| 333 | return; |
| 334 | } |
| 335 | /* |
| 336 | * During a stack walk, a return PC may point past-the-end of the code |
| 337 | * in the case that the last instruction is a call that isn't expected to |
| 338 | * return. Thus, we check <= code + GetCodeSize(). |
| 339 | * |
| 340 | * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state. |
| 341 | */ |
| 342 | CHECK(PcIsWithinQuickCode(pc)) |
| 343 | << PrettyMethod(this) |
| 344 | << " pc=" << std::hex << pc |
| 345 | << " code=" << code |
| 346 | << " size=" << GetCodeSize(); |
| 347 | } |
| 348 | |
Hiroshi Yamauchi | 9bdec88 | 2014-08-15 17:11:12 -0700 | [diff] [blame] | 349 | bool ArtMethod::IsEntrypointInterpreter() { |
| 350 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Hiroshi Yamauchi | 9bdec88 | 2014-08-15 17:11:12 -0700 | [diff] [blame] | 351 | if (!IsPortableCompiled()) { // Quick. |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 352 | const void* oat_quick_code = class_linker->GetOatMethodQuickCodeFor(this); |
Hiroshi Yamauchi | 9bdec88 | 2014-08-15 17:11:12 -0700 | [diff] [blame] | 353 | return oat_quick_code == nullptr || |
| 354 | oat_quick_code != GetEntryPointFromQuickCompiledCode(); |
| 355 | } else { // Portable. |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 356 | const void* oat_portable_code = class_linker->GetOatMethodPortableCodeFor(this); |
Hiroshi Yamauchi | 9bdec88 | 2014-08-15 17:11:12 -0700 | [diff] [blame] | 357 | return oat_portable_code == nullptr || |
| 358 | oat_portable_code != GetEntryPointFromPortableCompiledCode(); |
| 359 | } |
| 360 | } |
| 361 | |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 362 | const void* ArtMethod::GetQuickOatEntryPoint(size_t pointer_size) { |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 363 | if (IsPortableCompiled() || IsAbstract() || IsRuntimeMethod() || IsProxyMethod()) { |
| 364 | return nullptr; |
| 365 | } |
| 366 | Runtime* runtime = Runtime::Current(); |
| 367 | ClassLinker* class_linker = runtime->GetClassLinker(); |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 368 | const void* code = runtime->GetInstrumentation()->GetQuickCodeFor(this, pointer_size); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 369 | // On failure, instead of nullptr we get the quick-generic-jni-trampoline for native method |
| 370 | // indicating the generic JNI, or the quick-to-interpreter-bridge (but not the trampoline) |
| 371 | // for non-native methods. |
| 372 | if (class_linker->IsQuickToInterpreterBridge(code) || |
| 373 | class_linker->IsQuickGenericJniStub(code)) { |
| 374 | return nullptr; |
| 375 | } |
| 376 | return code; |
| 377 | } |
| 378 | |
| 379 | #ifndef NDEBUG |
| 380 | uintptr_t ArtMethod::NativeQuickPcOffset(const uintptr_t pc, const void* quick_entry_point) { |
| 381 | CHECK_NE(quick_entry_point, GetQuickToInterpreterBridge()); |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 382 | CHECK_EQ(quick_entry_point, Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this, sizeof(void*))); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 383 | return pc - reinterpret_cast<uintptr_t>(quick_entry_point); |
| 384 | } |
| 385 | #endif |
| 386 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 387 | void ArtMethod::Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, |
Ian Rogers | 0177e53 | 2014-02-11 16:30:46 -0800 | [diff] [blame] | 388 | const char* shorty) { |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 389 | if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEnd())) { |
| 390 | ThrowStackOverflowError(self); |
| 391 | return; |
| 392 | } |
| 393 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 394 | if (kIsDebugBuild) { |
| 395 | self->AssertThreadSuspensionIsAllowable(); |
| 396 | CHECK_EQ(kRunnable, self->GetState()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 397 | CHECK_STREQ(GetShorty(), shorty); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | // Push a transition back into managed code onto the linked list in thread. |
| 401 | ManagedStack fragment; |
| 402 | self->PushManagedStackFragment(&fragment); |
| 403 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 404 | Runtime* runtime = Runtime::Current(); |
Jeff Hao | 74180ca | 2013-03-27 15:29:11 -0700 | [diff] [blame] | 405 | // Call the invoke stub, passing everything as arguments. |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 406 | if (UNLIKELY(!runtime->IsStarted())) { |
Ian Rogers | 5d27faf | 2014-05-02 17:17:18 -0700 | [diff] [blame] | 407 | if (IsStatic()) { |
| 408 | art::interpreter::EnterInterpreterFromInvoke(self, this, nullptr, args, result); |
| 409 | } else { |
| 410 | Object* receiver = reinterpret_cast<StackReference<Object>*>(&args[0])->AsMirrorPtr(); |
| 411 | art::interpreter::EnterInterpreterFromInvoke(self, this, receiver, args + 1, result); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 412 | } |
| 413 | } else { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 414 | const bool kLogInvocationStartAndReturn = false; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 415 | bool have_quick_code = GetEntryPointFromQuickCompiledCode() != nullptr; |
| 416 | bool have_portable_code = GetEntryPointFromPortableCompiledCode() != nullptr; |
| 417 | if (LIKELY(have_quick_code || have_portable_code)) { |
Jeff Hao | 790ad90 | 2013-05-22 15:02:08 -0700 | [diff] [blame] | 418 | if (kLogInvocationStartAndReturn) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 419 | LOG(INFO) << StringPrintf("Invoking '%s' %s code=%p", PrettyMethod(this).c_str(), |
| 420 | have_quick_code ? "quick" : "portable", |
| 421 | have_quick_code ? GetEntryPointFromQuickCompiledCode() |
| 422 | : GetEntryPointFromPortableCompiledCode()); |
Jeff Hao | 790ad90 | 2013-05-22 15:02:08 -0700 | [diff] [blame] | 423 | } |
Hiroshi Yamauchi | 9bdec88 | 2014-08-15 17:11:12 -0700 | [diff] [blame] | 424 | |
| 425 | // Ensure that we won't be accidentally calling quick/portable compiled code when -Xint. |
| 426 | if (kIsDebugBuild && Runtime::Current()->GetInstrumentation()->IsForcedInterpretOnly()) { |
| 427 | CHECK(IsEntrypointInterpreter()) |
| 428 | << "Don't call compiled code when -Xint " << PrettyMethod(this); |
| 429 | } |
| 430 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 431 | if (!IsPortableCompiled()) { |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 432 | #if defined(__LP64__) || defined(__arm__) |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 433 | if (!IsStatic()) { |
| 434 | (*art_quick_invoke_stub)(this, args, args_size, self, result, shorty); |
| 435 | } else { |
| 436 | (*art_quick_invoke_static_stub)(this, args, args_size, self, result, shorty); |
| 437 | } |
| 438 | #else |
Ian Rogers | 0177e53 | 2014-02-11 16:30:46 -0800 | [diff] [blame] | 439 | (*art_quick_invoke_stub)(this, args, args_size, self, result, shorty); |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 440 | #endif |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 441 | } else { |
Ian Rogers | 0177e53 | 2014-02-11 16:30:46 -0800 | [diff] [blame] | 442 | (*art_portable_invoke_stub)(this, args, args_size, self, result, shorty[0]); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 443 | } |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 444 | if (UNLIKELY(self->GetException(nullptr) == Thread::GetDeoptimizationException())) { |
| 445 | // Unusual case where we were running generated code and an |
Jeff Hao | 790ad90 | 2013-05-22 15:02:08 -0700 | [diff] [blame] | 446 | // exception was thrown to force the activations to be removed from the |
| 447 | // stack. Continue execution in the interpreter. |
| 448 | self->ClearException(); |
| 449 | ShadowFrame* shadow_frame = self->GetAndClearDeoptimizationShadowFrame(result); |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 450 | self->SetTopOfStack(nullptr); |
Jeff Hao | 790ad90 | 2013-05-22 15:02:08 -0700 | [diff] [blame] | 451 | self->SetTopOfShadowStack(shadow_frame); |
| 452 | interpreter::EnterInterpreterFromDeoptimize(self, shadow_frame, result); |
| 453 | } |
| 454 | if (kLogInvocationStartAndReturn) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 455 | LOG(INFO) << StringPrintf("Returned '%s' %s code=%p", PrettyMethod(this).c_str(), |
| 456 | have_quick_code ? "quick" : "portable", |
| 457 | have_quick_code ? GetEntryPointFromQuickCompiledCode() |
| 458 | : GetEntryPointFromPortableCompiledCode()); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 459 | } |
| 460 | } else { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 461 | LOG(INFO) << "Not invoking '" << PrettyMethod(this) << "' code=null"; |
Ian Rogers | f224751 | 2014-12-02 16:17:08 -0800 | [diff] [blame^] | 462 | if (result != nullptr) { |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 463 | result->SetJ(0); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 464 | } |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | // Pop transition. |
| 469 | self->PopManagedStackFragment(fragment); |
| 470 | } |
| 471 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 472 | QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo() { |
| 473 | if (UNLIKELY(IsPortableCompiled())) { |
| 474 | // Portable compiled dex bytecode or jni stub. |
| 475 | return QuickMethodFrameInfo(kStackAlignment, 0u, 0u); |
| 476 | } |
| 477 | Runtime* runtime = Runtime::Current(); |
Daniel Mihalyi | e14f2b3 | 2014-10-10 18:24:11 +0200 | [diff] [blame] | 478 | |
| 479 | if (UNLIKELY(IsAbstract())) { |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 480 | return runtime->GetCalleeSaveMethodFrameInfo(Runtime::kRefsAndArgs); |
| 481 | } |
Daniel Mihalyi | e14f2b3 | 2014-10-10 18:24:11 +0200 | [diff] [blame] | 482 | |
| 483 | // For Proxy method we add special handling for the direct method case (there is only one |
| 484 | // direct method - constructor). Direct method is cloned from original |
| 485 | // java.lang.reflect.Proxy class together with code and as a result it is executed as usual |
| 486 | // quick compiled method without any stubs. So the frame info should be returned as it is a |
| 487 | // quick method not a stub. However, if instrumentation stubs are installed, the |
| 488 | // instrumentation->GetQuickCodeFor() returns the artQuickProxyInvokeHandler instead of an |
| 489 | // oat code pointer, thus we have to add a special case here. |
| 490 | if (UNLIKELY(IsProxyMethod())) { |
| 491 | if (IsDirect()) { |
| 492 | CHECK(IsConstructor()); |
| 493 | return GetQuickFrameInfo(EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode())); |
| 494 | } else { |
| 495 | return runtime->GetCalleeSaveMethodFrameInfo(Runtime::kRefsAndArgs); |
| 496 | } |
| 497 | } |
| 498 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 499 | if (UNLIKELY(IsRuntimeMethod())) { |
| 500 | return runtime->GetRuntimeMethodFrameInfo(this); |
| 501 | } |
| 502 | |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 503 | const void* entry_point = runtime->GetInstrumentation()->GetQuickCodeFor(this, sizeof(void*)); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 504 | ClassLinker* class_linker = runtime->GetClassLinker(); |
| 505 | // On failure, instead of nullptr we get the quick-generic-jni-trampoline for native method |
| 506 | // indicating the generic JNI, or the quick-to-interpreter-bridge (but not the trampoline) |
| 507 | // for non-native methods. And we really shouldn't see a failure for non-native methods here. |
| 508 | DCHECK(!class_linker->IsQuickToInterpreterBridge(entry_point)); |
| 509 | |
| 510 | if (class_linker->IsQuickGenericJniStub(entry_point)) { |
| 511 | // Generic JNI frame. |
| 512 | DCHECK(IsNative()); |
| 513 | StackHandleScope<1> hs(Thread::Current()); |
| 514 | uint32_t handle_refs = |
| 515 | MethodHelper(hs.NewHandle(this)).GetNumberOfReferenceArgsWithoutReceiver() + 1; |
| 516 | size_t scope_size = HandleScope::SizeOf(handle_refs); |
| 517 | QuickMethodFrameInfo callee_info = runtime->GetCalleeSaveMethodFrameInfo(Runtime::kRefsAndArgs); |
| 518 | |
| 519 | // Callee saves + handle scope + method ref + alignment |
| 520 | size_t frame_size = RoundUp(callee_info.FrameSizeInBytes() + scope_size |
| 521 | - sizeof(void*) // callee-save frame stores a whole method pointer |
| 522 | + sizeof(StackReference<mirror::ArtMethod>), |
| 523 | kStackAlignment); |
| 524 | |
| 525 | return QuickMethodFrameInfo(frame_size, callee_info.CoreSpillMask(), callee_info.FpSpillMask()); |
| 526 | } |
| 527 | |
| 528 | const void* code_pointer = EntryPointToCodePointer(entry_point); |
| 529 | return GetQuickFrameInfo(code_pointer); |
| 530 | } |
| 531 | |
| 532 | void ArtMethod::RegisterNative(const void* native_method, bool is_fast) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 533 | CHECK(IsNative()) << PrettyMethod(this); |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 534 | CHECK(!IsFastNative()) << PrettyMethod(this); |
Ian Rogers | f224751 | 2014-12-02 16:17:08 -0800 | [diff] [blame^] | 535 | CHECK(native_method != nullptr) << PrettyMethod(this); |
Ian Rogers | 987560f | 2014-04-22 11:42:59 -0700 | [diff] [blame] | 536 | if (is_fast) { |
| 537 | SetAccessFlags(GetAccessFlags() | kAccFastNative); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 538 | } |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 539 | SetEntryPointFromJni(native_method); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 540 | } |
| 541 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 542 | void ArtMethod::UnregisterNative() { |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 543 | CHECK(IsNative() && !IsFastNative()) << PrettyMethod(this); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 544 | // restore stub to lookup native pointer via dlsym |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 545 | RegisterNative(GetJniDlsymLookupStub(), false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 546 | } |
| 547 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 548 | } // namespace mirror |
| 549 | } // namespace art |