1 /*
2 * Copyright (C) 2012 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 #include "art_method-inl.h"
18 #include "callee_save_frame.h"
19 #include "common_throws.h"
20 #include "mirror/object-inl.h"
21 #include "thread.h"
22 #include "well_known_classes.h"
23
24 namespace art {
25
26 // Deliver an exception that's pending on thread helping set up a callee save frame on the way.
artDeliverPendingExceptionFromCode(Thread * self)27 extern "C" NO_RETURN void artDeliverPendingExceptionFromCode(Thread* self)
28 REQUIRES_SHARED(Locks::mutator_lock_) {
29 ScopedQuickEntrypointChecks sqec(self);
30 self->QuickDeliverException();
31 }
32
artInvokeObsoleteMethod(ArtMethod * method,Thread * self)33 extern "C" NO_RETURN uint64_t artInvokeObsoleteMethod(ArtMethod* method, Thread* self)
34 REQUIRES_SHARED(Locks::mutator_lock_) {
35 DCHECK(method->IsObsolete());
36 ScopedQuickEntrypointChecks sqec(self);
37 ThrowInternalError("Attempting to invoke obsolete version of '%s'.",
38 method->PrettyMethod().c_str());
39 self->QuickDeliverException();
40 }
41
42 // Called by generated code to throw an exception.
artDeliverExceptionFromCode(mirror::Throwable * exception,Thread * self)43 extern "C" NO_RETURN void artDeliverExceptionFromCode(mirror::Throwable* exception, Thread* self)
44 REQUIRES_SHARED(Locks::mutator_lock_) {
45 /*
46 * exception may be null, in which case this routine should
47 * throw NPE. NOTE: this is a convenience for generated code,
48 * which previously did the null check inline and constructed
49 * and threw a NPE if null. This routine responsible for setting
50 * exception_ in thread and delivering the exception.
51 */
52 ScopedQuickEntrypointChecks sqec(self);
53 if (exception == nullptr) {
54 self->ThrowNewException("Ljava/lang/NullPointerException;", "throw with null exception");
55 } else {
56 self->SetException(exception);
57 }
58 self->QuickDeliverException();
59 }
60
61 // Called by generated code to throw a NPE exception.
artThrowNullPointerExceptionFromCode(Thread * self)62 extern "C" NO_RETURN void artThrowNullPointerExceptionFromCode(Thread* self)
63 REQUIRES_SHARED(Locks::mutator_lock_) {
64 ScopedQuickEntrypointChecks sqec(self);
65 // We come from an explicit check in the generated code. This path is triggered
66 // only if the object is indeed null.
67 ThrowNullPointerExceptionFromDexPC(/* check_address */ false, 0U);
68 self->QuickDeliverException();
69 }
70
71 // Installed by a signal handler to throw a NPE exception.
artThrowNullPointerExceptionFromSignal(uintptr_t addr,Thread * self)72 extern "C" NO_RETURN void artThrowNullPointerExceptionFromSignal(uintptr_t addr, Thread* self)
73 REQUIRES_SHARED(Locks::mutator_lock_) {
74 ScopedQuickEntrypointChecks sqec(self);
75 ThrowNullPointerExceptionFromDexPC(/* check_address */ true, addr);
76 self->QuickDeliverException();
77 }
78
79 // Called by generated code to throw an arithmetic divide by zero exception.
artThrowDivZeroFromCode(Thread * self)80 extern "C" NO_RETURN void artThrowDivZeroFromCode(Thread* self)
81 REQUIRES_SHARED(Locks::mutator_lock_) {
82 ScopedQuickEntrypointChecks sqec(self);
83 ThrowArithmeticExceptionDivideByZero();
84 self->QuickDeliverException();
85 }
86
87 // Called by generated code to throw an array index out of bounds exception.
artThrowArrayBoundsFromCode(int index,int length,Thread * self)88 extern "C" NO_RETURN void artThrowArrayBoundsFromCode(int index, int length, Thread* self)
89 REQUIRES_SHARED(Locks::mutator_lock_) {
90 ScopedQuickEntrypointChecks sqec(self);
91 ThrowArrayIndexOutOfBoundsException(index, length);
92 self->QuickDeliverException();
93 }
94
95 // Called by generated code to throw a string index out of bounds exception.
artThrowStringBoundsFromCode(int index,int length,Thread * self)96 extern "C" NO_RETURN void artThrowStringBoundsFromCode(int index, int length, Thread* self)
97 REQUIRES_SHARED(Locks::mutator_lock_) {
98 ScopedQuickEntrypointChecks sqec(self);
99 ThrowStringIndexOutOfBoundsException(index, length);
100 self->QuickDeliverException();
101 }
102
artThrowStackOverflowFromCode(Thread * self)103 extern "C" NO_RETURN void artThrowStackOverflowFromCode(Thread* self)
104 REQUIRES_SHARED(Locks::mutator_lock_) {
105 ScopedQuickEntrypointChecks sqec(self);
106 ThrowStackOverflowError(self);
107 self->QuickDeliverException();
108 }
109
artThrowClassCastException(mirror::Class * dest_type,mirror::Class * src_type,Thread * self)110 extern "C" NO_RETURN void artThrowClassCastException(mirror::Class* dest_type,
111 mirror::Class* src_type,
112 Thread* self)
113 REQUIRES_SHARED(Locks::mutator_lock_) {
114 ScopedQuickEntrypointChecks sqec(self);
115 DCHECK(!dest_type->IsAssignableFrom(src_type));
116 ThrowClassCastException(dest_type, src_type);
117 self->QuickDeliverException();
118 }
119
artThrowClassCastExceptionForObject(mirror::Object * obj,mirror::Class * dest_type,Thread * self)120 extern "C" NO_RETURN void artThrowClassCastExceptionForObject(mirror::Object* obj,
121 mirror::Class* dest_type,
122 Thread* self)
123 REQUIRES_SHARED(Locks::mutator_lock_) {
124 DCHECK(obj != nullptr);
125 artThrowClassCastException(dest_type, obj->GetClass(), self);
126 }
127
artThrowArrayStoreException(mirror::Object * array,mirror::Object * value,Thread * self)128 extern "C" NO_RETURN void artThrowArrayStoreException(mirror::Object* array, mirror::Object* value,
129 Thread* self)
130 REQUIRES_SHARED(Locks::mutator_lock_) {
131 ScopedQuickEntrypointChecks sqec(self);
132 ThrowArrayStoreException(value->GetClass(), array->GetClass());
133 self->QuickDeliverException();
134 }
135
136 } // namespace art
137