blob: 13decc8068404553782c654e8fb26c2a410dec11 [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.
Andreas Gampecf4035a2014-05-28 22:43:01 -070027extern "C" void artDeliverPendingExceptionFromCode(Thread* thread,
28 StackReference<mirror::ArtMethod>* sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070029 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070030 FinishCalleeSaveFrameSetup(thread, sp, Runtime::kSaveAll);
jeffhao94d6df42012-11-26 16:02:12 -080031 thread->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070032}
33
34// Called by generated call to throw an exception.
Ian Rogers62d6c772013-02-27 08:32:07 -080035extern "C" void artDeliverExceptionFromCode(mirror::Throwable* exception, Thread* self,
Andreas Gampecf4035a2014-05-28 22:43:01 -070036 StackReference<mirror::ArtMethod>* sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070037 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070038 /*
39 * exception may be NULL, in which case this routine should
40 * throw NPE. NOTE: this is a convenience for generated code,
41 * which previously did the null check inline and constructed
42 * and threw a NPE if NULL. This routine responsible for setting
43 * exception_ in thread and delivering the exception.
44 */
Ian Rogers62d6c772013-02-27 08:32:07 -080045 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
46 ThrowLocation throw_location = self->GetCurrentLocationForThrow();
47 if (exception == NULL) {
48 self->ThrowNewException(throw_location, "Ljava/lang/NullPointerException;",
49 "throw with null exception");
50 } else {
51 self->SetException(throw_location, exception);
52 }
53 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070054}
55
56// Called by generated call to throw a NPE exception.
Mathieu Chartier66f19252012-09-18 08:57:04 -070057extern "C" void artThrowNullPointerExceptionFromCode(Thread* self,
Andreas Gampecf4035a2014-05-28 22:43:01 -070058 StackReference<mirror::ArtMethod>* sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070059 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070060 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
Dave Allison648d7112014-07-25 16:15:27 -070061 self->NoteSignalBeingHandled();
Ian Rogers62d6c772013-02-27 08:32:07 -080062 ThrowLocation throw_location = self->GetCurrentLocationForThrow();
63 ThrowNullPointerExceptionFromDexPC(throw_location);
Dave Allison648d7112014-07-25 16:15:27 -070064 self->NoteSignalHandlerDone();
jeffhao94d6df42012-11-26 16:02:12 -080065 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070066}
67
68// Called by generated call to throw an arithmetic divide by zero exception.
Andreas Gampecf4035a2014-05-28 22:43:01 -070069extern "C" void artThrowDivZeroFromCode(Thread* self, StackReference<mirror::ArtMethod>* sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070070 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers62d6c772013-02-27 08:32:07 -080071 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
Sebastien Hertz0a3b8632013-06-26 11:16:01 +020072 ThrowArithmeticExceptionDivideByZero();
Ian Rogers62d6c772013-02-27 08:32:07 -080073 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070074}
75
76// Called by generated call to throw an array index out of bounds exception.
Ian Rogers62d6c772013-02-27 08:32:07 -080077extern "C" void artThrowArrayBoundsFromCode(int index, int length, Thread* self,
Andreas Gampecf4035a2014-05-28 22:43:01 -070078 StackReference<mirror::ArtMethod>*sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070079 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers62d6c772013-02-27 08:32:07 -080080 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
81 ThrowArrayIndexOutOfBoundsException(index, length);
82 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070083}
84
Andreas Gampecf4035a2014-05-28 22:43:01 -070085extern "C" void artThrowStackOverflowFromCode(Thread* self, StackReference<mirror::ArtMethod>* sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070086 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers120f1c72012-09-28 17:17:10 -070087 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
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
Mathieu Chartier66f19252012-09-18 08:57:04 -070094extern "C" void artThrowNoSuchMethodFromCode(int32_t method_idx, Thread* self,
Andreas Gampecf4035a2014-05-28 22:43:01 -070095 StackReference<mirror::ArtMethod>* sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070096 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070097 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
Ian Rogers62d6c772013-02-27 08:32:07 -080098 ThrowNoSuchMethodError(method_idx);
jeffhao94d6df42012-11-26 16:02:12 -080099 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -0700100}
101
Ian Rogersa9a82542013-10-04 11:17:26 -0700102extern "C" void artThrowClassCastException(mirror::Class* dest_type, mirror::Class* src_type,
Andreas Gampecf4035a2014-05-28 22:43:01 -0700103 Thread* self, StackReference<mirror::ArtMethod>* sp)
Ian Rogersa9a82542013-10-04 11:17:26 -0700104 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
105 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
106 CHECK(!dest_type->IsAssignableFrom(src_type));
107 ThrowClassCastException(dest_type, src_type);
108 self->QuickDeliverException();
109}
110
111extern "C" void artThrowArrayStoreException(mirror::Object* array, mirror::Object* value,
Andreas Gampecf4035a2014-05-28 22:43:01 -0700112 Thread* self, StackReference<mirror::ArtMethod>* sp)
Ian Rogersa9a82542013-10-04 11:17:26 -0700113 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
114 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
115 ThrowArrayStoreException(value->GetClass(), array->GetClass());
116 self->QuickDeliverException();
117}
118
Ian Rogers57b86d42012-03-27 16:05:41 -0700119} // namespace art