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 | 62f0512 | 2014-03-21 11:21:29 -0700 | [diff] [blame] | 19 | #include "art_field-inl.h" |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 20 | #include "art_method-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 21 | #include "base/stringpiece.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 22 | #include "class-inl.h" |
| 23 | #include "dex_file-inl.h" |
Ian Rogers | c449aa8 | 2013-07-29 14:35:46 -0700 | [diff] [blame] | 24 | #include "dex_instruction.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 25 | #include "gc/accounting/card_table-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 26 | #include "interpreter/interpreter.h" |
| 27 | #include "jni_internal.h" |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 28 | #include "mapping_table.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 29 | #include "object-inl.h" |
| 30 | #include "object_array.h" |
| 31 | #include "object_array-inl.h" |
Ian Rogers | 62f0512 | 2014-03-21 11:21:29 -0700 | [diff] [blame] | 32 | #include "scoped_thread_state_change.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 33 | #include "string.h" |
| 34 | #include "object_utils.h" |
Ian Rogers | 62f0512 | 2014-03-21 11:21:29 -0700 | [diff] [blame] | 35 | #include "well_known_classes.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 36 | |
| 37 | namespace art { |
| 38 | namespace mirror { |
| 39 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 40 | 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] | 41 | extern "C" void art_quick_invoke_stub(ArtMethod*, uint32_t*, uint32_t, Thread*, JValue*, |
| 42 | const char*); |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 43 | #ifdef __LP64__ |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 44 | extern "C" void art_quick_invoke_static_stub(ArtMethod*, uint32_t*, uint32_t, Thread*, JValue*, |
| 45 | const char*); |
| 46 | #endif |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 47 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 48 | // TODO: get global references for these |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 49 | Class* ArtMethod::java_lang_reflect_ArtMethod_ = NULL; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 50 | |
Mathieu Chartier | 2b7c4d1 | 2014-05-19 10:52:16 -0700 | [diff] [blame] | 51 | ArtMethod* ArtMethod::FromReflectedMethod(const ScopedObjectAccessAlreadyRunnable& soa, |
| 52 | jobject jlr_method) { |
Ian Rogers | 62f0512 | 2014-03-21 11:21:29 -0700 | [diff] [blame] | 53 | mirror::ArtField* f = |
| 54 | soa.DecodeField(WellKnownClasses::java_lang_reflect_AbstractMethod_artMethod); |
| 55 | mirror::ArtMethod* method = f->GetObject(soa.Decode<mirror::Object*>(jlr_method))->AsArtMethod(); |
| 56 | DCHECK(method != nullptr); |
| 57 | return method; |
| 58 | } |
| 59 | |
| 60 | |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 61 | void ArtMethod::VisitRoots(RootCallback* callback, void* arg) { |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 62 | if (java_lang_reflect_ArtMethod_ != nullptr) { |
Mathieu Chartier | 815873e | 2014-02-13 18:02:13 -0800 | [diff] [blame] | 63 | callback(reinterpret_cast<mirror::Object**>(&java_lang_reflect_ArtMethod_), arg, 0, |
| 64 | kRootStickyClass); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 65 | } |
| 66 | } |
| 67 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 68 | InvokeType ArtMethod::GetInvokeType() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 69 | // TODO: kSuper? |
| 70 | if (GetDeclaringClass()->IsInterface()) { |
| 71 | return kInterface; |
| 72 | } else if (IsStatic()) { |
| 73 | return kStatic; |
| 74 | } else if (IsDirect()) { |
| 75 | return kDirect; |
| 76 | } else { |
| 77 | return kVirtual; |
| 78 | } |
| 79 | } |
| 80 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 81 | void ArtMethod::SetClass(Class* java_lang_reflect_ArtMethod) { |
| 82 | CHECK(java_lang_reflect_ArtMethod_ == NULL); |
| 83 | CHECK(java_lang_reflect_ArtMethod != NULL); |
| 84 | java_lang_reflect_ArtMethod_ = java_lang_reflect_ArtMethod; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 85 | } |
| 86 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 87 | void ArtMethod::ResetClass() { |
| 88 | CHECK(java_lang_reflect_ArtMethod_ != NULL); |
| 89 | java_lang_reflect_ArtMethod_ = NULL; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 90 | } |
| 91 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 92 | void ArtMethod::SetDexCacheStrings(ObjectArray<String>* new_dex_cache_strings) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 93 | SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_), |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 94 | new_dex_cache_strings); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 95 | } |
| 96 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 97 | void ArtMethod::SetDexCacheResolvedMethods(ObjectArray<ArtMethod>* new_dex_cache_methods) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 98 | SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_), |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 99 | new_dex_cache_methods); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 100 | } |
| 101 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 102 | void ArtMethod::SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_classes) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 103 | SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_), |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 104 | new_dex_cache_classes); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 105 | } |
| 106 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 107 | size_t ArtMethod::NumArgRegisters(const StringPiece& shorty) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 108 | CHECK_LE(1, shorty.length()); |
| 109 | uint32_t num_registers = 0; |
| 110 | for (int i = 1; i < shorty.length(); ++i) { |
| 111 | char ch = shorty[i]; |
| 112 | if (ch == 'D' || ch == 'J') { |
| 113 | num_registers += 2; |
| 114 | } else { |
| 115 | num_registers += 1; |
| 116 | } |
| 117 | } |
| 118 | return num_registers; |
| 119 | } |
| 120 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 121 | bool ArtMethod::IsProxyMethod() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 122 | return GetDeclaringClass()->IsProxyClass(); |
| 123 | } |
| 124 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 125 | ArtMethod* ArtMethod::FindOverriddenMethod() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 126 | if (IsStatic()) { |
| 127 | return NULL; |
| 128 | } |
| 129 | Class* declaring_class = GetDeclaringClass(); |
| 130 | Class* super_class = declaring_class->GetSuperClass(); |
| 131 | uint16_t method_index = GetMethodIndex(); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 132 | ObjectArray<ArtMethod>* super_class_vtable = super_class->GetVTable(); |
| 133 | ArtMethod* result = NULL; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 134 | // Did this method override a super class method? If so load the result from the super class' |
| 135 | // vtable |
| 136 | if (super_class_vtable != NULL && method_index < super_class_vtable->GetLength()) { |
| 137 | result = super_class_vtable->Get(method_index); |
| 138 | } else { |
| 139 | // Method didn't override superclass method so search interfaces |
| 140 | if (IsProxyMethod()) { |
| 141 | result = GetDexCacheResolvedMethods()->Get(GetDexMethodIndex()); |
| 142 | CHECK_EQ(result, |
| 143 | Runtime::Current()->GetClassLinker()->FindMethodForProxy(GetDeclaringClass(), this)); |
| 144 | } else { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame^] | 145 | StackHandleScope<2> hs(Thread::Current()); |
| 146 | MethodHelper mh(hs.NewHandle(this)); |
| 147 | MethodHelper interface_mh(hs.NewHandle<mirror::ArtMethod>(nullptr)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 148 | IfTable* iftable = GetDeclaringClass()->GetIfTable(); |
| 149 | for (size_t i = 0; i < iftable->Count() && result == NULL; i++) { |
| 150 | Class* interface = iftable->GetInterface(i); |
| 151 | for (size_t j = 0; j < interface->NumVirtualMethods(); ++j) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame^] | 152 | interface_mh.ChangeMethod(interface->GetVirtualMethod(j)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 153 | if (mh.HasSameNameAndSignature(&interface_mh)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame^] | 154 | result = interface_mh.GetMethod(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 155 | break; |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | #ifndef NDEBUG |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame^] | 162 | StackHandleScope<2> hs(Thread::Current()); |
| 163 | MethodHelper result_mh(hs.NewHandle(result)); |
| 164 | MethodHelper this_mh(hs.NewHandle(this)); |
| 165 | DCHECK(result == NULL || this_mh.HasSameNameAndSignature(&result_mh)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 166 | #endif |
| 167 | return result; |
| 168 | } |
| 169 | |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 170 | uint32_t ArtMethod::ToDexPc(const uintptr_t pc, bool abort_on_failure) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 171 | if (IsPortableCompiled()) { |
| 172 | // Portable doesn't use the machine pc, we just use dex pc instead. |
| 173 | return static_cast<uint32_t>(pc); |
| 174 | } |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 175 | const void* entry_point = GetQuickOatEntryPoint(); |
| 176 | MappingTable table( |
| 177 | entry_point != nullptr ? GetMappingTable(EntryPointToCodePointer(entry_point)) : nullptr); |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 178 | if (table.TotalSize() == 0) { |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 179 | // NOTE: Special methods (see Mir2Lir::GenSpecialCase()) have an empty mapping |
| 180 | // 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] | 181 | DCHECK(IsNative() || IsCalleeSaveMethod() || IsProxyMethod()) << PrettyMethod(this); |
| 182 | return DexFile::kDexNoIndex; // Special no mapping case |
| 183 | } |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 184 | uint32_t sought_offset = pc - reinterpret_cast<uintptr_t>(entry_point); |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 185 | // Assume the caller wants a pc-to-dex mapping so check here first. |
| 186 | typedef MappingTable::PcToDexIterator It; |
| 187 | for (It cur = table.PcToDexBegin(), end = table.PcToDexEnd(); cur != end; ++cur) { |
| 188 | if (cur.NativePcOffset() == sought_offset) { |
| 189 | return cur.DexPc(); |
| 190 | } |
| 191 | } |
| 192 | // Now check dex-to-pc mappings. |
| 193 | typedef MappingTable::DexToPcIterator It2; |
| 194 | for (It2 cur = table.DexToPcBegin(), end = table.DexToPcEnd(); cur != end; ++cur) { |
| 195 | if (cur.NativePcOffset() == sought_offset) { |
| 196 | return cur.DexPc(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 197 | } |
| 198 | } |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 199 | if (abort_on_failure) { |
| 200 | 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] | 201 | << "(PC " << reinterpret_cast<void*>(pc) << ", entry_point=" << entry_point |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 202 | << ") in " << PrettyMethod(this); |
| 203 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 204 | return DexFile::kDexNoIndex; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 205 | } |
| 206 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 207 | uintptr_t ArtMethod::ToNativePc(const uint32_t dex_pc) { |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 208 | const void* entry_point = GetQuickOatEntryPoint(); |
| 209 | MappingTable table( |
| 210 | entry_point != nullptr ? GetMappingTable(EntryPointToCodePointer(entry_point)) : nullptr); |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 211 | if (table.TotalSize() == 0) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 212 | DCHECK_EQ(dex_pc, 0U); |
| 213 | return 0; // Special no mapping/pc == 0 case |
| 214 | } |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 215 | // Assume the caller wants a dex-to-pc mapping so check here first. |
| 216 | typedef MappingTable::DexToPcIterator It; |
| 217 | for (It cur = table.DexToPcBegin(), end = table.DexToPcEnd(); cur != end; ++cur) { |
| 218 | if (cur.DexPc() == dex_pc) { |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 219 | return reinterpret_cast<uintptr_t>(entry_point) + cur.NativePcOffset(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 220 | } |
| 221 | } |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 222 | // Now check pc-to-dex mappings. |
| 223 | typedef MappingTable::PcToDexIterator It2; |
| 224 | for (It2 cur = table.PcToDexBegin(), end = table.PcToDexEnd(); cur != end; ++cur) { |
| 225 | if (cur.DexPc() == dex_pc) { |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 226 | return reinterpret_cast<uintptr_t>(entry_point) + cur.NativePcOffset(); |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | LOG(FATAL) << "Failed to find native offset for dex pc 0x" << std::hex << dex_pc |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 230 | << " in " << PrettyMethod(this); |
| 231 | return 0; |
| 232 | } |
| 233 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame^] | 234 | uint32_t ArtMethod::FindCatchBlock(Handle<ArtMethod> h_this, Handle<Class> exception_type, |
| 235 | uint32_t dex_pc, bool* has_no_move_exception) { |
| 236 | MethodHelper mh(h_this); |
| 237 | const DexFile::CodeItem* code_item = h_this->GetCodeItem(); |
Jeff Hao | aa96191 | 2014-04-22 13:54:32 -0700 | [diff] [blame] | 238 | // Set aside the exception while we resolve its type. |
| 239 | Thread* self = Thread::Current(); |
| 240 | ThrowLocation throw_location; |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 241 | StackHandleScope<1> hs(self); |
| 242 | Handle<mirror::Throwable> exception(hs.NewHandle(self->GetException(&throw_location))); |
Jeff Hao | aa96191 | 2014-04-22 13:54:32 -0700 | [diff] [blame] | 243 | self->ClearException(); |
Ian Rogers | 9e8f45e | 2013-07-31 10:58:53 -0700 | [diff] [blame] | 244 | // Default to handler not found. |
| 245 | uint32_t found_dex_pc = DexFile::kDexNoIndex; |
| 246 | // Iterate over the catch handlers associated with dex_pc. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 247 | for (CatchHandlerIterator it(*code_item, dex_pc); it.HasNext(); it.Next()) { |
| 248 | uint16_t iter_type_idx = it.GetHandlerTypeIndex(); |
| 249 | // Catch all case |
| 250 | if (iter_type_idx == DexFile::kDexNoIndex16) { |
Ian Rogers | 9e8f45e | 2013-07-31 10:58:53 -0700 | [diff] [blame] | 251 | found_dex_pc = it.GetHandlerAddress(); |
| 252 | break; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 253 | } |
| 254 | // Does this catch exception type apply? |
Jeff Hao | aa96191 | 2014-04-22 13:54:32 -0700 | [diff] [blame] | 255 | Class* iter_exception_type = mh.GetClassFromTypeIdx(iter_type_idx); |
Ian Rogers | 822266b | 2014-05-29 16:55:06 -0700 | [diff] [blame] | 256 | if (UNLIKELY(iter_exception_type == nullptr)) { |
| 257 | // Now have a NoClassDefFoundError as exception. Ignore in case the exception class was |
| 258 | // removed by a pro-guard like tool. |
Andreas Gampe | 72b3e43 | 2014-05-13 21:42:05 -0700 | [diff] [blame] | 259 | // 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] | 260 | self->ClearException(); |
| 261 | // Delete any long jump context as this routine is called during a stack walk which will |
| 262 | // release its in use context at the end. |
| 263 | delete self->GetLongJumpContext(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 264 | LOG(WARNING) << "Unresolved exception class when finding catch block: " |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame^] | 265 | << DescriptorToDot(h_this->GetTypeDescriptorFromTypeIdx(iter_type_idx)); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 266 | } else if (iter_exception_type->IsAssignableFrom(exception_type.Get())) { |
Ian Rogers | 9e8f45e | 2013-07-31 10:58:53 -0700 | [diff] [blame] | 267 | found_dex_pc = it.GetHandlerAddress(); |
| 268 | break; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 269 | } |
| 270 | } |
Ian Rogers | 9e8f45e | 2013-07-31 10:58:53 -0700 | [diff] [blame] | 271 | if (found_dex_pc != DexFile::kDexNoIndex) { |
| 272 | const Instruction* first_catch_instr = |
Jeff Hao | aa96191 | 2014-04-22 13:54:32 -0700 | [diff] [blame] | 273 | Instruction::At(&code_item->insns_[found_dex_pc]); |
Ian Rogers | 9e8f45e | 2013-07-31 10:58:53 -0700 | [diff] [blame] | 274 | *has_no_move_exception = (first_catch_instr->Opcode() != Instruction::MOVE_EXCEPTION); |
| 275 | } |
Jeff Hao | aa96191 | 2014-04-22 13:54:32 -0700 | [diff] [blame] | 276 | // Put the exception back. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 277 | if (exception.Get() != nullptr) { |
| 278 | self->SetException(throw_location, exception.Get()); |
Jeff Hao | aa96191 | 2014-04-22 13:54:32 -0700 | [diff] [blame] | 279 | } |
Ian Rogers | 9e8f45e | 2013-07-31 10:58:53 -0700 | [diff] [blame] | 280 | return found_dex_pc; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 281 | } |
| 282 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 283 | 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] | 284 | const char* shorty) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 285 | if (kIsDebugBuild) { |
| 286 | self->AssertThreadSuspensionIsAllowable(); |
| 287 | CHECK_EQ(kRunnable, self->GetState()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame^] | 288 | CHECK_STREQ(GetShorty(), shorty); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | // Push a transition back into managed code onto the linked list in thread. |
| 292 | ManagedStack fragment; |
| 293 | self->PushManagedStackFragment(&fragment); |
| 294 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 295 | Runtime* runtime = Runtime::Current(); |
Jeff Hao | 74180ca | 2013-03-27 15:29:11 -0700 | [diff] [blame] | 296 | // Call the invoke stub, passing everything as arguments. |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 297 | if (UNLIKELY(!runtime->IsStarted())) { |
Ian Rogers | 5d27faf | 2014-05-02 17:17:18 -0700 | [diff] [blame] | 298 | if (IsStatic()) { |
| 299 | art::interpreter::EnterInterpreterFromInvoke(self, this, nullptr, args, result); |
| 300 | } else { |
| 301 | Object* receiver = reinterpret_cast<StackReference<Object>*>(&args[0])->AsMirrorPtr(); |
| 302 | art::interpreter::EnterInterpreterFromInvoke(self, this, receiver, args + 1, result); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 303 | } |
| 304 | } else { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 305 | const bool kLogInvocationStartAndReturn = false; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 306 | bool have_quick_code = GetEntryPointFromQuickCompiledCode() != nullptr; |
| 307 | bool have_portable_code = GetEntryPointFromPortableCompiledCode() != nullptr; |
| 308 | if (LIKELY(have_quick_code || have_portable_code)) { |
Jeff Hao | 790ad90 | 2013-05-22 15:02:08 -0700 | [diff] [blame] | 309 | if (kLogInvocationStartAndReturn) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 310 | LOG(INFO) << StringPrintf("Invoking '%s' %s code=%p", PrettyMethod(this).c_str(), |
| 311 | have_quick_code ? "quick" : "portable", |
| 312 | have_quick_code ? GetEntryPointFromQuickCompiledCode() |
| 313 | : GetEntryPointFromPortableCompiledCode()); |
Jeff Hao | 790ad90 | 2013-05-22 15:02:08 -0700 | [diff] [blame] | 314 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 315 | if (!IsPortableCompiled()) { |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 316 | #ifdef __LP64__ |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 317 | if (!IsStatic()) { |
| 318 | (*art_quick_invoke_stub)(this, args, args_size, self, result, shorty); |
| 319 | } else { |
| 320 | (*art_quick_invoke_static_stub)(this, args, args_size, self, result, shorty); |
| 321 | } |
| 322 | #else |
Ian Rogers | 0177e53 | 2014-02-11 16:30:46 -0800 | [diff] [blame] | 323 | (*art_quick_invoke_stub)(this, args, args_size, self, result, shorty); |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 324 | #endif |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 325 | } else { |
Ian Rogers | 0177e53 | 2014-02-11 16:30:46 -0800 | [diff] [blame] | 326 | (*art_portable_invoke_stub)(this, args, args_size, self, result, shorty[0]); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 327 | } |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 328 | if (UNLIKELY(self->GetException(nullptr) == Thread::GetDeoptimizationException())) { |
| 329 | // Unusual case where we were running generated code and an |
Jeff Hao | 790ad90 | 2013-05-22 15:02:08 -0700 | [diff] [blame] | 330 | // exception was thrown to force the activations to be removed from the |
| 331 | // stack. Continue execution in the interpreter. |
| 332 | self->ClearException(); |
| 333 | ShadowFrame* shadow_frame = self->GetAndClearDeoptimizationShadowFrame(result); |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 334 | self->SetTopOfStack(nullptr, 0); |
Jeff Hao | 790ad90 | 2013-05-22 15:02:08 -0700 | [diff] [blame] | 335 | self->SetTopOfShadowStack(shadow_frame); |
| 336 | interpreter::EnterInterpreterFromDeoptimize(self, shadow_frame, result); |
| 337 | } |
| 338 | if (kLogInvocationStartAndReturn) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 339 | LOG(INFO) << StringPrintf("Returned '%s' %s code=%p", PrettyMethod(this).c_str(), |
| 340 | have_quick_code ? "quick" : "portable", |
| 341 | have_quick_code ? GetEntryPointFromQuickCompiledCode() |
| 342 | : GetEntryPointFromPortableCompiledCode()); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 343 | } |
| 344 | } else { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 345 | LOG(INFO) << "Not invoking '" << PrettyMethod(this) << "' code=null"; |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 346 | if (result != NULL) { |
| 347 | result->SetJ(0); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | // Pop transition. |
| 353 | self->PopManagedStackFragment(fragment); |
| 354 | } |
| 355 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 356 | bool ArtMethod::IsRegistered() { |
| 357 | void* native_method = |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 358 | GetFieldPtr<void*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_jni_)); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 359 | CHECK(native_method != nullptr); |
Jeff Hao | 79fe539 | 2013-04-24 18:41:58 -0700 | [diff] [blame] | 360 | void* jni_stub = GetJniDlsymLookupStub(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 361 | return native_method != jni_stub; |
| 362 | } |
| 363 | |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 364 | void ArtMethod::RegisterNative(Thread* self, const void* native_method, bool is_fast) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 365 | DCHECK(Thread::Current() == self); |
| 366 | CHECK(IsNative()) << PrettyMethod(this); |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 367 | CHECK(!IsFastNative()) << PrettyMethod(this); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 368 | CHECK(native_method != NULL) << PrettyMethod(this); |
Ian Rogers | 987560f | 2014-04-22 11:42:59 -0700 | [diff] [blame] | 369 | if (is_fast) { |
| 370 | SetAccessFlags(GetAccessFlags() | kAccFastNative); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 371 | } |
Ian Rogers | 987560f | 2014-04-22 11:42:59 -0700 | [diff] [blame] | 372 | SetNativeMethod(native_method); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 373 | } |
| 374 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 375 | void ArtMethod::UnregisterNative(Thread* self) { |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 376 | CHECK(IsNative() && !IsFastNative()) << PrettyMethod(this); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 377 | // restore stub to lookup native pointer via dlsym |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 378 | RegisterNative(self, GetJniDlsymLookupStub(), false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 379 | } |
| 380 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 381 | } // namespace mirror |
| 382 | } // namespace art |