blob: 76ea2ae6c86236e979ea8676c73eecc687f8fa2c [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
Ian Rogers62d6c772013-02-27 08:32:07 -080059// ClassCircularityError
60
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -070061void ThrowClassCircularityError(ObjPtr<mirror::Class> c)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070062 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -080063
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -070064void ThrowClassCircularityError(ObjPtr<mirror::Class> c, const char* fmt, ...)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070065 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Roland Levillain989ab3b2016-05-18 15:52:54 +010066
Ian Rogers62d6c772013-02-27 08:32:07 -080067// ClassCastException
68
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -070069void ThrowClassCastException(ObjPtr<mirror::Class> dest_type, ObjPtr<mirror::Class> src_type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070070 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -080071
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000072void ThrowClassCastException(const char* msg)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070073 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -080074
75// ClassFormatError
76
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -070077void ThrowClassFormatError(ObjPtr<mirror::Class> referrer, const char* fmt, ...)
Ian Rogers62d6c772013-02-27 08:32:07 -080078 __attribute__((__format__(__printf__, 2, 3)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070079 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070080
81// IllegalAccessError
82
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -070083void ThrowIllegalAccessErrorClass(ObjPtr<mirror::Class> referrer, ObjPtr<mirror::Class> accessed)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070084 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070085
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -070086void ThrowIllegalAccessErrorClassForMethodDispatch(ObjPtr<mirror::Class> referrer,
87 ObjPtr<mirror::Class> accessed,
Mathieu Chartiere401d142015-04-22 13:56:20 -070088 ArtMethod* called,
Ian Rogers87e552d2012-08-31 15:54:48 -070089 InvokeType type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070090 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070091
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -070092void ThrowIllegalAccessErrorMethod(ObjPtr<mirror::Class> referrer, ArtMethod* accessed)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070093 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070094
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -070095void ThrowIllegalAccessErrorField(ObjPtr<mirror::Class> referrer, ArtField* accessed)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070096 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070097
Mathieu Chartiere401d142015-04-22 13:56:20 -070098void ThrowIllegalAccessErrorFinalField(ArtMethod* referrer, ArtField* accessed)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070099 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700100
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700101void ThrowIllegalAccessError(ObjPtr<mirror::Class> referrer, const char* fmt, ...)
Ian Rogers62d6c772013-02-27 08:32:07 -0800102 __attribute__((__format__(__printf__, 2, 3)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700103 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800104
Jeff Hao11d5d8f2014-03-26 15:08:20 -0700105// IllegalAccessException
106
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000107void ThrowIllegalAccessException(const char* msg)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700108 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Jeff Hao11d5d8f2014-03-26 15:08:20 -0700109
Ian Rogers62d6c772013-02-27 08:32:07 -0800110// IllegalArgumentException
111
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000112void ThrowIllegalArgumentException(const char* msg)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700113 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800114
Ian Rogers87e552d2012-08-31 15:54:48 -0700115// IncompatibleClassChangeError
116
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700117void ThrowIncompatibleClassChangeError(InvokeType expected_type,
118 InvokeType found_type,
119 ArtMethod* method,
120 ArtMethod* referrer)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700121 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700122
Alex Light705ad492015-09-21 11:36:30 -0700123void ThrowIncompatibleClassChangeErrorClassForInterfaceSuper(ArtMethod* method,
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700124 ObjPtr<mirror::Class> target_class,
125 ObjPtr<mirror::Object> this_object,
Alex Light705ad492015-09-21 11:36:30 -0700126 ArtMethod* referrer)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700127 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Alex Light705ad492015-09-21 11:36:30 -0700128
Mathieu Chartiere401d142015-04-22 13:56:20 -0700129void ThrowIncompatibleClassChangeErrorClassForInterfaceDispatch(ArtMethod* interface_method,
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700130 ObjPtr<mirror::Object> this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700131 ArtMethod* referrer)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700132 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700133
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700134void ThrowIncompatibleClassChangeErrorField(ArtField* resolved_field,
135 bool is_static,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700136 ArtMethod* referrer)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700137 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700138
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700139void ThrowIncompatibleClassChangeError(ObjPtr<mirror::Class> referrer, const char* fmt, ...)
Ian Rogers62d6c772013-02-27 08:32:07 -0800140 __attribute__((__format__(__printf__, 2, 3)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700141 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700142
Alex Light9139e002015-10-09 15:59:48 -0700143void ThrowIncompatibleClassChangeErrorForMethodConflict(ArtMethod* method)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700144 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Alex Light9139e002015-10-09 15:59:48 -0700145
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700146// IOException
147
148void ThrowIOException(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700149 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800150
Andreas Gampe329d1882014-04-08 10:32:19 -0700151void ThrowWrappedIOException(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700152 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Andreas Gampe329d1882014-04-08 10:32:19 -0700153
Ian Rogers62d6c772013-02-27 08:32:07 -0800154// LinkageError
155
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700156void ThrowLinkageError(ObjPtr<mirror::Class> referrer, const char* fmt, ...)
Ian Rogers62d6c772013-02-27 08:32:07 -0800157 __attribute__((__format__(__printf__, 2, 3)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700158 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800159
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700160void ThrowWrappedLinkageError(ObjPtr<mirror::Class> referrer, const char* fmt, ...)
Vladimir Markod5e5a0e2015-05-08 12:26:59 +0100161 __attribute__((__format__(__printf__, 2, 3)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700162 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Vladimir Markod5e5a0e2015-05-08 12:26:59 +0100163
Ian Rogers62d6c772013-02-27 08:32:07 -0800164// NegativeArraySizeException
165
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700166void ThrowNegativeArraySizeException(int size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700167 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800168
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700169void ThrowNegativeArraySizeException(const char* msg)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700170 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800171
172
173// NoSuchFieldError
174
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700175void ThrowNoSuchFieldError(const StringPiece& scope,
176 ObjPtr<mirror::Class> c,
177 const StringPiece& type,
178 const StringPiece& name)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700179 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800180
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700181void ThrowNoSuchFieldException(ObjPtr<mirror::Class> c, const StringPiece& name)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700182 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Mathieu Chartier4e067782015-05-13 13:13:24 -0700183
Ian Rogers87e552d2012-08-31 15:54:48 -0700184// NoSuchMethodError
185
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700186void ThrowNoSuchMethodError(InvokeType type,
187 ObjPtr<mirror::Class> c,
188 const StringPiece& name,
Ian Rogersd91d6d62013-09-25 20:26:14 -0700189 const Signature& signature)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700190 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700191
Ian Rogers62d6c772013-02-27 08:32:07 -0800192// NullPointerException
193
Mathieu Chartierc7853442015-03-27 14:35:38 -0700194void ThrowNullPointerExceptionForFieldAccess(ArtField* field,
Ian Rogers62d6c772013-02-27 08:32:07 -0800195 bool is_read)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700196 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800197
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000198void ThrowNullPointerExceptionForMethodAccess(uint32_t method_idx,
Ian Rogers62d6c772013-02-27 08:32:07 -0800199 InvokeType type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700200 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800201
Mathieu Chartiere401d142015-04-22 13:56:20 -0700202void ThrowNullPointerExceptionForMethodAccess(ArtMethod* method,
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200203 InvokeType type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700204 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200205
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100206void ThrowNullPointerExceptionFromDexPC(bool check_address = false, uintptr_t addr = 0)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700207 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800208
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000209void ThrowNullPointerException(const char* msg)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700210 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800211
212// RuntimeException
213
214void ThrowRuntimeException(const char* fmt, ...)
215 __attribute__((__format__(__printf__, 1, 2)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700216 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800217
Leonard Mosescueb842212016-10-06 17:26:36 -0700218// SecurityException
219
220void ThrowSecurityException(const char* fmt, ...)
221 __attribute__((__format__(__printf__, 1, 2)))
222 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
223
Andreas Gampe103992b2016-01-04 15:32:43 -0800224// Stack overflow.
225
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700226void ThrowStackOverflowError(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Andreas Gampe103992b2016-01-04 15:32:43 -0800227
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100228// StringIndexOutOfBoundsException
229
230void ThrowStringIndexOutOfBoundsException(int index, int length)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700231 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100232
Ian Rogers62d6c772013-02-27 08:32:07 -0800233// VerifyError
234
Mathieu Chartier6b3d12b2016-10-13 13:59:58 -0700235void ThrowVerifyError(ObjPtr<mirror::Class> referrer, const char* fmt, ...)
Ian Rogers62d6c772013-02-27 08:32:07 -0800236 __attribute__((__format__(__printf__, 2, 3)))
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700237 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700238
Narayan Kamath208f8572016-08-03 12:46:58 +0100239// WrontMethodTypeException
240void ThrowWrongMethodTypeException(mirror::MethodType* callee_type,
241 mirror::MethodType* callsite_type)
242 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
243
Ian Rogers87e552d2012-08-31 15:54:48 -0700244} // namespace art
245
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700246#endif // ART_RUNTIME_COMMON_THROWS_H_