blob: 3bfa2f2611b1f0d6a568a5b407a0c8828c749cce [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 Rogers7655f292013-07-29 11:07:13 -070018#include "entrypoints/entrypoint_utils.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019#include "mirror/object.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070020#include "object_utils.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 Rogers2dd0e2c2013-01-24 12:42:14 -080027extern "C" void artDeliverPendingExceptionFromCode(Thread* thread, mirror::AbstractMethod** sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070028 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070029 FinishCalleeSaveFrameSetup(thread, sp, Runtime::kSaveAll);
jeffhao94d6df42012-11-26 16:02:12 -080030 thread->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070031}
32
33// Called by generated call to throw an exception.
Ian Rogers62d6c772013-02-27 08:32:07 -080034extern "C" void artDeliverExceptionFromCode(mirror::Throwable* exception, Thread* self,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035 mirror::AbstractMethod** sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070036 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070037 /*
38 * exception may be NULL, in which case this routine should
39 * throw NPE. NOTE: this is a convenience for generated code,
40 * which previously did the null check inline and constructed
41 * and threw a NPE if NULL. This routine responsible for setting
42 * exception_ in thread and delivering the exception.
43 */
Ian Rogers62d6c772013-02-27 08:32:07 -080044 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
45 ThrowLocation throw_location = self->GetCurrentLocationForThrow();
46 if (exception == NULL) {
47 self->ThrowNewException(throw_location, "Ljava/lang/NullPointerException;",
48 "throw with null exception");
49 } else {
50 self->SetException(throw_location, exception);
51 }
52 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070053}
54
55// Called by generated call to throw a NPE exception.
Mathieu Chartier66f19252012-09-18 08:57:04 -070056extern "C" void artThrowNullPointerExceptionFromCode(Thread* self,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080057 mirror::AbstractMethod** sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070058 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070059 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
Ian Rogers62d6c772013-02-27 08:32:07 -080060 ThrowLocation throw_location = self->GetCurrentLocationForThrow();
61 ThrowNullPointerExceptionFromDexPC(throw_location);
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 Rogers62d6c772013-02-27 08:32:07 -080066extern "C" void artThrowDivZeroFromCode(Thread* self,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080067 mirror::AbstractMethod** 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,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080076 mirror::AbstractMethod** 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
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080083extern "C" void artThrowStackOverflowFromCode(Thread* self, mirror::AbstractMethod** 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,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080091 mirror::AbstractMethod** 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 Rogers57b86d42012-03-27 16:05:41 -070098} // namespace art