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