Home | History | Annotate | Download | only in quick
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      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"
     18 #include "common_throws.h"
     19 #include "entrypoints/entrypoint_utils-inl.h"
     20 #include "mirror/object-inl.h"
     21 #include "thread.h"
     22 #include "well_known_classes.h"
     23 
     24 namespace art {
     25 
     26 // Deliver an exception that's pending on thread helping set up a callee save frame on the way.
     27 extern "C" void artDeliverPendingExceptionFromCode(Thread* thread,
     28                                                    StackReference<mirror::ArtMethod>* sp)
     29     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
     30   FinishCalleeSaveFrameSetup(thread, sp, Runtime::kSaveAll);
     31   thread->QuickDeliverException();
     32 }
     33 
     34 // Called by generated call to throw an exception.
     35 extern "C" void artDeliverExceptionFromCode(mirror::Throwable* exception, Thread* self,
     36                                             StackReference<mirror::ArtMethod>* sp)
     37     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
     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    */
     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();
     54 }
     55 
     56 // Called by generated call to throw a NPE exception.
     57 extern "C" void artThrowNullPointerExceptionFromCode(Thread* self,
     58                                                      StackReference<mirror::ArtMethod>* sp)
     59     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
     60   FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
     61   self->NoteSignalBeingHandled();
     62   ThrowLocation throw_location = self->GetCurrentLocationForThrow();
     63   ThrowNullPointerExceptionFromDexPC(throw_location);
     64   self->NoteSignalHandlerDone();
     65   self->QuickDeliverException();
     66 }
     67 
     68 // Called by generated call to throw an arithmetic divide by zero exception.
     69 extern "C" void artThrowDivZeroFromCode(Thread* self, StackReference<mirror::ArtMethod>* sp)
     70     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
     71   FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
     72   ThrowArithmeticExceptionDivideByZero();
     73   self->QuickDeliverException();
     74 }
     75 
     76 // Called by generated call to throw an array index out of bounds exception.
     77 extern "C" void artThrowArrayBoundsFromCode(int index, int length, Thread* self,
     78                                             StackReference<mirror::ArtMethod>*sp)
     79     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
     80   FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
     81   ThrowArrayIndexOutOfBoundsException(index, length);
     82   self->QuickDeliverException();
     83 }
     84 
     85 extern "C" void artThrowStackOverflowFromCode(Thread* self, StackReference<mirror::ArtMethod>* sp)
     86     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
     87   FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
     88   self->NoteSignalBeingHandled();
     89   ThrowStackOverflowError(self);
     90   self->NoteSignalHandlerDone();
     91   self->QuickDeliverException();
     92 }
     93 
     94 extern "C" void artThrowNoSuchMethodFromCode(int32_t method_idx, Thread* self,
     95                                              StackReference<mirror::ArtMethod>* sp)
     96     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
     97   FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
     98   ThrowNoSuchMethodError(method_idx);
     99   self->QuickDeliverException();
    100 }
    101 
    102 extern "C" void artThrowClassCastException(mirror::Class* dest_type, mirror::Class* src_type,
    103                                            Thread* self, StackReference<mirror::ArtMethod>* sp)
    104     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 
    111 extern "C" void artThrowArrayStoreException(mirror::Object* array, mirror::Object* value,
    112                                             Thread* self, StackReference<mirror::ArtMethod>* sp)
    113     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
    114   FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
    115   ThrowArrayStoreException(value->GetClass(), array->GetClass());
    116   self->QuickDeliverException();
    117 }
    118 
    119 }  // namespace art
    120