blob: 55a89388eaea31fbf59a02113fa61374dc630cd3 [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"
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -070022#include "obj_ptr.h"
Ian Rogers87e552d2012-08-31 15:54:48 -070023
24namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025namespace mirror {
Ian Rogers8d31bbd2013-10-13 10:44:14 -070026 class Class;
27 class Object;
Narayan Kamath208f8572016-08-03 12:46:58 +010028 class MethodType;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080029} // namespace mirror
Mathieu Chartierc7853442015-03-27 14:35:38 -070030class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070031class ArtMethod;
Alex Light705ad492015-09-21 11:36:30 -070032class DexFile;
Ian Rogersd91d6d62013-09-25 20:26:14 -070033class Signature;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080034class StringPiece;
Ian Rogers87e552d2012-08-31 15:54:48 -070035
Sebastien Hertz56adf602013-07-09 17:27:07 +020036// AbstractMethodError
37
Mathieu Chartiere401d142015-04-22 13:56:20 -070038void ThrowAbstractMethodError(ArtMethod* method)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070039 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Sebastien Hertz56adf602013-07-09 17:27:07 +020040
Alex Light705ad492015-09-21 11:36:30 -070041void ThrowAbstractMethodError(uint32_t method_idx, const DexFile& dex_file)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070042 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Alex Light705ad492015-09-21 11:36:30 -070043
Ian Rogers62d6c772013-02-27 08:32:07 -080044// ArithmeticException
Ian Rogers87e552d2012-08-31 15:54:48 -070045
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070046void ThrowArithmeticExceptionDivideByZero() REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -080047
48// ArrayIndexOutOfBoundsException
49
50void ThrowArrayIndexOutOfBoundsException(int index, int length)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070051 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070052
Ian Rogers62d6c772013-02-27 08:32:07 -080053// ArrayStoreException
54
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -070055void ThrowArrayStoreException(ObjPtr<mirror::Class> element_class,
56 ObjPtr<mirror::Class> array_class)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070057 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070058
Orion Hodsonc069a302017-01-18 09:23:12 +000059// BootstrapMethodError
60
61void ThrowBootstrapMethodError(const char* fmt, ...)
62 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
63
64void ThrowWrappedBootstrapMethodError(const char* fmt, ...)
65 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
66
Ian Rogers62d6c772013-02-27 08:32:07 -080067// ClassCircularityError
68
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -070069void ThrowClassCircularityError(ObjPtr<mirror::Class> c)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070070 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -080071
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -070072void ThrowClassCircularityError(ObjPtr<mirror::Class> c, const char* fmt, ...)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070073 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Roland Levillain989ab3b2016-05-18 15:52:54 +010074
Ian Rogers62d6c772013-02-27 08:32:07 -080075// ClassCastException
76
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -070077void ThrowClassCastException(ObjPtr<mirror::Class> dest_type, ObjPtr<mirror::Class> src_type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070078 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -080079
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000080void ThrowClassCastException(const char* msg)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070081 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -080082
83// ClassFormatError
84
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -070085void ThrowClassFormatError(ObjPtr<mirror::Class> referrer, const char* fmt, ...)
Ian Rogers62d6c772013-02-27 08:32:07 -080086 __attribute__((__format__(__printf__, 2, 3)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070087 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070088
89// IllegalAccessError
90
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -070091void ThrowIllegalAccessErrorClass(ObjPtr<mirror::Class> referrer, ObjPtr<mirror::Class> accessed)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070092 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070093
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -070094void ThrowIllegalAccessErrorClassForMethodDispatch(ObjPtr<mirror::Class> referrer,
95 ObjPtr<mirror::Class> accessed,
Mathieu Chartiere401d142015-04-22 13:56:20 -070096 ArtMethod* called,
Ian Rogers87e552d2012-08-31 15:54:48 -070097 InvokeType type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070098 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070099
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700100void ThrowIllegalAccessErrorMethod(ObjPtr<mirror::Class> referrer, ArtMethod* accessed)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700101 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700102
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700103void ThrowIllegalAccessErrorField(ObjPtr<mirror::Class> referrer, ArtField* accessed)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700104 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700105
Mathieu Chartiere401d142015-04-22 13:56:20 -0700106void ThrowIllegalAccessErrorFinalField(ArtMethod* referrer, ArtField* accessed)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700107 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700108
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700109void ThrowIllegalAccessError(ObjPtr<mirror::Class> referrer, const char* fmt, ...)
Ian Rogers62d6c772013-02-27 08:32:07 -0800110 __attribute__((__format__(__printf__, 2, 3)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700111 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800112
Jeff Hao11d5d8f2014-03-26 15:08:20 -0700113// IllegalAccessException
114
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000115void ThrowIllegalAccessException(const char* msg)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700116 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Jeff Hao11d5d8f2014-03-26 15:08:20 -0700117
Ian Rogers62d6c772013-02-27 08:32:07 -0800118// IllegalArgumentException
119
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000120void ThrowIllegalArgumentException(const char* msg)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700121 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800122
Ian Rogers87e552d2012-08-31 15:54:48 -0700123// IncompatibleClassChangeError
124
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700125void ThrowIncompatibleClassChangeError(InvokeType expected_type,
126 InvokeType found_type,
127 ArtMethod* method,
128 ArtMethod* referrer)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700129 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700130
Alex Light705ad492015-09-21 11:36:30 -0700131void ThrowIncompatibleClassChangeErrorClassForInterfaceSuper(ArtMethod* method,
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700132 ObjPtr<mirror::Class> target_class,
133 ObjPtr<mirror::Object> this_object,
Alex Light705ad492015-09-21 11:36:30 -0700134 ArtMethod* referrer)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700135 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Alex Light705ad492015-09-21 11:36:30 -0700136
Mathieu Chartiere401d142015-04-22 13:56:20 -0700137void ThrowIncompatibleClassChangeErrorClassForInterfaceDispatch(ArtMethod* interface_method,
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700138 ObjPtr<mirror::Object> this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700139 ArtMethod* referrer)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700140 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700141
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700142void ThrowIncompatibleClassChangeErrorField(ArtField* resolved_field,
143 bool is_static,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700144 ArtMethod* referrer)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700145 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700146
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700147void ThrowIncompatibleClassChangeError(ObjPtr<mirror::Class> referrer, const char* fmt, ...)
Ian Rogers62d6c772013-02-27 08:32:07 -0800148 __attribute__((__format__(__printf__, 2, 3)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700149 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700150
Alex Light9139e002015-10-09 15:59:48 -0700151void ThrowIncompatibleClassChangeErrorForMethodConflict(ArtMethod* method)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700152 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Alex Light9139e002015-10-09 15:59:48 -0700153
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700154// IOException
155
156void ThrowIOException(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700157 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800158
Andreas Gampe329d1882014-04-08 10:32:19 -0700159void ThrowWrappedIOException(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700160 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Andreas Gampe329d1882014-04-08 10:32:19 -0700161
Ian Rogers62d6c772013-02-27 08:32:07 -0800162// LinkageError
163
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700164void ThrowLinkageError(ObjPtr<mirror::Class> referrer, const char* fmt, ...)
Ian Rogers62d6c772013-02-27 08:32:07 -0800165 __attribute__((__format__(__printf__, 2, 3)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700166 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800167
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700168void ThrowWrappedLinkageError(ObjPtr<mirror::Class> referrer, const char* fmt, ...)
Vladimir Markod5e5a0e2015-05-08 12:26:59 +0100169 __attribute__((__format__(__printf__, 2, 3)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700170 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Vladimir Markod5e5a0e2015-05-08 12:26:59 +0100171
Ian Rogers62d6c772013-02-27 08:32:07 -0800172// NegativeArraySizeException
173
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700174void ThrowNegativeArraySizeException(int size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700175 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800176
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700177void ThrowNegativeArraySizeException(const char* msg)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700178 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800179
180
181// NoSuchFieldError
182
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700183void ThrowNoSuchFieldError(const StringPiece& scope,
184 ObjPtr<mirror::Class> c,
185 const StringPiece& type,
186 const StringPiece& name)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700187 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800188
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700189void ThrowNoSuchFieldException(ObjPtr<mirror::Class> c, const StringPiece& name)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700190 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Mathieu Chartier4e067782015-05-13 13:13:24 -0700191
Ian Rogers87e552d2012-08-31 15:54:48 -0700192// NoSuchMethodError
193
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700194void ThrowNoSuchMethodError(InvokeType type,
195 ObjPtr<mirror::Class> c,
196 const StringPiece& name,
Ian Rogersd91d6d62013-09-25 20:26:14 -0700197 const Signature& signature)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700198 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700199
Ian Rogers62d6c772013-02-27 08:32:07 -0800200// NullPointerException
201
Mathieu Chartierc7853442015-03-27 14:35:38 -0700202void ThrowNullPointerExceptionForFieldAccess(ArtField* field,
Ian Rogers62d6c772013-02-27 08:32:07 -0800203 bool is_read)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700204 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800205
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000206void ThrowNullPointerExceptionForMethodAccess(uint32_t method_idx,
Ian Rogers62d6c772013-02-27 08:32:07 -0800207 InvokeType type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700208 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800209
Mathieu Chartiere401d142015-04-22 13:56:20 -0700210void ThrowNullPointerExceptionForMethodAccess(ArtMethod* method,
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200211 InvokeType type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700212 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200213
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100214void ThrowNullPointerExceptionFromDexPC(bool check_address = false, uintptr_t addr = 0)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700215 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800216
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000217void ThrowNullPointerException(const char* msg)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700218 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800219
220// RuntimeException
221
222void ThrowRuntimeException(const char* fmt, ...)
223 __attribute__((__format__(__printf__, 1, 2)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700224 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800225
Leonard Mosescueb842212016-10-06 17:26:36 -0700226// SecurityException
227
228void ThrowSecurityException(const char* fmt, ...)
229 __attribute__((__format__(__printf__, 1, 2)))
230 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
231
Andreas Gampe103992b2016-01-04 15:32:43 -0800232// Stack overflow.
233
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700234void ThrowStackOverflowError(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Andreas Gampe103992b2016-01-04 15:32:43 -0800235
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100236// StringIndexOutOfBoundsException
237
238void ThrowStringIndexOutOfBoundsException(int index, int length)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700239 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100240
Ian Rogers62d6c772013-02-27 08:32:07 -0800241// VerifyError
242
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700243void ThrowVerifyError(ObjPtr<mirror::Class> referrer, const char* fmt, ...)
Ian Rogers62d6c772013-02-27 08:32:07 -0800244 __attribute__((__format__(__printf__, 2, 3)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700245 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700246
Orion Hodsonc069a302017-01-18 09:23:12 +0000247// WrongMethodTypeException
Narayan Kamath208f8572016-08-03 12:46:58 +0100248void ThrowWrongMethodTypeException(mirror::MethodType* callee_type,
249 mirror::MethodType* callsite_type)
250 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
251
Ian Rogers87e552d2012-08-31 15:54:48 -0700252} // namespace art
253
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700254#endif // ART_RUNTIME_COMMON_THROWS_H_