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 | |
Andreas Gampe | 103992b | 2016-01-04 15:32:43 -0800 | [diff] [blame] | 21 | #include "ScopedLocalRef.h" |
| 22 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 23 | #include "art_field-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 24 | #include "art_method-inl.h" |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 25 | #include "base/logging.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 26 | #include "class_linker-inl.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 27 | #include "dex_file-inl.h" |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 28 | #include "dex_instruction-inl.h" |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 29 | #include "invoke_type.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 30 | #include "mirror/class-inl.h" |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 31 | #include "mirror/method_type.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 32 | #include "mirror/object-inl.h" |
| 33 | #include "mirror/object_array-inl.h" |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 34 | #include "obj_ptr-inl.h" |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 35 | #include "thread.h" |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 36 | #include "verifier/method_verifier.h" |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 37 | |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 38 | namespace art { |
| 39 | |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 40 | static void AddReferrerLocation(std::ostream& os, ObjPtr<mirror::Class> referrer) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 41 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 42 | if (referrer != nullptr) { |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 43 | std::string location(referrer->GetLocation()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 44 | if (!location.empty()) { |
| 45 | os << " (declaration of '" << PrettyDescriptor(referrer) |
| 46 | << "' appears in " << location << ")"; |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 51 | static void ThrowException(const char* exception_descriptor, |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 52 | ObjPtr<mirror::Class> referrer, |
| 53 | const char* fmt, |
| 54 | va_list* args = nullptr) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 55 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 56 | std::ostringstream msg; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 57 | if (args != nullptr) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 58 | std::string vmsg; |
| 59 | StringAppendV(&vmsg, fmt, *args); |
| 60 | msg << vmsg; |
| 61 | } else { |
| 62 | msg << fmt; |
| 63 | } |
| 64 | AddReferrerLocation(msg, referrer); |
| 65 | Thread* self = Thread::Current(); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 66 | self->ThrowNewException(exception_descriptor, msg.str().c_str()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 69 | static void ThrowWrappedException(const char* exception_descriptor, |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 70 | ObjPtr<mirror::Class> referrer, |
| 71 | const char* fmt, |
| 72 | va_list* args = nullptr) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 73 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | 329d188 | 2014-04-08 10:32:19 -0700 | [diff] [blame] | 74 | std::ostringstream msg; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 75 | if (args != nullptr) { |
Andreas Gampe | 329d188 | 2014-04-08 10:32:19 -0700 | [diff] [blame] | 76 | std::string vmsg; |
| 77 | StringAppendV(&vmsg, fmt, *args); |
| 78 | msg << vmsg; |
| 79 | } else { |
| 80 | msg << fmt; |
| 81 | } |
| 82 | AddReferrerLocation(msg, referrer); |
| 83 | Thread* self = Thread::Current(); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 84 | self->ThrowNewWrappedException(exception_descriptor, msg.str().c_str()); |
Andreas Gampe | 329d188 | 2014-04-08 10:32:19 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Sebastien Hertz | 56adf60 | 2013-07-09 17:27:07 +0200 | [diff] [blame] | 87 | // AbstractMethodError |
| 88 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 89 | void ThrowAbstractMethodError(ArtMethod* method) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 90 | ThrowException("Ljava/lang/AbstractMethodError;", nullptr, |
Sebastien Hertz | 56adf60 | 2013-07-09 17:27:07 +0200 | [diff] [blame] | 91 | StringPrintf("abstract method \"%s\"", |
| 92 | PrettyMethod(method).c_str()).c_str()); |
| 93 | } |
| 94 | |
Alex Light | 705ad49 | 2015-09-21 11:36:30 -0700 | [diff] [blame] | 95 | void ThrowAbstractMethodError(uint32_t method_idx, const DexFile& dex_file) { |
| 96 | ThrowException("Ljava/lang/AbstractMethodError;", /* referrer */ nullptr, |
| 97 | StringPrintf("abstract method \"%s\"", |
| 98 | PrettyMethod(method_idx, |
| 99 | dex_file, |
| 100 | /* with_signature */ true).c_str()).c_str()); |
| 101 | } |
| 102 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 103 | // ArithmeticException |
| 104 | |
Sebastien Hertz | 0a3b863 | 2013-06-26 11:16:01 +0200 | [diff] [blame] | 105 | void ThrowArithmeticExceptionDivideByZero() { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 106 | ThrowException("Ljava/lang/ArithmeticException;", nullptr, "divide by zero"); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | // ArrayIndexOutOfBoundsException |
| 110 | |
| 111 | void ThrowArrayIndexOutOfBoundsException(int index, int length) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 112 | ThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", nullptr, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 113 | StringPrintf("length=%d; index=%d", length, index).c_str()); |
| 114 | } |
| 115 | |
| 116 | // ArrayStoreException |
| 117 | |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 118 | void ThrowArrayStoreException(ObjPtr<mirror::Class> element_class, |
| 119 | ObjPtr<mirror::Class> array_class) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 120 | ThrowException("Ljava/lang/ArrayStoreException;", nullptr, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 121 | StringPrintf("%s cannot be stored in an array of type %s", |
| 122 | PrettyDescriptor(element_class).c_str(), |
| 123 | PrettyDescriptor(array_class).c_str()).c_str()); |
| 124 | } |
| 125 | |
| 126 | // ClassCastException |
| 127 | |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 128 | void ThrowClassCastException(ObjPtr<mirror::Class> dest_type, ObjPtr<mirror::Class> src_type) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 129 | ThrowException("Ljava/lang/ClassCastException;", nullptr, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 130 | StringPrintf("%s cannot be cast to %s", |
| 131 | PrettyDescriptor(src_type).c_str(), |
| 132 | PrettyDescriptor(dest_type).c_str()).c_str()); |
| 133 | } |
| 134 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 135 | void ThrowClassCastException(const char* msg) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 136 | ThrowException("Ljava/lang/ClassCastException;", nullptr, msg); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | // ClassCircularityError |
| 140 | |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 141 | void ThrowClassCircularityError(ObjPtr<mirror::Class> c) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 142 | std::ostringstream msg; |
| 143 | msg << PrettyDescriptor(c); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 144 | ThrowException("Ljava/lang/ClassCircularityError;", c, msg.str().c_str()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 145 | } |
| 146 | |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 147 | void ThrowClassCircularityError(ObjPtr<mirror::Class> c, const char* fmt, ...) { |
Roland Levillain | 989ab3b | 2016-05-18 15:52:54 +0100 | [diff] [blame] | 148 | va_list args; |
| 149 | va_start(args, fmt); |
| 150 | ThrowException("Ljava/lang/ClassCircularityError;", c, fmt, &args); |
| 151 | va_end(args); |
| 152 | } |
| 153 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 154 | // ClassFormatError |
| 155 | |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 156 | void ThrowClassFormatError(ObjPtr<mirror::Class> referrer, const char* fmt, ...) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 157 | va_list args; |
| 158 | va_start(args, fmt); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 159 | ThrowException("Ljava/lang/ClassFormatError;", referrer, fmt, &args); |
Roland Levillain | ab880f4 | 2016-05-12 16:24:36 +0100 | [diff] [blame] | 160 | va_end(args); |
| 161 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 162 | |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 163 | // IllegalAccessError |
| 164 | |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 165 | void ThrowIllegalAccessErrorClass(ObjPtr<mirror::Class> referrer, ObjPtr<mirror::Class> accessed) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 166 | std::ostringstream msg; |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 167 | msg << "Illegal class access: '" << PrettyDescriptor(referrer) << "' attempting to access '" |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 168 | << PrettyDescriptor(accessed) << "'"; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 169 | ThrowException("Ljava/lang/IllegalAccessError;", referrer, msg.str().c_str()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 172 | void ThrowIllegalAccessErrorClassForMethodDispatch(ObjPtr<mirror::Class> referrer, |
| 173 | ObjPtr<mirror::Class> accessed, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 174 | ArtMethod* called, |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 175 | InvokeType type) { |
| 176 | std::ostringstream msg; |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 177 | msg << "Illegal class access ('" << PrettyDescriptor(referrer) << "' attempting to access '" |
| 178 | << PrettyDescriptor(accessed) << "') in attempt to invoke " << type |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 179 | << " method " << PrettyMethod(called).c_str(); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 180 | ThrowException("Ljava/lang/IllegalAccessError;", referrer, msg.str().c_str()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 183 | void ThrowIllegalAccessErrorMethod(ObjPtr<mirror::Class> referrer, ArtMethod* accessed) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 184 | std::ostringstream msg; |
| 185 | msg << "Method '" << PrettyMethod(accessed) << "' is inaccessible to class '" |
| 186 | << PrettyDescriptor(referrer) << "'"; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 187 | ThrowException("Ljava/lang/IllegalAccessError;", referrer, msg.str().c_str()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 190 | void ThrowIllegalAccessErrorField(ObjPtr<mirror::Class> referrer, ArtField* accessed) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 191 | std::ostringstream msg; |
| 192 | msg << "Field '" << PrettyField(accessed, false) << "' is inaccessible to class '" |
| 193 | << PrettyDescriptor(referrer) << "'"; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 194 | ThrowException("Ljava/lang/IllegalAccessError;", referrer, msg.str().c_str()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 197 | void ThrowIllegalAccessErrorFinalField(ArtMethod* referrer, ArtField* accessed) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 198 | std::ostringstream msg; |
| 199 | msg << "Final field '" << PrettyField(accessed, false) << "' cannot be written to by method '" |
| 200 | << PrettyMethod(referrer) << "'"; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 201 | ThrowException("Ljava/lang/IllegalAccessError;", |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 202 | referrer != nullptr ? referrer->GetDeclaringClass() : nullptr, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 203 | msg.str().c_str()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 206 | void ThrowIllegalAccessError(ObjPtr<mirror::Class> referrer, const char* fmt, ...) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 207 | va_list args; |
| 208 | va_start(args, fmt); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 209 | ThrowException("Ljava/lang/IllegalAccessError;", referrer, fmt, &args); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 210 | va_end(args); |
| 211 | } |
| 212 | |
Jeff Hao | 11d5d8f | 2014-03-26 15:08:20 -0700 | [diff] [blame] | 213 | // IllegalAccessException |
| 214 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 215 | void ThrowIllegalAccessException(const char* msg) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 216 | ThrowException("Ljava/lang/IllegalAccessException;", nullptr, msg); |
Jeff Hao | 11d5d8f | 2014-03-26 15:08:20 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 219 | // IllegalArgumentException |
| 220 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 221 | void ThrowIllegalArgumentException(const char* msg) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 222 | ThrowException("Ljava/lang/IllegalArgumentException;", nullptr, msg); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 226 | // IncompatibleClassChangeError |
| 227 | |
| 228 | void ThrowIncompatibleClassChangeError(InvokeType expected_type, InvokeType found_type, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 229 | ArtMethod* method, ArtMethod* referrer) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 230 | std::ostringstream msg; |
| 231 | msg << "The method '" << PrettyMethod(method) << "' was expected to be of type " |
| 232 | << expected_type << " but instead was found to be of type " << found_type; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 233 | ThrowException("Ljava/lang/IncompatibleClassChangeError;", |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 234 | referrer != nullptr ? referrer->GetDeclaringClass() : nullptr, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 235 | msg.str().c_str()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Alex Light | 705ad49 | 2015-09-21 11:36:30 -0700 | [diff] [blame] | 238 | void ThrowIncompatibleClassChangeErrorClassForInterfaceSuper(ArtMethod* method, |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 239 | ObjPtr<mirror::Class> target_class, |
| 240 | ObjPtr<mirror::Object> this_object, |
Alex Light | 705ad49 | 2015-09-21 11:36:30 -0700 | [diff] [blame] | 241 | ArtMethod* referrer) { |
| 242 | // Referrer is calling interface_method on this_object, however, the interface_method isn't |
| 243 | // implemented by this_object. |
| 244 | CHECK(this_object != nullptr); |
| 245 | std::ostringstream msg; |
| 246 | msg << "Class '" << PrettyDescriptor(this_object->GetClass()) |
| 247 | << "' does not implement interface '" << PrettyDescriptor(target_class) << "' in call to '" |
| 248 | << PrettyMethod(method) << "'"; |
| 249 | ThrowException("Ljava/lang/IncompatibleClassChangeError;", |
| 250 | referrer != nullptr ? referrer->GetDeclaringClass() : nullptr, |
| 251 | msg.str().c_str()); |
| 252 | } |
| 253 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 254 | void ThrowIncompatibleClassChangeErrorClassForInterfaceDispatch(ArtMethod* interface_method, |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 255 | ObjPtr<mirror::Object> this_object, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 256 | ArtMethod* referrer) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 257 | // Referrer is calling interface_method on this_object, however, the interface_method isn't |
| 258 | // implemented by this_object. |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 259 | CHECK(this_object != nullptr); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 260 | std::ostringstream msg; |
| 261 | msg << "Class '" << PrettyDescriptor(this_object->GetClass()) |
| 262 | << "' does not implement interface '" |
| 263 | << PrettyDescriptor(interface_method->GetDeclaringClass()) |
| 264 | << "' in call to '" << PrettyMethod(interface_method) << "'"; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 265 | ThrowException("Ljava/lang/IncompatibleClassChangeError;", |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 266 | referrer != nullptr ? referrer->GetDeclaringClass() : nullptr, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 267 | msg.str().c_str()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 270 | void ThrowIncompatibleClassChangeErrorField(ArtField* resolved_field, bool is_static, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 271 | ArtMethod* referrer) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 272 | std::ostringstream msg; |
| 273 | msg << "Expected '" << PrettyField(resolved_field) << "' to be a " |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 274 | << (is_static ? "static" : "instance") << " field" << " rather than a " |
| 275 | << (is_static ? "instance" : "static") << " field"; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 276 | ThrowException("Ljava/lang/IncompatibleClassChangeError;", referrer->GetDeclaringClass(), |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 277 | msg.str().c_str()); |
| 278 | } |
| 279 | |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 280 | void ThrowIncompatibleClassChangeError(ObjPtr<mirror::Class> referrer, const char* fmt, ...) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 281 | va_list args; |
| 282 | va_start(args, fmt); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 283 | ThrowException("Ljava/lang/IncompatibleClassChangeError;", referrer, fmt, &args); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 284 | va_end(args); |
| 285 | } |
| 286 | |
Alex Light | 9139e00 | 2015-10-09 15:59:48 -0700 | [diff] [blame] | 287 | void ThrowIncompatibleClassChangeErrorForMethodConflict(ArtMethod* method) { |
| 288 | DCHECK(method != nullptr); |
| 289 | ThrowException("Ljava/lang/IncompatibleClassChangeError;", |
| 290 | /*referrer*/nullptr, |
| 291 | StringPrintf("Conflicting default method implementations %s", |
| 292 | PrettyMethod(method).c_str()).c_str()); |
| 293 | } |
| 294 | |
| 295 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 296 | // IOException |
| 297 | |
| 298 | void ThrowIOException(const char* fmt, ...) { |
| 299 | va_list args; |
| 300 | va_start(args, fmt); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 301 | ThrowException("Ljava/io/IOException;", nullptr, fmt, &args); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 302 | va_end(args); |
| 303 | } |
| 304 | |
Andreas Gampe | 329d188 | 2014-04-08 10:32:19 -0700 | [diff] [blame] | 305 | void ThrowWrappedIOException(const char* fmt, ...) { |
| 306 | va_list args; |
| 307 | va_start(args, fmt); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 308 | ThrowWrappedException("Ljava/io/IOException;", nullptr, fmt, &args); |
Andreas Gampe | 329d188 | 2014-04-08 10:32:19 -0700 | [diff] [blame] | 309 | va_end(args); |
| 310 | } |
| 311 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 312 | // LinkageError |
| 313 | |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 314 | void ThrowLinkageError(ObjPtr<mirror::Class> referrer, const char* fmt, ...) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 315 | va_list args; |
| 316 | va_start(args, fmt); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 317 | ThrowException("Ljava/lang/LinkageError;", referrer, fmt, &args); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 318 | va_end(args); |
| 319 | } |
| 320 | |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 321 | void ThrowWrappedLinkageError(ObjPtr<mirror::Class> referrer, const char* fmt, ...) { |
Vladimir Marko | d5e5a0e | 2015-05-08 12:26:59 +0100 | [diff] [blame] | 322 | va_list args; |
| 323 | va_start(args, fmt); |
| 324 | ThrowWrappedException("Ljava/lang/LinkageError;", referrer, fmt, &args); |
| 325 | va_end(args); |
| 326 | } |
| 327 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 328 | // NegativeArraySizeException |
| 329 | |
| 330 | void ThrowNegativeArraySizeException(int size) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 331 | ThrowException("Ljava/lang/NegativeArraySizeException;", nullptr, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 332 | StringPrintf("%d", size).c_str()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | void ThrowNegativeArraySizeException(const char* msg) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 336 | ThrowException("Ljava/lang/NegativeArraySizeException;", nullptr, msg); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | // NoSuchFieldError |
| 340 | |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 341 | void ThrowNoSuchFieldError(const StringPiece& scope, ObjPtr<mirror::Class> c, |
Mathieu Chartier | 4e06778 | 2015-05-13 13:13:24 -0700 | [diff] [blame] | 342 | const StringPiece& type, const StringPiece& name) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 343 | std::ostringstream msg; |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 344 | std::string temp; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 345 | msg << "No " << scope << "field " << name << " of type " << type |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 346 | << " in class " << c->GetDescriptor(&temp) << " or its superclasses"; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 347 | ThrowException("Ljava/lang/NoSuchFieldError;", c, msg.str().c_str()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 350 | void ThrowNoSuchFieldException(ObjPtr<mirror::Class> c, const StringPiece& name) { |
Mathieu Chartier | 4e06778 | 2015-05-13 13:13:24 -0700 | [diff] [blame] | 351 | std::ostringstream msg; |
| 352 | std::string temp; |
| 353 | msg << "No field " << name << " in class " << c->GetDescriptor(&temp); |
| 354 | ThrowException("Ljava/lang/NoSuchFieldException;", c, msg.str().c_str()); |
| 355 | } |
| 356 | |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 357 | // NoSuchMethodError |
| 358 | |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 359 | void ThrowNoSuchMethodError(InvokeType type, ObjPtr<mirror::Class> c, const StringPiece& name, |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 360 | const Signature& signature) { |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 361 | std::ostringstream msg; |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 362 | std::string temp; |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 363 | msg << "No " << type << " method " << name << signature |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 364 | << " in class " << c->GetDescriptor(&temp) << " or its super classes"; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 365 | ThrowException("Ljava/lang/NoSuchMethodError;", c, msg.str().c_str()); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 368 | // NullPointerException |
| 369 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 370 | void ThrowNullPointerExceptionForFieldAccess(ArtField* field, bool is_read) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 371 | std::ostringstream msg; |
| 372 | msg << "Attempt to " << (is_read ? "read from" : "write to") |
| 373 | << " field '" << PrettyField(field, true) << "' on a null object reference"; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 374 | ThrowException("Ljava/lang/NullPointerException;", nullptr, msg.str().c_str()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 375 | } |
| 376 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 377 | static void ThrowNullPointerExceptionForMethodAccessImpl(uint32_t method_idx, |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 378 | const DexFile& dex_file, |
| 379 | InvokeType type) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 380 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 381 | std::ostringstream msg; |
| 382 | msg << "Attempt to invoke " << type << " method '" |
| 383 | << PrettyMethod(method_idx, dex_file, true) << "' on a null object reference"; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 384 | ThrowException("Ljava/lang/NullPointerException;", nullptr, msg.str().c_str()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 385 | } |
| 386 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 387 | void ThrowNullPointerExceptionForMethodAccess(uint32_t method_idx, |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 388 | InvokeType type) { |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 389 | ObjPtr<mirror::DexCache> dex_cache = |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 390 | Thread::Current()->GetCurrentMethod(nullptr)->GetDeclaringClass()->GetDexCache(); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 391 | const DexFile& dex_file = *dex_cache->GetDexFile(); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 392 | ThrowNullPointerExceptionForMethodAccessImpl(method_idx, dex_file, type); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 393 | } |
| 394 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 395 | void ThrowNullPointerExceptionForMethodAccess(ArtMethod* method, |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 396 | InvokeType type) { |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 397 | ObjPtr<mirror::DexCache> dex_cache = method->GetDeclaringClass()->GetDexCache(); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 398 | const DexFile& dex_file = *dex_cache->GetDexFile(); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 399 | ThrowNullPointerExceptionForMethodAccessImpl(method->GetDexMethodIndex(), |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 400 | dex_file, type); |
| 401 | } |
| 402 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 403 | static bool IsValidReadBarrierImplicitCheck(uintptr_t addr) { |
| 404 | DCHECK(kEmitCompilerReadBarrier); |
| 405 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Uint32Value(); |
| 406 | if (kUseBakerReadBarrier && (kRuntimeISA == kX86 || kRuntimeISA == kX86_64)) { |
| 407 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 408 | monitor_offset += gray_byte_position; |
| 409 | } |
| 410 | return addr == monitor_offset; |
| 411 | } |
| 412 | |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 413 | static bool IsValidImplicitCheck(uintptr_t addr, ArtMethod* method, const Instruction& instr) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 414 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 415 | if (!CanDoImplicitNullCheckOn(addr)) { |
| 416 | return false; |
| 417 | } |
| 418 | |
| 419 | switch (instr.Opcode()) { |
| 420 | case Instruction::INVOKE_DIRECT: |
| 421 | case Instruction::INVOKE_DIRECT_RANGE: |
| 422 | case Instruction::INVOKE_VIRTUAL: |
| 423 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 424 | case Instruction::INVOKE_INTERFACE: |
| 425 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 426 | case Instruction::INVOKE_VIRTUAL_QUICK: |
| 427 | case Instruction::INVOKE_VIRTUAL_RANGE_QUICK: { |
| 428 | // Without inlining, we could just check that the offset is the class offset. |
| 429 | // However, when inlining, the compiler can (validly) merge the null check with a field access |
| 430 | // on the same object. Note that the stack map at the NPE will reflect the invoke's location, |
| 431 | // which is the caller. |
| 432 | return true; |
| 433 | } |
| 434 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 435 | case Instruction::IGET_OBJECT: |
| 436 | if (kEmitCompilerReadBarrier && IsValidReadBarrierImplicitCheck(addr)) { |
| 437 | return true; |
| 438 | } |
| 439 | FALLTHROUGH_INTENDED; |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 440 | case Instruction::IGET: |
| 441 | case Instruction::IGET_WIDE: |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 442 | case Instruction::IGET_BOOLEAN: |
| 443 | case Instruction::IGET_BYTE: |
| 444 | case Instruction::IGET_CHAR: |
| 445 | case Instruction::IGET_SHORT: |
| 446 | case Instruction::IPUT: |
| 447 | case Instruction::IPUT_WIDE: |
| 448 | case Instruction::IPUT_OBJECT: |
| 449 | case Instruction::IPUT_BOOLEAN: |
| 450 | case Instruction::IPUT_BYTE: |
| 451 | case Instruction::IPUT_CHAR: |
| 452 | case Instruction::IPUT_SHORT: { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 453 | ArtField* field = |
| 454 | Runtime::Current()->GetClassLinker()->ResolveField(instr.VRegC_22c(), method, false); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 455 | return (addr == 0) || (addr == field->GetOffset().Uint32Value()); |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 456 | } |
| 457 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 458 | case Instruction::IGET_OBJECT_QUICK: |
| 459 | if (kEmitCompilerReadBarrier && IsValidReadBarrierImplicitCheck(addr)) { |
| 460 | return true; |
| 461 | } |
| 462 | FALLTHROUGH_INTENDED; |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 463 | case Instruction::IGET_QUICK: |
| 464 | case Instruction::IGET_BOOLEAN_QUICK: |
| 465 | case Instruction::IGET_BYTE_QUICK: |
| 466 | case Instruction::IGET_CHAR_QUICK: |
| 467 | case Instruction::IGET_SHORT_QUICK: |
| 468 | case Instruction::IGET_WIDE_QUICK: |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 469 | case Instruction::IPUT_QUICK: |
| 470 | case Instruction::IPUT_BOOLEAN_QUICK: |
| 471 | case Instruction::IPUT_BYTE_QUICK: |
| 472 | case Instruction::IPUT_CHAR_QUICK: |
| 473 | case Instruction::IPUT_SHORT_QUICK: |
| 474 | case Instruction::IPUT_WIDE_QUICK: |
| 475 | case Instruction::IPUT_OBJECT_QUICK: { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 476 | return (addr == 0u) || (addr == instr.VRegC_22c()); |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 477 | } |
| 478 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 479 | case Instruction::AGET_OBJECT: |
| 480 | if (kEmitCompilerReadBarrier && IsValidReadBarrierImplicitCheck(addr)) { |
| 481 | return true; |
| 482 | } |
| 483 | FALLTHROUGH_INTENDED; |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 484 | case Instruction::AGET: |
| 485 | case Instruction::AGET_WIDE: |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 486 | case Instruction::AGET_BOOLEAN: |
| 487 | case Instruction::AGET_BYTE: |
| 488 | case Instruction::AGET_CHAR: |
| 489 | case Instruction::AGET_SHORT: |
| 490 | case Instruction::APUT: |
| 491 | case Instruction::APUT_WIDE: |
| 492 | case Instruction::APUT_OBJECT: |
| 493 | case Instruction::APUT_BOOLEAN: |
| 494 | case Instruction::APUT_BYTE: |
| 495 | case Instruction::APUT_CHAR: |
Nicolas Geoffray | 350cc99 | 2016-06-29 21:45:10 +0100 | [diff] [blame] | 496 | case Instruction::APUT_SHORT: |
| 497 | case Instruction::FILL_ARRAY_DATA: |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 498 | case Instruction::ARRAY_LENGTH: { |
Nicolas Geoffray | 350cc99 | 2016-06-29 21:45:10 +0100 | [diff] [blame] | 499 | // The length access should crash. We currently do not do implicit checks on |
| 500 | // the array access itself. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 501 | return (addr == 0u) || (addr == mirror::Array::LengthOffset().Uint32Value()); |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | default: { |
| 505 | // We have covered all the cases where an NPE could occur. |
| 506 | // Note that this must be kept in sync with the compiler, and adding |
| 507 | // any new way to do implicit checks in the compiler should also update |
| 508 | // this code. |
| 509 | return false; |
| 510 | } |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | void ThrowNullPointerExceptionFromDexPC(bool check_address, uintptr_t addr) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 515 | uint32_t throw_dex_pc; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 516 | ArtMethod* method = Thread::Current()->GetCurrentMethod(&throw_dex_pc); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 517 | const DexFile::CodeItem* code = method->GetCodeItem(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 518 | CHECK_LT(throw_dex_pc, code->insns_size_in_code_units_); |
| 519 | const Instruction* instr = Instruction::At(&code->insns_[throw_dex_pc]); |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 520 | if (check_address && !IsValidImplicitCheck(addr, method, *instr)) { |
| 521 | const DexFile* dex_file = method->GetDeclaringClass()->GetDexCache()->GetDexFile(); |
| 522 | LOG(FATAL) << "Invalid address for an implicit NullPointerException check: " |
| 523 | << "0x" << std::hex << addr << std::dec |
| 524 | << ", at " |
| 525 | << instr->DumpString(dex_file) |
| 526 | << " in " |
| 527 | << PrettyMethod(method); |
| 528 | } |
| 529 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 530 | switch (instr->Opcode()) { |
| 531 | case Instruction::INVOKE_DIRECT: |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 532 | ThrowNullPointerExceptionForMethodAccess(instr->VRegB_35c(), kDirect); |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 533 | break; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 534 | case Instruction::INVOKE_DIRECT_RANGE: |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 535 | ThrowNullPointerExceptionForMethodAccess(instr->VRegB_3rc(), kDirect); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 536 | break; |
| 537 | case Instruction::INVOKE_VIRTUAL: |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 538 | ThrowNullPointerExceptionForMethodAccess(instr->VRegB_35c(), kVirtual); |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 539 | break; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 540 | case Instruction::INVOKE_VIRTUAL_RANGE: |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 541 | ThrowNullPointerExceptionForMethodAccess(instr->VRegB_3rc(), kVirtual); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 542 | break; |
| 543 | case Instruction::INVOKE_INTERFACE: |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 544 | ThrowNullPointerExceptionForMethodAccess(instr->VRegB_35c(), kInterface); |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 545 | break; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 546 | case Instruction::INVOKE_INTERFACE_RANGE: |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 547 | ThrowNullPointerExceptionForMethodAccess(instr->VRegB_3rc(), kInterface); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 548 | break; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 549 | case Instruction::INVOKE_VIRTUAL_QUICK: |
| 550 | case Instruction::INVOKE_VIRTUAL_RANGE_QUICK: { |
| 551 | // Since we replaced the method index, we ask the verifier to tell us which |
| 552 | // method is invoked at this location. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 553 | ArtMethod* invoked_method = |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 554 | verifier::MethodVerifier::FindInvokedMethodAtDexPc(method, throw_dex_pc); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 555 | if (invoked_method != nullptr) { |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 556 | // NPE with precise message. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 557 | ThrowNullPointerExceptionForMethodAccess(invoked_method, kVirtual); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 558 | } else { |
| 559 | // NPE with imprecise message. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 560 | ThrowNullPointerException("Attempt to invoke a virtual method on a null object reference"); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 561 | } |
| 562 | break; |
| 563 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 564 | case Instruction::IGET: |
| 565 | case Instruction::IGET_WIDE: |
| 566 | case Instruction::IGET_OBJECT: |
| 567 | case Instruction::IGET_BOOLEAN: |
| 568 | case Instruction::IGET_BYTE: |
| 569 | case Instruction::IGET_CHAR: |
| 570 | case Instruction::IGET_SHORT: { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 571 | ArtField* field = |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 572 | Runtime::Current()->GetClassLinker()->ResolveField(instr->VRegC_22c(), method, false); |
| 573 | ThrowNullPointerExceptionForFieldAccess(field, true /* read */); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 574 | break; |
| 575 | } |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 576 | case Instruction::IGET_QUICK: |
Mathieu Chartier | ffc605c | 2014-12-10 10:35:44 -0800 | [diff] [blame] | 577 | case Instruction::IGET_BOOLEAN_QUICK: |
| 578 | case Instruction::IGET_BYTE_QUICK: |
| 579 | case Instruction::IGET_CHAR_QUICK: |
| 580 | case Instruction::IGET_SHORT_QUICK: |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 581 | case Instruction::IGET_WIDE_QUICK: |
| 582 | case Instruction::IGET_OBJECT_QUICK: { |
| 583 | // Since we replaced the field index, we ask the verifier to tell us which |
| 584 | // field is accessed at this location. |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 585 | ArtField* field = |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 586 | verifier::MethodVerifier::FindAccessedFieldAtDexPc(method, throw_dex_pc); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 587 | if (field != nullptr) { |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 588 | // NPE with precise message. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 589 | ThrowNullPointerExceptionForFieldAccess(field, true /* read */); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 590 | } else { |
| 591 | // NPE with imprecise message. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 592 | ThrowNullPointerException("Attempt to read from a field on a null object reference"); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 593 | } |
| 594 | break; |
| 595 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 596 | case Instruction::IPUT: |
| 597 | case Instruction::IPUT_WIDE: |
| 598 | case Instruction::IPUT_OBJECT: |
| 599 | case Instruction::IPUT_BOOLEAN: |
| 600 | case Instruction::IPUT_BYTE: |
| 601 | case Instruction::IPUT_CHAR: |
| 602 | case Instruction::IPUT_SHORT: { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 603 | ArtField* field = |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 604 | Runtime::Current()->GetClassLinker()->ResolveField(instr->VRegC_22c(), method, false); |
| 605 | ThrowNullPointerExceptionForFieldAccess(field, false /* write */); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 606 | break; |
| 607 | } |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 608 | case Instruction::IPUT_QUICK: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 609 | case Instruction::IPUT_BOOLEAN_QUICK: |
| 610 | case Instruction::IPUT_BYTE_QUICK: |
| 611 | case Instruction::IPUT_CHAR_QUICK: |
| 612 | case Instruction::IPUT_SHORT_QUICK: |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 613 | case Instruction::IPUT_WIDE_QUICK: |
| 614 | case Instruction::IPUT_OBJECT_QUICK: { |
| 615 | // Since we replaced the field index, we ask the verifier to tell us which |
| 616 | // field is accessed at this location. |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 617 | ArtField* field = |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 618 | verifier::MethodVerifier::FindAccessedFieldAtDexPc(method, throw_dex_pc); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 619 | if (field != nullptr) { |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 620 | // NPE with precise message. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 621 | ThrowNullPointerExceptionForFieldAccess(field, false /* write */); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 622 | } else { |
| 623 | // NPE with imprecise message. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 624 | ThrowNullPointerException("Attempt to write to a field on a null object reference"); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 625 | } |
| 626 | break; |
| 627 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 628 | case Instruction::AGET: |
| 629 | case Instruction::AGET_WIDE: |
| 630 | case Instruction::AGET_OBJECT: |
| 631 | case Instruction::AGET_BOOLEAN: |
| 632 | case Instruction::AGET_BYTE: |
| 633 | case Instruction::AGET_CHAR: |
| 634 | case Instruction::AGET_SHORT: |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 635 | ThrowException("Ljava/lang/NullPointerException;", nullptr, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 636 | "Attempt to read from null array"); |
| 637 | break; |
| 638 | case Instruction::APUT: |
| 639 | case Instruction::APUT_WIDE: |
| 640 | case Instruction::APUT_OBJECT: |
| 641 | case Instruction::APUT_BOOLEAN: |
| 642 | case Instruction::APUT_BYTE: |
| 643 | case Instruction::APUT_CHAR: |
| 644 | case Instruction::APUT_SHORT: |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 645 | ThrowException("Ljava/lang/NullPointerException;", nullptr, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 646 | "Attempt to write to null array"); |
| 647 | break; |
| 648 | case Instruction::ARRAY_LENGTH: |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 649 | ThrowException("Ljava/lang/NullPointerException;", nullptr, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 650 | "Attempt to get length of null array"); |
| 651 | break; |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 652 | case Instruction::FILL_ARRAY_DATA: { |
| 653 | ThrowException("Ljava/lang/NullPointerException;", nullptr, |
| 654 | "Attempt to write to null array"); |
| 655 | break; |
| 656 | } |
Nicolas Geoffray | 7f0ae73 | 2016-06-29 14:54:35 +0100 | [diff] [blame] | 657 | case Instruction::MONITOR_ENTER: |
| 658 | case Instruction::MONITOR_EXIT: { |
| 659 | ThrowException("Ljava/lang/NullPointerException;", nullptr, |
| 660 | "Attempt to do a synchronize operation on a null object"); |
| 661 | break; |
| 662 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 663 | default: { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 664 | const DexFile* dex_file = |
| 665 | method->GetDeclaringClass()->GetDexCache()->GetDexFile(); |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 666 | LOG(FATAL) << "NullPointerException at an unexpected instruction: " |
| 667 | << instr->DumpString(dex_file) |
| 668 | << " in " |
| 669 | << PrettyMethod(method); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 670 | break; |
| 671 | } |
| 672 | } |
| 673 | } |
| 674 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 675 | void ThrowNullPointerException(const char* msg) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 676 | ThrowException("Ljava/lang/NullPointerException;", nullptr, msg); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | // RuntimeException |
| 680 | |
| 681 | void ThrowRuntimeException(const char* fmt, ...) { |
| 682 | va_list args; |
| 683 | va_start(args, fmt); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 684 | ThrowException("Ljava/lang/RuntimeException;", nullptr, fmt, &args); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 685 | va_end(args); |
| 686 | } |
| 687 | |
Andreas Gampe | 103992b | 2016-01-04 15:32:43 -0800 | [diff] [blame] | 688 | // Stack overflow. |
| 689 | |
| 690 | void ThrowStackOverflowError(Thread* self) { |
| 691 | if (self->IsHandlingStackOverflow()) { |
| 692 | LOG(ERROR) << "Recursive stack overflow."; |
| 693 | // We don't fail here because SetStackEndForStackOverflow will print better diagnostics. |
| 694 | } |
| 695 | |
| 696 | self->SetStackEndForStackOverflow(); // Allow space on the stack for constructor to execute. |
| 697 | JNIEnvExt* env = self->GetJniEnv(); |
| 698 | std::string msg("stack size "); |
| 699 | msg += PrettySize(self->GetStackSize()); |
| 700 | |
| 701 | // Avoid running Java code for exception initialization. |
| 702 | // TODO: Checks to make this a bit less brittle. |
| 703 | |
| 704 | std::string error_msg; |
| 705 | |
| 706 | // Allocate an uninitialized object. |
| 707 | ScopedLocalRef<jobject> exc(env, |
| 708 | env->AllocObject(WellKnownClasses::java_lang_StackOverflowError)); |
| 709 | if (exc.get() != nullptr) { |
| 710 | // "Initialize". |
| 711 | // StackOverflowError -> VirtualMachineError -> Error -> Throwable -> Object. |
| 712 | // Only Throwable has "custom" fields: |
| 713 | // String detailMessage. |
| 714 | // Throwable cause (= this). |
| 715 | // List<Throwable> suppressedExceptions (= Collections.emptyList()). |
| 716 | // Object stackState; |
| 717 | // StackTraceElement[] stackTrace; |
| 718 | // Only Throwable has a non-empty constructor: |
| 719 | // this.stackTrace = EmptyArray.STACK_TRACE_ELEMENT; |
| 720 | // fillInStackTrace(); |
| 721 | |
| 722 | // detailMessage. |
| 723 | // TODO: Use String::FromModifiedUTF...? |
| 724 | ScopedLocalRef<jstring> s(env, env->NewStringUTF(msg.c_str())); |
| 725 | if (s.get() != nullptr) { |
| 726 | env->SetObjectField(exc.get(), WellKnownClasses::java_lang_Throwable_detailMessage, s.get()); |
| 727 | |
| 728 | // cause. |
| 729 | env->SetObjectField(exc.get(), WellKnownClasses::java_lang_Throwable_cause, exc.get()); |
| 730 | |
| 731 | // suppressedExceptions. |
| 732 | ScopedLocalRef<jobject> emptylist(env, env->GetStaticObjectField( |
| 733 | WellKnownClasses::java_util_Collections, |
| 734 | WellKnownClasses::java_util_Collections_EMPTY_LIST)); |
| 735 | CHECK(emptylist.get() != nullptr); |
| 736 | env->SetObjectField(exc.get(), |
| 737 | WellKnownClasses::java_lang_Throwable_suppressedExceptions, |
| 738 | emptylist.get()); |
| 739 | |
| 740 | // stackState is set as result of fillInStackTrace. fillInStackTrace calls |
| 741 | // nativeFillInStackTrace. |
| 742 | ScopedLocalRef<jobject> stack_state_val(env, nullptr); |
| 743 | { |
| 744 | ScopedObjectAccessUnchecked soa(env); |
| 745 | stack_state_val.reset(soa.Self()->CreateInternalStackTrace<false>(soa)); |
| 746 | } |
| 747 | if (stack_state_val.get() != nullptr) { |
| 748 | env->SetObjectField(exc.get(), |
| 749 | WellKnownClasses::java_lang_Throwable_stackState, |
| 750 | stack_state_val.get()); |
| 751 | |
| 752 | // stackTrace. |
| 753 | ScopedLocalRef<jobject> stack_trace_elem(env, env->GetStaticObjectField( |
| 754 | WellKnownClasses::libcore_util_EmptyArray, |
| 755 | WellKnownClasses::libcore_util_EmptyArray_STACK_TRACE_ELEMENT)); |
| 756 | env->SetObjectField(exc.get(), |
| 757 | WellKnownClasses::java_lang_Throwable_stackTrace, |
| 758 | stack_trace_elem.get()); |
| 759 | } else { |
| 760 | error_msg = "Could not create stack trace."; |
| 761 | } |
| 762 | // Throw the exception. |
Mathieu Chartier | c4f3925 | 2016-10-05 18:32:08 -0700 | [diff] [blame] | 763 | self->SetException(self->DecodeJObject(exc.get())->AsThrowable()); |
Andreas Gampe | 103992b | 2016-01-04 15:32:43 -0800 | [diff] [blame] | 764 | } else { |
| 765 | // Could not allocate a string object. |
| 766 | error_msg = "Couldn't throw new StackOverflowError because JNI NewStringUTF failed."; |
| 767 | } |
| 768 | } else { |
| 769 | error_msg = "Could not allocate StackOverflowError object."; |
| 770 | } |
| 771 | |
| 772 | if (!error_msg.empty()) { |
| 773 | LOG(WARNING) << error_msg; |
| 774 | CHECK(self->IsExceptionPending()); |
| 775 | } |
| 776 | |
| 777 | bool explicit_overflow_check = Runtime::Current()->ExplicitStackOverflowChecks(); |
| 778 | self->ResetDefaultStackEnd(); // Return to default stack size. |
| 779 | |
| 780 | // And restore protection if implicit checks are on. |
| 781 | if (!explicit_overflow_check) { |
| 782 | self->ProtectStack(); |
| 783 | } |
| 784 | } |
| 785 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 786 | // StringIndexOutOfBoundsException |
| 787 | |
| 788 | void ThrowStringIndexOutOfBoundsException(int index, int length) { |
| 789 | ThrowException("Ljava/lang/StringIndexOutOfBoundsException;", nullptr, |
| 790 | StringPrintf("length=%d; index=%d", length, index).c_str()); |
| 791 | } |
| 792 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 793 | // VerifyError |
| 794 | |
Mathieu Chartier | 6b3d12b | 2016-10-13 13:59:58 -0700 | [diff] [blame] | 795 | void ThrowVerifyError(ObjPtr<mirror::Class> referrer, const char* fmt, ...) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 796 | va_list args; |
| 797 | va_start(args, fmt); |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 798 | ThrowException("Ljava/lang/VerifyError;", referrer, fmt, &args); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 799 | va_end(args); |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 800 | } |
| 801 | |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 802 | // WrongMethodTypeException |
| 803 | |
| 804 | void ThrowWrongMethodTypeException(mirror::MethodType* callee_type, |
| 805 | mirror::MethodType* callsite_type) { |
| 806 | // TODO(narayan): Should we provide more detail here ? The RI doesn't bother. |
| 807 | UNUSED(callee_type); |
| 808 | UNUSED(callsite_type); |
| 809 | |
| 810 | ThrowException("Ljava/lang/invoke/WrongMethodTypeException;", |
| 811 | nullptr, |
| 812 | "Invalid method type for signature polymorphic call"); |
| 813 | } |
| 814 | |
Ian Rogers | 87e552d | 2012-08-31 15:54:48 -0700 | [diff] [blame] | 815 | } // namespace art |