blob: 565b4edcc327d2db6ad39999e201656dcfc3b1f6 [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
Alex Lightdb01a092017-04-03 15:39:55 -070032extern "C" NO_RETURN uint64_t artInvokeObsoleteMethod(ArtMethod* method, Thread* self)
33 REQUIRES_SHARED(Locks::mutator_lock_) {
34 DCHECK(method->IsObsolete());
35 ScopedQuickEntrypointChecks sqec(self);
36 ThrowInternalError("Attempting to invoke obsolete version of '%s'.",
37 method->PrettyMethod().c_str());
38 self->QuickDeliverException();
39}
40
Vladimir Marko87f3fcb2016-04-28 15:52:11 +010041// Called by generated code to throw an exception.
Andreas Gampe65b798e2015-04-06 09:35:22 -070042extern "C" NO_RETURN void artDeliverExceptionFromCode(mirror::Throwable* exception, Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070043 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070044 /*
Mathieu Chartier2cebb242015-04-21 16:50:40 -070045 * exception may be null, in which case this routine should
Ian Rogers57b86d42012-03-27 16:05:41 -070046 * throw NPE. NOTE: this is a convenience for generated code,
47 * which previously did the null check inline and constructed
Mathieu Chartier2cebb242015-04-21 16:50:40 -070048 * and threw a NPE if null. This routine responsible for setting
Ian Rogers57b86d42012-03-27 16:05:41 -070049 * exception_ in thread and delivering the exception.
50 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070051 ScopedQuickEntrypointChecks sqec(self);
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070052 if (exception == nullptr) {
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000053 self->ThrowNewException("Ljava/lang/NullPointerException;", "throw with null exception");
Ian Rogers62d6c772013-02-27 08:32:07 -080054 } else {
Nicolas Geoffray14691c52015-03-05 10:40:17 +000055 self->SetException(exception);
Ian Rogers62d6c772013-02-27 08:32:07 -080056 }
57 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070058}
59
Vladimir Marko87f3fcb2016-04-28 15:52:11 +010060// Called by generated code to throw a NPE exception.
Andreas Gampe65b798e2015-04-06 09:35:22 -070061extern "C" NO_RETURN void artThrowNullPointerExceptionFromCode(Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070062 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070063 ScopedQuickEntrypointChecks sqec(self);
Nicolas Geoffraye8e11272016-06-28 18:08:46 +010064 // We come from an explicit check in the generated code. This path is triggered
65 // only if the object is indeed null.
66 ThrowNullPointerExceptionFromDexPC(/* check_address */ false, 0U);
67 self->QuickDeliverException();
68}
69
70// Installed by a signal handler to throw a NPE exception.
71extern "C" NO_RETURN void artThrowNullPointerExceptionFromSignal(uintptr_t addr, Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070072 REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffraye8e11272016-06-28 18:08:46 +010073 ScopedQuickEntrypointChecks sqec(self);
Nicolas Geoffraye8e11272016-06-28 18:08:46 +010074 ThrowNullPointerExceptionFromDexPC(/* check_address */ true, addr);
jeffhao94d6df42012-11-26 16:02:12 -080075 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070076}
77
Vladimir Marko87f3fcb2016-04-28 15:52:11 +010078// Called by generated code to throw an arithmetic divide by zero exception.
Andreas Gampe65b798e2015-04-06 09:35:22 -070079extern "C" NO_RETURN void artThrowDivZeroFromCode(Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070080 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070081 ScopedQuickEntrypointChecks sqec(self);
Sebastien Hertz0a3b8632013-06-26 11:16:01 +020082 ThrowArithmeticExceptionDivideByZero();
Ian Rogers62d6c772013-02-27 08:32:07 -080083 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070084}
85
Vladimir Marko87f3fcb2016-04-28 15:52:11 +010086// Called by generated code to throw an array index out of bounds exception.
Andreas Gampe65b798e2015-04-06 09:35:22 -070087extern "C" NO_RETURN void artThrowArrayBoundsFromCode(int index, int length, Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070088 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070089 ScopedQuickEntrypointChecks sqec(self);
Ian Rogers62d6c772013-02-27 08:32:07 -080090 ThrowArrayIndexOutOfBoundsException(index, length);
91 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070092}
93
Vladimir Marko87f3fcb2016-04-28 15:52:11 +010094// Called by generated code to throw a string index out of bounds exception.
95extern "C" NO_RETURN void artThrowStringBoundsFromCode(int index, int length, Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070096 REQUIRES_SHARED(Locks::mutator_lock_) {
Vladimir Marko87f3fcb2016-04-28 15:52:11 +010097 ScopedQuickEntrypointChecks sqec(self);
98 ThrowStringIndexOutOfBoundsException(index, length);
99 self->QuickDeliverException();
100}
101
Andreas Gampe65b798e2015-04-06 09:35:22 -0700102extern "C" NO_RETURN void artThrowStackOverflowFromCode(Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700103 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700104 ScopedQuickEntrypointChecks sqec(self);
jeffhaod7521322012-11-21 15:38:24 -0800105 ThrowStackOverflowError(self);
jeffhao94d6df42012-11-26 16:02:12 -0800106 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -0700107}
108
Andreas Gampe65b798e2015-04-06 09:35:22 -0700109extern "C" NO_RETURN void artThrowClassCastException(mirror::Class* dest_type,
110 mirror::Class* src_type,
111 Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700112 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700113 ScopedQuickEntrypointChecks sqec(self);
114 DCHECK(!dest_type->IsAssignableFrom(src_type));
Ian Rogersa9a82542013-10-04 11:17:26 -0700115 ThrowClassCastException(dest_type, src_type);
116 self->QuickDeliverException();
117}
118
Mathieu Chartierb99f4d62016-11-07 16:17:26 -0800119extern "C" NO_RETURN void artThrowClassCastExceptionForObject(mirror::Object* obj,
120 mirror::Class* dest_type,
121 Thread* self)
122 REQUIRES_SHARED(Locks::mutator_lock_) {
123 DCHECK(obj != nullptr);
124 artThrowClassCastException(dest_type, obj->GetClass(), self);
125}
126
Andreas Gampe65b798e2015-04-06 09:35:22 -0700127extern "C" NO_RETURN void artThrowArrayStoreException(mirror::Object* array, mirror::Object* value,
128 Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700129 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700130 ScopedQuickEntrypointChecks sqec(self);
Ian Rogersa9a82542013-10-04 11:17:26 -0700131 ThrowArrayStoreException(value->GetClass(), array->GetClass());
132 self->QuickDeliverException();
133}
134
Ian Rogers57b86d42012-03-27 16:05:41 -0700135} // namespace art