blob: 39c4e52b15b9436886c3dff4bad9441998e45b47 [file] [log] [blame]
Ian Rogers87e552d2012-08-31 15:54:48 -07001/*
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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_COMMON_THROWS_H_
18#define ART_RUNTIME_COMMON_THROWS_H_
Ian Rogers87e552d2012-08-31 15:54:48 -070019
Elliott Hughes76b61672012-12-12 17:47:30 -080020#include "base/mutex.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080021#include "invoke_type.h"
Ian Rogers87e552d2012-08-31 15:54:48 -070022
23namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080024namespace mirror {
Ian Rogers8d31bbd2013-10-13 10:44:14 -070025 class Class;
26 class Object;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080027} // namespace mirror
Mathieu Chartierc7853442015-03-27 14:35:38 -070028class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070029class ArtMethod;
Alex Light705ad492015-09-21 11:36:30 -070030class DexFile;
Ian Rogersd91d6d62013-09-25 20:26:14 -070031class Signature;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032class StringPiece;
Ian Rogers87e552d2012-08-31 15:54:48 -070033
Sebastien Hertz56adf602013-07-09 17:27:07 +020034// AbstractMethodError
35
Mathieu Chartiere401d142015-04-22 13:56:20 -070036void ThrowAbstractMethodError(ArtMethod* method)
Mathieu Chartier90443472015-07-16 20:32:27 -070037 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Sebastien Hertz56adf602013-07-09 17:27:07 +020038
Alex Light705ad492015-09-21 11:36:30 -070039void ThrowAbstractMethodError(uint32_t method_idx, const DexFile& dex_file)
40 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
41
Ian Rogers62d6c772013-02-27 08:32:07 -080042// ArithmeticException
Ian Rogers87e552d2012-08-31 15:54:48 -070043
Mathieu Chartier90443472015-07-16 20:32:27 -070044void ThrowArithmeticExceptionDivideByZero() SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -080045
46// ArrayIndexOutOfBoundsException
47
48void ThrowArrayIndexOutOfBoundsException(int index, int length)
Mathieu Chartier90443472015-07-16 20:32:27 -070049 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070050
Ian Rogers62d6c772013-02-27 08:32:07 -080051// ArrayStoreException
52
Ian Rogersef7d42f2014-01-06 12:55:46 -080053void ThrowArrayStoreException(mirror::Class* element_class, mirror::Class* array_class)
Mathieu Chartier90443472015-07-16 20:32:27 -070054 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070055
Ian Rogers62d6c772013-02-27 08:32:07 -080056// ClassCircularityError
57
Ian Rogers8d31bbd2013-10-13 10:44:14 -070058void ThrowClassCircularityError(mirror::Class* c)
Mathieu Chartier90443472015-07-16 20:32:27 -070059 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -080060
61// ClassCastException
62
Ian Rogersef7d42f2014-01-06 12:55:46 -080063void ThrowClassCastException(mirror::Class* dest_type, mirror::Class* src_type)
Mathieu Chartier90443472015-07-16 20:32:27 -070064 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -080065
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000066void ThrowClassCastException(const char* msg)
Mathieu Chartier90443472015-07-16 20:32:27 -070067 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -080068
69// ClassFormatError
70
Ian Rogersef7d42f2014-01-06 12:55:46 -080071void ThrowClassFormatError(mirror::Class* referrer, const char* fmt, ...)
Ian Rogers62d6c772013-02-27 08:32:07 -080072 __attribute__((__format__(__printf__, 2, 3)))
Mathieu Chartier90443472015-07-16 20:32:27 -070073 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070074
75// IllegalAccessError
76
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080077void ThrowIllegalAccessErrorClass(mirror::Class* referrer, mirror::Class* accessed)
Mathieu Chartier90443472015-07-16 20:32:27 -070078 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070079
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080080void ThrowIllegalAccessErrorClassForMethodDispatch(mirror::Class* referrer, mirror::Class* accessed,
Mathieu Chartiere401d142015-04-22 13:56:20 -070081 ArtMethod* called,
Ian Rogers87e552d2012-08-31 15:54:48 -070082 InvokeType type)
Mathieu Chartier90443472015-07-16 20:32:27 -070083 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070084
Mathieu Chartiere401d142015-04-22 13:56:20 -070085void ThrowIllegalAccessErrorMethod(mirror::Class* referrer, ArtMethod* accessed)
Mathieu Chartier90443472015-07-16 20:32:27 -070086 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070087
Mathieu Chartierc7853442015-03-27 14:35:38 -070088void ThrowIllegalAccessErrorField(mirror::Class* referrer, ArtField* accessed)
Mathieu Chartier90443472015-07-16 20:32:27 -070089 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070090
Mathieu Chartiere401d142015-04-22 13:56:20 -070091void ThrowIllegalAccessErrorFinalField(ArtMethod* referrer, ArtField* accessed)
Mathieu Chartier90443472015-07-16 20:32:27 -070092 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070093
Ian Rogers62d6c772013-02-27 08:32:07 -080094void ThrowIllegalAccessError(mirror::Class* referrer, const char* fmt, ...)
95 __attribute__((__format__(__printf__, 2, 3)))
Mathieu Chartier90443472015-07-16 20:32:27 -070096 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -080097
Jeff Hao11d5d8f2014-03-26 15:08:20 -070098// IllegalAccessException
99
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000100void ThrowIllegalAccessException(const char* msg)
Mathieu Chartier90443472015-07-16 20:32:27 -0700101 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Jeff Hao11d5d8f2014-03-26 15:08:20 -0700102
Ian Rogers62d6c772013-02-27 08:32:07 -0800103// IllegalArgumentException
104
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000105void ThrowIllegalArgumentException(const char* msg)
Mathieu Chartier90443472015-07-16 20:32:27 -0700106 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800107
Ian Rogers87e552d2012-08-31 15:54:48 -0700108// IncompatibleClassChangeError
109
110void ThrowIncompatibleClassChangeError(InvokeType expected_type, InvokeType found_type,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700111 ArtMethod* method, ArtMethod* referrer)
Mathieu Chartier90443472015-07-16 20:32:27 -0700112 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700113
Alex Light705ad492015-09-21 11:36:30 -0700114void ThrowIncompatibleClassChangeErrorClassForInterfaceSuper(ArtMethod* method,
115 mirror::Class* target_class,
116 mirror::Object* this_object,
117 ArtMethod* referrer)
118 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
119
Mathieu Chartiere401d142015-04-22 13:56:20 -0700120void ThrowIncompatibleClassChangeErrorClassForInterfaceDispatch(ArtMethod* interface_method,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800121 mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700122 ArtMethod* referrer)
Mathieu Chartier90443472015-07-16 20:32:27 -0700123 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700124
Mathieu Chartierc7853442015-03-27 14:35:38 -0700125void ThrowIncompatibleClassChangeErrorField(ArtField* resolved_field, bool is_static,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700126 ArtMethod* referrer)
Mathieu Chartier90443472015-07-16 20:32:27 -0700127 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700128
Ian Rogersef7d42f2014-01-06 12:55:46 -0800129void ThrowIncompatibleClassChangeError(mirror::Class* referrer, const char* fmt, ...)
Ian Rogers62d6c772013-02-27 08:32:07 -0800130 __attribute__((__format__(__printf__, 2, 3)))
Mathieu Chartier90443472015-07-16 20:32:27 -0700131 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700132
Alex Light9139e002015-10-09 15:59:48 -0700133void ThrowIncompatibleClassChangeErrorForMethodConflict(ArtMethod* method)
134 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
135
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700136// IOException
137
138void ThrowIOException(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)))
Mathieu Chartier90443472015-07-16 20:32:27 -0700139 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800140
Andreas Gampe329d1882014-04-08 10:32:19 -0700141void ThrowWrappedIOException(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)))
Mathieu Chartier90443472015-07-16 20:32:27 -0700142 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Andreas Gampe329d1882014-04-08 10:32:19 -0700143
Ian Rogers62d6c772013-02-27 08:32:07 -0800144// LinkageError
145
Ian Rogersef7d42f2014-01-06 12:55:46 -0800146void ThrowLinkageError(mirror::Class* referrer, const char* fmt, ...)
Ian Rogers62d6c772013-02-27 08:32:07 -0800147 __attribute__((__format__(__printf__, 2, 3)))
Mathieu Chartier90443472015-07-16 20:32:27 -0700148 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800149
Vladimir Markod5e5a0e2015-05-08 12:26:59 +0100150void ThrowWrappedLinkageError(mirror::Class* referrer, const char* fmt, ...)
151 __attribute__((__format__(__printf__, 2, 3)))
Mathieu Chartier90443472015-07-16 20:32:27 -0700152 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Vladimir Markod5e5a0e2015-05-08 12:26:59 +0100153
Ian Rogers62d6c772013-02-27 08:32:07 -0800154// NegativeArraySizeException
155
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700156void ThrowNegativeArraySizeException(int size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700157 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800158
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700159void ThrowNegativeArraySizeException(const char* msg)
Mathieu Chartier90443472015-07-16 20:32:27 -0700160 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800161
162
163// NoSuchFieldError
164
165void ThrowNoSuchFieldError(const StringPiece& scope, mirror::Class* c,
166 const StringPiece& type, const StringPiece& name)
Andreas Gampe103992b2016-01-04 15:32:43 -0800167 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800168
Mathieu Chartier4e067782015-05-13 13:13:24 -0700169void ThrowNoSuchFieldException(mirror::Class* c, const StringPiece& name)
Andreas Gampe103992b2016-01-04 15:32:43 -0800170 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Mathieu Chartier4e067782015-05-13 13:13:24 -0700171
Ian Rogers87e552d2012-08-31 15:54:48 -0700172// NoSuchMethodError
173
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800174void ThrowNoSuchMethodError(InvokeType type, mirror::Class* c, const StringPiece& name,
Ian Rogersd91d6d62013-09-25 20:26:14 -0700175 const Signature& signature)
Mathieu Chartier90443472015-07-16 20:32:27 -0700176 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700177
Ian Rogers62d6c772013-02-27 08:32:07 -0800178void ThrowNoSuchMethodError(uint32_t method_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700179 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800180
181// NullPointerException
182
Mathieu Chartierc7853442015-03-27 14:35:38 -0700183void ThrowNullPointerExceptionForFieldAccess(ArtField* field,
Ian Rogers62d6c772013-02-27 08:32:07 -0800184 bool is_read)
Mathieu Chartier90443472015-07-16 20:32:27 -0700185 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800186
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000187void ThrowNullPointerExceptionForMethodAccess(uint32_t method_idx,
Ian Rogers62d6c772013-02-27 08:32:07 -0800188 InvokeType type)
Mathieu Chartier90443472015-07-16 20:32:27 -0700189 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800190
Mathieu Chartiere401d142015-04-22 13:56:20 -0700191void ThrowNullPointerExceptionForMethodAccess(ArtMethod* method,
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200192 InvokeType type)
Mathieu Chartier90443472015-07-16 20:32:27 -0700193 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200194
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000195void ThrowNullPointerExceptionFromDexPC()
Mathieu Chartier90443472015-07-16 20:32:27 -0700196 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800197
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000198void ThrowNullPointerException(const char* msg)
Mathieu Chartier90443472015-07-16 20:32:27 -0700199 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800200
201// RuntimeException
202
203void ThrowRuntimeException(const char* fmt, ...)
204 __attribute__((__format__(__printf__, 1, 2)))
Mathieu Chartier90443472015-07-16 20:32:27 -0700205 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800206
Andreas Gampe103992b2016-01-04 15:32:43 -0800207// Stack overflow.
208
209void ThrowStackOverflowError(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
210
Ian Rogers62d6c772013-02-27 08:32:07 -0800211// VerifyError
212
Ian Rogersef7d42f2014-01-06 12:55:46 -0800213void ThrowVerifyError(mirror::Class* referrer, const char* fmt, ...)
Ian Rogers62d6c772013-02-27 08:32:07 -0800214 __attribute__((__format__(__printf__, 2, 3)))
Mathieu Chartier90443472015-07-16 20:32:27 -0700215 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700216
217} // namespace art
218
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700219#endif // ART_RUNTIME_COMMON_THROWS_H_