blob: 4d01b66f0a92ca8a6d8aaddb6c253cbf736b6526 [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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_CLASS_LINKER_INL_H_
18#define ART_RUNTIME_CLASS_LINKER_INL_H_
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019
20#include "class_linker.h"
21
22#include "mirror/dex_cache.h"
23#include "mirror/field.h"
24#include "mirror/iftable.h"
25#include "mirror/object_array.h"
26
27namespace art {
28
29inline mirror::String* ClassLinker::ResolveString(uint32_t string_idx,
30 const mirror::AbstractMethod* referrer) {
31 mirror::String* resolved_string = referrer->GetDexCacheStrings()->Get(string_idx);
32 if (UNLIKELY(resolved_string == NULL)) {
33 mirror::Class* declaring_class = referrer->GetDeclaringClass();
34 mirror::DexCache* dex_cache = declaring_class->GetDexCache();
35 const DexFile& dex_file = *dex_cache->GetDexFile();
36 resolved_string = ResolveString(dex_file, string_idx, dex_cache);
37 }
38 return resolved_string;
39}
40
41inline mirror::Class* ClassLinker::ResolveType(uint16_t type_idx,
42 const mirror::AbstractMethod* referrer) {
43 mirror::Class* resolved_type = referrer->GetDexCacheResolvedTypes()->Get(type_idx);
44 if (UNLIKELY(resolved_type == NULL)) {
45 mirror::Class* declaring_class = referrer->GetDeclaringClass();
46 mirror::DexCache* dex_cache = declaring_class->GetDexCache();
47 mirror::ClassLoader* class_loader = declaring_class->GetClassLoader();
48 const DexFile& dex_file = *dex_cache->GetDexFile();
49 resolved_type = ResolveType(dex_file, type_idx, dex_cache, class_loader);
50 }
51 return resolved_type;
52}
53
54inline mirror::Class* ClassLinker::ResolveType(uint16_t type_idx, const mirror::Field* referrer) {
55 mirror::Class* declaring_class = referrer->GetDeclaringClass();
56 mirror::DexCache* dex_cache = declaring_class->GetDexCache();
57 mirror::Class* resolved_type = dex_cache->GetResolvedType(type_idx);
58 if (UNLIKELY(resolved_type == NULL)) {
59 mirror::ClassLoader* class_loader = declaring_class->GetClassLoader();
60 const DexFile& dex_file = *dex_cache->GetDexFile();
61 resolved_type = ResolveType(dex_file, type_idx, dex_cache, class_loader);
62 }
63 return resolved_type;
64}
65
66inline mirror::AbstractMethod* ClassLinker::ResolveMethod(uint32_t method_idx,
67 const mirror::AbstractMethod* referrer,
68 InvokeType type) {
69 mirror::AbstractMethod* resolved_method =
70 referrer->GetDexCacheResolvedMethods()->Get(method_idx);
71 if (UNLIKELY(resolved_method == NULL || resolved_method->IsRuntimeMethod())) {
72 mirror::Class* declaring_class = referrer->GetDeclaringClass();
73 mirror::DexCache* dex_cache = declaring_class->GetDexCache();
74 mirror::ClassLoader* class_loader = declaring_class->GetClassLoader();
75 const DexFile& dex_file = *dex_cache->GetDexFile();
76 resolved_method = ResolveMethod(dex_file, method_idx, dex_cache, class_loader, referrer, type);
77 }
78 return resolved_method;
79}
80
81inline mirror::Field* ClassLinker::ResolveField(uint32_t field_idx,
82 const mirror::AbstractMethod* referrer,
83 bool is_static) {
84 mirror::Field* resolved_field =
85 referrer->GetDeclaringClass()->GetDexCache()->GetResolvedField(field_idx);
86 if (UNLIKELY(resolved_field == NULL)) {
87 mirror::Class* declaring_class = referrer->GetDeclaringClass();
88 mirror::DexCache* dex_cache = declaring_class->GetDexCache();
89 mirror::ClassLoader* class_loader = declaring_class->GetClassLoader();
90 const DexFile& dex_file = *dex_cache->GetDexFile();
91 resolved_field = ResolveField(dex_file, field_idx, dex_cache, class_loader, is_static);
92 }
93 return resolved_field;
94}
95
96template <class T>
97inline mirror::ObjectArray<T>* ClassLinker::AllocObjectArray(Thread* self, size_t length) {
98 return mirror::ObjectArray<T>::Alloc(self, GetClassRoot(kObjectArrayClass), length);
99}
100
101inline mirror::ObjectArray<mirror::Class>* ClassLinker::AllocClassArray(Thread* self,
102 size_t length) {
103 return mirror::ObjectArray<mirror::Class>::Alloc(self, GetClassRoot(kClassArrayClass), length);
104}
105
106inline mirror::ObjectArray<mirror::String>* ClassLinker::AllocStringArray(Thread* self,
107 size_t length) {
108 return mirror::ObjectArray<mirror::String>::Alloc(self, GetClassRoot(kJavaLangStringArrayClass),
109 length);
110}
111
112inline mirror::ObjectArray<mirror::AbstractMethod>* ClassLinker::AllocAbstractMethodArray(Thread* self,
113 size_t length) {
114 return mirror::ObjectArray<mirror::AbstractMethod>::Alloc(self,
115 GetClassRoot(kJavaLangReflectAbstractMethodArrayClass), length);
116}
117
118inline mirror::ObjectArray<mirror::AbstractMethod>* ClassLinker::AllocMethodArray(Thread* self,
119 size_t length) {
120 return mirror::ObjectArray<mirror::AbstractMethod>::Alloc(self,
121 GetClassRoot(kJavaLangReflectMethodArrayClass), length);
122}
123
124inline mirror::IfTable* ClassLinker::AllocIfTable(Thread* self, size_t ifcount) {
125 return down_cast<mirror::IfTable*>(
126 mirror::IfTable::Alloc(self, GetClassRoot(kObjectArrayClass), ifcount * mirror::IfTable::kMax));
127}
128
129inline mirror::ObjectArray<mirror::Field>* ClassLinker::AllocFieldArray(Thread* self,
130 size_t length) {
131 return mirror::ObjectArray<mirror::Field>::Alloc(self,
132 GetClassRoot(kJavaLangReflectFieldArrayClass),
133 length);
134}
135
136inline mirror::Class* ClassLinker::GetClassRoot(ClassRoot class_root)
137 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
138 DCHECK(class_roots_ != NULL);
139 mirror::Class* klass = class_roots_->Get(class_root);
140 DCHECK(klass != NULL);
141 return klass;
142}
143
144} // namespace art
145
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700146#endif // ART_RUNTIME_CLASS_LINKER_INL_H_