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 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 19 | #include "art_method-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 20 | #include "base/stringpiece.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 21 | #include "class-inl.h" |
| 22 | #include "dex_file-inl.h" |
Ian Rogers | c449aa8 | 2013-07-29 14:35:46 -0700 | [diff] [blame] | 23 | #include "dex_instruction.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 24 | #include "gc/accounting/card_table-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 25 | #include "interpreter/interpreter.h" |
| 26 | #include "jni_internal.h" |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 27 | #include "mapping_table.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 28 | #include "object-inl.h" |
| 29 | #include "object_array.h" |
| 30 | #include "object_array-inl.h" |
| 31 | #include "string.h" |
| 32 | #include "object_utils.h" |
| 33 | |
| 34 | namespace art { |
| 35 | namespace mirror { |
| 36 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 37 | extern "C" void art_portable_invoke_stub(ArtMethod*, uint32_t*, uint32_t, Thread*, JValue*, char); |
| 38 | extern "C" void art_quick_invoke_stub(ArtMethod*, uint32_t*, uint32_t, Thread*, JValue*, char); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 39 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 40 | // TODO: get global references for these |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 41 | Class* ArtMethod::java_lang_reflect_ArtMethod_ = NULL; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 42 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 43 | InvokeType ArtMethod::GetInvokeType() const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 44 | // TODO: kSuper? |
| 45 | if (GetDeclaringClass()->IsInterface()) { |
| 46 | return kInterface; |
| 47 | } else if (IsStatic()) { |
| 48 | return kStatic; |
| 49 | } else if (IsDirect()) { |
| 50 | return kDirect; |
| 51 | } else { |
| 52 | return kVirtual; |
| 53 | } |
| 54 | } |
| 55 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 56 | void ArtMethod::SetClass(Class* java_lang_reflect_ArtMethod) { |
| 57 | CHECK(java_lang_reflect_ArtMethod_ == NULL); |
| 58 | CHECK(java_lang_reflect_ArtMethod != NULL); |
| 59 | java_lang_reflect_ArtMethod_ = java_lang_reflect_ArtMethod; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 60 | } |
| 61 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 62 | void ArtMethod::ResetClass() { |
| 63 | CHECK(java_lang_reflect_ArtMethod_ != NULL); |
| 64 | java_lang_reflect_ArtMethod_ = NULL; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 67 | void ArtMethod::SetDexCacheStrings(ObjectArray<String>* new_dex_cache_strings) { |
| 68 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_), |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 69 | new_dex_cache_strings, false); |
| 70 | } |
| 71 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 72 | void ArtMethod::SetDexCacheResolvedMethods(ObjectArray<ArtMethod>* new_dex_cache_methods) { |
| 73 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_), |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 74 | new_dex_cache_methods, false); |
| 75 | } |
| 76 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 77 | void ArtMethod::SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_classes) { |
| 78 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_), |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 79 | new_dex_cache_classes, false); |
| 80 | } |
| 81 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 82 | void ArtMethod::SetDexCacheInitializedStaticStorage(ObjectArray<StaticStorageBase>* new_value) { |
| 83 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_initialized_static_storage_), |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 84 | new_value, false); |
| 85 | } |
| 86 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 87 | size_t ArtMethod::NumArgRegisters(const StringPiece& shorty) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 88 | CHECK_LE(1, shorty.length()); |
| 89 | uint32_t num_registers = 0; |
| 90 | for (int i = 1; i < shorty.length(); ++i) { |
| 91 | char ch = shorty[i]; |
| 92 | if (ch == 'D' || ch == 'J') { |
| 93 | num_registers += 2; |
| 94 | } else { |
| 95 | num_registers += 1; |
| 96 | } |
| 97 | } |
| 98 | return num_registers; |
| 99 | } |
| 100 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 101 | bool ArtMethod::IsProxyMethod() const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 102 | return GetDeclaringClass()->IsProxyClass(); |
| 103 | } |
| 104 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 105 | ArtMethod* ArtMethod::FindOverriddenMethod() const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 106 | if (IsStatic()) { |
| 107 | return NULL; |
| 108 | } |
| 109 | Class* declaring_class = GetDeclaringClass(); |
| 110 | Class* super_class = declaring_class->GetSuperClass(); |
| 111 | uint16_t method_index = GetMethodIndex(); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 112 | ObjectArray<ArtMethod>* super_class_vtable = super_class->GetVTable(); |
| 113 | ArtMethod* result = NULL; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 114 | // Did this method override a super class method? If so load the result from the super class' |
| 115 | // vtable |
| 116 | if (super_class_vtable != NULL && method_index < super_class_vtable->GetLength()) { |
| 117 | result = super_class_vtable->Get(method_index); |
| 118 | } else { |
| 119 | // Method didn't override superclass method so search interfaces |
| 120 | if (IsProxyMethod()) { |
| 121 | result = GetDexCacheResolvedMethods()->Get(GetDexMethodIndex()); |
| 122 | CHECK_EQ(result, |
| 123 | Runtime::Current()->GetClassLinker()->FindMethodForProxy(GetDeclaringClass(), this)); |
| 124 | } else { |
| 125 | MethodHelper mh(this); |
| 126 | MethodHelper interface_mh; |
| 127 | IfTable* iftable = GetDeclaringClass()->GetIfTable(); |
| 128 | for (size_t i = 0; i < iftable->Count() && result == NULL; i++) { |
| 129 | Class* interface = iftable->GetInterface(i); |
| 130 | for (size_t j = 0; j < interface->NumVirtualMethods(); ++j) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 131 | ArtMethod* interface_method = interface->GetVirtualMethod(j); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 132 | interface_mh.ChangeMethod(interface_method); |
| 133 | if (mh.HasSameNameAndSignature(&interface_mh)) { |
| 134 | result = interface_method; |
| 135 | break; |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | #ifndef NDEBUG |
| 142 | MethodHelper result_mh(result); |
| 143 | DCHECK(result == NULL || MethodHelper(this).HasSameNameAndSignature(&result_mh)); |
| 144 | #endif |
| 145 | return result; |
| 146 | } |
| 147 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 148 | uintptr_t ArtMethod::NativePcOffset(const uintptr_t pc) const { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 149 | const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this); |
| 150 | return pc - reinterpret_cast<uintptr_t>(code); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 151 | } |
| 152 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 153 | uint32_t ArtMethod::ToDexPc(const uintptr_t pc) const { |
Ian Rogers | c928de9 | 2013-02-27 14:30:44 -0800 | [diff] [blame] | 154 | #if !defined(ART_USE_PORTABLE_COMPILER) |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 155 | MappingTable table(GetMappingTable()); |
| 156 | if (table.TotalSize() == 0) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 157 | DCHECK(IsNative() || IsCalleeSaveMethod() || IsProxyMethod()) << PrettyMethod(this); |
| 158 | return DexFile::kDexNoIndex; // Special no mapping case |
| 159 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 160 | const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this); |
| 161 | uint32_t sought_offset = pc - reinterpret_cast<uintptr_t>(code); |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 162 | // Assume the caller wants a pc-to-dex mapping so check here first. |
| 163 | typedef MappingTable::PcToDexIterator It; |
| 164 | for (It cur = table.PcToDexBegin(), end = table.PcToDexEnd(); cur != end; ++cur) { |
| 165 | if (cur.NativePcOffset() == sought_offset) { |
| 166 | return cur.DexPc(); |
| 167 | } |
| 168 | } |
| 169 | // Now check dex-to-pc mappings. |
| 170 | typedef MappingTable::DexToPcIterator It2; |
| 171 | for (It2 cur = table.DexToPcBegin(), end = table.DexToPcEnd(); cur != end; ++cur) { |
| 172 | if (cur.NativePcOffset() == sought_offset) { |
| 173 | return cur.DexPc(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 174 | } |
| 175 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 176 | LOG(FATAL) << "Failed to find Dex offset for PC offset " << reinterpret_cast<void*>(sought_offset) |
| 177 | << "(PC " << reinterpret_cast<void*>(pc) << ", code=" << code |
| 178 | << ") in " << PrettyMethod(this); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 179 | return DexFile::kDexNoIndex; |
| 180 | #else |
| 181 | // Compiler LLVM doesn't use the machine pc, we just use dex pc instead. |
| 182 | return static_cast<uint32_t>(pc); |
| 183 | #endif |
| 184 | } |
| 185 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 186 | uintptr_t ArtMethod::ToNativePc(const uint32_t dex_pc) const { |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 187 | MappingTable table(GetMappingTable()); |
| 188 | if (table.TotalSize() == 0) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 189 | DCHECK_EQ(dex_pc, 0U); |
| 190 | return 0; // Special no mapping/pc == 0 case |
| 191 | } |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 192 | // Assume the caller wants a dex-to-pc mapping so check here first. |
| 193 | typedef MappingTable::DexToPcIterator It; |
| 194 | for (It cur = table.DexToPcBegin(), end = table.DexToPcEnd(); cur != end; ++cur) { |
| 195 | if (cur.DexPc() == dex_pc) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 196 | const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this); |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 197 | return reinterpret_cast<uintptr_t>(code) + 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) { |
| 204 | const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this); |
| 205 | return reinterpret_cast<uintptr_t>(code) + cur.NativePcOffset(); |
| 206 | } |
| 207 | } |
| 208 | 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] | 209 | << " in " << PrettyMethod(this); |
| 210 | return 0; |
| 211 | } |
| 212 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 213 | uint32_t ArtMethod::FindCatchBlock(Class* exception_type, uint32_t dex_pc, |
| 214 | bool* has_no_move_exception) const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 215 | MethodHelper mh(this); |
| 216 | const DexFile::CodeItem* code_item = mh.GetCodeItem(); |
Ian Rogers | 9e8f45e | 2013-07-31 10:58:53 -0700 | [diff] [blame] | 217 | // Default to handler not found. |
| 218 | uint32_t found_dex_pc = DexFile::kDexNoIndex; |
| 219 | // Iterate over the catch handlers associated with dex_pc. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 220 | for (CatchHandlerIterator it(*code_item, dex_pc); it.HasNext(); it.Next()) { |
| 221 | uint16_t iter_type_idx = it.GetHandlerTypeIndex(); |
| 222 | // Catch all case |
| 223 | if (iter_type_idx == DexFile::kDexNoIndex16) { |
Ian Rogers | 9e8f45e | 2013-07-31 10:58:53 -0700 | [diff] [blame] | 224 | found_dex_pc = it.GetHandlerAddress(); |
| 225 | break; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 226 | } |
| 227 | // Does this catch exception type apply? |
| 228 | Class* iter_exception_type = mh.GetDexCacheResolvedType(iter_type_idx); |
| 229 | if (iter_exception_type == NULL) { |
| 230 | // The verifier should take care of resolving all exception classes early |
| 231 | LOG(WARNING) << "Unresolved exception class when finding catch block: " |
Ian Rogers | 9e8f45e | 2013-07-31 10:58:53 -0700 | [diff] [blame] | 232 | << mh.GetTypeDescriptorFromTypeIdx(iter_type_idx); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 233 | } else if (iter_exception_type->IsAssignableFrom(exception_type)) { |
Ian Rogers | 9e8f45e | 2013-07-31 10:58:53 -0700 | [diff] [blame] | 234 | found_dex_pc = it.GetHandlerAddress(); |
| 235 | break; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 236 | } |
| 237 | } |
Ian Rogers | 9e8f45e | 2013-07-31 10:58:53 -0700 | [diff] [blame] | 238 | if (found_dex_pc != DexFile::kDexNoIndex) { |
| 239 | const Instruction* first_catch_instr = |
| 240 | Instruction::At(&mh.GetCodeItem()->insns_[found_dex_pc]); |
| 241 | *has_no_move_exception = (first_catch_instr->Opcode() != Instruction::MOVE_EXCEPTION); |
| 242 | } |
| 243 | return found_dex_pc; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 246 | void ArtMethod::Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result, |
| 247 | char result_type) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 248 | if (kIsDebugBuild) { |
| 249 | self->AssertThreadSuspensionIsAllowable(); |
| 250 | CHECK_EQ(kRunnable, self->GetState()); |
| 251 | } |
| 252 | |
| 253 | // Push a transition back into managed code onto the linked list in thread. |
| 254 | ManagedStack fragment; |
| 255 | self->PushManagedStackFragment(&fragment); |
| 256 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 257 | Runtime* runtime = Runtime::Current(); |
Jeff Hao | 74180ca | 2013-03-27 15:29:11 -0700 | [diff] [blame] | 258 | // Call the invoke stub, passing everything as arguments. |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 259 | if (UNLIKELY(!runtime->IsStarted())) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 260 | LOG(INFO) << "Not invoking " << PrettyMethod(this) << " for a runtime that isn't started"; |
| 261 | if (result != NULL) { |
| 262 | result->SetJ(0); |
| 263 | } |
| 264 | } else { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 265 | const bool kLogInvocationStartAndReturn = false; |
Jeff Hao | aa4a793 | 2013-05-13 11:28:27 -0700 | [diff] [blame] | 266 | if (GetEntryPointFromCompiledCode() != NULL) { |
Jeff Hao | 790ad90 | 2013-05-22 15:02:08 -0700 | [diff] [blame] | 267 | if (kLogInvocationStartAndReturn) { |
| 268 | LOG(INFO) << StringPrintf("Invoking '%s' code=%p", PrettyMethod(this).c_str(), GetEntryPointFromCompiledCode()); |
| 269 | } |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 270 | #ifdef ART_USE_PORTABLE_COMPILER |
Jeff Hao | 790ad90 | 2013-05-22 15:02:08 -0700 | [diff] [blame] | 271 | (*art_portable_invoke_stub)(this, args, args_size, self, result, result_type); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 272 | #else |
Jeff Hao | 790ad90 | 2013-05-22 15:02:08 -0700 | [diff] [blame] | 273 | (*art_quick_invoke_stub)(this, args, args_size, self, result, result_type); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 274 | #endif |
Jeff Hao | 790ad90 | 2013-05-22 15:02:08 -0700 | [diff] [blame] | 275 | if (UNLIKELY(reinterpret_cast<int32_t>(self->GetException(NULL)) == -1)) { |
| 276 | // Unusual case where we were running LLVM generated code and an |
| 277 | // exception was thrown to force the activations to be removed from the |
| 278 | // stack. Continue execution in the interpreter. |
| 279 | self->ClearException(); |
| 280 | ShadowFrame* shadow_frame = self->GetAndClearDeoptimizationShadowFrame(result); |
| 281 | self->SetTopOfStack(NULL, 0); |
| 282 | self->SetTopOfShadowStack(shadow_frame); |
| 283 | interpreter::EnterInterpreterFromDeoptimize(self, shadow_frame, result); |
| 284 | } |
| 285 | if (kLogInvocationStartAndReturn) { |
| 286 | LOG(INFO) << StringPrintf("Returned '%s' code=%p", PrettyMethod(this).c_str(), GetEntryPointFromCompiledCode()); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 287 | } |
| 288 | } else { |
| 289 | LOG(INFO) << "Not invoking '" << PrettyMethod(this) |
Jeff Hao | aa4a793 | 2013-05-13 11:28:27 -0700 | [diff] [blame] | 290 | << "' code=" << reinterpret_cast<const void*>(GetEntryPointFromCompiledCode()); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 291 | if (result != NULL) { |
| 292 | result->SetJ(0); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | // Pop transition. |
| 298 | self->PopManagedStackFragment(fragment); |
| 299 | } |
| 300 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 301 | bool ArtMethod::IsRegistered() const { |
| 302 | void* native_method = GetFieldPtr<void*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, native_method_), false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 303 | CHECK(native_method != NULL); |
Jeff Hao | 79fe539 | 2013-04-24 18:41:58 -0700 | [diff] [blame] | 304 | void* jni_stub = GetJniDlsymLookupStub(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 305 | return native_method != jni_stub; |
| 306 | } |
| 307 | |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 308 | extern "C" void art_work_around_app_jni_bugs(JNIEnv*, jobject); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 309 | void ArtMethod::RegisterNative(Thread* self, const void* native_method) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 310 | DCHECK(Thread::Current() == self); |
| 311 | CHECK(IsNative()) << PrettyMethod(this); |
| 312 | CHECK(native_method != NULL) << PrettyMethod(this); |
| 313 | if (!self->GetJniEnv()->vm->work_around_app_jni_bugs) { |
| 314 | SetNativeMethod(native_method); |
| 315 | } else { |
| 316 | // We've been asked to associate this method with the given native method but are working |
| 317 | // around JNI bugs, that include not giving Object** SIRT references to native methods. Direct |
| 318 | // the native method to runtime support and store the target somewhere runtime support will |
| 319 | // find it. |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 320 | #if defined(__i386__) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 321 | UNIMPLEMENTED(FATAL); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 322 | #else |
| 323 | SetNativeMethod(reinterpret_cast<void*>(art_work_around_app_jni_bugs)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 324 | #endif |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 325 | SetFieldPtr<const uint8_t*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, gc_map_), |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 326 | reinterpret_cast<const uint8_t*>(native_method), false); |
| 327 | } |
| 328 | } |
| 329 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 330 | void ArtMethod::UnregisterNative(Thread* self) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 331 | CHECK(IsNative()) << PrettyMethod(this); |
| 332 | // restore stub to lookup native pointer via dlsym |
Jeff Hao | 79fe539 | 2013-04-24 18:41:58 -0700 | [diff] [blame] | 333 | RegisterNative(self, GetJniDlsymLookupStub()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 334 | } |
| 335 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 336 | void ArtMethod::SetNativeMethod(const void* native_method) { |
| 337 | SetFieldPtr<const void*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, native_method_), |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 338 | native_method, false); |
| 339 | } |
| 340 | |
| 341 | } // namespace mirror |
| 342 | } // namespace art |