blob: e14cce2e01f239d1b57d238ff8f83013ca125ffb [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
17#ifndef ART_SRC_MIRROR_METHOD_INL_H_
18#define ART_SRC_MIRROR_METHOD_INL_H_
19
20#include "abstract_method.h"
21
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080022#include "dex_file.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070023#include "object_array.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080024#include "runtime.h"
25
26namespace art {
27namespace mirror {
28
29inline Class* AbstractMethod::GetDeclaringClass() const {
30 Class* result = GetFieldObject<Class*>(OFFSET_OF_OBJECT_MEMBER(AbstractMethod, declaring_class_), false);
31 DCHECK(result != NULL) << this;
32 DCHECK(result->IsIdxLoaded() || result->IsErroneous()) << this;
33 return result;
34}
35
36inline void AbstractMethod::SetDeclaringClass(Class *new_declaring_class) {
37 SetFieldObject(OFFSET_OF_OBJECT_MEMBER(AbstractMethod, declaring_class_), new_declaring_class, false);
38}
39
40inline uint32_t AbstractMethod::GetAccessFlags() const {
41 DCHECK(GetDeclaringClass()->IsIdxLoaded() || GetDeclaringClass()->IsErroneous());
42 return GetField32(OFFSET_OF_OBJECT_MEMBER(AbstractMethod, access_flags_), false);
43}
44
45inline uint16_t AbstractMethod::GetMethodIndex() const {
46 DCHECK(GetDeclaringClass()->IsResolved() || GetDeclaringClass()->IsErroneous());
47 return GetField32(OFFSET_OF_OBJECT_MEMBER(AbstractMethod, method_index_), false);
48}
49
50inline uint32_t AbstractMethod::GetDexMethodIndex() const {
51 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
52 return GetField32(OFFSET_OF_OBJECT_MEMBER(AbstractMethod, method_dex_index_), false);
53}
54
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070055inline ObjectArray<String>* AbstractMethod::GetDexCacheStrings() const {
56 return GetFieldObject<ObjectArray<String>*>(
57 OFFSET_OF_OBJECT_MEMBER(AbstractMethod, dex_cache_strings_), false);
58}
59
60inline ObjectArray<AbstractMethod>* AbstractMethod::GetDexCacheResolvedMethods() const {
61 return GetFieldObject<ObjectArray<AbstractMethod>*>(
62 OFFSET_OF_OBJECT_MEMBER(AbstractMethod, dex_cache_resolved_methods_), false);
63}
64
65inline ObjectArray<Class>* AbstractMethod::GetDexCacheResolvedTypes() const {
66 return GetFieldObject<ObjectArray<Class>*>(
67 OFFSET_OF_OBJECT_MEMBER(AbstractMethod, dex_cache_resolved_types_), false);
68}
69
70inline ObjectArray<StaticStorageBase>* AbstractMethod::GetDexCacheInitializedStaticStorage() const {
71 return GetFieldObject<ObjectArray<StaticStorageBase>*>(
72 OFFSET_OF_OBJECT_MEMBER(AbstractMethod, dex_cache_initialized_static_storage_),
73 false);
74}
75
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080076inline uint32_t AbstractMethod::GetCodeSize() const {
77 DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
78 uintptr_t code = reinterpret_cast<uintptr_t>(GetCode());
79 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
87inline bool AbstractMethod::CheckIncompatibleClassChange(InvokeType type) {
88 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
109inline void AbstractMethod::AssertPcIsWithinCode(uintptr_t pc) const {
110 if (!kIsDebugBuild) {
111 return;
112 }
113 if (IsNative() || IsRuntimeMethod() || IsProxyMethod()) {
114 return;
115 }
116 Runtime* runtime = Runtime::Current();
117 if (GetCode() == runtime->GetResolutionStubArray(Runtime::kStaticMethod)->GetData()) {
118 return;
119 }
120 DCHECK(IsWithinCode(pc))
121 << PrettyMethod(this)
122 << " pc=" << std::hex << pc
123 << " code=" << GetCode()
124 << " size=" << GetCodeSize();
125}
126
127inline uint32_t AbstractMethod::GetOatCodeOffset() const {
128 DCHECK(!Runtime::Current()->IsStarted());
129 return reinterpret_cast<uint32_t>(GetCode());
130}
131
132inline void AbstractMethod::SetOatCodeOffset(uint32_t code_offset) {
133 DCHECK(!Runtime::Current()->IsStarted());
134 SetCode(reinterpret_cast<void*>(code_offset));
135}
136
137inline uint32_t AbstractMethod::GetOatMappingTableOffset() const {
138 DCHECK(!Runtime::Current()->IsStarted());
139 return reinterpret_cast<uint32_t>(GetMappingTableRaw());
140}
141
142inline void AbstractMethod::SetOatMappingTableOffset(uint32_t mapping_table_offset) {
143 DCHECK(!Runtime::Current()->IsStarted());
144 SetMappingTable(reinterpret_cast<const uint32_t*>(mapping_table_offset));
145}
146
147inline uint32_t AbstractMethod::GetOatVmapTableOffset() const {
148 DCHECK(!Runtime::Current()->IsStarted());
149 return reinterpret_cast<uint32_t>(GetVmapTableRaw());
150}
151
152inline void AbstractMethod::SetOatVmapTableOffset(uint32_t vmap_table_offset) {
153 DCHECK(!Runtime::Current()->IsStarted());
154 SetVmapTable(reinterpret_cast<uint16_t*>(vmap_table_offset));
155}
156
157inline void AbstractMethod::SetOatNativeGcMapOffset(uint32_t gc_map_offset) {
158 DCHECK(!Runtime::Current()->IsStarted());
159 SetNativeGcMap(reinterpret_cast<uint8_t*>(gc_map_offset));
160}
161
162inline uint32_t AbstractMethod::GetOatNativeGcMapOffset() const {
163 DCHECK(!Runtime::Current()->IsStarted());
164 return reinterpret_cast<uint32_t>(GetNativeGcMap());
165}
166
167inline uint32_t AbstractMethod::GetOatInvokeStubOffset() const {
168 DCHECK(!Runtime::Current()->IsStarted());
169 return reinterpret_cast<uint32_t>(GetInvokeStub());
170}
171
172inline void AbstractMethod::SetOatInvokeStubOffset(uint32_t invoke_stub_offset) {
173 DCHECK(!Runtime::Current()->IsStarted());
174 SetInvokeStub(reinterpret_cast<InvokeStub*>(invoke_stub_offset));
175}
176
177inline bool AbstractMethod::IsRuntimeMethod() const {
178 return GetDexMethodIndex() == DexFile::kDexNoIndex16;
179}
180
181inline bool AbstractMethod::IsCalleeSaveMethod() const {
182 if (!IsRuntimeMethod()) {
183 return false;
184 }
185 Runtime* runtime = Runtime::Current();
186 bool result = false;
187 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
188 if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
189 result = true;
190 break;
191 }
192 }
193 return result;
194}
195
196inline bool AbstractMethod::IsResolutionMethod() const {
197 bool result = this == Runtime::Current()->GetResolutionMethod();
198 // Check that if we do think it is phony it looks like the resolution method.
199 DCHECK(!result || IsRuntimeMethod());
200 return result;
201}
202} // namespace mirror
203} // namespace art
204
205#endif // ART_SRC_MIRROR_METHOD_INL_H_