blob: ce1cf23c2047bdc0ce4e1bab31c94a93bfdc18bb [file] [log] [blame]
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001/*
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 Carlstromea46f952013-07-30 01:26:50 -070017#include "art_method.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080018
Andreas Gampe479b1de2016-07-19 18:27:17 -070019#include <cstddef>
20
Ian Rogerse63db272014-07-15 15:36:11 -070021#include "arch/context.h"
Ian Rogers62f05122014-03-21 11:21:29 -070022#include "art_field-inl.h"
Brian Carlstromea46f952013-07-30 01:26:50 -070023#include "art_method-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080024#include "base/stringpiece.h"
Hiroshi Yamauchi00370822015-08-18 14:47:25 -070025#include "class_linker-inl.h"
Andreas Gampe2a5c4682015-08-14 08:22:54 -070026#include "debugger.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070027#include "dex_file-inl.h"
David Sehr9323e6e2016-09-13 08:58:35 -070028#include "dex_file_annotations.h"
Ian Rogersc449aa82013-07-29 14:35:46 -070029#include "dex_instruction.h"
Ian Rogers6f3dbba2014-10-14 17:41:57 -070030#include "entrypoints/runtime_asm_entrypoints.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070031#include "gc/accounting/card_table-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032#include "interpreter/interpreter.h"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080033#include "jit/jit.h"
34#include "jit/jit_code_cache.h"
Nicolas Geoffray5550ca82015-08-21 18:38:30 +010035#include "jit/profiling_info.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080036#include "jni_internal.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070037#include "mirror/class-inl.h"
Alex Lighta01de592016-11-15 10:43:06 -080038#include "mirror/class_ext.h"
Neil Fuller0e844392016-09-08 13:43:31 +010039#include "mirror/executable.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070040#include "mirror/object_array-inl.h"
41#include "mirror/object-inl.h"
42#include "mirror/string.h"
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +000043#include "oat_file-inl.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070044#include "scoped_thread_state_change-inl.h"
Ian Rogers62f05122014-03-21 11:21:29 -070045#include "well_known_classes.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080046
47namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080048
Ian Rogers0177e532014-02-11 16:30:46 -080049extern "C" void art_quick_invoke_stub(ArtMethod*, uint32_t*, uint32_t, Thread*, JValue*,
50 const char*);
Ian Rogers936b37f2014-02-14 00:52:24 -080051extern "C" void art_quick_invoke_static_stub(ArtMethod*, uint32_t*, uint32_t, Thread*, JValue*,
52 const char*);
Jeff Hao5d917302013-02-27 17:57:33 -080053
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070054ArtMethod* ArtMethod::FromReflectedMethod(const ScopedObjectAccessAlreadyRunnable& soa,
55 jobject jlr_method) {
Mathieu Chartier0795f232016-09-27 18:43:30 -070056 ObjPtr<mirror::Executable> executable = soa.Decode<mirror::Executable>(jlr_method);
Neil Fuller0e844392016-09-08 13:43:31 +010057 DCHECK(executable != nullptr);
58 return executable->GetArtMethod();
Ian Rogers62f05122014-03-21 11:21:29 -070059}
60
Alex Lighta01de592016-11-15 10:43:06 -080061mirror::DexCache* ArtMethod::GetObsoleteDexCache() {
62 DCHECK(!Runtime::Current()->IsAotCompiler()) << PrettyMethod();
63 DCHECK(IsObsolete());
64 ObjPtr<mirror::ClassExt> ext(GetDeclaringClass()->GetExtData());
65 CHECK(!ext.IsNull());
66 ObjPtr<mirror::PointerArray> obsolete_methods(ext->GetObsoleteMethods());
67 CHECK(!obsolete_methods.IsNull());
68 DCHECK(ext->GetObsoleteDexCaches() != nullptr);
69 int32_t len = obsolete_methods->GetLength();
70 DCHECK_EQ(len, ext->GetObsoleteDexCaches()->GetLength());
Alex Light0b772572016-12-02 17:27:31 -080071 // Using kRuntimePointerSize (instead of using the image's pointer size) is fine since images
72 // should never have obsolete methods in them so they should always be the same.
Alex Lighta01de592016-11-15 10:43:06 -080073 PointerSize pointer_size = kRuntimePointerSize;
74 DCHECK_EQ(kRuntimePointerSize, Runtime::Current()->GetClassLinker()->GetImagePointerSize());
75 for (int32_t i = 0; i < len; i++) {
76 if (this == obsolete_methods->GetElementPtrSize<ArtMethod*>(i, pointer_size)) {
77 return ext->GetObsoleteDexCaches()->Get(i);
78 }
79 }
80 LOG(FATAL) << "This method does not appear in the obsolete map of its class!";
81 UNREACHABLE();
82}
83
Ian Rogers6b14d552014-10-28 21:50:58 -070084mirror::String* ArtMethod::GetNameAsString(Thread* self) {
Mathieu Chartiere401d142015-04-22 13:56:20 -070085 CHECK(!IsProxyMethod());
Ian Rogers6b14d552014-10-28 21:50:58 -070086 StackHandleScope<1> hs(self);
Mathieu Chartiere401d142015-04-22 13:56:20 -070087 Handle<mirror::DexCache> dex_cache(hs.NewHandle(GetDexCache()));
88 auto* dex_file = dex_cache->GetDexFile();
89 uint32_t dex_method_idx = GetDexMethodIndex();
90 const DexFile::MethodId& method_id = dex_file->GetMethodId(dex_method_idx);
Ian Rogers6b14d552014-10-28 21:50:58 -070091 return Runtime::Current()->GetClassLinker()->ResolveString(*dex_file, method_id.name_idx_,
92 dex_cache);
93}
94
Alex Light9139e002015-10-09 15:59:48 -070095void ArtMethod::ThrowInvocationTimeError() {
96 DCHECK(!IsInvokable());
97 // NOTE: IsDefaultConflicting must be first since the actual method might or might not be abstract
98 // due to the way we select it.
99 if (IsDefaultConflicting()) {
100 ThrowIncompatibleClassChangeErrorForMethodConflict(this);
101 } else {
102 DCHECK(IsAbstract());
103 ThrowAbstractMethodError(this);
104 }
105}
106
Ian Rogersef7d42f2014-01-06 12:55:46 -0800107InvokeType ArtMethod::GetInvokeType() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800108 // TODO: kSuper?
Nicolas Geoffray3aaf9642016-06-07 14:14:37 +0000109 if (IsStatic()) {
Nicolas Geoffray12abcbd2016-06-06 15:51:58 +0000110 return kStatic;
Nicolas Geoffray3aaf9642016-06-07 14:14:37 +0000111 } else if (GetDeclaringClass()->IsInterface()) {
112 return kInterface;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800113 } else if (IsDirect()) {
114 return kDirect;
115 } else {
116 return kVirtual;
117 }
118}
119
Brian Carlstromea46f952013-07-30 01:26:50 -0700120size_t ArtMethod::NumArgRegisters(const StringPiece& shorty) {
Ian Rogers6b604a12014-09-25 15:35:37 -0700121 CHECK_LE(1U, shorty.length());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800122 uint32_t num_registers = 0;
Ian Rogers6b604a12014-09-25 15:35:37 -0700123 for (size_t i = 1; i < shorty.length(); ++i) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800124 char ch = shorty[i];
125 if (ch == 'D' || ch == 'J') {
126 num_registers += 2;
127 } else {
128 num_registers += 1;
129 }
130 }
131 return num_registers;
132}
133
Alex Light6c8467f2015-11-20 15:03:26 -0800134bool ArtMethod::HasSameNameAndSignature(ArtMethod* other) {
Mathieu Chartier268764d2016-09-13 12:09:38 -0700135 ScopedAssertNoThreadSuspension ants("HasSameNameAndSignature");
Alex Light6c8467f2015-11-20 15:03:26 -0800136 const DexFile* dex_file = GetDexFile();
137 const DexFile::MethodId& mid = dex_file->GetMethodId(GetDexMethodIndex());
138 if (GetDexCache() == other->GetDexCache()) {
139 const DexFile::MethodId& mid2 = dex_file->GetMethodId(other->GetDexMethodIndex());
Ian Rogersf2247512014-12-02 16:17:08 -0800140 return mid.name_idx_ == mid2.name_idx_ && mid.proto_idx_ == mid2.proto_idx_;
141 }
Alex Light6c8467f2015-11-20 15:03:26 -0800142 const DexFile* dex_file2 = other->GetDexFile();
143 const DexFile::MethodId& mid2 = dex_file2->GetMethodId(other->GetDexMethodIndex());
Ian Rogersf2247512014-12-02 16:17:08 -0800144 if (!DexFileStringEquals(dex_file, mid.name_idx_, dex_file2, mid2.name_idx_)) {
145 return false; // Name mismatch.
146 }
147 return dex_file->GetMethodSignature(mid) == dex_file2->GetMethodSignature(mid2);
148}
149
Andreas Gampe542451c2016-07-26 09:02:02 -0700150ArtMethod* ArtMethod::FindOverriddenMethod(PointerSize pointer_size) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800151 if (IsStatic()) {
Ian Rogersf2247512014-12-02 16:17:08 -0800152 return nullptr;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800153 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700154 mirror::Class* declaring_class = GetDeclaringClass();
155 mirror::Class* super_class = declaring_class->GetSuperClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800156 uint16_t method_index = GetMethodIndex();
Ian Rogersf2247512014-12-02 16:17:08 -0800157 ArtMethod* result = nullptr;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800158 // Did this method override a super class method? If so load the result from the super class'
159 // vtable
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700160 if (super_class->HasVTable() && method_index < super_class->GetVTableLength()) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700161 result = super_class->GetVTableEntry(method_index, pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800162 } else {
163 // Method didn't override superclass method so search interfaces
164 if (IsProxyMethod()) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100165 result = mirror::DexCache::GetElementPtrSize(GetDexCacheResolvedMethods(pointer_size),
166 GetDexMethodIndex(),
167 pointer_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800168 CHECK_EQ(result,
169 Runtime::Current()->GetClassLinker()->FindMethodForProxy(GetDeclaringClass(), this));
170 } else {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700171 mirror::IfTable* iftable = GetDeclaringClass()->GetIfTable();
Ian Rogersf2247512014-12-02 16:17:08 -0800172 for (size_t i = 0; i < iftable->Count() && result == nullptr; i++) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700173 mirror::Class* interface = iftable->GetInterface(i);
Alex Light51a64d52015-12-17 13:55:59 -0800174 for (ArtMethod& interface_method : interface->GetVirtualMethods(pointer_size)) {
175 if (HasSameNameAndSignature(interface_method.GetInterfaceMethodIfProxy(pointer_size))) {
176 result = &interface_method;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800177 break;
178 }
179 }
180 }
181 }
182 }
Alex Light6c8467f2015-11-20 15:03:26 -0800183 DCHECK(result == nullptr ||
Alex Light51a64d52015-12-17 13:55:59 -0800184 GetInterfaceMethodIfProxy(pointer_size)->HasSameNameAndSignature(
185 result->GetInterfaceMethodIfProxy(pointer_size)));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800186 return result;
187}
188
Ian Rogerse0a02da2014-12-02 14:10:53 -0800189uint32_t ArtMethod::FindDexMethodIndexInOtherDexFile(const DexFile& other_dexfile,
190 uint32_t name_and_signature_idx) {
191 const DexFile* dexfile = GetDexFile();
192 const uint32_t dex_method_idx = GetDexMethodIndex();
193 const DexFile::MethodId& mid = dexfile->GetMethodId(dex_method_idx);
194 const DexFile::MethodId& name_and_sig_mid = other_dexfile.GetMethodId(name_and_signature_idx);
195 DCHECK_STREQ(dexfile->GetMethodName(mid), other_dexfile.GetMethodName(name_and_sig_mid));
196 DCHECK_EQ(dexfile->GetMethodSignature(mid), other_dexfile.GetMethodSignature(name_and_sig_mid));
197 if (dexfile == &other_dexfile) {
198 return dex_method_idx;
199 }
200 const char* mid_declaring_class_descriptor = dexfile->StringByTypeIdx(mid.class_idx_);
Mathieu Chartier9507fa22015-10-29 15:08:57 -0700201 const DexFile::TypeId* other_type_id = other_dexfile.FindTypeId(mid_declaring_class_descriptor);
202 if (other_type_id != nullptr) {
203 const DexFile::MethodId* other_mid = other_dexfile.FindMethodId(
204 *other_type_id, other_dexfile.GetStringId(name_and_sig_mid.name_idx_),
205 other_dexfile.GetProtoId(name_and_sig_mid.proto_idx_));
206 if (other_mid != nullptr) {
207 return other_dexfile.GetIndexForMethodId(*other_mid);
Ian Rogerse0a02da2014-12-02 14:10:53 -0800208 }
209 }
210 return DexFile::kDexNoIndex;
211}
212
Mathieu Chartiere401d142015-04-22 13:56:20 -0700213uint32_t ArtMethod::FindCatchBlock(Handle<mirror::Class> exception_type,
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700214 uint32_t dex_pc, bool* has_no_move_exception) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700215 const DexFile::CodeItem* code_item = GetCodeItem();
Jeff Haoaa961912014-04-22 13:54:32 -0700216 // Set aside the exception while we resolve its type.
217 Thread* self = Thread::Current();
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700218 StackHandleScope<1> hs(self);
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000219 Handle<mirror::Throwable> exception(hs.NewHandle(self->GetException()));
Jeff Haoaa961912014-04-22 13:54:32 -0700220 self->ClearException();
Ian Rogers9e8f45e2013-07-31 10:58:53 -0700221 // Default to handler not found.
222 uint32_t found_dex_pc = DexFile::kDexNoIndex;
223 // Iterate over the catch handlers associated with dex_pc.
Andreas Gampe542451c2016-07-26 09:02:02 -0700224 PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800225 for (CatchHandlerIterator it(*code_item, dex_pc); it.HasNext(); it.Next()) {
Andreas Gampea5b09a62016-11-17 15:21:22 -0800226 dex::TypeIndex iter_type_idx = it.GetHandlerTypeIndex();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800227 // Catch all case
Andreas Gampea5b09a62016-11-17 15:21:22 -0800228 if (!iter_type_idx.IsValid()) {
Ian Rogers9e8f45e2013-07-31 10:58:53 -0700229 found_dex_pc = it.GetHandlerAddress();
230 break;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800231 }
232 // Does this catch exception type apply?
Vladimir Marko05792b92015-08-03 11:56:49 +0100233 mirror::Class* iter_exception_type = GetClassFromTypeIndex(iter_type_idx,
234 true /* resolve */,
235 pointer_size);
Ian Rogers822266b2014-05-29 16:55:06 -0700236 if (UNLIKELY(iter_exception_type == nullptr)) {
237 // Now have a NoClassDefFoundError as exception. Ignore in case the exception class was
238 // removed by a pro-guard like tool.
Andreas Gampe72b3e432014-05-13 21:42:05 -0700239 // Note: this is not RI behavior. RI would have failed when loading the class.
Ian Rogers822266b2014-05-29 16:55:06 -0700240 self->ClearException();
241 // Delete any long jump context as this routine is called during a stack walk which will
242 // release its in use context at the end.
243 delete self->GetLongJumpContext();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800244 LOG(WARNING) << "Unresolved exception class when finding catch block: "
Mathieu Chartiere401d142015-04-22 13:56:20 -0700245 << DescriptorToDot(GetTypeDescriptorFromTypeIdx(iter_type_idx));
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700246 } else if (iter_exception_type->IsAssignableFrom(exception_type.Get())) {
Ian Rogers9e8f45e2013-07-31 10:58:53 -0700247 found_dex_pc = it.GetHandlerAddress();
248 break;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800249 }
250 }
Ian Rogers9e8f45e2013-07-31 10:58:53 -0700251 if (found_dex_pc != DexFile::kDexNoIndex) {
252 const Instruction* first_catch_instr =
Jeff Haoaa961912014-04-22 13:54:32 -0700253 Instruction::At(&code_item->insns_[found_dex_pc]);
Ian Rogers9e8f45e2013-07-31 10:58:53 -0700254 *has_no_move_exception = (first_catch_instr->Opcode() != Instruction::MOVE_EXCEPTION);
255 }
Jeff Haoaa961912014-04-22 13:54:32 -0700256 // Put the exception back.
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700257 if (exception.Get() != nullptr) {
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000258 self->SetException(exception.Get());
Jeff Haoaa961912014-04-22 13:54:32 -0700259 }
Ian Rogers9e8f45e2013-07-31 10:58:53 -0700260 return found_dex_pc;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800261}
262
Brian Carlstromea46f952013-07-30 01:26:50 -0700263void ArtMethod::Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* result,
Ian Rogers0177e532014-02-11 16:30:46 -0800264 const char* shorty) {
Dave Allison648d7112014-07-25 16:15:27 -0700265 if (UNLIKELY(__builtin_frame_address(0) < self->GetStackEnd())) {
266 ThrowStackOverflowError(self);
267 return;
268 }
269
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800270 if (kIsDebugBuild) {
271 self->AssertThreadSuspensionIsAllowable();
272 CHECK_EQ(kRunnable, self->GetState());
Andreas Gampe542451c2016-07-26 09:02:02 -0700273 CHECK_STREQ(GetInterfaceMethodIfProxy(kRuntimePointerSize)->GetShorty(), shorty);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800274 }
275
276 // Push a transition back into managed code onto the linked list in thread.
277 ManagedStack fragment;
278 self->PushManagedStackFragment(&fragment);
279
Ian Rogers62d6c772013-02-27 08:32:07 -0800280 Runtime* runtime = Runtime::Current();
Jeff Hao74180ca2013-03-27 15:29:11 -0700281 // Call the invoke stub, passing everything as arguments.
Daniel Mihalyieb076692014-08-22 17:33:31 +0200282 // If the runtime is not yet started or it is required by the debugger, then perform the
Aart Bik01223202016-05-05 15:10:42 -0700283 // Invocation by the interpreter, explicitly forcing interpretation over JIT to prevent
284 // cycling around the various JIT/Interpreter methods that handle method invocation.
Daniel Mihalyieb076692014-08-22 17:33:31 +0200285 if (UNLIKELY(!runtime->IsStarted() || Dbg::IsForcedInterpreterNeededForCalling(self, this))) {
Ian Rogers5d27faf2014-05-02 17:17:18 -0700286 if (IsStatic()) {
Aart Bik01223202016-05-05 15:10:42 -0700287 art::interpreter::EnterInterpreterFromInvoke(
288 self, this, nullptr, args, result, /*stay_in_interpreter*/ true);
Ian Rogers5d27faf2014-05-02 17:17:18 -0700289 } else {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700290 mirror::Object* receiver =
291 reinterpret_cast<StackReference<mirror::Object>*>(&args[0])->AsMirrorPtr();
Aart Bik01223202016-05-05 15:10:42 -0700292 art::interpreter::EnterInterpreterFromInvoke(
293 self, this, receiver, args + 1, result, /*stay_in_interpreter*/ true);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800294 }
295 } else {
Andreas Gampe542451c2016-07-26 09:02:02 -0700296 DCHECK_EQ(runtime->GetClassLinker()->GetImagePointerSize(), kRuntimePointerSize);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700297
298 constexpr bool kLogInvocationStartAndReturn = false;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800299 bool have_quick_code = GetEntryPointFromQuickCompiledCode() != nullptr;
Elliott Hughes956af0f2014-12-11 14:34:28 -0800300 if (LIKELY(have_quick_code)) {
Jeff Hao790ad902013-05-22 15:02:08 -0700301 if (kLogInvocationStartAndReturn) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700302 LOG(INFO) << StringPrintf(
David Sehr709b0702016-10-13 09:12:37 -0700303 "Invoking '%s' quick code=%p static=%d", PrettyMethod().c_str(),
Mathieu Chartiere401d142015-04-22 13:56:20 -0700304 GetEntryPointFromQuickCompiledCode(), static_cast<int>(IsStatic() ? 1 : 0));
Jeff Hao790ad902013-05-22 15:02:08 -0700305 }
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700306
Elliott Hughes956af0f2014-12-11 14:34:28 -0800307 // Ensure that we won't be accidentally calling quick compiled code when -Xint.
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800308 if (kIsDebugBuild && runtime->GetInstrumentation()->IsForcedInterpretOnly()) {
Calin Juravleffc87072016-04-20 14:22:09 +0100309 CHECK(!runtime->UseJitCompilation());
Vladimir Marko97d7e1c2016-10-04 14:44:28 +0100310 const void* oat_quick_code = (IsNative() || !IsInvokable() || IsProxyMethod())
311 ? nullptr
312 : GetOatMethodQuickCode(runtime->GetClassLinker()->GetImagePointerSize());
Nicolas Geoffray6bc43742015-10-12 18:11:10 +0100313 CHECK(oat_quick_code == nullptr || oat_quick_code != GetEntryPointFromQuickCompiledCode())
David Sehr709b0702016-10-13 09:12:37 -0700314 << "Don't call compiled code when -Xint " << PrettyMethod();
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700315 }
316
Elliott Hughes956af0f2014-12-11 14:34:28 -0800317 if (!IsStatic()) {
Ian Rogers0177e532014-02-11 16:30:46 -0800318 (*art_quick_invoke_stub)(this, args, args_size, self, result, shorty);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800319 } else {
Elliott Hughes956af0f2014-12-11 14:34:28 -0800320 (*art_quick_invoke_static_stub)(this, args, args_size, self, result, shorty);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800321 }
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000322 if (UNLIKELY(self->GetException() == Thread::GetDeoptimizationException())) {
Sebastien Hertzfd3077e2014-04-23 10:32:43 +0200323 // Unusual case where we were running generated code and an
Jeff Hao790ad902013-05-22 15:02:08 -0700324 // exception was thrown to force the activations to be removed from the
325 // stack. Continue execution in the interpreter.
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000326 self->DeoptimizeWithDeoptimizationException(result);
Jeff Hao790ad902013-05-22 15:02:08 -0700327 }
328 if (kLogInvocationStartAndReturn) {
David Sehr709b0702016-10-13 09:12:37 -0700329 LOG(INFO) << StringPrintf("Returned '%s' quick code=%p", PrettyMethod().c_str(),
Elliott Hughes956af0f2014-12-11 14:34:28 -0800330 GetEntryPointFromQuickCompiledCode());
Jeff Hao5d917302013-02-27 17:57:33 -0800331 }
332 } else {
David Sehr709b0702016-10-13 09:12:37 -0700333 LOG(INFO) << "Not invoking '" << PrettyMethod() << "' code=null";
Ian Rogersf2247512014-12-02 16:17:08 -0800334 if (result != nullptr) {
Jeff Hao5d917302013-02-27 17:57:33 -0800335 result->SetJ(0);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800336 }
337 }
338 }
339
340 // Pop transition.
341 self->PopManagedStackFragment(fragment);
342}
343
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700344void ArtMethod::RegisterNative(const void* native_method, bool is_fast) {
David Sehr709b0702016-10-13 09:12:37 -0700345 CHECK(IsNative()) << PrettyMethod();
346 CHECK(!IsFastNative()) << PrettyMethod();
347 CHECK(native_method != nullptr) << PrettyMethod();
Ian Rogers987560f2014-04-22 11:42:59 -0700348 if (is_fast) {
349 SetAccessFlags(GetAccessFlags() | kAccFastNative);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800350 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800351 SetEntryPointFromJni(native_method);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800352}
353
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700354void ArtMethod::UnregisterNative() {
David Sehr709b0702016-10-13 09:12:37 -0700355 CHECK(IsNative() && !IsFastNative()) << PrettyMethod();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800356 // restore stub to lookup native pointer via dlsym
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700357 RegisterNative(GetJniDlsymLookupStub(), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800358}
359
Alex Light9139e002015-10-09 15:59:48 -0700360bool ArtMethod::IsOverridableByDefaultMethod() {
361 return GetDeclaringClass()->IsInterface();
362}
363
Igor Murashkin9d4b6da2016-07-29 09:51:58 -0700364bool ArtMethod::IsAnnotatedWithFastNative() {
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700365 return IsAnnotatedWith(WellKnownClasses::dalvik_annotation_optimization_FastNative,
366 DexFile::kDexVisibilityBuild);
367}
368
369bool ArtMethod::IsAnnotatedWithCriticalNative() {
370 return IsAnnotatedWith(WellKnownClasses::dalvik_annotation_optimization_CriticalNative,
371 DexFile::kDexVisibilityBuild);
372}
373
374bool ArtMethod::IsAnnotatedWith(jclass klass, uint32_t visibility) {
Igor Murashkin9d4b6da2016-07-29 09:51:58 -0700375 Thread* self = Thread::Current();
376 ScopedObjectAccess soa(self);
377 StackHandleScope<1> shs(self);
378
Mathieu Chartier0795f232016-09-27 18:43:30 -0700379 ObjPtr<mirror::Class> annotation = soa.Decode<mirror::Class>(klass);
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700380 DCHECK(annotation->IsAnnotation());
381 Handle<mirror::Class> annotation_handle(shs.NewHandle(annotation));
Igor Murashkin9d4b6da2016-07-29 09:51:58 -0700382
383 // Note: Resolves any method annotations' classes as a side-effect.
384 // -- This seems allowed by the spec since it says we can preload any classes
385 // referenced by another classes's constant pool table.
David Sehr9323e6e2016-09-13 08:58:35 -0700386 return annotations::IsMethodAnnotationPresent(this, annotation_handle, visibility);
Igor Murashkin9d4b6da2016-07-29 09:51:58 -0700387}
388
Vladimir Marko97d7e1c2016-10-04 14:44:28 +0100389static uint32_t GetOatMethodIndexFromMethodIndex(const DexFile& dex_file,
390 uint16_t class_def_idx,
391 uint32_t method_idx) {
392 const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_idx);
393 const uint8_t* class_data = dex_file.GetClassData(class_def);
394 CHECK(class_data != nullptr);
395 ClassDataItemIterator it(dex_file, class_data);
396 // Skip fields
397 while (it.HasNextStaticField()) {
398 it.Next();
399 }
400 while (it.HasNextInstanceField()) {
401 it.Next();
402 }
403 // Process methods
404 size_t class_def_method_index = 0;
405 while (it.HasNextDirectMethod()) {
406 if (it.GetMemberIndex() == method_idx) {
407 return class_def_method_index;
408 }
409 class_def_method_index++;
410 it.Next();
411 }
412 while (it.HasNextVirtualMethod()) {
413 if (it.GetMemberIndex() == method_idx) {
414 return class_def_method_index;
415 }
416 class_def_method_index++;
417 it.Next();
418 }
419 DCHECK(!it.HasNext());
420 LOG(FATAL) << "Failed to find method index " << method_idx << " in " << dex_file.GetLocation();
421 UNREACHABLE();
422}
423
424static const OatFile::OatMethod FindOatMethodFor(ArtMethod* method,
425 PointerSize pointer_size,
426 bool* found)
427 REQUIRES_SHARED(Locks::mutator_lock_) {
428 // Although we overwrite the trampoline of non-static methods, we may get here via the resolution
429 // method for direct methods (or virtual methods made direct).
430 mirror::Class* declaring_class = method->GetDeclaringClass();
431 size_t oat_method_index;
432 if (method->IsStatic() || method->IsDirect()) {
433 // Simple case where the oat method index was stashed at load time.
434 oat_method_index = method->GetMethodIndex();
435 } else {
436 // Compute the oat_method_index by search for its position in the declared virtual methods.
437 oat_method_index = declaring_class->NumDirectMethods();
438 bool found_virtual = false;
439 for (ArtMethod& art_method : declaring_class->GetVirtualMethods(pointer_size)) {
440 // Check method index instead of identity in case of duplicate method definitions.
441 if (method->GetDexMethodIndex() == art_method.GetDexMethodIndex()) {
442 found_virtual = true;
443 break;
444 }
445 oat_method_index++;
446 }
447 CHECK(found_virtual) << "Didn't find oat method index for virtual method: "
David Sehr709b0702016-10-13 09:12:37 -0700448 << method->PrettyMethod();
Vladimir Marko97d7e1c2016-10-04 14:44:28 +0100449 }
450 DCHECK_EQ(oat_method_index,
451 GetOatMethodIndexFromMethodIndex(*declaring_class->GetDexCache()->GetDexFile(),
452 method->GetDeclaringClass()->GetDexClassDefIndex(),
453 method->GetDexMethodIndex()));
454 OatFile::OatClass oat_class = OatFile::FindOatClass(*declaring_class->GetDexCache()->GetDexFile(),
455 declaring_class->GetDexClassDefIndex(),
456 found);
457 if (!(*found)) {
458 return OatFile::OatMethod::Invalid();
459 }
460 return oat_class.GetOatMethod(oat_method_index);
461}
462
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700463bool ArtMethod::EqualParameters(Handle<mirror::ObjectArray<mirror::Class>> params) {
464 auto* dex_cache = GetDexCache();
465 auto* dex_file = dex_cache->GetDexFile();
466 const auto& method_id = dex_file->GetMethodId(GetDexMethodIndex());
467 const auto& proto_id = dex_file->GetMethodPrototype(method_id);
468 const DexFile::TypeList* proto_params = dex_file->GetProtoParameters(proto_id);
469 auto count = proto_params != nullptr ? proto_params->Size() : 0u;
470 auto param_len = params.Get() != nullptr ? params->GetLength() : 0u;
471 if (param_len != count) {
472 return false;
473 }
474 auto* cl = Runtime::Current()->GetClassLinker();
475 for (size_t i = 0; i < count; ++i) {
476 auto type_idx = proto_params->GetTypeItem(i).type_idx_;
477 auto* type = cl->ResolveType(type_idx, this);
478 if (type == nullptr) {
479 Thread::Current()->AssertPendingException();
480 return false;
481 }
482 if (type != params->GetWithoutChecks(i)) {
483 return false;
484 }
485 }
486 return true;
487}
488
Vladimir Marko97d7e1c2016-10-04 14:44:28 +0100489const uint8_t* ArtMethod::GetQuickenedInfo(PointerSize pointer_size) {
Nicolas Geoffray6bc43742015-10-12 18:11:10 +0100490 bool found = false;
Vladimir Marko97d7e1c2016-10-04 14:44:28 +0100491 OatFile::OatMethod oat_method = FindOatMethodFor(this, pointer_size, &found);
Nicolas Geoffray6bc43742015-10-12 18:11:10 +0100492 if (!found || (oat_method.GetQuickCode() != nullptr)) {
493 return nullptr;
494 }
Nicolas Geoffray4acefd32016-10-24 13:14:58 +0100495 if (kIsVdexEnabled) {
496 const OatQuickMethodHeader* header = oat_method.GetOatQuickMethodHeader();
497 // OatMethod without a header: no quickening table.
498 if (header == nullptr) {
499 return nullptr;
500 }
501 // The table is in the .vdex file.
502 const OatFile::OatDexFile* oat_dex_file = GetDexCache()->GetDexFile()->GetOatDexFile();
Mathieu Chartier1b868492016-11-16 16:22:37 -0800503 const OatFile* oat_file = oat_dex_file->GetOatFile();
504 if (oat_file == nullptr) {
505 return nullptr;
506 }
507 return oat_file->DexBegin() + header->vmap_table_offset_;
Nicolas Geoffray4acefd32016-10-24 13:14:58 +0100508 } else {
509 return oat_method.GetVmapTable();
510 }
Nicolas Geoffray6bc43742015-10-12 18:11:10 +0100511}
512
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +0100513const OatQuickMethodHeader* ArtMethod::GetOatQuickMethodHeader(uintptr_t pc) {
Nicolas Geoffray5a23d2e2015-11-03 18:58:57 +0000514 // Our callers should make sure they don't pass the instrumentation exit pc,
515 // as this method does not look at the side instrumentation stack.
516 DCHECK_NE(pc, reinterpret_cast<uintptr_t>(GetQuickInstrumentationExitPc()));
517
Nicolas Geoffray22cf3d32015-11-02 11:57:11 +0000518 if (IsRuntimeMethod()) {
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +0100519 return nullptr;
520 }
521
522 Runtime* runtime = Runtime::Current();
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100523 const void* existing_entry_point = GetEntryPointFromQuickCompiledCode();
David Sehr709b0702016-10-13 09:12:37 -0700524 CHECK(existing_entry_point != nullptr) << PrettyMethod() << "@" << this;
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100525 ClassLinker* class_linker = runtime->GetClassLinker();
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +0100526
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100527 if (class_linker->IsQuickGenericJniStub(existing_entry_point)) {
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +0100528 // The generic JNI does not have any method header.
529 return nullptr;
530 }
531
Nicolas Geoffray22cf3d32015-11-02 11:57:11 +0000532 if (existing_entry_point == GetQuickProxyInvokeHandler()) {
533 DCHECK(IsProxyMethod() && !IsConstructor());
534 // The proxy entry point does not have any method header.
535 return nullptr;
536 }
537
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100538 // Check whether the current entry point contains this pc.
539 if (!class_linker->IsQuickResolutionStub(existing_entry_point) &&
540 !class_linker->IsQuickToInterpreterBridge(existing_entry_point)) {
541 OatQuickMethodHeader* method_header =
542 OatQuickMethodHeader::FromEntryPoint(existing_entry_point);
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +0100543
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100544 if (method_header->Contains(pc)) {
545 return method_header;
546 }
547 }
548
549 // Check whether the pc is in the JIT code cache.
Vladimir Marko97d7e1c2016-10-04 14:44:28 +0100550 jit::Jit* jit = runtime->GetJit();
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100551 if (jit != nullptr) {
552 jit::JitCodeCache* code_cache = jit->GetCodeCache();
553 OatQuickMethodHeader* method_header = code_cache->LookupMethodHeader(pc, this);
554 if (method_header != nullptr) {
555 DCHECK(method_header->Contains(pc));
556 return method_header;
557 } else {
Nicolas Geoffray2a524bd2016-03-01 12:18:47 +0000558 DCHECK(!code_cache->ContainsPc(reinterpret_cast<const void*>(pc)))
David Sehr709b0702016-10-13 09:12:37 -0700559 << PrettyMethod()
Nicolas Geoffray2a524bd2016-03-01 12:18:47 +0000560 << ", pc=" << std::hex << pc
561 << ", entry_point=" << std::hex << reinterpret_cast<uintptr_t>(existing_entry_point)
562 << ", copy=" << std::boolalpha << IsCopied()
563 << ", proxy=" << std::boolalpha << IsProxyMethod();
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100564 }
565 }
566
567 // The code has to be in an oat file.
568 bool found;
Vladimir Marko97d7e1c2016-10-04 14:44:28 +0100569 OatFile::OatMethod oat_method =
570 FindOatMethodFor(this, class_linker->GetImagePointerSize(), &found);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100571 if (!found) {
Nicolas Geoffray49e43962015-10-28 16:16:16 +0000572 if (class_linker->IsQuickResolutionStub(existing_entry_point)) {
573 // We are running the generic jni stub, but the entry point of the method has not
574 // been updated yet.
Nicolas Geoffray703c2822015-10-30 12:23:16 +0000575 DCHECK_EQ(pc, 0u) << "Should be a downcall";
576 DCHECK(IsNative());
577 return nullptr;
578 }
579 if (existing_entry_point == GetQuickInstrumentationEntryPoint()) {
580 // We are running the generic jni stub, but the method is being instrumented.
581 DCHECK_EQ(pc, 0u) << "Should be a downcall";
Nicolas Geoffray49e43962015-10-28 16:16:16 +0000582 DCHECK(IsNative());
583 return nullptr;
584 }
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100585 // Only for unit tests.
586 // TODO(ngeoffray): Update these tests to pass the right pc?
587 return OatQuickMethodHeader::FromEntryPoint(existing_entry_point);
588 }
589 const void* oat_entry_point = oat_method.GetQuickCode();
590 if (oat_entry_point == nullptr || class_linker->IsQuickGenericJniStub(oat_entry_point)) {
David Sehr709b0702016-10-13 09:12:37 -0700591 DCHECK(IsNative()) << PrettyMethod();
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100592 return nullptr;
593 }
594
595 OatQuickMethodHeader* method_header = OatQuickMethodHeader::FromEntryPoint(oat_entry_point);
596 if (pc == 0) {
597 // This is a downcall, it can only happen for a native method.
598 DCHECK(IsNative());
599 return method_header;
600 }
601
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100602 DCHECK(method_header->Contains(pc))
David Sehr709b0702016-10-13 09:12:37 -0700603 << PrettyMethod()
Roland Levillain0b671c02016-08-19 12:02:34 +0100604 << " " << std::hex << pc << " " << oat_entry_point
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100605 << " " << (uintptr_t)(method_header->code_ + method_header->code_size_);
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +0100606 return method_header;
607}
608
Vladimir Marko97d7e1c2016-10-04 14:44:28 +0100609const void* ArtMethod::GetOatMethodQuickCode(PointerSize pointer_size) {
610 bool found;
611 OatFile::OatMethod oat_method = FindOatMethodFor(this, pointer_size, &found);
612 if (found) {
613 return oat_method.GetQuickCode();
614 }
615 return nullptr;
616}
617
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000618bool ArtMethod::HasAnyCompiledCode() {
Vladimir Marko97d7e1c2016-10-04 14:44:28 +0100619 if (IsNative() || !IsInvokable() || IsProxyMethod()) {
620 return false;
621 }
622
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000623 // Check whether the JIT has compiled it.
Vladimir Marko97d7e1c2016-10-04 14:44:28 +0100624 Runtime* runtime = Runtime::Current();
625 jit::Jit* jit = runtime->GetJit();
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000626 if (jit != nullptr && jit->GetCodeCache()->ContainsMethod(this)) {
627 return true;
628 }
629
630 // Check whether we have AOT code.
Vladimir Marko97d7e1c2016-10-04 14:44:28 +0100631 return GetOatMethodQuickCode(runtime->GetClassLinker()->GetImagePointerSize()) != nullptr;
Nicolas Geoffraya5891e82015-11-06 14:18:27 +0000632}
Nicolas Geoffray22cf3d32015-11-02 11:57:11 +0000633
Andreas Gampe542451c2016-07-26 09:02:02 -0700634void ArtMethod::CopyFrom(ArtMethod* src, PointerSize image_pointer_size) {
Nicolas Geoffray22cf3d32015-11-02 11:57:11 +0000635 memcpy(reinterpret_cast<void*>(this), reinterpret_cast<const void*>(src),
636 Size(image_pointer_size));
637 declaring_class_ = GcRoot<mirror::Class>(const_cast<ArtMethod*>(src)->GetDeclaringClass());
638
639 // If the entry point of the method we are copying from is from JIT code, we just
640 // put the entry point of the new method to interpreter. We could set the entry point
641 // to the JIT code, but this would require taking the JIT code cache lock to notify
642 // it, which we do not want at this level.
643 Runtime* runtime = Runtime::Current();
Calin Juravleffc87072016-04-20 14:22:09 +0100644 if (runtime->UseJitCompilation()) {
Nicolas Geoffray22cf3d32015-11-02 11:57:11 +0000645 if (runtime->GetJit()->GetCodeCache()->ContainsPc(GetEntryPointFromQuickCompiledCode())) {
646 SetEntryPointFromQuickCompiledCodePtrSize(GetQuickToInterpreterBridge(), image_pointer_size);
647 }
648 }
649 // Clear the profiling info for the same reasons as the JIT code.
650 if (!src->IsNative()) {
651 SetProfilingInfoPtrSize(nullptr, image_pointer_size);
652 }
653 // Clear hotness to let the JIT properly decide when to compile this method.
654 hotness_count_ = 0;
655}
656
Andreas Gampe542451c2016-07-26 09:02:02 -0700657bool ArtMethod::IsImagePointerSize(PointerSize pointer_size) {
Andreas Gampe479b1de2016-07-19 18:27:17 -0700658 // Hijack this function to get access to PtrSizedFieldsOffset.
659 //
660 // Ensure that PrtSizedFieldsOffset is correct. We rely here on usually having both 32-bit and
661 // 64-bit builds.
662 static_assert(std::is_standard_layout<ArtMethod>::value, "ArtMethod is not standard layout.");
Andreas Gampe542451c2016-07-26 09:02:02 -0700663 static_assert(
664 (sizeof(void*) != 4) ||
665 (offsetof(ArtMethod, ptr_sized_fields_) == PtrSizedFieldsOffset(PointerSize::k32)),
666 "Unexpected 32-bit class layout.");
667 static_assert(
668 (sizeof(void*) != 8) ||
669 (offsetof(ArtMethod, ptr_sized_fields_) == PtrSizedFieldsOffset(PointerSize::k64)),
670 "Unexpected 64-bit class layout.");
Andreas Gampe479b1de2016-07-19 18:27:17 -0700671
Andreas Gampe75f08852016-07-19 08:06:07 -0700672 Runtime* runtime = Runtime::Current();
673 if (runtime == nullptr) {
674 return true;
675 }
676 return runtime->GetClassLinker()->GetImagePointerSize() == pointer_size;
677}
678
David Sehr709b0702016-10-13 09:12:37 -0700679std::string ArtMethod::PrettyMethod(ArtMethod* m, bool with_signature) {
680 if (m == nullptr) {
681 return "null";
682 }
683 return m->PrettyMethod(with_signature);
684}
685
686std::string ArtMethod::PrettyMethod(bool with_signature) {
687 ArtMethod* m = this;
688 if (!m->IsRuntimeMethod()) {
689 m = m->GetInterfaceMethodIfProxy(Runtime::Current()->GetClassLinker()->GetImagePointerSize());
690 }
691 std::string result(PrettyDescriptor(m->GetDeclaringClassDescriptor()));
692 result += '.';
693 result += m->GetName();
694 if (UNLIKELY(m->IsFastNative())) {
695 result += "!";
696 }
697 if (with_signature) {
698 const Signature signature = m->GetSignature();
699 std::string sig_as_string(signature.ToString());
700 if (signature == Signature::NoSignature()) {
701 return result + sig_as_string;
702 }
703 result = PrettyReturnType(sig_as_string.c_str()) + " " + result +
704 PrettyArguments(sig_as_string.c_str());
705 }
706 return result;
707}
708
709std::string ArtMethod::JniShortName() {
710 std::string class_name(GetDeclaringClassDescriptor());
711 // Remove the leading 'L' and trailing ';'...
712 CHECK_EQ(class_name[0], 'L') << class_name;
713 CHECK_EQ(class_name[class_name.size() - 1], ';') << class_name;
714 class_name.erase(0, 1);
715 class_name.erase(class_name.size() - 1, 1);
716
717 std::string method_name(GetName());
718
719 std::string short_name;
720 short_name += "Java_";
721 short_name += MangleForJni(class_name);
722 short_name += "_";
723 short_name += MangleForJni(method_name);
724 return short_name;
725}
726
727std::string ArtMethod::JniLongName() {
728 std::string long_name;
729 long_name += JniShortName();
730 long_name += "__";
731
732 std::string signature(GetSignature().ToString());
733 signature.erase(0, 1);
734 signature.erase(signature.begin() + signature.find(')'), signature.end());
735
736 long_name += MangleForJni(signature);
737
738 return long_name;
739}
740
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800741} // namespace art