blob: 67cae8a7d9b5cfdbe8fc6840428bd57a4fba7e99 [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)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070027 REQUIRES_SHARED(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)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070034 REQUIRES_SHARED(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)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070053 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070054 ScopedQuickEntrypointChecks sqec(self);
Nicolas Geoffraye8e11272016-06-28 18:08:46 +010055 // We come from an explicit check in the generated code. This path is triggered
56 // only if the object is indeed null.
57 ThrowNullPointerExceptionFromDexPC(/* check_address */ false, 0U);
58 self->QuickDeliverException();
59}
60
61// Installed by a signal handler to throw a NPE exception.
62extern "C" NO_RETURN void artThrowNullPointerExceptionFromSignal(uintptr_t addr, Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070063 REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffraye8e11272016-06-28 18:08:46 +010064 ScopedQuickEntrypointChecks sqec(self);
Dave Allison648d7112014-07-25 16:15:27 -070065 self->NoteSignalBeingHandled();
Nicolas Geoffraye8e11272016-06-28 18:08:46 +010066 ThrowNullPointerExceptionFromDexPC(/* check_address */ true, addr);
Dave Allison648d7112014-07-25 16:15:27 -070067 self->NoteSignalHandlerDone();
jeffhao94d6df42012-11-26 16:02:12 -080068 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070069}
70
Vladimir Marko87f3fcb2016-04-28 15:52:11 +010071// Called by generated code to throw an arithmetic divide by zero exception.
Andreas Gampe65b798e2015-04-06 09:35:22 -070072extern "C" NO_RETURN void artThrowDivZeroFromCode(Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070073 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070074 ScopedQuickEntrypointChecks sqec(self);
Sebastien Hertz0a3b8632013-06-26 11:16:01 +020075 ThrowArithmeticExceptionDivideByZero();
Ian Rogers62d6c772013-02-27 08:32:07 -080076 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070077}
78
Vladimir Marko87f3fcb2016-04-28 15:52:11 +010079// Called by generated code to throw an array index out of bounds exception.
Andreas Gampe65b798e2015-04-06 09:35:22 -070080extern "C" NO_RETURN void artThrowArrayBoundsFromCode(int index, int length, Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070081 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070082 ScopedQuickEntrypointChecks sqec(self);
Ian Rogers62d6c772013-02-27 08:32:07 -080083 ThrowArrayIndexOutOfBoundsException(index, length);
84 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070085}
86
Vladimir Marko87f3fcb2016-04-28 15:52:11 +010087// Called by generated code to throw a string index out of bounds exception.
88extern "C" NO_RETURN void artThrowStringBoundsFromCode(int index, int length, Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070089 REQUIRES_SHARED(Locks::mutator_lock_) {
Vladimir Marko87f3fcb2016-04-28 15:52:11 +010090 ScopedQuickEntrypointChecks sqec(self);
91 ThrowStringIndexOutOfBoundsException(index, length);
92 self->QuickDeliverException();
93}
94
Andreas Gampe65b798e2015-04-06 09:35:22 -070095extern "C" NO_RETURN void artThrowStackOverflowFromCode(Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070096 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070097 ScopedQuickEntrypointChecks sqec(self);
Dave Allison648d7112014-07-25 16:15:27 -070098 self->NoteSignalBeingHandled();
jeffhaod7521322012-11-21 15:38:24 -080099 ThrowStackOverflowError(self);
Dave Allison648d7112014-07-25 16:15:27 -0700100 self->NoteSignalHandlerDone();
jeffhao94d6df42012-11-26 16:02:12 -0800101 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -0700102}
103
Andreas Gampe65b798e2015-04-06 09:35:22 -0700104extern "C" NO_RETURN void artThrowNoSuchMethodFromCode(int32_t method_idx, Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700105 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700106 ScopedQuickEntrypointChecks sqec(self);
Ian Rogers62d6c772013-02-27 08:32:07 -0800107 ThrowNoSuchMethodError(method_idx);
jeffhao94d6df42012-11-26 16:02:12 -0800108 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -0700109}
110
Andreas Gampe65b798e2015-04-06 09:35:22 -0700111extern "C" NO_RETURN void artThrowClassCastException(mirror::Class* dest_type,
112 mirror::Class* src_type,
113 Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700114 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700115 ScopedQuickEntrypointChecks sqec(self);
116 DCHECK(!dest_type->IsAssignableFrom(src_type));
Ian Rogersa9a82542013-10-04 11:17:26 -0700117 ThrowClassCastException(dest_type, src_type);
118 self->QuickDeliverException();
119}
120
Andreas Gampe65b798e2015-04-06 09:35:22 -0700121extern "C" NO_RETURN void artThrowArrayStoreException(mirror::Object* array, mirror::Object* value,
122 Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700123 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700124 ScopedQuickEntrypointChecks sqec(self);
Ian Rogersa9a82542013-10-04 11:17:26 -0700125 ThrowArrayStoreException(value->GetClass(), array->GetClass());
126 self->QuickDeliverException();
127}
128
Ian Rogers57b86d42012-03-27 16:05:41 -0700129} // namespace art