blob: 8ef3be821b6106f0d85b171893dba78a0d8d64c0 [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"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025#include "runtime.h"
26
27namespace art {
28namespace mirror {
29
Ian Rogersef7d42f2014-01-06 12:55:46 -080030inline Class* ArtMethod::GetDeclaringClass() {
31 Class* result = GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_),
32 false);
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) {
39 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_), new_declaring_class, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080040}
41
Ian Rogersef7d42f2014-01-06 12:55:46 -080042inline uint32_t ArtMethod::GetAccessFlags() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080043 DCHECK(GetDeclaringClass()->IsIdxLoaded() || GetDeclaringClass()->IsErroneous());
Brian Carlstromea46f952013-07-30 01:26:50 -070044 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, access_flags_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080045}
46
Ian Rogersef7d42f2014-01-06 12:55:46 -080047inline uint16_t ArtMethod::GetMethodIndex() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080048 DCHECK(GetDeclaringClass()->IsResolved() || GetDeclaringClass()->IsErroneous());
Brian Carlstromea46f952013-07-30 01:26:50 -070049 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080050}
51
Ian Rogersef7d42f2014-01-06 12:55:46 -080052inline uint32_t ArtMethod::GetDexMethodIndex() {
Dragos Sbirlea90af14d2013-08-15 17:50:16 -070053#ifdef ART_SEA_IR_MODE
54 // TODO: Re-add this check for (PORTABLE + SMALL + ) SEA IR when PORTABLE IS fixed!
55 // DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
56#else
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080057 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Dragos Sbirlea90af14d2013-08-15 17:50:16 -070058#endif
Ian Rogersef7d42f2014-01-06 12:55:46 -080059 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080060}
61
Ian Rogersef7d42f2014-01-06 12:55:46 -080062inline ObjectArray<String>* ArtMethod::GetDexCacheStrings() {
63 return GetFieldObject<ObjectArray<String> >(
Brian Carlstromea46f952013-07-30 01:26:50 -070064 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_), false);
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070065}
66
Ian Rogersef7d42f2014-01-06 12:55:46 -080067inline ObjectArray<ArtMethod>* ArtMethod::GetDexCacheResolvedMethods() {
68 return GetFieldObject<ObjectArray<ArtMethod> >(
Brian Carlstromea46f952013-07-30 01:26:50 -070069 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_), false);
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070070}
71
Ian Rogersef7d42f2014-01-06 12:55:46 -080072inline ObjectArray<Class>* ArtMethod::GetDexCacheResolvedTypes() {
73 return GetFieldObject<ObjectArray<Class> >(
Brian Carlstromea46f952013-07-30 01:26:50 -070074 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_), false);
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070075}
76
Ian Rogersef7d42f2014-01-06 12:55:46 -080077inline uint32_t ArtMethod::GetCodeSize() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080078 DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
Ian Rogersef7d42f2014-01-06 12:55:46 -080079 uintptr_t code = reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080080 if (code == 0) {
81 return 0;
82 }
83 // TODO: make this Thumb2 specific
84 code &= ~0x1;
85 return reinterpret_cast<uint32_t*>(code)[-1];
86}
87
Brian Carlstromea46f952013-07-30 01:26:50 -070088inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080089 switch (type) {
90 case kStatic:
91 return !IsStatic();
92 case kDirect:
93 return !IsDirect() || IsStatic();
94 case kVirtual: {
95 Class* methods_class = GetDeclaringClass();
96 return IsDirect() || (methods_class->IsInterface() && !IsMiranda());
97 }
98 case kSuper:
99 return false; // TODO: appropriate checks for call to super class.
100 case kInterface: {
101 Class* methods_class = GetDeclaringClass();
102 return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass());
103 }
104 default:
105 LOG(FATAL) << "Unreachable - invocation type: " << type;
106 return true;
107 }
108}
109
Ian Rogersef7d42f2014-01-06 12:55:46 -0800110inline void ArtMethod::AssertPcIsWithinQuickCode(uintptr_t pc) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800111 if (!kIsDebugBuild) {
112 return;
113 }
114 if (IsNative() || IsRuntimeMethod() || IsProxyMethod()) {
115 return;
116 }
Ian Rogers848871b2013-08-05 10:56:33 -0700117 if (pc == GetQuickInstrumentationExitPc()) {
Jeff Hao65d15d92013-07-16 16:39:33 -0700118 return;
119 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800120 const void* code = GetEntryPointFromQuickCompiledCode();
121 if (code == GetQuickToInterpreterBridge() || code == GetQuickInstrumentationEntryPoint()) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800122 return;
123 }
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700124 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Ian Rogersef7d42f2014-01-06 12:55:46 -0800125 if (code == GetQuickResolutionTrampoline(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
155inline uint32_t ArtMethod::GetOatMappingTableOffset() {
156 DCHECK(!Runtime::Current()->IsStarted());
157 return PointerToLowMemUInt32(GetMappingTable());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800158}
159
Brian Carlstromea46f952013-07-30 01:26:50 -0700160inline void ArtMethod::SetOatMappingTableOffset(uint32_t mapping_table_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800161 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogers1809a722013-08-09 22:05:32 -0700162 SetMappingTable(reinterpret_cast<const uint8_t*>(mapping_table_offset));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800163}
164
Ian Rogersef7d42f2014-01-06 12:55:46 -0800165inline uint32_t ArtMethod::GetOatVmapTableOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800166 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800167 return PointerToLowMemUInt32(GetVmapTable());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800168}
169
Brian Carlstromea46f952013-07-30 01:26:50 -0700170inline void ArtMethod::SetOatVmapTableOffset(uint32_t vmap_table_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800171 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogers1809a722013-08-09 22:05:32 -0700172 SetVmapTable(reinterpret_cast<uint8_t*>(vmap_table_offset));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800173}
174
Brian Carlstromea46f952013-07-30 01:26:50 -0700175inline void ArtMethod::SetOatNativeGcMapOffset(uint32_t gc_map_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800176 DCHECK(!Runtime::Current()->IsStarted());
177 SetNativeGcMap(reinterpret_cast<uint8_t*>(gc_map_offset));
178}
179
Ian Rogersef7d42f2014-01-06 12:55:46 -0800180inline uint32_t ArtMethod::GetOatNativeGcMapOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800181 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogersef7d42f2014-01-06 12:55:46 -0800182 return PointerToLowMemUInt32(GetNativeGcMap());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800183}
184
Ian Rogersef7d42f2014-01-06 12:55:46 -0800185inline bool ArtMethod::IsRuntimeMethod() {
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700186 return GetDexMethodIndex() == DexFile::kDexNoIndex;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800187}
188
Ian Rogersef7d42f2014-01-06 12:55:46 -0800189inline bool ArtMethod::IsCalleeSaveMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800190 if (!IsRuntimeMethod()) {
191 return false;
192 }
193 Runtime* runtime = Runtime::Current();
194 bool result = false;
195 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
196 if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
197 result = true;
198 break;
199 }
200 }
201 return result;
202}
203
Ian Rogersef7d42f2014-01-06 12:55:46 -0800204inline bool ArtMethod::IsResolutionMethod() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800205 bool result = this == Runtime::Current()->GetResolutionMethod();
206 // Check that if we do think it is phony it looks like the resolution method.
207 DCHECK(!result || IsRuntimeMethod());
208 return result;
209}
Jeff Hao88474b42013-10-23 16:24:40 -0700210
Ian Rogersef7d42f2014-01-06 12:55:46 -0800211inline bool ArtMethod::IsImtConflictMethod() {
Jeff Hao88474b42013-10-23 16:24:40 -0700212 bool result = this == Runtime::Current()->GetImtConflictMethod();
213 // Check that if we do think it is phony it looks like the imt conflict method.
214 DCHECK(!result || IsRuntimeMethod());
215 return result;
216}
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800217} // namespace mirror
218} // namespace art
219
Brian Carlstromea46f952013-07-30 01:26:50 -0700220#endif // ART_RUNTIME_MIRROR_ART_METHOD_INL_H_