blob: 40b43c1540709389e2ad65a38ac5a7a035bcbe21 [file] [log] [blame]
Shih-wei Liao2d831012011-09-28 22:06:53 -07001/*
Elliott Hughes0f3c5532012-03-30 14:51:51 -07002 * Copyright (C) 2012 The Android Open Source Project
Shih-wei Liao2d831012011-09-28 22:06:53 -07003 *
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#include "runtime_support.h"
18
19namespace art {
20
Ian Rogers57b86d42012-03-27 16:05:41 -070021void ThrowNewIllegalAccessErrorClass(Thread* self,
22 Class* referrer,
23 Class* accessed) {
24 self->ThrowNewExceptionF("Ljava/lang/IllegalAccessError;",
25 "illegal class access: '%s' -> '%s'",
26 PrettyDescriptor(referrer).c_str(),
27 PrettyDescriptor(accessed).c_str());
Shih-wei Liaoddbd01a2012-03-09 14:42:12 -080028}
29
Ian Rogers57b86d42012-03-27 16:05:41 -070030void ThrowNewIllegalAccessErrorClassForMethodDispatch(Thread* self,
31 Class* referrer,
32 Class* accessed,
33 const Method* caller,
34 const Method* called,
35 InvokeType type) {
36 std::ostringstream type_stream;
37 type_stream << type;
38 self->ThrowNewExceptionF("Ljava/lang/IllegalAccessError;",
39 "illegal class access ('%s' -> '%s')"
40 "in attempt to invoke %s method '%s' from '%s'",
41 PrettyDescriptor(referrer).c_str(),
42 PrettyDescriptor(accessed).c_str(),
43 type_stream.str().c_str(),
44 PrettyMethod(called).c_str(),
45 PrettyMethod(caller).c_str());
buzbee44b412b2012-02-04 08:50:53 -080046}
47
Ian Rogers57b86d42012-03-27 16:05:41 -070048void ThrowNewIncompatibleClassChangeErrorClassForInterfaceDispatch(Thread* self,
49 const Method* referrer,
50 const Method* interface_method,
51 Object* this_object) {
52 self->ThrowNewExceptionF("Ljava/lang/IncompatibleClassChangeError;",
53 "class '%s' does not implement interface '%s' in call to '%s' from '%s'",
54 PrettyDescriptor(this_object->GetClass()).c_str(),
55 PrettyDescriptor(interface_method->GetDeclaringClass()).c_str(),
56 PrettyMethod(interface_method).c_str(), PrettyMethod(referrer).c_str());
Shih-wei Liao2d831012011-09-28 22:06:53 -070057}
58
Ian Rogers57b86d42012-03-27 16:05:41 -070059void ThrowNewIllegalAccessErrorField(Thread* self,
60 Class* referrer,
61 Field* accessed) {
62 self->ThrowNewExceptionF("Ljava/lang/IllegalAccessError;",
63 "Field '%s' is inaccessible to class '%s'",
64 PrettyField(accessed, false).c_str(),
65 PrettyDescriptor(referrer).c_str());
Shih-wei Liao2d831012011-09-28 22:06:53 -070066}
67
Ian Rogers57b86d42012-03-27 16:05:41 -070068void ThrowNewIllegalAccessErrorFinalField(Thread* self,
69 const Method* referrer,
70 Field* accessed) {
71 self->ThrowNewExceptionF("Ljava/lang/IllegalAccessError;",
72 "Final field '%s' cannot be written to by method '%s'",
73 PrettyField(accessed, false).c_str(),
74 PrettyMethod(referrer).c_str());
Shih-wei Liao2d831012011-09-28 22:06:53 -070075}
76
Ian Rogers57b86d42012-03-27 16:05:41 -070077void ThrowNewIllegalAccessErrorMethod(Thread* self,
78 Class* referrer,
79 Method* accessed) {
80 self->ThrowNewExceptionF("Ljava/lang/IllegalAccessError;",
81 "Method '%s' is inaccessible to class '%s'",
82 PrettyMethod(accessed).c_str(),
83 PrettyDescriptor(referrer).c_str());
Shih-wei Liao2d831012011-09-28 22:06:53 -070084}
85
Ian Rogers57b86d42012-03-27 16:05:41 -070086void ThrowNullPointerExceptionForFieldAccess(Thread* self,
87 Field* field,
88 bool is_read) {
89 self->ThrowNewExceptionF("Ljava/lang/NullPointerException;",
90 "Attempt to %s field '%s' on a null object reference",
91 is_read ? "read from" : "write to",
92 PrettyField(field, true).c_str());
Shih-wei Liao2d831012011-09-28 22:06:53 -070093}
94
Ian Rogers57b86d42012-03-27 16:05:41 -070095void ThrowNullPointerExceptionForMethodAccess(Thread* self,
96 Method* caller,
97 uint32_t method_idx,
98 InvokeType type) {
99 const DexFile& dex_file =
100 Runtime::Current()->GetClassLinker()->FindDexFile(caller->GetDeclaringClass()->GetDexCache());
101 std::ostringstream type_stream;
102 type_stream << type;
103 self->ThrowNewExceptionF("Ljava/lang/NullPointerException;",
104 "Attempt to invoke %s method '%s' on a null object reference",
105 type_stream.str().c_str(),
106 PrettyMethod(method_idx, dex_file, true).c_str());
Shih-wei Liao2d831012011-09-28 22:06:53 -0700107}
108
TDYa1273f9137d2012-04-08 15:59:19 -0700109void ThrowNullPointerExceptionFromDexPC(Thread* self, Method* throw_method, uint32_t dex_pc) {
110 const DexFile::CodeItem* code = MethodHelper(throw_method).GetCodeItem();
111 CHECK_LT(dex_pc, code->insns_size_in_code_units_);
112 const Instruction* instr = Instruction::At(&code->insns_[dex_pc]);
113 DecodedInstruction dec_insn(instr);
114 switch (instr->Opcode()) {
115 case Instruction::INVOKE_DIRECT:
116 case Instruction::INVOKE_DIRECT_RANGE:
117 ThrowNullPointerExceptionForMethodAccess(self, throw_method, dec_insn.vB, kDirect);
118 break;
119 case Instruction::INVOKE_VIRTUAL:
120 case Instruction::INVOKE_VIRTUAL_RANGE:
121 ThrowNullPointerExceptionForMethodAccess(self, throw_method, dec_insn.vB, kVirtual);
122 break;
123 case Instruction::IGET:
124 case Instruction::IGET_WIDE:
125 case Instruction::IGET_OBJECT:
126 case Instruction::IGET_BOOLEAN:
127 case Instruction::IGET_BYTE:
128 case Instruction::IGET_CHAR:
129 case Instruction::IGET_SHORT: {
130 Field* field =
131 Runtime::Current()->GetClassLinker()->ResolveField(dec_insn.vC, throw_method, false);
132 ThrowNullPointerExceptionForFieldAccess(self, field, true /* read */);
133 break;
134 }
135 case Instruction::IPUT:
136 case Instruction::IPUT_WIDE:
137 case Instruction::IPUT_OBJECT:
138 case Instruction::IPUT_BOOLEAN:
139 case Instruction::IPUT_BYTE:
140 case Instruction::IPUT_CHAR:
141 case Instruction::IPUT_SHORT: {
142 Field* field =
143 Runtime::Current()->GetClassLinker()->ResolveField(dec_insn.vC, throw_method, false);
144 ThrowNullPointerExceptionForFieldAccess(self, field, false /* write */);
145 break;
146 }
147 case Instruction::AGET:
148 case Instruction::AGET_WIDE:
149 case Instruction::AGET_OBJECT:
150 case Instruction::AGET_BOOLEAN:
151 case Instruction::AGET_BYTE:
152 case Instruction::AGET_CHAR:
153 case Instruction::AGET_SHORT:
154 self->ThrowNewException("Ljava/lang/NullPointerException;",
155 "Attempt to read from null array");
156 break;
157 case Instruction::APUT:
158 case Instruction::APUT_WIDE:
159 case Instruction::APUT_OBJECT:
160 case Instruction::APUT_BOOLEAN:
161 case Instruction::APUT_BYTE:
162 case Instruction::APUT_CHAR:
163 case Instruction::APUT_SHORT:
164 self->ThrowNewException("Ljava/lang/NullPointerException;",
165 "Attempt to write to null array");
166 break;
167 default: {
168 const DexFile& dex_file = Runtime::Current()->GetClassLinker()
169 ->FindDexFile(throw_method->GetDeclaringClass()->GetDexCache());
170 std::string message("Null pointer exception during instruction '");
171 message += instr->DumpString(&dex_file);
172 message += "'";
173 self->ThrowNewException("Ljava/lang/NullPointerException;", message.c_str());
174 break;
175 }
176 }
177}
178
Ian Rogers57b86d42012-03-27 16:05:41 -0700179std::string FieldNameFromIndex(const Method* method, uint32_t ref,
180 verifier::VerifyErrorRefType ref_type, bool access) {
Ian Rogersd81871c2011-10-03 13:57:23 -0700181 CHECK_EQ(static_cast<int>(ref_type), static_cast<int>(verifier::VERIFY_ERROR_REF_FIELD));
Elliott Hughes6c8867d2011-10-03 16:34:05 -0700182
183 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
184 const DexFile& dex_file = class_linker->FindDexFile(method->GetDeclaringClass()->GetDexCache());
185
186 const DexFile::FieldId& id = dex_file.GetFieldId(ref);
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700187 std::string class_name(PrettyDescriptor(dex_file.GetFieldDeclaringClassDescriptor(id)));
Ian Rogers0571d352011-11-03 19:51:38 -0700188 const char* field_name = dex_file.StringDataByIdx(id.name_idx_);
Elliott Hughes6c8867d2011-10-03 16:34:05 -0700189 if (!access) {
190 return class_name + "." + field_name;
191 }
192
193 std::string result;
194 result += "tried to access field ";
195 result += class_name + "." + field_name;
196 result += " from class ";
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800197 result += PrettyDescriptor(method->GetDeclaringClass());
Elliott Hughes6c8867d2011-10-03 16:34:05 -0700198 return result;
199}
200
Ian Rogers57b86d42012-03-27 16:05:41 -0700201std::string MethodNameFromIndex(const Method* method, uint32_t ref,
202 verifier::VerifyErrorRefType ref_type, bool access) {
Ian Rogersd81871c2011-10-03 13:57:23 -0700203 CHECK_EQ(static_cast<int>(ref_type), static_cast<int>(verifier::VERIFY_ERROR_REF_METHOD));
Elliott Hughes6c8867d2011-10-03 16:34:05 -0700204
205 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
206 const DexFile& dex_file = class_linker->FindDexFile(method->GetDeclaringClass()->GetDexCache());
207
208 const DexFile::MethodId& id = dex_file.GetMethodId(ref);
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700209 std::string class_name(PrettyDescriptor(dex_file.GetMethodDeclaringClassDescriptor(id)));
Ian Rogers0571d352011-11-03 19:51:38 -0700210 const char* method_name = dex_file.StringDataByIdx(id.name_idx_);
Elliott Hughes6c8867d2011-10-03 16:34:05 -0700211 if (!access) {
212 return class_name + "." + method_name;
213 }
214
215 std::string result;
216 result += "tried to access method ";
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700217 result += class_name + "." + method_name + ":" +
Ian Rogers0571d352011-11-03 19:51:38 -0700218 dex_file.CreateMethodSignature(id.proto_idx_, NULL);
Elliott Hughes6c8867d2011-10-03 16:34:05 -0700219 result += " from class ";
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800220 result += PrettyDescriptor(method->GetDeclaringClass());
Elliott Hughes6c8867d2011-10-03 16:34:05 -0700221 return result;
222}
223
Ian Rogers57b86d42012-03-27 16:05:41 -0700224// Helper function to allocate array for FILLED_NEW_ARRAY.
225Array* CheckAndAllocArrayFromCode(uint32_t type_idx, Method* method, int32_t component_count,
226 Thread* self, bool access_check) {
227 if (UNLIKELY(component_count < 0)) {
228 self->ThrowNewExceptionF("Ljava/lang/NegativeArraySizeException;", "%d", component_count);
229 return NULL; // Failure
Elliott Hughes6c8867d2011-10-03 16:34:05 -0700230 }
Ian Rogers57b86d42012-03-27 16:05:41 -0700231 Class* klass = method->GetDexCacheResolvedTypes()->Get(type_idx);
232 if (UNLIKELY(klass == NULL)) { // Not in dex cache so try to resolve
233 klass = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, method);
234 if (klass == NULL) { // Error
235 DCHECK(Thread::Current()->IsExceptionPending());
236 return NULL; // Failure
Ian Rogers19846512012-02-24 11:42:47 -0800237 }
Ian Rogersea2a11d2011-10-11 16:48:51 -0700238 }
Ian Rogers57b86d42012-03-27 16:05:41 -0700239 if (UNLIKELY(klass->IsPrimitive() && !klass->IsPrimitiveInt())) {
240 if (klass->IsPrimitiveLong() || klass->IsPrimitiveDouble()) {
241 Thread::Current()->ThrowNewExceptionF("Ljava/lang/RuntimeException;",
242 "Bad filled array request for type %s",
243 PrettyDescriptor(klass).c_str());
Ian Rogers573db4a2011-12-13 15:30:50 -0800244 } else {
Ian Rogers57b86d42012-03-27 16:05:41 -0700245 Thread::Current()->ThrowNewExceptionF("Ljava/lang/InternalError;",
246 "Found type %s; filled-new-array not implemented for anything but \'int\'",
247 PrettyDescriptor(klass).c_str());
Ian Rogers573db4a2011-12-13 15:30:50 -0800248 }
Ian Rogers57b86d42012-03-27 16:05:41 -0700249 return NULL; // Failure
Ian Rogersad25ac52011-10-04 19:13:33 -0700250 } else {
Ian Rogers57b86d42012-03-27 16:05:41 -0700251 if (access_check) {
252 Class* referrer = method->GetDeclaringClass();
253 if (UNLIKELY(!referrer->CanAccess(klass))) {
254 ThrowNewIllegalAccessErrorClass(self, referrer, klass);
255 return NULL; // Failure
256 }
Ian Rogers60db5ab2012-02-20 17:02:00 -0800257 }
Ian Rogers57b86d42012-03-27 16:05:41 -0700258 DCHECK(klass->IsArrayClass()) << PrettyClass(klass);
259 return Array::Alloc(klass, component_count);
260 }
261}
262
263// Slow path field resolution and declaring class initialization
264Field* FindFieldFromCode(uint32_t field_idx, const Method* referrer, Thread* self,
265 bool is_static, bool is_primitive, bool is_set, size_t expected_size) {
266 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
267 Field* resolved_field = class_linker->ResolveField(field_idx, referrer, is_static);
268 if (UNLIKELY(resolved_field == NULL)) {
269 DCHECK(self->IsExceptionPending()); // Throw exception and unwind
270 return NULL; // failure
271 } else {
272 Class* fields_class = resolved_field->GetDeclaringClass();
273 Class* referring_class = referrer->GetDeclaringClass();
274 if (UNLIKELY(!referring_class->CanAccess(fields_class))) {
275 ThrowNewIllegalAccessErrorClass(self, referring_class, fields_class);
276 return NULL; // failure
277 } else if (UNLIKELY(!referring_class->CanAccessMember(fields_class,
278 resolved_field->GetAccessFlags()))) {
279 ThrowNewIllegalAccessErrorField(self, referring_class, resolved_field);
280 return NULL; // failure
281 } else if (UNLIKELY(is_set && resolved_field->IsFinal() && (fields_class != referring_class))) {
282 ThrowNewIllegalAccessErrorFinalField(self, referrer, resolved_field);
283 return NULL; // failure
284 } else {
285 FieldHelper fh(resolved_field);
286 if (UNLIKELY(fh.IsPrimitiveType() != is_primitive ||
287 fh.FieldSize() != expected_size)) {
288 self->ThrowNewExceptionF("Ljava/lang/NoSuchFieldError;",
289 "Attempted read of %zd-bit %s on field '%s'",
290 expected_size * (32 / sizeof(int32_t)),
291 is_primitive ? "primitive" : "non-primitive",
292 PrettyField(resolved_field, true).c_str());
293 return NULL; // failure
294 } else if (!is_static) {
295 // instance fields must be being accessed on an initialized class
296 return resolved_field;
Ian Rogers60db5ab2012-02-20 17:02:00 -0800297 } else {
Ian Rogers57b86d42012-03-27 16:05:41 -0700298 // If the class is already initializing, we must be inside <clinit>, or
299 // we'd still be waiting for the lock.
300 if (fields_class->IsInitializing()) {
301 return resolved_field;
Ian Rogers0045a292012-03-31 21:08:41 -0700302 } else if (Runtime::Current()->GetClassLinker()->EnsureInitialized(fields_class, true, true)) {
Ian Rogers57b86d42012-03-27 16:05:41 -0700303 return resolved_field;
Ian Rogers60db5ab2012-02-20 17:02:00 -0800304 } else {
Ian Rogers57b86d42012-03-27 16:05:41 -0700305 DCHECK(self->IsExceptionPending()); // Throw exception and unwind
306 return NULL; // failure
Ian Rogers60db5ab2012-02-20 17:02:00 -0800307 }
308 }
Ian Rogers57b86d42012-03-27 16:05:41 -0700309 }
310 }
311}
312
313// Slow path method resolution
314Method* FindMethodFromCode(uint32_t method_idx, Object* this_object, const Method* referrer,
315 Thread* self, bool access_check, InvokeType type) {
316 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
317 bool is_direct = type == kStatic || type == kDirect;
318 Method* resolved_method = class_linker->ResolveMethod(method_idx, referrer, is_direct);
319 if (UNLIKELY(resolved_method == NULL)) {
320 DCHECK(self->IsExceptionPending()); // Throw exception and unwind
321 return NULL; // failure
322 } else {
323 if (!access_check) {
324 if (is_direct) {
325 return resolved_method;
326 } else if (type == kInterface) {
327 Method* interface_method =
328 this_object->GetClass()->FindVirtualMethodForInterface(resolved_method);
329 if (UNLIKELY(interface_method == NULL)) {
330 ThrowNewIncompatibleClassChangeErrorClassForInterfaceDispatch(self, referrer,
331 resolved_method,
332 this_object);
333 return NULL; // failure
334 } else {
335 return interface_method;
336 }
Ian Rogers60db5ab2012-02-20 17:02:00 -0800337 } else {
Ian Rogers57b86d42012-03-27 16:05:41 -0700338 ObjectArray<Method>* vtable;
339 uint16_t vtable_index = resolved_method->GetMethodIndex();
340 if (type == kSuper) {
341 vtable = referrer->GetDeclaringClass()->GetSuperClass()->GetVTable();
342 } else {
343 vtable = this_object->GetClass()->GetVTable();
344 }
345 // TODO: eliminate bounds check?
346 return vtable->Get(vtable_index);
347 }
348 } else {
349 Class* methods_class = resolved_method->GetDeclaringClass();
350 Class* referring_class = referrer->GetDeclaringClass();
351 if (UNLIKELY(!referring_class->CanAccess(methods_class) ||
352 !referring_class->CanAccessMember(methods_class,
353 resolved_method->GetAccessFlags()))) {
354 // The referring class can't access the resolved method, this may occur as a result of a
355 // protected method being made public by implementing an interface that re-declares the
356 // method public. Resort to the dex file to determine the correct class for the access check
357 const DexFile& dex_file = class_linker->FindDexFile(referring_class->GetDexCache());
358 methods_class = class_linker->ResolveType(dex_file,
359 dex_file.GetMethodId(method_idx).class_idx_,
360 referring_class);
361 if (UNLIKELY(!referring_class->CanAccess(methods_class))) {
362 ThrowNewIllegalAccessErrorClassForMethodDispatch(self, referring_class, methods_class,
363 referrer, resolved_method, type);
364 return NULL; // failure
365 } else if (UNLIKELY(!referring_class->CanAccessMember(methods_class,
366 resolved_method->GetAccessFlags()))) {
367 ThrowNewIllegalAccessErrorMethod(self, referring_class, resolved_method);
368 return NULL; // failure
369 }
370 }
371 if (is_direct) {
372 return resolved_method;
373 } else if (type == kInterface) {
374 Method* interface_method =
375 this_object->GetClass()->FindVirtualMethodForInterface(resolved_method);
376 if (UNLIKELY(interface_method == NULL)) {
377 ThrowNewIncompatibleClassChangeErrorClassForInterfaceDispatch(self, referrer,
378 resolved_method,
379 this_object);
380 return NULL; // failure
381 } else {
382 return interface_method;
383 }
384 } else {
385 ObjectArray<Method>* vtable;
386 uint16_t vtable_index = resolved_method->GetMethodIndex();
387 if (type == kSuper) {
388 Class* super_class = referring_class->GetSuperClass();
389 if (LIKELY(super_class != NULL)) {
390 vtable = referring_class->GetSuperClass()->GetVTable();
391 } else {
392 vtable = NULL;
393 }
394 } else {
395 vtable = this_object->GetClass()->GetVTable();
396 }
397 if (LIKELY(vtable != NULL &&
398 vtable_index < static_cast<uint32_t>(vtable->GetLength()))) {
399 return vtable->GetWithoutChecks(vtable_index);
400 } else {
401 // Behavior to agree with that of the verifier
402 self->ThrowNewExceptionF("Ljava/lang/NoSuchMethodError;",
403 "attempt to invoke %s method '%s' from '%s'"
404 " using incorrect form of method dispatch",
405 (type == kSuper ? "super class" : "virtual"),
406 PrettyMethod(resolved_method).c_str(),
407 PrettyMethod(referrer).c_str());
408 return NULL; // failure
409 }
Ian Rogers60db5ab2012-02-20 17:02:00 -0800410 }
411 }
412 }
Ian Rogers60db5ab2012-02-20 17:02:00 -0800413}
414
Ian Rogers57b86d42012-03-27 16:05:41 -0700415Class* ResolveVerifyAndClinit(uint32_t type_idx, const Method* referrer, Thread* self,
416 bool can_run_clinit, bool verify_access) {
417 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
418 Class* klass = class_linker->ResolveType(type_idx, referrer);
419 if (UNLIKELY(klass == NULL)) {
jeffhao441d9122012-03-21 17:29:10 -0700420 CHECK(self->IsExceptionPending());
Ian Rogers57b86d42012-03-27 16:05:41 -0700421 return NULL; // Failure - Indicate to caller to deliver exception
jeffhao441d9122012-03-21 17:29:10 -0700422 }
Ian Rogers57b86d42012-03-27 16:05:41 -0700423 // Perform access check if necessary.
424 Class* referring_class = referrer->GetDeclaringClass();
425 if (verify_access && UNLIKELY(!referring_class->CanAccess(klass))) {
426 ThrowNewIllegalAccessErrorClass(self, referring_class, klass);
427 return NULL; // Failure - Indicate to caller to deliver exception
Ian Rogers14b1b242011-10-11 18:54:34 -0700428 }
Ian Rogers57b86d42012-03-27 16:05:41 -0700429 // If we're just implementing const-class, we shouldn't call <clinit>.
430 if (!can_run_clinit) {
431 return klass;
Ian Rogersdfcdf1a2011-10-10 17:50:35 -0700432 }
Ian Rogers57b86d42012-03-27 16:05:41 -0700433 // If we are the <clinit> of this class, just return our storage.
434 //
435 // Do not set the DexCache InitializedStaticStorage, since that implies <clinit> has finished
436 // running.
437 if (klass == referring_class && MethodHelper(referrer).IsClassInitializer()) {
438 return klass;
Ian Rogersdfcdf1a2011-10-10 17:50:35 -0700439 }
Ian Rogers0045a292012-03-31 21:08:41 -0700440 if (!class_linker->EnsureInitialized(klass, true, true)) {
Ian Rogers57b86d42012-03-27 16:05:41 -0700441 CHECK(self->IsExceptionPending());
442 return NULL; // Failure - Indicate to caller to deliver exception
Ian Rogersdfcdf1a2011-10-10 17:50:35 -0700443 }
Ian Rogers57b86d42012-03-27 16:05:41 -0700444 referrer->GetDexCacheInitializedStaticStorage()->Set(type_idx, klass);
445 return klass;
Shih-wei Liao2d831012011-09-28 22:06:53 -0700446}
447
448} // namespace art