blob: 80ba118d9617a60cfefbd49cb1e2f5e38b6259b1 [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 Rogers2dd0e2c2013-01-24 12:42:14 -080018#include "mirror/object.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070019#include "object_utils.h"
20#include "runtime_support.h"
21#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
Ian Rogers474b6da2012-09-25 00:20:38 -070026// Used to implement MOVE_EXCEPTION.
27extern "C" void* GetAndClearException(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
28 DCHECK(self->IsExceptionPending());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080029 mirror::Throwable* exception = self->GetException();
Ian Rogers474b6da2012-09-25 00:20:38 -070030 self->ClearException();
31 return exception;
32}
33
Ian Rogers57b86d42012-03-27 16:05:41 -070034// 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 -080035extern "C" void artDeliverPendingExceptionFromCode(Thread* thread, 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 FinishCalleeSaveFrameSetup(thread, sp, Runtime::kSaveAll);
jeffhao94d6df42012-11-26 16:02:12 -080038 thread->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070039}
40
41// Called by generated call to throw an exception.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080042extern "C" void artDeliverExceptionFromCode(mirror::Throwable* exception, Thread* thread,
43 mirror::AbstractMethod** sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070044 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070045 /*
46 * exception may be NULL, in which case this routine should
47 * throw NPE. NOTE: this is a convenience for generated code,
48 * which previously did the null check inline and constructed
49 * and threw a NPE if NULL. This routine responsible for setting
50 * exception_ in thread and delivering the exception.
51 */
52 FinishCalleeSaveFrameSetup(thread, sp, Runtime::kSaveAll);
jeffhao94d6df42012-11-26 16:02:12 -080053 thread->DeliverException(exception);
54 thread->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,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080059 mirror::AbstractMethod** 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 Rogers0399dde2012-06-06 17:09:28 -070062 uint32_t dex_pc;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080063 mirror::AbstractMethod* throw_method = self->GetCurrentMethod(&dex_pc);
Ian Rogers87e552d2012-08-31 15:54:48 -070064 ThrowNullPointerExceptionFromDexPC(throw_method, dex_pc);
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.
Mathieu Chartier66f19252012-09-18 08:57:04 -070069extern "C" void artThrowDivZeroFromCode(Thread* thread,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080070 mirror::AbstractMethod** sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070071 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070072 FinishCalleeSaveFrameSetup(thread, sp, Runtime::kSaveAll);
73 thread->ThrowNewException("Ljava/lang/ArithmeticException;", "divide by zero");
jeffhao94d6df42012-11-26 16:02:12 -080074 thread->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070075}
76
77// Called by generated call to throw an array index out of bounds exception.
Mathieu Chartier66f19252012-09-18 08:57:04 -070078extern "C" void artThrowArrayBoundsFromCode(int index, int limit, Thread* thread,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080079 mirror::AbstractMethod** sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070080 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070081 FinishCalleeSaveFrameSetup(thread, sp, Runtime::kSaveAll);
82 thread->ThrowNewExceptionF("Ljava/lang/ArrayIndexOutOfBoundsException;",
83 "length=%d; index=%d", limit, index);
jeffhao94d6df42012-11-26 16:02:12 -080084 thread->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -070085}
86
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080087extern "C" void artThrowStackOverflowFromCode(Thread* self, mirror::AbstractMethod** sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070088 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers120f1c72012-09-28 17:17:10 -070089 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
jeffhaod7521322012-11-21 15:38:24 -080090 ThrowStackOverflowError(self);
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,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080095 mirror::AbstractMethod** 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 Rogers2dd0e2c2013-01-24 12:42:14 -080098 mirror::AbstractMethod* method = self->GetCurrentMethod();
Ian Rogers87e552d2012-08-31 15:54:48 -070099 ThrowNoSuchMethodError(method_idx, method);
jeffhao94d6df42012-11-26 16:02:12 -0800100 self->QuickDeliverException();
Ian Rogers57b86d42012-03-27 16:05:41 -0700101}
102
Ian Rogers57b86d42012-03-27 16:05:41 -0700103} // namespace art