blob: 4d8aa6f7414d477725b1f1492503f15b9801ca32 [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 {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080052 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Brian Carlstromea46f952013-07-30 01:26:50 -070053 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_dex_index_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080054}
55
Brian Carlstromea46f952013-07-30 01:26:50 -070056inline ObjectArray<String>* ArtMethod::GetDexCacheStrings() const {
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070057 return GetFieldObject<ObjectArray<String>*>(
Brian Carlstromea46f952013-07-30 01:26:50 -070058 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_), false);
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070059}
60
Brian Carlstromea46f952013-07-30 01:26:50 -070061inline ObjectArray<ArtMethod>* ArtMethod::GetDexCacheResolvedMethods() const {
62 return GetFieldObject<ObjectArray<ArtMethod>*>(
63 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_), false);
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070064}
65
Brian Carlstromea46f952013-07-30 01:26:50 -070066inline ObjectArray<Class>* ArtMethod::GetDexCacheResolvedTypes() const {
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070067 return GetFieldObject<ObjectArray<Class>*>(
Brian Carlstromea46f952013-07-30 01:26:50 -070068 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_), false);
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070069}
70
Brian Carlstromea46f952013-07-30 01:26:50 -070071inline ObjectArray<StaticStorageBase>* ArtMethod::GetDexCacheInitializedStaticStorage() const {
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070072 return GetFieldObject<ObjectArray<StaticStorageBase>*>(
Brian Carlstromea46f952013-07-30 01:26:50 -070073 OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_initialized_static_storage_),
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070074 false);
75}
76
Brian Carlstromea46f952013-07-30 01:26:50 -070077inline uint32_t ArtMethod::GetCodeSize() const {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080078 DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
Jeff Haoaa4a7932013-05-13 11:28:27 -070079 uintptr_t code = reinterpret_cast<uintptr_t>(GetEntryPointFromCompiledCode());
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
Brian Carlstromea46f952013-07-30 01:26:50 -0700110inline void ArtMethod::AssertPcIsWithinCode(uintptr_t pc) const {
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 }
120 const void* code = GetEntryPointFromCompiledCode();
Ian Rogers848871b2013-08-05 10:56:33 -0700121 if (code == GetCompiledCodeToInterpreterBridge() || 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();
Jeff Hao65d15d92013-07-16 16:39:33 -0700125 if (code == GetResolutionTrampoline(class_linker)) {
126 return;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800127 }
128 DCHECK(IsWithinCode(pc))
129 << 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
Brian Carlstromea46f952013-07-30 01:26:50 -0700135inline uint32_t ArtMethod::GetOatCodeOffset() const {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800136 DCHECK(!Runtime::Current()->IsStarted());
Jeff Haoaa4a7932013-05-13 11:28:27 -0700137 return reinterpret_cast<uint32_t>(GetEntryPointFromCompiledCode());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800138}
139
Brian Carlstromea46f952013-07-30 01:26:50 -0700140inline void ArtMethod::SetOatCodeOffset(uint32_t code_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800141 DCHECK(!Runtime::Current()->IsStarted());
Jeff Haoaa4a7932013-05-13 11:28:27 -0700142 SetEntryPointFromCompiledCode(reinterpret_cast<void*>(code_offset));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800143}
144
Brian Carlstromea46f952013-07-30 01:26:50 -0700145inline uint32_t ArtMethod::GetOatMappingTableOffset() const {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800146 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogers1809a722013-08-09 22:05:32 -0700147 return reinterpret_cast<uint32_t>(GetMappingTable());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800148}
149
Brian Carlstromea46f952013-07-30 01:26:50 -0700150inline void ArtMethod::SetOatMappingTableOffset(uint32_t mapping_table_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800151 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogers1809a722013-08-09 22:05:32 -0700152 SetMappingTable(reinterpret_cast<const uint8_t*>(mapping_table_offset));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800153}
154
Brian Carlstromea46f952013-07-30 01:26:50 -0700155inline uint32_t ArtMethod::GetOatVmapTableOffset() const {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800156 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogers1809a722013-08-09 22:05:32 -0700157 return reinterpret_cast<uint32_t>(GetVmapTable());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800158}
159
Brian Carlstromea46f952013-07-30 01:26:50 -0700160inline void ArtMethod::SetOatVmapTableOffset(uint32_t vmap_table_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800161 DCHECK(!Runtime::Current()->IsStarted());
Ian Rogers1809a722013-08-09 22:05:32 -0700162 SetVmapTable(reinterpret_cast<uint8_t*>(vmap_table_offset));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800163}
164
Brian Carlstromea46f952013-07-30 01:26:50 -0700165inline void ArtMethod::SetOatNativeGcMapOffset(uint32_t gc_map_offset) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800166 DCHECK(!Runtime::Current()->IsStarted());
167 SetNativeGcMap(reinterpret_cast<uint8_t*>(gc_map_offset));
168}
169
Brian Carlstromea46f952013-07-30 01:26:50 -0700170inline uint32_t ArtMethod::GetOatNativeGcMapOffset() const {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800171 DCHECK(!Runtime::Current()->IsStarted());
172 return reinterpret_cast<uint32_t>(GetNativeGcMap());
173}
174
Brian Carlstromea46f952013-07-30 01:26:50 -0700175inline bool ArtMethod::IsRuntimeMethod() const {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800176 return GetDexMethodIndex() == DexFile::kDexNoIndex16;
177}
178
Brian Carlstromea46f952013-07-30 01:26:50 -0700179inline bool ArtMethod::IsCalleeSaveMethod() const {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800180 if (!IsRuntimeMethod()) {
181 return false;
182 }
183 Runtime* runtime = Runtime::Current();
184 bool result = false;
185 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
186 if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
187 result = true;
188 break;
189 }
190 }
191 return result;
192}
193
Brian Carlstromea46f952013-07-30 01:26:50 -0700194inline bool ArtMethod::IsResolutionMethod() const {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800195 bool result = this == Runtime::Current()->GetResolutionMethod();
196 // Check that if we do think it is phony it looks like the resolution method.
197 DCHECK(!result || IsRuntimeMethod());
198 return result;
199}
200} // namespace mirror
201} // namespace art
202
Brian Carlstromea46f952013-07-30 01:26:50 -0700203#endif // ART_RUNTIME_MIRROR_ART_METHOD_INL_H_