Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 1 | /* |
Elliott Hughes | 0f3c553 | 2012-03-30 14:51:51 -0700 | [diff] [blame] | 2 | * Copyright (C) 2012 The Android Open Source Project |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 3 | * |
| 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 Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 18 | #include "common_throws.h" |
Ian Rogers | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 19 | #include "entrypoints/entrypoint_utils.h" |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 20 | #include "mirror/object-inl.h" |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 21 | #include "object_utils.h" |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 22 | #include "thread.h" |
Ian Rogers | 120f1c7 | 2012-09-28 17:17:10 -0700 | [diff] [blame] | 23 | #include "well_known_classes.h" |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | // Deliver an exception that's pending on thread helping set up a callee save frame on the way. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 28 | extern "C" void artDeliverPendingExceptionFromCode(Thread* thread, mirror::ArtMethod** sp) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 29 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 30 | FinishCalleeSaveFrameSetup(thread, sp, Runtime::kSaveAll); |
jeffhao | 94d6df4 | 2012-11-26 16:02:12 -0800 | [diff] [blame] | 31 | thread->QuickDeliverException(); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | // Called by generated call to throw an exception. |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 35 | extern "C" void artDeliverExceptionFromCode(mirror::Throwable* exception, Thread* self, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 36 | mirror::ArtMethod** sp) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 37 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 38 | /* |
| 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 Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 45 | 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 Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | // Called by generated call to throw a NPE exception. |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 57 | extern "C" void artThrowNullPointerExceptionFromCode(Thread* self, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 58 | mirror::ArtMethod** sp) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 59 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 60 | FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 61 | ThrowLocation throw_location = self->GetCurrentLocationForThrow(); |
| 62 | ThrowNullPointerExceptionFromDexPC(throw_location); |
jeffhao | 94d6df4 | 2012-11-26 16:02:12 -0800 | [diff] [blame] | 63 | self->QuickDeliverException(); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | // Called by generated call to throw an arithmetic divide by zero exception. |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 67 | extern "C" void artThrowDivZeroFromCode(Thread* self, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 68 | mirror::ArtMethod** sp) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 69 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 70 | FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll); |
Sebastien Hertz | 0a3b863 | 2013-06-26 11:16:01 +0200 | [diff] [blame] | 71 | ThrowArithmeticExceptionDivideByZero(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 72 | self->QuickDeliverException(); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | // Called by generated call to throw an array index out of bounds exception. |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 76 | extern "C" void artThrowArrayBoundsFromCode(int index, int length, Thread* self, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 77 | mirror::ArtMethod** sp) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 78 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 79 | FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll); |
| 80 | ThrowArrayIndexOutOfBoundsException(index, length); |
| 81 | self->QuickDeliverException(); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 84 | extern "C" void artThrowStackOverflowFromCode(Thread* self, mirror::ArtMethod** sp) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 85 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 120f1c7 | 2012-09-28 17:17:10 -0700 | [diff] [blame] | 86 | FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll); |
jeffhao | d752132 | 2012-11-21 15:38:24 -0800 | [diff] [blame] | 87 | ThrowStackOverflowError(self); |
jeffhao | 94d6df4 | 2012-11-26 16:02:12 -0800 | [diff] [blame] | 88 | self->QuickDeliverException(); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 91 | extern "C" void artThrowNoSuchMethodFromCode(int32_t method_idx, Thread* self, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 92 | mirror::ArtMethod** sp) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 93 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 94 | FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 95 | ThrowNoSuchMethodError(method_idx); |
jeffhao | 94d6df4 | 2012-11-26 16:02:12 -0800 | [diff] [blame] | 96 | self->QuickDeliverException(); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 99 | extern "C" void artThrowClassCastException(mirror::Class* dest_type, mirror::Class* src_type, |
| 100 | Thread* self, mirror::ArtMethod** sp) |
| 101 | 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 | |
| 108 | extern "C" void artThrowArrayStoreException(mirror::Object* array, mirror::Object* value, |
| 109 | Thread* self, mirror::ArtMethod** sp) |
| 110 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 111 | FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll); |
| 112 | ThrowArrayStoreException(value->GetClass(), array->GetClass()); |
| 113 | self->QuickDeliverException(); |
| 114 | } |
| 115 | |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 116 | } // namespace art |