blob: 2778e32ece23acec90dada31476a41cad2ad7c04 [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"
Ian Rogersa9a82542013-10-04 11:17:26 -070019#include "mirror/object-inl.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070020#include "thread.h"
Ian Rogers120f1c72012-09-28 17:17:10 -070021#include "well_known_classes.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070022
23namespace art {
24
25// 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 -070026extern "C" NO_RETURN void artDeliverPendingExceptionFromCode(Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -070027 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070028 ScopedQuickEntrypointChecks sqec(self);
29 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070030}
31
Vladimir Marko87f3fcb2016-04-28 15:52:11 +010032// Called by generated code to throw an exception.
Andreas Gampe65b798e2015-04-06 09:35:22 -070033extern "C" NO_RETURN void artDeliverExceptionFromCode(mirror::Throwable* exception, Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -070034 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070035 /*
Mathieu Chartier2cebb242015-04-21 16:50:40 -070036 * exception may be null, in which case this routine should
Ian Rogers57b86d42012-03-27 16:05:41 -070037 * throw NPE. NOTE: this is a convenience for generated code,
38 * which previously did the null check inline and constructed
Mathieu Chartier2cebb242015-04-21 16:50:40 -070039 * and threw a NPE if null. This routine responsible for setting
Ian Rogers57b86d42012-03-27 16:05:41 -070040 * exception_ in thread and delivering the exception.
41 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070042 ScopedQuickEntrypointChecks sqec(self);
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070043 if (exception == nullptr) {
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000044 self->ThrowNewException("Ljava/lang/NullPointerException;", "throw with null exception");
Ian Rogers62d6c772013-02-27 08:32:07 -080045 } else {
Nicolas Geoffray14691c52015-03-05 10:40:17 +000046 self->SetException(exception);
Ian Rogers62d6c772013-02-27 08:32:07 -080047 }
48 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070049}
50
Vladimir Marko87f3fcb2016-04-28 15:52:11 +010051// Called by generated code to throw a NPE exception.
Andreas Gampe65b798e2015-04-06 09:35:22 -070052extern "C" NO_RETURN void artThrowNullPointerExceptionFromCode(Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -070053 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070054 ScopedQuickEntrypointChecks sqec(self);
Dave Allison648d7112014-07-25 16:15:27 -070055 self->NoteSignalBeingHandled();
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000056 ThrowNullPointerExceptionFromDexPC();
Dave Allison648d7112014-07-25 16:15:27 -070057 self->NoteSignalHandlerDone();
jeffhao94d6df42012-11-26 16:02:12 -080058 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070059}
60
Vladimir Marko87f3fcb2016-04-28 15:52:11 +010061// Called by generated code to throw an arithmetic divide by zero exception.
Andreas Gampe65b798e2015-04-06 09:35:22 -070062extern "C" NO_RETURN void artThrowDivZeroFromCode(Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -070063 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070064 ScopedQuickEntrypointChecks sqec(self);
Sebastien Hertz0a3b8632013-06-26 11:16:01 +020065 ThrowArithmeticExceptionDivideByZero();
Ian Rogers62d6c772013-02-27 08:32:07 -080066 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070067}
68
Vladimir Marko87f3fcb2016-04-28 15:52:11 +010069// Called by generated code to throw an array index out of bounds exception.
Andreas Gampe65b798e2015-04-06 09:35:22 -070070extern "C" NO_RETURN void artThrowArrayBoundsFromCode(int index, int length, Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -070071 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070072 ScopedQuickEntrypointChecks sqec(self);
Ian Rogers62d6c772013-02-27 08:32:07 -080073 ThrowArrayIndexOutOfBoundsException(index, length);
74 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070075}
76
Vladimir Marko87f3fcb2016-04-28 15:52:11 +010077// Called by generated code to throw a string index out of bounds exception.
78extern "C" NO_RETURN void artThrowStringBoundsFromCode(int index, int length, Thread* self)
79 SHARED_REQUIRES(Locks::mutator_lock_) {
80 ScopedQuickEntrypointChecks sqec(self);
81 ThrowStringIndexOutOfBoundsException(index, length);
82 self->QuickDeliverException();
83}
84
Andreas Gampe65b798e2015-04-06 09:35:22 -070085extern "C" NO_RETURN void artThrowStackOverflowFromCode(Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -070086 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070087 ScopedQuickEntrypointChecks sqec(self);
Dave Allison648d7112014-07-25 16:15:27 -070088 self->NoteSignalBeingHandled();
jeffhaod7521322012-11-21 15:38:24 -080089 ThrowStackOverflowError(self);
Dave Allison648d7112014-07-25 16:15:27 -070090 self->NoteSignalHandlerDone();
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 artThrowNoSuchMethodFromCode(int32_t method_idx, Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -070095 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070096 ScopedQuickEntrypointChecks sqec(self);
Ian Rogers62d6c772013-02-27 08:32:07 -080097 ThrowNoSuchMethodError(method_idx);
jeffhao94d6df42012-11-26 16:02:12 -080098 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070099}
100
Andreas Gampe65b798e2015-04-06 09:35:22 -0700101extern "C" NO_RETURN void artThrowClassCastException(mirror::Class* dest_type,
102 mirror::Class* src_type,
103 Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -0700104 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700105 ScopedQuickEntrypointChecks sqec(self);
106 DCHECK(!dest_type->IsAssignableFrom(src_type));
Ian Rogersa9a82542013-10-04 11:17:26 -0700107 ThrowClassCastException(dest_type, src_type);
108 self->QuickDeliverException();
109}
110
Andreas Gampe65b798e2015-04-06 09:35:22 -0700111extern "C" NO_RETURN void artThrowArrayStoreException(mirror::Object* array, mirror::Object* value,
112 Thread* self)
Mathieu Chartier90443472015-07-16 20:32:27 -0700113 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700114 ScopedQuickEntrypointChecks sqec(self);
Ian Rogersa9a82542013-10-04 11:17:26 -0700115 ThrowArrayStoreException(value->GetClass(), array->GetClass());
116 self->QuickDeliverException();
117}
118
Ian Rogers57b86d42012-03-27 16:05:41 -0700119} // namespace art