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 "entrypoints/entrypoint_utils-inl.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     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
29   ScopedQuickEntrypointChecks sqec(self);
30   self->QuickDeliverException();
31 }
32 
33 // Called by generated call to throw an exception.
artDeliverExceptionFromCode(mirror::Throwable * exception,Thread * self)34 extern "C" NO_RETURN void artDeliverExceptionFromCode(mirror::Throwable* exception, Thread* self)
35     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
36   /*
37    * exception may be null, in which case this routine should
38    * throw NPE.  NOTE: this is a convenience for generated code,
39    * which previously did the null check inline and constructed
40    * and threw a NPE if null.  This routine responsible for setting
41    * exception_ in thread and delivering the exception.
42    */
43   ScopedQuickEntrypointChecks sqec(self);
44   if (exception == nullptr) {
45     self->ThrowNewException("Ljava/lang/NullPointerException;", "throw with null exception");
46   } else {
47     self->SetException(exception);
48   }
49   self->QuickDeliverException();
50 }
51 
52 // Called by generated call to throw a NPE exception.
artThrowNullPointerExceptionFromCode(Thread * self)53 extern "C" NO_RETURN void artThrowNullPointerExceptionFromCode(Thread* self)
54     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
55   ScopedQuickEntrypointChecks sqec(self);
56   self->NoteSignalBeingHandled();
57   ThrowNullPointerExceptionFromDexPC();
58   self->NoteSignalHandlerDone();
59   self->QuickDeliverException();
60 }
61 
62 // Called by generated call to throw an arithmetic divide by zero exception.
artThrowDivZeroFromCode(Thread * self)63 extern "C" NO_RETURN void artThrowDivZeroFromCode(Thread* self)
64     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
65   ScopedQuickEntrypointChecks sqec(self);
66   ThrowArithmeticExceptionDivideByZero();
67   self->QuickDeliverException();
68 }
69 
70 // Called by generated call to throw an array index out of bounds exception.
artThrowArrayBoundsFromCode(int index,int length,Thread * self)71 extern "C" NO_RETURN void artThrowArrayBoundsFromCode(int index, int length, Thread* self)
72     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
73   ScopedQuickEntrypointChecks sqec(self);
74   ThrowArrayIndexOutOfBoundsException(index, length);
75   self->QuickDeliverException();
76 }
77 
artThrowStackOverflowFromCode(Thread * self)78 extern "C" NO_RETURN void artThrowStackOverflowFromCode(Thread* self)
79     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
80   ScopedQuickEntrypointChecks sqec(self);
81   self->NoteSignalBeingHandled();
82   ThrowStackOverflowError(self);
83   self->NoteSignalHandlerDone();
84   self->QuickDeliverException();
85 }
86 
artThrowNoSuchMethodFromCode(int32_t method_idx,Thread * self)87 extern "C" NO_RETURN void artThrowNoSuchMethodFromCode(int32_t method_idx, Thread* self)
88     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
89   ScopedQuickEntrypointChecks sqec(self);
90   ThrowNoSuchMethodError(method_idx);
91   self->QuickDeliverException();
92 }
93 
artThrowClassCastException(mirror::Class * dest_type,mirror::Class * src_type,Thread * self)94 extern "C" NO_RETURN void artThrowClassCastException(mirror::Class* dest_type,
95                                                      mirror::Class* src_type,
96                                                      Thread* self)
97     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
98   ScopedQuickEntrypointChecks sqec(self);
99   DCHECK(!dest_type->IsAssignableFrom(src_type));
100   ThrowClassCastException(dest_type, src_type);
101   self->QuickDeliverException();
102 }
103 
artThrowArrayStoreException(mirror::Object * array,mirror::Object * value,Thread * self)104 extern "C" NO_RETURN void artThrowArrayStoreException(mirror::Object* array, mirror::Object* value,
105                                                       Thread* self)
106     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
107   ScopedQuickEntrypointChecks sqec(self);
108   ThrowArrayStoreException(value->GetClass(), array->GetClass());
109   self->QuickDeliverException();
110 }
111 
112 }  // namespace art
113