blob: e6f294ace7302978634d7df56b6b2827a64c7367 [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 Rogers7655f292013-07-29 11:07:13 -070019#include "entrypoints/entrypoint_utils.h"
Ian Rogersa9a82542013-10-04 11:17:26 -070020#include "mirror/object-inl.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070021#include "object_utils.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070022#include "thread.h"
Ian Rogers120f1c72012-09-28 17:17:10 -070023#include "well_known_classes.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070024
25namespace art {
26
27// Deliver an exception that's pending on thread helping set up a callee save frame on the way.
Andreas Gampecf4035a2014-05-28 22:43:01 -070028extern "C" void artDeliverPendingExceptionFromCode(Thread* thread,
29 StackReference<mirror::ArtMethod>* sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070030 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070031 FinishCalleeSaveFrameSetup(thread, sp, Runtime::kSaveAll);
jeffhao94d6df42012-11-26 16:02:12 -080032 thread->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070033}
34
35// Called by generated call to throw an exception.
Ian Rogers62d6c772013-02-27 08:32:07 -080036extern "C" void artDeliverExceptionFromCode(mirror::Throwable* exception, Thread* self,
Andreas Gampecf4035a2014-05-28 22:43:01 -070037 StackReference<mirror::ArtMethod>* sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070038 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070039 /*
40 * exception may be NULL, in which case this routine should
41 * throw NPE. NOTE: this is a convenience for generated code,
42 * which previously did the null check inline and constructed
43 * and threw a NPE if NULL. This routine responsible for setting
44 * exception_ in thread and delivering the exception.
45 */
Ian Rogers62d6c772013-02-27 08:32:07 -080046 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
47 ThrowLocation throw_location = self->GetCurrentLocationForThrow();
48 if (exception == NULL) {
49 self->ThrowNewException(throw_location, "Ljava/lang/NullPointerException;",
50 "throw with null exception");
51 } else {
52 self->SetException(throw_location, exception);
53 }
54 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070055}
56
57// Called by generated call to throw a NPE exception.
Mathieu Chartier66f19252012-09-18 08:57:04 -070058extern "C" void artThrowNullPointerExceptionFromCode(Thread* self,
Andreas Gampecf4035a2014-05-28 22:43:01 -070059 StackReference<mirror::ArtMethod>* sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070060 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070061 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
Ian Rogers62d6c772013-02-27 08:32:07 -080062 ThrowLocation throw_location = self->GetCurrentLocationForThrow();
63 ThrowNullPointerExceptionFromDexPC(throw_location);
jeffhao94d6df42012-11-26 16:02:12 -080064 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070065}
66
67// Called by generated call to throw an arithmetic divide by zero exception.
Andreas Gampecf4035a2014-05-28 22:43:01 -070068extern "C" void artThrowDivZeroFromCode(Thread* self, StackReference<mirror::ArtMethod>* sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070069 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers62d6c772013-02-27 08:32:07 -080070 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
Sebastien Hertz0a3b8632013-06-26 11:16:01 +020071 ThrowArithmeticExceptionDivideByZero();
Ian Rogers62d6c772013-02-27 08:32:07 -080072 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070073}
74
75// Called by generated call to throw an array index out of bounds exception.
Ian Rogers62d6c772013-02-27 08:32:07 -080076extern "C" void artThrowArrayBoundsFromCode(int index, int length, Thread* self,
Andreas Gampecf4035a2014-05-28 22:43:01 -070077 StackReference<mirror::ArtMethod>*sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070078 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers62d6c772013-02-27 08:32:07 -080079 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
80 ThrowArrayIndexOutOfBoundsException(index, length);
81 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070082}
83
Andreas Gampecf4035a2014-05-28 22:43:01 -070084extern "C" void artThrowStackOverflowFromCode(Thread* self, StackReference<mirror::ArtMethod>* sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070085 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers120f1c72012-09-28 17:17:10 -070086 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
jeffhaod7521322012-11-21 15:38:24 -080087 ThrowStackOverflowError(self);
jeffhao94d6df42012-11-26 16:02:12 -080088 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070089}
90
Mathieu Chartier66f19252012-09-18 08:57:04 -070091extern "C" void artThrowNoSuchMethodFromCode(int32_t method_idx, Thread* self,
Andreas Gampecf4035a2014-05-28 22:43:01 -070092 StackReference<mirror::ArtMethod>* sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070093 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070094 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
Ian Rogers62d6c772013-02-27 08:32:07 -080095 ThrowNoSuchMethodError(method_idx);
jeffhao94d6df42012-11-26 16:02:12 -080096 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070097}
98
Ian Rogersa9a82542013-10-04 11:17:26 -070099extern "C" void artThrowClassCastException(mirror::Class* dest_type, mirror::Class* src_type,
Andreas Gampecf4035a2014-05-28 22:43:01 -0700100 Thread* self, StackReference<mirror::ArtMethod>* sp)
Ian Rogersa9a82542013-10-04 11:17:26 -0700101 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
102 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
103 CHECK(!dest_type->IsAssignableFrom(src_type));
104 ThrowClassCastException(dest_type, src_type);
105 self->QuickDeliverException();
106}
107
108extern "C" void artThrowArrayStoreException(mirror::Object* array, mirror::Object* value,
Andreas Gampecf4035a2014-05-28 22:43:01 -0700109 Thread* self, StackReference<mirror::ArtMethod>* sp)
Ian Rogersa9a82542013-10-04 11:17:26 -0700110 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
111 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
112 ThrowArrayStoreException(value->GetClass(), array->GetClass());
113 self->QuickDeliverException();
114}
115
Ian Rogers57b86d42012-03-27 16:05:41 -0700116} // namespace art