blob: c3a1f09db3df64f497612e8966dc0e022d0fbed9 [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
Roland Levillain90328ac2016-05-18 12:25:38 +010061void ThrowClassCircularityError(mirror::Class* c, const char* fmt, ...)
62 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
63
Ian Rogers62d6c772013-02-27 08:32:07 -080064// ClassCastException
65
Ian Rogersef7d42f2014-01-06 12:55:46 -080066void ThrowClassCastException(mirror::Class* dest_type, mirror::Class* src_type)
Mathieu Chartier90443472015-07-16 20:32:27 -070067 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -080068
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000069void ThrowClassCastException(const char* msg)
Mathieu Chartier90443472015-07-16 20:32:27 -070070 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -080071
72// ClassFormatError
73
Ian Rogersef7d42f2014-01-06 12:55:46 -080074void ThrowClassFormatError(mirror::Class* referrer, const char* fmt, ...)
Ian Rogers62d6c772013-02-27 08:32:07 -080075 __attribute__((__format__(__printf__, 2, 3)))
Mathieu Chartier90443472015-07-16 20:32:27 -070076 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070077
78// IllegalAccessError
79
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080080void ThrowIllegalAccessErrorClass(mirror::Class* referrer, mirror::Class* accessed)
Mathieu Chartier90443472015-07-16 20:32:27 -070081 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070082
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080083void ThrowIllegalAccessErrorClassForMethodDispatch(mirror::Class* referrer, mirror::Class* accessed,
Mathieu Chartiere401d142015-04-22 13:56:20 -070084 ArtMethod* called,
Ian Rogers87e552d2012-08-31 15:54:48 -070085 InvokeType type)
Mathieu Chartier90443472015-07-16 20:32:27 -070086 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070087
Mathieu Chartiere401d142015-04-22 13:56:20 -070088void ThrowIllegalAccessErrorMethod(mirror::Class* referrer, ArtMethod* 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 Chartierc7853442015-03-27 14:35:38 -070091void ThrowIllegalAccessErrorField(mirror::Class* 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
Mathieu Chartiere401d142015-04-22 13:56:20 -070094void ThrowIllegalAccessErrorFinalField(ArtMethod* referrer, ArtField* accessed)
Mathieu Chartier90443472015-07-16 20:32:27 -070095 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -070096
Ian Rogers62d6c772013-02-27 08:32:07 -080097void ThrowIllegalAccessError(mirror::Class* referrer, const char* fmt, ...)
98 __attribute__((__format__(__printf__, 2, 3)))
Mathieu Chartier90443472015-07-16 20:32:27 -070099 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800100
Jeff Hao11d5d8f2014-03-26 15:08:20 -0700101// IllegalAccessException
102
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000103void ThrowIllegalAccessException(const char* msg)
Mathieu Chartier90443472015-07-16 20:32:27 -0700104 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Jeff Hao11d5d8f2014-03-26 15:08:20 -0700105
Ian Rogers62d6c772013-02-27 08:32:07 -0800106// IllegalArgumentException
107
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000108void ThrowIllegalArgumentException(const char* msg)
Mathieu Chartier90443472015-07-16 20:32:27 -0700109 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800110
Ian Rogers87e552d2012-08-31 15:54:48 -0700111// IncompatibleClassChangeError
112
113void ThrowIncompatibleClassChangeError(InvokeType expected_type, InvokeType found_type,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700114 ArtMethod* method, ArtMethod* referrer)
Mathieu Chartier90443472015-07-16 20:32:27 -0700115 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700116
Alex Light705ad492015-09-21 11:36:30 -0700117void ThrowIncompatibleClassChangeErrorClassForInterfaceSuper(ArtMethod* method,
118 mirror::Class* target_class,
119 mirror::Object* this_object,
120 ArtMethod* referrer)
121 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
122
Mathieu Chartiere401d142015-04-22 13:56:20 -0700123void ThrowIncompatibleClassChangeErrorClassForInterfaceDispatch(ArtMethod* interface_method,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800124 mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700125 ArtMethod* referrer)
Mathieu Chartier90443472015-07-16 20:32:27 -0700126 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700127
Mathieu Chartierc7853442015-03-27 14:35:38 -0700128void ThrowIncompatibleClassChangeErrorField(ArtField* resolved_field, bool is_static,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700129 ArtMethod* referrer)
Mathieu Chartier90443472015-07-16 20:32:27 -0700130 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700131
Ian Rogersef7d42f2014-01-06 12:55:46 -0800132void ThrowIncompatibleClassChangeError(mirror::Class* referrer, const char* fmt, ...)
Ian Rogers62d6c772013-02-27 08:32:07 -0800133 __attribute__((__format__(__printf__, 2, 3)))
Mathieu Chartier90443472015-07-16 20:32:27 -0700134 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700135
Alex Light9139e002015-10-09 15:59:48 -0700136void ThrowIncompatibleClassChangeErrorForMethodConflict(ArtMethod* method)
137 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
138
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700139// IOException
140
141void ThrowIOException(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)))
Mathieu Chartier90443472015-07-16 20:32:27 -0700142 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800143
Andreas Gampe329d1882014-04-08 10:32:19 -0700144void ThrowWrappedIOException(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)))
Mathieu Chartier90443472015-07-16 20:32:27 -0700145 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Andreas Gampe329d1882014-04-08 10:32:19 -0700146
Ian Rogers62d6c772013-02-27 08:32:07 -0800147// LinkageError
148
Ian Rogersef7d42f2014-01-06 12:55:46 -0800149void ThrowLinkageError(mirror::Class* referrer, const char* fmt, ...)
Ian Rogers62d6c772013-02-27 08:32:07 -0800150 __attribute__((__format__(__printf__, 2, 3)))
Mathieu Chartier90443472015-07-16 20:32:27 -0700151 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800152
Vladimir Markod5e5a0e2015-05-08 12:26:59 +0100153void ThrowWrappedLinkageError(mirror::Class* referrer, const char* fmt, ...)
154 __attribute__((__format__(__printf__, 2, 3)))
Mathieu Chartier90443472015-07-16 20:32:27 -0700155 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Vladimir Markod5e5a0e2015-05-08 12:26:59 +0100156
Ian Rogers62d6c772013-02-27 08:32:07 -0800157// NegativeArraySizeException
158
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700159void ThrowNegativeArraySizeException(int size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700160 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800161
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700162void ThrowNegativeArraySizeException(const char* msg)
Mathieu Chartier90443472015-07-16 20:32:27 -0700163 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800164
165
166// NoSuchFieldError
167
168void ThrowNoSuchFieldError(const StringPiece& scope, mirror::Class* c,
169 const StringPiece& type, const StringPiece& name)
Andreas Gampe103992b2016-01-04 15:32:43 -0800170 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800171
Mathieu Chartier4e067782015-05-13 13:13:24 -0700172void ThrowNoSuchFieldException(mirror::Class* c, const StringPiece& name)
Andreas Gampe103992b2016-01-04 15:32:43 -0800173 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Mathieu Chartier4e067782015-05-13 13:13:24 -0700174
Ian Rogers87e552d2012-08-31 15:54:48 -0700175// NoSuchMethodError
176
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800177void ThrowNoSuchMethodError(InvokeType type, mirror::Class* c, const StringPiece& name,
Ian Rogersd91d6d62013-09-25 20:26:14 -0700178 const Signature& signature)
Mathieu Chartier90443472015-07-16 20:32:27 -0700179 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700180
Ian Rogers62d6c772013-02-27 08:32:07 -0800181void ThrowNoSuchMethodError(uint32_t method_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700182 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800183
184// NullPointerException
185
Mathieu Chartierc7853442015-03-27 14:35:38 -0700186void ThrowNullPointerExceptionForFieldAccess(ArtField* field,
Ian Rogers62d6c772013-02-27 08:32:07 -0800187 bool is_read)
Mathieu Chartier90443472015-07-16 20:32:27 -0700188 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800189
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000190void ThrowNullPointerExceptionForMethodAccess(uint32_t method_idx,
Ian Rogers62d6c772013-02-27 08:32:07 -0800191 InvokeType type)
Mathieu Chartier90443472015-07-16 20:32:27 -0700192 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800193
Mathieu Chartiere401d142015-04-22 13:56:20 -0700194void ThrowNullPointerExceptionForMethodAccess(ArtMethod* method,
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200195 InvokeType type)
Mathieu Chartier90443472015-07-16 20:32:27 -0700196 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200197
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000198void ThrowNullPointerExceptionFromDexPC()
Mathieu Chartier90443472015-07-16 20:32:27 -0700199 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800200
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000201void ThrowNullPointerException(const char* msg)
Mathieu Chartier90443472015-07-16 20:32:27 -0700202 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800203
204// RuntimeException
205
206void ThrowRuntimeException(const char* fmt, ...)
207 __attribute__((__format__(__printf__, 1, 2)))
Mathieu Chartier90443472015-07-16 20:32:27 -0700208 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers62d6c772013-02-27 08:32:07 -0800209
Andreas Gampe103992b2016-01-04 15:32:43 -0800210// Stack overflow.
211
212void ThrowStackOverflowError(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
213
Ian Rogers62d6c772013-02-27 08:32:07 -0800214// VerifyError
215
Ian Rogersef7d42f2014-01-06 12:55:46 -0800216void ThrowVerifyError(mirror::Class* referrer, const char* fmt, ...)
Ian Rogers62d6c772013-02-27 08:32:07 -0800217 __attribute__((__format__(__printf__, 2, 3)))
Mathieu Chartier90443472015-07-16 20:32:27 -0700218 SHARED_REQUIRES(Locks::mutator_lock_) COLD_ATTR;
Ian Rogers87e552d2012-08-31 15:54:48 -0700219
220} // namespace art
221
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700222#endif // ART_RUNTIME_COMMON_THROWS_H_