blob: 088f616d41086bb8c15b49549d6e8d1302a2cc87 [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
Brian Carlstromea46f952013-07-30 01:26:50 -070030inline Class* ArtMethod::GetDeclaringClass() const {
31 Class* result = GetFieldObject<Class*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032 DCHECK(result != NULL) << this;
33 DCHECK(result->IsIdxLoaded() || result->IsErroneous()) << this;
34 return result;
35}
36
Brian Carlstromea46f952013-07-30 01:26:50 -070037inline void ArtMethod::SetDeclaringClass(Class *new_declaring_class) {
38 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_), new_declaring_class, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080039}
40
Brian Carlstromea46f952013-07-30 01:26:50 -070041inline uint32_t ArtMethod::GetAccessFlags() const {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080042 DCHECK(GetDeclaringClass()->IsIdxLoaded() || GetDeclaringClass()->IsErroneous());
Brian Carlstromea46f952013-07-30 01:26:50 -070043 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, access_flags_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080044}
45
Brian Carlstromea46f952013-07-30 01:26:50 -070046inline uint16_t ArtMethod::GetMethodIndex() const {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080047 DCHECK(GetDeclaringClass()->IsResolved() || GetDeclaringClass()->IsErroneous());
Brian Carlstromea46f952013-07-30 01:26:50 -070048 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080049}
50
Brian Carlstromea46f952013-07-30 01:26:50 -070051inline uint32_t ArtMethod::GetDexMethodIndex() const {
Dragos Sbirlea90af14d2013-08-15 17:50:16 -070052#ifdef ART_SEA_IR_MODE
53 // TODO: Re-add this check for (PORTABLE + SMALL + ) SEA IR when PORTABLE IS fixed!
54 // DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
55#else
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080056 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Dragos Sbirlea90af14d2013-08-15 17:50:16 -070057#endif
Brian Carlstromea46f952013-07-30 01:26:50 -070058 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_dex_index_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080059}
60
Brian Carlstromea46f952013-07-30 01:26:50 -070061inline ObjectArray<String>* ArtMethod::GetDexCacheStrings() const {
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070062 return GetFieldObject<ObjectArray<String>*>(
Brian Carlstromea46f952013-07-30 01:26:50 -070063 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_), false);
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070064}
65
Brian Carlstromea46f952013-07-30 01:26:50 -070066inline ObjectArray<ArtMethod>* ArtMethod::GetDexCacheResolvedMethods() const {
67 return GetFieldObject<ObjectArray<ArtMethod>*>(
68 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_), false);
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070069}
70
Brian Carlstromea46f952013-07-30 01:26:50 -070071inline ObjectArray<Class>* ArtMethod::GetDexCacheResolvedTypes() const {
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070072 return GetFieldObject<ObjectArray<Class>*>(
Brian Carlstromea46f952013-07-30 01:26:50 -070073 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_), false);
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070074}
75
Brian Carlstromea46f952013-07-30 01:26:50 -070076inline uint32_t ArtMethod::GetCodeSize() const {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080077 DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
Jeff Haoaa4a7932013-05-13 11:28:27 -070078 uintptr_t code = reinterpret_cast<uintptr_t>(GetEntryPointFromCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080079 if (code == 0) {
80 return 0;
81 }
82 // TODO: make this Thumb2 specific
83 code &= ~0x1;
84 return reinterpret_cast<uint32_t*>(code)[-1];
85}
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
Brian Carlstromea46f952013-07-30 01:26:50 -0700109inline void ArtMethod::AssertPcIsWithinCode(uintptr_t pc) const {
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 }
119 const void* code = GetEntryPointFromCompiledCode();
Ian Rogers848871b2013-08-05 10:56:33 -0700120 if (code == GetCompiledCodeToInterpreterBridge() || 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();
Jeff Hao65d15d92013-07-16 16:39:33 -0700124 if (code == GetResolutionTrampoline(class_linker)) {
125 return;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800126 }
127 DCHECK(IsWithinCode(pc))
128 << PrettyMethod(this)
129 << " pc=" << std::hex << pc
Jeff Hao65d15d92013-07-16 16:39:33 -0700130 << " code=" << code
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800131 << " size=" << GetCodeSize();
132}
133
Brian Carlstromea46f952013-07-30 01:26:50 -0700134inline uint32_t ArtMethod::GetOatCodeOffset() const {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800135 DCHECK(!Runtime::Current()->IsStarted());
Jeff Haoaa4a7932013-05-13 11:28:27 -0700136 return reinterpret_cast<uint32_t>(GetEntryPointFromCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800137}
138
Brian Carlstromea46f952013-07-30 01:26:50 -0700139inline void ArtMethod::SetOatCodeOffset(uint32_t code_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800140 DCHECK(!Runtime::Current()->IsStarted());
Jeff Haoaa4a7932013-05-13 11:28:27 -0700141 SetEntryPointFromCompiledCode(reinterpret_cast<void*>(code_offset));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800142}
143
Brian Carlstromea46f952013-07-30 01:26:50 -0700144inline uint32_t ArtMethod::GetOatMappingTableOffset() const {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800145 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogers1809a722013-08-09 22:05:32 -0700146 return reinterpret_cast<uint32_t>(GetMappingTable());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800147}
148
Brian Carlstromea46f952013-07-30 01:26:50 -0700149inline void ArtMethod::SetOatMappingTableOffset(uint32_t mapping_table_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800150 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogers1809a722013-08-09 22:05:32 -0700151 SetMappingTable(reinterpret_cast<const uint8_t*>(mapping_table_offset));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800152}
153
Brian Carlstromea46f952013-07-30 01:26:50 -0700154inline uint32_t ArtMethod::GetOatVmapTableOffset() const {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800155 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogers1809a722013-08-09 22:05:32 -0700156 return reinterpret_cast<uint32_t>(GetVmapTable());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800157}
158
Brian Carlstromea46f952013-07-30 01:26:50 -0700159inline void ArtMethod::SetOatVmapTableOffset(uint32_t vmap_table_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800160 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogers1809a722013-08-09 22:05:32 -0700161 SetVmapTable(reinterpret_cast<uint8_t*>(vmap_table_offset));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800162}
163
Brian Carlstromea46f952013-07-30 01:26:50 -0700164inline void ArtMethod::SetOatNativeGcMapOffset(uint32_t gc_map_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800165 DCHECK(!Runtime::Current()->IsStarted());
166 SetNativeGcMap(reinterpret_cast<uint8_t*>(gc_map_offset));
167}
168
Brian Carlstromea46f952013-07-30 01:26:50 -0700169inline uint32_t ArtMethod::GetOatNativeGcMapOffset() const {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800170 DCHECK(!Runtime::Current()->IsStarted());
171 return reinterpret_cast<uint32_t>(GetNativeGcMap());
172}
173
Brian Carlstromea46f952013-07-30 01:26:50 -0700174inline bool ArtMethod::IsRuntimeMethod() const {
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700175 return GetDexMethodIndex() == DexFile::kDexNoIndex;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800176}
177
Brian Carlstromea46f952013-07-30 01:26:50 -0700178inline bool ArtMethod::IsCalleeSaveMethod() const {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800179 if (!IsRuntimeMethod()) {
180 return false;
181 }
182 Runtime* runtime = Runtime::Current();
183 bool result = false;
184 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
185 if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
186 result = true;
187 break;
188 }
189 }
190 return result;
191}
192
Brian Carlstromea46f952013-07-30 01:26:50 -0700193inline bool ArtMethod::IsResolutionMethod() const {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800194 bool result = this == Runtime::Current()->GetResolutionMethod();
195 // Check that if we do think it is phony it looks like the resolution method.
196 DCHECK(!result || IsRuntimeMethod());
197 return result;
198}
Jeff Hao88474b42013-10-23 16:24:40 -0700199
200inline bool ArtMethod::IsImtConflictMethod() const {
201 bool result = this == Runtime::Current()->GetImtConflictMethod();
202 // Check that if we do think it is phony it looks like the imt conflict method.
203 DCHECK(!result || IsRuntimeMethod());
204 return result;
205}
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800206} // namespace mirror
207} // namespace art
208
Brian Carlstromea46f952013-07-30 01:26:50 -0700209#endif // ART_RUNTIME_MIRROR_ART_METHOD_INL_H_