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