blob: 31cf7d937392d5a77d77dc093177cad77a10d2fc [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 Rogers57b86d42012-03-27 16:05:41 -070018#include "object.h"
19#include "object_utils.h"
20#include "runtime_support.h"
21#include "thread.h"
22
23namespace art {
24
25// Deliver an exception that's pending on thread helping set up a callee save frame on the way.
26extern "C" void artDeliverPendingExceptionFromCode(Thread* thread, Method** sp) {
27 FinishCalleeSaveFrameSetup(thread, sp, Runtime::kSaveAll);
28 thread->DeliverException();
29}
30
31// Called by generated call to throw an exception.
32extern "C" void artDeliverExceptionFromCode(Throwable* exception, Thread* thread, Method** sp) {
33 /*
34 * exception may be NULL, in which case this routine should
35 * throw NPE. NOTE: this is a convenience for generated code,
36 * which previously did the null check inline and constructed
37 * and threw a NPE if NULL. This routine responsible for setting
38 * exception_ in thread and delivering the exception.
39 */
40 FinishCalleeSaveFrameSetup(thread, sp, Runtime::kSaveAll);
41 if (exception == NULL) {
42 thread->ThrowNewException("Ljava/lang/NullPointerException;", "throw with null exception");
43 } else {
44 thread->SetException(exception);
45 }
46 thread->DeliverException();
47}
48
49// Called by generated call to throw a NPE exception.
50extern "C" void artThrowNullPointerExceptionFromCode(Thread* self, Method** sp) {
51 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
Ian Rogers0399dde2012-06-06 17:09:28 -070052 uint32_t dex_pc;
53 Method* throw_method = self->GetCurrentMethod(&dex_pc);
TDYa1273f9137d2012-04-08 15:59:19 -070054 ThrowNullPointerExceptionFromDexPC(self, throw_method, dex_pc);
Ian Rogers57b86d42012-03-27 16:05:41 -070055 self->DeliverException();
56}
57
58// Called by generated call to throw an arithmetic divide by zero exception.
59extern "C" void artThrowDivZeroFromCode(Thread* thread, Method** sp) {
60 FinishCalleeSaveFrameSetup(thread, sp, Runtime::kSaveAll);
61 thread->ThrowNewException("Ljava/lang/ArithmeticException;", "divide by zero");
62 thread->DeliverException();
63}
64
65// Called by generated call to throw an array index out of bounds exception.
66extern "C" void artThrowArrayBoundsFromCode(int index, int limit, Thread* thread, Method** sp) {
67 FinishCalleeSaveFrameSetup(thread, sp, Runtime::kSaveAll);
68 thread->ThrowNewExceptionF("Ljava/lang/ArrayIndexOutOfBoundsException;",
69 "length=%d; index=%d", limit, index);
70 thread->DeliverException();
71}
72
73extern "C" void artThrowStackOverflowFromCode(Thread* thread, Method** sp) {
74 FinishCalleeSaveFrameSetup(thread, sp, Runtime::kSaveAll);
Elliott Hughes6cf23882012-06-15 15:42:07 -070075 // Remove extra entry pushed onto second stack during method tracing.
Ian Rogers57b86d42012-03-27 16:05:41 -070076 if (Runtime::Current()->IsMethodTracingActive()) {
77 TraceMethodUnwindFromCode(thread);
78 }
Elliott Hughes6cf23882012-06-15 15:42:07 -070079 thread->SetStackEndForStackOverflow(); // Allow space on the stack for constructor to execute.
80 thread->ThrowNewExceptionF("Ljava/lang/StackOverflowError;", "stack size %s",
81 PrettySize(thread->GetStackSize()).c_str());
82 thread->ResetDefaultStackEnd(); // Return to default stack size.
Ian Rogers57b86d42012-03-27 16:05:41 -070083 thread->DeliverException();
84}
85
86extern "C" void artThrowNoSuchMethodFromCode(int32_t method_idx, Thread* self, Method** sp) {
87 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
Ian Rogers0399dde2012-06-06 17:09:28 -070088 Method* method = self->GetCurrentMethod();
Ian Rogers57b86d42012-03-27 16:05:41 -070089 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
90 MethodNameFromIndex(method, method_idx, verifier::VERIFY_ERROR_REF_METHOD, false).c_str());
91 self->DeliverException();
92}
93
Ian Rogers57b86d42012-03-27 16:05:41 -070094extern "C" void artThrowVerificationErrorFromCode(int32_t kind, int32_t ref, Thread* self, Method** sp) {
95 FinishCalleeSaveFrameSetup(self, sp, Runtime::kSaveAll);
Ian Rogers0399dde2012-06-06 17:09:28 -070096 Method* method = self->GetCurrentMethod();
Logan Chien9e5f5c12012-04-10 13:51:45 +080097 ThrowVerificationError(self, method, kind, ref);
Ian Rogers57b86d42012-03-27 16:05:41 -070098 self->DeliverException();
99}
100
101} // namespace art