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 // IllegalAccessException 115 116 void ThrowIllegalAccessException(const char* msg) 117 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 118 119 // IllegalArgumentException 120 121 void ThrowIllegalArgumentException(const char* msg) 122 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 123 124 // IllegalAccessException 125 126 void ThrowIllegalStateException(const char* msg) 127 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 128 129 // IncompatibleClassChangeError 130 131 void ThrowIncompatibleClassChangeError(InvokeType expected_type, 132 InvokeType found_type, 133 ArtMethod* method, 134 ArtMethod* referrer) 135 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 136 137 void ThrowIncompatibleClassChangeErrorClassForInterfaceDispatch(ArtMethod* interface_method, 138 ObjPtr<mirror::Object> this_object, 139 ArtMethod* referrer) 140 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 141 142 void ThrowIncompatibleClassChangeErrorField(ArtField* resolved_field, 143 bool is_static, 144 ArtMethod* referrer) 145 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 146 147 void ThrowIncompatibleClassChangeError(ObjPtr<mirror::Class> referrer, const char* fmt, ...) 148 __attribute__((__format__(__printf__, 2, 3))) 149 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 150 151 void ThrowIncompatibleClassChangeErrorForMethodConflict(ArtMethod* method) 152 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 153 154 // IndexOutOfBoundsException 155 156 void ThrowIndexOutOfBoundsException(int index, int length) 157 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 158 159 // InternalError 160 161 void ThrowInternalError(const char* fmt, ...) 162 __attribute__((__format__(__printf__, 1, 2))) 163 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 164 165 // IOException 166 167 void ThrowIOException(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2))) 168 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 169 170 void ThrowWrappedIOException(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2))) 171 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 172 173 // LinkageError 174 175 void ThrowLinkageError(ObjPtr<mirror::Class> referrer, const char* fmt, ...) 176 __attribute__((__format__(__printf__, 2, 3))) 177 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 178 179 void ThrowWrappedLinkageError(ObjPtr<mirror::Class> referrer, const char* fmt, ...) 180 __attribute__((__format__(__printf__, 2, 3))) 181 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 182 183 // NegativeArraySizeException 184 185 void ThrowNegativeArraySizeException(int size) 186 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 187 188 void ThrowNegativeArraySizeException(const char* msg) 189 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 190 191 192 // NoSuchFieldError 193 194 void ThrowNoSuchFieldError(std::string_view scope, 195 ObjPtr<mirror::Class> c, 196 std::string_view type, 197 std::string_view name) 198 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 199 200 void ThrowNoSuchFieldException(ObjPtr<mirror::Class> c, std::string_view name) 201 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 202 203 // NoSuchMethodError 204 205 void ThrowNoSuchMethodError(InvokeType type, 206 ObjPtr<mirror::Class> c, 207 std::string_view name, 208 const Signature& signature) 209 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 210 211 // NullPointerException 212 213 void ThrowNullPointerExceptionForFieldAccess(ArtField* field, ArtMethod* method, bool is_read) 214 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 215 216 void ThrowNullPointerExceptionForMethodAccess(uint32_t method_idx, 217 InvokeType type) 218 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 219 220 void ThrowNullPointerExceptionForMethodAccess(ArtMethod* method, 221 InvokeType type) 222 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 223 224 void ThrowNullPointerExceptionFromDexPC(bool check_address = false, uintptr_t addr = 0) 225 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 226 227 void ThrowNullPointerException(const char* msg) 228 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 229 230 void ThrowNullPointerException() 231 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 232 233 // ReadOnlyBufferException 234 235 void ThrowReadOnlyBufferException() REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 236 237 // RuntimeException 238 239 void ThrowRuntimeException(const char* fmt, ...) 240 __attribute__((__format__(__printf__, 1, 2))) 241 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 242 243 // SecurityException 244 245 void ThrowSecurityException(const char* fmt, ...) 246 __attribute__((__format__(__printf__, 1, 2))) 247 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 248 249 // Stack overflow. 250 251 void ThrowStackOverflowError(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 252 253 // StringIndexOutOfBoundsException 254 255 void ThrowStringIndexOutOfBoundsException(int index, int length) 256 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 257 258 // UnsupportedOperationException 259 260 void ThrowUnsupportedOperationException() REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 261 262 // VerifyError 263 264 void ThrowVerifyError(ObjPtr<mirror::Class> referrer, const char* fmt, ...) 265 __attribute__((__format__(__printf__, 2, 3))) 266 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 267 268 // WrongMethodTypeException 269 270 void ThrowWrongMethodTypeException(ObjPtr<mirror::MethodType> callee_type, 271 ObjPtr<mirror::MethodType> callsite_type) 272 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 273 274 void ThrowWrongMethodTypeException(const std::string& expected_descriptor, 275 const std::string& actual_descriptor) 276 REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR; 277 278 } // namespace art 279 280 #endif // ART_RUNTIME_COMMON_THROWS_H_ 281