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