blob: 4afef7993de882f0d950865c8644f4ff44521afc [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
Alex Lightdb01a092017-04-03 15:39:55 -0700154// InternalError
155
156void ThrowInternalError(const char* fmt, ...)
157 __attribute__((__format__(__printf__, 1, 2)))
158 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
159
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700160// IOException
161
162void ThrowIOException(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700163 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800164
Andreas Gampe329d1882014-04-08 10:32:19 -0700165void ThrowWrappedIOException(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700166 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Andreas Gampe329d1882014-04-08 10:32:19 -0700167
Ian Rogers62d6c772013-02-27 08:32:07 -0800168// LinkageError
169
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700170void ThrowLinkageError(ObjPtr<mirror::Class> referrer, const char* fmt, ...)
Ian Rogers62d6c772013-02-27 08:32:07 -0800171 __attribute__((__format__(__printf__, 2, 3)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700172 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800173
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700174void ThrowWrappedLinkageError(ObjPtr<mirror::Class> referrer, const char* fmt, ...)
Vladimir Markod5e5a0e2015-05-08 12:26:59 +0100175 __attribute__((__format__(__printf__, 2, 3)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700176 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Vladimir Markod5e5a0e2015-05-08 12:26:59 +0100177
Ian Rogers62d6c772013-02-27 08:32:07 -0800178// NegativeArraySizeException
179
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700180void ThrowNegativeArraySizeException(int size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700181 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800182
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700183void ThrowNegativeArraySizeException(const char* msg)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700184 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800185
186
187// NoSuchFieldError
188
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700189void ThrowNoSuchFieldError(const StringPiece& scope,
190 ObjPtr<mirror::Class> c,
191 const StringPiece& type,
192 const StringPiece& name)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700193 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800194
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700195void ThrowNoSuchFieldException(ObjPtr<mirror::Class> c, const StringPiece& name)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700196 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Mathieu Chartier4e067782015-05-13 13:13:24 -0700197
Ian Rogers87e552d2012-08-31 15:54:48 -0700198// NoSuchMethodError
199
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700200void ThrowNoSuchMethodError(InvokeType type,
201 ObjPtr<mirror::Class> c,
202 const StringPiece& name,
Ian Rogersd91d6d62013-09-25 20:26:14 -0700203 const Signature& signature)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700204 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700205
Ian Rogers62d6c772013-02-27 08:32:07 -0800206// NullPointerException
207
Mathieu Chartierc7853442015-03-27 14:35:38 -0700208void ThrowNullPointerExceptionForFieldAccess(ArtField* field,
Ian Rogers62d6c772013-02-27 08:32:07 -0800209 bool is_read)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700210 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800211
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000212void ThrowNullPointerExceptionForMethodAccess(uint32_t method_idx,
Ian Rogers62d6c772013-02-27 08:32:07 -0800213 InvokeType type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700214 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800215
Mathieu Chartiere401d142015-04-22 13:56:20 -0700216void ThrowNullPointerExceptionForMethodAccess(ArtMethod* method,
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200217 InvokeType type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700218 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200219
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100220void ThrowNullPointerExceptionFromDexPC(bool check_address = false, uintptr_t addr = 0)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700221 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800222
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000223void ThrowNullPointerException(const char* msg)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700224 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800225
226// RuntimeException
227
228void ThrowRuntimeException(const char* fmt, ...)
229 __attribute__((__format__(__printf__, 1, 2)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700230 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800231
Leonard Mosescueb842212016-10-06 17:26:36 -0700232// SecurityException
233
234void ThrowSecurityException(const char* fmt, ...)
235 __attribute__((__format__(__printf__, 1, 2)))
236 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
237
Andreas Gampe103992b2016-01-04 15:32:43 -0800238// Stack overflow.
239
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700240void ThrowStackOverflowError(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Andreas Gampe103992b2016-01-04 15:32:43 -0800241
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100242// StringIndexOutOfBoundsException
243
244void ThrowStringIndexOutOfBoundsException(int index, int length)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700245 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100246
Ian Rogers62d6c772013-02-27 08:32:07 -0800247// VerifyError
248
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700249void ThrowVerifyError(ObjPtr<mirror::Class> referrer, const char* fmt, ...)
Ian Rogers62d6c772013-02-27 08:32:07 -0800250 __attribute__((__format__(__printf__, 2, 3)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700251 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700252
Orion Hodsonc069a302017-01-18 09:23:12 +0000253// WrongMethodTypeException
Narayan Kamath208f8572016-08-03 12:46:58 +0100254void ThrowWrongMethodTypeException(mirror::MethodType* callee_type,
255 mirror::MethodType* callsite_type)
256 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
257
Ian Rogers87e552d2012-08-31 15:54:48 -0700258} // namespace art
259
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700260#endif // ART_RUNTIME_COMMON_THROWS_H_