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 | |
| 17 | #ifndef ART_SRC_MIRROR_METHOD_INL_H_ |
| 18 | #define ART_SRC_MIRROR_METHOD_INL_H_ |
| 19 | |
| 20 | #include "abstract_method.h" |
| 21 | |
| 22 | #include "array.h" |
| 23 | #include "dex_file.h" |
| 24 | #include "runtime.h" |
| 25 | |
| 26 | namespace art { |
| 27 | namespace mirror { |
| 28 | |
| 29 | inline 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 | |
| 36 | inline void AbstractMethod::SetDeclaringClass(Class *new_declaring_class) { |
| 37 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(AbstractMethod, declaring_class_), new_declaring_class, false); |
| 38 | } |
| 39 | |
| 40 | inline uint32_t AbstractMethod::GetAccessFlags() const { |
| 41 | DCHECK(GetDeclaringClass()->IsIdxLoaded() || GetDeclaringClass()->IsErroneous()); |
| 42 | return GetField32(OFFSET_OF_OBJECT_MEMBER(AbstractMethod, access_flags_), false); |
| 43 | } |
| 44 | |
| 45 | inline uint16_t AbstractMethod::GetMethodIndex() const { |
| 46 | DCHECK(GetDeclaringClass()->IsResolved() || GetDeclaringClass()->IsErroneous()); |
| 47 | return GetField32(OFFSET_OF_OBJECT_MEMBER(AbstractMethod, method_index_), false); |
| 48 | } |
| 49 | |
| 50 | inline 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 | |
| 55 | inline uint32_t AbstractMethod::GetCodeSize() const { |
| 56 | DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this); |
| 57 | uintptr_t code = reinterpret_cast<uintptr_t>(GetCode()); |
| 58 | if (code == 0) { |
| 59 | return 0; |
| 60 | } |
| 61 | // TODO: make this Thumb2 specific |
| 62 | code &= ~0x1; |
| 63 | return reinterpret_cast<uint32_t*>(code)[-1]; |
| 64 | } |
| 65 | |
| 66 | inline bool AbstractMethod::CheckIncompatibleClassChange(InvokeType type) { |
| 67 | switch (type) { |
| 68 | case kStatic: |
| 69 | return !IsStatic(); |
| 70 | case kDirect: |
| 71 | return !IsDirect() || IsStatic(); |
| 72 | case kVirtual: { |
| 73 | Class* methods_class = GetDeclaringClass(); |
| 74 | return IsDirect() || (methods_class->IsInterface() && !IsMiranda()); |
| 75 | } |
| 76 | case kSuper: |
| 77 | return false; // TODO: appropriate checks for call to super class. |
| 78 | case kInterface: { |
| 79 | Class* methods_class = GetDeclaringClass(); |
| 80 | return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass()); |
| 81 | } |
| 82 | default: |
| 83 | LOG(FATAL) << "Unreachable - invocation type: " << type; |
| 84 | return true; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | inline void AbstractMethod::AssertPcIsWithinCode(uintptr_t pc) const { |
| 89 | if (!kIsDebugBuild) { |
| 90 | return; |
| 91 | } |
| 92 | if (IsNative() || IsRuntimeMethod() || IsProxyMethod()) { |
| 93 | return; |
| 94 | } |
| 95 | Runtime* runtime = Runtime::Current(); |
| 96 | if (GetCode() == runtime->GetResolutionStubArray(Runtime::kStaticMethod)->GetData()) { |
| 97 | return; |
| 98 | } |
| 99 | DCHECK(IsWithinCode(pc)) |
| 100 | << PrettyMethod(this) |
| 101 | << " pc=" << std::hex << pc |
| 102 | << " code=" << GetCode() |
| 103 | << " size=" << GetCodeSize(); |
| 104 | } |
| 105 | |
| 106 | inline uint32_t AbstractMethod::GetOatCodeOffset() const { |
| 107 | DCHECK(!Runtime::Current()->IsStarted()); |
| 108 | return reinterpret_cast<uint32_t>(GetCode()); |
| 109 | } |
| 110 | |
| 111 | inline void AbstractMethod::SetOatCodeOffset(uint32_t code_offset) { |
| 112 | DCHECK(!Runtime::Current()->IsStarted()); |
| 113 | SetCode(reinterpret_cast<void*>(code_offset)); |
| 114 | } |
| 115 | |
| 116 | inline uint32_t AbstractMethod::GetOatMappingTableOffset() const { |
| 117 | DCHECK(!Runtime::Current()->IsStarted()); |
| 118 | return reinterpret_cast<uint32_t>(GetMappingTableRaw()); |
| 119 | } |
| 120 | |
| 121 | inline void AbstractMethod::SetOatMappingTableOffset(uint32_t mapping_table_offset) { |
| 122 | DCHECK(!Runtime::Current()->IsStarted()); |
| 123 | SetMappingTable(reinterpret_cast<const uint32_t*>(mapping_table_offset)); |
| 124 | } |
| 125 | |
| 126 | inline uint32_t AbstractMethod::GetOatVmapTableOffset() const { |
| 127 | DCHECK(!Runtime::Current()->IsStarted()); |
| 128 | return reinterpret_cast<uint32_t>(GetVmapTableRaw()); |
| 129 | } |
| 130 | |
| 131 | inline void AbstractMethod::SetOatVmapTableOffset(uint32_t vmap_table_offset) { |
| 132 | DCHECK(!Runtime::Current()->IsStarted()); |
| 133 | SetVmapTable(reinterpret_cast<uint16_t*>(vmap_table_offset)); |
| 134 | } |
| 135 | |
| 136 | inline void AbstractMethod::SetOatNativeGcMapOffset(uint32_t gc_map_offset) { |
| 137 | DCHECK(!Runtime::Current()->IsStarted()); |
| 138 | SetNativeGcMap(reinterpret_cast<uint8_t*>(gc_map_offset)); |
| 139 | } |
| 140 | |
| 141 | inline uint32_t AbstractMethod::GetOatNativeGcMapOffset() const { |
| 142 | DCHECK(!Runtime::Current()->IsStarted()); |
| 143 | return reinterpret_cast<uint32_t>(GetNativeGcMap()); |
| 144 | } |
| 145 | |
| 146 | inline uint32_t AbstractMethod::GetOatInvokeStubOffset() const { |
| 147 | DCHECK(!Runtime::Current()->IsStarted()); |
| 148 | return reinterpret_cast<uint32_t>(GetInvokeStub()); |
| 149 | } |
| 150 | |
| 151 | inline void AbstractMethod::SetOatInvokeStubOffset(uint32_t invoke_stub_offset) { |
| 152 | DCHECK(!Runtime::Current()->IsStarted()); |
| 153 | SetInvokeStub(reinterpret_cast<InvokeStub*>(invoke_stub_offset)); |
| 154 | } |
| 155 | |
| 156 | inline bool AbstractMethod::IsRuntimeMethod() const { |
| 157 | return GetDexMethodIndex() == DexFile::kDexNoIndex16; |
| 158 | } |
| 159 | |
| 160 | inline bool AbstractMethod::IsCalleeSaveMethod() const { |
| 161 | if (!IsRuntimeMethod()) { |
| 162 | return false; |
| 163 | } |
| 164 | Runtime* runtime = Runtime::Current(); |
| 165 | bool result = false; |
| 166 | for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) { |
| 167 | if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) { |
| 168 | result = true; |
| 169 | break; |
| 170 | } |
| 171 | } |
| 172 | return result; |
| 173 | } |
| 174 | |
| 175 | inline bool AbstractMethod::IsResolutionMethod() const { |
| 176 | bool result = this == Runtime::Current()->GetResolutionMethod(); |
| 177 | // Check that if we do think it is phony it looks like the resolution method. |
| 178 | DCHECK(!result || IsRuntimeMethod()); |
| 179 | return result; |
| 180 | } |
| 181 | } // namespace mirror |
| 182 | } // namespace art |
| 183 | |
| 184 | #endif // ART_SRC_MIRROR_METHOD_INL_H_ |