• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 #ifndef ART_RUNTIME_COMMON_THROWS_H_
18 #define ART_RUNTIME_COMMON_THROWS_H_
19 
20 #include <string_view>
21 
22 #include "base/locks.h"
23 #include "base/macros.h"
24 #include "obj_ptr.h"
25 
26 namespace art HIDDEN {
27 namespace mirror {
28 class Class;
29 class Object;
30 class MethodType;
31 }  // namespace mirror
32 class ArtField;
33 class ArtMethod;
34 class DexFile;
35 enum InvokeType : uint32_t;
36 class Signature;
37 
38 // The descriptor of the transaction abort exception.
39 constexpr const char kTransactionAbortErrorDescriptor[] = "Ldalvik/system/TransactionAbortError;";
40 
41 // AbstractMethodError
42 
43 void ThrowAbstractMethodError(ArtMethod* method)
44     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
45 
46 void ThrowAbstractMethodError(uint32_t method_idx, const DexFile& dex_file)
47     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
48 
49 // ArithmeticException
50 
51 void ThrowArithmeticExceptionDivideByZero() REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
52 
53 // ArrayIndexOutOfBoundsException
54 
55 void ThrowArrayIndexOutOfBoundsException(int index, int length)
56     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
57 
58 // ArrayStoreException
59 
60 void ThrowArrayStoreException(ObjPtr<mirror::Class> element_class,
61                               ObjPtr<mirror::Class> array_class)
62     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
63 
64 // BootstrapMethodError
65 
66 void ThrowBootstrapMethodError(const char* fmt, ...)
67     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
68 
69 void ThrowWrappedBootstrapMethodError(const char* fmt, ...)
70     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
71 
72 // ClassCircularityError
73 
74 void ThrowClassCircularityError(ObjPtr<mirror::Class> c)
75     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
76 
77 void ThrowClassCircularityError(ObjPtr<mirror::Class> c, const char* fmt, ...)
78     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
79 
80 // ClassCastException
81 
82 void ThrowClassCastException(ObjPtr<mirror::Class> dest_type, ObjPtr<mirror::Class> src_type)
83     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
84 
85 void ThrowClassCastException(const char* msg)
86     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
87 
88 // ClassFormatError
89 
90 EXPORT void ThrowClassFormatError(ObjPtr<mirror::Class> referrer, const char* fmt, ...)
91     __attribute__((__format__(__printf__, 2, 3))) REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
92 
93 // IllegalAccessError
94 
95 EXPORT void ThrowIllegalAccessErrorClass(ObjPtr<mirror::Class> referrer,
96                                          ObjPtr<mirror::Class> accessed)
97     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
98 
99 void ThrowIllegalAccessErrorClassForMethodDispatch(ObjPtr<mirror::Class> referrer,
100                                                    ObjPtr<mirror::Class> accessed,
101                                                    ArtMethod* called,
102                                                    InvokeType type)
103     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
104 
105 void ThrowIllegalAccessErrorMethod(ObjPtr<mirror::Class> referrer, ArtMethod* accessed)
106     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
107 
108 EXPORT void ThrowIllegalAccessErrorField(ObjPtr<mirror::Class> referrer, ArtField* accessed)
109     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
110 
111 EXPORT void ThrowIllegalAccessErrorFinalField(ArtMethod* referrer, ArtField* accessed)
112     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
113 
114 void ThrowIllegalAccessError(ObjPtr<mirror::Class> referrer, const char* fmt, ...)
115     __attribute__((__format__(__printf__, 2, 3)))
116     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
117 
118 void ThrowIllegalAccessErrorForImplementingMethod(ObjPtr<mirror::Class> klass,
119                                                   ArtMethod* implementation_method,
120                                                   ArtMethod* interface_method)
121     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
122 
123 // IllegalAccessException
124 
125 void ThrowIllegalAccessException(const char* msg)
126     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
127 
128 // IllegalArgumentException
129 
130 void ThrowIllegalArgumentException(const char* msg)
131     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
132 
133 // IllegalAccessException
134 
135 EXPORT void ThrowIllegalStateException(const char* msg)
136     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
137 
138 // IncompatibleClassChangeError
139 
140 void ThrowIncompatibleClassChangeError(InvokeType expected_type,
141                                        InvokeType found_type,
142                                        ArtMethod* method,
143                                        ArtMethod* referrer)
144     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
145 
146 void ThrowIncompatibleClassChangeErrorClassForInterfaceDispatch(ArtMethod* interface_method,
147                                                                 ObjPtr<mirror::Object> this_object,
148                                                                 ArtMethod* referrer)
149     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
150 
151 EXPORT void ThrowIncompatibleClassChangeErrorField(ArtField* resolved_field,
152                                                    bool is_static,
153                                                    ArtMethod* referrer)
154     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
155 
156 void ThrowIncompatibleClassChangeError(ObjPtr<mirror::Class> referrer, const char* fmt, ...)
157     __attribute__((__format__(__printf__, 2, 3)))
158     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
159 
160 void ThrowIncompatibleClassChangeErrorForMethodConflict(ArtMethod* method)
161     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
162 
163 // IndexOutOfBoundsException
164 
165 void ThrowIndexOutOfBoundsException(int index, int length)
166     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
167 
168 // InternalError
169 
170 void ThrowInternalError(const char* fmt, ...)
171     __attribute__((__format__(__printf__, 1, 2)))
172     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
173 
174 // IOException
175 
176 void ThrowIOException(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)))
177     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
178 
179 void ThrowWrappedIOException(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)))
180     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
181 
182 // LinkageError
183 
184 void ThrowLinkageError(ObjPtr<mirror::Class> referrer, const char* fmt, ...)
185     __attribute__((__format__(__printf__, 2, 3)))
186     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
187 
188 void ThrowWrappedLinkageError(ObjPtr<mirror::Class> referrer, const char* fmt, ...)
189     __attribute__((__format__(__printf__, 2, 3)))
190     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
191 
192 // NegativeArraySizeException
193 
194 void ThrowNegativeArraySizeException(int size)
195     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
196 
197 void ThrowNegativeArraySizeException(const char* msg)
198     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
199 
200 
201 // NoSuchFieldError
202 
203 EXPORT void ThrowNoSuchFieldError(std::string_view scope,
204                                   ObjPtr<mirror::Class> c,
205                                   std::string_view type,
206                                   std::string_view name)
207     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
208 
209 void ThrowNoSuchFieldException(ObjPtr<mirror::Class> c, std::string_view name)
210     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
211 
212 // NoSuchMethodError
213 
214 void ThrowNoSuchMethodError(InvokeType type,
215                             ObjPtr<mirror::Class> c,
216                             std::string_view name,
217                             const Signature& signature)
218     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
219 
220 // NullPointerException
221 
222 void ThrowNullPointerExceptionForFieldAccess(ArtField* field, ArtMethod* method, bool is_read)
223     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
224 
225 void ThrowNullPointerExceptionForMethodAccess(uint32_t method_idx,
226                                               InvokeType type)
227     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
228 
229 void ThrowNullPointerExceptionForMethodAccess(ArtMethod* method,
230                                               InvokeType type)
231     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
232 
233 void ThrowNullPointerExceptionFromDexPC(bool check_address = false, uintptr_t addr = 0)
234     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
235 
236 EXPORT void ThrowNullPointerException(const char* msg)
237     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
238 
239 void ThrowNullPointerException()
240     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
241 
242 // ReadOnlyBufferException
243 
244 void ThrowReadOnlyBufferException() REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
245 
246 // RuntimeException
247 
248 void ThrowRuntimeException(const char* fmt, ...)
249     __attribute__((__format__(__printf__, 1, 2)))
250     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
251 
252 // SecurityException
253 
254 void ThrowSecurityException(const char* fmt, ...)
255     __attribute__((__format__(__printf__, 1, 2)))
256     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
257 
258 // Stack overflow.
259 
260 void ThrowStackOverflowError(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
261 
262 // StringIndexOutOfBoundsException
263 
264 void ThrowStringIndexOutOfBoundsException(int index, int length)
265     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
266 
267 // UnsupportedOperationException
268 
269 void ThrowUnsupportedOperationException() REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
270 
271 // VerifyError
272 
273 void ThrowVerifyError(ObjPtr<mirror::Class> referrer, const char* fmt, ...)
274     __attribute__((__format__(__printf__, 2, 3)))
275     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
276 
277 // WrongMethodTypeException
278 
279 void ThrowWrongMethodTypeException(ObjPtr<mirror::MethodType> callee_type,
280                                    ObjPtr<mirror::MethodType> callsite_type)
281     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
282 
283 void ThrowWrongMethodTypeException(const std::string& expected_descriptor,
284                                    const std::string& actual_descriptor)
285     REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
286 
287 }  // namespace art
288 
289 #endif  // ART_RUNTIME_COMMON_THROWS_H_
290