blob: 879010e36e4a8c346c6a6b88aa2226adb0fc20bb [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);
Ian Rogers62d6c772013-02-27 08:32:07 -080061 ThrowLocation throw_location = self->GetCurrentLocationForThrow();
62 ThrowNullPointerExceptionFromDexPC(throw_location);
jeffhao94d6df42012-11-26 16:02:12 -080063 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070064}
65
66// Called by generated call to throw an arithmetic divide by zero exception.
Andreas Gampecf4035a2014-05-28 22:43:01 -070067extern "C" void artThrowDivZeroFromCode(Thread* self, StackReference<mirror::ArtMethod>* sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070068 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers62d6c772013-02-27 08:32:07 -080069 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
Sebastien Hertz0a3b8632013-06-26 11:16:01 +020070 ThrowArithmeticExceptionDivideByZero();
Ian Rogers62d6c772013-02-27 08:32:07 -080071 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070072}
73
74// Called by generated call to throw an array index out of bounds exception.
Ian Rogers62d6c772013-02-27 08:32:07 -080075extern "C" void artThrowArrayBoundsFromCode(int index, int length, Thread* self,
Andreas Gampecf4035a2014-05-28 22:43:01 -070076 StackReference<mirror::ArtMethod>*sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070077 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers62d6c772013-02-27 08:32:07 -080078 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
79 ThrowArrayIndexOutOfBoundsException(index, length);
80 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070081}
82
Andreas Gampecf4035a2014-05-28 22:43:01 -070083extern "C" void artThrowStackOverflowFromCode(Thread* self, StackReference<mirror::ArtMethod>* sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070084 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers120f1c72012-09-28 17:17:10 -070085 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
jeffhaod7521322012-11-21 15:38:24 -080086 ThrowStackOverflowError(self);
jeffhao94d6df42012-11-26 16:02:12 -080087 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070088}
89
Mathieu Chartier66f19252012-09-18 08:57:04 -070090extern "C" void artThrowNoSuchMethodFromCode(int32_t method_idx, Thread* self,
Andreas Gampecf4035a2014-05-28 22:43:01 -070091 StackReference<mirror::ArtMethod>* sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070092 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070093 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
Ian Rogers62d6c772013-02-27 08:32:07 -080094 ThrowNoSuchMethodError(method_idx);
jeffhao94d6df42012-11-26 16:02:12 -080095 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070096}
97
Ian Rogersa9a82542013-10-04 11:17:26 -070098extern "C" void artThrowClassCastException(mirror::Class* dest_type, mirror::Class* src_type,
Andreas Gampecf4035a2014-05-28 22:43:01 -070099 Thread* self, StackReference<mirror::ArtMethod>* sp)
Ian Rogersa9a82542013-10-04 11:17:26 -0700100 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
101 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
102 CHECK(!dest_type->IsAssignableFrom(src_type));
103 ThrowClassCastException(dest_type, src_type);
104 self->QuickDeliverException();
105}
106
107extern "C" void artThrowArrayStoreException(mirror::Object* array, mirror::Object* value,
Andreas Gampecf4035a2014-05-28 22:43:01 -0700108 Thread* self, StackReference<mirror::ArtMethod>* sp)
Ian Rogersa9a82542013-10-04 11:17:26 -0700109 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
110 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
111 ThrowArrayStoreException(value->GetClass(), array->GetClass());
112 self->QuickDeliverException();
113}
114
Ian Rogers57b86d42012-03-27 16:05:41 -0700115} // namespace art