blob: 5a82b3ae2e192b9090119c6027df9d362395b452 [file] [log] [blame]
Ian Rogers57b86d42012-03-27 16:05:41 -07001/*
Elliott Hughes0f3c5532012-03-30 14:51:51 -07002 * Copyright (C) 2012 The Android Open Source Project
Ian Rogers57b86d42012-03-27 16:05:41 -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 "callee_save_frame.h"
Ian Rogersa9a82542013-10-04 11:17:26 -070018#include "common_throws.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070019#include "entrypoints/entrypoint_utils-inl.h"
Ian Rogersa9a82542013-10-04 11:17:26 -070020#include "mirror/object-inl.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070021#include "thread.h"
Ian Rogers120f1c72012-09-28 17:17:10 -070022#include "well_known_classes.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070023
24namespace art {
25
26// Deliver an exception that's pending on thread helping set up a callee save frame on the way.
Andreas Gampe65b798e2015-04-06 09:35:22 -070027extern "C" NO_RETURN void artDeliverPendingExceptionFromCode(Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -070028 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070029 ScopedQuickEntrypointChecks sqec(self);
30 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070031}
32
33// Called by generated call to throw an exception.
Andreas Gampe65b798e2015-04-06 09:35:22 -070034extern "C" NO_RETURN void artDeliverExceptionFromCode(mirror::Throwable* exception, Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -070035 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070036 /*
Mathieu Chartier2cebb242015-04-21 16:50:40 -070037 * exception may be null, in which case this routine should
Ian Rogers57b86d42012-03-27 16:05:41 -070038 * throw NPE. NOTE: this is a convenience for generated code,
39 * which previously did the null check inline and constructed
Mathieu Chartier2cebb242015-04-21 16:50:40 -070040 * and threw a NPE if null. This routine responsible for setting
Ian Rogers57b86d42012-03-27 16:05:41 -070041 * exception_ in thread and delivering the exception.
42 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070043 ScopedQuickEntrypointChecks sqec(self);
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070044 if (exception == nullptr) {
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000045 self->ThrowNewException("Ljava/lang/NullPointerException;", "throw with null exception");
Ian Rogers62d6c772013-02-27 08:32:07 -080046 } else {
Nicolas Geoffray14691c52015-03-05 10:40:17 +000047 self->SetException(exception);
Ian Rogers62d6c772013-02-27 08:32:07 -080048 }
49 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070050}
51
52// Called by generated call to throw a NPE exception.
Andreas Gampe65b798e2015-04-06 09:35:22 -070053extern "C" NO_RETURN void artThrowNullPointerExceptionFromCode(Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -070054 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070055 ScopedQuickEntrypointChecks sqec(self);
Dave Allison648d7112014-07-25 16:15:27 -070056 self->NoteSignalBeingHandled();
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000057 ThrowNullPointerExceptionFromDexPC();
Dave Allison648d7112014-07-25 16:15:27 -070058 self->NoteSignalHandlerDone();
jeffhao94d6df42012-11-26 16:02:12 -080059 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070060}
61
62// Called by generated call to throw an arithmetic divide by zero exception.
Andreas Gampe65b798e2015-04-06 09:35:22 -070063extern "C" NO_RETURN void artThrowDivZeroFromCode(Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -070064 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070065 ScopedQuickEntrypointChecks sqec(self);
Sebastien Hertz0a3b8632013-06-26 11:16:01 +020066 ThrowArithmeticExceptionDivideByZero();
Ian Rogers62d6c772013-02-27 08:32:07 -080067 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070068}
69
70// Called by generated call to throw an array index out of bounds exception.
Andreas Gampe65b798e2015-04-06 09:35:22 -070071extern "C" NO_RETURN void artThrowArrayBoundsFromCode(int index, int length, Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -070072 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070073 ScopedQuickEntrypointChecks sqec(self);
Ian Rogers62d6c772013-02-27 08:32:07 -080074 ThrowArrayIndexOutOfBoundsException(index, length);
75 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070076}
77
Andreas Gampe65b798e2015-04-06 09:35:22 -070078extern "C" NO_RETURN void artThrowStackOverflowFromCode(Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -070079 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070080 ScopedQuickEntrypointChecks sqec(self);
Dave Allison648d7112014-07-25 16:15:27 -070081 self->NoteSignalBeingHandled();
jeffhaod7521322012-11-21 15:38:24 -080082 ThrowStackOverflowError(self);
Dave Allison648d7112014-07-25 16:15:27 -070083 self->NoteSignalHandlerDone();
jeffhao94d6df42012-11-26 16:02:12 -080084 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070085}
86
Andreas Gampe65b798e2015-04-06 09:35:22 -070087extern "C" NO_RETURN void artThrowNoSuchMethodFromCode(int32_t method_idx, Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -070088 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070089 ScopedQuickEntrypointChecks sqec(self);
Ian Rogers62d6c772013-02-27 08:32:07 -080090 ThrowNoSuchMethodError(method_idx);
jeffhao94d6df42012-11-26 16:02:12 -080091 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070092}
93
Andreas Gampe65b798e2015-04-06 09:35:22 -070094extern "C" NO_RETURN void artThrowClassCastException(mirror::Class* dest_type,
95 mirror::Class* src_type,
96 Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -070097 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070098 ScopedQuickEntrypointChecks sqec(self);
99 DCHECK(!dest_type->IsAssignableFrom(src_type));
Ian Rogersa9a82542013-10-04 11:17:26 -0700100 ThrowClassCastException(dest_type, src_type);
101 self->QuickDeliverException();
102}
103
Andreas Gampe65b798e2015-04-06 09:35:22 -0700104extern "C" NO_RETURN void artThrowArrayStoreException(mirror::Object* array, mirror::Object* value,
105 Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -0700106 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700107 ScopedQuickEntrypointChecks sqec(self);
Ian Rogersa9a82542013-10-04 11:17:26 -0700108 ThrowArrayStoreException(value->GetClass(), array->GetClass());
109 self->QuickDeliverException();
110}
111
Ian Rogers57b86d42012-03-27 16:05:41 -0700112} // namespace art