Home | History | Annotate | Download | only in mirror
      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_RUNTIME_MIRROR_ART_METHOD_INL_H_
     18 #define ART_RUNTIME_MIRROR_ART_METHOD_INL_H_
     19 
     20 #include "art_method.h"
     21 
     22 #include "dex_file.h"
     23 #include "entrypoints/entrypoint_utils.h"
     24 #include "object_array.h"
     25 #include "runtime.h"
     26 
     27 namespace art {
     28 namespace mirror {
     29 
     30 inline Class* ArtMethod::GetDeclaringClass() const {
     31   Class* result = GetFieldObject<Class*>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_), false);
     32   DCHECK(result != NULL) << this;
     33   DCHECK(result->IsIdxLoaded() || result->IsErroneous()) << this;
     34   return result;
     35 }
     36 
     37 inline void ArtMethod::SetDeclaringClass(Class *new_declaring_class) {
     38   SetFieldObject(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_), new_declaring_class, false);
     39 }
     40 
     41 inline uint32_t ArtMethod::GetAccessFlags() const {
     42   DCHECK(GetDeclaringClass()->IsIdxLoaded() || GetDeclaringClass()->IsErroneous());
     43   return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, access_flags_), false);
     44 }
     45 
     46 inline uint16_t ArtMethod::GetMethodIndex() const {
     47   DCHECK(GetDeclaringClass()->IsResolved() || GetDeclaringClass()->IsErroneous());
     48   return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_), false);
     49 }
     50 
     51 inline uint32_t ArtMethod::GetDexMethodIndex() const {
     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
     56   DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
     57 #endif
     58   return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_dex_index_), false);
     59 }
     60 
     61 inline ObjectArray<String>* ArtMethod::GetDexCacheStrings() const {
     62   return GetFieldObject<ObjectArray<String>*>(
     63       OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_), false);
     64 }
     65 
     66 inline ObjectArray<ArtMethod>* ArtMethod::GetDexCacheResolvedMethods() const {
     67   return GetFieldObject<ObjectArray<ArtMethod>*>(
     68       OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_), false);
     69 }
     70 
     71 inline ObjectArray<Class>* ArtMethod::GetDexCacheResolvedTypes() const {
     72   return GetFieldObject<ObjectArray<Class>*>(
     73       OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_), false);
     74 }
     75 
     76 inline ObjectArray<StaticStorageBase>* ArtMethod::GetDexCacheInitializedStaticStorage() const {
     77   return GetFieldObject<ObjectArray<StaticStorageBase>*>(
     78       OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_initialized_static_storage_),
     79       false);
     80 }
     81 
     82 inline uint32_t ArtMethod::GetCodeSize() const {
     83   DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
     84   uintptr_t code = reinterpret_cast<uintptr_t>(GetEntryPointFromCompiledCode());
     85   if (code == 0) {
     86     return 0;
     87   }
     88   // TODO: make this Thumb2 specific
     89   code &= ~0x1;
     90   return reinterpret_cast<uint32_t*>(code)[-1];
     91 }
     92 
     93 inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) {
     94   switch (type) {
     95     case kStatic:
     96       return !IsStatic();
     97     case kDirect:
     98       return !IsDirect() || IsStatic();
     99     case kVirtual: {
    100       Class* methods_class = GetDeclaringClass();
    101       return IsDirect() || (methods_class->IsInterface() && !IsMiranda());
    102     }
    103     case kSuper:
    104       return false;  // TODO: appropriate checks for call to super class.
    105     case kInterface: {
    106       Class* methods_class = GetDeclaringClass();
    107       return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass());
    108     }
    109     default:
    110       LOG(FATAL) << "Unreachable - invocation type: " << type;
    111       return true;
    112   }
    113 }
    114 
    115 inline void ArtMethod::AssertPcIsWithinCode(uintptr_t pc) const {
    116   if (!kIsDebugBuild) {
    117     return;
    118   }
    119   if (IsNative() || IsRuntimeMethod() || IsProxyMethod()) {
    120     return;
    121   }
    122   if (pc == GetQuickInstrumentationExitPc()) {
    123     return;
    124   }
    125   const void* code = GetEntryPointFromCompiledCode();
    126   if (code == GetCompiledCodeToInterpreterBridge() || code == GetQuickInstrumentationEntryPoint()) {
    127     return;
    128   }
    129   ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
    130   if (code == GetResolutionTrampoline(class_linker)) {
    131     return;
    132   }
    133   DCHECK(IsWithinCode(pc))
    134       << PrettyMethod(this)
    135       << " pc=" << std::hex << pc
    136       << " code=" << code
    137       << " size=" << GetCodeSize();
    138 }
    139 
    140 inline uint32_t ArtMethod::GetOatCodeOffset() const {
    141   DCHECK(!Runtime::Current()->IsStarted());
    142   return reinterpret_cast<uint32_t>(GetEntryPointFromCompiledCode());
    143 }
    144 
    145 inline void ArtMethod::SetOatCodeOffset(uint32_t code_offset) {
    146   DCHECK(!Runtime::Current()->IsStarted());
    147   SetEntryPointFromCompiledCode(reinterpret_cast<void*>(code_offset));
    148 }
    149 
    150 inline uint32_t ArtMethod::GetOatMappingTableOffset() const {
    151   DCHECK(!Runtime::Current()->IsStarted());
    152   return reinterpret_cast<uint32_t>(GetMappingTable());
    153 }
    154 
    155 inline void ArtMethod::SetOatMappingTableOffset(uint32_t mapping_table_offset) {
    156   DCHECK(!Runtime::Current()->IsStarted());
    157   SetMappingTable(reinterpret_cast<const uint8_t*>(mapping_table_offset));
    158 }
    159 
    160 inline uint32_t ArtMethod::GetOatVmapTableOffset() const {
    161   DCHECK(!Runtime::Current()->IsStarted());
    162   return reinterpret_cast<uint32_t>(GetVmapTable());
    163 }
    164 
    165 inline void ArtMethod::SetOatVmapTableOffset(uint32_t vmap_table_offset) {
    166   DCHECK(!Runtime::Current()->IsStarted());
    167   SetVmapTable(reinterpret_cast<uint8_t*>(vmap_table_offset));
    168 }
    169 
    170 inline void ArtMethod::SetOatNativeGcMapOffset(uint32_t gc_map_offset) {
    171   DCHECK(!Runtime::Current()->IsStarted());
    172   SetNativeGcMap(reinterpret_cast<uint8_t*>(gc_map_offset));
    173 }
    174 
    175 inline uint32_t ArtMethod::GetOatNativeGcMapOffset() const {
    176   DCHECK(!Runtime::Current()->IsStarted());
    177   return reinterpret_cast<uint32_t>(GetNativeGcMap());
    178 }
    179 
    180 inline bool ArtMethod::IsRuntimeMethod() const {
    181   return GetDexMethodIndex() == DexFile::kDexNoIndex;
    182 }
    183 
    184 inline bool ArtMethod::IsCalleeSaveMethod() const {
    185   if (!IsRuntimeMethod()) {
    186     return false;
    187   }
    188   Runtime* runtime = Runtime::Current();
    189   bool result = false;
    190   for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
    191     if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) {
    192       result = true;
    193       break;
    194     }
    195   }
    196   return result;
    197 }
    198 
    199 inline bool ArtMethod::IsResolutionMethod() const {
    200   bool result = this == Runtime::Current()->GetResolutionMethod();
    201   // Check that if we do think it is phony it looks like the resolution method.
    202   DCHECK(!result || IsRuntimeMethod());
    203   return result;
    204 }
    205 }  // namespace mirror
    206 }  // namespace art
    207 
    208 #endif  // ART_RUNTIME_MIRROR_ART_METHOD_INL_H_
    209