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