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