1 /*
2  * Copyright (C) 2013 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_DEX_CACHE_INL_H_
18 #define ART_RUNTIME_MIRROR_DEX_CACHE_INL_H_
19 
20 #include "dex_cache.h"
21 
22 #include "art_field-inl.h"
23 #include "art_method-inl.h"
24 #include "base/logging.h"
25 #include "mirror/class.h"
26 #include "runtime.h"
27 
28 namespace art {
29 namespace mirror {
30 
ClassSize(size_t pointer_size)31 inline uint32_t DexCache::ClassSize(size_t pointer_size) {
32   uint32_t vtable_entries = Object::kVTableLength + 5;
33   return Class::ComputeClassSize(true, vtable_entries, 0, 0, 0, 0, 0, pointer_size);
34 }
35 
SetResolvedType(uint32_t type_idx,Class * resolved)36 inline void DexCache::SetResolvedType(uint32_t type_idx, Class* resolved) {
37   // TODO default transaction support.
38   DCHECK(resolved == nullptr || !resolved->IsErroneous());
39   GetResolvedTypes()->Set(type_idx, resolved);
40 }
41 
GetResolvedField(uint32_t idx,size_t ptr_size)42 inline ArtField* DexCache::GetResolvedField(uint32_t idx, size_t ptr_size) {
43   DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), ptr_size);
44   auto* field = GetResolvedFields()->GetElementPtrSize<ArtField*>(idx, ptr_size);
45   if (field == nullptr || field->GetDeclaringClass()->IsErroneous()) {
46     return nullptr;
47   }
48   return field;
49 }
50 
SetResolvedField(uint32_t idx,ArtField * field,size_t ptr_size)51 inline void DexCache::SetResolvedField(uint32_t idx, ArtField* field, size_t ptr_size) {
52   DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), ptr_size);
53   GetResolvedFields()->SetElementPtrSize(idx, field, ptr_size);
54 }
55 
GetResolvedMethod(uint32_t method_idx,size_t ptr_size)56 inline ArtMethod* DexCache::GetResolvedMethod(uint32_t method_idx, size_t ptr_size) {
57   DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), ptr_size);
58   auto* method = GetResolvedMethods()->GetElementPtrSize<ArtMethod*>(method_idx, ptr_size);
59   // Hide resolution trampoline methods from the caller
60   if (method != nullptr && method->IsRuntimeMethod()) {
61     DCHECK_EQ(method, Runtime::Current()->GetResolutionMethod());
62     return nullptr;
63   }
64   return method;
65 }
66 
SetResolvedMethod(uint32_t idx,ArtMethod * method,size_t ptr_size)67 inline void DexCache::SetResolvedMethod(uint32_t idx, ArtMethod* method, size_t ptr_size) {
68   DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), ptr_size);
69   GetResolvedMethods()->SetElementPtrSize(idx, method, ptr_size);
70 }
71 
72 }  // namespace mirror
73 }  // namespace art
74 
75 #endif  // ART_RUNTIME_MIRROR_DEX_CACHE_INL_H_
76