blob: 25df40b6c07e5a3edbe2e84a09f78476df97c553 [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.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070027extern "C" void artDeliverPendingExceptionFromCode(Thread* self)
Ian Rogersb726dcb2012-09-05 08:57:23 -070028 SHARED_LOCKS_REQUIRED(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.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070034extern "C" void artDeliverExceptionFromCode(mirror::Throwable* exception, Thread* self)
Ian Rogersb726dcb2012-09-05 08:57:23 -070035 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070036 /*
37 * exception may be NULL, in which case this routine should
38 * throw NPE. NOTE: this is a convenience for generated code,
39 * which previously did the null check inline and constructed
40 * and threw a NPE if NULL. This routine responsible for setting
41 * exception_ in thread and delivering the exception.
42 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070043 ScopedQuickEntrypointChecks sqec(self);
Ian Rogers62d6c772013-02-27 08:32:07 -080044 ThrowLocation throw_location = self->GetCurrentLocationForThrow();
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070045 if (exception == nullptr) {
Ian Rogers62d6c772013-02-27 08:32:07 -080046 self->ThrowNewException(throw_location, "Ljava/lang/NullPointerException;",
47 "throw with null exception");
48 } else {
49 self->SetException(throw_location, exception);
50 }
51 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070052}
53
54// Called by generated call to throw a NPE exception.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070055extern "C" void artThrowNullPointerExceptionFromCode(Thread* self)
Ian Rogersb726dcb2012-09-05 08:57:23 -070056 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070057 ScopedQuickEntrypointChecks sqec(self);
Dave Allison648d7112014-07-25 16:15:27 -070058 self->NoteSignalBeingHandled();
Ian Rogers62d6c772013-02-27 08:32:07 -080059 ThrowLocation throw_location = self->GetCurrentLocationForThrow();
60 ThrowNullPointerExceptionFromDexPC(throw_location);
Dave Allison648d7112014-07-25 16:15:27 -070061 self->NoteSignalHandlerDone();
jeffhao94d6df42012-11-26 16:02:12 -080062 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070063}
64
65// Called by generated call to throw an arithmetic divide by zero exception.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070066extern "C" void artThrowDivZeroFromCode(Thread* self)
Ian Rogersb726dcb2012-09-05 08:57:23 -070067 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070068 ScopedQuickEntrypointChecks sqec(self);
Sebastien Hertz0a3b8632013-06-26 11:16:01 +020069 ThrowArithmeticExceptionDivideByZero();
Ian Rogers62d6c772013-02-27 08:32:07 -080070 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070071}
72
73// Called by generated call to throw an array index out of bounds exception.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070074extern "C" void artThrowArrayBoundsFromCode(int index, int length, Thread* self)
Ian Rogersb726dcb2012-09-05 08:57:23 -070075 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070076 ScopedQuickEntrypointChecks sqec(self);
Ian Rogers62d6c772013-02-27 08:32:07 -080077 ThrowArrayIndexOutOfBoundsException(index, length);
78 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070079}
80
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070081extern "C" void artThrowStackOverflowFromCode(Thread* self)
Ian Rogersb726dcb2012-09-05 08:57:23 -070082 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070083 ScopedQuickEntrypointChecks sqec(self);
Dave Allison648d7112014-07-25 16:15:27 -070084 self->NoteSignalBeingHandled();
jeffhaod7521322012-11-21 15:38:24 -080085 ThrowStackOverflowError(self);
Dave Allison648d7112014-07-25 16:15:27 -070086 self->NoteSignalHandlerDone();
jeffhao94d6df42012-11-26 16:02:12 -080087 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070088}
89
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070090extern "C" void artThrowNoSuchMethodFromCode(int32_t method_idx, Thread* self)
Ian Rogersb726dcb2012-09-05 08:57:23 -070091 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070092 ScopedQuickEntrypointChecks sqec(self);
Ian Rogers62d6c772013-02-27 08:32:07 -080093 ThrowNoSuchMethodError(method_idx);
jeffhao94d6df42012-11-26 16:02:12 -080094 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070095}
96
Ian Rogersa9a82542013-10-04 11:17:26 -070097extern "C" void artThrowClassCastException(mirror::Class* dest_type, mirror::Class* src_type,
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070098 Thread* self)
Ian Rogersa9a82542013-10-04 11:17:26 -070099 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700100 ScopedQuickEntrypointChecks sqec(self);
101 DCHECK(!dest_type->IsAssignableFrom(src_type));
Ian Rogersa9a82542013-10-04 11:17:26 -0700102 ThrowClassCastException(dest_type, src_type);
103 self->QuickDeliverException();
104}
105
106extern "C" void artThrowArrayStoreException(mirror::Object* array, mirror::Object* value,
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700107 Thread* self)
Ian Rogersa9a82542013-10-04 11:17:26 -0700108 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700109 ScopedQuickEntrypointChecks sqec(self);
Ian Rogersa9a82542013-10-04 11:17:26 -0700110 ThrowArrayStoreException(value->GetClass(), array->GetClass());
111 self->QuickDeliverException();
112}
113
Ian Rogers57b86d42012-03-27 16:05:41 -0700114} // namespace art