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 "base/mutex.h"
21 #include "invoke_type.h"
22 
23 namespace art {
24 namespace mirror {
25   class Class;
26   class Object;
27 }  // namespace mirror
28 class ArtField;
29 class ArtMethod;
30 class Signature;
31 class StringPiece;
32 
33 // AbstractMethodError
34 
35 void ThrowAbstractMethodError(ArtMethod* method)
36     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
37 
38 // ArithmeticException
39 
40 void ThrowArithmeticExceptionDivideByZero() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
41 
42 // ArrayIndexOutOfBoundsException
43 
44 void ThrowArrayIndexOutOfBoundsException(int index, int length)
45     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
46 
47 // ArrayStoreException
48 
49 void ThrowArrayStoreException(mirror::Class* element_class, mirror::Class* array_class)
50     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
51 
52 // ClassCircularityError
53 
54 void ThrowClassCircularityError(mirror::Class* c)
55     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
56 
57 // ClassCastException
58 
59 void ThrowClassCastException(mirror::Class* dest_type, mirror::Class* src_type)
60     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
61 
62 void ThrowClassCastException(const char* msg)
63     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
64 
65 // ClassFormatError
66 
67 void ThrowClassFormatError(mirror::Class* referrer, const char* fmt, ...)
68     __attribute__((__format__(__printf__, 2, 3)))
69     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
70 
71 // IllegalAccessError
72 
73 void ThrowIllegalAccessErrorClass(mirror::Class* referrer, mirror::Class* accessed)
74     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
75 
76 void ThrowIllegalAccessErrorClassForMethodDispatch(mirror::Class* referrer, mirror::Class* accessed,
77                                                    ArtMethod* called,
78                                                    InvokeType type)
79     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
80 
81 void ThrowIllegalAccessErrorMethod(mirror::Class* referrer, ArtMethod* accessed)
82     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
83 
84 void ThrowIllegalAccessErrorField(mirror::Class* referrer, ArtField* accessed)
85     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
86 
87 void ThrowIllegalAccessErrorFinalField(ArtMethod* referrer, ArtField* accessed)
88     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
89 
90 void ThrowIllegalAccessError(mirror::Class* referrer, const char* fmt, ...)
91     __attribute__((__format__(__printf__, 2, 3)))
92     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
93 
94 // IllegalAccessException
95 
96 void ThrowIllegalAccessException(const char* msg)
97     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
98 
99 // IllegalArgumentException
100 
101 void ThrowIllegalArgumentException(const char* msg)
102     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
103 
104 // IncompatibleClassChangeError
105 
106 void ThrowIncompatibleClassChangeError(InvokeType expected_type, InvokeType found_type,
107                                        ArtMethod* method, ArtMethod* referrer)
108     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
109 
110 void ThrowIncompatibleClassChangeErrorClassForInterfaceDispatch(ArtMethod* interface_method,
111                                                                 mirror::Object* this_object,
112                                                                 ArtMethod* referrer)
113     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
114 
115 void ThrowIncompatibleClassChangeErrorField(ArtField* resolved_field, bool is_static,
116                                             ArtMethod* referrer)
117     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
118 
119 void ThrowIncompatibleClassChangeError(mirror::Class* referrer, const char* fmt, ...)
120     __attribute__((__format__(__printf__, 2, 3)))
121     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
122 
123 // IOException
124 
125 void ThrowIOException(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)))
126     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
127 
128 void ThrowWrappedIOException(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)))
129     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
130 
131 // LinkageError
132 
133 void ThrowLinkageError(mirror::Class* referrer, const char* fmt, ...)
134     __attribute__((__format__(__printf__, 2, 3)))
135     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
136 
137 void ThrowWrappedLinkageError(mirror::Class* referrer, const char* fmt, ...)
138     __attribute__((__format__(__printf__, 2, 3)))
139     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
140 
141 // NegativeArraySizeException
142 
143 void ThrowNegativeArraySizeException(int size)
144     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
145 
146 void ThrowNegativeArraySizeException(const char* msg)
147     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
148 
149 
150 // NoSuchFieldError
151 
152 void ThrowNoSuchFieldError(const StringPiece& scope, mirror::Class* c,
153                            const StringPiece& type, const StringPiece& name)
154     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
155 
156 void ThrowNoSuchFieldException(mirror::Class* c, const StringPiece& name)
157     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
158 
159 // NoSuchMethodError
160 
161 void ThrowNoSuchMethodError(InvokeType type, mirror::Class* c, const StringPiece& name,
162                             const Signature& signature)
163     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
164 
165 void ThrowNoSuchMethodError(uint32_t method_idx)
166     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
167 
168 // NullPointerException
169 
170 void ThrowNullPointerExceptionForFieldAccess(ArtField* field,
171                                              bool is_read)
172     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
173 
174 void ThrowNullPointerExceptionForMethodAccess(uint32_t method_idx,
175                                               InvokeType type)
176     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
177 
178 void ThrowNullPointerExceptionForMethodAccess(ArtMethod* method,
179                                               InvokeType type)
180     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
181 
182 void ThrowNullPointerExceptionFromDexPC()
183     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
184 
185 void ThrowNullPointerException(const char* msg)
186     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
187 
188 // RuntimeException
189 
190 void ThrowRuntimeException(const char* fmt, ...)
191     __attribute__((__format__(__printf__, 1, 2)))
192     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
193 
194 // VerifyError
195 
196 void ThrowVerifyError(mirror::Class* referrer, const char* fmt, ...)
197     __attribute__((__format__(__printf__, 2, 3)))
198     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) COLD_ATTR;
199 
200 }  // namespace art
201 
202 #endif  // ART_RUNTIME_COMMON_THROWS_H_
203