blob: fb9a09a95fd83d8c60161215aead183bb1b45471 [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#ifndef ART_RUNTIME_MIRROR_ART_METHOD_INL_H_
18#define ART_RUNTIME_MIRROR_ART_METHOD_INL_H_
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019
Brian Carlstromea46f952013-07-30 01:26:50 -070020#include "art_method.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080021
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080022#include "dex_file.h"
Ian Rogers7655f292013-07-29 11:07:13 -070023#include "entrypoints/entrypoint_utils.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070024#include "object_array.h"
Vladimir Marko96c6ab92014-04-08 14:00:50 +010025#include "oat.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080026#include "runtime.h"
27
28namespace art {
29namespace mirror {
30
Ian Rogersef7d42f2014-01-06 12:55:46 -080031inline Class* ArtMethod::GetDeclaringClass() {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070032 Class* result = GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080033 DCHECK(result != NULL) << this;
34 DCHECK(result->IsIdxLoaded() || result->IsErroneous()) << this;
35 return result;
36}
37
Brian Carlstromea46f952013-07-30 01:26:50 -070038inline void ArtMethod::SetDeclaringClass(Class *new_declaring_class) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010039 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_),
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070040 new_declaring_class);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080041}
42
Ian Rogersef7d42f2014-01-06 12:55:46 -080043inline uint32_t ArtMethod::GetAccessFlags() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080044 DCHECK(GetDeclaringClass()->IsIdxLoaded() || GetDeclaringClass()->IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070045 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080046}
47
Ian Rogersef7d42f2014-01-06 12:55:46 -080048inline uint16_t ArtMethod::GetMethodIndex() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080049 DCHECK(GetDeclaringClass()->IsResolved() || GetDeclaringClass()->IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070050 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080051}
52
Ian Rogersef7d42f2014-01-06 12:55:46 -080053inline uint32_t ArtMethod::GetDexMethodIndex() {
Dragos Sbirlea90af14d2013-08-15 17:50:16 -070054#ifdef ART_SEA_IR_MODE
55 // TODO: Re-add this check for (PORTABLE + SMALL + ) SEA IR when PORTABLE IS fixed!
56 // DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
57#else
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080058 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Dragos Sbirlea90af14d2013-08-15 17:50:16 -070059#endif
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070060 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080061}
62
Ian Rogersef7d42f2014-01-06 12:55:46 -080063inline ObjectArray<String>* ArtMethod::GetDexCacheStrings() {
64 return GetFieldObject<ObjectArray<String> >(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070065 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070066}
67
Ian Rogersef7d42f2014-01-06 12:55:46 -080068inline ObjectArray<ArtMethod>* ArtMethod::GetDexCacheResolvedMethods() {
69 return GetFieldObject<ObjectArray<ArtMethod> >(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070070 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070071}
72
Ian Rogersef7d42f2014-01-06 12:55:46 -080073inline ObjectArray<Class>* ArtMethod::GetDexCacheResolvedTypes() {
74 return GetFieldObject<ObjectArray<Class> >(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070075 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070076}
77
Ian Rogersef7d42f2014-01-06 12:55:46 -080078inline uint32_t ArtMethod::GetCodeSize() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080079 DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
Vladimir Marko8a630572014-04-09 18:45:35 +010080 const void* code = EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode());
81 if (code == nullptr) {
82 return 0u;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080083 }
Vladimir Marko8a630572014-04-09 18:45:35 +010084 return reinterpret_cast<const OatMethodHeader*>(code)[-1].code_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080085}
86
Brian Carlstromea46f952013-07-30 01:26:50 -070087inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080088 switch (type) {
89 case kStatic:
90 return !IsStatic();
91 case kDirect:
92 return !IsDirect() || IsStatic();
93 case kVirtual: {
94 Class* methods_class = GetDeclaringClass();
95 return IsDirect() || (methods_class->IsInterface() && !IsMiranda());
96 }
97 case kSuper:
98 return false; // TODO: appropriate checks for call to super class.
99 case kInterface: {
100 Class* methods_class = GetDeclaringClass();
101 return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass());
102 }
103 default:
104 LOG(FATAL) << "Unreachable - invocation type: " << type;
105 return true;
106 }
107}
108
Ian Rogersef7d42f2014-01-06 12:55:46 -0800109inline void ArtMethod::AssertPcIsWithinQuickCode(uintptr_t pc) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800110 if (!kIsDebugBuild) {
111 return;
112 }
113 if (IsNative() || IsRuntimeMethod() || IsProxyMethod()) {
114 return;
115 }
Ian Rogers848871b2013-08-05 10:56:33 -0700116 if (pc == GetQuickInstrumentationExitPc()) {
Jeff Hao65d15d92013-07-16 16:39:33 -0700117 return;
118 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800119 const void* code = GetEntryPointFromQuickCompiledCode();
120 if (code == GetQuickToInterpreterBridge() || code == GetQuickInstrumentationEntryPoint()) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800121 return;
122 }
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700123 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Vladimir Marko8a630572014-04-09 18:45:35 +0100124 if (code == GetQuickResolutionTrampoline(class_linker) ||
125 code == GetQuickToInterpreterBridgeTrampoline(class_linker)) {
Jeff Hao65d15d92013-07-16 16:39:33 -0700126 return;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800127 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800128 DCHECK(IsWithinQuickCode(pc))
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800129 << PrettyMethod(this)
130 << " pc=" << std::hex << pc
Jeff Hao65d15d92013-07-16 16:39:33 -0700131 << " code=" << code
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800132 << " size=" << GetCodeSize();
133}
134
Ian Rogersef7d42f2014-01-06 12:55:46 -0800135inline uint32_t ArtMethod::GetQuickOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800136 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800137 return PointerToLowMemUInt32(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800138}
139
Ian Rogersef7d42f2014-01-06 12:55:46 -0800140inline uint32_t ArtMethod::GetPortableOatCodeOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800141 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800142 return PointerToLowMemUInt32(GetEntryPointFromPortableCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800143}
144
Ian Rogersef7d42f2014-01-06 12:55:46 -0800145inline void ArtMethod::SetQuickOatCodeOffset(uint32_t code_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800146 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800147 SetEntryPointFromQuickCompiledCode(reinterpret_cast<void*>(code_offset));
148}
149
150inline void ArtMethod::SetPortableOatCodeOffset(uint32_t code_offset) {
151 DCHECK(!Runtime::Current()->IsStarted());
152 SetEntryPointFromPortableCompiledCode(reinterpret_cast<void*>(code_offset));
153}
154
Brian Carlstromea46f952013-07-30 01:26:50 -0700155inline void ArtMethod::SetOatNativeGcMapOffset(uint32_t gc_map_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800156 DCHECK(!Runtime::Current()->IsStarted());
157 SetNativeGcMap(reinterpret_cast<uint8_t*>(gc_map_offset));
158}
159
Ian Rogersef7d42f2014-01-06 12:55:46 -0800160inline uint32_t ArtMethod::GetOatNativeGcMapOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800161 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800162 return PointerToLowMemUInt32(GetNativeGcMap());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800163}
164
Ian Rogersef7d42f2014-01-06 12:55:46 -0800165inline bool ArtMethod::IsRuntimeMethod() {
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700166 return GetDexMethodIndex() == DexFile::kDexNoIndex;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800167}
168
Ian Rogersef7d42f2014-01-06 12:55:46 -0800169inline bool ArtMethod::IsCalleeSaveMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800170 if (!IsRuntimeMethod()) {
171 return false;
172 }
173 Runtime* runtime = Runtime::Current();
174 bool result = false;
175 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
176 if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
177 result = true;
178 break;
179 }
180 }
181 return result;
182}
183
Ian Rogersef7d42f2014-01-06 12:55:46 -0800184inline bool ArtMethod::IsResolutionMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800185 bool result = this == Runtime::Current()->GetResolutionMethod();
186 // Check that if we do think it is phony it looks like the resolution method.
187 DCHECK(!result || IsRuntimeMethod());
188 return result;
189}
Jeff Hao88474b42013-10-23 16:24:40 -0700190
Ian Rogersef7d42f2014-01-06 12:55:46 -0800191inline bool ArtMethod::IsImtConflictMethod() {
Jeff Hao88474b42013-10-23 16:24:40 -0700192 bool result = this == Runtime::Current()->GetImtConflictMethod();
193 // Check that if we do think it is phony it looks like the imt conflict method.
194 DCHECK(!result || IsRuntimeMethod());
195 return result;
196}
Mathieu Chartier4e305412014-02-19 10:54:44 -0800197
198template<VerifyObjectFlags kVerifyFlags>
199inline void ArtMethod::SetNativeMethod(const void* native_method) {
200 SetFieldPtr<false, true, kVerifyFlags>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700201 OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_jni_), native_method);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800202}
203
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800204} // namespace mirror
205} // namespace art
206
Brian Carlstromea46f952013-07-30 01:26:50 -0700207#endif // ART_RUNTIME_MIRROR_ART_METHOD_INL_H_