quick_throw_entrypoints.cc revision 8438ed31e10f3881ed92f03877d5edaca7d5b48c
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 "entrypoints/entrypoint_utils.h"
19#include "mirror/object.h"
20#include "object_utils.h"
21#include "thread.h"
22#include "well_known_classes.h"
23
24namespace art {
25
26// Deliver an exception that's pending on thread helping set up a callee save frame on the way.
27extern "C" void artDeliverPendingExceptionFromCode(Thread* thread, mirror::ArtMethod** sp)
28    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
29  FinishCalleeSaveFrameSetup(thread, sp, Runtime::kSaveAll);
30  thread->QuickDeliverException();
31}
32
33// Called by generated call to throw an exception.
34extern "C" void artDeliverExceptionFromCode(mirror::Throwable* exception, Thread* self,
35                                            mirror::ArtMethod** sp)
36    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
37  /*
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   */
44  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();
53}
54
55// Called by generated call to throw a NPE exception.
56extern "C" void artThrowNullPointerExceptionFromCode(Thread* self,
57                                                     mirror::ArtMethod** sp)
58    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
59  FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
60  ThrowLocation throw_location = self->GetCurrentLocationForThrow();
61  LG << "artThrowNullPointerExceptionFromCode GetDexPc=0x" << std::hex << throw_location.GetDexPc();
62  ThrowNullPointerExceptionFromDexPC(throw_location);
63  self->QuickDeliverException();
64}
65
66// Called by generated call to throw an arithmetic divide by zero exception.
67extern "C" void artThrowDivZeroFromCode(Thread* self,
68                                        mirror::ArtMethod** sp)
69    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
70  FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
71  ThrowArithmeticExceptionDivideByZero();
72  self->QuickDeliverException();
73}
74
75// Called by generated call to throw an array index out of bounds exception.
76extern "C" void artThrowArrayBoundsFromCode(int index, int length, Thread* self,
77                                            mirror::ArtMethod** sp)
78    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
79  FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
80  ThrowArrayIndexOutOfBoundsException(index, length);
81  self->QuickDeliverException();
82}
83
84extern "C" void artThrowStackOverflowFromCode(Thread* self, mirror::ArtMethod** sp)
85    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
86  FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
87  ThrowStackOverflowError(self);
88  self->QuickDeliverException();
89}
90
91extern "C" void artThrowNoSuchMethodFromCode(int32_t method_idx, Thread* self,
92                                             mirror::ArtMethod** sp)
93    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
94  FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
95  ThrowNoSuchMethodError(method_idx);
96  self->QuickDeliverException();
97}
98
99}  // namespace art
100