Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 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 | #include "common_throws.h" |
| 18 | |
Ian Rogers | 22d5e73 | 2014-07-15 22:23:51 -0700 | [diff] [blame] | 19 | #include <sstream> |
| 20 | |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 21 | #include "base/logging.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 22 | #include "class_linker-inl.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 23 | #include "dex_file-inl.h" |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 24 | #include "dex_instruction-inl.h" |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 25 | #include "invoke_type.h" |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 26 | #include "mirror/art_method-inl.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 27 | #include "mirror/class-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 28 | #include "mirror/object-inl.h" |
| 29 | #include "mirror/object_array-inl.h" |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 30 | #include "thread.h" |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 31 | #include "verifier/method_verifier.h" |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 32 | |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 33 | namespace art { |
| 34 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 35 | static void AddReferrerLocation(std::ostream& os, mirror::Class* referrer) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 36 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 37 | if (referrer != NULL) { |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 38 | std::string location(referrer->GetLocation()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 39 | if (!location.empty()) { |
| 40 | os << " (declaration of '" << PrettyDescriptor(referrer) |
| 41 | << "' appears in " << location << ")"; |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 46 | static void ThrowException(const char* exception_descriptor, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 47 | mirror::Class* referrer, const char* fmt, va_list* args = NULL) |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 48 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 49 | std::ostringstream msg; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 50 | if (args != NULL) { |
| 51 | std::string vmsg; |
| 52 | StringAppendV(&vmsg, fmt, *args); |
| 53 | msg << vmsg; |
| 54 | } else { |
| 55 | msg << fmt; |
| 56 | } |
| 57 | AddReferrerLocation(msg, referrer); |
| 58 | Thread* self = Thread::Current(); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 59 | self->ThrowNewException(exception_descriptor, msg.str().c_str()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 62 | static void ThrowWrappedException(const char* exception_descriptor, |
Andreas Gampe | 329d188 | 2014-04-08 10:32:19 -0700 | [diff] [blame] | 63 | mirror::Class* referrer, const char* fmt, va_list* args = NULL) |
| 64 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 65 | std::ostringstream msg; |
| 66 | if (args != NULL) { |
| 67 | std::string vmsg; |
| 68 | StringAppendV(&vmsg, fmt, *args); |
| 69 | msg << vmsg; |
| 70 | } else { |
| 71 | msg << fmt; |
| 72 | } |
| 73 | AddReferrerLocation(msg, referrer); |
| 74 | Thread* self = Thread::Current(); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 75 | self->ThrowNewWrappedException(exception_descriptor, msg.str().c_str()); |
Andreas Gampe | 329d188 | 2014-04-08 10:32:19 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Sebastien Hertz | 56adf60 | 2013-07-09 17:27:07 +0200 | [diff] [blame] | 78 | // AbstractMethodError |
| 79 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 80 | void ThrowAbstractMethodError(mirror::ArtMethod* method) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 81 | ThrowException("Ljava/lang/AbstractMethodError;", NULL, |
Sebastien Hertz | 56adf60 | 2013-07-09 17:27:07 +0200 | [diff] [blame] | 82 | StringPrintf("abstract method \"%s\"", |
| 83 | PrettyMethod(method).c_str()).c_str()); |
| 84 | } |
| 85 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 86 | // ArithmeticException |
| 87 | |
Sebastien Hertz | 0a3b863 | 2013-06-26 11:16:01 +0200 | [diff] [blame] | 88 | void ThrowArithmeticExceptionDivideByZero() { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 89 | ThrowException("Ljava/lang/ArithmeticException;", NULL, "divide by zero"); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | // ArrayIndexOutOfBoundsException |
| 93 | |
| 94 | void ThrowArrayIndexOutOfBoundsException(int index, int length) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 95 | ThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", NULL, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 96 | StringPrintf("length=%d; index=%d", length, index).c_str()); |
| 97 | } |
| 98 | |
| 99 | // ArrayStoreException |
| 100 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 101 | void ThrowArrayStoreException(mirror::Class* element_class, mirror::Class* array_class) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 102 | ThrowException("Ljava/lang/ArrayStoreException;", NULL, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 103 | StringPrintf("%s cannot be stored in an array of type %s", |
| 104 | PrettyDescriptor(element_class).c_str(), |
| 105 | PrettyDescriptor(array_class).c_str()).c_str()); |
| 106 | } |
| 107 | |
| 108 | // ClassCastException |
| 109 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 110 | void ThrowClassCastException(mirror::Class* dest_type, mirror::Class* src_type) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 111 | ThrowException("Ljava/lang/ClassCastException;", NULL, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 112 | StringPrintf("%s cannot be cast to %s", |
| 113 | PrettyDescriptor(src_type).c_str(), |
| 114 | PrettyDescriptor(dest_type).c_str()).c_str()); |
| 115 | } |
| 116 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 117 | void ThrowClassCastException(const char* msg) { |
| 118 | ThrowException("Ljava/lang/ClassCastException;", NULL, msg); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | // ClassCircularityError |
| 122 | |
| 123 | void ThrowClassCircularityError(mirror::Class* c) { |
| 124 | std::ostringstream msg; |
| 125 | msg << PrettyDescriptor(c); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 126 | ThrowException("Ljava/lang/ClassCircularityError;", c, msg.str().c_str()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | // ClassFormatError |
| 130 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 131 | void ThrowClassFormatError(mirror::Class* referrer, const char* fmt, ...) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 132 | va_list args; |
| 133 | va_start(args, fmt); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 134 | ThrowException("Ljava/lang/ClassFormatError;", referrer, fmt, &args); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 135 | va_end(args);} |
| 136 | |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 137 | // IllegalAccessError |
| 138 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 139 | void ThrowIllegalAccessErrorClass(mirror::Class* referrer, mirror::Class* accessed) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 140 | std::ostringstream msg; |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 141 | msg << "Illegal class access: '" << PrettyDescriptor(referrer) << "' attempting to access '" |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 142 | << PrettyDescriptor(accessed) << "'"; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 143 | ThrowException("Ljava/lang/IllegalAccessError;", referrer, msg.str().c_str()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 146 | void ThrowIllegalAccessErrorClassForMethodDispatch(mirror::Class* referrer, mirror::Class* accessed, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 147 | mirror::ArtMethod* called, |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 148 | InvokeType type) { |
| 149 | std::ostringstream msg; |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 150 | msg << "Illegal class access ('" << PrettyDescriptor(referrer) << "' attempting to access '" |
| 151 | << PrettyDescriptor(accessed) << "') in attempt to invoke " << type |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 152 | << " method " << PrettyMethod(called).c_str(); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 153 | ThrowException("Ljava/lang/IllegalAccessError;", referrer, msg.str().c_str()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 156 | void ThrowIllegalAccessErrorMethod(mirror::Class* referrer, mirror::ArtMethod* accessed) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 157 | std::ostringstream msg; |
| 158 | msg << "Method '" << PrettyMethod(accessed) << "' is inaccessible to class '" |
| 159 | << PrettyDescriptor(referrer) << "'"; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 160 | ThrowException("Ljava/lang/IllegalAccessError;", referrer, msg.str().c_str()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 163 | void ThrowIllegalAccessErrorField(mirror::Class* referrer, mirror::ArtField* accessed) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 164 | std::ostringstream msg; |
| 165 | msg << "Field '" << PrettyField(accessed, false) << "' is inaccessible to class '" |
| 166 | << PrettyDescriptor(referrer) << "'"; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 167 | ThrowException("Ljava/lang/IllegalAccessError;", referrer, msg.str().c_str()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 170 | void ThrowIllegalAccessErrorFinalField(mirror::ArtMethod* referrer, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 171 | mirror::ArtField* accessed) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 172 | std::ostringstream msg; |
| 173 | msg << "Final field '" << PrettyField(accessed, false) << "' cannot be written to by method '" |
| 174 | << PrettyMethod(referrer) << "'"; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 175 | ThrowException("Ljava/lang/IllegalAccessError;", |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 176 | referrer != NULL ? referrer->GetClass() : NULL, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 177 | msg.str().c_str()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 180 | void ThrowIllegalAccessError(mirror::Class* referrer, const char* fmt, ...) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 181 | va_list args; |
| 182 | va_start(args, fmt); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 183 | ThrowException("Ljava/lang/IllegalAccessError;", referrer, fmt, &args); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 184 | va_end(args); |
| 185 | } |
| 186 | |
Jeff Hao | 11d5d8f | 2014-03-26 15:08:20 -0700 | [diff] [blame] | 187 | // IllegalAccessException |
| 188 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 189 | void ThrowIllegalAccessException(const char* msg) { |
| 190 | ThrowException("Ljava/lang/IllegalAccessException;", NULL, msg); |
Jeff Hao | 11d5d8f | 2014-03-26 15:08:20 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 193 | // IllegalArgumentException |
| 194 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 195 | void ThrowIllegalArgumentException(const char* msg) { |
| 196 | ThrowException("Ljava/lang/IllegalArgumentException;", NULL, msg); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 200 | // IncompatibleClassChangeError |
| 201 | |
| 202 | void ThrowIncompatibleClassChangeError(InvokeType expected_type, InvokeType found_type, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 203 | mirror::ArtMethod* method, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 204 | mirror::ArtMethod* referrer) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 205 | std::ostringstream msg; |
| 206 | msg << "The method '" << PrettyMethod(method) << "' was expected to be of type " |
| 207 | << expected_type << " but instead was found to be of type " << found_type; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 208 | ThrowException("Ljava/lang/IncompatibleClassChangeError;", |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 209 | referrer != NULL ? referrer->GetClass() : NULL, |
| 210 | msg.str().c_str()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 213 | void ThrowIncompatibleClassChangeErrorClassForInterfaceDispatch(mirror::ArtMethod* interface_method, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 214 | mirror::Object* this_object, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 215 | mirror::ArtMethod* referrer) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 216 | // Referrer is calling interface_method on this_object, however, the interface_method isn't |
| 217 | // implemented by this_object. |
| 218 | CHECK(this_object != NULL); |
| 219 | std::ostringstream msg; |
| 220 | msg << "Class '" << PrettyDescriptor(this_object->GetClass()) |
| 221 | << "' does not implement interface '" |
| 222 | << PrettyDescriptor(interface_method->GetDeclaringClass()) |
| 223 | << "' in call to '" << PrettyMethod(interface_method) << "'"; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 224 | ThrowException("Ljava/lang/IncompatibleClassChangeError;", |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 225 | referrer != NULL ? referrer->GetClass() : NULL, |
| 226 | msg.str().c_str()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 229 | void ThrowIncompatibleClassChangeErrorField(mirror::ArtField* resolved_field, bool is_static, |
| 230 | mirror::ArtMethod* referrer) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 231 | std::ostringstream msg; |
| 232 | msg << "Expected '" << PrettyField(resolved_field) << "' to be a " |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 233 | << (is_static ? "static" : "instance") << " field" << " rather than a " |
| 234 | << (is_static ? "instance" : "static") << " field"; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 235 | ThrowException("Ljava/lang/IncompatibleClassChangeError;", referrer->GetClass(), |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 236 | msg.str().c_str()); |
| 237 | } |
| 238 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 239 | void ThrowIncompatibleClassChangeError(mirror::Class* referrer, const char* fmt, ...) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 240 | va_list args; |
| 241 | va_start(args, fmt); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 242 | ThrowException("Ljava/lang/IncompatibleClassChangeError;", referrer, fmt, &args); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 243 | va_end(args); |
| 244 | } |
| 245 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 246 | // IOException |
| 247 | |
| 248 | void ThrowIOException(const char* fmt, ...) { |
| 249 | va_list args; |
| 250 | va_start(args, fmt); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 251 | ThrowException("Ljava/io/IOException;", NULL, fmt, &args); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 252 | va_end(args); |
| 253 | } |
| 254 | |
Andreas Gampe | 329d188 | 2014-04-08 10:32:19 -0700 | [diff] [blame] | 255 | void ThrowWrappedIOException(const char* fmt, ...) { |
| 256 | va_list args; |
| 257 | va_start(args, fmt); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 258 | ThrowWrappedException("Ljava/io/IOException;", NULL, fmt, &args); |
Andreas Gampe | 329d188 | 2014-04-08 10:32:19 -0700 | [diff] [blame] | 259 | va_end(args); |
| 260 | } |
| 261 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 262 | // LinkageError |
| 263 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 264 | void ThrowLinkageError(mirror::Class* referrer, const char* fmt, ...) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 265 | va_list args; |
| 266 | va_start(args, fmt); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 267 | ThrowException("Ljava/lang/LinkageError;", referrer, fmt, &args); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 268 | va_end(args); |
| 269 | } |
| 270 | |
| 271 | // NegativeArraySizeException |
| 272 | |
| 273 | void ThrowNegativeArraySizeException(int size) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 274 | ThrowException("Ljava/lang/NegativeArraySizeException;", NULL, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 275 | StringPrintf("%d", size).c_str()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | void ThrowNegativeArraySizeException(const char* msg) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 279 | ThrowException("Ljava/lang/NegativeArraySizeException;", NULL, msg); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | // NoSuchFieldError |
| 283 | |
| 284 | void ThrowNoSuchFieldError(const StringPiece& scope, mirror::Class* c, |
| 285 | const StringPiece& type, const StringPiece& name) |
| 286 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 287 | std::ostringstream msg; |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 288 | std::string temp; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 289 | msg << "No " << scope << "field " << name << " of type " << type |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 290 | << " in class " << c->GetDescriptor(&temp) << " or its superclasses"; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 291 | ThrowException("Ljava/lang/NoSuchFieldError;", c, msg.str().c_str()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | // NoSuchMethodError |
| 295 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 296 | void ThrowNoSuchMethodError(InvokeType type, mirror::Class* c, const StringPiece& name, |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 297 | const Signature& signature) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 298 | std::ostringstream msg; |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 299 | std::string temp; |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 300 | msg << "No " << type << " method " << name << signature |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 301 | << " in class " << c->GetDescriptor(&temp) << " or its super classes"; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 302 | ThrowException("Ljava/lang/NoSuchMethodError;", c, msg.str().c_str()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 305 | void ThrowNoSuchMethodError(uint32_t method_idx) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 306 | mirror::ArtMethod* method = Thread::Current()->GetCurrentMethod(nullptr); |
| 307 | mirror::DexCache* dex_cache = method->GetDeclaringClass()->GetDexCache(); |
Ian Rogers | 4445a7e | 2012-10-05 17:19:13 -0700 | [diff] [blame] | 308 | const DexFile& dex_file = *dex_cache->GetDexFile(); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 309 | std::ostringstream msg; |
| 310 | msg << "No method '" << PrettyMethod(method_idx, dex_file, true) << "'"; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 311 | ThrowException("Ljava/lang/NoSuchMethodError;", |
| 312 | method->GetDeclaringClass(), msg.str().c_str()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | // NullPointerException |
| 316 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 317 | void ThrowNullPointerExceptionForFieldAccess(mirror::ArtField* field, bool is_read) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 318 | std::ostringstream msg; |
| 319 | msg << "Attempt to " << (is_read ? "read from" : "write to") |
| 320 | << " field '" << PrettyField(field, true) << "' on a null object reference"; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 321 | ThrowException("Ljava/lang/NullPointerException;", NULL, msg.str().c_str()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 322 | } |
| 323 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 324 | static void ThrowNullPointerExceptionForMethodAccessImpl(uint32_t method_idx, |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 325 | const DexFile& dex_file, |
| 326 | InvokeType type) |
| 327 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 328 | std::ostringstream msg; |
| 329 | msg << "Attempt to invoke " << type << " method '" |
| 330 | << PrettyMethod(method_idx, dex_file, true) << "' on a null object reference"; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 331 | ThrowException("Ljava/lang/NullPointerException;", NULL, msg.str().c_str()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 332 | } |
| 333 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 334 | void ThrowNullPointerExceptionForMethodAccess(uint32_t method_idx, |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 335 | InvokeType type) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 336 | mirror::DexCache* dex_cache = |
| 337 | Thread::Current()->GetCurrentMethod(nullptr)->GetDeclaringClass()->GetDexCache(); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 338 | const DexFile& dex_file = *dex_cache->GetDexFile(); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 339 | ThrowNullPointerExceptionForMethodAccessImpl(method_idx, dex_file, type); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 340 | } |
| 341 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 342 | void ThrowNullPointerExceptionForMethodAccess(mirror::ArtMethod* method, |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 343 | InvokeType type) { |
| 344 | mirror::DexCache* dex_cache = method->GetDeclaringClass()->GetDexCache(); |
| 345 | const DexFile& dex_file = *dex_cache->GetDexFile(); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 346 | ThrowNullPointerExceptionForMethodAccessImpl(method->GetDexMethodIndex(), |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 347 | dex_file, type); |
| 348 | } |
| 349 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 350 | void ThrowNullPointerExceptionFromDexPC() { |
| 351 | uint32_t throw_dex_pc; |
| 352 | mirror::ArtMethod* method = Thread::Current()->GetCurrentMethod(&throw_dex_pc); |
| 353 | const DexFile::CodeItem* code = method->GetCodeItem(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 354 | CHECK_LT(throw_dex_pc, code->insns_size_in_code_units_); |
| 355 | const Instruction* instr = Instruction::At(&code->insns_[throw_dex_pc]); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 356 | switch (instr->Opcode()) { |
| 357 | case Instruction::INVOKE_DIRECT: |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 358 | ThrowNullPointerExceptionForMethodAccess(instr->VRegB_35c(), kDirect); |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 359 | break; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 360 | case Instruction::INVOKE_DIRECT_RANGE: |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 361 | ThrowNullPointerExceptionForMethodAccess(instr->VRegB_3rc(), kDirect); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 362 | break; |
| 363 | case Instruction::INVOKE_VIRTUAL: |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 364 | ThrowNullPointerExceptionForMethodAccess(instr->VRegB_35c(), kVirtual); |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 365 | break; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 366 | case Instruction::INVOKE_VIRTUAL_RANGE: |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 367 | ThrowNullPointerExceptionForMethodAccess(instr->VRegB_3rc(), kVirtual); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 368 | break; |
| 369 | case Instruction::INVOKE_INTERFACE: |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 370 | ThrowNullPointerExceptionForMethodAccess(instr->VRegB_35c(), kInterface); |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 371 | break; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 372 | case Instruction::INVOKE_INTERFACE_RANGE: |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 373 | ThrowNullPointerExceptionForMethodAccess(instr->VRegB_3rc(), kInterface); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 374 | break; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 375 | case Instruction::INVOKE_VIRTUAL_QUICK: |
| 376 | case Instruction::INVOKE_VIRTUAL_RANGE_QUICK: { |
| 377 | // Since we replaced the method index, we ask the verifier to tell us which |
| 378 | // method is invoked at this location. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 379 | mirror::ArtMethod* invoked_method = |
| 380 | verifier::MethodVerifier::FindInvokedMethodAtDexPc(method, throw_dex_pc); |
| 381 | if (invoked_method != NULL) { |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 382 | // NPE with precise message. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 383 | ThrowNullPointerExceptionForMethodAccess(invoked_method, kVirtual); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 384 | } else { |
| 385 | // NPE with imprecise message. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 386 | ThrowNullPointerException("Attempt to invoke a virtual method on a null object reference"); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 387 | } |
| 388 | break; |
| 389 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 390 | case Instruction::IGET: |
| 391 | case Instruction::IGET_WIDE: |
| 392 | case Instruction::IGET_OBJECT: |
| 393 | case Instruction::IGET_BOOLEAN: |
| 394 | case Instruction::IGET_BYTE: |
| 395 | case Instruction::IGET_CHAR: |
| 396 | case Instruction::IGET_SHORT: { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 397 | mirror::ArtField* field = |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 398 | Runtime::Current()->GetClassLinker()->ResolveField(instr->VRegC_22c(), method, false); |
| 399 | ThrowNullPointerExceptionForFieldAccess(field, true /* read */); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 400 | break; |
| 401 | } |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 402 | case Instruction::IGET_QUICK: |
Mathieu Chartier | ffc605c | 2014-12-10 10:35:44 -0800 | [diff] [blame] | 403 | case Instruction::IGET_BOOLEAN_QUICK: |
| 404 | case Instruction::IGET_BYTE_QUICK: |
| 405 | case Instruction::IGET_CHAR_QUICK: |
| 406 | case Instruction::IGET_SHORT_QUICK: |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 407 | case Instruction::IGET_WIDE_QUICK: |
| 408 | case Instruction::IGET_OBJECT_QUICK: { |
| 409 | // Since we replaced the field index, we ask the verifier to tell us which |
| 410 | // field is accessed at this location. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 411 | mirror::ArtField* field = |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 412 | verifier::MethodVerifier::FindAccessedFieldAtDexPc(method, throw_dex_pc); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 413 | if (field != NULL) { |
| 414 | // NPE with precise message. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 415 | ThrowNullPointerExceptionForFieldAccess(field, true /* read */); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 416 | } else { |
| 417 | // NPE with imprecise message. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 418 | ThrowNullPointerException("Attempt to read from a field on a null object reference"); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 419 | } |
| 420 | break; |
| 421 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 422 | case Instruction::IPUT: |
| 423 | case Instruction::IPUT_WIDE: |
| 424 | case Instruction::IPUT_OBJECT: |
| 425 | case Instruction::IPUT_BOOLEAN: |
| 426 | case Instruction::IPUT_BYTE: |
| 427 | case Instruction::IPUT_CHAR: |
| 428 | case Instruction::IPUT_SHORT: { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 429 | mirror::ArtField* field = |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 430 | Runtime::Current()->GetClassLinker()->ResolveField(instr->VRegC_22c(), method, false); |
| 431 | ThrowNullPointerExceptionForFieldAccess(field, false /* write */); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 432 | break; |
| 433 | } |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 434 | case Instruction::IPUT_QUICK: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 435 | case Instruction::IPUT_BOOLEAN_QUICK: |
| 436 | case Instruction::IPUT_BYTE_QUICK: |
| 437 | case Instruction::IPUT_CHAR_QUICK: |
| 438 | case Instruction::IPUT_SHORT_QUICK: |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 439 | case Instruction::IPUT_WIDE_QUICK: |
| 440 | case Instruction::IPUT_OBJECT_QUICK: { |
| 441 | // Since we replaced the field index, we ask the verifier to tell us which |
| 442 | // field is accessed at this location. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 443 | mirror::ArtField* field = |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 444 | verifier::MethodVerifier::FindAccessedFieldAtDexPc(method, throw_dex_pc); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 445 | if (field != NULL) { |
| 446 | // NPE with precise message. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 447 | ThrowNullPointerExceptionForFieldAccess(field, false /* write */); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 448 | } else { |
| 449 | // NPE with imprecise message. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 450 | ThrowNullPointerException("Attempt to write to a field on a null object reference"); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 451 | } |
| 452 | break; |
| 453 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 454 | case Instruction::AGET: |
| 455 | case Instruction::AGET_WIDE: |
| 456 | case Instruction::AGET_OBJECT: |
| 457 | case Instruction::AGET_BOOLEAN: |
| 458 | case Instruction::AGET_BYTE: |
| 459 | case Instruction::AGET_CHAR: |
| 460 | case Instruction::AGET_SHORT: |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 461 | ThrowException("Ljava/lang/NullPointerException;", NULL, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 462 | "Attempt to read from null array"); |
| 463 | break; |
| 464 | case Instruction::APUT: |
| 465 | case Instruction::APUT_WIDE: |
| 466 | case Instruction::APUT_OBJECT: |
| 467 | case Instruction::APUT_BOOLEAN: |
| 468 | case Instruction::APUT_BYTE: |
| 469 | case Instruction::APUT_CHAR: |
| 470 | case Instruction::APUT_SHORT: |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 471 | ThrowException("Ljava/lang/NullPointerException;", NULL, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 472 | "Attempt to write to null array"); |
| 473 | break; |
| 474 | case Instruction::ARRAY_LENGTH: |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 475 | ThrowException("Ljava/lang/NullPointerException;", NULL, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 476 | "Attempt to get length of null array"); |
| 477 | break; |
| 478 | default: { |
| 479 | // TODO: We should have covered all the cases where we expect a NPE above, this |
| 480 | // message/logging is so we can improve any cases we've missed in the future. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 481 | const DexFile* dex_file = |
| 482 | method->GetDeclaringClass()->GetDexCache()->GetDexFile(); |
| 483 | ThrowException("Ljava/lang/NullPointerException;", NULL, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 484 | StringPrintf("Null pointer exception during instruction '%s'", |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 485 | instr->DumpString(dex_file).c_str()).c_str()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 486 | break; |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 491 | void ThrowNullPointerException(const char* msg) { |
| 492 | ThrowException("Ljava/lang/NullPointerException;", NULL, msg); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | // RuntimeException |
| 496 | |
| 497 | void ThrowRuntimeException(const char* fmt, ...) { |
| 498 | va_list args; |
| 499 | va_start(args, fmt); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 500 | ThrowException("Ljava/lang/RuntimeException;", NULL, fmt, &args); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 501 | va_end(args); |
| 502 | } |
| 503 | |
| 504 | // VerifyError |
| 505 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 506 | void ThrowVerifyError(mirror::Class* referrer, const char* fmt, ...) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 507 | va_list args; |
| 508 | va_start(args, fmt); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame^] | 509 | ThrowException("Ljava/lang/VerifyError;", referrer, fmt, &args); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 510 | va_end(args); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | } // namespace art |