Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1 | /* |
| 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 Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_MIRROR_ART_METHOD_INL_H_ |
| 18 | #define ART_RUNTIME_MIRROR_ART_METHOD_INL_H_ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 19 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 20 | #include "art_method.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 21 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 22 | #include "dex_file.h" |
Ian Rogers | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 23 | #include "entrypoints/entrypoint_utils.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 24 | #include "object_array.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 25 | #include "runtime.h" |
| 26 | |
| 27 | namespace art { |
| 28 | namespace mirror { |
| 29 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 30 | inline Class* ArtMethod::GetDeclaringClass() const { |
| 31 | Class* result = GetFieldObject<Class*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_), false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 32 | DCHECK(result != NULL) << this; |
| 33 | DCHECK(result->IsIdxLoaded() || result->IsErroneous()) << this; |
| 34 | return result; |
| 35 | } |
| 36 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 37 | inline void ArtMethod::SetDeclaringClass(Class *new_declaring_class) { |
| 38 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_), new_declaring_class, false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 39 | } |
| 40 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 41 | inline uint32_t ArtMethod::GetAccessFlags() const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 42 | DCHECK(GetDeclaringClass()->IsIdxLoaded() || GetDeclaringClass()->IsErroneous()); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 43 | return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, access_flags_), false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 44 | } |
| 45 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 46 | inline uint16_t ArtMethod::GetMethodIndex() const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 47 | DCHECK(GetDeclaringClass()->IsResolved() || GetDeclaringClass()->IsErroneous()); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 48 | return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_), false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 49 | } |
| 50 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 51 | inline uint32_t ArtMethod::GetDexMethodIndex() const { |
Dragos Sbirlea | 90af14d | 2013-08-15 17:50:16 -0700 | [diff] [blame] | 52 | #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 Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 56 | DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous()); |
Dragos Sbirlea | 90af14d | 2013-08-15 17:50:16 -0700 | [diff] [blame] | 57 | #endif |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 58 | return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_dex_index_), false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 59 | } |
| 60 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 61 | inline ObjectArray<String>* ArtMethod::GetDexCacheStrings() const { |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 62 | return GetFieldObject<ObjectArray<String>*>( |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 63 | OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_), false); |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 66 | inline ObjectArray<ArtMethod>* ArtMethod::GetDexCacheResolvedMethods() const { |
| 67 | return GetFieldObject<ObjectArray<ArtMethod>*>( |
| 68 | OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_), false); |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 71 | inline ObjectArray<Class>* ArtMethod::GetDexCacheResolvedTypes() const { |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 72 | return GetFieldObject<ObjectArray<Class>*>( |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 73 | OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_), false); |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 76 | inline uint32_t ArtMethod::GetCodeSize() const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 77 | DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this); |
Jeff Hao | aa4a793 | 2013-05-13 11:28:27 -0700 | [diff] [blame] | 78 | uintptr_t code = reinterpret_cast<uintptr_t>(GetEntryPointFromCompiledCode()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 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 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 87 | inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 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 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 109 | inline void ArtMethod::AssertPcIsWithinCode(uintptr_t pc) const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 110 | if (!kIsDebugBuild) { |
| 111 | return; |
| 112 | } |
| 113 | if (IsNative() || IsRuntimeMethod() || IsProxyMethod()) { |
| 114 | return; |
| 115 | } |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 116 | if (pc == GetQuickInstrumentationExitPc()) { |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 117 | return; |
| 118 | } |
| 119 | const void* code = GetEntryPointFromCompiledCode(); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 120 | if (code == GetCompiledCodeToInterpreterBridge() || code == GetQuickInstrumentationEntryPoint()) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 121 | return; |
| 122 | } |
Jeff Hao | 0aba0ba | 2013-06-03 14:49:28 -0700 | [diff] [blame] | 123 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 124 | if (code == GetResolutionTrampoline(class_linker)) { |
| 125 | return; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 126 | } |
| 127 | DCHECK(IsWithinCode(pc)) |
| 128 | << PrettyMethod(this) |
| 129 | << " pc=" << std::hex << pc |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 130 | << " code=" << code |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 131 | << " size=" << GetCodeSize(); |
| 132 | } |
| 133 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 134 | inline uint32_t ArtMethod::GetOatCodeOffset() const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 135 | DCHECK(!Runtime::Current()->IsStarted()); |
Jeff Hao | aa4a793 | 2013-05-13 11:28:27 -0700 | [diff] [blame] | 136 | return reinterpret_cast<uint32_t>(GetEntryPointFromCompiledCode()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 137 | } |
| 138 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 139 | inline void ArtMethod::SetOatCodeOffset(uint32_t code_offset) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 140 | DCHECK(!Runtime::Current()->IsStarted()); |
Jeff Hao | aa4a793 | 2013-05-13 11:28:27 -0700 | [diff] [blame] | 141 | SetEntryPointFromCompiledCode(reinterpret_cast<void*>(code_offset)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 142 | } |
| 143 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 144 | inline uint32_t ArtMethod::GetOatMappingTableOffset() const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 145 | DCHECK(!Runtime::Current()->IsStarted()); |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 146 | return reinterpret_cast<uint32_t>(GetMappingTable()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 149 | inline void ArtMethod::SetOatMappingTableOffset(uint32_t mapping_table_offset) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 150 | DCHECK(!Runtime::Current()->IsStarted()); |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 151 | SetMappingTable(reinterpret_cast<const uint8_t*>(mapping_table_offset)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 152 | } |
| 153 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 154 | inline uint32_t ArtMethod::GetOatVmapTableOffset() const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 155 | DCHECK(!Runtime::Current()->IsStarted()); |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 156 | return reinterpret_cast<uint32_t>(GetVmapTable()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 157 | } |
| 158 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 159 | inline void ArtMethod::SetOatVmapTableOffset(uint32_t vmap_table_offset) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 160 | DCHECK(!Runtime::Current()->IsStarted()); |
Ian Rogers | 1809a72 | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 161 | SetVmapTable(reinterpret_cast<uint8_t*>(vmap_table_offset)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 162 | } |
| 163 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 164 | inline void ArtMethod::SetOatNativeGcMapOffset(uint32_t gc_map_offset) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 165 | DCHECK(!Runtime::Current()->IsStarted()); |
| 166 | SetNativeGcMap(reinterpret_cast<uint8_t*>(gc_map_offset)); |
| 167 | } |
| 168 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 169 | inline uint32_t ArtMethod::GetOatNativeGcMapOffset() const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 170 | DCHECK(!Runtime::Current()->IsStarted()); |
| 171 | return reinterpret_cast<uint32_t>(GetNativeGcMap()); |
| 172 | } |
| 173 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 174 | inline bool ArtMethod::IsRuntimeMethod() const { |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 175 | return GetDexMethodIndex() == DexFile::kDexNoIndex; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 176 | } |
| 177 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 178 | inline bool ArtMethod::IsCalleeSaveMethod() const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 179 | 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 Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 193 | inline bool ArtMethod::IsResolutionMethod() const { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 194 | 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 Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 199 | |
| 200 | inline 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 Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 206 | } // namespace mirror |
| 207 | } // namespace art |
| 208 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 209 | #endif // ART_RUNTIME_MIRROR_ART_METHOD_INL_H_ |