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